1
0
rtx/rtxMask.py
2016-05-23 16:01:04 +02:00

85 lines
2.0 KiB
Python

# -*- coding: UTF-8 -*-
'''
rtx - RetroText
rtxMask: Klasse zur Verarbeitung einer Eingabemaske
by Anna Christina Naß <acn@acn.wtf>
released under GPL
'''
import glob
import logging
import config
import cept
class rtxMask:
""" Klasse zur Verarbeitung einer Eingabemaske
"""
posx = 0
posy = 0
lines = []
answers = []
def __init__(self):
def addLine(x, y, length, linetype="text"):
""" adds a new line for the mask to the object """
lines.append((x,y,length, linetype))
def get_answer(self, nr):
""" returns the answer for a specific line """
if nr >= 0 and nr <= len(self.answers):
return self.answers[nr]
else
return False
def get_answers(self):
""" returns the array of all answers """
return self.answers
def _pos_cur_to_line(self, line):
""" positions the cursor to the beginning of a line """
zeile=lines(line)
_pos_cur_to_xy(self, zeile.posx, zeile.posy)
def _pos_cur_to_xy(self, x, y):
""" positions the cursor to a (x,y) position on screen """
toX=0x41 + x
toY=0x41 + y
gotoString = "\x1f" + chr(toX) + chr(toY)
glob.ser.write(bytes(gotoString, "latin-1"))
def process_input(self):
""" reads the input from the client, fills the mask and gets the input """
for i in range(len(lines)):
# position the cursor
self._pos_cur_to_line(lines[i])
lineinput = "" # this will be the answer
weiter = True
# read input and interpret it
while weiter==True:
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
if instr == cept.TER:
answer[i] = lineinput
weiter=False
elif instr.isalnum():
lineinput += instr
elif instr == cept.BSP:
lineinput = lineinput[:-1]
else:
echostr = ""
# lineinput == Zeilenende beachten
# dafür aber die Konstruktion von lines nochmal umbauen, um auf "length" zugreifen zu können...
glob.ser.write(bytes(echostr, "latin-1"))