Exemple #1
0
class SearchDialog(Dialog):

	READY = 0
	SEARCHING = 1
	CANCELLED = 2

	def __init__(self, ui):
		Dialog.__init__(self, ui, _('Search'), # T: Dialog title
			buttons=gtk.BUTTONS_CLOSE, help='Help:Searching',
			defaultwindowsize=(400, 300)
		)

		hbox = gtk.HBox(spacing=5)
		self.vbox.pack_start(hbox, False)
		hbox.pack_start(gtk.Label(_('Search')+': '), False) # T: input label
		self.query_entry = InputEntry()
		hbox.add(self.query_entry)
		self.search_button = gtk.Button(stock=gtk.STOCK_FIND)
		hbox.pack_start(self.search_button, False)

		if gtk.gtk_version >= (2, 20) \
		and gtk.pygtk_version >= (2, 22):
			self.spinner = gtk.Spinner()
			hbox.pack_start(self.spinner, False)
		else:
			self.spinner = None

		self.cancel_button = gtk.Button(stock=gtk.STOCK_STOP)
		hbox.pack_start(self.cancel_button, False)
		self._set_state(self.READY)

		help_text = _(
			'For advanced search you can use operators like\n'
			'AND, OR and NOT. See the help page for more details.'
		) # T: help text for the search dialog
		if gtk.gtk_version >= (2, 12, 0):
			self.query_entry.set_tooltip_text(help_text)
		else:
			tooltips = gtk.Tooltips()
			tooltips.set_tip(self.query_entry, help_text)

		self.namespacecheckbox = gtk.CheckButton(_('Limit search to current namespace'))
			# T: checkbox option in search dialog
		self.vbox.pack_start(self.namespacecheckbox, False)

		# TODO advanced query editor
		# TODO checkbox _('Match c_ase')
		# TODO checkbox _('Whole _word')

		self.results_treeview = SearchResultsTreeView(self.ui)
		self.vbox.add(ScrolledWindow(self.results_treeview))

		self.search_button.connect_object('clicked', self.__class__._search, self)
		self.cancel_button.connect_object('clicked', self.__class__._cancel, self)
		self.query_entry.connect_object('activate', self.__class__._search, self)

	def search(self, query):
		'''Trigger a search to be performed.
		Because search can take a long time to execute it is best to
		call this method after the dialog is shown.

		@param query: the query as string
		'''
		self.query_entry.set_text(query)
		self._search()

	def _search(self):
		string = self.query_entry.get_text()
		if self.namespacecheckbox.get_active():
			string = 'Namespace: "%s" ' % self.ui.page.name + string
		#~ print '!! QUERY: ' + string

		self._set_state(self.SEARCHING)
		try:
			self.results_treeview.search(string)
		except Exception, error:
			ErrorDialog(self, error).run()

		if not self.results_treeview.cancelled:
			self._set_state(self.READY)
		else:
			self._set_state(self.CANCELLED)
Exemple #2
0
class SearchDialog(Dialog):

    READY = 0
    SEARCHING = 1
    CANCELLED = 2

    def __init__(self, ui):
        Dialog.__init__(
            self,
            ui,
            _('Search'),  # T: Dialog title
            buttons=gtk.BUTTONS_CLOSE,
            help='Help:Searching',
            defaultwindowsize=(400, 300))

        hbox = gtk.HBox(spacing=5)
        self.vbox.pack_start(hbox, False)
        hbox.pack_start(gtk.Label(_('Search') + ': '), False)  # T: input label
        self.query_entry = InputEntry()
        hbox.add(self.query_entry)
        self.search_button = gtk.Button(stock=gtk.STOCK_FIND)
        hbox.pack_start(self.search_button, False)

        if gtk.gtk_version >= (2, 20) \
        and gtk.pygtk_version >= (2, 22): # update in pygtk was later
            self.spinner = gtk.Spinner()
            hbox.pack_start(self.spinner, False)
        else:
            self.spinner = None

        self.cancel_button = gtk.Button(stock=gtk.STOCK_STOP)
        hbox.pack_start(self.cancel_button, False)
        self._set_state(self.READY)

        help_text = _('For advanced search you can use operators like\n'
                      'AND, OR and NOT. See the help page for more details.'
                      )  # T: help text for the search dialog
        if gtk.gtk_version >= (2, 12) \
        and gtk.pygtk_version >= (2, 12):
            self.query_entry.set_tooltip_text(help_text)
        else:
            tooltips = gtk.Tooltips()
            tooltips.set_tip(self.query_entry, help_text)

        self.namespacecheckbox = gtk.CheckButton(
            _('Limit search to the current page and sub-pages'))
        # T: checkbox option in search dialog
        self.vbox.pack_start(self.namespacecheckbox, False)

        # TODO advanced query editor
        # TODO checkbox _('Match c_ase')
        # TODO checkbox _('Whole _word')

        self.results_treeview = SearchResultsTreeView(self.ui)
        self.vbox.add(ScrolledWindow(self.results_treeview))

        self.search_button.connect_object('clicked', self.__class__._search,
                                          self)
        self.cancel_button.connect_object('clicked', self.__class__._cancel,
                                          self)
        self.query_entry.connect_object('activate', self.__class__._search,
                                        self)

    def search(self, query):
        '''Trigger a search to be performed.
		Because search can take a long time to execute it is best to
		call this method after the dialog is shown.

		@param query: the query as string
		'''
        self.query_entry.set_text(query)
        self._search()

    def _search(self):
        string = self.query_entry.get_text()
        if self.namespacecheckbox.get_active():
            string = 'Section: "%s" ' % self.ui.page.name + string
        #~ print '!! QUERY: ' + string

        self._set_state(self.SEARCHING)
        try:
            self.results_treeview.search(string)
        except Exception, error:
            ErrorDialog(self, error).run()

        if not self.results_treeview.cancelled:
            self._set_state(self.READY)
        else:
            self._set_state(self.CANCELLED)
Exemple #3
0
class SearchDialog(Dialog):

    READY = 0
    SEARCHING = 1
    CANCELLED = 2

    def __init__(self, widget, notebook, page, navigation):
        Dialog.__init__(
            self,
            widget,
            _('Search'),  # T: Dialog title
            buttons=Gtk.ButtonsType.CLOSE,
            help='Help:Searching',
            defaultwindowsize=(400, 300))
        self.page = page

        hbox = Gtk.HBox(spacing=5)
        self.vbox.pack_start(hbox, False, True, 0)
        hbox.pack_start(Gtk.Label(_('Search') + ': '), False, True,
                        0)  # T: input label
        self.query_entry = InputEntry()
        hbox.add(self.query_entry)
        self.search_button = Gtk.Button.new_with_mnemonic(
            _('_Find'))  # T: Button label
        hbox.pack_start(self.search_button, False, True, 0)

        self.spinner = Gtk.Spinner()
        hbox.pack_start(self.spinner, False, True, 0)

        self.cancel_button = Gtk.Button.new_with_mnemonic(
            _('_Cancel'))  # T: Button label
        hbox.pack_start(self.cancel_button, False, True, 0)
        self._set_state(self.READY)

        help_text = _('For advanced search you can use operators like\n'
                      'AND, OR and NOT. See the help page for more details.'
                      )  # T: help text for the search dialog
        self.query_entry.set_tooltip_text(help_text)

        self.namespacecheckbox = Gtk.CheckButton.new_with_mnemonic(
            _('Limit search to the current page and sub-pages'))
        # T: checkbox option in search dialog
        if page is not None:
            self.vbox.pack_start(self.namespacecheckbox, False, True, 0)

        # TODO advanced query editor
        # TODO checkbox _('Match c_ase')
        # TODO checkbox _('Whole _word')

        self.results_treeview = SearchResultsTreeView(notebook, navigation)
        self.vbox.pack_start(ScrolledWindow(self.results_treeview), True, True,
                             0)

        self.search_button.connect_object('clicked', self.__class__._search,
                                          self)
        self.cancel_button.connect_object('clicked', self.__class__._cancel,
                                          self)
        self.query_entry.connect_object('activate', self.__class__._search,
                                        self)

    def search(self, query):
        '''Trigger a search to be performed.
		Because search can take a long time to execute it is best to
		call this method after the dialog is shown.

		@param query: the query as string
		'''
        self.query_entry.set_text(query)
        self._search()

    def _search(self):
        string = self.query_entry.get_text()
        if self.namespacecheckbox.get_active():
            assert self.page is not None
            string = 'Section: "%s" ' % self.page.name + string
        #~ print('!! QUERY: ' + string)

        self._set_state(self.SEARCHING)
        try:
            self.results_treeview.search(string)
        except Exception as error:
            ErrorDialog(self, error).run()

        if not self.results_treeview.cancelled:
            self._set_state(self.READY)
        else:
            self._set_state(self.CANCELLED)

    def _cancel(self):
        self.results_treeview.cancelled = True

    def _set_state(self, state):
        # TODO set cursor for treeview part
        # TODO set label or something ?
        def hide(button):
            button.hide()
            button.set_no_show_all(True)

        def show(button):
            button.set_no_show_all(False)
            button.show_all()

        if state in (self.READY, self.CANCELLED):
            self.query_entry.set_sensitive(True)
            hide(self.cancel_button)
            if self.spinner:
                self.spinner.stop()
                hide(self.spinner)
            show(self.search_button)
        elif state == self.SEARCHING:
            self.query_entry.set_sensitive(False)
            hide(self.search_button)
            if self.spinner:
                show(self.spinner)
                self.spinner.start()
            show(self.cancel_button)
        else:
            assert False, 'BUG: invalid state'