Example #1
0
 def show(self, name):
     """
     Show the panel with name. Brings panel to top.
     """
     panel = self.__panels[name]
     panel.show()
     self.update()
Example #2
0
    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
Example #3
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()
Example #4
0
 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
Example #5
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
Example #6
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()
Example #7
0
	def __init__(self):
		"""
		Iniciamos el juego
		"""
		
		self.positions = []
		self.letters = []
		self.errors = 0
		self.wordslist = ''
		if len(argv) == 2:
			self.wordslist = argv[1]
		else:
			self.wordslist = 'words.txt'
		if not isfile(self.wordslist) or not access(self.wordslist, R_OK):
			curses.endwin()
			print (_('The file %s don\'t exists or you not have read permissions') % self.wordslist)
			exit(-1)
			
		f = open(self.wordslist, 'r')
		words = f.readlines()
		f.close()
			
		n = randint(0, len(words)-1)
		self.word = words[n].split()[0]
		
		self.word2 = ''
		
		i = 1
		while i <= len(self.word):
			self.word2 += '*'
			i += 1
		
		stdscr.addstr(1, 4, ' ______')
		stdscr.addstr(2, 4, '/     |')
		stdscr.addstr(3, 4, '|')
		stdscr.addstr(4, 4, '|')
		stdscr.addstr(5, 4, '|')
		stdscr.addstr(6, 4, '|')
		stdscr.addstr(9, 4, 'Palabra: %s' % self.word2)

		
		panel = self.show_letters()
		panel.show()
		curses.panel.update_panels()
		stdscr.refresh()
		
		self.checkLetter()
Example #8
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()
Example #9
0
	def retry(self):
		"""
		Al terminar la partida nos preguntara si queremos volver a jugar
		"""
		stdscr.addstr(12, 4, _('Press any key to start new game or press ESC to exit'))
		key = stdscr.getch()
		
		if key < 256:
			if key == 27:
				self.salir()
			else:
				self.positions = []
				self.letters = []
				self.errors = 0
				stdscr.clear()
				self.word2 = ''
				self.show_letters(True)
				
				f = open(self.wordslist, 'r')
				words = f.readlines()
				f.close()
				
				n = randint(0, len(words)-1)
				self.word = words[n].split()[0]
				
				self.word2 = ''
				
				i = 1	
				while i <= len(self.word):
					self.word2 += '*'
					i += 1
				
				stdscr.addstr(1, 4, ' ______')
				stdscr.addstr(2, 4, '/     |')
				stdscr.addstr(3, 4, '|')
				stdscr.addstr(4, 4, '|')
				stdscr.addstr(5, 4, '|')
				stdscr.addstr(6, 4, '|')
				stdscr.addstr(9, 4, 'Palabra: %s' % self.word2)
				
				panel = self.show_letters()
				panel.show()
				self.redraw()
		else:
			self.retry()
Example #10
0
    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
Example #11
0
    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
Example #12
0
	def redraw(self):
		"""
		Repinta la ventana
		"""
		letters = ''
				
		if self.word2 != self.word:
			
			if self.errors == 1:
				stdscr.addstr(3, 10, 'O')
			
			if self.errors == 2:
				stdscr.addstr(4, 10, '|')
				
			if self.errors == 3:
				stdscr.addstr(4, 9, '/|')
				
			if self.errors == 4:
				stdscr.addstr(4, 9, '/|\\')
				
			if self.errors == 5:
				stdscr.addstr(5, 9, '/')
				
			if self.errors == 6:
				stdscr.addstr(5, 9, '/ \\')
				stdscr.addstr(9, 4, _('Word: %s') % self.word)
					
				stdscr.addstr(11, 4, _('YOU FAIL!'), curses.color_pair(1) )
				self.retry()
				
			stdscr.addstr(9, 4, _('Word: %s') % self.word2)
			
			for k in self.letters:
				letters += ' ' + k
			
			panel = self.show_letters()
			panel.show()
			self.checkLetter()
		
		else:
			stdscr.addstr(9, 4, _('Word: %s') % self.word2)
			stdscr.addstr(11, 4, _('YOU WIN!'), curses.color_pair(2) )
			self.retry()
Example #13
0
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()
Example #14
0
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()
Example #15
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
Example #16
0
	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:
Example #17
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