[POS-commit] r1119 - in stoqlib/trunk/stoqlib/gui: . glade
Evandro Vale Miquelito
evandro at async.com.br
Thu Sep 1 20:58:19 BRT 2005
Author: evandro
Date: Thu Sep 1 20:58:18 2005
New Revision: 1119
Modified:
stoqlib/trunk/stoqlib/gui/glade/SearchBar.glade
stoqlib/trunk/stoqlib/gui/search.py
Log:
Adding support in stoqlib for a maximum number of results associated with a
search bar. We also have now a label displaying the number of results we got
after a search.
Modified: stoqlib/trunk/stoqlib/gui/glade/SearchBar.glade
==============================================================================
--- stoqlib/trunk/stoqlib/gui/glade/SearchBar.glade (original)
+++ stoqlib/trunk/stoqlib/gui/glade/SearchBar.glade Thu Sep 1 20:58:18 2005
@@ -3,69 +3,87 @@
<glade-interface>
<widget class="GtkWindow" id="SearchBar">
<child>
- <widget class="GtkAlignment" id="alignment1">
- <property name="border_width">5</property>
+ <widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
- <property name="xalign">0.00999999977648</property>
- <property name="xscale">0.509999990463</property>
- <property name="yalign">0.0</property>
- <property name="yscale">0.0</property>
<child>
- <widget class="GtkHBox" id="hbox1">
- <property name="spacing">5</property>
+ <widget class="GtkAlignment" id="alignment1">
+ <property name="border_width">5</property>
<property name="visible">True</property>
+ <property name="xalign">0.00999999977648</property>
+ <property name="xscale">0.509999990463</property>
+ <property name="yalign">0.0</property>
+ <property name="yscale">0.0</property>
<child>
- <widget class="GtkImage" id="search_icon">
- <property name="stock" context="yes" translatable="yes">gtk-missing-image</property>
+ <widget class="GtkHBox" id="hbox1">
+ <property name="spacing">5</property>
<property name="visible">True</property>
- <property name="xalign">1.0</property>
+ <child>
+ <widget class="GtkImage" id="search_icon">
+ <property name="stock" context="yes" translatable="yes">gtk-missing-image</property>
+ <property name="visible">True</property>
+ <property name="xalign">1.0</property>
+ </widget>
+ </child>
+ <child>
+ <widget class="kiwi+ui+widgets+label+Label" id="search_label">
+ <property name="data_type">str</property>
+ <property name="label" context="yes" translatable="yes">Search Item</property>
+ <property name="xalign">1.0</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="kiwi+ui+widgets+label+Label" id="kiwilabel1">
+ <property name="data_type">str</property>
+ <property name="justify">right</property>
+ <property name="label" context="yes" translatable="yes">:</property>
+ <property name="xalign">1.0</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkEntry" id="search_entry">
+ <property name="is_focus">True</property>
+ <property name="visible">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkButton" id="search_button">
+ <property name="label" context="yes" translatable="yes">Search</property>
+ <property name="visible">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">4</property>
+ </packing>
+ </child>
</widget>
</child>
- <child>
- <widget class="kiwi+ui+widgets+label+Label" id="search_label">
- <property name="data_type">str</property>
- <property name="label" context="yes" translatable="yes">Search Item</property>
- <property name="xalign">1.0</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <widget class="kiwi+ui+widgets+label+Label" id="kiwilabel1">
- <property name="data_type">str</property>
- <property name="justify">right</property>
- <property name="label" context="yes" translatable="yes">:</property>
- <property name="xalign">1.0</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="position">2</property>
- </packing>
- </child>
- <child>
- <widget class="GtkEntry" id="search_entry">
- <property name="is_focus">True</property>
- <property name="visible">True</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="position">3</property>
- </packing>
- </child>
- <child>
- <widget class="GtkButton" id="search_button">
- <property name="label" context="yes" translatable="yes">Search</property>
- <property name="visible">True</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="position">4</property>
- </packing>
- </child>
</widget>
</child>
+ <child>
+ <widget class="kiwi+ui+widgets+label+Label" id="search_results_label">
+ <property name="data_type">str</property>
+ <property name="justify">right</property>
+ <property name="label" context="yes" translatable="yes">Found %s items</property>
+ <property name="xalign">1.0</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</widget>
</child>
</widget>
Modified: stoqlib/trunk/stoqlib/gui/search.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/search.py (original)
+++ stoqlib/trunk/stoqlib/gui/search.py Thu Sep 1 20:58:18 2005
@@ -17,6 +17,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
+# Author(s): Evandro Vale Miquelito <evandro at async.com.br>
+#
"""
gui/search.py:
@@ -106,7 +108,9 @@
widgets = ('search_button',
'search_label',
"search_entry",
+ "search_results_label",
"search_icon")
+
SEARCH_ICON_SIZE = gtk.ICON_SIZE_LARGE_TOOLBAR
ANIMATE_TIMEOUT = 200
@@ -117,7 +121,7 @@
self._animate_search_icon_id = -1
self.search_icon.set_from_stock("searchtool-icon1",
self.SEARCH_ICON_SIZE)
- self._update_widgets()
+ self.search_entry.grab_focus()
self.parent = parent
# Since we need to synchronize transactions each time we search for
# objects we have to create a special transaction for the SearchBar
@@ -130,15 +134,11 @@
self.search_label.set_text(_('Find Items'))
else:
self.search_label.set_text(search_lbl_text)
+ self.search_results_label.set_size('small')
+ self.search_results_label.set_color('red')
+ self.search_results_label.set_text('')
self._split_field_types()
- def _update_widgets(self):
- if self.search_entry.get_text() != '':
- self.search_button.set_sensitive(True)
- else:
- self.search_button.set_sensitive(False)
- self.search_entry.grab_focus()
-
def get_search_string(self):
return self.search_entry.get_text()
@@ -252,11 +252,11 @@
def _run_query(self):
search_str = self.get_search_string()
- if not search_str:
- # Clear the kiwi list if we don't have a valid search string
- self.parent.update_klist()
- return
- query = self._build_query(search_str)
+ if search_str:
+ query = self._build_query(search_str)
+ else:
+ # A default SQLObject query that means all the results
+ query = 1 == 1
extra_query = self.parent.get_extra_query()
if extra_query:
@@ -274,9 +274,24 @@
# Synchronizing transaction.
# XXX Waiting for a SQLObject sync method
rollback_and_begin(self.conn)
- objs = self.table_type.select(query, **kwargs)
+
+ search_results = self.table_type.select(query, **kwargs)
+ max_search_results = get_max_search_results()
+ objs = search_results[:max_search_results]
+
+ total = search_results.count()
+ if total > max_search_results:
+ msg = _('Listing %d results of about %d.' % (max_search_results,
+ total))
+ self.search_results_label.set_text(msg)
+ else:
+ msg = _('Found %d results' % total)
+ self.search_results_label.set_text(msg)
+
objs = self.parent.filter_results(objs)
- self.parent.update_klist(objs)
+ # Since SQLObject doesn't support distinct-counting of sliced
+ # objects we need to send here a list instead of a SearchResults
+ self.parent.update_klist(list(objs))
def close_connection(self):
# XXX Waiting for SQLObject improvements. We need there a simple
@@ -339,9 +354,6 @@
def on_search_entry__activate(self, *args):
self.search_items()
- def on_search_entry__changed(self, *args):
- self._update_widgets()
-
class SearchEditorToolBar(SlaveDelegate):
""" Slave for internal use of SearchEditor, offering an eventbox for a
@@ -638,3 +650,15 @@
def new(self):
self.run()
+
+
+max_search_results = None
+
+def set_max_search_results(max):
+ global max_search_results
+ assert max
+ max_search_results = max
+
+def get_max_search_results():
+ global max_search_results
+ return max_search_results
More information about the POS-commit
mailing list