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 create_page(pageid): ret = None # generated pages if pageid.startswith("00000") or pageid == "9a": # login ret = Login_UI.create_page(User.user(), pageid) basedir = PATH_DATA + "00000/" if not ret and (pageid.startswith("71") or pageid.startswith("78")): # historic page overview ret = Historic_UI.create_page(User.user(), pageid) basedir = PATH_DATA + "8/" if not ret and pageid.startswith("7"): # user management ret = User_UI.create_page(User.user(), pageid) basedir = PATH_DATA + "7/" if not ret and pageid.startswith("8"): # messaging ret = Messaging_UI.create_page(User.user(), pageid) basedir = PATH_DATA + "8/" if not ret and pageid.startswith("55"): # wikipedia basedir = PATH_DATA + "55/" ret = MediaWiki_UI.create_page(pageid, basedir) if not ret and pageid.startswith("35"): # Congress Wiki basedir = PATH_DATA + "55/" ret = MediaWiki_UI.create_page(pageid, basedir) if not ret and pageid.startswith("45"): # c64 wiki basedir = PATH_DATA + "45/" ret = MediaWiki_UI.create_page(pageid, basedir) if not ret and pageid.startswith("666"): # images ret = Image_UI.create_page(pageid) basedir = PATH_DATA + "55/" if not ret and pageid.startswith("6502"): # RSS basedir = PATH_DATA + "55/" ret = RSS_UI.create_page(pageid, basedir) if ret: (meta, data_cept) = ret else: basedir = None data_cept = None for dir in [ "", "hist/10/", "hist/11/" ]: for i in reversed(range(0, len(pageid))): testdir = PATH_DATA + dir + pageid[:i+1] if os.path.isdir(testdir): filename = pageid[i+1:] sys.stderr.write("filename: '" + filename + "'\n") basedir = testdir + "/" break if basedir: filename_meta = basedir + filename + ".meta" filename_cept = basedir + filename + ".cept" filename_cm = basedir + filename + ".cm" if os.path.isfile(filename_meta): with open(filename_meta) as f: meta = json.load(f) if os.path.isfile(filename_cept): with open(filename_cept, mode='rb') as f: data_cept = f.read() elif os.path.isfile(filename_cm): data_cept = CM.read(filename_cm) break if data_cept is None: return None try: with open(basedir + "a.glob") as f: glob = json.load(f) meta.update(glob) # combine dicts, glob overrides meta except: pass cept_1 = bytearray() cept_1.extend(Cept.hide_cursor()) if meta.get("clear_screen", False): cept_1.extend(Cept.serial_limited_mode()) cept_1.extend(Cept.clear_screen()) last_filename_include = "" sys.stderr.write("Clear Screen\n"); cept_1.extend(create_preamble(basedir, meta)) cept_2 = bytearray() if meta.get("cls2", False): cept_2.extend(Cept.serial_limited_mode()) cept_2.extend(Cept.clear_screen()) last_filename_include = "" # header if the data is actually there, if not ignore this try: hf = headerfooter(pageid, meta["publisher_name"], meta["publisher_color"]) cept_2.extend(hf) except: pass if meta.get("parallel_mode", False): cept_2.extend(Cept.parallel_mode()) # payload cept_2.extend(data_cept) cept_2.extend(Cept.serial_limited_mode()) # footer if it exists try: cept_2.extend(hf) except: pass cept_2.extend(Cept.sequence_end_of_page()) inputs = meta.get("inputs") return (cept_1, cept_2, meta["links"], inputs, meta.get("autoplay", False))