1
0

some progress :)

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

View File

@ -60,7 +60,7 @@ class rtxMask:
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): def _cut_off_rest_of_line(self, line, pos):
""" erases the rest of the line from the 'lines' variable and from the screen """ """ erases the rest of the line from the 'lines' variable and from the screen """
zeile = self.answers[line] zeile = self.answers[line]
@ -69,18 +69,20 @@ class rtxMask:
if zeile[pos:] != "": if zeile[pos:] != "":
numOfSpaces = len(zeile[pos:]) numOfSpaces = len(zeile[pos:])
spaces = " " * numOfSpaces spaces = " " * numOfSpaces
backSpaces = "\x08" * numOfSpaces backSpaces = cept.BSP * numOfSpaces
glob.ser.write(bytes(spaces + backSpaces, "latin-1")) glob.ser.write(bytes(spaces + backSpaces, "latin-1"))
"""
def process_input(self): def process_input(self):
""" reads the input from the client, fills the mask and gets the input """ """ reads the input from the client, fills the mask and gets the input """
# if there have no input lines been defined, no input can be processed - so exit the function
if len(lines) == 0: if len(lines) == 0:
logging.debug("Keine Zeilen in der Maske definiert!") logging.debug("Keine Zeilen in der Maske definiert!")
return False return False
# position the cursor into the first field # position the cursor into the first field
self._pos_cur_to_line(lines[1]) self._pos_cur_to_line(lines[0])
posx = 0 # cursor position inside the line - max. position is length-1 posx = 0 # cursor position inside the line - max. position is length-1
posy = 0 # the current line - max. number is len(lines)-1 posy = 0 # the current line - max. number is len(lines)-1
@ -95,21 +97,56 @@ class rtxMask:
echostr = instr echostr = instr
if instr == cept.TER or instr == cept.CR: if instr == cept.TER or instr == cept.CR:
# go to the beginning of the next line
# or finish the mask
if posy == len(lines)-1: if posy == len(lines)-1:
# this was the last line, now send the data # this was the last line, now send the data
# TODO # TODO: weitermachen
weiter = False else:
elif instr.isalnum(): # go to the beginning of the next line
self._set_str_at_pos(instr, posx, posy) posy += 1
posx += 1 posx = 0
self._pos_cur_to_line(lines[posy])
elif instr == cept.BSP: elif instr == cept.BSP:
answers[posy] = answers[posy][:-1] answers[posy] = answers[posy][:-1]
posx -= 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: else:
echostr = "" 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 = ""
# lineinput == Zeilenende beachten # now send the echo
glob.ser.write(bytes(echostr, "latin-1")) glob.ser.write(bytes(echostr, "latin-1"))