Python urwid.connect_signal() Examples

The following are 30 code examples of urwid.connect_signal(). 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: gazua.py    From ec2-gazua with MIT License 6 votes vote down vote up
def on_aws_changed(self):
        # aws
        self.aws_view.update_focus()

        # group
        urwid.disconnect_signal(self.group_view.get_walker(), "modified",
                                self.on_group_changed)
        aws_name = self.aws_view.get_selected_name()
        self.group_view.update_widgets(
            list(self.manager.instances[aws_name].keys()))
        urwid.connect_signal(self.group_view.get_walker(), "modified",
                             self.on_group_changed)

        # instance
        group_name = self.group_view.get_selected_name()
        self.instance_view.update_widgets(
            self.manager.instances[aws_name][group_name]) 
Example #2
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def get_items(self):
        q = self.session.query(self.modelclass).order_by(self._orderby)
        if self._filter:
            filt = []
            for name, value in self._filter.items():
                filt.append(getattr(self.modelclass, name).like("%{}%".format(value)))
            q = q.filter(*filt)
        items = []
        for row in q:
            disprow = []
            pk = getattr(row, str(self._pkname))
            disprow.append( ('fixed', 6, urwid.Text(str(pk))) )
            for colname in self._colnames:
                md = self.metadata[colname]
                fmt, width = self._FORMATS.get(md.coltype, ("{!s:10.10}", 10))
                disprow.append( ('fixed', width, urwid.Text(fmt.format(getattr(row, colname)))) )
            le = ListEntry(urwid.Columns(disprow, dividechars=1))
            urwid.connect_signal(le, 'activate', self._edit, pk)
            urwid.connect_signal(le, 'delete', self._delete, pk)
            items.append(le)
        return urwid.SimpleListWalker(items) 
Example #3
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def _create_relation_input(self):
        choices = dict(models.get_choices(self.session, self.modelclass, self.metadata.colname, None))
        addnew = urwid.Button("Add New")
        urwid.connect_signal(addnew, 'click', self._add_new_related)
        # Cancel
        canc = urwid.Button("Cancel")
        urwid.connect_signal(canc, 'click', self._cancel)
        butcol = urwid.Columns([AM(addnew, "buttn", "buttnf"), AM(canc, "buttn", "buttnf")])
        wlist = [butcol]
        if self.metadata.nullable:
            entry = ListEntry(urwid.Text("None (remove)"))
            urwid.connect_signal(entry, 'activate', self._single_select)
            wlist.append(entry)
        for pk, cname in choices.items():
            entry = ListEntry(urwid.Text(cname))
            urwid.connect_signal(entry, 'activate', self._single_select, pk)
            wlist.append(entry)
        listbox = urwid.ListBox(urwid.SimpleListWalker(wlist))
        return urwid.BoxAdapter(urwid.LineBox(listbox), 9) 
Example #4
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        wlist = []
        addnew = urwid.Button("Add")
        urwid.connect_signal(addnew, 'click', self._add_new_attribute)
        addnew = urwid.AttrWrap(addnew, 'selectable', 'butfocus')
        wlist.append(addnew)
        for attrib in getattr(self.row, self.metadata.colname): # list-like attribute
            entry = ListEntry(urwid.Columns(
                    [(30, urwid.Text(str(attrib.type))),
                     urwid.Text(unicode(attrib.value).encode("utf-8"))]))
            entry.attrname = attrib.type.name
            urwid.connect_signal(entry, 'activate', self._edit_attribute)
            urwid.connect_signal(entry, 'delete', self._delete)
            wlist.append(entry)
        listbox = urwid.ListBox(urwid.SimpleFocusListWalker(wlist))
        return urwid.BoxAdapter(urwid.LineBox(listbox), max(7, len(wlist)+2))

    # edit attrib 
Example #5
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        menulist = []
        # big title
        bt = urwid.BigText("Storage Editor", urwid.HalfBlock5x4Font())
        bt = urwid.Padding(bt, "center", None)
        # primary tables for editing
        self.primlist = [TableItemWidget(s) for s in self._PRIMARY_TABLES]
        for b in self.primlist:
            urwid.connect_signal(b, 'activate', self._select)
        pmenu = urwid.GridFlow(self.primlist, 20, 2, 1, "left")
        # heading blurbs
        subhead = urwid.AttrMap(urwid.Text("Select an object type to view or edit."), "subhead")
        supportsubhead = urwid.AttrMap(urwid.Text("Select a supporting object to view or edit."), "subhead")
        # secondary/support tables
        self.seclist = [TableItemWidget(s) for s in self._SUPPORT_TABLES]
        for b in self.seclist:
            urwid.connect_signal(b, 'activate', self._select)
        smenu = urwid.GridFlow(self.seclist, 25, 1, 0, "left")
        divider = urwid.Divider("-", top=1, bottom=1)
        menulist = [bt, divider, subhead, pmenu, divider, supportsubhead, smenu]
        listbox = urwid.ListBox(urwid.SimpleListWalker(menulist))
        return urwid.Frame(listbox) 
Example #6
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def get_form_buttons(self, defaultdata=None, create=False):
        ok = urwid.Button("OK")
        urwid.connect_signal(ok, 'click', self._ok, defaultdata)
        ok = AM(ok, 'selectable', 'butfocus')
        cancel = urwid.Button("Cancel")
        urwid.connect_signal(cancel, 'click', self._cancel)
        cancel = AM(cancel, 'selectable', 'butfocus')
        l = [ok, cancel]
        if create:
            ok_edit = urwid.Button("OK and Edit")
            urwid.connect_signal(ok_edit, 'click', self._ok_and_edit, defaultdata)
            ok_edit = AM(ok_edit, 'selectable', 'butfocus')
            l = [ok, ok_edit, cancel]
        else:
            l = [ok, cancel]
        butgrid = urwid.GridFlow(l, 15, 3, 1, 'center')
        return urwid.Pile([urwid.Divider(), butgrid ], focus_item=1) 
Example #7
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        wlist = []
        addnew = urwid.Button("Add")
        urwid.connect_signal(addnew, 'click', self._add_new_option)
        addnew = urwid.AttrWrap(addnew, 'selectable', 'butfocus')
        wlist.append(addnew)
        for attrib in getattr(self.row, self.metadata.colname): # list-like attribute
            entry = ListEntry(urwid.Columns(
                    [(30, urwid.Text(str(attrib.type))),
                     urwid.Text(unicode(attrib.value).encode("utf-8"))]))
            entry.attrname = attrib.type.name
            urwid.connect_signal(entry, 'activate', self._edit_option)
            urwid.connect_signal(entry, 'delete', self._delete)
            wlist.append(entry)
        listbox = urwid.ListBox(urwid.SimpleFocusListWalker(wlist))
        return urwid.BoxAdapter(urwid.LineBox(listbox), max(7, len(wlist)+2)) 
Example #8
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def _build_list(self):
        choices = get_related_choices(self.session, self.modelclass, self.metadata, None)

        #listbox.body.remove(listentry)

        #choices.update(self.currentvalue)
        wlist = []
#        current = self.currentvalue
#        for pk, cobj in choices.items():
#            if pk in current:
#                but = urwid.CheckBox(str(cobj), state=True)
#            else:
#                but = urwid.CheckBox(str(cobj), state=False)
#            urwid.connect_signal(but, 'change', self._multi_select, (pk, cobj))
#            wlist.append(but)
#        return urwid.ListBox(urwid.SimpleListWalker(wlist)) 
Example #9
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def _add_new_testequipment_ok(self, frm, data):
        eq, roles, uut = data
        dbrow = models.create(models.TestEquipment, environment=self.environmentrow, equipment=eq, UUT=uut, roles=roles)
        self.session.add(dbrow)
        try:
            self.session.commit()
        except:
            self.session.rollback()
            ex, val, tb = sys.exc_info()
            DEBUG(ex.__name__, val)
            self._emit("message", "{}: {}".format(ex.__name__, val))
        entry = ListEntry(urwid.Text(self._stringify_te(dbrow)))
        urwid.connect_signal(entry, 'activate', self._edit_testequipment)
        urwid.connect_signal(entry, 'delete', self._delete_testequipment)
        entry.testequipment = dbrow
        listbox = self._w.contents[1][0].base_widget
        listbox.body.append(entry)
        urwid.disconnect_signal(frm, 'ok', self._add_new_testequipment_ok)
        urwid.disconnect_signal(frm, 'cancel', self._add_new_testequipment_cancel)
        frm._emit("popform") 
Example #10
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        # buttons
        done = urwid.Button("Done")
        urwid.connect_signal(done, 'click', self._done_multiselect)
        done = urwid.AttrWrap(done, 'selectable', 'butfocus')
        add = urwid.Button("Add New")
        urwid.connect_signal(add, 'click', self._add_new)
        add = urwid.AttrWrap(add, 'selectable', 'butfocus')
        cancel = urwid.Button("Cancel")
        urwid.connect_signal(cancel, 'click', self._cancel)
        cancel = urwid.AttrWrap(cancel, 'selectable', 'butfocus')
        # footer and header
        header = urwid.GridFlow([done, add, cancel], 15, 3, 1, 'center')
        footer = urwid.Padding(urwid.Text(
            ("popup", "Tab to button box to select buttons. Arrow keys transfer selection.")))
        body = self._build_body()
        return urwid.Frame(body, header=header, footer=footer, focus_part="body") 
Example #11
Source File: ui.py    From sen with MIT License 6 votes vote down vote up
def run(self):
        """
        prompt for text input.
        """
        # set up widgets
        leftpart = urwid.Text(self.arguments.prompt_text, align='left')
        editpart = urwid.Edit(multiline=True, edit_text=self.arguments.initial_text)

        # build promptwidget
        edit = urwid.Columns([
            ('fixed', len(self.arguments.prompt_text), leftpart),
            ('weight', 1, editpart),
        ])
        self.ui.prompt_bar = urwid.AttrMap(edit, "main_list_dg")

        self.ui.reload_footer()
        self.ui.set_focus("footer")

        urwid.connect_signal(editpart, "change", run_command_callback,
                             user_args=[self.ui, self.docker_object]) 
Example #12
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        showeq = urwid.Text(self._testequipment.equipment.name)
        maxlen = 0
        uutcb = urwid.CheckBox("DUT/UUT", state=self._testequipment.UUT)
        urwid.connect_signal(uutcb, 'change', self._uut_select)
        blist = [AM(uutcb, "important")]
        for role in self._roles:
            label = str(role)
            maxlen = max(len(label), maxlen)
            state = role in self._testequipment.roles
            but = urwid.CheckBox(str(role), state=state)
            urwid.connect_signal(but, 'change', self._multi_select, role)
            blist.append(but)
        roleboxes = urwid.Padding(urwid.GridFlow(blist, maxlen+4, 1, 0, "left"))
    #    # buttons
        ok, cancel = self.get_form_buttons()
        buts = urwid.Columns([(10, ok), (10, cancel)], dividechars=1, focus_column=0)
        div = urwid.Divider()
        return urwid.ListBox(urwid.SimpleListWalker([AM(showeq, "flagged"), div, roleboxes, div, buts])) 
Example #13
Source File: gazua.py    From ec2-gazua with MIT License 6 votes vote down vote up
def _init_views(self):
        aws_names = list(self.manager.aws_names)
        self.aws_view = AWSView(aws_names)

        aws_name = self.aws_view.get_selected_name()
        group_names = list(self.manager.instances[aws_name].keys())
        self.group_view = GroupView(group_names)

        group_name = self.group_view.get_selected_name()
        init_instances = self.manager.instances[aws_name][group_name]
        self.instance_view = InstanceView(init_instances)

        urwid.connect_signal(self.aws_view.get_walker(), "modified",
                             self.on_aws_changed)
        urwid.connect_signal(self.group_view.get_walker(), "modified",
                             self.on_group_changed)

        self.view = Columns([
            (15, self.aws_view.get_widget()),
            (25, self.group_view.get_widget()),
            self.instance_view.get_widget()
        ]) 
Example #14
Source File: app.py    From sclack with GNU General Public License v3.0 6 votes vote down vote up
def mount_chatbox(self, executor, channel):
        yield from asyncio.gather(
            loop.run_in_executor(executor, self.store.load_channel, channel),
            loop.run_in_executor(executor, self.store.load_messages, channel)
        )
        messages = self.render_messages(self.store.state.messages)
        header = self.render_chatbox_header()
        self._loading = False
        self.sidebar.select_channel(channel)
        self.message_box = MessageBox(
            user=self.store.state.auth['user'],
            is_read_only=self.store.state.channel.get('is_read_only', False)
        )
        self.chatbox = ChatBox(messages, header, self.message_box, self.urwid_loop)
        urwid.connect_signal(self.chatbox, 'set_insert_mode', self.set_insert_mode)
        urwid.connect_signal(self.chatbox, 'mark_read', self.handle_mark_read)
        urwid.connect_signal(self.chatbox, 'open_quick_switcher', self.open_quick_switcher)
        urwid.connect_signal(self.chatbox, 'open_set_snooze', self.open_set_snooze)

        urwid.connect_signal(self.message_box.prompt_widget, 'submit_message', self.submit_message)
        urwid.connect_signal(self.message_box.prompt_widget, 'go_to_last_message', self.go_to_last_message)

        self.real_time_task = loop.create_task(self.start_real_time()) 
Example #15
Source File: buttons.py    From zulip-terminal with Apache License 2.0 6 votes vote down vote up
def __init__(self, controller: Any, caption: str,
                 show_function: Callable[..., Any], width: int,
                 prefix_character: Union[str, Tuple[Any, str]]='\N{BULLET}',
                 text_color: Optional[str]=None,
                 count: int=0) -> None:
        if isinstance(prefix_character, tuple):
            prefix = prefix_character[1]
        else:
            prefix = prefix_character
        assert len(prefix) in (0, 1)
        self._caption = caption
        self.prefix_character = prefix_character
        self.post_prefix_spacing = ' ' if prefix else ''
        self.count = count

        prefix_length = 0 if prefix == '' else 2
        # Space either side, at least one space between
        self.width_for_text_and_count = width - 3 - prefix_length

        self.text_color = text_color
        self.show_function = show_function
        super().__init__("")
        self.update_count(count)
        self.controller = controller
        urwid.connect_signal(self, 'click', self.activate) 
Example #16
Source File: widgets.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def build_attribute_input(self, colmd, data):
        wid = AttributeInput(self.session, self.modelclass, colmd, self.row)
        urwid.connect_signal(wid, "pushform", self._subform)
        urwid.connect_signal(wid, 'message', self._message)
        wid.colname = colmd.colname
        return wid 
Example #17
Source File: app.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def configure_screen(self, screen):
        screen.set_terminal_properties(colors=self.store.config['colors'])
        screen.set_mouse_tracking()
        if self.workspaces_line is not None:
            urwid.connect_signal(self.workspaces_line, 'switch_workspace', self.switch_to_workspace) 
Example #18
Source File: app.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def open_quick_switcher(self):
        if not self.quick_switcher:
            self.quick_switcher = QuickSwitcher(self.urwid_loop.widget, self.urwid_loop)
            urwid.connect_signal(self.quick_switcher, 'go_to_channel', self.go_to_channel)
            self.urwid_loop.widget = self.quick_switcher 
Example #19
Source File: app.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def open_set_snooze(self):
        if not self.set_snooze_widget:
            self.set_snooze_widget = SetSnoozeWidget(self.urwid_loop.widget, self.urwid_loop)
            urwid.connect_signal(self.set_snooze_widget, 'set_snooze_time', self.handle_set_snooze_time)
            urwid.connect_signal(self.set_snooze_widget, 'close_set_snooze', self.handle_close_set_snooze)
            self.urwid_loop.widget = self.set_snooze_widget 
Example #20
Source File: app.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def render_chatbox_header(self):

        if self.store.state.channel['id'][0] == 'D':
            user = self.store.find_user_by_id(self.store.state.channel['user'])
            header = ChannelHeader(
                name=user.get('display_name') or user.get('real_name') or user['name'],
                topic=user['profile']['status_text'],
                is_starred=self.store.state.channel.get('is_starred', False),
                is_dm_workaround_please_remove_me=True
            )
        else:
            are_more_members = False
            if self.store.state.members.get('response_metadata', None):
                if self.store.state.members['response_metadata'].get('next_cursor', None):
                    are_more_members = True
            header = ChannelHeader(
                name=self.store.state.channel['name'],
                topic=self.store.state.channel['topic']['value'],
                num_members=len(self.store.state.members['members']),
                more_members=are_more_members,
                pin_count=self.store.state.pin_count,
                is_private=self.store.state.channel.get('is_group', False),
                is_starred=self.store.state.channel.get('is_starred', False)
            )
            urwid.connect_signal(header.topic_widget, 'done', self.on_change_topic)
        return header 
Example #21
Source File: widgets.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def build(self):
        choices = sorted(self._attribute_types.keys())
        ls = ListScrollSelector(choices)
        urwid.connect_signal(ls, 'change', self._update_desc)
        ls = AM(ls, "selectable", "butfocus")
        te = urwid.Edit(edit_text="", multiline=True, allow_tab=True)
        ok, cancel = self.get_form_buttons()
        cols = urwid.Columns([ls, ("weight", 2, te), (10, ok), (10, cancel)], dividechars=1, focus_column=0)
        self.descw = urwid.Text(self._attribute_types[choices[0]].description)
        return urwid.Pile([cols, self.descw]) 
Example #22
Source File: __main__.py    From upass with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, caption, callback):
        """Initialize a button."""
        super(PasswordButton, self).__init__("")
        self.caption = caption[:-len('.gpg')]
        urwid.connect_signal(self, 'click', callback, self.caption)
        self._w = urwid.AttrMap(urwid.SelectableIcon(
            [u'├ ', self.caption], 0), 'button', 'button_reversed') 
Example #23
Source File: widgets.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def _subform(self, oldform, newform):
        urwid.connect_signal(newform, 'popform', self._popform)
        urwid.connect_signal(newform, 'message', self._message)
        ovl = urwid.Overlay(urwid.LineBox(newform), self._w,
                "center", ("relative", 80), "middle", ("relative", 80), min_width=40, min_height=20)
        self._w = ovl 
Example #24
Source File: widgets.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def get_form_buttons(self):
        ok = urwid.Button("OK")
        urwid.connect_signal(ok, 'click', self._ok)
        ok = AM(ok, 'selectable', 'butfocus')
        cancel = urwid.Button("Cancel")
        urwid.connect_signal(cancel, 'click', self._cancel)
        cancel = AM(cancel, 'selectable', 'butfocus')
        return ok, cancel 
Example #25
Source File: widgets.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def _create_equipment_input(self):
        choices = self.session.query(models.Equipment).order_by("name")
        wlist = []
        for row in choices:
            entry = ListEntry(urwid.Text(row.name))
            urwid.connect_signal(entry, 'activate', self._eq_select, row)
            wlist.append(entry)
        listbox = urwid.ListBox(urwid.SimpleListWalker(wlist))
        return urwid.BoxAdapter(urwid.LineBox(listbox), 9) 
Example #26
Source File: widgets.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def get_form_buttons(self):
        ok = urwid.Button("OK")
        urwid.connect_signal(ok, 'click', self._ok)
        ok = AM(ok, 'selectable', 'butfocus')
        cancel = urwid.Button("Cancel")
        urwid.connect_signal(cancel, 'click', self._cancel)
        cancel = AM(cancel, 'selectable', 'butfocus')
        return ok, cancel 
Example #27
Source File: widgets.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def build(self):
        wlist = []
        entry = ListEntry(urwid.Text("None (cancel)"))
        urwid.connect_signal(entry, 'activate', self._cancel)
        wlist.append(entry)
        for intf in models.Interface.select_unattached(self.session):
            wlist.append(self._get_intf_entry(intf))
        return urwid.ListBox(urwid.SimpleListWalker(wlist)) 
Example #28
Source File: widgets.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def _add_new(self, b):
        colname = self.metadata.colname
        relmodel = getattr(self.modelclass, colname).property.mapper.class_
        newform = get_create_form(self.session, relmodel)
        urwid.connect_signal(newform, 'popform', self._popsubform)
        urwid.connect_signal(newform, 'message', self._message)
        ovl = urwid.Overlay(urwid.LineBox(newform), self._w,
                "center", ("relative", 90), "middle", ("relative", 90), min_width=40, min_height=20)
        self._w = ovl 
Example #29
Source File: widgets.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def _build_list(self):
        choices = get_related_choices(self.session, self.modelclass, self.metadata, None)
        choices.update(self.currentvalue)
        wlist = []
        current = self.currentvalue
        for pk, cobj in choices.items():
            if pk in current:
                but = urwid.CheckBox(str(cobj), state=True)
            else:
                but = urwid.CheckBox(str(cobj), state=False)
            urwid.connect_signal(but, 'change', self._multi_select, (pk, cobj))
            wlist.append(but)
        return urwid.ListBox(urwid.SimpleListWalker(wlist)) 
Example #30
Source File: widgets.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def _get_intf_entry(self, intf):
        entry = ListEntry(urwid.Text(unicode(intf).encode("utf-8")))
        urwid.connect_signal(entry, 'activate', self._sel_interface)
        entry.interface = intf
        return entry