def make_panel(self, stdscr, h, w, y, x, str, normal=True): win = curses.newwin(h, w, y, x) panel = curses.panel.new_panel(win) panel.top() win.erase() if normal: win.box() win.addstr(1, 2, str) return win, panel
def make_panel(self, stdscr, h,w, y,x, str, normal=True): win = curses.newwin(h,w, y,x) panel = curses.panel.new_panel(win) panel.top() win.erase() if normal: win.box() win.addstr(1, 2, str) return win, panel
def display(self, scr, *args): result = (None, None) if args: y, x, color = args else: y, x, color = 0, 0, curses.A_NORMAL window = scr.subwin(y, x) window.keypad(1) panel = curses.panel.new_panel(window) panel.top() panel.show() window.clear() while True: window.refresh() curses.doupdate() for index, item in enumerate(self): if index == self.position: mode = curses.A_REVERSE | color else: mode = curses.A_NORMAL | color msg = '%d. %s' % (index + 1, item) window.addstr(1 + index, 1, msg, mode) key = window.getch() if key in (curses.KEY_ENTER, ord('\n')): result = (self.position, self[self.position]) break elif key == curses.KEY_UP: self.navigate(-1) elif key == 16: # ^P self.navigate(-1) elif key == curses.KEY_DOWN: self.navigate(1) elif key == 14: # ^N self.navigate(1) # We can't quit on ESC because cursor movements # involve ESC on many terminals. # elif key == 27: # ESCAPE # break elif key == ord('Q'): break elif chr(key) in string.digits: self.navigate(key - ord('0'), rel=-1) elif chr(key) in string.letters: for i in xrange(0, len(self)): if self[i][0].lower() >= chr(key).lower(): self.navigate(i, rel=0) break elif key == ord('\t'): self.navigate(5) window.clear() panel.hide() curses.panel.update_panels() curses.doupdate() return result
def top(self, name): """ Bring the panel with name to top of stack. """ panel = self.__panels[name] if panel.hidden(): panel.show() panel.top() self.update() self.__currentPanel = name
def display(self, scr, *args): result = (None, None) if args: y, x = args else: y, x = 0, 0 window = scr.subwin(y, x) window.keypad(1) panel = curses.panel.new_panel(window) panel.top() panel.show() window.clear() while True: window.refresh() curses.doupdate() for index, item in enumerate(self): if index == self.position: mode = curses.A_REVERSE | curses.color_pair(1) else: mode = curses.A_NORMAL | curses.color_pair(1) msg = '%d. %s' % (index + 1, item) window.addstr(1 + index, 1, msg, mode) key = window.getch() if key in (curses.KEY_ENTER, ord('\n')): result = (self.position, self[self.position]) break elif key == curses.KEY_UP: self.navigate(-1) elif key == curses.KEY_DOWN: self.navigate(1) elif key == 27: # ESCAPE break elif key == ord('Q'): break elif chr(key) in string.digits: self.navigate(key - ord('0'), rel=-1) elif chr(key) in string.letters: for i in xrange(0, len(self)): if self[i][0].lower() >= chr(key).lower(): self.navigate(i, rel=0) break elif key == ord('\t'): self.navigate(5) window.clear() panel.hide() curses.panel.update_panels() curses.doupdate() return result
def choose(io, somelist, defidx=0, prompt="choose"): """Select an item from a list.""" if len(somelist) == 0: return None root = io.root root.bottom() py, px = io.getmaxyx() outwin = io.derwin(py - 3, px - 10, 3, 5) outwin.box() outwin.refresh() win = outwin.derwin(py - 5, px - 12, 1, 1) panel = curses.panel.new_panel(outwin) print_menu_list(somelist, win, py) panel.top() panel.show() defidx = int(defidx) if defidx < 0: defidx = 0 if defidx >= len(somelist): defidx = len(somelist) - 1 try: try: ri = get_input(io, prompt, defidx + 1) # menu list starts at one except EOFError: return None if ri: try: idx = int(ri) - 1 except ValueError: io.errlog("Bad selection. Type in the number.") return None else: try: return somelist[idx] except IndexError: io.errlog("Bad selection. Selection out of range.") return None else: return None finally: panel.hide() win.erase() outwin.clear() root.show()
def choose(io, somelist, defidx=0, prompt="choose"): """Select an item from a list.""" if len(somelist) == 0: return None root = io.root root.bottom() py, px = io.getmaxyx() outwin = io.derwin(py-3,px-10, 3,5) outwin.box() outwin.refresh() win = outwin.derwin(py-5,px-12, 1,1) panel = curses.panel.new_panel(outwin) print_menu_list(somelist, win, py) panel.top() panel.show() defidx = int(defidx) if defidx < 0: defidx = 0 if defidx >= len(somelist): defidx = len(somelist)-1 try: try: ri = get_input(io, prompt, defidx+1) # menu list starts at one except EOFError: return None if ri: try: idx = int(ri)-1 except ValueError: io.errlog("Bad selection. Type in the number.") return None else: try: return somelist[idx] except IndexError: io.errlog("Bad selection. Selection out of range.") return None else: return None finally: panel.hide() win.erase() ; outwin.clear() root.show()
def createWinAndPanel(self, name, l, h, y, x): win = curses.newwin(l, h, y, x) win.box() win.border(0) panel = curses.panel.new_panel(win) #does this do a deepcopy? Does the existing panel go into garbage? self.panelStack[name] = panel panel.top() panel.show() self.screen.refresh win.refresh() curses.panel.update_panels() return win, panel
def ask_meta_pwd(meta_hello='Please enter Meta Password'): scrh, scrw = scrwin.getmaxyx() pww = 32 pwh = 3 pwx = (scrw - pww) / 2 pwy = (scrh - pwh) / 2 show_all_panels(really=False) scrwin.clear() win = curses.newwin(1, pww, pwy - 2, pwx) panel = curses.panel.new_panel(win) panel.top() panel.show() pad = (((pww - 2) - len(meta_hello)) / 2) * ' ' win.addnstr(0, 0, meta_hello + pad, pww - 2) curses.panel.update_panels() curses.doupdate() pww = password_window(pwx, pwy, pww) pww.display() pwd = pww.getpwd()
def ask_meta_pwd(meta_hello='Please enter Meta Password'): scrh, scrw = scrwin.getmaxyx() pww = 32 pwh = 3 pwx = (scrw - pww) / 2 pwy = (scrh - pwh) / 2 show_all_panels(really=False) scrwin.clear() win = curses.newwin(1, pww, pwy-2,pwx) panel = curses.panel.new_panel(win) panel.top() panel.show() pad = (((pww-2) - len(meta_hello))/2)*' ' win.addnstr(0,0,meta_hello+pad,pww-2) curses.panel.update_panels() curses.doupdate() pww = password_window(pwx,pwy,pww) pww.display() pwd = pww.getpwd()
def newpopup(h, w, y, x, title=None, line=True, opts=None): win, panel, wb, pn = newlinebox(h, w, y, x, title, line=line, opts=opts) if opts is not None: win.bkgd(" ", opts) panel.top() return win, panel, wb, pn
"""Select an item from a list.""" if len(somelist) == 0: return None root = io.root root.bottom() py, px = io.getmaxyx() outwin = io.derwin(py-3,px-10, 3,5) outwin.box() outwin.refresh() win = outwin.derwin(py-5,px-12, 1,1) panel = curses.panel.new_panel(outwin) print_menu_list(somelist, win, py) panel.top() panel.show() defidx = int(defidx) if defidx < 0: defidx = 0 if defidx >= len(somelist): defidx = len(somelist)-1 try: try: ri = get_input(io, prompt, defidx+1) # menu list starts at one except EOFError: return None if ri: try: idx = int(ri)-1
def display(self, scr, *args, **kwargs): if 'timeout' in kwargs: timeout = kwargs['timeout'] else: timeout = 0.0 result = (None, None) if args: y, x, color = args else: y, x, color = 0, 0, curses.A_NORMAL window = scr.subwin(y, x) window.keypad(1) panel = curses.panel.new_panel(window) panel.top() panel.show() window.clear() curses.cbreak() window.timeout(int(timeout) * 1000) while True: h, w = window.getmaxyx() ts = time.strftime('%a, %d %b %Y at %H:%M:%S') scr.addstr(0, w - len(ts), ts, curses.A_NORMAL | color) scr.refresh() window.refresh() curses.doupdate() index = 0 anything = False fp = os.popen(self.cmd, 'r') for line in fp: line = line.strip() if line == '' and not anything: continue anything = True index += 1 if index == 1: window.clear() window.refresh() mode = curses.A_NORMAL | color msg = line try: window.addstr(index, 1, msg, mode) except curses.error: # out of room break fp.close() key = window.getch() if key == 27: # ESCAPE break elif key == ord('Q'): break elif key == ord('q'): break window.clear() panel.hide() curses.panel.update_panels() curses.doupdate() return result