/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to search.py

  • Committer: rodney.dawes at canonical
  • Date: 2008-10-25 06:02:09 UTC
  • Revision ID: rodney.dawes@canonical.com-20081025060209-irlizouino63cs1m
        * preferences/__init__.py:
        Remove the dialog separator
        Remove useless extra call to self._create_pages()
        Make the default window size smaller
        Set the default border width on various widgets
        Set the current notebook page to the first one

        * preferences/identity.py:
        Set various border widths appropriately
        Align the labels to the left
        Remove the unneeded bold markup from the labels
        Change the "User Id" label to "E-Mail"
        Align the radio group labels to the top of the groups

        * preferences/plugins.py:
        Set various border widths appropriately
        Set the default paned position to something more sensible
        Set the shadow type on the treeview's scrolled window to in
        Align the Author and Version labels to the left

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
from gi.repository import GObject
18
 
from gi.repository import Gtk
 
17
try:
 
18
    import pygtk
 
19
    pygtk.require("2.0")
 
20
except:
 
21
    pass
 
22
 
 
23
import gobject
 
24
import gtk
19
25
 
20
26
from bzrlib.plugins.search import index as _mod_index
21
 
 
22
 
from bzrlib.plugins.gtk.i18n import _i18n
23
 
 
24
 
 
25
 
class SearchDialog(Gtk.Dialog):
 
27
from bzrlib.plugins.gtk import _i18n
 
28
 
 
29
class SearchDialog(gtk.Dialog):
26
30
    """Search dialog."""
27
 
 
28
31
    def __init__(self, index, parent=None):
29
 
        super(SearchDialog, self).__init__(
30
 
            title="Search Revisions", parent=parent,
31
 
            flags=Gtk.DialogFlags.MODAL,
32
 
            buttons=(Gtk.STOCK_OK, Gtk.ResponseType.OK,
33
 
                Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
34
 
        pixbuf = self.render_icon_pixbuf(Gtk.STOCK_FIND, Gtk.IconSize.MENU)
 
32
        gtk.Dialog.__init__(self, title="Search Revisions",
 
33
                                  parent=parent,
 
34
                                  flags=gtk.DIALOG_MODAL,
 
35
                                  buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
 
36
                                           gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
 
37
        pixbuf = self.render_icon(gtk.STOCK_FIND, gtk.ICON_SIZE_MENU)
35
38
        self.set_icon(pixbuf)
36
39
        
37
40
        # Get arguments
38
41
        self.index = index
39
42
 
40
 
        self.searchbar = Gtk.HBox()
41
 
        searchbar_label = Gtk.Label(label=_i18n("Search for:"))
 
43
        self.searchbar = gtk.HBox()
 
44
        searchbar_label = gtk.Label(_i18n("Search for:"))
42
45
        self.searchbar.pack_start(searchbar_label, False, False, 0)
43
 
        self.searchentry = Gtk.Entry()
 
46
        self.searchentry = gtk.Entry()
44
47
        self.searchentry.connect('activate', self._searchentry_activate)
45
48
        # TODO: Completion using the bzr-search suggests functionality
46
49
        self.searchbar.add(self.searchentry)
47
 
        self.get_content_area().pack_start(self.searchbar, False, False, 0)
48
 
 
49
 
        self.results_model = Gtk.ListStore(
50
 
            GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_PYOBJECT)
51
 
        self.results_treeview = Gtk.TreeView(self.results_model)
52
 
        self.results_treeview.connect(
53
 
            "row-activated", self._searchresult_row_activated)
54
 
 
55
 
        documentname_column = Gtk.TreeViewColumn(
56
 
            _i18n("Document"), Gtk.CellRendererText(), text=0)
 
50
        self.vbox.pack_start(self.searchbar, expand=False, fill=False)
 
51
 
 
52
        self.results_model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
 
53
        self.results_treeview = gtk.TreeView(self.results_model)
 
54
        self.results_treeview.connect("row-activated", self._searchresult_row_activated)
 
55
 
 
56
        documentname_column = gtk.TreeViewColumn(_i18n("Document"), gtk.CellRendererText(), text=0)
57
57
        self.results_treeview.append_column(documentname_column)
58
58
 
59
 
        summary_column = Gtk.TreeViewColumn(
60
 
            _i18n("Summary"), Gtk.CellRendererText(), text=1)
 
59
        summary_column = gtk.TreeViewColumn(_i18n("Summary"), gtk.CellRendererText(), text=1)
61
60
        self.results_treeview.append_column(summary_column)
62
61
 
63
 
        results_scrolledwindow = Gtk.ScrolledWindow()
64
 
        results_scrolledwindow.set_policy(
65
 
            Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
 
62
        results_scrolledwindow = gtk.ScrolledWindow()
 
63
        results_scrolledwindow.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
66
64
        results_scrolledwindow.add(self.results_treeview)
67
65
 
68
 
        self.get_content_area().pack_start(
69
 
            results_scrolledwindow, True, True, 0)
 
66
        self.vbox.pack_start(results_scrolledwindow, expand=True, fill=True)
70
67
 
71
68
        self.set_default_size(600, 400)
72
69
        # Show the dialog
83
80
        self.results_model.clear()
84
81
        self.index._branch.lock_read()
85
82
        try:
86
 
            query = [
87
 
                (query_item,)
88
 
                for query_item in self.searchentry.get_text().split(" ")]
 
83
            query = [(query_item,) for query_item in self.searchentry.get_text().split(" ")]
89
84
            for result in self.index.search(query):
90
85
                if isinstance(result, _mod_index.FileTextHit):
91
86
                    revid = result.text_key[-1]
93
88
                    revid = result.revision_key[0]
94
89
                else:
95
90
                    raise AssertionError()
96
 
                self.results_model.append(
97
 
                    [result.document_name(), result.summary(), revid])
 
91
                self.results_model.append([result.document_name(), result.summary(), revid])
98
92
        finally:
99
93
            self.index._branch.unlock()
100
94
    
101
95
    def _searchresult_row_activated(self, treeview, path, view_column):
102
 
        self.response(Gtk.ResponseType.OK)
 
96
        self.response(gtk.RESPONSE_OK)