[Sugar-devel] [RFC PATCH 4/8] Add a ListViewButton to the journal search toolbar.
Andrés Ambrois
andresambrois at gmail.com
Sat May 1 15:33:52 EDT 2010
Add a button to display the sorting options. Create a sort-property-changed
signal in the toolbar to notify the activity of changes.
Use a RadioToolButton for a future implementation of multiple journal views
(as described in the Journal Design Proposal).
Signed-off-by: Andrés Ambrois <andresambrois at gmail.com>
---
src/jarabe/journal/journaltoolbox.py | 64 +++++++++++++++++++++++++++++++++-
1 files changed, 63 insertions(+), 1 deletions(-)
diff --git a/src/jarabe/journal/journaltoolbox.py b/src/jarabe/journal/journaltoolbox.py
index 7466461..48aeb34 100644
--- a/src/jarabe/journal/journaltoolbox.py
+++ b/src/jarabe/journal/journaltoolbox.py
@@ -30,6 +30,7 @@ from sugar.graphics.toolbox import Toolbox
from sugar.graphics.toolcombobox import ToolComboBox
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.toggletoolbutton import ToggleToolButton
+from sugar.graphics.radiotoolbutton import RadioToolButton
from sugar.graphics.combobox import ComboBox
from sugar.graphics.menuitem import MenuItem
from sugar.graphics.icon import Icon
@@ -74,7 +75,10 @@ class SearchToolbar(gtk.Toolbar):
__gsignals__ = {
'query-changed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
- ([object]))
+ ([object])),
+ 'sort-property-changed': (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ([str, object]))
}
def __init__(self):
@@ -109,6 +113,17 @@ class SearchToolbar(gtk.Toolbar):
self.insert(tool_item, -1)
tool_item.show()
+ self._add_separator(expand=True)
+
+ self._list_view_button = ListViewButton()
+ # TODO: Connect when Grid View is implemented
+ #self._list_view.connect('toggled', self.__view_button_toggled_cb)
+ self._list_view_button.set_active(True)
+ self.insert(self._list_view_button, -1)
+ self._list_view_button.connect('sort-property-changed',
+ self.__sort_changed_cb)
+ self._list_view_button.show()
+
# TODO: enable it when the DS supports saving the buddies.
#self._with_search_combo = self._get_with_search_combo()
#tool_item = ToolComboBox(self._with_search_combo)
@@ -119,6 +134,9 @@ class SearchToolbar(gtk.Toolbar):
self.refresh_filters()
+ def __sort_changed_cb(self, button, property, order):
+ self.emit('sort-property-changed', property, order)
+
def give_entry_focus(self):
self._search_entry.grab_focus()
@@ -467,3 +485,47 @@ class EntryToolbar(gtk.Toolbar):
activity_info.get_bundle_id())
palette.menu.append(menu_item)
menu_item.show()
+
+class ListViewButton(RadioToolButton):
+ __gtype_name__ = 'JournalListViewButton'
+
+ __gsignals__ = {
+ 'sort-property-changed': (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ([str, object])),
+ }
+
+ _SORT_OPTIONS = [
+ ('timestamp', 'view-lastedit', _('View by last edit')),
+ ('ctime', 'view-created', _('View by creation date')),
+ ('filesize', 'view-size', _('View by size')),
+ ]
+
+ def __init__(self):
+ RadioToolButton.__init__(self)
+
+ self.props.tooltip = _('List view')
+ self.props.named_icon = 'view-list'
+ # TODO: Set accelerator when Grid View is implemented
+ #self.props.accelerator = _('<Ctrl>2')
+ self.props.group = None
+
+ for property, icon, label in self._SORT_OPTIONS:
+ button = MenuItem(icon_name=icon, text_label=label)
+ button.connect('activate',
+ self.__sort_type_changed_cb,
+ property,
+ icon)
+ button.show()
+ self.props.palette.menu.insert(button, -1)
+
+ def __sort_type_changed_cb(self, widget, property, named_icon):
+ #FIXME: Implement sorting order
+ self.emit('sort-property-changed', property, gtk.SORT_ASCENDING)
+
+ self.props.named_icon = named_icon
+
+ if not self.props.active:
+ self.props.active = True
+ else:
+ self.emit('toggled')
--
1.6.3.3
More information about the Sugar-devel
mailing list