Esempio n. 1
0
 def hide(self, name):
     """
     Hide the panel with name.
     """
     panel = self.__panels[name]
     if not panel.hidden():
         panel.hide()
         self.update()
Esempio n. 2
0
 def toggle(self, name):
     """
     Toggle the visibility of the panel with name.
     """
     panel = self.__panels[name]
     if panel.hidden():
         panel.show()
     else:
         panel.hide()
     self.update()
Esempio n. 3
0
	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
Esempio n. 4
0
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()
Esempio n. 5
0
        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 yes_no(io, prompt, default=True):
	yesno = get_input(io, prompt, IF(default, "Y", "N"))
	return yesno.upper().startswith("Y")

def print_menu_list(clist, win, lines=20):
	"""Print a list with leading numeric menu choices. Use two columns in necessary."""
    y, x = win.getbegyx()
	h = max((len(clist)/2)+1, lines)
	i1, i2 = 1, h+1
	for c1, c2 in map(None, clist[:h], clist[h:]):
		if c2:
Esempio n. 6
0
    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