def showHelp(self): string = "Type a command key for contextual help: " unicurses.waddstr(self.scr.win, string) while True: try: key = chr(self.scr.getch(self.scr.win)) except ValueError: continue if key in self.keymap and self.keymap[key]['help'] != None: if self.keymap[key]['help'] == False: break unicurses.wclear(self.scr.win) err = self.keymap[key]['stat'] if isinstance(err, basestring): attr = self.scr.attr['err'] unicurses.wmove(self.scr.win, self.scr.h - 1, 0) unicurses.waddnstr(self.scr.win, err, self.scr.w, attr) unicurses.wmove(self.scr.win, 0, 0) title = self.keymap[key]['text'] title = ' ' * (self.scr.w - len(title) - 6) + title + " Help \n" unicurses.waddstr(self.scr.win, title, self.scr.attr['ttl']) unicurses.waddstr(self.scr.win, self.keymap[key]['help']) string = "\n\nPress 'q' to exit help.\n\n" unicurses.waddstr(self.scr.win, string) while chr(self.scr.getch(self.scr.win)) != 'q': pass break
def render(self): unicurses.wclear(self.scr.win) if self.scr.msg != None: unicurses.wmove(self.scr.win, self.scr.h - 1, 0) if isinstance(self.scr.msg, basestring): unicurses.waddnstr(self.scr.win, self.scr.msg, self.scr.w) elif isinstance(self.scr.msg, tuple): attr = self.scr.attr[self.scr.msg[0]] msg = self.scr.msg[1] unicurses.waddnstr(self.scr.win, msg, self.scr.w, attr) unicurses.wmove(self.scr.win, 0, 0) unicurses.waddstr(self.scr.win, self.titlebar, self.scr.attr['ttl']) for opt in self.curropts: if opt == None: unicurses.waddstr(self.scr.win, "\n") continue key = opt['key'] + ": " unicurses.waddstr(self.scr.win, key, self.scr.attr['key']) if not isinstance(opt['val'], basestring): pad = 2 if opt['stat'] != True else 0 if opt['wait'] == True or opt['val'] == True: pad += 2 self.dotstr(opt['text'], None, pad) else: unicurses.waddstr(self.scr.win, opt['text']) attr = self.scr.attr['val'] if opt['stat'] != True: attr = self.scr.attr['err'] unicurses.waddstr(self.scr.win, " !", attr) if opt['wait'] == True: unicurses.waddstr(self.scr.win, " ~", self.scr.attr['slp']) elif opt['val'] == True: unicurses.waddstr(self.scr.win, " +", attr) elif opt['val'] == (None, ): unicurses.waddstr(self.scr.win, " unchanged", self.scr.attr['slp']) elif isinstance(opt['val'], (basestring, list)): if len(opt['text']) > 0: unicurses.waddstr(self.scr.win, " ") value = opt['val'] if isinstance(value, list): value = ','.join(value) if '*' in opt['act']: value = '*' * len(value) self.dotstr(value, attr) if unicurses.getyx(self.scr.win)[1] > 0: unicurses.waddstr(self.scr.win, "\n") unicurses.waddstr(self.scr.win, "\n")
def draw_string(self, string, attributes=0, wrapping=False, silent=True): """Try to draw a string with given attributes.""" if wrapping: returncode = curses.waddnstr(self.win, string, self.width, attributes) else: returncode = curses.waddstr(self.win, string, attributes) # End of window reached if returncode == curses.ERR and not silent: raise EndOfWin()
def render(self): unicurses.wclear(self.scr.win) if self.scr.msg != None: unicurses.wmove(self.scr.win, self.scr.h - 1, 0) if isinstance(self.scr.msg, basestring): unicurses.waddnstr(self.scr.win, self.scr.msg, self.scr.w) elif isinstance(self.scr.msg, tuple): attr = self.scr.attr[self.scr.msg[0]] msg = self.scr.msg[1] unicurses.waddnstr(self.scr.win, msg, self.scr.w, attr) unicurses.wmove(self.scr.win, 0, 0) unicurses.waddstr(self.scr.win, self.titlebar, self.scr.attr['ttl']) for opt in self.curropts: if opt == None: unicurses.waddstr(self.scr.win, "\n") continue key = opt['key'] + ": " unicurses.waddstr(self.scr.win, key, self.scr.attr['key']) if not isinstance(opt['val'], basestring): pad = 2 if opt['stat'] != True else 0 if opt['wait'] == True or opt['val'] == True: pad += 2 self.dotstr(opt['text'], None, pad) else: unicurses.waddstr(self.scr.win, opt['text']) attr = self.scr.attr['val'] if opt['stat'] != True: attr = self.scr.attr['err'] unicurses.waddstr(self.scr.win, " !", attr) if opt['wait'] == True: unicurses.waddstr(self.scr.win, " ~", self.scr.attr['slp']) elif opt['val'] == True: unicurses.waddstr(self.scr.win, " +", attr) elif opt['val'] == (None,): unicurses.waddstr(self.scr.win, " unchanged", self.scr.attr['slp']) elif isinstance(opt['val'], (basestring, list)): if len(opt['text']) > 0: unicurses.waddstr(self.scr.win, " ") value = opt['val'] if isinstance(value, list): value = ','.join(value) if '*' in opt['act']: value = '*'*len(value) self.dotstr(value, attr) if unicurses.getyx(self.scr.win)[1] > 0: unicurses.waddstr(self.scr.win, "\n") unicurses.waddstr(self.scr.win, "\n")
def showHelp(self): string = "Type a command key for contextual help: " unicurses.waddstr(self.scr.win, string) while True: try: key = chr(self.scr.getch(self.scr.win)) except ValueError: continue if key in self.keymap and self.keymap[key]['help'] != None: if self.keymap[key]['help'] == False: break unicurses.wclear(self.scr.win) err = self.keymap[key]['stat'] if isinstance(err, basestring): attr = self.scr.attr['err'] unicurses.wmove(self.scr.win, self.scr.h - 1, 0) unicurses.waddnstr(self.scr.win, err, self.scr.w, attr) unicurses.wmove(self.scr.win, 0, 0) title = self.keymap[key]['text'] title = ' '*(self.scr.w - len(title) - 6) + title + " Help \n" unicurses.waddstr(self.scr.win, title, self.scr.attr['ttl']) unicurses.waddstr(self.scr.win, self.keymap[key]['help']) string = "\n\nPress 'q' to exit help.\n\n" unicurses.waddstr(self.scr.win, string) while chr(self.scr.getch(self.scr.win)) != 'q': pass break