本文整理汇总了Python中ui.UI.update_credit方法的典型用法代码示例。如果您正苦于以下问题:Python UI.update_credit方法的具体用法?Python UI.update_credit怎么用?Python UI.update_credit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ui.UI
的用法示例。
在下文中一共展示了UI.update_credit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LazzorManager
# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import update_credit [as 别名]
class LazzorManager(object):
def __init__(self, config_file_path):
config = ConfigParser.RawConfigParser()
config.read(config_file_path)
self._logger = logging.getLogger(__name__)
self._ui = UI("lazzormanagement\nbooting...")
user_config_file_path = os.path.dirname(config_file_path) + \
os.path.sep + config.get('Users', 'users_file')
self._user_manager = UserManager(user_config_file_path)
self._lazzor = Lazzor()
while True:
try:
self._upay_session_manager = nupay.SessionManager(config)
break
except nupay.SessionConnectionError as e:
self._logger.warning("Can not reach the database")
self._ui.warning_database_connection(timeout = 5)
except nupay.TimeoutError as e:
self._logger.warning("Timeout while connection to the database")
self._ui.warning_database_connection(timeout = 5)
self._ui.notify_try_again()
self._token_reader = nupay.USBTokenReader()
def _login(self):
while True:
user = self._ui.choose_user(self._user_manager.users)
passcode = self._ui.get_passcode(user.username)
passcode_ok = self._user_manager.check_passcode(user, passcode)
if passcode_ok == False:
self._ui.notify_bad_passcode(user.timeout)
elif user.active == False:
self._ui.notify_inactive_user(user.username)
else:
self._logger.debug("Leaving user selection mode")
return user
def _activate_laser(self, user):
def ui_update(session):
if session.credit % 5 == 0:
self._ui.update_credit(session.credit)
self._logger.info("Waiting for USB stick with purse")
self._ui.notify_waiting_for_usb()
while True:
try:
tokens = self._token_reader.read_tokens()
break
except nupay.NoTokensAvailableError:
if self._ui.check_button_pressed():
self._ui.wait_for_buttons()
return
time.sleep(1)
self._logger.info("Read %d tokens"%len(tokens))
self._ui.notify_credit()
try:
with self._upay_session_manager.create_session() as session:
session.validate_tokens(tokens, ui_update)
self._ui.update_credit(session.credit)
self._logger.info("Balance is %.02f Eur" % session.credit)
self._ui.wait_for_ok()
if session.credit > 0:
self._run_payment_loop(session)
except nupay.SessionConnectionError as e:
self._logger.warning("Databse connection could not be estalished")
self._ui.warning_database_connection(timeout = 5)
except nupay.TimeoutError:
self._logger.warning("Databse connection timed out")
self._ui.warning_database_connection(timeout = 5)
finally:
self._lazzor.lock_laser()
def _run_payment_loop(self, session):
total_on_time = 0
prev_on_time = 0
paid_time = 0
minute_cost = Decimal(0.5)
sub_total = Decimal(0)
self._ui.active_screen()
self._lazzor.lock_laser()
self._lazzor.reset_consumption_timer()
while self._token_reader.medium_valid:
if total_on_time > paid_time:
self._logger.info("Getting more money")
#.........这里部分代码省略.........