class ListSelectView(SlaveView): """ ListSelectView for selecting an item from a list. """ gsignal('selection-changed', object) def __init__(self, items, column_name='name'): self.column_name = column_name self.items = items super(SlaveView, self).__init__() def create_ui(self): self.widget = gtk.VBox() columns = [Column(attr=self.column_name, sortable=True, editable=False, resizeable=True)] self.list_box = ObjectList(columns) for item in self.items: self.add_item(item) s = self.list_box.get_selection() s.set_mode(gtk.SELECTION_MULTIPLE) self.list_box.show_all() self.widget.pack_start(self.list_box) def add_item(self, item): item_object = DictAsAttrProxy({self.column_name: str(item)}) self.list_box.append(item_object) def selected_items(self): return [i.as_dict.values()[0] for i in self.list_box.selected_items] def on_list_box__selection_changed(self, *args, **kwargs): self.emit('selection-changed', self.selected_items())
class TodoView(PidaView): key = 'todo.list' label_text = _('TODO') icon_name = 'accessories-text-editor' def create_ui(self): self.todo_list = ObjectList([ Column('line', sorted=True), Column('todo', resizable=True, width=200, tooltip_attr='todo'), Column('marker', width=50), ]) self.add_main_widget(self.todo_list) self.todo_list.show_all() def clear_items(self): gcall(self.todo_list.clear) def add_item(self, todo, line, marker): self.todo_list.append(TodoItem(todo, line, marker)) def on_todo_list__item_activated(self, olist, item): self.svc.boss.editor.cmd('goto_line', line=item.line) def can_be_closed(self): self.svc.get_action('show_todo').set_active(False)
class ValidatorView(PidaView): key = 'language.validator' icon_name = 'python-icon' label_text = _('Validator') def create_ui(self): self._last_selected = None self.document = None self.tasks = {} self.restart = False self.errors_ol = ObjectList([Column('markup', use_markup=True)]) self.errors_ol.set_headers_visible(False) self.scrolled_window = gtk.ScrolledWindow() self.scrolled_window.show() self.scrolled_window.add(self.errors_ol) self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.add_main_widget(self.scrolled_window) self.errors_ol.show_all() self.sort_combo = AttrSortCombo( self.errors_ol, [ ('lineno', _('Line Number')), ('message', _('Message')), ('type_', _('Type')), ], 'lineno', ) self.sort_combo.show() self.add_main_widget(self.sort_combo, expand=False) def set_validator(self, validator, document): # this is quite an act we have to do here because of the many cornercases # 1. Jobs once started run through. This is for caching purpuses as a validator # is supposed to cache results, somehow. # 2. buffers can switch quite often and n background jobs are still # running # set the old task job to default priorty again old = self.tasks.get(self.document, None) if old: old.priority = PRIO_LOW self.document = document self.clear() if self.tasks.has_key(document): # set the priority of the current validator higher, so it feels # faster on the current view if self.svc.boss.window.paned.is_visible_pane(self.pane): prio = PRIO_FOREGROUND else: prio = PRIO_DEFAULT self.tasks[document].priorty = prio # when restart is set, the set_validator is run again so the # list gets updated from the validator cache. this happens when # the buffer switched to another file and back again self.restart = True self.svc.log.debug(_('Validator task for {doc} already running'), doc=document) return self.restart = False if validator: def wrap_add_node(document, *args): # we need this proxy function as a task may be still running in # background and the document already switched # this way we still can fill up the cache by letting the task run # sometimes args have a lengh of 0 so we have to catch this if self.document == document and args: item = args[0] self.add_node(item) if self._last_selected: if self._last_selected[0] == self.document: if item.lineno == self._last_selected[1]: self.errors_ol.selected_item = item def on_complete(document, validator): del self.tasks[document] # refire the task and hope the cache will just display stuff, # elsewise the task is run again validator.sync() if document == self.document and self.restart: self.set_validator(validator, document) radd = partial(wrap_add_node, document) rcomp = partial(on_complete, document, validator) if self.svc.boss.window.paned.is_visible_pane(self.pane): prio = PRIO_FOREGROUND else: prio = PRIO_DEFAULT task = GeneratorTask(validator.run_cached, radd, complete_callback=rcomp, priority=prio) self.tasks[document] = task task.start() def add_node(self, node): if node: node.lookup_color = self.errors_ol.style.lookup_color self.errors_ol.append(node) def clear(self): self.errors_ol.clear() def on_errors_ol__selection_changed(self, ol): item = ol.selected_item # may be None self._last_selected = (self.document, getattr(item, 'lineno', 0)) def on_errors_ol__item_activated(self, ol, item): self.svc.boss.editor.cmd('goto_line', line=int(item.lineno)) def can_be_closed(self): self.svc.get_action('show_validator').set_active(False)
class ValidatorView(PidaView): key = 'language.validator' icon_name = 'python-icon' label_text = _('Validator') def create_ui(self): self._last_selected = None self.document = None self.tasks = {} self.restart = False self.errors_ol = ObjectList([ Column('markup', use_markup=True) ]) self.errors_ol.set_headers_visible(False) self.scrolled_window = gtk.ScrolledWindow() self.scrolled_window.show() self.scrolled_window.add(self.errors_ol) self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.add_main_widget(self.scrolled_window) self.errors_ol.show_all() self.sort_combo = AttrSortCombo( self.errors_ol, [ ('lineno', _('Line Number')), ('message', _('Message')), ('type_', _('Type')), ], 'lineno', ) self.sort_combo.show() self.add_main_widget(self.sort_combo, expand=False) def set_validator(self, validator, document): # this is quite an act we have to do here because of the many cornercases # 1. Jobs once started run through. This is for caching purpuses as a validator # is supposed to cache results, somehow. # 2. buffers can switch quite often and n background jobs are still # running # set the old task job to default priorty again old = self.tasks.get(self.document, None) if old: old.priority = PRIO_LOW self.document = document self.clear() if self.tasks.has_key(document): # set the priority of the current validator higher, so it feels # faster on the current view if self.svc.boss.window.paned.is_visible_pane(self.pane): prio = PRIO_FOREGROUND else: prio = PRIO_DEFAULT self.tasks[document].priorty = prio # when restart is set, the set_validator is run again so the # list gets updated from the validator cache. this happens when # the buffer switched to another file and back again self.restart = True self.svc.log.debug(_('Validator task for {doc} already running'), doc=document) return self.restart = False if validator: def wrap_add_node(document, *args): # we need this proxy function as a task may be still running in # background and the document already switched # this way we still can fill up the cache by letting the task run # sometimes args have a lengh of 0 so we have to catch this if self.document == document and args: item = args[0] self.add_node(item) if self._last_selected: if self._last_selected[0] == self.document: if item.lineno == self._last_selected[1]: self.errors_ol.selected_item = item def on_complete(document, validator): del self.tasks[document] # refire the task and hope the cache will just display stuff, # elsewise the task is run again validator.sync() if document == self.document and self.restart: self.set_validator(validator, document) radd = partial(wrap_add_node, document) rcomp = partial(on_complete, document, validator) if self.svc.boss.window.paned.is_visible_pane(self. pane): prio = PRIO_FOREGROUND else: prio = PRIO_DEFAULT task = GeneratorTask(validator.run_cached, radd, complete_callback=rcomp, priority=prio) self.tasks[document] = task task.start() def add_node(self, node): if node: node.lookup_color = self.errors_ol.style.lookup_color self.errors_ol.append(node) def clear(self): self.errors_ol.clear() def on_errors_ol__selection_changed(self, ol): item = ol.selected_item # may be None self._last_selected = (self.document, getattr(item, 'lineno', 0)) def on_errors_ol__item_activated(self, ol, item): self.svc.boss.editor.cmd('goto_line', line=int(item.lineno)) def can_be_closed(self): self.svc.get_action('show_validator').set_active(False)
class PasteHistoryView(PidaView): key = 'pastebin.history' label_text = _('Paste History') icon_name = gtk.STOCK_PASTE #glade_file_name = 'paste-history.glade' def create_ui(self): self.history_tree = ObjectList( [Column('markup', use_markup=True, expand=True)]) self.history_tree.set_headers_visible(False) self.add_main_widget(self.history_tree) self.x11_clipboard = gtk.Clipboard(selection="PRIMARY") self.gnome_clipboard = gtk.Clipboard(selection="CLIPBOARD") self.history_tree.connect('item-right-clicked', self.on_paste_rclick) self.__pulse_bar = gtk.ProgressBar() self.add_main_widget(self.__pulse_bar, expand=False) # only show pulse bar if working self.__pulse_bar.hide() self.__pulse_bar.set_size_request(-1, 12) self.__pulse_bar.set_pulse_step(0.01) self.history_tree.show_all() @property def tree_selected(self): return self.history_tree.selected_item def set(self, pastes): '''Sets the paste list to the tree view. First reset it, then rebuild it. ''' self.history_tree.clear() self.history_tree.expand(pastes) self.tree_selected = None def add_paste(self, item): self.history_tree.append(item) def copy_current_paste(self): '''Callback function bound to the toolbar button view that copies the selected paste''' if self.tree_selected != None: self.x11_clipboard.set_text(self.tree_selected.get_url()) self.gnome_clipboard.set_text(self.tree_selected.get_url()) def view_current_paste(self): '''Callback function bound to the toolbar button view that shows the selected paste''' if self.tree_selected != None: self.service.boss.call_command('pastemanager', 'view_paste', paste=self.tree_selected) else: print _("ERROR: No paste selected") def remove_current_paste(self): '''Callback function bound to the toolbar button delete that removes the selected paste''' if self.tree_selected != None: self.service.boss.call_command('pastemanager', 'delete_paste', paste=self.tree_selected) else: print _("ERROR: No paste selected") def cb_paste_db_clicked(self, ol, item): """ Callback function called when an item is double clicked, and copy it to the gnome/gtk clipboard """ if item is not None: self.svc.boss.cmd('browseweb', 'browse', url=item.url) # self.__gnome_clipboard.set_text(self.__tree_selected.get_url()) # aa: view the paste def cb_paste_m_clicked(self, paste, tree_item): '''Callback function called when an item is middle clicked, and copy it to the mouse buffer clipboard''' if self.__tree_selected != None: self.__x11_clipboard.set_text(self.__tree_selected.get_url()) def cb_paste_r_clicked(self, paste, tree_item, event): menu = gtk.Menu() sensitives = (tree_item is not None) for action in [ 'pastemanager+new_paste', None, 'pastemanager+remove_paste', 'pastemanager+view_paste', None, 'pastemanager+copy_url_to_clipboard' ]: if action is None: menu.append(gtk.SeparatorMenuItem()) else: act = self.service.action_group.get_action(action) if 'new_paste' not in action: act.set_sensitive(sensitives) mi = gtk.ImageMenuItem() act.connect_proxy(mi) mi.show() menu.append(mi) menu.show_all() menu.popup(None, None, None, event.button, event.time) def on_paste_rclick(self, ol, item, event): self.svc.boss.cmd('contexts', 'popup_menu', context='url-menu', url=item.url, event=event) def start_pulse(self): '''Starts the pulse''' self._pulsing = True self.__pulse_bar.show() gobject.timeout_add(100, self._pulse) def stop_pulse(self): self.__pulse_bar.hide() self._pulsing = False def _pulse(self): self.__pulse_bar.pulse() return self._pulsing def can_be_closed(self): self.svc.get_action('show_pastes').set_active(False)
class RfcView(PidaView): key = 'rfc.list' label_text = 'RFC' def create_ui(self): self._vbox = gtk.VBox(spacing=3) self._vbox.set_border_width(6) self.add_main_widget(self._vbox) self.create_toolbar() self.create_searchbar() self.create_list() self.create_progressbar() self._vbox.show_all() def create_searchbar(self): h = gtk.HBox() self._search_description = gtk.Entry() self._search_description.connect('changed', self._on_search_changed) l = gtk.Label() l.set_text(_('Filter : ')) h.pack_start(l, expand=False) h.pack_start(self._search_description) self._vbox.pack_start(h, expand=False) self._search_description.show_all() def create_toolbar(self): self._uim = gtk.UIManager() self._uim.insert_action_group(self.svc.get_action_group(), 0) uidef_data = pkgutil.get_data(__name__, 'uidef/rfc-toolbar.xml') self._uim.add_ui_from_string(uidef_data) self._uim.ensure_update() self._toolbar = self._uim.get_toplevels('toolbar')[0] self._toolbar.set_style(gtk.TOOLBAR_ICONS) self._toolbar.set_icon_size(gtk.ICON_SIZE_SMALL_TOOLBAR) self._vbox.pack_start(self._toolbar, expand=False) self._toolbar.show_all() def create_list(self): self._list = ObjectList( [ Column('number', title=_('Number')), Column('description', title=_('Description')) ] ) self._scroll = gtk.ScrolledWindow() self._scroll.add(self._list) self._list.connect('item-activated', self._on_list_double_click) self._vbox.pack_start(self._scroll) self._list.show_all() def create_progressbar(self): self._progressbar = gtk.ProgressBar() self._progressbar.set_text(_('Download RFC Index')) self._vbox.pack_start(self._progressbar, expand=False) self._progressbar.set_no_show_all(True) self._progressbar.hide() def update_progressbar(self, current, max): if max > 1: self._progressbar.set_fraction(float(current) / float(max)) def show_progressbar(self, show): self._progressbar.set_no_show_all(False) if show: self._progressbar.show() else: self._progressbar.hide() def set_items(self, items): self._list.extend(items) def clear(self): self._list.clear() def can_be_closed(self): self.svc.get_action('show_rfc').set_active(False) def _on_list_double_click(self, ot, item): self.svc.browse(id=item.number) def _on_search_changed(self, w): self.svc.filter(self._search_description.get_text())