def __init__(self, title, search_caption): # HEADER self.title = title self.title_text = urwid.Text(self.title) # LIST VIEW self.list_walker = urwid.SimpleFocusListWalker([]) self.list_view = PListBox(self.list_walker) self.load_default_data() self.set_data(self.default_list_data) # SEARCH BOX self.search_view = Edit(caption=search_caption) urwid.connect_signal(self.search_view, C.SUBMIT, self.filter_list) urwid.connect_signal(self.search_view, C.CANCEL, self.exit_search) self.filter_str = '' # COMMANDS c = self._command_map.copy() c['/'] = C.SEARCH c['r'] = C.REFRESH c['i'] = C.ITEM_EDIT c['a'] = C.ITEM_ADD c['d'] = C.ITEM_DEL self._command_map = c # SIGNALS urwid.register_signal(self.__class__, [C.SUBMIT, C.MESSAGE]) # MAIN VIEW self.pile = urwid.Pile([(urwid.PACK, self.title_text), (urwid.PACK, HDivider()), self.list_view]) super().__init__(self.pile)
def __init__(self, client, frequency=1, all=False): self.client = client self.frequency = frequency self.all = False urwid.register_signal(ContainerMonitor, 'container-list') self.get_count = 1 self.end_get = 0
def __init__(self, model, connection, actions=[]): self._model = model self._model_error_handler = None self._table = None self._query_editor = None self._sql_autocomplete_engine = SQLAutocompleteEngine(model) self._connection = connection self._schema_cache = schema_cache_instance self._actions = [] self._actions_to_signals = {} default_actions = [('F1', u'F1 Help', self.SIGNAL_ACTION_HELP), ('F2', u'F2 Query Editor'), ('F4', u'F4 Log', self.SIGNAL_ACTION_QUERY_LOG), ('F5', u'F5 Refresh', self.SIGNAL_ACTION_REFRESH), ('F10', u'F10 Quit', self.SIGNAL_ACTION_QUIT)] default_actions.extend(actions) self._prepare_actions_and_signals(default_actions) header = self._make_header() body = self._make_body() footer = self._make_footer() self._cmd_history_pending_cmd = None super().__init__(body, header, footer) signals = self.SIGNALS signals.extend(self._actions_to_signals.values()) urwid.register_signal(self.__class__, signals) urwid.connect_signal(self, self.SIGNAL_ACTION_REFRESH, self.refresh_model) self._connect_model_signals() self._update_breadcrumbs()
def __init__(self, p_todolist): self._todolist = p_todolist self.titleedit = urwid.Edit("Title: ", "") self.sortedit = urwid.Edit("Sort expression: ", "") self.filteredit = urwid.Edit("Filter expression: ", "") group = [] self.relevantradio = urwid.RadioButton(group, "Only show relevant todo items", True) self.allradio = urwid.RadioButton(group, "Show all todo items") self.pile = urwid.Pile([ self.filteredit, self.titleedit, self.sortedit, 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'])
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'])
def __init__(self, model: TableStore): self._model = model self._columns = [] self._layout = TableLayout() self._rowcount = len(self._model) # self._header = Header(self._model.columns) self._body = Body() urwid.connect_signal(self._body, 'keypress', self._on_body_keypress) self._footer = urwid.Text('') self._widget_size = (0, 0) self._visible_columns = 0 self._focused_row_index = 0 self._focused_col_index = 0 self._input_processor = InputProcessor() urwid.connect_signal(model, model.Signals.ROWS_LOADED, lambda *x: self.refresh()) urwid.connect_signal(model, model.Signals.ROW_INSERTED, self._on_row_inserted) urwid.connect_signal(model, model.Signals.ROW_DELETED, self._on_row_deleted) urwid.connect_signal(model, model.Signals.ROW_UPDATED, self._on_row_updated) super().__init__( self._body, # urwid.AttrMap(self._header, 'thead'), # urwid.AttrMap(self._footer, 'tfoot') ) urwid.register_signal(self.__class__, self.SIGNALS)
def __init__(self, p_text=""): urwid.register_signal(ConsoleWidget, ['close']) self.width = 0 self.pile = urwid.Pile([]) super().__init__(self.pile)
def __init__(self, ): txt1 = urwid.Text( ("Use the arrow keys to navigate the views.\n\n" "Pressing ENTER will:\n" "- upload the selected local file to the remote directory.\n" "- download the selected remote file to the local directory.\n" "There is NO overwrite confirmation.\n" "Currently you can't upload or download whole directories.\n\n" "Press F1 to display this information.\n\n" "Press F2 to execute PHP code.\n\n" "Press F3 to delete the selected file.\n" "Works for both local and remote files.\n" "There is NO delete confirmation.\n\n" "Press F4 to quit.\n\n" "Press F1 again to return to the main view.")) items = [txt1] listWalker = urwid.SimpleFocusListWalker(items) listView = urwid.ListBox(listWalker) body = urwid.LineBox(listView) urwid.register_signal(self.__class__, ["close"]) super(HelpWindow, self).__init__(body, None, None)
def register_signal_emitters(self): """ Inform urwid of which classes will be sending specific signals. """ if 'groupme' in self.configuration.config['general']['interfaces']: urwid.register_signal(GroupMeAPI, 'show-status-message') urwid.register_signal(InputArea, 'message-send')
def __init__(self, group: List[MultiRadioButton], id: int, label: Any, column_content: List[Widget], state: Any = "first True", on_state_change: Any = None, user_data: Any = None, app: ApplicationHandler = None): self._group = group self._id = id self._label = label self._column_content = column_content if type(state) is str: if str(state).lower() == 'first true': if self._id == 1: self._state = True else: self._state = state self._on_state_change = on_state_change self._user_data = user_data self.application = app self._selectable = True select_on: int = self.get_selected_id() if select_on is not None: self._state = True if select_on == self._id else False if len(self._group) >= self._id: del self._group[self._id - 1] # remove old MMI from self._group self._hidden_widget: MultiRadioButton = MultiRadioButton(self._group, self._id, self._label, self._column_content, self._state, self._on_state_change, self._user_data) self._hidden_widget.parent = self connect_signal(self._hidden_widget, 'change', self.handle_changed) self.display_widget = self._create_display_widget() super(MultiMenuItem, self).__init__(self.display_widget) register_signal(self.__class__, ['change', 'postchange']) connect_signal(self, 'change', self.mark_as_dirty)
def __init__(self, p_view, p_title, p_keymap): self._view = None self.keymap = p_keymap # store a state for multi-key shortcuts (e.g. 'gg') self.keystate = None # store offset length for postpone command (e.g. '3' for 'p3w') self._pp_offset = None self._title_widget = urwid.Text(p_title, align='center') self.todolist = urwid.SimpleFocusListWalker([]) self.listbox = urwid.ListBox(self.todolist) self.view = p_view pile = urwid.Pile([ (1, urwid.Filler(self._title_widget)), (1, urwid.Filler(urwid.Divider('\u2500'))), ('weight', 1, self.listbox), ]) pile.focus_position = 2 super().__init__(pile) urwid.register_signal(TodoListWidget, ['execute_command_silent', 'execute_command', 'refresh', 'add_pending_action', 'remove_pending_action', 'repeat_cmd', 'column_action', 'show_keystate', 'toggle_mark', ])
def __init__(self, scriptPath): self.url = urlparse(scriptPath) self.cwd = self.getCwd() urwid.register_signal(self.__class__, ["download"]) super(RemoteBrowser, self).__init__("Remote")
def __init__(self, autocomplete_engine): super().__init__(multiline=True, allow_tab=True, wrap='space') self._autocomplete_engine = autocomplete_engine self._suggestion_index = -1 self._suggestions_found = False self._last_autocomplete_text_pos = None self._start_autocomplete_markers = [' ', '\t', '.', '(', '`', '*'] urwid.register_signal(self.__class__, [self.SIGNAL_LOADING_SUGGESTIONS, self.SIGNAL_SHOW_SUGGESTIONS, self.SIGNAL_HIDE_SUGGESTIONS])
def __init__(self, tlist_data): urwid.register_signal(ColumnViewportFocusList, ColumnViewportFocusList.signals) self.tlists = ColumnViewportFocusList() urwid.connect_signal(self.tlists, 'pack', self.pack) self.build_tlists(tlist_data) self.columns = Columns([], min_width=32) super().__init__(self.columns)
def __init__(self, *args, **kwargs): self.history = [] self.history_pos = None # temporary history storage for edits before cmd execution self.history_tmp = [] super().__init__(*args, **kwargs) urwid.register_signal(CommandLineWidget, ['blur', 'execute_command'])
def _setup_signals(self): urwid.register_signal( ChannelListBox, ['exit', 'skip', 'rate', 'trash']) urwid.connect_signal(self.channel_list_box, 'exit', self.on_exit) urwid.connect_signal(self.channel_list_box, 'skip', self.on_skip) urwid.connect_signal( self.channel_list_box, 'rate', self.on_rate_and_unrate) urwid.connect_signal(self.channel_list_box, 'trash', self.on_trash)
def _setup_signals(self): urwid.register_signal(ChannelListBox, ['exit', 'skip', 'rate', 'trash']) urwid.connect_signal(self.channel_list_box, 'exit', self.on_exit) urwid.connect_signal(self.channel_list_box, 'skip', self.on_skip) urwid.connect_signal(self.channel_list_box, 'rate', self.on_rate_and_unrate) urwid.connect_signal(self.channel_list_box, 'trash', self.on_trash)
def __init__(self, model): self._model = model; self._search_input = EmacsEdit() self._tables_list = self._create_tables_list() header = urwid.Pile([urwid.AttrMap(self._search_input, 'editbox'), urwid.Divider('-')]) super().__init__(self._tables_list, header, focus_part='header') urwid.register_signal(self.__class__, [self.SIGNAL_ESCAPE, self.SIGNAL_CHANGE_TABLE]) urwid.connect_signal(self._search_input, 'change', self.filter_list) urwid.connect_signal(self._tables_list, self._tables_list.SIGNAL_SELECTED, self.on_select_table)
def _setup_signals(self): urwid.register_signal(PlayerListBox, ['quit', 'next', 'pause', 'stop', 'mute', 'volume_up', 'volume_down']) urwid.connect_signal(self.list_box, 'quit', self.on_quit) urwid.connect_signal(self.list_box, 'next', self.on_next) urwid.connect_signal(self.list_box, 'pause', self.on_pause) urwid.connect_signal(self.list_box, 'stop', self.on_stop) urwid.connect_signal(self.list_box, 'mute', self.on_mute) urwid.connect_signal(self.list_box, 'volume_up', self.on_volume_up) urwid.connect_signal(self.list_box, 'volume_down', self.on_volume_down)
def __init__(self, id, caption, description: Any = None, app: ApplicationHandler = None): Text.__init__(self, caption) self.id = id self.description = description register_signal(self.__class__, ['activate']) self.application = app
def __init__(self): self.history = History() self._cmd_strings = {} self.cmd_args_suggestions = {} self._colon_cmds = [ ('q', 'quit', self._quit), ('cc', 'clearcache', self._clear_cache) ] self._cmd_keys = {} self._autocomplete = None urwid.register_signal(self.__class__, self.SIGNAL_ERROR)
def __init__(self, address: Union[str, Tuple[str, int]], num_retries: int, retry_delay: Optional[int]) -> None: urwid.register_signal(type(self), UPDATE_MSG) self.window = Window(self) self.address = address self.aloop: Optional[asyncio.AbstractEventLoop] = None self.num_retries = num_retries self.retry_delay = retry_delay if retry_delay else 2 self.retry: bool = False self.exiting: bool = False super().__init__()
def __init__(self, connection_data, session_name=None): self.set_log_prefix('Connection') self.is_tcp = False self.database = None self._retry_count = 0 self.con = self._create_mysql_connection(connection_data) self._connection_data = connection_data try: self.session_name = connection_data['name'] except KeyError: self.session_name = session_name urwid.register_signal(self.__class__, [self.SIGNAL_EXCEPTION])
def __init__(self, opt_dict, statechange_cb): """ Args: opt_dict: InstConfigData option description dictionary. statechange_cb: 'change' signal handler for each checkbox. """ urwid.register_signal(OptionListWalker, ['focus_change']) item_states = [(i, d['enabled']) for i, d in opt_dict.iteritems()] item_states.sort() super(OptionListWalker, self).__init__(item_states, statechange_cb) return
def __init__(self) -> None: self.model = Model(self) self.view = View(self) # setup communication urwid.register_signal(View, ['move', 'zoom']) urwid.connect_signal(self.view, 'move', self.handle_move) urwid.connect_signal(self.view, 'zoom', self.handle_zoom) # setup remaining things screen = urwid.raw_display.Screen() self.screen_size = screen.get_cols_rows()
def __init__(self, caption, size): tCaption = urwid.Text(caption) tSize = urwid.Text(size, "right") horiz = urwid.Columns([("pack", tCaption), tSize]) self.value = caption self.isDir = (size == "DIR") urwid.register_signal(self.__class__, ["activate"]) super(Item, self).__init__(horiz, None, "focus")
def __init__(self, callbacks, prompt=">> "): input_prompt = ('fixed', len(prompt), urwid.Text(('input_prompt', prompt))) text_field = urwid.Edit(multiline=True, allow_tab=True) super().__init__(urwid.Columns([input_prompt, text_field])) self.text_field = self._w[1] urwid.register_signal(self.__class__, 'send_message') urwid.connect_signal(self, 'send_message', callbacks['on_send_message']) urwid.register_signal(self.__class__, 'paste_text') urwid.connect_signal(self, 'paste_text', callbacks['on_paste_text'])
def __init__(self, player=None): # init variables, objects self.palette = [("body", "yellow", ""), ("focus", "black", "brown")] self.player = player self.playlist = Playlist() self.searchlist = Searchlist() self.prompt = Prompt() self.top = Top(self.player) self.window = urwid.Frame(self.playlist.get_box(), self.top, self.prompt) self.screen = urwid.raw_display.Screen() # setting up signals urwid.register_signal(Prompt, ["perform_search", "cancel_input"]) urwid.register_signal(Searchlist, ["add_track", "play_track"]) urwid.register_signal(Playlist, ["play_track"]) urwid.register_signal(urwid.Frame, ["set_volume"]) urwid.connect_signal(self.prompt, "perform_search", self.search_callback) urwid.connect_signal(self.prompt, "cancel_input", self.cancel_input_callback) urwid.connect_signal(self.searchlist, "add_track", self.add_track_callback) urwid.connect_signal(self.searchlist, "play_track", self.play_track_callback) urwid.connect_signal(self.searchlist, "play_track", self.top.play_track_callback) urwid.connect_signal(self.playlist, "play_track", self.play_track_callback) urwid.connect_signal(self.playlist, "play_track", self.top.play_track_callback) urwid.connect_signal(self.window, "set_volume", self.top.set_volume_callback) # starting the main loop self.loop = urwid.MainLoop(self.window, self.palette, unhandled_input=self._handle_global_input) self.loop.set_alarm_in(0.5, self.top.update)
def main_window(self): # initialize front page view self.header = Header(self, 'Front Page', self.tab_list) self.page_content_list += self.header.header_content self.post_generator = self.model.get_subreddit_posts() self.post_content = urwid.BoxAdapter( PostBody(self, self.post_generator), 43) self.page_content = urwid.ListBox( urwid.SimpleFocusListWalker(self.header.header_content + [self.post_content])) self.page_content.set_focus(4) self.frame = urwid.Frame(self.page_content, footer=self.sub_footer) self.page_list.append(self.frame.contents['body']) urwid.register_signal(self, self.auth_signals) return self.frame
def __init__(self, p_completer, *args, **kwargs): self.history = [] self.history_pos = None # temporary history storage for edits before cmd execution self.history_tmp = [] self.completer = p_completer self.completion_box = CompletionBoxWidget() self._surrounding_text = None # text before insertion of completion super().__init__(*args, **kwargs) urwid.register_signal(CommandLineWidget, [ 'blur', 'execute_command', 'show_completions', 'hide_completions' ])
def __init__(self, p_completer, *args, **kwargs): self.history = [] self.history_pos = None # temporary history storage for edits before cmd execution self.history_tmp = [] self.completer = p_completer self.completion_box = CompletionBoxWidget() self._surrounding_text = None # text before insertion of completion super().__init__(*args, **kwargs) urwid.register_signal(CommandLineWidget, ['blur', 'execute_command', 'show_completions', 'hide_completions'])
def __init__(self, widget, attrmap=None, focusmap=None, keymap={}, selectable=True, *args, **kwargs): cls = widget.__class__ signals = urwid.signals._signals._supported[cls] for signal in signals: urwid.register_signal(MappedWrap, signal) self.__dict__['_widget'] = widget self.__dict__['keymap'] = dict(keymap) self.__dict__['_s'] = selectable super(MappedWrap, self).__init__(widget, attrmap, focusmap, *args, **kwargs)
def __init__(self, model): self._model = model self._rowcount = len(self._model) self._header = THeader(self._model.columns) self._body = self.make_body() self._footer = urwid.Text('') self._widget_size = None self._visible_columns = 0 self._focused_row_index = 0 self._focused_col_index = 0 self._input_processor = InputProcessor() urwid.connect_signal(model, model.SIGNAL_LOAD, self.refresh) super().__init__(self._body, urwid.AttrMap(self._header, 'theader'), urwid.AttrMap(self._footer, 'tfooter')) urwid.register_signal(self.__class__, self.SIGNALS) self._update_footer()
def __init__(self, actions, command_processor=None): self._action_bar = urwid.AttrMap(ActionBar(actions), 'action_bar') self._message_bar = urwid.AttrMap(urwid.Text(''), 'info_message') self._command_bar = None self._command_processor = None self._clear_error_timer = None if command_processor is not None: self._command_processor = command_processor command_bar = CommandEdit(command_processor) self._command_bar = urwid.AttrMap(command_bar, 'command_bar') urwid.connect_signal(command_bar, command_bar.SIGNAL_CANCEL, self.cancel_command_edit) urwid.connect_signal(command_processor, command_processor.SIGNAL_ERROR, self.show_command_error) super().__init__(self._action_bar) urwid.register_signal(self.__class__, self.SIGNAL_EXIT_COMMAND_MODE)
def __init__(self, jid, password): sleekxmpp.ClientXMPP.__init__(self, jid, password) # The session_start event will be triggered when # the bot establishes its connection with the server # and the XML streams are ready for use. We want to # listen for this event so that we we can initialize # our roster. self.add_event_handler("session_start", self.start) self.add_event_handler("print_roster", self.print_roster) urwid.register_signal(self, ['new chats', 'new roster']) # The message event is triggered whenever a message # stanza is received. Be aware that that includes # MUC messages and error messages. self.add_event_handler("message", self.message) xmpplock.release()
def __init__(self): self.inTxt = urwid.Edit("", "", True) inFiller = urwid.Filler(self.inTxt, "top", "pack") inBox = urwid.LineBox(inFiller, "Code") self.outTxt = urwid.Text("") outFiller = urwid.Filler(self.outTxt, "top", "pack") outBox = urwid.LineBox(outFiller, "Result") self.main = urwid.Columns([inBox, outBox]) bReturn = urwid.Button("F2 Return", self.onReturn) bQuit = urwid.Button("F4 Quit", self.onQuit) bExecute = urwid.Button("F5 Execute", self.onExecute) footer = urwid.Columns([(13, bReturn), (11, bQuit), (14, bExecute)], 1) urwid.register_signal(self.__class__, ["close", "execute"]) super(CodeWindow, self).__init__(self.main, None, footer)
def draw(self): self.header_text = [('key', "Aker"), " ", ('msg', "User:"******"%s" % self.user.name), " "] self.footer_text = [('msg', "Move:"), ('key', "Up"), ",", ('key', "Down"), ",", ('key', "Left"), ",", ('key', "Right"), ",", ('key', "PgUp"), ",", ('key', "PgDn"), ",", ('msg', "Select:"), ('key', "Enter"), " ", ('msg', "Refresh:"), ('key', "F5"), " ", ('msg', "Quit:"), ('key', "F9"), " ", ('msg', "By:"), ('key', "Ahmed Nazmy")] # Define widgets self.header = Header(self.header_text) self.footer = Footer(self.footer_text) self.hostgrouplist = HostGroupList(list(self.user.hostgroups.keys())) self.hostlist = HostList(list(self.user.allowed_ssh_hosts.keys())) self.topframe = urwid.Frame(self.hostgrouplist.get_box(), header=self.header, footer=self.footer) self.screen = urwid.raw_display.Screen() # Register signals urwid.register_signal(HostList, ['connect']) urwid.register_signal(HostGroupList, ['group_chosen']) # Connect signals urwid.connect_signal(self.hostgrouplist.search, 'change', self.group_search_handler) urwid.connect_signal(self.hostgrouplist, 'group_chosen', self.group_chosen_handler) urwid.connect_signal(self.hostlist.search, 'change', self.host_search_handler) urwid.connect_signal(self.hostlist, 'connect', self.host_chosen_handler) self.loop = urwid.MainLoop(self.topframe, palette=self.palette, unhandled_input=self._input_handler, screen=self.screen, pop_ups=True)
def _setup_ui(self): email = input('豆瓣账户 (Email地址): ') password = getpass.getpass('豆瓣密码: ') api = DoubanFMApi() api.login(email, password) songs = api.get_redheart_songs() # 头部 self.title = urwid.Text('') self._update_title() divider = urwid.Divider() header = urwid.Padding(urwid.Pile([divider, self.title, divider]), left=4, right=4) # 歌曲列表 index = 0 for song in songs: self.btns.append(SongButton(song, self._on_item_pressed, index)) index += 1 self.song_listbox = SongListBox(self.btns) # 页面 self.main = urwid.Padding(urwid.Frame(self.song_listbox, header=header, footer=divider), left=4, right=4) # 注册信号回调 urwid.register_signal(SongListBox, ['exit', 'stop', 'next_song', 'change_mode']) urwid.connect_signal(self.song_listbox, 'exit', self._on_exit) urwid.connect_signal(self.song_listbox, 'stop', self.stop_song) urwid.connect_signal(self.song_listbox, 'next_song', self.next_song) urwid.connect_signal(self.song_listbox, 'change_mode', self.change_mode) self.loop = urwid.MainLoop(self.main, palette=self.palette) self.loop.screen.set_terminal_properties(colors=256)
def __init__(self, autocomplete_engine=None): editor = QueryEditor(autocomplete_engine) container = urwid.Filler(urwid.AttrMap(editor, ''), valign='top') title = u'[F9: Run. Ctrl-F9: Clear. Esc: Close. Ctrl-P/Ctrl-N: Query history. Ctrl-Shift-Up/Down: Resize editor.]' self._suggestions_widget = SuggestionsWidget() frame = urwid.Frame(body=container, footer=self._suggestions_widget) line_box = urwid.LineBox(frame, title=title, title_align='right') urwid.connect_signal(editor, editor.SIGNAL_LOADING_SUGGESTIONS, self._loading_suggestions) urwid.connect_signal(editor, editor.SIGNAL_SHOW_SUGGESTIONS, self._show_suggestions) urwid.connect_signal(editor, editor.SIGNAL_HIDE_SUGGESTIONS, self._hide_suggestions) super().__init__(line_box, 'linebox') urwid.register_signal( self.__class__, [self.SIGNAL_LOADING_SUGGESTIONS, self.SIGNAL_LOADED_SUGGESTIONS])
def __init__(self, serv_port, custom_proxy_class = None ): self._init_iparser() self.header = urwid.AttrWrap(urwid.Text(self.header_text), 'ext') self.footer = EEdit(" Current interception pattern: ") self.flowWalker = urwid.SimpleListWalker([]) self.mscreen = urwid.ListBox(self.flowWalker) self.logWalker = urwid.SimpleListWalker([]) self.eventlog = urwid.ListBox(self.logWalker) self.reqEdit = urwid.WidgetPlaceholder(urwid.Filler(urwid.Text(('ext', ' No requests intercepted yet '), align='center'), 'middle')) self.reqEditor = EEdit("", multiline=False) self.editor_locked = False self.body = urwid.WidgetPlaceholder(self.mscreen) self.view = urwid.Frame( urwid.AttrWrap(self.body, 'body'), header = self.header, footer = urwid.AttrWrap(self.footer, 'ext')) urwid.register_signal(EEdit, ['done']) urwid.connect_signal(self.footer, 'done', self._on_pattern_set) urwid.connect_signal(self.reqEditor, 'done', self._on_req_modified) self.loop = urwid.MainLoop(self.view, self.palette, unhandled_input = self.unhandled_input) if custom_proxy_class: self.proxy = custom_proxy_class(serv_port) else: self.proxy = Proxy(serv_port)
def register_signal(obj, name): if obj.__class__ not in _registered_signals: _registered_signals[obj.__class__] = [] if name not in _registered_signals[obj.__class__]: _registered_signals[obj.__class__].append(name) urwid.register_signal(obj.__class__, _registered_signals[obj.__class__])
def __init__(self, text): ur.register_signal(Search, ["search"]) super(Search, self).__init__(text)
def classmaker(cls): urwid.register_signal(cls, signals) return cls
def mainUI(friendsList, chateesList, chatHist): xmpplock.acquire() xmpplock.release() debugger_print("entered mainUI") div = urwid.Divider(".") debugger_print("What is xmpp?") debugger_print(type(globals()['xmpp'])) debugger_print(globals()['xmpp']) global xmpp chatObj = urwid.Padding(urwid.Text(chatHist), left=2, right=10) friendsText = urwid.Padding(urwid.Text("Your friends"), left=2, right=10) chateeText = urwid.Padding(urwid.Text("Open chats"), left=2, right=10) friendButtons = urwid.Pile([]) debugger_print("friendbuttons contents:") debugger_print(friendButtons.contents) chateeButtons = urwid.Pile(([])) def redraw_chat_text(data): frame.header = urwid.AttrWrap(urwid.Text( [u"Redrawing chat text"]), 'header') for z in xmpp.get_live_names_list(): alreadyInList = False for (y, r) in chateeButtons.contents: if y.original_widget.original_widget.get_label() == z: alreadyInList = True if (alreadyInList == False): chateeButtons.contents.append((urwid.Padding(urwid.AttrWrap(urwid.Button(z, chateeButtonPress), 'buttn', 'buttnf'), left=5, right =10), ('weight', 1))) global currName if (xmpp.get_name_for_jid(currName.decode('utf-8')) != None): chatHist = xmpp.return_msg_history(currName.decode('utf-8')) else: chatHist = xmpp.return_msg_history(xmpp.get_jid_for_name(currName.encode('utf-8'))) frame.header = urwid.AttrWrap(urwid.Text( [u"Got stuff for ", currName]), 'header') #resizing the list of chats' hackery here newChatHist = None effectiveLen = len(chatHist) print(chatObj.width) lenOfRows = global_height if (effectiveLen <= lenOfRows): newChatHist = chatHist else: lenOfRows = 0 - lenOfRows newChatHist = chatHist[lenOfRows:] parsedHistory = chatHistParse(newChatHist) chatObj.original_widget.set_text(parsedHistory) global write_fd def chateeButtonPress(button): frame.header = urwid.AttrWrap(urwid.Text( [u"Pressed: ", button.get_label()]), 'header') global currName currName = button.get_label() debugger_print(currName) debugger_print(type(currName)) if (xmpp.get_name_for_jid(currName.decode('utf-8')) != None): chatHist = xmpp.return_msg_history(currName.decode('utf-8')) else: chatHist = xmpp.return_msg_history(xmpp.get_jid_for_name(currName.encode('utf-8'))) parsedHistory = chatHistParse(chatHist) chatObj.original_widget.set_text(parsedHistory) def friendButtonPress(button): frame.header = urwid.AttrWrap(urwid.Text( [u"Pressed: ", button.get_label()]), 'header') for (x, r) in chateeButtons.contents: if x.original_widget.original_widget.get_label() == button.get_label(): return chateeButtons.contents.append((urwid.Padding(urwid.AttrWrap(urwid.Button(button.get_label(), chateeButtonPress), 'buttn', 'buttnf'), left=5, right =10), ('weight', 1))) xmpp.add_name_live(button.get_label()) def rosterRefresh(): friendButtons.contents = [] friendButtons.contents.extend( [(urwid.Padding(urwid.AttrWrap(urwid.Button(jid, friendButtonPress), 'buttn', 'buttnf'), left=5, right =10), ('weight', 1)) for [jid, name] in name_jid_map]) urwid.register_signal(TermTalk, ['new chats', 'new roster']) urwid.connect_signal(xmpp, 'new chats', redraw_chat_text) urwid.connect_signal(xmpp, 'new roster', rosterRefresh) friend = urwid.Pile([friendsText, friendButtons]) chatee = urwid.Pile([chateeText, chateeButtons]) text_edit_padding = ('editcp', u"Type: ") editObj = urwid.Edit(text_edit_padding, "") textEntry = urwid.Padding(urwid.AttrWrap(editObj, 'editbx,', 'editfc'), left = 2, width = global_width) foot = urwid.Pile([div, textEntry]) allFriendsList = urwid.Columns([friend, chatee]) listbox_content = [ div, allFriendsList, div, chatObj] listbox = urwid.ListBox(urwid.SimpleListWalker(listbox_content)) frame = urwid.Frame(urwid.AttrWrap(listbox,'body'), footer=foot) if urwid.web_display.is_web_request(): screen = urwid.web_display.Screen() else: screen = urwid.raw_display.Screen() def unhandled(key): if key == "enter": frame.header = urwid.AttrWrap(urwid.Text( [u"Typed: ", editObj.text[6:]]), 'header') #####instead call that function do that thing global currName if currName != None and currName != "": xmpp.send_curr_message(editObj.text[6:]) else: frame.header = urwid.AttrWrap(urwid.Text( [u"currName?: ", currName]), 'header') editObj.set_edit_text("") palette = [ ('buttnf', 'dark blue', "white", "bold"), ('buttn', 'white', 'dark blue'), ('header', 'white', 'dark cyan', 'bold') ] debugger_print("about to exit mainUI") loop = urwid.MainLoop(frame, palette, unhandled_input=unhandled) write_fd = loop.watch_pipe(redraw_chat_text) loop.run() exit()
def __init__(self, p_widget_list, p_focus_item=None): urwid.register_signal(MainPile, ['blur_console']) super().__init__(p_widget_list, p_focus_item)
def __init__(self, ui_debug=False, ipc=None): # init logging # Palette maps colors to attribute specifiers # All UI-Elements may be assigned these attributes palette = self.load_palette() # Set Encoding to UTF-8 # usually urwid respects the system locale # but it is much more likely that the locale is wrong, # than that we ever need other encodings than utf-8. urwid.set_encoding("UTF-8") # register signals urwid.register_signal(DataFieldWidget, ["field_changed"]) urwid.register_signal(KeyframeWidget, ["frame_changed"]) signal.signal(signal.SIGTERM, self.handle_sigterm) signal.signal(signal.SIGINT, self.handle_sigint) # Set to true when a shutdown was sheduled # Set to false when a sheduled shutdown shall be aborted self.shutdown_sheduled = False # init ipc if not given if not ipc: ipc = SharedMemoryIPC() self.rec = Recorder(ipc, self, ilog) self.converter = JsonConverter() # Define the ListWalker for the list of FrameElements self.listWalker = urwid.SimpleListWalker([]) self.keyframelist = urwid.ListBox(self.listWalker) # Header of the UI-Frame (stays on top) self.headline = "Record Script - Exit:<q> Leave ConsoleWidget:<ESC> Use ConsoleWidget:<:>" self.header = urwid.Text(("caption3", self.headline)) # Footer of the UI-Frame (stays on bottom, contains the console) loglevel = config["console_log_level"] self.console = ConsoleWidget(ipc, self.rec, self, loglevel) # HelpView self.helpView = HelpView() # Motor View self.motorView = MotorViewWidget() # Motor Info View self.motorInfoProvider = MotorInfoProvider() self.motorInfoLW = urwid.SimpleListWalker([]) self.motorInfos = urwid.ListBox(self.motorInfoLW) self.motorInfoList = ScrollIndicatorWidget(self.motorInfos) # Frame View self.frameList = ScrollIndicatorWidget(self.keyframelist) # Initialise the Mainframe super(Mainframe, self).__init__(self.frameList, self.header, self.console) self.update_meta() # Select the Screen Type ('curses' or the default 'raw') if "screen" in config and config["screen"] == "curses": screen = urwid.curses_display.Screen() else: screen = urwid.raw_display.Screen() screen.set_terminal_properties(colors=256, bright_is_bold=False, has_underline=True) # Start the UI-Loop self.loop = urwid.MainLoop(self, palette, unhandled_input=self.unhandled_input, screen=screen) self.set_focus("footer") with ipc.record: if not ui_debug: self.loop.run()
super(TitledPile, self).__init__(widgets, *args, **kwargs) if not self.isEmpty(): self.focus_position = 1 def shiftUp(self): if self.focus_position > 1: super(TitledPile, self).shiftUp() else: urwid.emit_signal(self, 'top') def isEmpty(self): return len(self.contents) == 1 def add(self, widget): self.contents.append((widget, self.options())) if len(self.contents) == 2: self.focus_position = 1 def set(self, widgets): super(TitledPile, self).set((self.title,) + tuple(widgets)) if len(self.contents) >= 2: self.focus_position = 1 def setTitle(self, widget): self.title = widget self.contents[0] = (widget, self.options()) urwid.register_signal(TitledPile, ('shift', 'bottom', 'top')) urwid.register_signal(MappedPile, ('shift', 'bottom', 'top')) urwid.register_signal(MappedList, ('shift', 'bottom', 'top'))
signals = urwid.Edit.signals + ["prompt_enter"] def __init__(self, *args, **kwargs): self.single = False urwid.Edit.__init__(self, *args, **kwargs) def keypress(self, size, key): if self.single: urwid.emit_signal(self, "prompt_enter", self, key) elif key == "enter": urwid.emit_signal(self, "prompt_enter", self, self.get_edit_text()) else: return urwid.Edit.keypress(self, size, key) urwid.register_signal(StatusbarEdit, "prompt_enter") class Statusbar(object): """Statusbar object, ripped off from bpython.cli. This class provides the status bar at the bottom of the screen. It has message() and prompt() methods for user interactivity, as well as settext() and clear() methods for changing its appearance. The check() method needs to be called repeatedly if the statusbar is going to be aware of when it should update its display after a message() has been called (it'll display for a couple of seconds and then disappear). It should be called as:
def __init__(self): urwid.register_signal(EditSms, "send_signal") super(EditSms, self).__init__(multiline=True)
def __init__(self, *args, **kwargs): self.__super.__init__(*args, **kwargs) self._history = [] def keypress(self, size, key): if key == "enter": line = self.edit_text urwid.emit_signal(self, "line_submitted", line) self._history.append(line) self.edit_text = "" else: return self.__super.keypress(size, key) urwid.register_signal(FancyEdit, ["line_submitted"]) class DywypiShell(AsyncUrwidBridge): """Creates a Twisted-friendly urwid app that allows interacting with dywypi via a shell. """ def __init__(self, *args, **kwargs): # self.hub = kwargs.pop('hub') super(DywypiShell, self).__init__(*args, **kwargs) # TODO does this need to be a real object? a real Network instance? self.network = object() def build_toplevel_widget(self):
def __init__(self): super(MessageEdit, self).__init__(caption='> ') urwid.register_signal(MessageEdit, ['send_message', 'send_meta_message'])
signals = urwid.Edit.signals + ['prompt_enter'] def __init__(self, *args, **kwargs): self.single = False urwid.Edit.__init__(self, *args, **kwargs) def keypress(self, size, key): if self.single: urwid.emit_signal(self, 'prompt_enter', self, key) elif key == 'enter': urwid.emit_signal(self, 'prompt_enter', self, self.get_edit_text()) else: return urwid.Edit.keypress(self, size, key) urwid.register_signal(StatusbarEdit, 'prompt_enter') class Statusbar(object): """Statusbar object, ripped off from bpython.cli. This class provides the status bar at the bottom of the screen. It has message() and prompt() methods for user interactivity, as well as settext() and clear() methods for changing its appearance. The check() method needs to be called repeatedly if the statusbar is going to be aware of when it should update its display after a message() has been called (it'll display for a couple of seconds and then disappear). It should be called as: foo = Statusbar('Initial text to display')
def __init__(self, client, frequency=1, all=False): self.get_count = 1 self.client = client self.frequency = frequency self.all = False urwid.register_signal(ImageMonitor, 'image-list')
def __init__(self, *args, **kwargs): self.__super.__init__(*args, **kwargs) self._history = [] def keypress(self, size, key): if key == 'enter': line = self.edit_text urwid.emit_signal(self, 'line_submitted', line) self._history.append(line) self.edit_text = '' else: return self.__super.keypress(size, key) urwid.register_signal(FancyEdit, ['line_submitted']) class DywypiShell(UrwidProtocol): """Creates a Twisted-friendly urwid app that allows interacting with dywypi via a shell. """ # TODO i don't think client.nick should really be part of the exposed # interface; should be a .me returning a peer probably # TODO for some reason this is the client even though the thing below is # actually called a Client so we should figure this the f**k out nick = 'dywypi' def __init__(self, loop, network, *args, **kwargs): super().__init__(loop, **kwargs)
def registerSignals(self): urwid.register_signal(ui.TaskList, [ 'complete', 'newtask', 'updatetask', 'details', ]) urwid.register_signal(ui.TaskEdit, [ 'complete', 'newtask', 'updatetask', 'details', ]) urwid.register_signal(ui.TaskDetails, [ 'comment', 'loadproject', 'updatedescription', 'updatetask', 'usertypeahead', 'assigntask', 'complete', 'newtask', 'details', ]) urwid.register_signal(ui.AssigneeTypeAhead, [ 'usertypeahead', 'assigntask', ]) urwid.register_signal(ui.CommentEdit, ['comment']) urwid.register_signal(ui.DescriptionEdit, ['updatedescription']) urwid.register_signal(ui.TaskNameEdit, 'updatetask') urwid.register_signal(ui.WorkspaceMenu, 'click') urwid.register_signal(ui.ProjectList, 'loadproject')
def _signalling(cls): urwid.register_signal(cls, signals) cls.SIGNALS = signals return cls