diff --git a/brmbar3/brmbar-gui-qt4.py b/brmbar3/brmbar-gui-qt4.py index 429aeb6..a351bee 100755 --- a/brmbar3/brmbar-gui-qt4.py +++ b/brmbar3/brmbar-gui-qt4.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 import sys +import subprocess from PySide import QtCore, QtGui, QtDeclarative @@ -10,6 +11,12 @@ import brmbar # User credit balance limit; sale will fail when balance is below this limit. LIMIT_BALANCE = -200 +# When below this credit balance, an alert hook script (see below) is run. +ALERT_BALANCE = 0 +# This script is executed when a user is buying things and their balance is +# below LIMIT_BALANCE (with argument "limit") or below ALERT_BALANCE +# (with argument "alert"). +ALERT_SCRIPT = "./alert.sh" class ShopAdapter(QtCore.QObject): @@ -76,7 +83,14 @@ class ShopAdapter(QtCore.QObject): @QtCore.Slot('QVariant', 'QVariant', result='QVariant') def canSellItem(self, itemid, userid): user = brmbar.Account.load(db, id = userid) - return -user.balance() > LIMIT_BALANCE + if -user.balance() > ALERT_BALANCE: + return True + elif -user.balance() > LIMIT_BALANCE: + subprocess.call(["sh", ALERT_SCRIPT, "alert"]) + return True + else: + subprocess.call(["sh", ALERT_SCRIPT, "limit"]) + return False @QtCore.Slot('QVariant', 'QVariant', result='QVariant') def sellItem(self, itemid, userid):