Example #1
0
    def create_interface(self):
        self.screen = Screen()
        self.screen.start()

        self.screen.register_palette([
            ("title", "white", "dark blue", "standout"),
            ("line", "light gray", "black"),
            ("help", "white", "dark blue")]
        )

        self.body = ListBox(SimpleListWalker([]))
        self.lines = self.body.body

        self.title = Text(MAIN_TITLE)
        self.header = AttrWrap(self.title, "title")

        self.help = AttrWrap(
            Text(HELP_STRINGS["main"]),
            "help"
        )

        self.input = Edit(caption="%s> " % self.ircchannel)
        self.footer = Pile([self.help, self.input])

        self.top = Frame(self.body, self.header, self.footer)
Example #2
0
 def __init__(self, parent, cur_index):
     self.parent = parent
     group = []
     for i, option in enumerate(self.parent._options):
         if option.enabled:
             btn = ClickableThing(option.label)
             connect_signal(btn, 'click', self.click, i)
             if i == cur_index:
                 rhs = '\N{BLACK LEFT-POINTING SMALL TRIANGLE} '
             else:
                 rhs = ''
         else:
             btn = option.label
             rhs = ''
         row = Columns([
             (1, Text("")),
             btn,
             (2, Text(rhs)),
         ])
         if option.enabled:
             row = AttrWrap(row, 'menu_button', 'menu_button focus')
         else:
             row = AttrWrap(row, 'info_minor')
         btn = UrwidPadding(row, width=self.parent._padding.width)
         group.append(btn)
     list_box = ListBox(group)
     list_box.base_widget.focus_position = cur_index
     super().__init__(Color.body(LineBox(list_box)))
Example #3
0
    def update_widgets(self,
                       update_dir=True,
                       update_file=True,
                       update_select=True):
        """
        Update self.dir_widget, self.file_widget or self.select_widget,
        corresponding to which of the paramters are set to True.
        """

        if update_dir or update_file:
            (dirlist, filelist) = self._dirfiles(self.directory)

        if update_dir:
            # Directory widget:
            widget_list = [
                AttrWrap(SelText(dir), None, self.attr[1]) for dir in dirlist
            ]

            self.dir_widget.box_widget.body = SimpleListWalker(widget_list)

        if update_file:
            # File widget:
            widget_list = [
                AttrWrap(SelText(dir), None, self.attr[1]) for dir in filelist
            ]

            self.file_widget.box_widget.body = SimpleListWalker(widget_list)

        if update_select:
            # Selection widget:
            selected_file = join(self.directory, self.file)
            self.select_widget.set_edit_text(selected_file)
Example #4
0
    def _build_widget(self, **kwargs):
        total_items = []
        for _item in self.radio_items.keys():
            desc = AttrWrap(
                Text("  {}".format(
                    self.radio_items[_item][1])), 'input', 'input focus')
            total_items.append(
                AttrWrap(self.radio_items[_item][0], 'input', 'input focus'))
            total_items.append(AttrWrap(desc, 'input'))
            total_items.append(Divider('-'))

        self.input_lbox = ListBox(SimpleListWalker(total_items[:-1]))
        self.add_buttons()

        self.container_box_adapter = BoxAdapter(self.input_lbox,
                                                len(total_items))
        self.container_lbox = ListBox(
            [self.container_box_adapter,
             Divider(),
             self.btn_pile])

        return LineBox(
            BoxAdapter(self.container_lbox,
                       height=len(total_items) + 3),
            title=self.title)
Example #5
0
 def add_buttons(self):
     """ Adds default CONFIRM/Cancel buttons for dialog
     """
     self.btn_confirm = AttrWrap(Button("Confirm", self.submit),
                                 'button_primary', 'button_primary focus')
     self.btn_cancel = AttrWrap(Button("Cancel",
                                       self.cancel), 'button_secondary',
                                'button_secondary focus')
     self.btn_pile = Pile([self.btn_confirm, self.btn_cancel])
Example #6
0
 def __init__(self):
     w = []
     w.append(AttrWrap(padding(
         Text("Ubuntu Openstack Installer - Software Installation")),
         "header_title"))
     w.append(AttrWrap(Text(
         '(Q)uit', align='center'), "header_menu"))
     w = Pile(w)
     super().__init__(w)
Example #7
0
 def __init__(self):
     w = []
     w.append(AttrWrap(padding(Text(TITLE_TEXT)), "header_title"))
     w.append(
         AttrWrap(
             Text(
                 '(A)dd units \N{BULLET} (H)elp \N{BULLET} '
                 '(R)efresh \N{BULLET} (Q)uit',
                 align='center'), "header_menu"))
     w = Pile(w)
     super().__init__(w)
Example #8
0
    def _build_node_waiting(self):
        """ creates a loading screen if nodes do not exist yet """
        text = [
            Text("\n\n\n"),
            Text(self.message, align="center"),
            Text("\n\n\n")
        ]

        load_box = [
            AttrWrap(Text("\u2582", align="center"), "pending_icon_on"),
            AttrWrap(Text("\u2581", align="center"), "pending_icon_on"),
            AttrWrap(Text("\u2583", align="center"), "pending_icon_on"),
            AttrWrap(Text("\u2584", align="center"), "pending_icon_on"),
            AttrWrap(Text("\u2585", align="center"), "pending_icon_on"),
            AttrWrap(Text("\u2586", align="center"), "pending_icon_on"),
            AttrWrap(Text("\u2587", align="center"), "pending_icon_on"),
            AttrWrap(Text("\u2588", align="center"), "pending_icon_on")
        ]

        # Add loading boxes
        random.shuffle(load_box)
        loading_boxes = []
        loading_boxes.append(('weight', 1, Text('')))
        for i in load_box:
            loading_boxes.append(
                ('pack', load_box[random.randrange(len(load_box))]))
        loading_boxes.append(('weight', 1, Text('')))
        loading_boxes = Columns(loading_boxes)

        return ScrollableListBox(text + [loading_boxes])
Example #9
0
 def __init__(self, parent, cur_index):
     self.parent = parent
     group = []
     for i, option in enumerate(self.parent._options):
         if option.enabled:
             btn = _PopUpButton(option.label, state=(i == cur_index))
             connect_signal(btn, 'click', self.click, i)
             group.append(AttrWrap(btn, 'menu_button', 'menu_button focus'))
         else:
             btn = Text("    " + option.label)
             group.append(AttrWrap(btn, 'info_minor'))
     list_box = ListBox(group)
     list_box.base_widget.focus_position = cur_index
     super().__init__(LineBox(list_box))
Example #10
0
 def __init__(self, parent, cur_index):
     self.parent = parent
     group = []
     for i, option in enumerate(self.parent._options):
         if option[1]:
             btn = _PopUpButton(option[0], state=i==cur_index)
             connect_signal(btn, 'click', self.click, i)
             group.append(AttrWrap(btn, 'menu_button', 'menu_button focus'))
         else:
             btn = Text("    " + option[0])
             group.append(AttrWrap(btn, 'info_minor'))
     pile = Pile(group)
     pile.set_focus(group[cur_index])
     fill = Filler(pile, valign=TOP)
     super().__init__(LineBox(fill))
Example #11
0
 def __init__(self, parent):
     self.parent = parent
     close = ActionBackButton("(close)")
     connect_signal(close, "click", self.close)
     group = [Color.menu_button(close)]
     width = 0
     for i, option in enumerate(self.parent._options):
         if option.enabled:
             if isinstance(option.label, Widget):
                 btn = option.label
             else:
                 btn = Color.menu_button(ActionMenuButton(option.label))
             width = max(width, len(btn.base_widget.label))
             connect_signal(btn.base_widget, 'click', self.click,
                            option.value)
         else:
             label = option.label
             if isinstance(label, Widget):
                 label = label.base_widget.label
             width = max(width, len(label))
             btn = Columns([
                 ('fixed', 1, Text("")),
                 Text(label),
                 ('fixed', 1, Text(">")),
             ],
                           dividechars=1)
             btn = AttrWrap(btn, 'info_minor')
         group.append(btn)
     self.width = width
     super().__init__(LineBox(ListBox(group)))
Example #12
0
    def __init__(self, parser, encoding):
        self.loop = None
        self.parser = parser
        self.panel_focus = 1
        self.show_ladder = False
        self.search = {
            'phone': '',
            'chan': '',
            'call_id': '',
        }

        self.sidebar = Sidebar(sorted(self.parser.get_phone_set()))
        connect_signal(self.sidebar, 'select', self.on_result_selected)
        connect_signal(self.sidebar, 'search', self.on_search)

        self.log_display = LogDisplay(parser, encoding)

        self.cols = Columns([
            ('fixed', 20, self.sidebar),
            ('fixed', 1, Filler(Divider(), 'top')),
            ('weight', 1, self.log_display),
        ])

        self.footer = Text('')
        self.set_footer_text()
        self.frame = Frame(self.cols, footer=AttrWrap(self.footer, 'bar'))
Example #13
0
 def __init__(self, msg=None, height=10):
     if not msg:
         msg = "Processing."
     listbox = ListBox([Text(msg)])
     box_adapter = BoxAdapter(listbox, height=height)
     linebox = LineBox(box_adapter, title="Info")
     super().__init__(AttrWrap(linebox, 'dialog'))
Example #14
0
    def __init__(self, name, named_grid_elements: list, callback: Callable):
        self.name = name
        self.named_widgets = {}
        unnamed_grid_elements = []
        for row in named_grid_elements:
            self.named_widgets.update(row)
            unnamed_grid_elements.append(list(row.values()))

        confirm = Button("Confirm", "confirm_button", self.__confirm)
        abort = Button("Abort", "abort_button", self.__quit)
        unnamed_grid_elements.append([confirm, abort])

        super().__init__(unnamed_grid_elements)
        self.keybind["f1"] = self.keybind["ctrl x"] = self.__confirm
        self.keybind["f5"] = self.keybind["ctrl g"] = self.__quit

        self.on_submit = callback

        bottom = Filler(self, valign="top")
        popup = AttrWrap(
            Filler(Text("Work in progress...\n\nPlease wait.", "center")),
            "popup")
        self.overlay = Overlay(popup, bottom, "center", 30, "middle", 5)

        self.root = WidgetPlaceholder(bottom)
Example #15
0
 def do(self, done, caption='', text='', tab=None):
     self._done = done
     self._tab = tab
     self.set_caption(caption)
     self.set_edit_text(text)
     self._end = True  # TODO: find a better way to move the cursor the end.
     self._top[0](AttrWrap(self, 'input'))
Example #16
0
 def __init__(self, key, name, on_mouseLeft):
     self.key = key
     self.on_mouseLeft = on_mouseLeft
     super().__init__([
         AttrWrap(Text(self._key2human(key) + ' '), 'style1-reverse'),
         (len(name), Text(name)),
     ], 0)
Example #17
0
 def set_results(self, results):
     self.phones_text.set_text([('key', 'F4'),
                                ' Results (%s)' % len(results)])
     self.items[:] = []
     group = []
     for ref in results:
         item = RadioButton(group, ref, state=False)
         connect_signal(item, 'change', self.on_select_phone, ref)
         item = AttrWrap(item, 'no', 'selection')
         self.items.append(item)
Example #18
0
 def update(self):
     if self.show_add_units:
         add_unit_string = '(A)dd Services \N{BULLET}'
     else:
         add_unit_string = ''
     tw = AttrWrap(Text(add_unit_string + ' (H)elp \N{BULLET} '
                        '(R)efresh \N{BULLET} (Q)uit',
                        align='center'),
                   "header_menu")
     self.pile.contents[1] = (tw, self.pile.options())
Example #19
0
    def __init__(self, parser):
        self.parser = parser
        self.find = {'ref': '', 'text': ''}
        self.isolate_filter = (None, None)
        self.line_collection = None
        self.jump_stack = []
        self.expansions = {}
        self.show_sip_level = 2
        self.show_ladder = False
        self.show_only_filtered = False
        self.show_verbose = True
        self.show_channel = True
        self.line_no_before_isolate = 0
        self.showing_help = False

        self.walker = LogLineWalker([('Select call on the left side', None)],
                                    self.jump, self.expand, self.isolate)
        self.header = AttrWrap(Text([('key', 'F6'), ' Log']), 'bar')
        self.listbox = ListBox(self.walker)
        self.frame = Frame(self.listbox, header=self.header)
Example #20
0
    def __init__(self, charm_classes, cb, **kwargs):
        self.charms = charm_classes
        self.cb = cb
        self.count_editor = None
        self.boxes = []

        w = self._build_widget()
        w = AttrWrap(w, "dialog")

        # Handle signals from add charm
        connect_signal(self, 'done', cb)
        super().__init__(w)
Example #21
0
 def __init__(self):
     """
       Initializes the widget
     """
     close_button = Button("close")
     connect_signal(close_button, 'click',
                    lambda button: self._emit('close'))
     help_window = Pile([
         Padding(Text(self.help_text), 'center', width=('relative', 90)),
         Padding(AttrMap(close_button, 'popbg'), 'center', 9)
     ])
     super(HelpWindow,
           self).__init__(AttrWrap(Filler(help_window), 'progress'))
Example #22
0
    def __init__(self,
                 height,
                 directory=".",
                 file="",
                 attr=(None, None),
                 show_hidden=False):
        """
        height -- height of the directory list and the file list
        directory, file -- default selection
        attr -- (inner selectable widgets, selected widgets)
        show_hidden -- If True, hidden files are shown by default.
        """

        self.directory = abspath(directory)
        self.file = ""
        self.attr = attr
        self.height = height
        self.show_hidden = show_hidden

        # Create dummy widgets for directory and file display:
        self.dir_widget = AttrWrap(
            BoxAdapter(ListBox([self._blank]), self.height), self.attr[0])
        self.file_widget = AttrWrap(
            BoxAdapter(ListBox([self._blank]), self.height), self.attr[0])

        columns = Columns([self.dir_widget, self.file_widget], 1)

        # Selection widget:
        self.select_widget = AttrWrap(Edit("", ""), self.attr[0], self.attr[1])

        # Buttons and checkbox:
        button_widgets = [
            AttrWrap(Button(button, self._action), attr[0], attr[1])
            for button in ["OK", "Cancel"]
        ]
        button_grid = GridFlow(button_widgets, 12, 2, 1, 'center')

        button_cols = Columns([
            CheckBox(self.SHOW_HIDDEN_TEXT, self.show_hidden, False,
                     self._toggle_hidden), button_grid
        ])

        self.outer_widget = Pile([
            columns, self._blank,
            Text(self.SELECTION_TEXT), self.select_widget, self._blank,
            button_cols
        ])

        self.update_widgets()

        WidgetWrap.__init__(self, self.outer_widget)
Example #23
0
 def refresh(self):
     tMap = self._keyMap
     res = []
     if self._state is not None:
         n, tMap = self._state
         w = AttrWrap(Text(f'{n}:'), 'style1bold')
         res.append((w, self._w.options('pack')))
         res.append(
             (HotkeyItem('esc', '',
                         on_mouseLeft=self._fire), self._w.options('pack')))
     for key, o in tMap.items():
         res.append(
             (HotkeyItem(key, o[0],
                         on_mouseLeft=self._fire), self._w.options('pack')))
     self._w.contents = res
Example #24
0
    def __init__(self, opts, index=0):
        self._icon = ClickableThing(Text(""))
        self._padding = UrwidPadding(
            AttrWrap(
                Columns([
                    (1, Text('[')),
                    self._icon,
                    (3, Text('\N{BLACK DOWN-POINTING SMALL TRIANGLE} ]')),
                ],
                        dividechars=1), 'menu_button', 'menu_button focus'))

        options = []
        for opt in opts:
            options.append(Option(opt))

        self.options = options
        self._set_index(index)
        super().__init__(_Launcher(self, self._padding))
Example #25
0
    def _w_init(self):
        self.dialogLoader = DialogLoader(
            self.apiExecutor,
            self.config.user,
            query=None,
            dateStart='today',
            dateEnd=True,
            direction=-1,
            limitDates=5,
            limitResults=5,
        )
        self.dialogs = DialogList(self.dialogLoader)

        self.sidebar_filters = FiltersList({
            k: dict(v, type=v['type'].split('.', 1)[1])
            for k, v in self.config.filters.items()
            if v['type'].startswith('sidebar.')
        })

        self._w = AttrWrap(
            Columns(
                [
                    ('weight', 2, self.sidebar_filters),  # sidebar
                    ('weight', 8, self.dialogs),  # wrapper
                ],
                0),
            'style0')
        self.childs += [self.dialogs, self.sidebar_filters]
        #! в будущем эта карта будет модифицироваться при смене фокуса, таким образом горячие клавиши будут контекстными
        self.hotkeys({
            'f2': ('One', self.hk_test_f1),
            'D': ('Three', lambda *_: print('HK-SHIFT-D')),
            'ctrl d': ('FourFive', lambda *_: print('HK-CTRL-D')),
            'meta d': ('FourFive', lambda *_: print('HK-ALT-D')),
            'enter': ('FourFive', lambda *_: print('HK-ENTER')),
            'm': ('Move to', {
                '1': ('One', lambda *_: print('HK-M,1')),
                '2': ('Two', lambda *_: print('HK-M,2')),
                '3': ('Three', lambda *_: print('HK-M,3')),
            }),
        })
        super()._w_init()
Example #26
0
    def __init__(self, content, default, tooltip, left_margin, source=None):
        """
        General Edit Field

        Args:
            content: text of the editbox
            default: default value of the editbox
            tooltip: tooltip of the editbox
            left_margin: left_margin of the editbox
            source: there this item is from for value reference
        """
        text = u" *  " + content + u": "
        self.core = Edit(('editcp', ""), default)
        self.source = source
        self.widget = Pile([
            Text(text),
            Padding(AttrWrap(self.core, 'editbx', 'editfc'), left=4),
            Padding(Text(tooltip), left=4)
        ])
        super().__init__(self.widget, left=2 + left_margin - 4, right=2)
Example #27
0
    def _build_widget(self, **kwargs):

        total_items = []
        for _item in self.input_items.keys():
            total_items.append(
                AttrWrap(self.input_items[_item], 'input', 'input focus'))
        self.input_lbox = ListBox(SimpleListWalker(total_items))

        # Add buttons
        self.add_buttons()
        self.container_box_adapter = BoxAdapter(self.input_lbox,
                                                len(total_items))
        self.container_lbox = ListBox(
            [self.container_box_adapter,
             Divider(), self.btn_pile])

        return LineBox(BoxAdapter(self.container_lbox,
                                  height=len(total_items) + 1 +
                                  len(self.btn_pile.contents)),
                       title=self.title)
Example #28
0
 def _get_at_pos(self, pos):
     """Return a widget for the line phone passed."""
     if pos < 0:
         # line 0 is the start of the file, no more above
         return None, None
     elif pos < len(self.lines):
         # we have that line so return it
         obj, tag = self.lines[pos]
         if isinstance(obj, (basestring, tuple, list)):
             log_text = LogText(obj or '', wrap=urwid.CLIP)
             log_text.my_tag = tag
             connect_signal(log_text, 'jump', self.on_jump)
             connect_signal(log_text, 'expand', self.on_expand)
             connect_signal(log_text, 'isolate', self.on_isolate)
             return AttrWrap(log_text, '', 'current'), pos
         else:
             return obj, pos
     else:
         # no more lines
         return None, None
Example #29
0
 def __init__(self, parent):
     self.parent = parent
     close_text = "(close)"
     close = ActionBackButton(close_text)
     connect_signal(close, "click", self.close)
     group = [Color.menu_button(close)]
     width = len(close_text)
     for i, action in enumerate(self.parent._actions):
         if action.enabled:
             if isinstance(action.label, Widget):
                 btn = action.label
             elif action.opens_dialog:
                 btn = Color.menu_button(ActionMenuOpenButton(action.label))
             else:
                 btn = Color.menu_button(ActionMenuButton(action.label))
             width = max(width, len(btn.base_widget.label))
             connect_signal(btn.base_widget, 'click', self.click,
                            action.value)
         else:
             label = action.label
             if isinstance(label, Widget):
                 label = label.base_widget.label
             width = max(width, len(label))
             if action.opens_dialog:
                 rhs = "\N{BLACK RIGHT-POINTING SMALL TRIANGLE}"
             else:
                 rhs = ""
             btn = Columns([
                 ('fixed', 1, Text("")),
                 Text(label),
                 ('fixed', 1, Text(rhs)),
             ],
                           dividechars=1)
             btn = AttrWrap(btn, 'info_minor')
         group.append(btn)
     self.width = width
     super().__init__(LineBox(ListBox(group)))
Example #30
0
 def __init__(self, phones):
     self.phone_edit = EnterEdit('Phone:', '')
     self.chan_edit = EnterEdit('Chanl:', '')
     self.call_id_edit = EnterEdit('SipID:', '')
     self.text_edit = EnterEdit('Find:', '')
     connect_signal(self.phone_edit, 'enter', self.on_change, 'phone')
     connect_signal(self.chan_edit, 'enter', self.on_change, 'chan')
     connect_signal(self.call_id_edit, 'enter', self.on_change, 'call_id')
     connect_signal(self.text_edit, 'enter', self.on_change, 'text')
     self.phones_text = Text([('key', 'F4'), ' Phones'])
     self.head = Pile([
         AttrWrap(Text([('key', 'F3'), ' Search']), 'bar'),
         AttrWrap(self.phone_edit, 'no', 'selection'),
         AttrWrap(self.chan_edit, 'no', 'selection'),
         AttrWrap(self.call_id_edit, 'no', 'selection'),
         Divider('-'),
         AttrWrap(self.text_edit, 'no', 'selection'),
         AttrWrap(self.phones_text, 'bar'),
     ])
     self.items = SimpleListWalker([])
     self.set_results(phones)
     self.listbox = ListBox(self.items)
     self.frame = Frame(self.listbox, header=self.head)
Example #31
0
 def __init__(self, text):
     AttrWrap.__init__(self, Text(text, wrap='clip'), None, 'focus')