Python urwid.emit_signal() Examples

The following are 30 code examples of urwid.emit_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: cli.py    From EvilOSX with GNU General Public License v3.0 6 votes vote down vote up
def keypress(self, size, key):
        if key == "enter":
            command = self._edit_box.edit_text

            if self._prompt_mode:
                # We're in prompt mode, return the value
                # to the queue which unblocks the prompt method.
                self._prompt_queue.put(command)
                self._prompt_mode = False
                self.clear()
            else:
                # Normal mode, call listeners.
                urwid.emit_signal(self, "line_entered", command)

            self._edit_box.edit_text = ""
        else:
            urwid.Edit.keypress(self._edit_box, size, key) 
Example #2
Source File: TodoListWidget.py    From topydo with GNU General Public License v3.0 6 votes vote down vote up
def _execute_on_selected(self, p_cmd_str, p_execute_signal):
        """
        Executes command specified by p_cmd_str on selected todo item.

        p_cmd_str should be a string with one replacement field ('{}') which
        will be substituted by id of the selected todo item.

        p_execute_signal is the signal name passed to the main loop. It should
        be one of 'execute_command' or 'execute_command_silent'.
        """
        try:
            todo = self.listbox.focus.todo
            todo_id = str(self.view.todolist.number(todo))

            urwid.emit_signal(self, p_execute_signal, p_cmd_str, todo_id)

            # force screen redraw after editing
            if p_cmd_str.startswith('edit'):
                urwid.emit_signal(self, 'refresh')
        except AttributeError:
            # No todo item selected
            pass 
Example #3
Source File: TodoListWidget.py    From topydo with GNU General Public License v3.0 6 votes vote down vote up
def resolve_action(self, p_action_str, p_size=None):
        """
        Checks whether action specified in p_action_str is "built-in" or
        contains topydo command (i.e. starts with 'cmd') and forwards it to
        proper executing methods.

        p_size should be specified for some of the builtin actions like 'up' or
        'home' as they can interact with urwid.ListBox.keypress or
        urwid.ListBox.calculate_visible.
        """
        if p_action_str.startswith(('cmd ', 'cmdv ')):
            prefix, cmd = p_action_str.split(' ', 1)
            execute_signal = get_execute_signal(prefix)

            if '{}' in cmd:
                self._execute_on_selected(cmd, execute_signal)
            else:
                urwid.emit_signal(self, execute_signal, cmd)
        else:
            self.execute_builtin_action(p_action_str, p_size) 
Example #4
Source File: components.py    From sclack with GNU General Public License v3.0 6 votes vote down vote up
def handle_floating_date(self, size):
        # No messages, no date
        if not self.focus:
            urwid.emit_signal(self, 'set_date', None)
            return
        middle, top, _ = self.calculate_visible(size, self.focus)
        row_offset, widget, focus_position, _, _ = middle
        index = focus_position - row_offset + top[0]
        all_before = self.body[:index]
        all_before.reverse()
        text_divider = None
        for row in all_before:
            if isinstance(row, TextDivider):
                text_divider = row
                break
        urwid.emit_signal(self, 'set_date', text_divider) 
Example #5
Source File: set_snooze.py    From sclack with GNU General Public License v3.0 6 votes vote down vote up
def keypress(self, size, key):
        reserved_keys = ('up', 'down', 'page up', 'page down')
        if key in reserved_keys:
            return super(SetSnoozeWidget, self).keypress(size, key)
        elif key == 'enter':
            focus = self.snooze_time_list.body.get_focus()
            if focus[0]:
                urwid.emit_signal(self, 'set_snooze_time', focus[0].id)
                urwid.emit_signal(self, 'close_set_snooze')
                return True
        elif key == 'esc':
            focus = self.snooze_time_list.body.get_focus()
            if focus[0]:
                urwid.emit_signal(self, 'close_set_snooze')
                return True

        self.header.keypress((size[0],), key) 
Example #6
Source File: components.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def set_insert_mode(self):
        urwid.emit_signal(self, 'set_insert_mode') 
Example #7
Source File: components.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def mouse_event(self, size, event, button, col, row, focus):
        if event == 'mouse press':
            now = time.time()
            if self.last_time_clicked and (now - self.last_time_clicked < 0.5):
                urwid.emit_signal(self, 'go_to_channel', self.id)
            self.last_time_clicked = now 
Example #8
Source File: components.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def mark_as_read(self, data):
        urwid.emit_signal(self, 'mark_read', data) 
Example #9
Source File: components.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def auto_scroll(self, switch):
        if type(switch) != bool:
            return

        self._auto_scroll = switch
        urwid.emit_signal(self, 'set_auto_scroll', switch) 
Example #10
Source File: components.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def mark_read_emit(self, loop, data):
        urwid.emit_signal(self, 'mark_read', data) 
Example #11
Source File: components.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def keypress(self, size, key):
        keymap = Store.instance.config['keymap']
        self.handle_floating_date(size)

        if key in (keymap['cursor_up'], keymap['cursor_down'], 'up', 'down', ):
            now = time.time()
            max_focus = self.get_focus()[1]

            if now - self.last_keypress[0] < MARK_READ_ALARM_PERIOD and self.last_keypress[1] is not None:
                if max_focus < self.last_keypress[2]:
                    max_focus = self.last_keypress[2]

                self.event_loop.remove_alarm(self.last_keypress[1])

            self.last_keypress = (
                now,
                self.event_loop.set_alarm_in(MARK_READ_ALARM_PERIOD, self.mark_read_emit, max_focus),
                max_focus
            )

        # Go to insert mode
        if key == 'down' and self.get_focus()[1] == len(self.body) - 1:
            urwid.emit_signal(self, 'set_insert_mode')
            return True

        super(ChatBoxMessages, self).keypress(size, key)

        if key in ('page up', 'page down'):
            self.auto_scroll = self.get_focus()[1] == len(self.body) - 1

        if key == keymap['cursor_up']:
            self.keypress(size, 'up')
        if key == keymap['cursor_down']:
            self.keypress(size, 'down') 
Example #12
Source File: components.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def keypress(self, size, key):
        if key == 'enter':
            urwid.emit_signal(self, 'submit_message', self.get_edit_text())
            return True
        elif key == 'up':
            urwid.emit_signal(self, 'go_to_last_message')
            return True
        return super(MessagePrompt, self).keypress(size, key) 
Example #13
Source File: components.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def mouse_event(self, size, event, button, col, row, focus):
        if event == 'mouse press':
            now = time.time()
            if self.last_time_clicked and (now - self.last_time_clicked < 0.5):
                urwid.emit_signal(self, 'select_workspace', self.number)
            self.last_time_clicked = now 
Example #14
Source File: components.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def switch_workspace(self, number):
        if number - 1 != self.selected:
            self.select(number)
            urwid.emit_signal(self, 'switch_workspace', number) 
Example #15
Source File: customUrwidClasses.py    From TerminusBrowser with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def keypress(self, size, key):
        if key == 'esc':
            urwid.emit_signal(self, 'exit_command')

        if key == 'tab':
            autoComplete(self)

        if key == 'enter':
            command = self.edit_text.strip()
            if command:
                self.edit_text = u''
                self.historyList.append(command)
                urwid.emit_signal(self, 'command_entered', command)
            self.historyIndex = len(self.historyList)
            self.edit_text = u''

        if key == 'up':
            self.historyIndex -= 1

            if self.historyIndex < 0:
                self.historyIndex = 0
            else:
                self.edit_text = self.historyList[self.historyIndex]

        if key == 'down':
            self.historyIndex += 1

            if self.historyIndex >= len(self.historyList):
                self.historyIndex = len(self.historyList)
                self.edit_text = u''
            else:
                self.edit_text = self.historyList[self.historyIndex]
        else:
            urwid.Edit.keypress(self, size, key) 
Example #16
Source File: mystations.py    From clay with GNU General Public License v3.0 5 votes vote down vote up
def start_station(self):
        """
        Start playing the selected station
        """
        urwid.emit_signal(self, 'activate', self) 
Example #17
Source File: mystations.py    From clay with GNU General Public License v3.0 5 votes vote down vote up
def item_activated(self, mystationlistitem):
        """
        Called when a specific station  is selected.
        Re-emits this event.
        """
        urwid.emit_signal(self, 'activate', mystationlistitem) 
Example #18
Source File: myplaylists.py    From clay with GNU General Public License v3.0 5 votes vote down vote up
def start_playlist(self):
        """
        Start playing the selected playlist
        """
        urwid.emit_signal(self, 'activate', self) 
Example #19
Source File: myplaylists.py    From clay with GNU General Public License v3.0 5 votes vote down vote up
def item_activated(self, myplaylistlistitem):
        """
        Called when a specific playlist is selected.
        Re-emits this event.
        """
        urwid.emit_signal(self, 'activate', myplaylistlistitem) 
Example #20
Source File: search.py    From clay with GNU General Public License v3.0 5 votes vote down vote up
def send_query(self):
        """
        Send a message to urwid to search the filled in search query
        """
        urwid.emit_signal(self, 'search-requested', self.query.edit_text) 
Example #21
Source File: songlist.py    From clay with GNU General Public License v3.0 5 votes vote down vote up
def _send_signal(self, signal):
        urwid.emit_signal(self, signal, self) 
Example #22
Source File: songlist.py    From clay with GNU General Public License v3.0 5 votes vote down vote up
def close(self, *_):
        """
        Close this menu.
        """
        urwid.emit_signal(self, 'close') 
Example #23
Source File: CommandLineWidget.py    From topydo with GNU General Public License v3.0 5 votes vote down vote up
def completion_mode(self, p_enable):
        if p_enable is True:
            urwid.emit_signal(self, 'show_completions')
        elif p_enable is False:
            self._surrounding_text = None
            if self.completion_mode:
                self.completion_box.clear()
                urwid.emit_signal(self, 'hide_completions') 
Example #24
Source File: ViewWidget.py    From topydo with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, p_todolist):
        self._todolist = p_todolist

        self.titleedit = urwid.Edit("Title: ", "")
        self.sortedit = urwid.Edit("Sort expression: ", "")
        self.groupedit = urwid.Edit("Group expression: ", "")
        self.filteredit = urwid.Edit("Filter expression: ", "")

        radiogroup = []
        self.relevantradio = urwid.RadioButton(radiogroup, "Only show relevant todo items", True)
        self.allradio = urwid.RadioButton(radiogroup, "Show all todo items")

        self.pile = urwid.Pile([
            self.filteredit,
            self.titleedit,
            self.sortedit,
            self.groupedit,
            self.relevantradio,
            self.allradio,
            urwid.Button("Save", lambda _: urwid.emit_signal(self, 'save')),
            urwid.Button("Cancel", lambda _: self.close()),
        ])

        self.reset()

        super().__init__(self.pile)

        urwid.register_signal(ViewWidget, ['save', 'close']) 
Example #25
Source File: ViewWidget.py    From topydo with GNU General Public License v3.0 5 votes vote down vote up
def close(self):
        urwid.emit_signal(self, 'close') 
Example #26
Source File: TodoListWidget.py    From topydo with GNU General Public License v3.0 5 votes vote down vote up
def keystate(self, p_keystate):
        self._keystate = p_keystate
        keystate_to_show = p_keystate if p_keystate else ''
        urwid.emit_signal(self, 'show_keystate', keystate_to_show) 
Example #27
Source File: TodoListWidget.py    From topydo with GNU General Public License v3.0 5 votes vote down vote up
def _mark_all(self):
        for todo in self.listbox.body:
            if isinstance(todo, TodoWidget):
                todo_id = str(self.view.todolist.number(todo.todo))
                urwid.emit_signal(self, 'toggle_mark', todo_id, 'mark')
                todo.mark() 
Example #28
Source File: TodoListWidget.py    From topydo with GNU General Public License v3.0 5 votes vote down vote up
def _add_pending_action(self, p_action, p_size):
        """
        Creates action waiting for execution and forwards it to the mainloop.
        """
        def generate_callback():
            def callback(*args):
                self.resolve_action(p_action, p_size)
                self.keystate = None

            return callback

        urwid.emit_signal(self, 'add_pending_action', generate_callback()) 
Example #29
Source File: CommandLineWidget.py    From topydo with GNU General Public License v3.0 5 votes vote down vote up
def _blur(self):
        self.clear()
        urwid.emit_signal(self, 'blur') 
Example #30
Source File: CommandLineWidget.py    From topydo with GNU General Public License v3.0 5 votes vote down vote up
def _emit_command(self):
        if len(self.edit_text) > 0:
            urwid.emit_signal(self, 'execute_command', self.edit_text)
            self._save_to_history()
            self.clear()