def __init__(self, entry, window, context=None, tabhistory=[], **kwargs): super(CompletionStatusDisplay, self).__init__(entry, window, **kwargs) self.__entry = entry self.__window = window self.__context = context self.__tabhistory = tabhistory self.__token = None self.__completer = None self.__complsys = CompletionSystem() self.__current_completion = None self.__current_history = None self.__pending_completion_load = False self.__completion_display = MatchPopup(_('Completions (%s)') % ('TAB',), TabCompletionView, self.__entry, self.__window, self.__context) self.__completion_display.connect('item-selected', self.__on_completion_selected) self.__tab_history_display = MatchPopup(_('Tab History'), MatchingHistoryView, self.__entry, self.__window, self.__context) self.__tab_history_display.connect('item-selected', self.__on_histitem_selected) self.__global_history_display = MatchPopup(_('Global History Search (%s)') % ('Ctrl-R',), MatchingHistoryView, self.__entry, self.__window, self.__context) self.__global_history_display.connect('item-selected', self.__on_histitem_selected) self.__overview_visible = False self.__completion_visible = False self.__tab_history_visible = False self.__global_history_visible = False self.get_box().pack_start(self.__completion_display.get_miniview(), expand=True) self.get_box().pack_start(gtk.VSeparator(), expand=False) self.get_box().pack_start(self.__global_history_display.get_miniview(), expand=True)
def __init__(self, entry, window, context=None, tabhistory=[], **kwargs): super(CompletionStatusDisplay, self).__init__(entry, window, **kwargs) self.__entry = entry self.__window = window self.__context = context self.__tabhistory = tabhistory self.__token = None self.__completer = None self.__complsys = CompletionSystem() self.__current_completion = None self.__current_history = None self.__pending_completion_load = False self.__completion_display = MatchPopup( _('Completions (%s)') % ('TAB', ), TabCompletionView, self.__entry, self.__window, self.__context) self.__completion_display.connect('item-selected', self.__on_completion_selected) self.__tab_history_display = MatchPopup(_('Tab History'), MatchingHistoryView, self.__entry, self.__window, self.__context) self.__tab_history_display.connect('item-selected', self.__on_histitem_selected) self.__global_history_display = MatchPopup( _('Global History Search (%s)') % ('Ctrl-R', ), MatchingHistoryView, self.__entry, self.__window, self.__context) self.__global_history_display.connect('item-selected', self.__on_histitem_selected) self.__overview_visible = False self.__completion_visible = False self.__tab_history_visible = False self.__global_history_visible = False self.get_box().pack_start(self.__completion_display.get_miniview(), expand=True) self.get_box().pack_start(gtk.VSeparator(), expand=False) self.get_box().pack_start(self.__global_history_display.get_miniview(), expand=True)
class CompletionStatusDisplay(hotwidgets.TransientPopup): __gsignals__ = { "histitem-selected": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, )), "completion-selected": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, )), "completions-loaded": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []), } def __init__(self, entry, window, context=None, tabhistory=[], **kwargs): super(CompletionStatusDisplay, self).__init__(entry, window, **kwargs) self.__entry = entry self.__window = window self.__context = context self.__tabhistory = tabhistory self.__token = None self.__completer = None self.__complsys = CompletionSystem() self.__current_completion = None self.__current_history = None self.__pending_completion_load = False self.__completion_display = MatchPopup( _('Completions (%s)') % ('TAB', ), TabCompletionView, self.__entry, self.__window, self.__context) self.__completion_display.connect('item-selected', self.__on_completion_selected) self.__tab_history_display = MatchPopup(_('Tab History'), MatchingHistoryView, self.__entry, self.__window, self.__context) self.__tab_history_display.connect('item-selected', self.__on_histitem_selected) self.__global_history_display = MatchPopup( _('Global History Search (%s)') % ('Ctrl-R', ), MatchingHistoryView, self.__entry, self.__window, self.__context) self.__global_history_display.connect('item-selected', self.__on_histitem_selected) self.__overview_visible = False self.__completion_visible = False self.__tab_history_visible = False self.__global_history_visible = False self.get_box().pack_start(self.__completion_display.get_miniview(), expand=True) self.get_box().pack_start(gtk.VSeparator(), expand=False) self.get_box().pack_start(self.__global_history_display.get_miniview(), expand=True) def __on_histitem_selected(self, th, histitem): self.emit('histitem-selected', histitem) def __on_completion_selected(self, ac, compl): self.emit('completion-selected', compl) def invalidate(self): self.__token = None self.__completer = None self.__current_completion = None self.__pending_completion_load = False self.hide_all() def hide_all(self): if self.__completion_visible: self.__completion_display.hide() self.__completion_visible = False if self.__tab_history_visible: self.__tab_history_display.hide() self.__tab_history_visible = False if self.__global_history_visible: self.__global_history_display.hide() self.__global_history_visible = False if self.__overview_visible: super(CompletionStatusDisplay, self).hide() self.__overview_visible = False def set_completion(self, completer, text, context): if text == self.__token and completer == self.__completer: return _logger.debug("new completion: %s", text) self.invalidate() self.__token = text self.__completer = completer if completer: self.__complsys.async_complete(completer, text, context.get_cwd(), self.__completions_result) def completion_request(self): if self.__current_completion is not None: if not self.__completion_visible: self.hide_all() self.__completion_visible = True self.__completion_display.show() self.__completion_display.reposition() self.__completion_display.queue_reposition() return self.__current_completion if self.__completer: self.hide_all() self.__pending_completion_load = True return True return None def show(self): self.__overview_visible = True super(CompletionStatusDisplay, self).show() self.reposition() self.queue_reposition() def hide(self): self.__overview_visible = False super(CompletionStatusDisplay, self).hide() def __completions_result(self, completer, text, results): if not (text == self.__token and completer == self.__completer): _logger.debug("stale completion result") return self.__current_completion = results self.__completion_display.set_content( self.__current_completion.results) if self.__pending_completion_load: self.__current_completion = results self.emit('completions-loaded') self.__pending_completion_load = False else: if self.__current_completion.results or self.__current_history: self.show() self.queue_reposition() def _set_size_request(self): (ref_x, ref_y, ref_w, ref_h, bits) = self.__entry.get_parent_window().get_geometry() _logger.debug("setting size request width to %d*0.75", ref_w) self.set_size_request((int(ref_w * 0.75)), -1) def set_history_search(self, lang_uuid, histsearch): histitems = map( lambda result: (lang_uuid, result), self.__context.history.search_commands(lang_uuid, histsearch)) self.__current_history = not not histitems self.__global_history_display.set_content(histitems, uniquify=True) self.__global_history_display.set_matchtext(histsearch) def popup_tab_history(self): if self.__tab_history_visible: return _logger.debug("doing tab history popup") self.hide() self.__tab_history_display.set_content(self.__tabhistory, uniquify=False) self.__tab_history_display.reposition() self.__tab_history_display.queue_reposition() self.__tab_history_visible = True self.__tab_history_display.show() def popup_global_history(self): if self.__global_history_visible: return self.hide() self.__global_history_display.reposition() self.__global_history_display.queue_reposition() self.__global_history_visible = True self.__global_history_display.show() def get_state(self): if self.__tab_history_visible: return 'tabhistory' elif self.__global_history_visible: return 'globalhistory' elif self.__completion_visible: return 'completions' return None def select_next(self): if self.__tab_history_visible: self.__tab_history_display.select_next() return True elif self.__global_history_visible: self.__global_history_display.select_next() return True elif self.__completion_visible: self.__completion_display.select_next() return True return False def select_prev(self): if self.__tab_history_visible: self.__tab_history_display.select_prev() return True elif self.__global_history_visible: self.__global_history_display.select_prev() return True elif self.__completion_visible: self.__completion_display.select_prev() return True return False def page_up(self): if self.__tab_history_visible: self.__tab_history_display.page_up() return True elif self.__global_history_visible: self.__global_history_display.page_up() return True elif self.__completion_visible: self.__completion_display.page_up() return True return False def page_down(self): if self.__tab_history_visible: self.__tab_history_display.page_down() return True elif self.__global_history_visible: self.__global_history_display.page_down() return True elif self.__completion_visible: self.__completion_display.page_down() return True return False def activate_selected(self): if self.__tab_history_visible: self.__tab_history_display.emit_itemselected() return True elif self.__global_history_visible: self.__global_history_display.emit_itemselected() return True elif self.__completion_visible: self.__completion_display.emit_itemselected() return True return False
class CompletionStatusDisplay(hotwidgets.TransientPopup): __gsignals__ = { "histitem-selected" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)), "completion-selected" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)), "completions-loaded" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []), } def __init__(self, entry, window, context=None, tabhistory=[], **kwargs): super(CompletionStatusDisplay, self).__init__(entry, window, **kwargs) self.__entry = entry self.__window = window self.__context = context self.__tabhistory = tabhistory self.__token = None self.__completer = None self.__complsys = CompletionSystem() self.__current_completion = None self.__current_history = None self.__pending_completion_load = False self.__completion_display = MatchPopup(_('Completions (%s)') % ('TAB',), TabCompletionView, self.__entry, self.__window, self.__context) self.__completion_display.connect('item-selected', self.__on_completion_selected) self.__tab_history_display = MatchPopup(_('Tab History'), MatchingHistoryView, self.__entry, self.__window, self.__context) self.__tab_history_display.connect('item-selected', self.__on_histitem_selected) self.__global_history_display = MatchPopup(_('Global History Search (%s)') % ('Ctrl-R',), MatchingHistoryView, self.__entry, self.__window, self.__context) self.__global_history_display.connect('item-selected', self.__on_histitem_selected) self.__overview_visible = False self.__completion_visible = False self.__tab_history_visible = False self.__global_history_visible = False self.get_box().pack_start(self.__completion_display.get_miniview(), expand=True) self.get_box().pack_start(gtk.VSeparator(), expand=False) self.get_box().pack_start(self.__global_history_display.get_miniview(), expand=True) def __on_histitem_selected(self, th, histitem): self.emit('histitem-selected', histitem) def __on_completion_selected(self, ac, compl): self.emit('completion-selected', compl) def invalidate(self): self.__token = None self.__completer = None self.__current_completion = None self.__pending_completion_load = False self.hide_all() def hide_all(self): if self.__completion_visible: self.__completion_display.hide() self.__completion_visible = False if self.__tab_history_visible: self.__tab_history_display.hide() self.__tab_history_visible = False if self.__global_history_visible: self.__global_history_display.hide() self.__global_history_visible = False if self.__overview_visible: super(CompletionStatusDisplay, self).hide() self.__overview_visible = False def set_completion(self, completer, text, context): if text == self.__token and completer == self.__completer: return _logger.debug("new completion: %s", text) self.invalidate() self.__token = text self.__completer = completer if completer: self.__complsys.async_complete(completer, text, context.get_cwd(), self.__completions_result) def completion_request(self): if self.__current_completion is not None: if not self.__completion_visible: self.hide_all() self.__completion_visible = True self.__completion_display.show() self.__completion_display.reposition() self.__completion_display.queue_reposition() return self.__current_completion if self.__completer: self.hide_all() self.__pending_completion_load = True return True return None def show(self): self.__overview_visible = True super(CompletionStatusDisplay, self).show() self.reposition() self.queue_reposition() def hide(self): self.__overview_visible = False super(CompletionStatusDisplay, self).hide() def __completions_result(self, completer, text, results): if not (text == self.__token and completer == self.__completer): _logger.debug("stale completion result") return self.__current_completion = results self.__completion_display.set_content(self.__current_completion.results) if self.__pending_completion_load: self.__current_completion = results self.emit('completions-loaded') self.__pending_completion_load = False else: if self.__current_completion.results or self.__current_history: self.show() self.queue_reposition() def _set_size_request(self): (ref_x, ref_y, ref_w, ref_h, bits) = self.__entry.get_parent_window().get_geometry() _logger.debug("setting size request width to %d*0.75", ref_w) self.set_size_request((int(ref_w*0.75)), -1) def set_history_search(self, lang_uuid, histsearch): histitems = [(lang_uuid,result) for result in self.__context.history.search_commands(lang_uuid, histsearch)] self.__current_history = not not histitems self.__global_history_display.set_content(histitems, uniquify=True) self.__global_history_display.set_matchtext(histsearch) def popup_tab_history(self): if self.__tab_history_visible: return _logger.debug("doing tab history popup") self.hide() self.__tab_history_display.set_content(self.__tabhistory, uniquify=False) self.__tab_history_display.reposition() self.__tab_history_display.queue_reposition() self.__tab_history_visible = True self.__tab_history_display.show() def popup_global_history(self): if self.__global_history_visible: return self.hide() self.__global_history_display.reposition() self.__global_history_display.queue_reposition() self.__global_history_visible = True self.__global_history_display.show() def get_state(self): if self.__tab_history_visible: return 'tabhistory' elif self.__global_history_visible: return 'globalhistory' elif self.__completion_visible: return 'completions' return None def select_next(self): if self.__tab_history_visible: self.__tab_history_display.select_next() return True elif self.__global_history_visible: self.__global_history_display.select_next() return True elif self.__completion_visible: self.__completion_display.select_next() return True return False def select_prev(self): if self.__tab_history_visible: self.__tab_history_display.select_prev() return True elif self.__global_history_visible: self.__global_history_display.select_prev() return True elif self.__completion_visible: self.__completion_display.select_prev() return True return False def page_up(self): if self.__tab_history_visible: self.__tab_history_display.page_up() return True elif self.__global_history_visible: self.__global_history_display.page_up() return True elif self.__completion_visible: self.__completion_display.page_up() return True return False def page_down(self): if self.__tab_history_visible: self.__tab_history_display.page_down() return True elif self.__global_history_visible: self.__global_history_display.page_down() return True elif self.__completion_visible: self.__completion_display.page_down() return True return False def activate_selected(self): if self.__tab_history_visible: self.__tab_history_display.emit_itemselected() return True elif self.__global_history_visible: self.__global_history_display.emit_itemselected() return True elif self.__completion_visible: self.__completion_display.emit_itemselected() return True return False