Python urwid.Widget() Examples

The following are 19 code examples of urwid.Widget(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module urwid , or try the search function .
Example #1
Source File: screenElements.py    From alertR with GNU Affero General Public License v3.0 7 votes vote down vote up
def _createAlertLevelsWidgetList(self, alertLevels: List[AlertLevel]) -> List[urwid.Widget]:

        temp = list()
        first = True
        for alertLevel in alertLevels:

            if first:
                first = False
            else:
                temp.append(urwid.Divider())
                temp.append(urwid.Divider("-"))

            temp.extend(self._createAlertLevelWidgetList(alertLevel))

        return temp

    # this function creates the detailed output of a alert level object
    # in a list 
Example #2
Source File: main.py    From wikicurses with MIT License 6 votes vote down vote up
def __init__(self):
        def selectButton(radio_button, new_state, parameter):
            if new_state:
                closeOverlay()
                self._select(parameter)

        super().__init__(urwid.SimpleFocusListWalker([]))
        buttons = []
        for i, item in enumerate(self._items()):
            if isinstance(item, urwid.Widget):
                self.body.append(item)
                continue
            elif isinstance(item, tuple):
                name, selected, parameter = item
            else:
                parameter = name = item
                selected = False
            self.body.append(urwid.RadioButton(buttons, name, selected,
                                               selectButton, parameter))
            if selected:
                self.set_focus(i) 
Example #3
Source File: screenElements.py    From alertR with GNU Affero General Public License v3.0 6 votes vote down vote up
def _createSensorsWidgetList(self, sensors: List[Sensor]) -> List[urwid.Widget]:

        temp = list()
        first = True
        for sensor in sensors:

            if first:
                first = False
            else:
                temp.append(urwid.Divider())
                temp.append(urwid.Divider("-"))

            temp.extend(self._createSensorWidgetList(sensor))

        return temp

    # this function creates the detailed output of a sensor object
    # in a list 
Example #4
Source File: screenElements.py    From alertR with GNU Affero General Public License v3.0 6 votes vote down vote up
def _createAlertWidgetList(self, alert: Alert) -> List[urwid.Widget]:

        temp = list()

        temp.append(urwid.Text("Alert ID:"))
        temp.append(urwid.Text(str(alert.alertId)))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Remote Alert ID:"))
        temp.append(urwid.Text(str(alert.remoteAlertId)))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Description:"))
        temp.append(urwid.Text(alert.description))

        return temp

    # this function creates the detailed output of all sensor objects
    # in a list 
Example #5
Source File: test_canvas.py    From anyMesh-Python with MIT License 6 votes vote down vote up
def test1(self):
        a = urwid.Text("")
        b = urwid.Text("")
        blah = urwid.TextCanvas()
        blah.finalize(a, (10,1), False)
        blah2 = urwid.TextCanvas()
        blah2.finalize(a, (15,1), False)
        bloo = urwid.TextCanvas()
        bloo.finalize(b, (20,2), True)

        urwid.CanvasCache.store(urwid.Widget, blah)
        urwid.CanvasCache.store(urwid.Widget, blah2)
        urwid.CanvasCache.store(urwid.Widget, bloo)

        self.cct(a, (10,1), False, blah)
        self.cct(a, (15,1), False, blah2)
        self.cct(a, (15,1), True, None)
        self.cct(a, (10,2), False, None)
        self.cct(b, (20,2), True, bloo)
        self.cct(b, (21,2), True, None)
        urwid.CanvasCache.invalidate(a)
        self.cct(a, (10,1), False, None)
        self.cct(a, (15,1), False, None)
        self.cct(b, (20,2), True, bloo) 
Example #6
Source File: screenElements.py    From alertR with GNU Affero General Public License v3.0 6 votes vote down vote up
def _createAlertWidgetList(self, alert: Alert) -> List[urwid.Widget]:

        temp = list()

        temp.append(urwid.Text("Alert ID:"))
        temp.append(urwid.Text(str(alert.alertId)))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Remote Alert ID:"))
        temp.append(urwid.Text(str(alert.remoteAlertId)))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Description:"))
        temp.append(urwid.Text(alert.description))

        return temp

    # this function creates the detailed output of a node object
    # in a list 
Example #7
Source File: screenElements.py    From alertR with GNU Affero General Public License v3.0 6 votes vote down vote up
def _createAlertLevelsWidgetList(self, alertLevels: List[AlertLevel]) -> List[urwid.Widget]:

        temp = list()
        first = True
        for alertLevel in alertLevels:

            if first:
                first = False
            else:
                temp.append(urwid.Divider())
                temp.append(urwid.Divider("-"))

            temp.extend(self._createAlertLevelWidgetList(alertLevel))

        return temp

    # this function creates the detailed output of a alert level object
    # in a list 
Example #8
Source File: __main__.py    From hangups with MIT License 5 votes vote down vote up
def __init__(self, keybindings):
        self._widgets = []  # [urwid.Widget]
        self._widget_title = {}  # {urwid.Widget: str}
        self._tab_index = None  # int
        self._keys = keybindings
        self._tabs = urwid.Text('')
        self._frame = urwid.Frame(None)
        super().__init__(urwid.Pile([
            ('pack', urwid.AttrMap(self._tabs, 'tab_background')),
            ('weight', 1, self._frame),
        ])) 
Example #9
Source File: screenElements.py    From alertR with GNU Affero General Public License v3.0 5 votes vote down vote up
def _createAlertLevelWidgetList(self, alertLevel: AlertLevel) -> List[urwid.Widget]:

        temp = list()

        temp.append(urwid.Text("Alert Level:"))
        temp.append(urwid.Text(str(alertLevel.level)))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Name:"))
        temp.append(urwid.Text(alertLevel.name))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Trigger Always:"))
        if alertLevel.triggerAlways == 0:
            temp.append(urwid.Text("No"))
        elif alertLevel.triggerAlways == 1:
            temp.append(urwid.Text("Yes"))
        else:
            temp.append(urwid.Text("Undefined"))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Rules Activated:"))
        if alertLevel.rulesActivated == 0:
            temp.append(urwid.Text("No"))
        elif alertLevel.rulesActivated == 1:
            temp.append(urwid.Text("Yes"))
        else:
            temp.append(urwid.Text("Undefined"))

        return temp

    # this function creates the detailed output of all alert objects
    # in a list 
Example #10
Source File: screenElements.py    From alertR with GNU Affero General Public License v3.0 5 votes vote down vote up
def _createManagerWidgetList(self, manager: Manager) -> List[urwid.Widget]:

        temp = list()

        temp.append(urwid.Text("Manager ID:"))
        temp.append(urwid.Text(str(manager.managerId)))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Description:"))
        temp.append(urwid.Text(manager.description))

        return temp

    # this function creates the detailed output of a node object
    # in a list 
Example #11
Source File: screenElements.py    From alertR with GNU Affero General Public License v3.0 5 votes vote down vote up
def _createAlertLevelWidgetList(self, alertLevel: AlertLevel) -> List[urwid.Widget]:

        temp = list()

        temp.append(urwid.Text("Alert Level:"))
        temp.append(urwid.Text(str(alertLevel.level)))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Name:"))
        temp.append(urwid.Text(alertLevel.name))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Trigger Always:"))
        if alertLevel.triggerAlways == 0:
            temp.append(urwid.Text("No"))
        elif alertLevel.triggerAlways == 1:
            temp.append(urwid.Text("Yes"))
        else:
            temp.append(urwid.Text("Undefined"))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Rules Activated:"))
        if alertLevel.rulesActivated == 0:
            temp.append(urwid.Text("No"))
        elif alertLevel.rulesActivated == 1:
            temp.append(urwid.Text("Yes"))
        else:
            temp.append(urwid.Text("Undefined"))

        return temp

    # this function creates the detailed output of a node object
    # in a list 
Example #12
Source File: test_canvas.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def cct(self, widget, size, focus, expected):
        got = urwid.CanvasCache.fetch(widget, urwid.Widget, size, focus)
        assert expected==got, "got: %s expected: %s"%(got, expected) 
Example #13
Source File: tabs.py    From stig with GNU General Public License v3.0 5 votes vote down vote up
def insert(self, title, widget=None, position=-1, focus=True):
        """
        Insert new tab

        title: Any flow or fixed widget to use as the tab's title
        widget: Widget to show when this tab is selected or None
        position: Where to insert the new tab; int for list-like index or
                  'right'/'left' to insert next to focused tab
        focus: True to focus the new tab, False otherwise

        Return TabID of inserted tab
        """
        curpos = self.focus_position
        if position == 'right':
            newpos = (curpos + 1) if curpos is not None else 0
        elif position == 'left':
            newpos = max(curpos, 0) if curpos is not None else 0
        elif isinstance(position, int):
            if position < 0:
                newpos = position + len(self._contents) + 1
            else:
                newpos = position
        else:
            raise ValueError('Invalid position: {!r}'.format(position))

        # Insert new tab ID
        this_id = _find_unused_id(self._ids)
        self._ids.insert(newpos, this_id)

        # Insert title
        self._tabbar.base_widget.insert(newpos, title)

        # Insert content
        self._contents.insert(newpos, widget)
        if focus:
            self.focus_position = newpos
        return this_id 
Example #14
Source File: tabs.py    From stig with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *contents, tabbar=None):
        """
        Create new Tabs widget

        contents: Iterable of dictionaries or iterables that match the arguments
                  of the `insert` method
        tabbar: TabBar instance that is used to display tab titles or any object
                with a 'base_widget' attribute (e.g. AttrMap) that returns a
                TabBar object
        """
        if tabbar is None:
            self._tabbar = TabBar()
        elif not isinstance(tabbar, urwid.Widget):
            raise ValueError('tabbar must be TabBar instance, not {}: {!r}'
                             .format(type(tabbar).__name__, tabbar))
        else:
            self._tabbar = tabbar

        self._ids = []
        self._focus_history = []
        self._info = defaultdict(lambda: {})
        self._contents = urwid.MonitoredFocusList()
        self._contents.set_focus_changed_callback(self._focus_changed_callback)
        for content in contents:
            if not isinstance(content, abc.Mapping):
                content = dict(zip(('title', 'widget', 'position', 'focus'),
                                   content))
            self.insert(**content) 
Example #15
Source File: screenElements.py    From alertR with GNU Affero General Public License v3.0 4 votes vote down vote up
def _createSensorWidgetList(self, sensor: Sensor) -> List[urwid.Widget]:

        temp = list()

        temp.append(urwid.Text("Sensor ID:"))
        temp.append(urwid.Text(str(sensor.sensorId)))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Remote Sensor ID:"))
        temp.append(urwid.Text(str(sensor.remoteSensorId)))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Alert Delay:"))
        temp.append(urwid.Text(str(sensor.alertDelay) + " Seconds"))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Description:"))
        temp.append(urwid.Text(sensor.description))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("State:"))
        if sensor.state == 0:
            temp.append(urwid.AttrMap(urwid.Text("Normal"), "neutral"))
        elif sensor.state == 1:
            temp.append(urwid.AttrMap(urwid.Text("Triggered"), "sensoralert"))
        else:
            temp.append(urwid.AttrMap(urwid.Text("Undefined"), "redColor"))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Data Type:"))
        if sensor.dataType == SensorDataType.NONE:
            temp.append(urwid.Text("None"))
        elif sensor.dataType == SensorDataType.INT:
            temp.append(urwid.Text("Integer"))
        elif sensor.dataType == SensorDataType.FLOAT:
            temp.append(urwid.Text("Floating Point"))
        else:
            temp.append(urwid.Text("Unknown"))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Data:"))
        if sensor.dataType == SensorDataType.NONE:
            temp.append(urwid.Text("None"))
        else:
            temp.append(urwid.Text(str(sensor.data)))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Last Updated (Server Time):"))
        lastUpdatedWidget = urwid.Text(time.strftime("%D %H:%M:%S", time.localtime(sensor.lastStateUpdated)))
        temp.append(lastUpdatedWidget)

        return temp

    # this function returns the final urwid widget that is used
    # to render this object 
Example #16
Source File: screenElements.py    From alertR with GNU Affero General Public License v3.0 4 votes vote down vote up
def _createNodeWidgetList(self, node: Node) -> List[urwid.Widget]:

        temp = list()

        temp.append(urwid.Text("Node ID:"))
        temp.append(urwid.Text(str(node.nodeId)))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Username:"))
        temp.append(urwid.Text(node.username))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Hostname:"))
        temp.append(urwid.Text(node.hostname))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Node Type:"))
        temp.append(urwid.Text(node.nodeType))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Instance:"))
        temp.append(urwid.Text(node.instance))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Version:"))
        versionWidget = urwid.Text(str(node.version) + "-" + str(node.rev))
        temp.append(versionWidget)
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Connected:"))
        if node.connected == 0:
            temp.append(urwid.AttrMap(urwid.Text("False"), "disconnected"))
        elif node.connected == 1:
            temp.append(urwid.AttrMap(urwid.Text("True"), "neutral"))
        else:
            temp.append(urwid.AttrMap(urwid.Text("Undefined"), "redColor"))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Persistent Connection:"))
        if node.persistent == 0:
            temp.append(urwid.Text("False"))

        elif node.persistent == 1:
            if node.connected == 0:
                temp.append(urwid.AttrMap(urwid.Text("True"), "disconnected"))

            else:
                temp.append(urwid.Text("True"))

        else:
            temp.append(urwid.AttrMap(urwid.Text("Undefined"), "redColor"))

        return temp

    # this function returns the final urwid widget that is used
    # to render this object 
Example #17
Source File: screenElements.py    From alertR with GNU Affero General Public License v3.0 4 votes vote down vote up
def _createNodeWidgetList(self, node: Node) -> List[urwid.Widget]:

        temp = list()

        temp.append(urwid.Text("Node ID:"))
        temp.append(urwid.Text(str(node.nodeId)))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Username:"))
        temp.append(urwid.Text(node.username))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Hostname:"))
        temp.append(urwid.Text(node.hostname))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Node Type:"))
        temp.append(urwid.Text(node.nodeType))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Instance:"))
        temp.append(urwid.Text(node.instance))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Version:"))
        versionWidget = urwid.Text(str(node.version) + "-" + str(node.rev))
        temp.append(versionWidget)
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Connected:"))
        if node.connected == 0:
            temp.append(urwid.AttrMap(urwid.Text("False"), "disconnected"))
        elif node.connected == 1:
            temp.append(urwid.AttrMap(urwid.Text("True"), "neutral"))
        else:
            temp.append(urwid.AttrMap(urwid.Text("Undefined"), "redColor"))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Persistent Connection:"))
        if node.persistent == 0:
            temp.append(urwid.Text("False"))
        elif node.persistent == 1:
            if node.connected == 0:
                temp.append(urwid.AttrMap(urwid.Text("True"), "disconnected"))
            else:
                temp.append(urwid.Text("True"))
        else:
            temp.append(urwid.AttrMap(urwid.Text("Undefined"), "redColor"))

        return temp

    # this function creates the detailed output of a sensor object
    # in a list 
Example #18
Source File: screenElements.py    From alertR with GNU Affero General Public License v3.0 4 votes vote down vote up
def _createNodeWidgetList(self, node: Node) -> List[urwid.Widget]:

        temp = list()

        temp.append(urwid.Text("Node ID:"))
        temp.append(urwid.Text(str(node.nodeId)))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Username:"))
        temp.append(urwid.Text(node.username))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Hostname:"))
        temp.append(urwid.Text(node.hostname))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Node Type:"))
        temp.append(urwid.Text(node.nodeType))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Instance:"))
        temp.append(urwid.Text(node.instance))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Version:"))
        versionWidget = urwid.Text(str(node.version) + "-" + str(node.rev))
        temp.append(versionWidget)
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Connected:"))
        if node.connected == 0:
            temp.append(urwid.AttrMap(urwid.Text("False"), "disconnected"))
        elif node.connected == 1:
            temp.append(urwid.AttrMap(urwid.Text("True"), "neutral"))
        else:
            temp.append(urwid.AttrMap(urwid.Text("Undefined"), "redColor"))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Persistent Connection:"))
        if node.persistent == 0:
            temp.append(urwid.Text("False"))

        elif node.persistent == 1:
            if node.connected == 0:
                temp.append(urwid.AttrMap(urwid.Text("True"), "disconnected"))

            else:
                temp.append(urwid.Text("True"))
        else:
            temp.append(urwid.AttrMap(urwid.Text("Undefined"), "redColor"))

        return temp

    # this function returns the final urwid widget that is used
    # to render this object 
Example #19
Source File: screenElements.py    From alertR with GNU Affero General Public License v3.0 4 votes vote down vote up
def _createSensorWidgetList(self, sensor: Sensor) -> List[urwid.Widget]:

        temp = list()

        temp.append(urwid.Text("Sensor ID:"))
        temp.append(urwid.Text(str(sensor.sensorId)))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Remote Sensor ID:"))
        temp.append(urwid.Text(str(sensor.remoteSensorId)))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Alert Delay:"))
        temp.append(urwid.Text(str(sensor.alertDelay) + " Seconds"))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Description:"))
        temp.append(urwid.Text(sensor.description))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("State:"))
        if sensor.state == 0:
            temp.append(urwid.AttrMap(urwid.Text("Normal"), "neutral"))
        elif sensor.state == 1:
            temp.append(urwid.AttrMap(urwid.Text("Triggered"), "sensoralert"))
        else:
            temp.append(urwid.AttrMap(urwid.Text("Undefined"), "redColor"))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Data Type:"))
        if sensor.dataType == SensorDataType.NONE:
            temp.append(urwid.Text("None"))
        elif sensor.dataType == SensorDataType.INT:
            temp.append(urwid.Text("Integer"))
        elif sensor.dataType == SensorDataType.FLOAT:
            temp.append(urwid.Text("Floating Point"))
        else:
            temp.append(urwid.Text("Unknown"))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Data:"))
        if sensor.dataType == SensorDataType.NONE:
            temp.append(urwid.Text("None"))
        else:
            temp.append(urwid.Text(str(sensor.data)))
        temp.append(urwid.Divider())

        temp.append(urwid.Text("Last Updated (Server Time):"))
        lastUpdatedWidget = urwid.Text(time.strftime("%D %H:%M:%S", time.localtime(sensor.lastStateUpdated)))
        temp.append(lastUpdatedWidget)

        return temp

    # this function returns the final urwid widget that is used
    # to render this object