Beispiel #1
0
	def create_logout():
		meta = {
			"clear_screen": False,
			"links": {
				"#": "00000"
			},
			"publisher_color": 7
		}

		data_cept = bytearray()
		data_cept.extend(Cept.parallel_mode())
		data_cept.extend(Cept.clear_screen())
		data_cept.extend(Cept.set_cursor(2, 1))
		data_cept.extend(Cept.set_screen_bg_color(12))
		data_cept.extend(Cept.set_fg_color(7))
		data_cept.extend(Login_UI.btx_logo())
		data_cept.extend(Cept.set_left_g3())
		data_cept.extend(Cept.set_fg_color(15))
		data_cept.extend(Cept.repeat("Q", 40))
		data_cept.extend(Cept.set_fg_color(7))
		data_cept.extend(Cept.set_left_g0())
		data_cept.extend(Cept.set_cursor(19, 8))
		data_cept.extend(Cept.from_str("Vielen Dank für Ihren Anruf!"))
		data_cept.extend(b'\r\n')
		data_cept.extend(b'\r\n')
		data_cept.extend(Cept.set_left_g3())
		data_cept.extend(Cept.set_fg_color(15))
		data_cept.extend(Cept.repeat("Q", 40))
		return (meta, data_cept)
Beispiel #2
0
	def create_search_page(mediawiki, basedir):
		meta = {
			"clear_screen": True,
			"links": {
				"0": "0"
			},
			"inputs": {
				"fields": [
					{
						"name": "search",
						"line": 18,
						"column": 9,
						"height": 1,
						"width": 31,
						"bgcolor": 0,
						"fgcolor": 15,
						"validate": "call:MediaWiki_UI.callback_validate_search:" + str(mediawiki.id)
					}
				],
				"confirm": False,
				"target": "call:MediaWiki_UI.callback_search:" + str(mediawiki.id)
			},
			"publisher_color": 0
		}

		data_cept = bytearray()
		data_cept.extend(Cept.parallel_mode())
		data_cept.extend(Cept.set_screen_bg_color(7))
		data_cept.extend(Cept.set_cursor(2, 1))
		data_cept.extend(Cept.set_line_bg_color(0))
		data_cept.extend(b'\n')
		data_cept.extend(Cept.set_line_bg_color(0))
		data_cept.extend(Cept.double_height())
		data_cept.extend(Cept.set_fg_color(7))
		data_cept.extend(Cept.from_str(mediawiki.title))
		data_cept.extend(b'\r\n')
		data_cept.extend(Cept.normal_size())
		data_cept.extend(b'\n')
		data_cept.extend(Cept.set_cursor(18, 1))
		data_cept.extend(Cept.set_fg_color(0))
		data_cept.extend(Cept.from_str(mediawiki.search_string))
		# trick: show cursor now so that user knows they can enter text, even though more
		# data is loading
		data_cept.extend(Cept.show_cursor())
		image = Image_UI(basedir + mediawiki.image, colors = 4)
#		image = Image_UI(basedir + "wikipedia.png", colors = 4)

		data_cept.extend(Cept.define_palette(image.palette))
		data_cept.extend(image.drcs)

		data_cept.extend(Cept.hide_cursor())

		y = 6
		for l in image.chars:
			data_cept.extend(Cept.set_cursor(y, int((41 - len(image.chars[0])) / 2)))
			data_cept.extend(Cept.load_g0_drcs())
			data_cept.extend(l)
			y += 1

		return (meta, data_cept)
Beispiel #3
0
 def line():
     data_cept = bytearray()
     data_cept.extend(Cept.set_left_g3())
     data_cept.extend(Cept.set_fg_color(15))
     data_cept.extend(Cept.repeat("Q", 40))
     data_cept.extend(Cept.set_fg_color(7))
     data_cept.extend(Cept.set_left_g0())
     return data_cept
Beispiel #4
0
 def set_color(self):
     cept_data = bytearray()
     if self.fgcolor is not None:
         cept_data.extend(Cept.set_fg_color(self.fgcolor))
     if self.bgcolor is not None:
         cept_data.extend(Cept.set_bg_color(self.bgcolor))
     return cept_data
Beispiel #5
0
def headerfooter(pageid, publisher_name, publisher_color):
	hide_header_footer = len(publisher_name) == 0
	hide_price = False
	# Early screenshots had a two-line publisher name with
	# the BTX logo in it for BTX-internal pages. Some .meta
	# files still reference this, but we should remove this.
	if publisher_name == "!BTX":
#		publisher_name = (
#			b'\x1b\x22\x41'                 # parallel mode
#			b'\x9b\x30\x40'                 # select palette #0
#			b'\x9e'                         # ???
#			b'\x87'                         # set fg color to #7
#			b'\x1b\x28\x20\x40'             # load DRCs into G0
#			b'\x0f'                         # G0 into left charset
#			b'\x21\x22\x23'                 # "!"#"
#			b'\n'
#			b'\r'
#			b'\x24\x25\x26'                 # "$%&"
#			b'\x0b'                         # cursor up
#			b'\x09'                         # cursor right
#			b'\x1b\x28\x40'                 # load G0 into G0
#			b'\x0f'                         # G0 into left charset
#			b'\n'
#			b'\x8d'                         # double height
#			# TODO: this does not draw!! :(
#			b'Bildschirmtext'
#		)
		publisher_name = "Bildschirmtext"
		hide_price = True
	else:
		publisher_name = publisher_name[:30]

	hf = bytearray(Cept.set_res_40_24())
	hf.extend(Cept.set_cursor(23, 1))
	hf.extend(Cept.unprotect_line())
	hf.extend(Cept.set_line_fg_color_simple(12))
	hf.extend(Cept.parallel_limited_mode())
	hf.extend(Cept.set_cursor(24, 1))
	hf.extend(Cept.unprotect_line())
	hf.extend(b' \b')
	hf.extend(Cept.clear_line())
	hf.extend(Cept.cursor_home())
	hf.extend(Cept.unprotect_line())
	hf.extend(b' \b')
	hf.extend(Cept.clear_line())
	hf.extend(Cept.serial_limited_mode())
	hf.extend(Cept.set_cursor(24, 1))
	hf.extend(Cept.set_fg_color(8))
	hf.extend(b'\b')
	hf.extend(Cept.code_9d())
	hf.extend(b'\b')

	if publisher_color < 8:
		color_string = Cept.set_fg_color(publisher_color)
	else:
		color_string = Cept.set_fg_color_simple(publisher_color - 8)

	hf.extend(color_string)

	hf.extend(Cept.set_cursor(24, 19))

	if not hide_header_footer:
		hf.extend(Cept.from_str(pageid).rjust(22))

	hf.extend(Cept.cursor_home())
	hf.extend(Cept.set_palette(1))
	hf.extend(Cept.set_fg_color(8))
	hf.extend(b'\b')
	hf.extend(Cept.code_9d())
	hf.extend(b'\b')
	
	hf.extend(color_string)

	hf.extend(b'\r')

	hf.extend(Cept.from_str(publisher_name))

	# TODO: price
	if not hide_header_footer and not hide_price:
		hf.extend(Cept.set_cursor(1, 31))
		hf.extend(b'  ')
		hf.extend(Cept.from_str(Util.format_currency(0)))

	hf.extend(Cept.cursor_home())
	hf.extend(Cept.set_palette(0))
	hf.extend(Cept.protect_line())
	hf.extend(b'\n')
	return hf
    def messaging_create_message_detail(user, index, is_read):
        messages = user.messaging.select(is_read, index, 1)
        if len(messages) == 0:
            return None

        message = messages[0]

        meta = {
            "publisher_name": "Bildschirmtext",
            "include": "11a",
            "palette": "11a",
            "clear_screen": True,
            "links": {
                "0": "89" if is_read else "88",
            },
            "publisher_color": 7
        }

        from_date = message.from_date()
        from_time = message.from_time()
        if message.from_user.personal_data:
            from_street = message.from_user.street
            from_zip = message.from_user.zip
            from_city = message.from_user.city
        else:
            from_street = ""
            from_zip = ""
            from_city = ""

        data_cept = bytearray(Cept.parallel_limited_mode())
        data_cept.extend(Cept.set_cursor(2, 1))
        data_cept.extend(Cept.set_fg_color(3))
        data_cept.extend(b'von ')
        data_cept.extend(
            Cept.from_str(message.from_user.user_id.ljust(12)) + b' ' +
            Cept.from_str(message.from_user.ext.rjust(5, '0')))
        data_cept.extend(Cept.set_cursor(2, 41 - len(from_date)))
        data_cept.extend(Cept.from_str(from_date))
        data_cept.extend(Cept.repeat(" ", 4))
        data_cept.extend(Cept.from_str(message.from_user.org_name))
        data_cept.extend(Cept.set_cursor(3, 41 - len(from_time)))
        data_cept.extend(Cept.from_str(from_time))
        data_cept.extend(Cept.repeat(" ", 4))
        data_cept.extend(Cept.set_fg_color_simple(0))
        data_cept.extend(
            Cept.from_str(message.from_user.first_name) + b' ' +
            Cept.from_str(message.from_user.last_name))
        data_cept.extend(b'\r\n')
        data_cept.extend(Cept.repeat(" ", 4))
        data_cept.extend(Cept.from_str(from_street))
        data_cept.extend(b'\r\n')
        data_cept.extend(Cept.repeat(" ", 4))
        data_cept.extend(Cept.from_str(from_zip))
        data_cept.extend(b' ')
        data_cept.extend(Cept.from_str(from_city))
        data_cept.extend(b'\r\n')
        data_cept.extend(b'an  ')
        data_cept.extend(
            Cept.from_str(user.user_id.ljust(12)) + b' ' +
            Cept.from_str(user.ext.rjust(5, '0')))
        data_cept.extend(b'\r\n')
        data_cept.extend(Cept.repeat(" ", 4))
        data_cept.extend(
            Cept.from_str(user.first_name) + b' ' +
            Cept.from_str(user.last_name))
        data_cept.extend(b'\r\n\n')
        data_cept.extend(Cept.from_str(message.body()))
        data_cept.extend(Cept.set_cursor(23, 1))
        data_cept.extend(b'0')
        data_cept.extend(b'\x1b\x29\x20\x40'  # load DRCs into G1
                         b'\x1b\x7e'  # G1 into right charset
                         )
        data_cept.extend(Cept.from_str(" Gesamtübersicht"))
        data_cept.extend(Cept.repeat(" ", 22))

        user.messaging.mark_as_read(message.index)

        return (meta, data_cept)
Beispiel #7
0
    def create_article_page(sheet_number):
        is_first_page = sheet_number == 0

        if not RSS_UI.feed:
            RSS_UI.feed = feedparser.parse(
                "https://www.pagetable.com/?feed=rss2")

        entry = RSS_UI.feed["entries"][6]
        title = entry["title"]
        html = entry["content"][0]["value"]
        soup = BeautifulSoup(html, 'html.parser')

        page = Cept_page_from_HTML()
        page.soup = soup
        page.article_prefix = "XXX"
        page.insert_html_tags(soup.children)

        meta = {
            "clear_screen": True,
            "links": {
                "0": "0"
            },
            "publisher_color": 0
        }

        data_cept = bytearray()
        data_cept.extend(Cept.parallel_mode())

        if is_first_page:
            data_cept.extend(Cept.set_screen_bg_color(7))
            data_cept.extend(Cept.set_cursor(2, 1))
            data_cept.extend(Cept.set_line_bg_color(0))
            data_cept.extend(b'\n')
            data_cept.extend(Cept.set_line_bg_color(0))
            data_cept.extend(Cept.double_height())
            data_cept.extend(Cept.set_fg_color(7))
            data_cept.extend(Cept.from_str(title[:39]))
            data_cept.extend(b'\r\n')
            data_cept.extend(Cept.normal_size())
            data_cept.extend(b'\n')

        # print navigation
        # * on sheet 0, so we don't have to print it again on later sheets
        # * on the last sheet, because it doesn't show the "#" text
        # * on the second last sheet, because navigating back from the last one needs to show "#" again
        if sheet_number == 0 or sheet_number >= page.number_of_sheets() - 2:
            data_cept.extend(Cept.set_cursor(23, 1))
            data_cept.extend(Cept.set_line_bg_color(0))
            data_cept.extend(Cept.set_fg_color(7))
            data_cept.extend(Cept.from_str("0 < Back"))
            s = "# > Next"
            data_cept.extend(Cept.set_cursor(23, 41 - len(s)))
            if sheet_number == page.number_of_sheets() - 1:
                data_cept.extend(Cept.repeat(" ", len(s)))
            else:
                data_cept.extend(Cept.from_str(s))

        data_cept.extend(Cept.set_cursor(5, 1))

        # add text
        data_cept.extend(page.cept_for_sheet(sheet_number))

        return (meta, data_cept)
Beispiel #8
0
    def edit(self, skip_entry=False):
        start = True
        dct = False
        prefix = bytearray()
        inject_char = None

        while True:
            if start and not skip_entry:
                start = False
                self.print_hint()
                cept_data = bytearray()
                self.__y = 0
                if self.height > 1 or self.cursor_home:
                    cept_data.extend(Cept.set_cursor(self.line, self.column))
                    self.__x = 0
                else:
                    cept_data.extend(
                        Cept.set_cursor(self.line,
                                        self.column + len(self.string)))
                    self.__x = len(self.string)
                if self.fgcolor:
                    cept_data.extend(Cept.set_fg_color(self.fgcolor))
                if self.bgcolor:
                    cept_data.extend(Cept.set_bg_color(self.bgcolor))
                cept_data.extend(Cept.show_cursor())
                sys.stdout.buffer.write(cept_data)
                sys.stdout.flush()

            if skip_entry:
                sys.stderr.write("skipping\n")
                break

            if inject_char:
                c = inject_char
                inject_char = None
            else:
                c = Util.readchar()
            sys.stderr.write("In: " + hex(ord(c)) + "\n")

            if self.command_mode and ord(
                    c) == Cept.ini() and self.string[-1:] == chr(Cept.ini()):
                # exit command mode, tell parent to clear
                return (None, False)

            c2 = Cept.code_to_str(prefix + bytes([ord(c)]))
            if c2 is None:  # sequence not complete
                prefix.append(ord(c))
                continue
            prefix = bytearray()
            if c2 == "":  # we couldn't decode it
                continue
            c = c2

            # if c < 0x20
            #     c is a CEPT control code
            # if c >= 0x20
            #     c is Unicode

            if ord(c) < 0x20:  #and ord(c) != Cept.ini():
                prefix = bytearray()
                if ord(c) == Cept.ini():
                    if not self.command_mode:
                        is_editor_code = False
                        sys.stderr.write("entering command mode\n")
                        editor = Editor()
                        editor.line = 24
                        editor.column = 1
                        editor.height = 1
                        editor.width = 20
                        editor.string = chr(Cept.ini())
                        editor.command_mode = True
                        editor.clear_line = True
                        editor.echo_ter = True
                        editor.draw()
                        (val, dct) = editor.edit()
                        sys.stderr.write("exited command mode\n")
                        if val is None:  # "**" in command mode
                            self.string = ""
                            self.draw()
                        else:
                            Editor.debug_print(val)
                            if val.startswith(chr(Cept.ini()) +
                                              "02") and len(val) == 4:
                                # editor codes *021# etc.
                                is_editor_code = True
                                code = int(val[3:])
                                map = {
                                    1: "\r",  # CR
                                    2: "\x0b",  # UP
                                    4: "\x08",  # LEFT
                                    6: "\x09",  # RIGHT
                                    8: "\n",  # DOWN
                                    9: "\x1a"  # DCT
                                }
                                c = map.get(code)
                                if c is not None:
                                    inject_char = c
                                else:
                                    sys.stderr.write(
                                        "ignoring invalid editor code\n")
                            else:
                                # global code
                                if not self.no_navigation or val == chr(
                                        Cept.ini()) + "00" or val == chr(
                                            Cept.ini()) + "09":
                                    return (val, False)
                                sys.stderr.write("ignoring navigation\n")
                        start = True
                        continue
                elif ord(c) == Cept.ter():
                    if self.echo_ter:
                        sys.stdout.write("#")
                        sys.stdout.flush()
                    break
                elif ord(c) == Cept.dct():
                    dct = True
                    break
                self.insert_control_character(c)
            else:  # ord(c) >= 0x20
                character_legal = True
                string_legal = False
                # CEPT doesn't have a concept of backspace, so the backspace key
                # sends the sequence CSR_LEFT, SPACE, CSR_LEFT. It is very tricky
                # to detect this properly, so we will just allow spaces in
                # "number" and "alpha" input fields.
                if self.type == "number" and not c.isdigit() and not c == " ":
                    character_legal = False
                elif self.type == "alpha" and not c.isalpha() and not c == " ":
                    character_legal = False
                elif self.legal_values:
                    s = self.try_insert_character(c).rstrip()
                    character_legal = False
                    for legal_input in self.legal_values:
                        if s == legal_input:
                            character_legal = True
                            string_legal = True
                            #							sys.stderr.write("string_legal!\n")
                            break
                        elif legal_input.startswith(s):
                            character_legal = True
                            #							sys.stderr.write("character_legal!\n")
                            break
                if character_legal or self.end_on_illegal_character:
                    if self.insert_character(c):
                        if self.type == "password":
                            sys.stdout.write("*")
                        else:
                            sys.stdout.buffer.write(Cept.from_str(c))
                        sys.stdout.flush()
                if not character_legal and self.end_on_illegal_character:
                    break
                if string_legal and self.end_on_legal_string:
                    break
#			sys.stderr.write("self.__data:\n" + pprint.pformat(self.__data) + "\n")
#			sys.stderr.write("self.string:\n" + pprint.pformat(self.string) + "\n")

        return (self.string, dct)
Beispiel #9
0
	def create_login():
		meta = {
			"clear_screen": False,
			"links": {
			},
			"publisher_color": 7,
			"inputs": {
				"fields": [
					{
						"name": "user_id",
						"hint": "Teilnehmernummer oder # eingeben",
						"line": 18,
						"column": 26,
						"height": 1,
						"width": 10,
						"bgcolor": 12,
						"fgcolor": 3
					},
					{
						"name": "ext",
						"hint": "Mitbenutzer oder # eingeben",
						"line": 18,
						"column": 37,
						"height": 1,
						"width": 1,
						"bgcolor": 12,
						"fgcolor": 3,
						"type": "number",
						"cursor_home": True,
						"default": "1"
					},
					{
						"name": "password",
						"hint": "Nächstes Feld mit #; Leer für Gast",
						"line": 20,
						"column": 26,
						"height": 1,
						"width": 14,
						"bgcolor": 12,
						"fgcolor": 3,
						"type": "password",
						"validate": "call:Login_UI.callback_login"
					}
				],
				"confirm": False,
				"target": "page:000001a",
				"no_navigation": True
			}
		}

		data_cept = bytearray()
		data_cept.extend(Cept.parallel_mode())
		data_cept.extend(Cept.clear_screen())
		data_cept.extend(Cept.set_cursor(2, 1))
		data_cept.extend(Cept.set_screen_bg_color(12))
		data_cept.extend(Cept.set_fg_color(7))
		data_cept.extend(Login_UI.btx_logo())
		data_cept.extend(Cept.set_left_g3())
		data_cept.extend(Cept.set_fg_color(15))
		data_cept.extend(Cept.repeat("Q", 40))
		data_cept.extend(Cept.set_fg_color(7))
		data_cept.extend(Cept.set_left_g0())
		data_cept.extend(Cept.set_cursor(18, 8))
		data_cept.extend(Cept.from_str("Teilnehmer"))
		data_cept.extend(Cept.set_cursor(18, 25))
		data_cept.extend(b":")
		data_cept.extend(Cept.set_cursor(18, 36))
		data_cept.extend(Cept.set_fg_color(3))
		data_cept.extend(b'-')
		data_cept.extend(Cept.set_fg_color(7))
		data_cept.extend(Cept.set_cursor(20, 8))
		data_cept.extend(Cept.from_str("persönl. Kennwort:"))
		data_cept.extend(b'\r\n')
		data_cept.extend(Cept.set_left_g3())
		data_cept.extend(Cept.set_fg_color(15))
		data_cept.extend(Cept.repeat("Q", 40))
		return (meta, data_cept)