fab6710881347a4fc23a4647fc11275582461afd
[quicknote] / src / search.py
1 #!/usr/bin/env python2.5
2 # -*- coding: utf-8 -*-
3
4
5 import logging
6
7 import gobject
8 import gtk
9
10 try:
11         _
12 except NameError:
13         _ = lambda x: x
14
15
16 _moduleLogger = logging.getLogger(__name__)
17
18
19 class Search(gtk.HBox):
20
21         __gsignals__ = {
22                 'search_changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
23         }
24
25         def __init__(self):
26                 _moduleLogger.info("search, init")
27                 gtk.HBox.__init__(self, homogeneous = False, spacing = 3)
28                 self.connect("hide", self._on_hide)
29                 self.connect("show", self._on_show)
30
31                 label = gtk.Label(_("Search:  "))
32
33                 self._searchEntry = gtk.Entry()
34                 self._searchEntry.connect("changed", self._on_search_entry_changed, None)
35
36                 closeImage = gtk.Image()
37                 closeImage.set_from_stock("gtk-close", gtk.ICON_SIZE_MENU)
38                 closeSearch = gtk.Button()
39                 closeSearch.set_image(closeImage)
40                 closeSearch.connect("clicked", self._on_close)
41
42                 searchHBox = gtk.HBox()
43                 searchHBox.pack_start(label, expand = False, fill = False)
44                 searchHBox.pack_start(self._searchEntry, expand = True, fill = True)
45                 searchHBox.pack_start(closeSearch, expand = False, fill = False)
46                 self.pack_start(searchHBox, expand = True, fill = True)
47
48         def get_search_pattern(self):
49                 return self._searchEntry.get_text()
50
51         def _on_search_entry_changed(self, widget = None, data = None):
52                 self.emit("search_changed")
53
54         def _on_close(self, *args):
55                 self.hide()
56
57         def _on_show(self, *args):
58                 self._searchEntry.grab_focus()
59
60         def _on_hide(self, *args):
61                 # HACK Disabled for now.  Clearing this resets the note list which
62                 # causes the current note to lose focus.
63                 # self._searchEntry.set_text("")
64                 pass