Display now has scrolling text implemented in a python thread and error-screens, etc

This commit is contained in:
Florian Streibelt 2011-10-15 03:49:13 +02:00
parent 15493ee6aa
commit 665ba7cc5e
1 changed files with 69 additions and 2 deletions

View File

@ -18,6 +18,9 @@ import os
import time import time
import urllib2 import urllib2
from thread import start_new_thread, allocate_lock
import time
COLOR_HINT = Fore.YELLOW + Style.BRIGHT COLOR_HINT = Fore.YELLOW + Style.BRIGHT
COLOR_ERROR = Fore.RED COLOR_ERROR = Fore.RED
@ -32,8 +35,62 @@ COLOR_RESET = Style.RESET_ALL
display_fifo = None display_fifo = None
scroll_line1 = None
scroll_line2 = None
def print_display(s):
lock = allocate_lock()
def display_handle_scroll(line,text,offset):
if (text):
send_display("\x1f\x24\x01%c%s" % (chr(line),text[offset:(20+offset)]))
l = len(text)
missing_chars=20+offset-l
if (missing_chars>0):
send_display(text[:missing_chars])
offset=((offset+1)%l)
else:
offset=0 #reset offset
return offset
def display_scroll_text(line,text):
global scroll_line1,scroll_line2
lock.acquire()
if (line==1): #clear the line on invocation:
send_display("\x1f\x24\x01%c\x18" % chr(line) )
scroll_line1 = text
if (line==2): #clear the line on invocation:
send_display("\x1f\x24\x01%c\x18" % chr(line) )
scroll_line2 = text
lock.release()
def display_screen(title,message):
if (len(title)<21):
send_display("\x1f\x24\x01%c\x18%s" % (chr(1),'\xdb'*20) )
if (len(title)<20):
pos=1+(20-len(title))/2
else:
pos=1
send_display("\x1f\x24%c%c%s" % (chr(pos),chr(1),title) )
else:
display_scroll_text(1,title)
display_scroll_text(2,message)
def display_thread(x):
global scroll_line1,scroll_line2
offset_line1=0
offset_line2=0
while(True):
lock.acquire()
offset_line1 = display_handle_scroll(1,scroll_line1,offset_line1)
offset_line2 = display_handle_scroll(2,scroll_line2,offset_line2)
lock.release()
time.sleep(.5)
def send_display(s):
global display_fifo global display_fifo
if not display_fifo: if not display_fifo:
try: try:
@ -55,6 +112,12 @@ def print_display(s):
pass pass
return return
def print_display(s):
lock.acquire()
# scroll_line1=None
# scroll_line2=None
# send_display(s)
lock.release()
def clear(): def clear():
os.system('clear') os.system('clear')
@ -399,9 +462,13 @@ def handle(line, status):
def main(): def main():
colorama.init() colorama.init()
status = Status() status = Status()
global scroll_line1,scroll_line2
print_display("\x1b\x40Kassensystem \n startet...") print_display("\x1b\x40Kassensystem \n startet...")
start_new_thread(display_thread,(1,))
#display_scroll_text(1,"Line1: Text, dumm scrollend!")
#display_scroll_text(4,"Line2: Und hier Text, auch dumm scrollend!")
display_screen("HINWEIS","Herzlich willkommen bei der Freitagsrunde! *** ")
while True: while True:
clear() clear()
status.dump() status.dump()