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 win_show(win, label, label_color): starty, startx = uni.getbegyx(win) height, width = uni.getmaxyx(win) uni.box(win, 0, 0) uni.mvwaddch(win, 2, 0, uni.ACS_LTEE) uni.mvwhline(win, 2, 1, uni.ACS_HLINE, width - 2) uni.mvwaddch(win, 2, width - 1, uni.ACS_RTEE) print_in_middle(win, 1, 0, width, label, uni.COLOR_PAIR(label_color))
def win_show(win, label, label_color): starty, startx = uni.getbegyx(win) height, width = uni.getmaxyx(win) #starty, startx = (0, 0) # Box around window uni.box(win, 0, 0) # Connects header to box (left) uni.mvwaddch(win, 2, 0, uni.ACS_LTEE) # Header line uni.mvwhline(win, 2, 1, uni.ACS_HLINE, width - 2) # Connects header to box (right) uni.mvwaddch(win, 2, width - 1, uni.ACS_RTEE)
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()
#my_wins = [0] * 3 stdscr = uni.initscr() uni.cbreak() uni.noecho() uni.keypad(stdscr, True) uni.curs_set(0) uni.start_color() # Sub window # Max coords of parent window maxy, maxx = uni.getmaxyx(stdscr) menu_height = 3 menu = uni.newwin(menu_height, maxx, 0, 0) starty, startx = uni.getbegyx(menu) height, width = uni.getmaxyx(menu) # Box line uni.box(menu, 0, 0) #uni.bkgd(uni.COLOR_PAIR(1)) # Box label #uni.wattron(menu, uni.COLOR_PAIR(0)) #uni.mvwaddstr(menu, 0, 2, "Garin") uni.mvwaddstr(menu, 1, 1, "File") uni.mvwaddstr(menu, 1, len("File") + 2, "Edit") #uni.wattroff(menu, uni.COLOR_PAIR(0)) uni.refresh()
def y(self): """Y coordinate of upper left corner.""" y, _ = curses.getbegyx(self.win) return y
def x(self): """X coordinate of upper left corner.""" _, x = curses.getbegyx(self.win) return x