예제 #1
0
파일: app.py 프로젝트: socek/Menu-Gui
class Title(object):
    def __init__(self, stdscr, title):
        maxy, maxx = stdscr.getmaxyx()
        self._win = curses.newwin(1, maxx, 0, 0)
        maxx = self._win.getmaxyx()[1] -2
        self._text = String(title)        
        
        data = self._text.center(maxx)
        self._win.addstr(data, colors.COLORS['main title'])
        self._win.refresh()

    def close(self):
        self._win.clear()
예제 #2
0
파일: button.py 프로젝트: socek/Menu-Gui
class Button(Widget):
    color = {
        'normal' : 'normal',
        'active' : 'highlited',
    }
    
    def __init__(self, parent, pos_y, pos_x, label, width, fun = None):
        super(Button, self).__init__(parent, pos_y, pos_x)
        
        self._label = String(label)
        self._width = width
        self._fun = fun
    
    def refresh(self):
        c_window = self._parent._c_window
        
        c_window.addstr(self._pos_y, self._pos_x, self._label.center(self._width), self.flags() )
        
    def flags(self):
        if self._highlited:
            name = self.color['active']
            flags = COLORS[name]
        else:
            name = self.color['normal']
            flags = COLORS[name]
            
        if self._active:
            flags |= curses.A_BOLD
        
        return flags

    def _on_char(self, var):
        if var[0] == 10:
            self.runme()
        else:
            return var

    def runme(self):
        if self._fun != None:
            self._fun(self)
    
    @property
    def width(self):
        return self._width

    def set_label(self, label):
        self._label = String(label)