Added first Code fragments for external display.
This commit is contained in:
parent
af69d2f16f
commit
7bcc8f0c18
|
@ -30,6 +30,27 @@ COLOR_MUCH = Fore.YELLOW + Style.BRIGHT
|
|||
|
||||
COLOR_RESET = Style.RESET_ALL
|
||||
|
||||
display_fifo = None
|
||||
|
||||
|
||||
def print_display(s):
|
||||
global display_fifo
|
||||
"""
|
||||
Comment out this return for now if you dont
|
||||
want to use the display.
|
||||
|
||||
return
|
||||
|
||||
"""
|
||||
if not display_fifo:
|
||||
try:
|
||||
display_fifo = open('/tmp/display', 'w')
|
||||
except IOError:
|
||||
display_fifo = None
|
||||
return
|
||||
display_fifo.write(s)
|
||||
display_fifo.flush()
|
||||
|
||||
|
||||
def clear():
|
||||
os.system('clear')
|
||||
|
@ -71,6 +92,7 @@ def delay(what, seconds):
|
|||
|
||||
def warn_balance():
|
||||
print('Kontostand im Minus, bitte Geld aufladen.')
|
||||
print_display('\e\x0cKontostand im Minus, bitte Geld aufladen.')
|
||||
|
||||
|
||||
def error_page(message):
|
||||
|
@ -122,6 +144,7 @@ class Status:
|
|||
if self.logged_in():
|
||||
print('Eingeloggt als: %s%s%s' % (COLOR_SOME, self.login_name, COLOR_RESET))
|
||||
print()
|
||||
print_display('\e\x0cBenutzer: %10s' %self.login_name[:10])
|
||||
if self.transfers:
|
||||
initial_command, initial_balance = self.transfers[0]
|
||||
|
||||
|
@ -142,6 +165,7 @@ class Status:
|
|||
print(COLOR_SOME + 'Committen nicht vergessen.' + COLOR_RESET)
|
||||
else:
|
||||
print('Kontostand beträgt: %s%.2f Euro%s' % (COLOR_MUCH, self.balance, COLOR_RESET))
|
||||
print_display('Kontostand: %8.2f' % self.balance)
|
||||
if self.balance < 0:
|
||||
print()
|
||||
warn_balance()
|
||||
|
@ -149,6 +173,7 @@ class Status:
|
|||
print(COLOR_MUCH + 'Bitte einloggen.' + COLOR_RESET)
|
||||
print()
|
||||
print('Scanne dazu deine ID-Karte mit dem Barcode-Leser.')
|
||||
print_display("\e\x0cAnmeldung: Bitte ID-Karte scannen...")
|
||||
print()
|
||||
|
||||
def logged_in(self):
|
||||
|
@ -173,6 +198,7 @@ class Status:
|
|||
try:
|
||||
command.run(self.login_name)
|
||||
except urllib2.HTTPError as e:
|
||||
print_display('\e\x0cFEHLER: Server Error%20s' % str(e)[:20])
|
||||
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
||||
break
|
||||
else:
|
||||
|
@ -344,8 +370,10 @@ def handle(line, status):
|
|||
item = status.find(line)
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code == 404: # URL not found == item not found with REST
|
||||
print_display('\e\x0cFEHLER:\nAktion/ware unbekannt')
|
||||
error_page('FEHLER: Aktion oder Ware "%s" nicht bekannt' % line)
|
||||
else:
|
||||
print_display('\e\x0cFEHLER: Server Error%20s' % str(e)[:20])
|
||||
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
||||
else:
|
||||
status.buy(item)
|
||||
|
@ -354,8 +382,10 @@ def handle(line, status):
|
|||
status.login(line)
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code == 404: # URL not found == user unknown
|
||||
print_display('\e\x0cFEHLER: Nutzer ist unbekannt: "%7s"' % line[:7])
|
||||
error_page('FEHLER: Benutzer "%s" nicht bekannt' % line)
|
||||
else:
|
||||
print_display('\e\x0cFEHLER: Server Error%20s' % str(e)[:20])
|
||||
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
||||
except urllib2.URLError as e:
|
||||
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
||||
|
@ -365,6 +395,8 @@ def main():
|
|||
colorama.init()
|
||||
status = Status()
|
||||
|
||||
print_display("\x1b\x40Kassensystem \n startet...")
|
||||
|
||||
while True:
|
||||
clear()
|
||||
status.dump()
|
||||
|
@ -382,3 +414,4 @@ if __name__ == '__main__':
|
|||
main()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
print_display("\x1b\x40Goodbye!")
|
||||
|
|
Loading…
Reference in New Issue