def showLineEdit(self, sel, quiet): maxwidth = 4096 fw, hw = self.scr.w - 2, (self.scr.w - 2) / 2 unicurses.waddstr(self.scr.win, "Edit " + sel['text'] + ":\n> ") unicurses.noutrefresh(self.scr.win) (yn, xn) = unicurses.getyx(self.scr.win) buf = unicurses.newpad(1, maxwidth + 1) unicurses.keypad(buf, 1) offs, length, submit = 0, 0, False if not quiet and sel['val'] != None and sel['val'] != (None, ): length = len(sel['val']) unicurses.waddstr(buf, sel['val']) offs = max(0, length / hw - 1) (yb, xb) = unicurses.getbegyx(self.scr.win) (yp, xp) = (yn + yb, xn + xb) unicurses.prefresh(buf, 0, offs * hw, yp, xp, yp, xp + fw - 1) unicurses.doupdate() while True: if quiet: ch = self.scr.getch(buf, redact=True) else: etc = (buf, 0, offs * hw, yn, xn, yn, xn + fw - 1) ch = self.scr.getch(buf, etc) (y, x) = unicurses.getyx(buf) if ch in (ord('\n'), unicurses.KEY_ENTER): sel['val'] = unicurses.mvwinstr(buf, 0, 0, length) if sel['val'] != None and len(sel['val']) == 0: sel['val'] = None submit = True break elif ch == ord('\x1b'): break elif ch == unicurses.KEY_HOME and x > 0: unicurses.wmove(buf, y, 0) elif ch == unicurses.KEY_END and x < length: unicurses.wmove(buf, y, length) elif ch == unicurses.KEY_LEFT and x > 0: unicurses.wmove(buf, y, x - 1) elif ch == unicurses.KEY_RIGHT and x < length: unicurses.wmove(buf, y, x + 1) elif ch in (ord('\b'), ord('\x7f'), unicurses.KEY_BACKSPACE, unicurses.KEY_DC) and x > 0: unicurses.wmove(buf, y, x - 1) unicurses.wdelch(buf) length -= 1 elif ord(' ') <= ch <= ord('~') and length < maxwidth: unicurses.winsstr(buf, chr(ch)) length += 1 unicurses.wmove(buf, y, x + 1) else: continue if quiet: continue oldoffs, offs = offs, max(0, unicurses.getyx(buf)[1] / hw - 1) if oldoffs < offs and maxwidth - offs * hw < fw: unicurses.wclrtoeol(self.scr.win) unicurses.noutrefresh(self.scr.win) (yb, xb) = unicurses.getbegyx(self.scr.win) (yp, xp) = (yn + yb, xn + xb) unicurses.prefresh(buf, 0, offs * hw, yp, xp, yp, xp + fw - 1) unicurses.doupdate() return submit
def showLineEdit(self, sel, quiet): maxwidth = 4096 fw, hw = self.scr.w - 2, (self.scr.w - 2)/2 unicurses.waddstr(self.scr.win, "Edit " + sel['text'] + ":\n> ") unicurses.noutrefresh(self.scr.win) (yn, xn) = unicurses.getyx(self.scr.win) buf = unicurses.newpad(1, maxwidth + 1) unicurses.keypad(buf, 1) offs, length, submit = 0, 0, False if not quiet and sel['val'] != None: length = len(sel['val']) unicurses.waddstr(buf, sel['val']) offs = max(0, length/hw - 1) (yb, xb) = unicurses.getbegyx(self.scr.win) (yp, xp) = (yn + yb, xn + xb) unicurses.prefresh(buf, 0, offs*hw, yp, xp, yp, xp + fw - 1) unicurses.doupdate() while True: if quiet: ch = self.scr.getch(buf) else: etc = (buf, 0, offs*hw, yn, xn, yn, xn + fw - 1) ch = self.scr.getch(buf, etc) (y, x) = unicurses.getyx(buf) if ch in (ord('\n'), unicurses.KEY_ENTER): sel['val'] = unicurses.mvwinstr(buf, 0, 0, length) if sel['val'] != None and len(sel['val']) == 0: sel['val'] = None submit = True break elif ch == ord('\x1b'): break elif ch == unicurses.KEY_HOME and x > 0: unicurses.wmove(buf, y, 0) elif ch == unicurses.KEY_END and x < length: unicurses.wmove(buf, y, length) elif ch == unicurses.KEY_LEFT and x > 0: unicurses.wmove(buf, y, x - 1) elif ch == unicurses.KEY_RIGHT and x < length: unicurses.wmove(buf, y, x + 1) elif ch in (ord('\b'), ord('\x7f'), unicurses.KEY_BACKSPACE, unicurses.KEY_DC) and x > 0: unicurses.wmove(buf, y, x - 1) unicurses.wdelch(buf) length -= 1 elif ord(' ') <= ch <= ord('~') and length < maxwidth: unicurses.winsstr(buf, chr(ch)) length += 1 unicurses.wmove(buf, y, x + 1) else: continue if quiet: continue oldoffs, offs = offs, max(0, unicurses.getyx(buf)[1]/hw - 1) if oldoffs < offs and maxwidth - offs*hw < fw: unicurses.wclrtoeol(self.scr.win) unicurses.noutrefresh(self.scr.win) (yb, xb) = unicurses.getbegyx(self.scr.win) (yp, xp) = (yn + yb, xn + xb) unicurses.prefresh(buf, 0, offs*hw, yp, xp, yp, xp + fw - 1) unicurses.doupdate() return submit
def render(self, etc=None): unicurses.redrawwin(self.screen) unicurses.noutrefresh(self.screen) (hw, ww) = unicurses.getmaxyx(self.screen) (yw, xw) = (max(0, (hw - self.h)/2), max(0, (ww - self.w)/2)) if yw > 0 and xw > 0: unicurses.mvwin(self.frame, yw - 1, xw - 1) unicurses.noutrefresh(self.frame) unicurses.mvwin(self.win, yw, xw) unicurses.noutrefresh(self.win) if etc != None: (buf, a, b, c, d, e, f) = etc (yb, xb) = unicurses.getbegyx(self.win) unicurses.prefresh(buf, a, b, c + yb, d + xb, e + yb, f + xb) unicurses.doupdate()
def render(self, etc=None): unicurses.redrawwin(self.screen) unicurses.noutrefresh(self.screen) (hw, ww) = unicurses.getmaxyx(self.screen) (yw, xw) = (max(0, (hw - self.h) / 2), max(0, (ww - self.w) / 2)) if yw > 0 and xw > 0: unicurses.mvwin(self.frame, yw - 1, xw - 1) unicurses.noutrefresh(self.frame) unicurses.mvwin(self.win, yw, xw) unicurses.noutrefresh(self.win) if etc != None: (buf, a, b, c, d, e, f) = etc (yb, xb) = unicurses.getbegyx(self.win) unicurses.prefresh(buf, a, b, c + yb, d + xb, e + yb, f + xb) unicurses.doupdate()