gimmie r668 - in trunk: . gimmie



Author: orph
Date: Sat Feb  9 10:24:49 2008
New Revision: 668
URL: http://svn.gnome.org/viewvc/gimmie?rev=668&view=rev

Log:
2008-02-09  Alex Graveley  <alex beatniksoftware com>

	Some re-org now that we expect to add another frontend (Awn).
	This removes some of the hacks made for the applet version.

	* gimmie/gimmie_awn.py: Make the TopicBox a subclass of
	awn.AppletDialog, and use a GrabOnShowHelper to auto-hide a shown
	one.

	* gimmie/gimmie_util.py (GrabOnShowHelper): Convert to gtk.Window
	mixin instead of subclass and move to here from gimmie_util.py, so
	it can be used by gimmie_awn.py.

	* gimmie/gimmie_base.py (Topic.get_topic_window): Remove gross
	import of a gimmie_topicwin to instantiate a view.



Modified:
   trunk/ChangeLog
   trunk/gimmie/gimmie_applet.py
   trunk/gimmie/gimmie_awn.py
   trunk/gimmie/gimmie_bar.py
   trunk/gimmie/gimmie_base.py
   trunk/gimmie/gimmie_gui.py
   trunk/gimmie/gimmie_topicwin.py
   trunk/gimmie/gimmie_util.py

Modified: trunk/gimmie/gimmie_applet.py
==============================================================================
--- trunk/gimmie/gimmie_applet.py	(original)
+++ trunk/gimmie/gimmie_applet.py	Sat Feb  9 10:24:49 2008
@@ -19,7 +19,7 @@
 from gimmie_people import PeopleTopic
 from gimmie_prefs import Preferences
 from gimmie_topicwin import TopicView, TimeBar
-from gimmie_util import bookmarks, icon_factory, launcher, GConfBridge, KillFocusPadding, ToolMenuButton
+from gimmie_util import bookmarks, icon_factory, launcher, GConfBridge, KillFocusPadding, ToolMenuButton, GrabOnShowHelper
 
 
 def color_average(col1, col2, colormap):
@@ -37,75 +37,6 @@
     return color_average(col1, state_col, widget.get_colormap())
 
 
-class GrabOnShowWindow(gtk.Window):
-    __gsignals__ = {
-        'grab-broken-event': 'override',
-        'map-event' : 'override',
-        'unmap-event' : 'override',
-        'button-press-event' : 'override',
-        'key-press-event' : 'override',
-        }
-
-    def __init__(self):
-        gtk.Window.__init__(self)
-        self.grabbed = False
-
-    def _grab_window_event(self, win, ev):
-        if ev.type in (gtk.gdk.UNMAP, gtk.gdk.SELECTION_CLEAR):
-            self.do_map_event(ev) 
-        return False
-
-    def do_grab_broken_event(self, ev):
-        if ev.grab_window and self.grabbed:
-            ev_widget = ev.grab_window.get_user_data()
-            if isinstance(ev_widget, gtk.Widget):
-                ev_widget.connect("event", self._grab_window_event)
-
-            self.grabbed = False # No longer grabbed
-        return True
-
-    def do_map_event(self, ev):
-        if not self.grabbed:
-            self.grab_focus()
-            self.grab_add()
-
-            time = gtk.get_current_event_time()
-            gtk.gdk.pointer_grab(self.window, True, gtk.gdk.BUTTON_PRESS_MASK, None, None, time)
-            gtk.gdk.keyboard_grab(self.window, True, time)
-        self.grabbed = True
-
-    def do_unmap_event(self, ev):
-        if self.grabbed:
-            time = gtk.get_current_event_time()
-            gtk.gdk.pointer_ungrab(time)
-            gtk.gdk.keyboard_ungrab(time)
-            self.grab_remove()
-        self.grabbed = False
-
-    def do_button_press_event(self, ev):
-        win_tuple = gtk.gdk.window_at_pointer()
-        ev_win = (win_tuple and win_tuple[0]) or None
-
-        if not ev_win:
-            # External application, hide and give up grab
-            self.hide()
-        elif ev_win.get_toplevel() != self.window:
-            # Other toplevel window, hide and forward the event
-            ev_widget = ev_win.get_user_data()
-            if ev_widget.event(ev):
-                self.hide()
-            else:
-                return False
-
-        return True
-
-    def do_key_press_event(self, ev):
-        if not gtk.Window.do_key_press_event(self, ev) \
-               and ev.keyval == gtk.gdk.keyval_from_name("Escape"):
-            self.hide()
-            return True
-
-
 class AppletOrientationHelper:
     def __init__(self, widget, applet, track_widget):
         update_cb = lambda: self.update_position(widget, track_widget, applet)
@@ -179,14 +110,16 @@
         widget.move(x, y)
 
 
-class TopicMenu(GrabOnShowWindow, TopicView):
+class TopicMenu(gtk.Window, TopicView):
     '''
     Panel applet menu version of topic window.
     '''
     def __init__(self, topic):
-        GrabOnShowWindow.__init__(self)
+        gtk.Window.__init__(self)
         TopicView.__init__(self, topic)
 
+        self.grab_helper = GrabOnShowHelper(self)
+
         self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_POPUP_MENU)
         self.set_decorated(False)
 
@@ -429,15 +362,6 @@
         self.toolbar.insert(self._make_toolbar_expander(), -1)
 
 
-def get_topic_window_mod(self):
-    if not self.topic_window:
-        self.topic_window = TopicMenu(self)
-    return self.topic_window
-
-### Override Topic to use the applet menu version.
-Topic.get_topic_window = get_topic_window_mod
-
-
 class TopicButtonMod(gtk.ToggleButton):
     __gsignals__ = {
         'button-press-event' : 'override',
@@ -561,11 +485,10 @@
 
     def _show(self):
         if not self.topic_win:
-            self.topic_win = self.topic.get_topic_window()
+            self.topic_win = TopicMenu(self.topic)
             self.topic_win.connect("map-event", self._map)
             self.topic_win.connect("unmap-event", self._unmap)
-            #self.topic_win.realize()
-            #self.do_set_wm_icon_geometry()
+            self.topic.set_topic_window(self.topic_win)
 
             AppletOrientationHelper(self.topic_win, self.applet, self)
 

Modified: trunk/gimmie/gimmie_awn.py
==============================================================================
--- trunk/gimmie/gimmie_awn.py	(original)
+++ trunk/gimmie/gimmie_awn.py	Sat Feb  9 10:24:49 2008
@@ -12,22 +12,25 @@
 gimmie_globals.gimmie_is_panel_applet = lambda: True
 
 from gimmie_base import Topic
-from gimmie_util import bookmarks, icon_factory, ToolMenuButton
+from gimmie_util import bookmarks, icon_factory, ToolMenuButton, GrabOnShowHelper
 from gimmie_topicwin import TopicView, TimeBar
 
 
-class TopicBox(gtk.VBox, TopicView):
+class TopicBox(awn.AppletDialog, TopicView):
     '''
     Panel applet menu version of topic window.
     '''
-    def __init__(self, topic):
-        gtk.VBox.__init__(self, False, 0)
+    def __init__(self, applet, topic):
+        awn.AppletDialog.__init__(self, applet)
         TopicView.__init__(self, topic)
 
+        self.grab_helper = GrabOnShowHelper(self)
+
         # Contains the visual frame, giving it some space
-        self._content = self
+        self._content = gtk.VBox(False, 0)
         self._content.set_border_width(0)
         self._content.show()
+        self.add(self._content)
 
         # Toolbar
         self._content.pack_start(self.toolbar, False, False, 0)
@@ -63,9 +66,9 @@
         body.pack_start(self.content_frame, True, True, 0)
 
         # Bound the height request of the scrolled window and icon view
-        #self.scroll.connect("size-request", self._scroll_get_best_size)
-        #self.scroll.get_vadjustment().connect("changed",
-        #                                      lambda adj: self.scroll.queue_resize_no_redraw())
+        self.scroll.connect("size-request", self._scroll_get_best_size)
+        self.scroll.get_vadjustment().connect("changed",
+                                              lambda adj: self.scroll.queue_resize_no_redraw())
 
         self.view.set_size_request(500, -1)
         self.view.connect("item-activated", lambda v, p: self.hide()) # Iconify on item open
@@ -139,8 +142,8 @@
         vadj.set_property("upper", 0)
 
         ### NOTE: Awn applet isn't a toplevel, it's embedded in an AppletDialog
-        #w, h = self.size_request()
-        #self.resize(w, h)
+        w, h = self.child.size_request()
+        self.resize(w, h)
 
     def load_items(self, items, ondone_cb = None):
         '''
@@ -233,15 +236,6 @@
         self.toolbar.insert(self._make_toolbar_expander(), -1)
 
 
-def get_topic_window_mod(self):
-    if not self.topic_window:
-        self.topic_window = TopicBox(self)
-    return self.topic_window
-
-### Override Topic to use the applet menu version.
-Topic.get_topic_window = get_topic_window_mod
-
-
 class GimmieAwnApplet(awn.AppletSimple):
     def __init__ (self, uid, orient, height, topic):
         awn.AppletSimple.__init__ (self, uid, orient, height)
@@ -251,18 +245,17 @@
         self.set_icon(topic.get_icon(height))
 
         self.title = awn.awn_title_get_default()
-        self.dialog = awn.AppletDialog(self)
         self.connect("button-press-event", self.button_press)
         self.connect("enter-notify-event", self.enter_notify)
         self.connect("leave-notify-event", self.leave_notify)
 
     def button_press(self, widget, event):
         if not self.topic_win:
-            self.topic_win = self.topic.get_topic_window()
-            self.dialog.add(self.topic_win)
+            self.topic_win = TopicBox(self, self.topic)
+            self.topic.set_topic_window(self.topic_win)
         self.title.hide(self)
         self.topic_win.search_tool_item.entry.grab_focus()
-        self.dialog.show_all()
+        self.topic_win.show_all()
 
     def enter_notify(self, widget, event):
         self.title.show(self, self.topic.get_name())

Modified: trunk/gimmie/gimmie_bar.py
==============================================================================
--- trunk/gimmie/gimmie_bar.py	(original)
+++ trunk/gimmie/gimmie_bar.py	Sat Feb  9 10:24:49 2008
@@ -1,10 +1,232 @@
 #!/usr/bin/env python
 
+from gettext import gettext as _
+
 import gtk
 
-from gimmie_base import IOrientationAware
-from gimmie_gui import EdgeWindow, AnchoredWindow, TopicRunningList, TopicButton
-from gimmie_util import FocusRaiser, NoWindowButton
+from gimmie_base import IOrientationAware, gimmie_get_topic_for_uri
+from gimmie_gui import EdgeWindow, AnchoredWindow, TopicRunningList
+from gimmie_util import FocusRaiser, NoWindowButton, KillFocusPadding
+from gimmie_topicwin import TopicView, ZoomMenuToolItem
+
+
+class HideOnDeleteWindow(gtk.Window):
+    __gsignals__ = {
+        'hide' : 'override',
+        'delete-event' : 'override',
+        'key-press-event' : 'override',
+        }
+
+    def __init__(self):
+        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
+
+        # Act the same as hidden when iconified by hiding from the task list.
+        self.connect("map-event", lambda w, ev: self.set_skip_taskbar_hint(False))
+        self.connect("unmap-event", lambda w, ev: self.set_skip_taskbar_hint(True))
+
+    def do_hide(self):
+        self.chain()
+
+        # Workaround Gtk bug, where adding or changing Widgets
+        # while the Window is hidden causes it to be reshown at
+        # 0,0...
+        self_x, self_y = self.get_position()
+        self.move(self_x, self_y)
+        return True
+
+    def do_delete_event(self, ev):
+        self.hide()
+        return True
+
+    def do_key_press_event(self, ev):
+        if not gtk.Window.do_key_press_event(self, ev) \
+               and ev.keyval == gtk.gdk.keyval_from_name("Escape"):
+            self.iconify()
+            return True
+
+
+class TopicWindow(HideOnDeleteWindow, TopicView):
+    '''
+    The toplevel window representing a Topic\'s ItemSources, allowing one to be
+    active at a time and displaying it\'s item contents using an ItemIconView.
+    '''
+    def __init__(self, topic):
+        HideOnDeleteWindow.__init__(self)
+        TopicView.__init__(self, topic)
+
+        self.set_title(topic.get_name())
+        self.set_position(gtk.WIN_POS_CENTER)
+        self.set_default_size(730, -1)
+
+        self.add_accel_group(self.accel_group)
+
+        ### Uncomment to use the topic's color as a border
+        #self.modify_bg(gtk.STATE_NORMAL, topic.get_hint_color())
+
+        # Vbox containing the toolbar and content
+        vbox = gtk.VBox(False, 0)
+        vbox.show()
+        self.add(vbox)
+
+        # Toolbar
+        vbox.pack_start(self.toolbar, False, False, 0)
+
+        # Contains the visual frame, giving it some space
+        content = gtk.HBox(False, 0)
+        content.set_border_width(12)
+        content.show()
+        vbox.add(content)
+
+        # Hbox containing the sidebar buttons and the iconview
+        body = gtk.HBox(False, 12)
+        body.show()
+        content.pack_start(body, True, True, 0)
+
+        # Load up the sidebar
+        body.pack_start(self.sidebar, False, False, 0)
+
+        # Add frame containing the icon view
+        body.pack_start(self.content_frame, True, True, 0)
+
+        # Iconview for the current sidebar selection
+        self.view.connect("item-activated", lambda v, p: self.iconify()) # Iconify on item open
+
+        # Zoom drop down list
+        self.zoom_menu = ZoomMenuToolItem()
+        self.zoom_menu.set_tooltip(self.tooltips, _("Set the zoom level"))
+        self.zoom_menu.set_is_important(True)
+        self.zoom_menu.connect("zoom-changed", lambda w, num_days: self.zoom_changed(num_days))
+        self.zoom_menu.connect("open-timeline", lambda w: self._open_timeline())
+
+        ### Uncomment to make parts of the window draggable (only toolbar currently)
+        #self.connect_after("button-press-event",
+        #                   lambda w, ev: self.begin_move_drag(ev.button,
+        #                                                      int(ev.x_root),
+        #                                                      int(ev.y_root),
+        #                                                      ev.time))
+
+        # Setup the toolbar
+        self._add_toolbar_items()
+
+        # Select an initial sidebar button
+        self.find_first_button()
+
+    def get_zoom_level(self):
+        return self.zoom_menu.get_zoom_level()
+
+    def get_zoom_level_list(self):
+        return self.zoom_menu.get_zoom_level_list()
+
+    def set_zoom_level(self, zoom):
+        self.zoom_menu.set_zoom_level(zoom)
+
+    def show_hide_zoomer(self, show):
+        self.zoom_menu.set_sensitive(show)
+
+    def _open_timeline(self):
+        topic = gimmie_get_topic_for_uri("topic://Computer")
+        topicwin = topic.get_topic_window()
+        topicwin.set_source_by_uri("source://Timeline")
+        topicwin.present()
+
+    def _add_toolbar_items(self):
+        for i in self.topic.get_toolbar_items(self.tooltips):
+            if not i:
+                i = gtk.SeparatorToolItem()
+            i.show_all()
+            self.toolbar.insert(i, -1)
+
+        # Right-align the zoom and search tool items
+        sep = gtk.SeparatorToolItem()
+        sep.set_draw(False)
+        sep.set_expand(True)
+        sep.show()
+        self.toolbar.insert(sep, -1)
+
+        self.toolbar.insert(self.zoom_menu, -1)
+
+        self.add_search_toolitem()
+
+
+class TopicButton(gtk.Button):
+    __gsignals__ = {
+        'size-allocate' : 'override',
+        'button-press-event' : 'override'
+        }
+
+    def __init__(self, topic, edge_gravity):
+        gtk.Button.__init__(self)
+        self.modify_bg(gtk.STATE_NORMAL, topic.get_hint_color())
+        self.set_property("can-default", False)
+        self.set_property("can-focus", False)
+        self.set_border_width(0)
+        
+        KillFocusPadding(self, "topic-button")
+        
+        label = topic.get_button_content(edge_gravity)
+        label.show()
+        self.add(label)
+
+        ### FIXME: Figure out why button adds 2px of padding
+        #self.set_size_request(-1, 24)
+        
+        self.topic = topic
+        self.topic_win = None
+
+    def do_set_wm_icon_geometry(self):
+        '''
+        Set the _NET_WM_ICON_GEOMETRY window manager hint, so that the topic
+        window will minimize onto this button\'s allocatied area.  See
+        http://standards.freedesktop.org/wm-spec/latest for details.
+        '''
+        if self.window and self.topic_win and self.topic_win.window:
+            win_x, win_y = self.window.get_origin()
+
+            # values are left, right, width, height
+            propvals = [win_x + self.allocation.x,
+                        win_y + self.allocation.y,
+                        self.allocation.width,
+                        self.allocation.height]
+
+            # tell window manager where to animate minimizing this app
+            self.topic_win.window.property_change("_NET_WM_ICON_GEOMETRY",
+                                                  "CARDINAL",
+                                                  32,
+                                                  gtk.gdk.PROP_MODE_REPLACE,
+                                                  propvals)
+
+    def do_clicked(self):
+        if not self.topic_win:
+            self.topic_win = TopicWindow(self.topic)
+            self.topic_win.realize()
+            self.topic.set_topic_window(self.topic_win)
+            self.do_set_wm_icon_geometry()
+        self.topic_win.deiconify()
+        self.topic_win.present()
+
+    def do_size_allocate(self, alloc):
+        ret = self.chain(alloc)
+        self.do_set_wm_icon_geometry()
+        return ret
+
+    def do_button_press_event(self, ev):
+        if ev.button == 3:
+            menu = gtk.Menu()
+
+            for mi in self.topic.get_context_menu_items():
+                if not mi:
+                    mi = gtk.SeparatorMenuItem()
+                    mi.show()
+                menu.append(mi)
+
+            menu.connect('selection-done', lambda x: menu.destroy())
+
+            menu.attach_to_widget(self, None)
+            menu.popup(None, None, None, ev.button, ev.time)
+
+            return True
+        else:
+            return self.chain(ev)
 
 
 class GimmieBar:

Modified: trunk/gimmie/gimmie_base.py
==============================================================================
--- trunk/gimmie/gimmie_base.py	(original)
+++ trunk/gimmie/gimmie_base.py	Sat Feb  9 10:24:49 2008
@@ -406,13 +406,13 @@
                         yield item
 
     def get_topic_window(self):
-        # FIXME: Hack around rescursive import
-        from gimmie_topicwin import TopicWindow
-        
-        if not self.topic_window:
-            self.topic_window = TopicWindow(self)
+        assert self.topic_window, "Request for unset topic window!"
         return self.topic_window
 
+    def set_topic_window(self, win):
+        assert self.topic_window == None, "Attempt to set topic window twice!"
+        self.topic_window = win
+
     def get_source_for_uri(self, uri):
         for source in self.get_sidebar_source_list():
             if isinstance(source, Item) and source.get_uri() == uri:

Modified: trunk/gimmie/gimmie_gui.py
==============================================================================
--- trunk/gimmie/gimmie_gui.py	(original)
+++ trunk/gimmie/gimmie_gui.py	Sat Feb  9 10:24:49 2008
@@ -335,86 +335,6 @@
             self.show()
 
 
-class TopicButton(gtk.Button):
-    __gsignals__ = {
-        'size-allocate' : 'override',
-        'button-press-event' : 'override'
-        }
-
-    def __init__(self, topic, edge_gravity):
-        gtk.Button.__init__(self)
-        self.modify_bg(gtk.STATE_NORMAL, topic.get_hint_color())
-        self.set_property("can-default", False)
-        self.set_property("can-focus", False)
-        self.set_border_width(0)
-        
-        KillFocusPadding(self, "topic-button")
-        
-        label = topic.get_button_content(edge_gravity)
-        label.show()
-        self.add(label)
-
-        ### FIXME: Figure out why button adds 2px of padding
-        #self.set_size_request(-1, 24)
-        
-        self.topic = topic
-        self.topic_win = None
-
-    def do_set_wm_icon_geometry(self):
-        '''
-        Set the _NET_WM_ICON_GEOMETRY window manager hint, so that the topic
-        window will minimize onto this button\'s allocatied area.  See
-        http://standards.freedesktop.org/wm-spec/latest for details.
-        '''
-        if self.window and self.topic_win and self.topic_win.window:
-            win_x, win_y = self.window.get_origin()
-
-            # values are left, right, width, height
-            propvals = [win_x + self.allocation.x,
-                        win_y + self.allocation.y,
-                        self.allocation.width,
-                        self.allocation.height]
-
-            # tell window manager where to animate minimizing this app
-            self.topic_win.window.property_change("_NET_WM_ICON_GEOMETRY",
-                                                  "CARDINAL",
-                                                  32,
-                                                  gtk.gdk.PROP_MODE_REPLACE,
-                                                  propvals)
-
-    def do_clicked(self):
-        if not self.topic_win:
-            self.topic_win = self.topic.get_topic_window()
-            self.topic_win.realize()
-            self.do_set_wm_icon_geometry()
-        self.topic_win.deiconify()
-        self.topic_win.present()
-
-    def do_size_allocate(self, alloc):
-        ret = self.chain(alloc)
-        self.do_set_wm_icon_geometry()
-        return ret
-
-    def do_button_press_event(self, ev):
-        if ev.button == 3:
-            menu = gtk.Menu()
-
-            for mi in self.topic.get_context_menu_items():
-                if not mi:
-                    mi = gtk.SeparatorMenuItem()
-                    mi.show()
-                menu.append(mi)
-
-            menu.connect('selection-done', lambda x: menu.destroy())
-
-            menu.attach_to_widget(self, None)
-            menu.popup(None, None, None, ev.button, ev.time)
-
-            return True
-        else:
-            return self.chain(ev)
-
-
 class DockWindow(gtk.Window):
     __gsignals__ = {
         'realize' : 'override',

Modified: trunk/gimmie/gimmie_topicwin.py
==============================================================================
--- trunk/gimmie/gimmie_topicwin.py	(original)
+++ trunk/gimmie/gimmie_topicwin.py	Sat Feb  9 10:24:49 2008
@@ -19,7 +19,7 @@
 except ImportError:
     pass
 
-from gimmie_base import ItemSource, gimmie_get_topic_for_uri
+from gimmie_base import ItemSource
 from gimmie_util import bookmarks, icon_factory, ToolMenuButton, gconf_bridge
 from gimmie_globals import gimmie_is_panel_applet
 
@@ -573,41 +573,6 @@
             self.spark.set_dates(dates)
 
 
-class HideOnDeleteWindow(gtk.Window):
-    __gsignals__ = {
-        'hide' : 'override',
-        'delete-event' : 'override',
-        'key-press-event' : 'override',
-        }
-
-    def __init__(self):
-        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
-
-        # Act the same as hidden when iconified by hiding from the task list.
-        self.connect("map-event", lambda w, ev: self.set_skip_taskbar_hint(False))
-        self.connect("unmap-event", lambda w, ev: self.set_skip_taskbar_hint(True))
-
-    def do_hide(self):
-        self.chain()
-
-        # Workaround Gtk bug, where adding or changing Widgets
-        # while the Window is hidden causes it to be reshown at
-        # 0,0...
-        self_x, self_y = self.get_position()
-        self.move(self_x, self_y)
-        return True
-
-    def do_delete_event(self, ev):
-        self.hide()
-        return True
-
-    def do_key_press_event(self, ev):
-        if not gtk.Window.do_key_press_event(self, ev) \
-               and ev.keyval == gtk.gdk.keyval_from_name("Escape"):
-            self.iconify()
-            return True
-
-
 class ItemIconView(gtk.IconView):
     '''
     Icon view which displays Items in the style of the Nautilus horizontal mode,
@@ -1244,107 +1209,3 @@
         self.toolbar.insert(item, -1)
         self.search_tool_item = item
 
-
-class TopicWindow(HideOnDeleteWindow, TopicView):
-    '''
-    The toplevel window representing a Topic\'s ItemSources, allowing one to be
-    active at a time and displaying it\'s item contents using an ItemIconView.
-    '''
-    def __init__(self, topic):
-        HideOnDeleteWindow.__init__(self)
-        TopicView.__init__(self, topic)
-
-        self.set_title(topic.get_name())
-        self.set_position(gtk.WIN_POS_CENTER)
-        self.set_default_size(730, -1)
-
-        self.add_accel_group(self.accel_group)
-
-        ### Uncomment to use the topic's color as a border
-        #self.modify_bg(gtk.STATE_NORMAL, topic.get_hint_color())
-
-        # Vbox containing the toolbar and content
-        vbox = gtk.VBox(False, 0)
-        vbox.show()
-        self.add(vbox)
-
-        # Toolbar
-        vbox.pack_start(self.toolbar, False, False, 0)
-
-        # Contains the visual frame, giving it some space
-        content = gtk.HBox(False, 0)
-        content.set_border_width(12)
-        content.show()
-        vbox.add(content)
-
-        # Hbox containing the sidebar buttons and the iconview
-        body = gtk.HBox(False, 12)
-        body.show()
-        content.pack_start(body, True, True, 0)
-
-        # Load up the sidebar
-        body.pack_start(self.sidebar, False, False, 0)
-
-        # Add frame containing the icon view
-        body.pack_start(self.content_frame, True, True, 0)
-
-        # Iconview for the current sidebar selection
-        self.view.connect("item-activated", lambda v, p: self.iconify()) # Iconify on item open
-
-        # Zoom drop down list
-        self.zoom_menu = ZoomMenuToolItem()
-        self.zoom_menu.set_tooltip(self.tooltips, _("Set the zoom level"))
-        self.zoom_menu.set_is_important(True)
-        self.zoom_menu.connect("zoom-changed", lambda w, num_days: self.zoom_changed(num_days))
-        self.zoom_menu.connect("open-timeline", lambda w: self._open_timeline())
-
-        ### Uncomment to make parts of the window draggable (only toolbar currently)
-        #self.connect_after("button-press-event",
-        #                   lambda w, ev: self.begin_move_drag(ev.button,
-        #                                                      int(ev.x_root),
-        #                                                      int(ev.y_root),
-        #                                                      ev.time))
-
-        # Setup the toolbar
-        self._add_toolbar_items()
-
-        # Select an initial sidebar button
-        self.find_first_button()
-
-    def get_zoom_level(self):
-        return self.zoom_menu.get_zoom_level()
-
-    def get_zoom_level_list(self):
-        return self.zoom_menu.get_zoom_level_list()
-
-    def set_zoom_level(self, zoom):
-        self.zoom_menu.set_zoom_level(zoom)
-
-    def show_hide_zoomer(self, show):
-        self.zoom_menu.set_sensitive(show)
-
-    def _open_timeline(self):
-        topic = gimmie_get_topic_for_uri("topic://Computer")
-        topicwin = topic.get_topic_window()
-        topicwin.set_source_by_uri("source://Timeline")
-        topicwin.present()
-
-    def _add_toolbar_items(self):
-        for i in self.topic.get_toolbar_items(self.tooltips):
-            if not i:
-                i = gtk.SeparatorToolItem()
-            i.show_all()
-            self.toolbar.insert(i, -1)
-
-        # Right-align the zoom and search tool items
-        sep = gtk.SeparatorToolItem()
-        sep.set_draw(False)
-        sep.set_expand(True)
-        sep.show()
-        self.toolbar.insert(sep, -1)
-
-        self.toolbar.insert(self.zoom_menu, -1)
-
-        self.add_search_toolitem()
-
-

Modified: trunk/gimmie/gimmie_util.py
==============================================================================
--- trunk/gimmie/gimmie_util.py	(original)
+++ trunk/gimmie/gimmie_util.py	Sat Feb  9 10:24:49 2008
@@ -364,6 +364,77 @@
             self.label_horiz.show()
 
 
+class GrabOnShowHelper:
+    def __init__(self, window):
+        self.window = window
+        window.connect("grab-broken-event", self.do_grab_broken_event)
+        window.connect("map-event", self.do_map_event)
+        window.connect("unmap-event", self.do_unmap_event)
+        window.connect("button-press-event", self.do_button_press_event)
+        window.connect("key-press-event", self.do_key_press_event)
+
+        self.grabbed = False
+
+    def _grab_window_event(self, win, ev):
+        if ev.type in (gtk.gdk.UNMAP, gtk.gdk.SELECTION_CLEAR):
+            self.do_map_event(ev) 
+        return False
+
+    def do_grab_broken_event(self, win, ev):
+        if ev.grab_window and self.grabbed:
+            ev_widget = ev.grab_window.get_user_data()
+            if isinstance(ev_widget, gtk.Widget):
+                ev_widget.connect("event", self._grab_window_event)
+
+            self.grabbed = False # No longer grabbed
+        return True
+
+    def do_map_event(self, win, ev):
+        if not self.grabbed:
+            self.window.grab_focus()
+            self.window.grab_add()
+
+            time = gtk.get_current_event_time()
+            gtk.gdk.pointer_grab(self.window.window,
+                                 True,
+                                 gtk.gdk.BUTTON_PRESS_MASK,
+                                 None,
+                                 None,
+                                 time)
+            gtk.gdk.keyboard_grab(self.window.window, True, time)
+        self.grabbed = True
+
+    def do_unmap_event(self, win, ev):
+        if self.grabbed:
+            time = gtk.get_current_event_time()
+            gtk.gdk.pointer_ungrab(time)
+            gtk.gdk.keyboard_ungrab(time)
+            self.window.grab_remove()
+        self.grabbed = False
+
+    def do_button_press_event(self, win, ev):
+        win_tuple = gtk.gdk.window_at_pointer()
+        ev_win = (win_tuple and win_tuple[0]) or None
+
+        if not ev_win:
+            # External application, hide and give up grab
+            self.window.hide()
+        elif ev_win.get_toplevel() != self.window.window:
+            # Other toplevel window, hide and forward the event
+            ev_widget = ev_win.get_user_data()
+            if ev_widget.event(ev):
+                self.window.hide()
+            else:
+                return False
+
+        return True
+
+    def do_key_press_event(self, win, ev):
+        if ev.keyval == gtk.gdk.keyval_from_name("Escape"):
+            self.window.hide()
+            return True
+
+
 class IconFactory:
     '''
     Icon lookup swiss-army knife (from menutreemodel.py)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]