1
0

some progress :)

This commit is contained in:
acn 2016-06-02 16:50:10 +02:00
parent 0876bef079
commit 9e1ee97095

View File

@ -12,104 +12,141 @@ import config
import cept import cept
class rtxMask: class rtxMask:
""" Klasse zur Verarbeitung einer Eingabemaske """ Klasse zur Verarbeitung einer Eingabemaske
""" """
lines = [] lines = []
answers = [] answers = []
def __init__(self): def __init__(self):
def addLine(x, y, length): def addLine(x, y, length):
""" adds a new line for the mask to the object """ """ adds a new line for the mask to the object """
newLine['x'] = x newLine['x'] = x
newLine['y'] = y newLine['y'] = y
newLine['length'] = length newLine['length'] = length
self.lines.append(newLine) self.lines.append(newLine)
def get_answer(self, nr): def get_answer(self, nr):
""" returns the answer for a specific line """ """ returns the answer for a specific line """
if nr >= 0 and nr <= len(self.answers): if nr >= 0 and nr <= len(self.answers):
return self.answers[nr] return self.answers[nr]
else else
return False return False
def get_answers(self): def get_answers(self):
""" returns the array of all answers """ """ returns the array of all answers """
return self.answers return self.answers
def _pos_cur_to_line(self, line): def _pos_cur_to_line(self, line):
""" positions the cursor to the beginning of a line """ """ positions the cursor to the beginning of a line """
zeile=self.lines[line] zeile=self.lines[line]
self._pos_cur_to_xy(zeile['x'], zeile['y']) self._pos_cur_to_xy(zeile['x'], zeile['y'])
def _pos_cur_to_xy(self, x, y): def _pos_cur_to_xy(self, x, y):
""" positions the cursor to a (x,y) position on screen """ """ positions the cursor to a (x,y) position on screen """
toX=0x41 + x toX=0x41 + x
toY=0x41 + y toY=0x41 + y
gotoString = "\x1f" + chr(toX) + chr(toY) gotoString = "\x1f" + chr(toX) + chr(toY)
glob.ser.write(bytes(gotoString, "latin-1")) glob.ser.write(bytes(gotoString, "latin-1"))
def _set_str_at_pos(self, char, pos, line): def _set_str_at_pos(self, char, pos, line):
""" changes the 'char' at a position 'pos' of a specific answer 'line' """ """ changes the 'char' at a position 'pos' of a specific answer 'line' """
zeile = self.answers[line] zeile = self.answers[line]
# if the line is shorter than the position, add spaces # if the line is shorter than the position, add spaces
while len(zeile) < pos: while len(zeile) < pos:
zeile += " " zeile += " "
zeile = zeile[:pos-1] + char + zeile[pos:] zeile = zeile[:pos-1] + char + zeile[pos:]
answers[line] = zeile answers[line] = zeile
"""
def _cut_off_rest_of_line(self, line, pos):
""" erases the rest of the line from the 'lines' variable and from the screen """
zeile = self.answers[line]
self.answers[line] = zeile[:pos]
def _cut_off_rest_of_line(self, line, pos): if zeile[pos:] != "":
""" erases the rest of the line from the 'lines' variable and from the screen """ numOfSpaces = len(zeile[pos:])
zeile = self.answers[line] spaces = " " * numOfSpaces
self.answers[line] = zeile[:pos] backSpaces = cept.BSP * numOfSpaces
glob.ser.write(bytes(spaces + backSpaces, "latin-1"))
"""
def process_input(self):
""" reads the input from the client, fills the mask and gets the input """
if zeile[pos:] != "": # if there have no input lines been defined, no input can be processed - so exit the function
numOfSpaces = len(zeile[pos:]) if len(lines) == 0:
spaces = " " * numOfSpaces logging.debug("Keine Zeilen in der Maske definiert!")
backSpaces = "\x08" * numOfSpaces return False
glob.ser.write(bytes(spaces + backSpaces, "latin-1"))
def process_input(self): # position the cursor into the first field
""" reads the input from the client, fills the mask and gets the input """ self._pos_cur_to_line(lines[0])
if len(lines) == 0: posx = 0 # cursor position inside the line - max. position is length-1
logging.debug("Keine Zeilen in der Maske definiert!") posy = 0 # the current line - max. number is len(lines)-1
return False
# position the cursor into the first field weiter = True
self._pos_cur_to_line(lines[1]) # read input and interpret it
posx = 0 # cursor position inside the line - max. position is length-1 while weiter==True:
posy = 0 # the current line - max. number is len(lines)-1 # if the modem hangs up, exit the function:
#if config.MODE == "modem" and glob.ser.getCD() == False:
# weiter=False
in_byte = glob.ser.read(1)
instr = str(in_byte, encoding="latin-1")
echostr = instr
weiter = True if instr == cept.TER or instr == cept.CR:
# read input and interpret it # go to the beginning of the next line
while weiter==True: # or finish the mask
# if the modem hangs up, exit the function: if posy == len(lines)-1:
#if config.MODE == "modem" and glob.ser.getCD() == False: # this was the last line, now send the data
# weiter=False # TODO: weitermachen
in_byte = glob.ser.read(1) else:
instr = str(in_byte, encoding="latin-1") # go to the beginning of the next line
echostr = instr posy += 1
posx = 0
self._pos_cur_to_line(lines[posy])
elif instr == cept.BSP:
answers[posy] = answers[posy][:-1]
posx -= 1
elif instr == cept.UP:
# if the cursor is in the first line, we can't go higher...
# so we ignore the keypress
echostr = "" # no echo needed, we position the curser ourselves
if posy > 0:
posy -= 1
posx = 0
self._pos_cur_to_line(lines[posy])
elif instr == cept.DOWN:
# same here: last line => it can't go lower => ignore
echostr = "" # no echo needed, we position the curser ourselves
if posy < len(self.lines):
posy += 1
posx = 0
self._pos_cur_to_line(lines[posy])
elif instr == cept.LEFT:
if posx > 0:
posx -= 1
else:
echostr = ""
elif instr == cept.RIGHT:
if posx < len(answers[posy]):
posx += 1
else:
echostr = ""
elif instr == cept.SEND: # ist das DCT??
# TODO: send data
elif instr.isalnum():
# "normal" input
# TODO: lineinput == Zeilenende beachten
self._set_str_at_pos(instr, posx, posy)
posx += 1
else:
# ignore the rest and do not echo it :)
echostr = ""
if instr == cept.TER or instr == cept.CR: # now send the echo
if posy == len(lines)-1: glob.ser.write(bytes(echostr, "latin-1"))
# this was the last line, now send the data
# TODO
weiter = False
elif instr.isalnum():
self._set_str_at_pos(instr, posx, posy)
posx += 1
elif instr == cept.BSP:
answers[posy] = answers[posy][:-1]
posx -= 1
else:
echostr = ""
# lineinput == Zeilenende beachten
glob.ser.write(bytes(echostr, "latin-1"))