def tuiWritePost(stdscr, width, height, tui_klub_id): try: stdscr.refresh() curses.cbreak() stdscr.addstr(0, 3, "Tvuj prispevek: [ alt+1 napoveda sl ]") footer = "-=[ klavesy: CTRL+G (odesli), CTRL+X (zrus), ALT+1 ]=-" if len(footer) >= width - 1: footer = "-=[ ^G, ^X, ALT+1 ]=-" stdscr.addstr(height - 1, 0, footer) height, width = stdscr.getmaxyx() x = 2 y = 2 h = height - y w = width - x rectangle(stdscr, y - 1, x - 1, h, w) editwin = curses.newwin(h - 1 - 1, w - 2, y, x) stdscr.refresh() box = inputBox(editwin) text = box.edit(None, "YES") try: if (text != ""): curses.nocbreak() orig_text = text tmp = orig_text.strip().split('\n') text = "" for i in tmp: text += i if (len(i) != width - 4): text += '\n' if (nyx_send_message(tui_klub_id, text) == 0): stdscr.addstr(0, 0, " " * width) stdscr.addstr( 0, 0, "*** Prispevek odeslan do klubu: " + sutf8(str(tui_klub_id))) else: stdscr.addstr(0, 0, " " * width) stdscr.addstr( 0, 0, "! Chyba pri odesilani prispevku do klubu") #stdscr.getch() ugetch(stdscr) curses.cbreak() except Exception: stdscr.addstr(0, 0, "Nepodarilo se odeslat prispevek") traceback.print_exc(file=sys.stdout) ugetch(stdscr) stdscr.refresh() stdscr.clear() except Exception: traceback.print_exc(file=sys.stdout) input("Zmackni Enter ...") print("Problem pri ziskani cisla klubu.")
def tuiMail(): screen = curses.initscr() height, width = screen.getmaxyx() msgDisplayed = 0 tmp = [] strings = [] nyx_list_mail() tmp = getMail() row_num = len(strings) strings = tmp curses.noecho() curses.cbreak() curses.start_color() screen.keypad(1) curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_MAGENTA) highlightText = curses.color_pair(1) normalText = curses.A_NORMAL max_row = height - 2 box = curses.newwin(max_row + 2, width, 0, 0) pages = int(ceil(row_num / max_row)) last_pos = 1 last_page = 1 position = last_pos page = last_page for i in range(1, len(strings)): if (i + (max_row * (page - 1)) == position + (max_row * (page - 1))): box.addstr(i - (max_row * (page - 1)), 0, actual_char + " " + cleanHtml(sutf8(strings[i - 1])), highlightText) else: box.addstr(i - (max_row * (page - 1)), 0, " " + cleanHtml(sutf8(strings[i - 1])), normalText) if i == max_row: break mm_footer_help = "-=[ pohyb: j,k,ENTER ]=-" box.addstr(height - 1, 0, mm_footer_help) screen.refresh() box.refresh() tuiMailDisplayed = 0 x = screen.getch() while x != 113: # dokud neni stisknuta klavesa 'q' if (tuiMailDisplayed == 0): if x == curses.KEY_DOWN or x == ord('j'): if page == 1: if position < i: position = position + 1 else: if pages > 1: page = page + 1 position = 1 + (max_row * (page - 1)) elif page == pages: if position < row_num: position = position + 1 else: if position < max_row + (max_row * (page - 1)): position = position + 1 else: page = page + 1 position = 1 + (max_row * (page - 1)) elif x == ord("f"): screen.clear() screen.refresh() curses.cbreak() screen.addstr(1, 3, "Vyhledat dopisy od: [ ctrl+g pro odeslani ]") x = 4 y = 4 h = 1 w = 25 rectangle(screen, x - 1, y - 1, h + x + 1, w + y + 1) editwin = curses.newwin(h, w, x, y) screen.refresh() searchBox = inputBox(editwin) searchBox.edit() text = searchBox.gather() if (text != ""): nyx_filter_mail(text, "") tmp = getMail() row_num = len(strings) strings = tmp elif x == curses.KEY_UP or x == ord('k'): if page == 1: if position > 1: position = position - 1 else: if position > (1 + (max_row * (page - 1))): position = position - 1 else: page = page - 1 position = max_row + (max_row * (page - 1)) elif x == curses.KEY_LEFT or x == ord('h'): if page > 1: page = page - 1 position = 1 + (max_row * (page - 1)) elif x == curses.KEY_RIGHT or x == ord('l'): if page < pages: page = page + 1 position = (1 + (max_row * (page - 1))) elif x == ord("\n") and position != 0: displayMail(screen, strings, position, width, height) tuiMailDisplayed = 1 elif tuiMailDisplayed == 1: if x == ord("q"): tuiMailDisplayed = 0 elif x in (curses.KEY_LEFT, ord('h')): if position < len(strings): position += 1 displayMail(screen, strings, position, width, height) elif x in (curses.KEY_RIGHT, ord('l')): if position > 1: position -= 1 displayMail(screen, strings, position, width, height) elif x == ord("o"): # O - odpovez screen.clear() screen.refresh() curses.cbreak() msg_id = getCurrentMsgId(strings, position) msg_content = getMailContent(msg_id) msg_recepient = msg_content[0][0] screen.addstr(0, 2, "Zadej zpravu pro " + msg_recepient + ":") #footer="pos " + str(position) + " page " + str(page) + " mr " + str(max_row) + " row_num " + str(row_num) + " | -=[ ctlr+G - posli, ctrl+X - zrus ]=-" footer = "-=[ ctlr+G - posli, ctrl+X - zrus ]=-" screen.addstr(height - 1, 0, footer) height, width = screen.getmaxyx() x = 2 y = 2 h = height - y w = width - x rectangle(screen, y - 1, x - 1, h, w) editwin = curses.newwin(h - 2, w - 2, y, x) screen.refresh() mailBox = inputBox(editwin) text = mailBox.edit() curses.nocbreak() if (text != ""): #text=cleanHtml(text) text = mailPrepareText(text, width, height) if (nyx_send_mail(msg_recepient, text) == 0): screen.addstr(0, 0, " " * width) screen.addstr( 0, 0, "*** Dopis pro " + msg_recepient + " odeslan.") else: screen.addstr(0, 0, " " * width) screen.addstr(0, 0, "! Chyba pri odesilani dopisu") x = ugetch(screen) else: screen.addstr(0, 0, " " * width) screen.addstr(0, 2, "Zprava zrusena, stiskni ENTER ...") x = ugetch(screen) curses.cbreak() tuiMailDisplayed = 0 nyx_list_mail() tmp = getMail() row_num = len(strings) strings = tmp if tuiMailDisplayed == 0: box.erase() for i in range(1, len(strings)): if (i + (max_row * (page - 1)) == position + (max_row * (page - 1))): box.addstr( i - (max_row * (page - 1)), 0, actual_char + " " + cleanHtml(sutf8(strings[i - 1])), highlightText) else: box.addstr(i - (max_row * (page - 1)), 0, " " + cleanHtml(sutf8(strings[i - 1])), normalText) if i == max_row: break box.addstr(height - 1, 0, mm_footer_help) screen.refresh() box.refresh() x = screen.getch() curses.endwin()
def fBrowser(strings, last_pos, last_page): #def fBrowser(): screen = curses.initscr() curses.start_color() curses.noecho() row_num = len(strings) height, width = screen.getmaxyx() tmp = [] for i in strings: tmp.append(i[:width - 4]) strings = tmp curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_CYAN) hiTe = curses.color_pair(1) noTe = curses.A_NORMAL max_row = height - 1 box = curses.newwin(max_row + 2, width, 0, 0) #box.box() pages = int(ceil(row_num / max_row)) position = last_pos page = last_page screen.refresh() box.refresh() x = None page = 0 while x != ord('q'): # dokud neni stisknuta klavesa 'q' if x == curses.KEY_DOWN or x == ord('j'): if (position % max_row < max_row - 1 and position < row_num - 1): position = position + 1 elif x == curses.KEY_UP or x == ord('k'): if (position % max_row > 0 and position > 0): position = position - 1 elif x == curses.KEY_LEFT or x == ord('h'): if (page > 0): page -= 1 position = max_row * page + max_row - 1 elif x == curses.KEY_RIGHT or x == ord('l'): if (page < pages - 1): page += 1 position = max_row * page elif x == ord('r'): dir = str(getConfig('soubory')[0][0]) os.chdir(dir) strings = ls('.', 'py') pages = int(ceil(row_num / max_row)) row_num = len(strings) position = 0 page = 0 elif x == ord('d'): y = None dir = str(getConfig('soubory')[0][0]) while y != ord('\n'): box.addstr(height - 1, 0, (" " * (width - 1))) box.addstr(height - 1, 0, "Directory: " + str(dir)) screen.refresh() box.refresh() y = screen.getch() if y in (curses.KEY_BACKSPACE, 263, 127): dir = dir[:-1] else: dir += chr(y) if (len(dir) > 0): dir = dir[:-1] updateConfig('soubory', dir) strings = ls(dir, '') pages = int(ceil(row_num / max_row)) row_num = len(strings) position = 0 page = 0 elif x == ord('f'): y = None filter = "" while y != ord('\n'): box.addstr(height - 1, 0, (" " * (width - 1))) box.addstr(height - 1, 0, "Filter: " + str(filter)) screen.refresh() box.refresh() y = screen.getch() if y in (curses.KEY_BACKSPACE, 263, 127): filter = filter[:-1] else: filter += chr(y) if (len(filter) > 0): filter = filter[:-1] tmp = [] for i in strings: if filter in i: tmp.append(i) strings = tmp if filter == "": strings = ls('.', '') pages = int(ceil(row_num / max_row)) row_num = len(strings) position = 0 page = 0 elif x == ord("\n"): screen.erase() if not (strings[position] is None and position < row_num): return (strings[position]) else: return (None) box.erase() shift = page * max_row for i in range(0, max_row): if row_num == 0: box.addstr(1, 1, "Zadna data.", hiTe) elif i + shift == row_num: break else: if (i + shift == position): box.addstr( i, 2, actual_char + " " + sutf8(strings[i + shift][:width - 5]), hiTe) else: box.addstr(i, 2, " " + sutf8(strings[i + shift][:width - 5]), noTe) footer = "-=[ Keys: j,k,l,h,q,f,r,d,ENTER shift: " + str( shift) + " i: " + str(i) + " pos: " + str(position) + "]=-" if (len(footer) >= height - 1): footer = "-=[ Keys: j,k,l,h,q,f,r,d,ENTER ]=-" box.addstr(height - 1, 0, footer, noTe) screen.refresh() box.refresh() x = screen.getch()
def draw_menu(stdscr): global tui_klub_id k = 0 cursor_x = 0 cursor_y = 0 encoding = locale.getpreferredencoding() locale.setlocale(locale.LC_ALL, '') stdscr = curses.initscr() # Clear and refresh the screen for a blank canvas stdscr.clear() stdscr.refresh() # Start colors in curses curses.start_color() curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) klub_strana = 1 # Loop where k is the last character pressed while (k != ord('q')): # RODICOVSKY ZAMEK rodzam = getParentalLockStatus() #print(str(rodzam)) if (rodzam == 1): rodzamkl = getParentalLockClub() conyxDBLast(rodzamkl) tui_klub_id = rodzamkl # Initialization stdscr.clear() height, width = stdscr.getmaxyx() tui_klub_id = getLastVisitedClub() club_changed = 0 if rodzam == 1: if k == ord("0"): # k - konfigurace tuiConfig() elif k == ord("c") or k == ord("\n"): # C - cti prispevky zobrazDiskuzi(str(tui_klub_id), stdscr, 1) stdscr.clear() elif k == ord("p"): # P - pis try: stdscr.refresh() curses.cbreak() stdscr.addstr( 0, 3, "Tvuj novy prispevek: [ ctrl+g nebo zaplneni okenka pro odeslani ]" ) height, width = stdscr.getmaxyx() x = 2 y = 2 h = height - y w = width - x rectangle(stdscr, x - 1, y - 1, h + 1, w) editwin = curses.newwin(h - 1, w - 2, x, y) stdscr.refresh() #box=Textbox(editwin) box = inputBox(editwin) box.edit() text = box.gather() try: if (text != ""): text = text[:-1] curses.nocbreak() orig_text = text tmp = orig_text.strip().split('\n') text = "" for i in tmp: text += i if (len(i) != width - 4): text += '\n' nazev_klubu = nactiNazevKlubu(tui_klub_id)[:width - 1] if (nyx_send_message(tui_klub_id, text) == 0): stdscr.addstr(0, 0, " " * width) stdscr.addstr( 0, 0, "*** Prispevek odeslan do klubu: " + sutf8(str(tui_klub_id)) + " " + nazev_klubu) else: stdscr.addstr(0, 0, " " * width) stdscr.addstr( 0, 0, "! Chyba pri odesilani prispevku do klubu" + nazev_klubu) #stdscr.getch() x = ugetch(stdscr) curses.cbreak() except Exception: stdscr.addstr(0, 0, "Nepodarilo se odeslat prispevek") #traceback.print_exc(file=sys.stdout) #stdscr.getch() x = ugetch(stdscr) stdscr.refresh() stdscr.clear() except Exception: traceback.print_exc(file=sys.stdout) input("Zmackni Enter ...") print("Problem pri ziskani cisla klubu.") else: if k == curses.KEY_DOWN: cursor_y = cursor_y + 1 elif k == ord("0"): # k - konfigurace tuiConfig() elif k == ord("1"): # 1 - napoveda tuiFile("napoveda.txt") elif k == ord("m"): # m - ozna(m)eni curses.endwin() nyx_feed_notices() stdscr.clear() elif k == curses.KEY_UP: cursor_y = cursor_y - 1 elif k == curses.KEY_RIGHT: cursor_x = cursor_x + 1 elif k == curses.KEY_LEFT: cursor_x = cursor_x - 1 elif k == ord("z"): # Z - zmeny try: tuiFile("CHANGELOG") except Exception: print("Nemuzu zobrazit seznam zmen.") elif k == ord("n"): # N - neprectene kluby retVal = tuiMainMenu(1) if (retVal): tui_klub_id = retVal conyxDBLast(tui_klub_id) club_changed = 1 klub_strana = 1 stdscr.clear() elif k == ord("r"): # R - kluby s reakci retVal = tuiMainMenu(2) if (retVal): tui_klub_id = retVal conyxDBLast(tui_klub_id) club_changed = 1 klub_strana = 1 stdscr.clear() elif k == ord("h"): # H - historie retVal = tuiMainMenu(4) #retVal=nyx_bookmarks_history() if (retVal): tui_klub_id = retVal conyxDBLast(tui_klub_id) club_changed = 1 klub_strana = 1 stdscr.clear() elif k == ord("s"): # S - sledovane retVal = tuiMainMenu(0) if (retVal): tui_klub_id = retVal conyxDBLast(tui_klub_id) club_changed = 1 stdscr.clear() elif k == ord("c") or k == ord("\n"): # C - cti prispevky zobrazDiskuzi(str(tui_klub_id), stdscr, 1) stdscr.clear() elif k == ord("o"): # O - cti predchozi od nejstarsiho prispevku res = conyxDBQuery( 'select min(id_prispevek) prid from prispevek_cache') ret = zobrazDiskuzi(str(tui_klub_id), stdscr, 1, res[1][0][0], "older") res_aft = conyxDBQuery( 'select min(id_prispevek) prid from prispevek_cache') if (res != res_aft): klub_strana += 1 stdscr.clear() elif k == ord("w"): # W - vyhledej writeup na celem Nyxu stdscr.addstr(0, 1, "Hledej na celem Nyxu:") footer = "-=[ klavesy: CTRL+G odeslat, CTRL+X zrusit ]=-" if (len(footer) >= height - 1): footer = "-=[ ^G, ^X ]=-" stdscr.addstr(height - 1, 0, footer) x = 1 y = 1 h = height - 3 w = width - 3 rectangle(stdscr, y, x, y + h, x + w) editwin = curses.newwin(h - 1, w - 1, y + 1, x + 1) stdscr.refresh() #box=Textbox(editwin) box = inputBox(editwin) box.edit() text = box.gather() if text != "": #print("TEXT: "+text) #stdscr.getch() rx, res = nyx_search_writeups(None, text, None) buffer = [] for i in res["data"]: buffer.append(i["klub_jmeno"] + "|" + i["nick"] + "|" + cleanhtml(i["content"])) tuiBuffer("Vysledek hledani", buffer) else: stdscr.clear() elif k == ord("v"): # V - vyhledat klicove slovo stdscr.addstr(0, 1, "Hledej v diskuzi:") footer = "-=[ klavesy: CTRL+G odeslat, CTRL+X zrusit ]=-" if (len(footer) >= height - 1): footer = "-=[ ^G, ^X ]=-" stdscr.addstr(height - 1, 0, footer) x = 1 y = 1 h = height - 3 w = width - 3 rectangle(stdscr, y, x, y + h, x + w) editwin = curses.newwin(h - 1, w - 1, y + 1, x + 1) stdscr.refresh() box = inputBox(editwin) box.edit() text = box.gather() if text is not None and text != "": ret = zobrazDiskuzi(str(tui_klub_id), stdscr, 1, None, None, None, text) stdscr.clear() elif k == ord("l"): # B - vyhledat prispevky uzivatele stdscr.addstr(0, 1, "Hledej prispevky uzivatele:") footer = "-=[ klavesy: CTRL+G odeslat, CTRL+X zrusit ]=-" if (len(footer) >= height - 1): footer = "-=[ ^G, ^X ]=-" stdscr.addstr(height - 1, 0, footer) x = 1 y = 1 h = height - 3 w = width - 3 rectangle(stdscr, y, x, y + h, x + w) editwin = curses.newwin(h - 1, w - 1, y + 1, x + 1) stdscr.refresh() #box=Textbox(editwin) box = inputBox(editwin) box.edit() text = box.gather() if text != "": ret = zobrazDiskuzi(str(tui_klub_id), stdscr, 1, None, None, text) stdscr.clear() elif k == ord( "e"): # U - cti nasledujici od nejnovejsiho prispevku res = conyxDBQuery( 'select max(id_prispevek) prid from prispevek_cache') ret = zobrazDiskuzi(str(tui_klub_id), stdscr, 1, res[1][0][0], "newer") if (klub_strana > 1): klub_strana -= 1 stdscr.clear() elif k == ord("p"): # P - pis tuiWritePost(stdscr, width, height, tui_klub_id) elif k == ord("i"): # I - informace ze zahlavi klubu retVal = nyx_disc_header_desc(str(tui_klub_id)) if (retVal): linelen = width - 1 stdscr.addstr( 0, 0, sutf8(cleanHtml( nactiNazevKlubu(tui_klub_id)))[:linelen], curses.color_pair(1)) lineno = 0 for i in range(0, len(retVal[0]), linelen): stdscr.addstr( lineno + 1, 0, sutf8(cleanHtml(retVal[0]))[i:(i + linelen)]) lineno += 1 if lineno > height - 2: break stdscr.addstr(height - 1, 0, "-=[ q - zpatky ]=-") else: stdscr.addstr(0, 0, sutf8("Bez zahlavi")) stdscr.refresh() #stdscr.getch() ugetch(stdscr) stdscr.clear() elif k == ord("f"): # F - odesli soubor dir = str(getConfig('soubory')[0][0]) strings = ls(dir, '') sel = fBrowser(strings, 0, 0) if (not (sel is None)): stdscr.refresh() curses.cbreak() header = "Text k souboru:" height, width = stdscr.getmaxyx() footer = "-=[ klavesy: CTRL+G odeslat, CTRL+X zrusit ]=-" if len(footer) >= width - 1: footer = "-=[ ^G, ^X, ALT+1 ]=-" stdscr.addstr(0, 2, header) stdscr.addstr(height - 1, 0, footer) x = 2 y = 2 h = height - y w = width - x rectangle(stdscr, y - 1, x - 1, h, w) editwin = curses.newwin(h - 1 - 1, w - 2, y, x) stdscr.refresh() box = inputBox(editwin) text = box.edit() stdscr.clear() nazev_klubu = nactiNazevKlubu(tui_klub_id)[:width - 1] if (nyx_send_message(tui_klub_id, text, sel) == 0): stdscr.addstr(0, 0, " " * width) stdscr.addstr( 0, 0, "*** Prispevek se souborem odeslan do klubu: " + sutf8(str(tui_klub_id)) + " " + nazev_klubu) else: stdscr.addstr(0, 0, " " * width) stdscr.addstr( 0, 0, "! Chyba pri odesilani prispevku se souborem do klubu " + nazev_klubu) stdscr.refresh() x = ugetch(stdscr) elif k == ord("d"): # D - dopisy tuiMail() elif k == ord("k"): # K - klub try: stdscr.refresh() curses.cbreak() stdscr.addstr(1, 3, "Vyber klub (cislo):") stdscr.addstr(height - 1, 0, "-=[ klavesy: CTRL+G, CTRL+X ]=-") x = 4 y = 4 h = 1 w = 12 rectangle(stdscr, x - 1, y - 1, h + x + 1, w + y + 1) editwin = curses.newwin(h, w, x, y) stdscr.refresh() #box=Textbox(editwin) box = inputBox(editwin) box.edit() text = box.gather() try: if (text != ""): tui_klub_id = int(text) conyxDBLast(tui_klub_id) conyxDBSetForumLast(tui_klub_id) except Exception: stdscr.addstr(0, 0, "Neplatny vyber klubu") traceback.print_exc(file=sys.stdout) #stdscr.getch() ugetch(stdscr) klub_strana = 1 stdscr.refresh() stdscr.clear() except Exception: traceback.print_exc(file=sys.stdout) input("Zmackni Enter ...") print("Problem pri ziskani cisla klubu.") rodzam = getParentalLockStatus() stdscr.refresh() stdscr.clear() cursor_x = max(0, cursor_x) cursor_x = min(width - 1, cursor_x) cursor_y = max(0, cursor_y) cursor_y = min(height - 1, cursor_y) # Declaration of strings start_y = int((height // 2) - 8) if (rodzam == 1): title = "klávesa c - čti" start_x_title = int((width // 2) - (len(title) // 2) - len(title) % 2) stdscr.addstr(start_y, start_x_title, sutf8(title)) subtitle = "klávesa p - piš" stdscr.addstr(start_y + 2, start_x_title, sutf8(subtitle)) else: title = "C O N Y X"[:width - 1] subtitle = "CONSOLE NYX CLIENT"[:width - 1] #keystr = "Posledni klavesa: {}".format(k)[:width-1] + " KLUB: " + str(tui_klub_id) + " str.: " + str(klub_strana) keystr = " KLUB [" + str(klub_strana) + "] : " + str(tui_klub_id) nazev_klubu = nactiNazevKlubu(tui_klub_id)[:width - 1] pre_sbar = "(q)uit |" post_sbar = "| (1) napoveda" fill_len = width - 1 - len(pre_sbar) - len(post_sbar) statusbarstr = pre_sbar + ("_" * fill_len) + post_sbar sun = "Slunce: " + str(sunrise().strftime("%H.%M")) + "-" + str( sunset().strftime("%H.%M")) moon = "Měsíc: " + str(moon_phase()) zodnow = datetime.datetime.now().strftime("%Y-%m-%d") name_zodiac = "Zvěrokruh: " + str(zodiac(zodnow)) today = datetime.datetime.now().strftime("%d.%m.") day = hlp_day(datetime.datetime.now().strftime("%w")) name_date = datetime.datetime.now().strftime("%m-%d") name_day_name = hlp_nday_qry( "select name from jmeniny where date = '%s'" % name_date) name_day = "Dnes je " + day + " " + today + " a svátek má " + name_day_name[ 0][0] credits = "MMXVIII-MMXX" if k == 0: credits = "MMXVIII-MMXX" keystr = " KLUB [" + str(klub_strana) + "] : " + str( tui_klub_id) # Centering calculations start_x_title = int((width // 2) - (len(title) // 2) - len(title) % 2) start_x_subtitle = int((width // 2) - (len(subtitle) // 2) - len(subtitle) % 2) start_x_keystr = int((width // 2) - (len(keystr) // 2) - len(keystr) % 2) start_x_credits = int((width // 2) - (len(credits) // 2) - len(credits) % 2) start_x_nazev_klubu = int((width // 2) - (len(nazev_klubu) // 2) - len(nazev_klubu) % 2) start_x_sun = int((width // 2) - (len(sun) // 2) - len(sun) % 2) start_x_moon = int((width // 2) - (len(moon) // 2) - len(moon) % 2) start_x_zodiac = int((width // 2) - (len(name_zodiac) // 2) - len(name_zodiac) % 2) start_x_name_day = int((width // 2) - (len(name_day) // 2) - len(name_day) % 2) # Render status bar stdscr.attron(curses.color_pair(3)) stdscr.addstr(height - 1, 0, sutf8(statusbarstr)) stdscr.addstr(height - 1, len(statusbarstr), " " * (width - len(statusbarstr) - 1)) stdscr.attroff(curses.color_pair(3)) # Turning on attributes for title stdscr.attron(curses.color_pair(2)) stdscr.attron(curses.A_BOLD) # Rendering title #stdscr.addstr(start_y, start_x_title, sutf8(title)) # Print rest of text stdscr.addstr( start_y, start_x_title, sutf8(title), ) # Turning off attributes for the rest stdscr.attroff(curses.color_pair(2)) stdscr.attroff(curses.A_BOLD) stdscr.addstr(start_y + 2, start_x_keystr, sutf8(keystr)) stdscr.addstr(start_y + 4, start_x_nazev_klubu, sutf8(nazev_klubu)) stdscr.addstr(start_y + 6, start_x_sun, sutf8(sun)) stdscr.addstr(start_y + 8, start_x_moon, sutf8(moon)) stdscr.addstr(start_y + 10, start_x_name_day, sutf8(name_day)) stdscr.addstr(start_y + 12, start_x_zodiac, sutf8(name_zodiac)) stdscr.move(cursor_y, cursor_x) # Refresh the screen stdscr.refresh() # Wait for next input #k = stdscr.getch() k = ugetch(stdscr)
def tuiMainMenu(typ_klubu=0): global tui_klub_id nr, buf = nyx_list_disc("", 0) # stahni zahlavi klubu strings = [] screen = curses.initscr() curses.noecho() curses.cbreak() curses.start_color() screen.keypad(1) curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_CYAN) global width global height height, width = screen.getmaxyx() last_pos = 1 last_page = 1 encoding = locale.getpreferredencoding() locale.setlocale(locale.LC_ALL, '') code = locale.getpreferredencoding() x = "" pages = 0 page = 0 row_num = 0 smode = 0 try: if 1 == 1: # last_pos!=0 and row_num>0: highlightText = curses.color_pair(1) normalText = curses.A_NORMAL max_row = height - 2 box = curses.newwin(height, width, 0, 0) pages = int(ceil(row_num / max_row)) position = last_pos page = last_page search_substr = "" # POKUS NACIST KLUBY PRED KAZDYM NAVRATEM Z KLUBU while x != ord('q'): # neni stisknuta klavesa 'q' if typ_klubu == 1: cols, rows = conyxDBQuery( "select id_klub, id_klub||'|'||jmeno||'|'||unread||'|'||replies txt from klub_cache where unread != '0' order by jmeno asc" ) #box.addstr(0,0,"Nacten seznam neprectenych klubu") elif typ_klubu == 2: cols, rows = conyxDBQuery( "select id_klub, id_klub||'|'||jmeno||'|'||unread||'|'||replies txt from klub_cache where unread != '0' and replies != '0' order by jmeno asc" ) elif typ_klubu == 3: cols, rows = conyxDBQuery( "select distinct id_klub, id_klub||'|'||jmeno||'|'||unread||'|'||replies txt from klub_cache, last where last.forum_id = klub_cache.id_klub" ) elif typ_klubu == 4: cols, rows = nyx_bookmarks_history() else: cols, rows = conyxDBQuery( "select id_klub, id_klub||'|'||jmeno||'|'||unread||'|'||replies txt from klub_cache order by jmeno asc" ) box.erase() strings = [] refs = [] ret = 0 row_num = len(strings) for i in rows: strings.append(cleanHtml(i[1].replace('\n', ' '))) refs.append(i[0]) row_num = len(strings) tmp = [] refs_tmp = [] try: if (len(search_substr) > 0): for i in strings: if (search_substr.upper() in strip_accents(i).upper()): tmp.append(i[:width - 3]) else: for i in strings: tmp.append(i[:width - 3]) except Exception as e: #curses.endwin() traceback.print_exc(file=sys.stdout) print("Problem s textovym uzivatelskym rozhranim") print("Na strance: " + str(page)) #height,width=screen.getmaxyx() row_num = len(tmp) strings = tmp # highlightText=curses.color_pair(1) pages = int(ceil(row_num / max_row)) footer = "pos " + str(position) + " page " + str( page ) + " mr " + str(max_row) + " row_num " + str( row_num ) + " | -=[ f - vyhledej, j,k,l,h - pohyb, q - zpet, p - pis ]=-" if len(footer) >= width - 1: footer = "-=[ f hledej, j,k,l,h pohyb, p pis, q zpet ]=-" box.addstr(height - 1, 0, footer) for i in range(1 + (max_row * (page - 1)), max_row + 1 + (max_row * (page - 1))): if row_num == 0: if typ_klubu == 1: box.addstr(1, 0, "Zadny dalsi neprecteny klub.", highlightText) elif typ_klubu == 2: box.addstr(1, 0, "Zadny dalsi klub s reakci.", highlightText) else: box.addstr(1, 0, "Zadna data.", highlightText) else: if (i + (max_row * (page - 1)) == position + (max_row * (page - 1))): box.addstr( i - (max_row * (page - 1)), 0, actual_char + " " + cleanHtml(sutf8(strings[i - 1])), highlightText) else: box.addstr(i - (max_row * (page - 1)), 0, " " + cleanHtml(sutf8(strings[i - 1])), normalText) if i == row_num: break search_str = "Hledat: " + str(search_substr) box.addstr(0, 2, search_str) # y,x screen.refresh() box.refresh() x = ugetch(screen) ret = 0 try: if x in ( curses.KEY_DOWN, ord('j') ) and smode == 0 and position < row_num: # j - down if position < max_row + (max_row * (page - 1)): position = position + 1 else: if page <= pages: page = page + 1 position = 1 + (max_row * (page - 1)) elif x in (curses.KEY_UP, ord('k') ) and smode == 0 and position > 1: # k - up if position > 1 + (max_row * (page - 1)): position = position - 1 else: page = page - 1 position = max_row + (max_row * (page - 1)) elif x in (curses.KEY_LEFT, ord('h'), ord('u')) and smode == 0: # h - left if page > 1: page = page - 1 position = 1 + (max_row * (page - 1)) elif x in (curses.KEY_RIGHT, ord('l'), ord('n')) and smode == 0: # l - right if page < pages: page = page + 1 position = 1 + (max_row * (page - 1)) elif x == ord("f"): smode = 1 # TURN ON SEARCH MODE elif x in (curses.KEY_BACKSPACE, 263, 127) and smode == 1: # backspace if (len(search_substr) > 0): search_substr = search_substr[:-1] elif x == ord("\n"): if (len(strings) > 0 and row_num != 0): screen.erase() strings_split = strings[position - 1].split("|") try: ret = int(strings_split[0]) except Exception as e: ret = 1 else: if (smode == 1): try: search_substr += chr(x) except Exception as e: traceback.print_exc(file=sys.stdout) print( "Problem s textovym uzivatelskym rozhranim" ) print("Stisknuta klavesa " + str(ord(x))) #height,width=screen.getmaxyx() curses.endwin() #screen.getch() ugetch(screen) except Exception as e: traceback.print_exc(file=sys.stdout) print("Problem s textovym uzivatelskym rozhranim") print("Stisknuta klavesa " + str(ord(x))) if ret != 0: tui_klub_id = ret conyxDBLast(tui_klub_id) conyxDBSetForumLast(tui_klub_id) zobrazDiskuzi(str(tui_klub_id), screen, 1) screen.clear() #return(tui_klub_id) else: screen.addstr(0, 0, "Nemas zadne neprectene kluby.") #screen.getch() ugetch(screen) curses.endwin() except Exception: curses.endwin() traceback.print_exc(file=sys.stdout) print("Problem s textovym uzivatelskym rozhranim") print("Na strance: " + str(page)) input("Stiskni klavesu...")
def hlp_ytb_dialog(strings=""): screen = curses.initscr() curses.start_color() curses.noecho() row_num = len(strings) height, width = screen.getmaxyx() row_num = len(strings) height, width = screen.getmaxyx() curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_CYAN) hiTe = curses.color_pair(1) noTe = curses.A_NORMAL max_row = height - 3 box = curses.newwin(max_row - 1, width - 4, 2, 2) screen.refresh() box.refresh() x = None page = 0 shift = 0 position = 0 while x != ord('q'): # dokud neni stisknuta klavesa 'q' if x == curses.KEY_DOWN or x == ord('j'): if (position % max_row < max_row - 1 and position < row_num - 1): position = position + 1 elif x == ord('s'): y = None term = "" while y != ord('\n'): box.addstr(0, 0, (" " * (width - 6))) box.addstr(0, 0, "Term: " + str(term)) screen.refresh() box.refresh() y = screen.getch() if y in (curses.KEY_BACKSPACE, 263, 127): term = term[:-1] else: term += chr(y) if (len(term) > 0): term = term[:-1] strings = ytb_search(term, width, max_row) row_num = len(strings) box.refresh() screen.refresh() elif x == curses.KEY_UP or x == ord('k'): if (position % max_row > 0 and position > 0): position = position - 1 elif x == ord("\n"): #box.erase() #box.addstr(0,0,"Selected: "+str(strings[position][0])) #box.addstr(1,0,"Link: "+str(strings[position][1])) #box.refresh() #screen.refresh() return (strings[position][1]) box.erase() for i in range(0, max_row): if row_num == 0: box.addstr(0, 1, "[s] pro vyhledani na YTB", hiTe) elif i + shift == row_num: break else: if (i + shift == position): box.addstr( i, 2, actual_char + " " + sutf8(strings[i + shift][0][:width - 10]), hiTe) else: box.addstr( i, 2, " " + sutf8(strings[i + shift][0][:width - 10]), noTe) footer = "[ Klavesy: j,k,s,q,ENTER shift: " + str( shift) + " i: " + str(i) + " pos: " + str(position) if height <= 50: footer = "[ Klavesy: j,k,s,q,ENTER ]" box.addstr(max_row - 2, 0, footer, noTe) screen.refresh() box.refresh() x = screen.getch()