deskbar-applet r2138 - in trunk: . deskbar/interfaces deskbar/ui po
- From: sebp svn gnome org
- To: svn-commits-list gnome org
- Subject: deskbar-applet r2138 - in trunk: . deskbar/interfaces deskbar/ui po
- Date: Thu, 24 Apr 2008 17:54:24 +0100 (BST)
Author: sebp
Date: Thu Apr 24 16:54:23 2008
New Revision: 2138
URL: http://svn.gnome.org/viewvc/deskbar-applet?rev=2138&view=rev
Log:
2008-04-24 Sebastian PÃlsterl <sebp cvs gnome org>
* deskbar/ui/AbstractCuemiacView.py:
* deskbar/ui/CuemiacAlignedView.py:
* deskbar/ui/CuemiacWindowController.py:
* deskbar/ui/CuemiacWindowView.py:
* deskbar/ui/Makefile.am:
* po/POTFILES.in:
Moved duplicate code from both UIs to new
AbstractCuemiacView class
2008-04-24 Sebastian PÃlsterl <sebp cvs gnome org>
* deskbar/interfaces/View.py:
Removed not used methods
Added:
trunk/deskbar/ui/AbstractCuemiacView.py
Modified:
trunk/ChangeLog
trunk/deskbar/interfaces/View.py
trunk/deskbar/ui/CuemiacAlignedView.py
trunk/deskbar/ui/CuemiacWindowController.py
trunk/deskbar/ui/CuemiacWindowView.py
trunk/deskbar/ui/Makefile.am
trunk/po/POTFILES.in
Modified: trunk/deskbar/interfaces/View.py
==============================================================================
--- trunk/deskbar/interfaces/View.py (original)
+++ trunk/deskbar/interfaces/View.py Thu Apr 24 16:54:23 2008
@@ -30,12 +30,6 @@
def get_entry(self):
raise NotImplementedError
- def show_history(self, value):
- raise NotImplementedError
-
- def is_history_visible(self):
- raise NotImplementedError
-
def receive_focus(self, time):
raise NotImplementedError
Added: trunk/deskbar/ui/AbstractCuemiacView.py
==============================================================================
--- (empty file)
+++ trunk/deskbar/ui/AbstractCuemiacView.py Thu Apr 24 16:54:23 2008
@@ -0,0 +1,282 @@
+import gtk
+import gtk.gdk
+import gobject
+from gettext import gettext as _
+import deskbar.core.Utils
+import deskbar.interfaces.View
+from deskbar.ui.cuemiac.CuemiacEntry import CuemiacEntry
+from deskbar.ui.cuemiac.CuemiacHeader import CuemiacHeader
+from deskbar.ui.cuemiac.CuemiacModel import CuemiacModel
+from deskbar.ui.cuemiac.CuemiacTreeView import CuemiacTreeView
+from deskbar.ui.cuemiac.CuemiacItems import CuemiacCategory
+from deskbar.ui.cuemiac.CuemiacHistory import CuemiacHistoryView
+from deskbar.ui.cuemiac.CuemiacActionsTreeView import CuemiacActionsTreeView, CuemiacActionsModel
+from deskbar.ui.cuemiac.LingeringSelectionWindow import LingeringSelectionWindow
+
+class AbstractCuemiacView (deskbar.interfaces.View):
+ """
+ An abstract base class for all cuemiac derived UIs
+
+ It creates and packs all necessary widget and connects
+ the signals correctly. L{self.vbox_main} contains the actual
+ UI.
+
+ You still have to implement methods from L{deskbar.interfaces.View}:
+ * get_toplevel
+ * receive_focus
+ """
+
+ VBOX_MAIN_SPACING = 12
+ VBOX_MAIN_BORDER_WIDTH = 6
+
+ def __init__(self, controller, model):
+ deskbar.interfaces.View.__init__(self, controller, model)
+ self._do_clear = True
+
+ self._model.connect("query-ready", lambda s,m: gobject.idle_add(self.append_matches, s, m))
+
+ # VBox
+ self._create_vbox_main()
+ self.vbox_main.show()
+
+ self._create_header()
+ self.header.show()
+
+ # History TreeView
+ self._create_history_box()
+ self.history_box.show()
+
+ # Results TreeView
+ self._create_results_treeview()
+ self.cview.show()
+ self.scrolled_results.show()
+
+ # Actions TreeView
+ self._create_actions_view()
+ self.aview.show()
+ self.scrolled_actions.show()
+
+ def _create_vbox_main(self):
+ """
+ Sets self.vbox_main
+ """
+ self.vbox_main = gtk.VBox(spacing=self.VBOX_MAIN_SPACING)
+ self.vbox_main.set_border_width(self.VBOX_MAIN_BORDER_WIDTH)
+
+ def _create_cuemiac_entry(self):
+ """
+ Sets self.entry
+ """
+ # Search entry
+ self.default_entry_pixbuf = deskbar.core.Utils.load_icon("deskbar-applet-panel-h.png", width=23, height=14)
+ self.entry = CuemiacEntry (self.default_entry_pixbuf)
+ self.entry.connect("changed", self._controller.on_query_entry_changed)
+ # Connect this before "go-next/previous" to parse history
+ self.entry.connect("key-press-event", self._controller.on_query_entry_key_press_event)
+ self.entry.connect("activate", self._controller.on_query_entry_activate)
+ self.entry.connect("go-next", lambda e: self._focus_matches_if_visible("top"))
+ self.entry.connect("go-previous", lambda e: self._focus_matches_if_visible("bottom"))
+
+ def _create_header(self):
+ """
+ Sets self.entry and self.header
+ """
+# self.completion = gtk.EntryCompletion()
+# self.completion.set_model(self._model.get_history())
+# self.completion.set_inline_completion(True)
+# self.completion.set_popup_completion(False)
+# self.completion.set_text_column(1)
+
+ self._create_cuemiac_entry()
+# self.entry.get_entry().set_completion(self.completion)
+ self.entry.show()
+
+ self.header = CuemiacHeader ( self.entry )
+
+ def _create_history_box(self):
+ """
+ Sets:
+ * self.history_box
+ * self.hview
+ * self.empty_button
+ """
+ self.history_box = gtk.HBox(spacing=6)
+
+ hlabel = gtk.Label()
+ # translators: _H is a mnemonic, i.e. pressing Alt+h will focus the widget
+ hlabel.set_markup_with_mnemonic("<b>%s:</b>" % _("_History"))
+ hlabel.show()
+ self.history_box.pack_start(hlabel, False)
+
+ self.hview = CuemiacHistoryView(self._model.get_history())
+ self.hview.connect("match-selected", self._controller.on_history_match_selected)
+ self.hview.show()
+ self.history_box.pack_start(self.hview)
+ hlabel.set_mnemonic_widget(self.hview)
+
+ self.empty_button = gtk.Button()
+ self.empty_button.set_image( gtk.image_new_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_MENU) )
+ self.empty_button.connect("clicked", self._controller.on_clear_history)
+ self.empty_button.show()
+ self.history_box.pack_start(self.empty_button, False)
+
+ def _create_results_treeview(self):
+ """
+ Sets:
+ * self.treeview_model
+ * self.cview
+ * self.scrolled_results
+ """
+ self.treeview_model = CuemiacModel ()
+ self.treeview_model.connect("category-added", self._controller.on_category_added)
+
+ self.cview = CuemiacTreeView (self.treeview_model)
+ #self.cview.connect ("key-press-event", self._on_cview_key_press)
+ self.cview.connect ("match-selected", self._controller.on_match_selected)
+ self.cview.connect ("do-default-action", self._controller.on_do_default_action)
+ self.cview.connect ("pressed-up-at-top", lambda s: self.entry.grab_focus())
+ self.cview.connect ("pressed-down-at-bottom", lambda s: self.entry.grab_focus())
+ self.cview.connect_after ("cursor-changed", self._controller.on_treeview_cursor_changed)
+ self.cview.connect ("row-expanded", self._controller.on_category_expanded, self.treeview_model)
+ self.cview.connect ("row-collapsed", self._controller.on_category_collapsed, self.treeview_model)
+
+ LingeringSelectionWindow (self.cview)
+
+ self.scrolled_results = gtk.ScrolledWindow ()
+ self.scrolled_results.set_policy (gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+ self.scrolled_results.set_shadow_type(gtk.SHADOW_IN)
+ self.scrolled_results.add(self.cview)
+
+ def _create_actions_view(self):
+ """
+ Sets:
+ * self.actions_box
+ * self.actions_model
+ * self.aview
+ * self.scrolled_actions
+ """
+ self.actions_box = gtk.VBox(spacing=3)
+
+ self.actions_model = CuemiacActionsModel()
+ self.aview = CuemiacActionsTreeView(self.actions_model)
+ self.aview.connect ("action-selected", self._controller.on_action_selected)
+ self.aview.connect ("go-back", self._on_go_back)
+
+ LingeringSelectionWindow (self.aview)
+
+ self.scrolled_actions = gtk.ScrolledWindow()
+ self.scrolled_actions.set_policy (gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+ self.scrolled_actions.set_shadow_type(gtk.SHADOW_IN)
+ self.scrolled_actions.add(self.aview)
+ self.actions_box.pack_start(self.scrolled_actions)
+
+ buttonbox = gtk.HButtonBox()
+ buttonbox.set_layout(gtk.BUTTONBOX_START)
+ buttonbox.show()
+ self.actions_box.pack_start(buttonbox, False)
+
+ back_button = gtk.Button(_("Back to Matches"))
+ back_button.set_image( gtk.image_new_from_stock(gtk.STOCK_GO_BACK, gtk.ICON_SIZE_MENU) )
+ back_button.set_relief(gtk.RELIEF_NONE)
+ back_button.connect("clicked", self._on_go_back)
+ back_button.show()
+ buttonbox.pack_start(back_button, False, False, 0)
+
+ def _focus_matches_if_visible(self, mode):
+ if (self.results_box.get_property("visible")):
+ if mode == "top":
+ self.cview.select_first_item()
+ elif mode == "bottom":
+ self.cview.select_last_item()
+ self.cview.grab_focus()
+ return True
+ else:
+ return False
+
+ def _on_go_back(self, widget):
+ self._show_matches()
+ self.cview.grab_focus()
+ return False
+
+ def _show_matches(self):
+ self.scrolled_results.show()
+ self.actions_box.hide()
+
+ def _show_actions(self):
+ self.scrolled_results.hide()
+ self.actions_box.show()
+
+ def clear_results(self):
+ self.treeview_model.clear()
+
+ def clear_actions(self):
+ self.actions_model.clear()
+
+ def clear_query(self):
+ self.entry.set_text("")
+ self.entry.set_icon( self.default_entry_pixbuf )
+
+
+ def get_entry(self):
+ return self.entry
+
+ def set_clear(self):
+ """
+ Set a flag to clear the list of matches and actions
+ as soon as the first result arrives
+ """
+ self._do_clear = True
+
+ def mark_history_empty(self, val):
+ self.hview.set_sensitive (not val)
+ self.empty_button.set_sensitive (not val)
+
+ def show_results(self):
+ self.results_box.show()
+ self._show_matches()
+
+ def display_actions(self, actions, qstring):
+ self.actions_model.clear()
+ self._show_actions()
+ self.actions_model.add_actions(actions, qstring)
+ self.aview.grab_focus()
+
+ def set_sensitive (self, active):
+ """
+ Called when the UI should be in/active because modules are loading
+ """
+ self.vbox_main.set_sensitive(active)
+ if active:
+ self.entry.grab_focus()
+
+ def update_entry_icon (self, icon=None):
+ if icon == None:
+ icon = self.default_entry_pixbuf
+ if not (self.cview.get_toplevel().flags() & gtk.MAPPED):
+ # The view is hidden, just show default icon
+ self.entry.set_icon (icon)
+ return
+
+ path, column = self.cview.get_cursor ()
+
+ if path != None and self.entry.get_text() != "":
+ match = self.treeview_model[self.treeview_model.get_iter(path)][self.treeview_model.MATCHES]
+ if not isinstance(match, CuemiacCategory):
+ icon = match.get_icon()
+
+ self.entry.set_icon (icon)
+
+ def append_matches (self, sender, matches):
+ """
+ We suppose that the results belong to the text
+ that is currently in the entry
+ """
+ if self._do_clear:
+ self._do_clear = False
+ self.clear_results()
+ self.clear_actions()
+ # Display default icon in entry
+ self.update_entry_icon()
+ self.treeview_model.append (matches, self.entry.get_text())
+
+
\ No newline at end of file
Modified: trunk/deskbar/ui/CuemiacAlignedView.py
==============================================================================
--- trunk/deskbar/ui/CuemiacAlignedView.py (original)
+++ trunk/deskbar/ui/CuemiacAlignedView.py Thu Apr 24 16:54:23 2008
@@ -2,20 +2,10 @@
import gtk.gdk
import gobject
import gnomeapplet
-from gettext import gettext as _
-import deskbar.interfaces.View
-import deskbar.core.Utils
-from deskbar.ui.cuemiac.CuemiacEntry import CuemiacEntry
-from deskbar.ui.cuemiac.CuemiacHeader import CuemiacHeader
-from deskbar.ui.cuemiac.CuemiacModel import CuemiacModel
-from deskbar.ui.cuemiac.CuemiacTreeView import CuemiacTreeView
-from deskbar.ui.cuemiac.CuemiacItems import CuemiacCategory
-from deskbar.ui.cuemiac.CuemiacHistory import CuemiacHistoryView
-from deskbar.ui.cuemiac.CuemiacActionsTreeView import CuemiacActionsTreeView, CuemiacActionsModel
-from deskbar.ui.cuemiac.LingeringSelectionWindow import LingeringSelectionWindow
+from deskbar.ui.AbstractCuemiacView import AbstractCuemiacView
from deskbar.ui.cuemiac.CuemiacAlignedWindow import CuemiacAlignedWindow
-class CuemiacAlignedView(deskbar.interfaces.View, CuemiacAlignedWindow):
+class CuemiacAlignedView(AbstractCuemiacView, CuemiacAlignedWindow):
"""
This class is responsible for setting up the GUI.
It displays the older version of deskbar's GUI, where the
@@ -26,10 +16,9 @@
VBOX_MAIN_BORDER_WIDTH = 6
def __init__(self, controller, model, widget, applet):
- deskbar.interfaces.View.__init__(self, controller, model)
+ AbstractCuemiacView.__init__(self, controller, model)
CuemiacAlignedWindow.__init__(self, widget, applet)
self._controller.register_view(self)
- self._do_clear = True
self.applet = applet
self.set_type_hint (gtk.gdk.WINDOW_TYPE_HINT_MENU)
@@ -51,110 +40,9 @@
self.set_role("deskbar-search-window")
- self._model.connect("query-ready", lambda s,m: gobject.idle_add(self.append_matches, s, m))
-
- # VBox
- self.vbox_main = gtk.VBox(spacing=self.VBOX_MAIN_SPACING)
- self.vbox_main.set_border_width(self.VBOX_MAIN_BORDER_WIDTH)
+ # VBox
self.add(self.vbox_main)
- self.vbox_main.show()
-
-# self.completion = gtk.EntryCompletion()
-# self.completion.set_model(self._model.get_history())
-# self.completion.set_inline_completion(True)
-# self.completion.set_popup_completion(False)
-# self.completion.set_text_column(1)
-
- # Search entry
- self.default_entry_pixbuf = deskbar.core.Utils.load_icon("deskbar-applet-panel-h.png", width=23, height=14)
- self.entry = CuemiacEntry (self.default_entry_pixbuf)
- self.entry.connect("changed", self._controller.on_query_entry_changed)
- # Connect this before "go-next/previous" to parse history
- self.entry.connect("key-press-event", self._controller.on_query_entry_key_press_event)
- self.entry.connect("activate", self._controller.on_query_entry_activate)
- self.entry.connect("go-next", lambda e: self.__focus_matches_if_visible("top"))
- self.entry.connect("go-previous", lambda e: self.__focus_matches_if_visible("bottom"))
-# self.entry.get_entry().set_completion(self.completion)
- self.entry.show()
-
- self.header = CuemiacHeader ( self.entry )
- self.header.show()
-
- # History TreeView
- self.history_box = gtk.HBox(spacing=6)
- self.history_box.show()
-
- hlabel = gtk.Label()
- # translators: _H is a mnemonic, i.e. pressing Alt+h will focus the widget
- hlabel.set_markup_with_mnemonic("<b>%s:</b>" % _("_History"))
- hlabel.show()
- self.history_box.pack_start(hlabel, False)
-
- self.hview = CuemiacHistoryView(self._model.get_history())
- self.hview.connect("match-selected", self._controller.on_history_match_selected)
- self.hview.show()
- self.history_box.pack_start(self.hview)
- hlabel.set_mnemonic_widget(self.hview)
-
- self.empty_button = gtk.Button()
- self.empty_button.set_image( gtk.image_new_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_MENU) )
- self.empty_button.connect("clicked", self._controller.on_clear_history)
- self.empty_button.show()
- self.history_box.pack_start(self.empty_button, False)
-
- # Results TreeView
- self.treeview_model = CuemiacModel ()
- self.treeview_model.connect("category-added", self._controller.on_category_added)
-
- self.cview = CuemiacTreeView (self.treeview_model)
- #self.cview.connect ("key-press-event", self._on_cview_key_press)
- self.cview.connect ("match-selected", self._controller.on_match_selected)
- self.cview.connect ("do-default-action", self._controller.on_do_default_action)
- self.cview.connect ("pressed-up-at-top", lambda s: self.entry.grab_focus())
- self.cview.connect ("pressed-down-at-bottom", lambda s: self.entry.grab_focus())
- self.cview.connect_after ("cursor-changed", self._controller.on_treeview_cursor_changed)
- self.cview.connect ("row-expanded", self._controller.on_category_expanded, self.treeview_model)
- self.cview.connect ("row-collapsed", self._controller.on_category_collapsed, self.treeview_model)
- self.cview.show()
-
- LingeringSelectionWindow (self.cview)
-
- self.scrolled_results = gtk.ScrolledWindow ()
- self.scrolled_results.set_policy (gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
- self.scrolled_results.set_shadow_type(gtk.SHADOW_IN)
- self.scrolled_results.add(self.cview)
- self.scrolled_results.show()
- # Actions TreeView
- self.actions_box = gtk.VBox(spacing=3)
-
- self.actions_model = CuemiacActionsModel()
- self.aview = CuemiacActionsTreeView(self.actions_model)
- self.aview.connect ("action-selected", self._controller.on_action_selected)
- self.aview.connect ("go-back", self.__on_go_back)
- self.aview.show()
-
- LingeringSelectionWindow (self.aview)
-
- self.scrolled_actions = gtk.ScrolledWindow()
- self.scrolled_actions.set_policy (gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
- self.scrolled_actions.set_shadow_type(gtk.SHADOW_IN)
- self.scrolled_actions.add(self.aview)
- self.scrolled_actions.show()
- self.actions_box.pack_start(self.scrolled_actions)
-
- buttonbox = gtk.HButtonBox()
- buttonbox.set_layout(gtk.BUTTONBOX_START)
- buttonbox.show()
- self.actions_box.pack_start(buttonbox, False)
-
- back_button = gtk.Button(_("Back to Matches"))
- back_button.set_image( gtk.image_new_from_stock(gtk.STOCK_GO_BACK, gtk.ICON_SIZE_MENU) )
- back_button.set_relief(gtk.RELIEF_NONE)
- back_button.connect("clicked", self.__on_go_back)
- back_button.show()
- buttonbox.pack_start(back_button, False, False, 0)
-
# Results
self.results_box = gtk.HBox()
self.results_box.pack_start(self.scrolled_results)
@@ -164,34 +52,14 @@
self.resize( *self.size_request() )
def clear_all(self):
- deskbar.interfaces.View.clear_all(self)
+ AbstractCuemiacView.clear_all(self)
self.applet.set_state(gtk.STATE_NORMAL)
self.results_box.hide()
self.__adjust_popup_size()
- def clear_results(self):
- self.treeview_model.clear()
-
- def clear_actions(self):
- self.actions_model.clear()
-
- def clear_query(self):
- self.entry.set_text("")
- self.entry.set_icon( self.default_entry_pixbuf )
-
def get_toplevel(self):
return self
-
- def get_entry(self):
- return self.entry
-
- def set_clear(self):
- """
- Set a flag to clear the list of matches and actions
- as soon as the first result arrives
- """
- self._do_clear = True
-
+
def receive_focus(self, time):
self.applet.set_state(gtk.STATE_SELECTED)
self.update_position()
@@ -200,91 +68,18 @@
self.show()
self.present_with_time(time)
self.entry.grab_focus()
-
- def mark_history_empty(self, val):
- self.hview.set_sensitive (not val)
- self.empty_button.set_sensitive (not val)
-
- def __show_matches(self):
- self.scrolled_results.show()
- self.actions_box.hide()
-
- def __show_actions(self):
- self.scrolled_results.hide()
- self.actions_box.show()
-
- def show_results(self):
- self.results_box.show()
- self.__show_matches()
- def display_actions(self, actions, qstring):
- self.actions_model.clear()
- self.__show_actions()
- self.actions_model.add_actions(actions, qstring)
- self.aview.grab_focus()
-
def append_matches (self, sender, matches):
- """
- We suppose that the results belong to the text
- that is currently in the entry
- """
- if self._do_clear:
- self._do_clear = False
- self.clear_results()
- self.clear_actions()
- # Display default icon in entry
- self.update_entry_icon()
- self.treeview_model.append (matches, self.entry.get_text())
+ AbstractCuemiacView.append_matches(self, sender, matches)
# Wait a little bit to resize, otherwise we get a size that's too small
gobject.timeout_add(200, self.__adjust_popup_size)
-
- def set_sensitive (self, active):
- """
- Called when the UI should be in/active because modules are loading
- """
- self.vbox_main.set_sensitive(active)
- if active:
- self.entry.grab_focus()
-
- def update_entry_icon (self, icon=None):
- if icon == None:
- icon = self.default_entry_pixbuf
- if not (self.cview.get_toplevel().flags() & gtk.MAPPED):
- # The view is hidden, just show default icon
- self.entry.set_icon (icon)
- return
-
- path, column = self.cview.get_cursor ()
-
- if path != None and self.entry.get_text() != "":
- match = self.treeview_model[self.treeview_model.get_iter(path)][self.treeview_model.MATCHES]
- if not isinstance(match, CuemiacCategory):
- icon = match.get_icon()
-
- self.entry.set_icon (icon)
-
- def __on_go_back(self, widget):
- self.__show_matches()
- self.cview.grab_focus()
- return False
def __on_window_key_press_event(self, window, event):
if event.keyval == gtk.keysyms.Escape:
self.emit("destroy-event", event)
return False
-
- def __focus_matches_if_visible(self, mode):
- if (self.results_box.get_property("visible")):
- if mode == "top":
- self.cview.select_first_item()
- elif mode == "bottom":
- self.cview.select_last_item()
- self.cview.grab_focus()
- return True
- else:
- return False
-
+
def __adjust_popup_size (self):
"""adjust window size to the size of the children"""
# FIXME: Should we handle width intelligently also?
Modified: trunk/deskbar/ui/CuemiacWindowController.py
==============================================================================
--- trunk/deskbar/ui/CuemiacWindowController.py (original)
+++ trunk/deskbar/ui/CuemiacWindowController.py Thu Apr 24 16:54:23 2008
@@ -39,9 +39,9 @@
if self._model.get_clear_entry():
self._view.clear_all()
window = self._view.get_toplevel()
- x, y = window.get_position()
if self._model.get_ui_name() == deskbar.WINDOW_UI_NAME:
+ x, y = window.get_position()
self._model.set_window_x(x)
self._model.set_window_y(y)
Modified: trunk/deskbar/ui/CuemiacWindowView.py
==============================================================================
--- trunk/deskbar/ui/CuemiacWindowView.py (original)
+++ trunk/deskbar/ui/CuemiacWindowView.py Thu Apr 24 16:54:23 2008
@@ -1,29 +1,18 @@
import gtk
import gtk.gdk
import gobject
-from gettext import gettext as _
-import deskbar.interfaces.View
-import deskbar.core.Utils
-from deskbar.ui.cuemiac.CuemiacEntry import CuemiacEntry
-from deskbar.ui.cuemiac.CuemiacHeader import CuemiacHeader
-from deskbar.ui.cuemiac.CuemiacModel import CuemiacModel
-from deskbar.ui.cuemiac.CuemiacTreeView import CuemiacTreeView
-from deskbar.ui.cuemiac.CuemiacItems import CuemiacCategory
-from deskbar.ui.cuemiac.CuemiacHistory import CuemiacHistoryView
-from deskbar.ui.cuemiac.CuemiacActionsTreeView import CuemiacActionsTreeView, CuemiacActionsModel
-from deskbar.ui.cuemiac.LingeringSelectionWindow import LingeringSelectionWindow
+from deskbar.ui.AbstractCuemiacView import AbstractCuemiacView
-class CuemiacWindowView(deskbar.interfaces.View, gtk.Window):
+class CuemiacWindowView(AbstractCuemiacView, gtk.Window):
"""
This class is responsible for setting up the GUI.
"""
def __init__(self, controller, model):
- deskbar.interfaces.View.__init__(self, controller, model)
+ AbstractCuemiacView.__init__(self, controller, model)
gtk.Window.__init__(self)
self._controller.register_view(self)
self.__small_window_height = None
- self._do_clear = True
self.connect("configure-event", self.__save_window_size)
self.connect("delete-event", self._controller.on_quit)
@@ -36,113 +25,14 @@
self.set_role("deskbar-search-window")
self.set_property("skip-taskbar-hint", True)
- self._model.connect("query-ready", lambda s,m: gobject.idle_add(self.append_matches, s, m))
-
- # VBox
- self.vbox_main = gtk.VBox(spacing=12)
- self.vbox_main.set_border_width(6)
self.add(self.vbox_main)
- self.vbox_main.show()
-
-# self.completion = gtk.EntryCompletion()
-# self.completion.set_model(self._model.get_history())
-# self.completion.set_inline_completion(True)
-# self.completion.set_popup_completion(False)
-# self.completion.set_text_column(1)
-
- self.default_entry_pixbuf = deskbar.core.Utils.load_icon("deskbar-applet-panel-h.png", width=23, height=14)
- self.entry = CuemiacEntry (self.default_entry_pixbuf)
- self.entry.connect("changed", self._controller.on_query_entry_changed)
- # Connect this before "go-next/previous" to parse history
- self.entry.connect("key-press-event", self._controller.on_query_entry_key_press_event)
- self.entry.connect("activate", self._controller.on_query_entry_activate)
- self.entry.connect("go-next", lambda e: self.__focus_matches_if_visible("top"))
- self.entry.connect("go-previous", lambda e: self.__focus_matches_if_visible("bottom"))
-# self.entry.get_entry().set_completion(self.completion)
- self.entry.show()
-
- header = CuemiacHeader ( self.entry )
- header.show()
-
+
# Search entry
- self.vbox_main.pack_start(header, False)
+ self.vbox_main.pack_start(self.header, False)
# History TreeView
- hhbox = gtk.HBox(spacing=6)
- hhbox.show()
- self.vbox_main.pack_start(hhbox, False)
-
- hlabel = gtk.Label()
- # translators: _H is a mnemonic, i.e. pressing Alt+h will focus the widget
- hlabel.set_markup_with_mnemonic("<b>%s:</b>" % _("_History"))
- hlabel.show()
- hhbox.pack_start(hlabel, False)
-
- self.hview = CuemiacHistoryView(self._model.get_history())
- self.hview.connect("match-selected", self._controller.on_history_match_selected)
- self.hview.show()
- hhbox.pack_start(self.hview)
- hlabel.set_mnemonic_widget(self.hview)
-
- self.empty_button = gtk.Button()
- self.empty_button.set_image( gtk.image_new_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_MENU) )
- self.empty_button.connect("clicked", self._controller.on_clear_history)
- self.empty_button.show()
- hhbox.pack_start(self.empty_button, False)
-
- # Results TreeView
- self.treeview_model = CuemiacModel ()
- self.treeview_model.connect("category-added", self._controller.on_category_added)
-
- self.cview = CuemiacTreeView (self.treeview_model)
- #self.cview.connect ("key-press-event", self._on_cview_key_press)
- self.cview.connect ("match-selected", self._controller.on_match_selected)
- self.cview.connect ("do-default-action", self._controller.on_do_default_action)
- self.cview.connect ("pressed-up-at-top", lambda s: self.entry.grab_focus())
- self.cview.connect ("pressed-down-at-bottom", lambda s: self.entry.grab_focus())
- self.cview.connect_after ("cursor-changed", self._controller.on_treeview_cursor_changed)
- self.cview.connect ("row-expanded", self._controller.on_category_expanded, self.treeview_model)
- self.cview.connect ("row-collapsed", self._controller.on_category_collapsed, self.treeview_model)
- self.cview.show()
+ self.vbox_main.pack_start(self.history_box, False)
- LingeringSelectionWindow (self.cview)
-
- self.scrolled_results = gtk.ScrolledWindow ()
- self.scrolled_results.set_policy (gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
- self.scrolled_results.set_shadow_type(gtk.SHADOW_IN)
- self.scrolled_results.add(self.cview)
- self.scrolled_results.show()
-
- # Actions TreeView
- self.actions_box = gtk.VBox(spacing=3)
-
- self.actions_model = CuemiacActionsModel()
- self.aview = CuemiacActionsTreeView(self.actions_model)
- self.aview.connect ("action-selected", self._controller.on_action_selected)
- self.aview.connect ("go-back", self.__on_go_back)
- self.aview.show()
-
- LingeringSelectionWindow (self.aview)
-
- self.scrolled_actions = gtk.ScrolledWindow()
- self.scrolled_actions.set_policy (gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
- self.scrolled_actions.set_shadow_type(gtk.SHADOW_IN)
- self.scrolled_actions.add(self.aview)
- self.scrolled_actions.show()
- self.actions_box.pack_start(self.scrolled_actions)
-
- buttonbox = gtk.HButtonBox()
- buttonbox.set_layout(gtk.BUTTONBOX_START)
- buttonbox.show()
- self.actions_box.pack_start(buttonbox, False)
-
- back_button = gtk.Button(_("Back to Matches"))
- back_button.set_image( gtk.image_new_from_stock(gtk.STOCK_GO_BACK, gtk.ICON_SIZE_MENU) )
- back_button.set_relief(gtk.RELIEF_NONE)
- back_button.connect("clicked", self.__on_go_back)
- back_button.show()
- buttonbox.pack_start(back_button, False, False, 0)
-
# Results
self.results_box = gtk.HBox()
self.results_box.connect("unmap", self.__save_window_height)
@@ -151,127 +41,34 @@
self.vbox_main.pack_start(self.results_box)
def clear_all(self):
- deskbar.interfaces.View.clear_all(self)
+ AbstractCuemiacView.clear_all(self)
width, height = self.get_size()
if self.__small_window_height != None:
self.resize( width, self.__small_window_height )
self.results_box.hide()
- def clear_results(self):
- self.treeview_model.clear()
-
- def clear_actions(self):
- self.actions_model.clear()
-
- def clear_query(self):
- self.entry.set_text("")
- self.entry.set_icon( self.default_entry_pixbuf )
-
def get_toplevel(self):
return self
- def get_entry(self):
- return self.entry
-
- def set_clear(self):
- """
- Set a flag to clear the list of matches and actions
- as soon as the first result arrives
- """
- self._do_clear = True
-
def receive_focus(self, time):
self.entry.grab_focus()
self.realize()
self.window.set_user_time(time)
self.present()
self.move( self._model.get_window_x(), self._model.get_window_y() )
-
- def mark_history_empty(self, val):
- self.hview.set_sensitive (not val)
- self.empty_button.set_sensitive (not val)
-
- def __show_matches(self):
- self.scrolled_results.show()
- self.actions_box.hide()
-
- def __show_actions(self):
- self.scrolled_results.hide()
- self.actions_box.show()
def show_results(self):
+ AbstractCuemiacView.show_results(self)
width, height = self.get_size()
- self.results_box.show()
- self.__show_matches()
self.resize( width, self._model.get_window_height() )
-
- def display_actions(self, actions, qstring):
- self.actions_model.clear()
- self.__show_actions()
- self.actions_model.add_actions(actions, qstring)
- self.aview.grab_focus()
-
- def append_matches (self, sender, matches):
- """
- We suppose that the results belong to the text
- that is currently in the entry
- """
- if self._do_clear:
- self._do_clear = False
- self.clear_results()
- self.clear_actions()
- # Display default icon in entry
- self.update_entry_icon()
- self.treeview_model.append (matches, self.entry.get_text())
-
- def set_sensitive (self, active):
- """
- Called when the UI should be in/active because modules are loading
- """
- self.vbox_main.set_sensitive(active)
- if active:
- self.entry.grab_focus()
- def update_entry_icon (self, icon=None):
- if icon == None:
- icon = self.default_entry_pixbuf
- if not (self.cview.get_toplevel().flags() & gtk.MAPPED):
- # The view is hidden, just show default icon
- self.entry.set_icon (icon)
- return
-
- path, column = self.cview.get_cursor ()
-
- if path != None and self.entry.get_text() != "":
- match = self.treeview_model[self.treeview_model.get_iter(path)][self.treeview_model.MATCHES]
- if not isinstance(match, CuemiacCategory):
- icon = match.get_icon()
-
- self.entry.set_icon (icon)
-
- def __on_go_back(self, widget):
- self.__show_matches()
- self.cview.grab_focus()
- return False
-
def __on_window_key_press_event(self, window, event):
if event.keyval == gtk.keysyms.Escape:
self.emit("destroy-event", event)
return False
- def __focus_matches_if_visible(self, mode):
- if (self.results_box.get_property("visible")):
- if mode == "top":
- self.cview.select_first_item()
- elif mode == "bottom":
- self.cview.select_last_item()
- self.cview.grab_focus()
- return True
- else:
- return False
-
def __save_window_size(self, window, event):
"""
Save window width and height of the window when
Modified: trunk/deskbar/ui/Makefile.am
==============================================================================
--- trunk/deskbar/ui/Makefile.am (original)
+++ trunk/deskbar/ui/Makefile.am Thu Apr 24 16:54:23 2008
@@ -5,6 +5,7 @@
__init__.py \
About.py \
AbstractCuemiacDeskbarIcon.py \
+ AbstractCuemiacView.py \
CuemiacWindowController.py \
CuemiacWindowView.py \
CuemiacAlignedView.py \
Modified: trunk/po/POTFILES.in
==============================================================================
--- trunk/po/POTFILES.in (original)
+++ trunk/po/POTFILES.in Thu Apr 24 16:54:23 2008
@@ -41,8 +41,7 @@
deskbar/ui/About.py
deskbar/ui/cuemiac/CuemiacHeader.py
deskbar/ui/cuemiac/CuemiacItems.py
-deskbar/ui/CuemiacAlignedView.py
-deskbar/ui/CuemiacWindowView.py
+deskbar/ui/AbstractCuemiacView.py
deskbar/ui/DeskbarApplet.py
deskbar/ui/DeskbarStatusIcon.py
deskbar/ui/preferences/AccelEntry.py
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]