deskbar-applet r1864 - in branches/button-ui/deskbar/ui: . cuemiac



Author: sebp
Date: Thu Jan 24 16:27:05 2008
New Revision: 1864
URL: http://svn.gnome.org/viewvc/deskbar-applet?rev=1864&view=rev

Log:
Entry is now focusable
Still have problems with the proper size of the window

Modified:
   branches/button-ui/deskbar/ui/CuemiacAlignedView.py
   branches/button-ui/deskbar/ui/CuemiacWindowController.py
   branches/button-ui/deskbar/ui/cuemiac/CuemiacAlignedWindow.py

Modified: branches/button-ui/deskbar/ui/CuemiacAlignedView.py
==============================================================================
--- branches/button-ui/deskbar/ui/CuemiacAlignedView.py	(original)
+++ branches/button-ui/deskbar/ui/CuemiacAlignedView.py	Thu Jan 24 16:27:05 2008
@@ -1,6 +1,7 @@
 import gtk
 import gtk.gdk
 import gobject
+import gnomeapplet
 from gettext import gettext as _
 import deskbar.interfaces.View
 import deskbar.core.Utils
@@ -23,15 +24,26 @@
     
     def __init__(self, controller, model, widget, applet):
         deskbar.interfaces.View.__init__(self, controller, model)
-        CuemiacAlignedWindow.__init__(self, widget, applet, gtk.WINDOW_POPUP)
+        CuemiacAlignedWindow.__init__(self, widget, applet)#, gtk.WINDOW_POPUP)
         self._controller.register_view(self)
         self.__small_window_height = None
         self._do_clear = True
+        self.applet = applet
+        
+        self.set_type_hint (gtk.gdk.WINDOW_TYPE_HINT_MENU)
+        self.set_keep_above(True)
+        self.applet.set_applet_flags(gnomeapplet.EXPAND_MINOR)
+        self.applet.set_flags(gtk.CAN_FOCUS)
+        
+        self._screen_height = self.get_screen().get_height ()
+        self._screen_width = self.get_screen().get_width ()
+        self._max_window_height = int (0.8 * self._screen_height)
+        self._max_window_width = int (0.6 * self._screen_width)
         
-        self.connect("configure-event", self.__save_window_size)
         self.connect("delete-event", self._controller.on_quit)
         self.connect("destroy-event", self._controller.on_quit)
         self.connect("key-press-event", self.__on_window_key_press_event)
+        self.connect("button-press-event", self.__on_button_press_event)
        
         self.set_title("Deskbar Applet")
         self.set_default_size( self._model.get_window_width(), -1 )
@@ -65,11 +77,11 @@
 #        self.entry.get_entry().set_completion(self.completion)
         self.entry.show()
         
-        header = CuemiacHeader ( self.entry )
-        header.show()   
+        self.header = CuemiacHeader ( self.entry )
+        self.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)
@@ -149,21 +161,23 @@
        
         # Results
         self.results_box = gtk.HBox()
-        self.results_box.connect("unmap", self.__save_window_height)
         self.results_box.pack_start(self.scrolled_results)
         self.results_box.pack_start(self.actions_box)
         self.vbox_main.pack_start(self.results_box)
+        
+        self.__adjust_popup_size()
    
     def __on_row_act(self, view, path, column):
         print "======================"
     
     def clear_all(self):
         deskbar.interfaces.View.clear_all(self)
-        width, height = self.get_size()
-        
-        if self.__small_window_height != None:
-            self.resize( width, self.__small_window_height )
+#        width, height = self.get_size()
+#        
+#        if self.__small_window_height != None:
+#            self.resize( width, self.__small_window_height )
         self.results_box.hide()
+        self.resize( *self.size_request() )
     
     def clear_results(self):
         self.treeview_model.clear()
@@ -189,9 +203,9 @@
         self._do_clear = True
     
     def receive_focus(self, time):
-        self.entry.grab_focus()
         self.update_position()
-        self.present()
+        self.entry.grab_focus()
+        self.present_with_time (time)
     
     def __show_matches(self):
         self.scrolled_results.show()
@@ -202,10 +216,11 @@
         self.actions_box.show()
     
     def show_results(self):
-        width, height = self.get_size()
+        #width, height = self.get_size()
         self.results_box.show()
         self.__show_matches()
-        self.resize( width, self._model.get_window_height() )
+        #self.resize( width, self._model.get_window_height() )
+        self.__adjust_popup_size()
     
     def display_actions(self, actions, qstring):
         self.actions_model.clear()
@@ -262,6 +277,9 @@
                 
         return False
     
+    def __on_button_press_event(self, window, event):
+        print event
+    
     def __focus_matches_if_visible(self, mode):
         if (self.results_box.get_property("visible")):
             if mode == "top":
@@ -273,18 +291,14 @@
         else:
             return False
         
-    def __save_window_size(self, window, event):
-        """
-        Save window width and height of the window when
-        results_box is not visible
-        """
-        self._model.set_window_width( event.width )
-        if self.__small_window_height == None:
-            self.__small_window_height = event.height
-            
-    def __save_window_height(self, resultsbox):
-        """
-        Save window height before results_box disappears
-        """
-        self._model.set_window_height( self.get_size()[1] )
+    def __adjust_popup_size (self):
+        """adjust window size to the size of the children"""
+        # FIXME: Should we handle width intelligently also?
+        w, h = self.size_request ()
+        h = h + self.header.allocation.height + 2 # To ensure we don't always show scrollbars
+        h = min (h, self._max_window_height)
+        w = min (w, self._max_window_width)
+        if w > 0 and h > 0:
+            self.resize (w, h)
+
         

Modified: branches/button-ui/deskbar/ui/CuemiacWindowController.py
==============================================================================
--- branches/button-ui/deskbar/ui/CuemiacWindowController.py	(original)
+++ branches/button-ui/deskbar/ui/CuemiacWindowController.py	Thu Jan 24 16:27:05 2008
@@ -24,8 +24,6 @@
         """
         Toggle view if keybinding has been activated
         """
-
-        print self._view
         if self._view.get_toplevel().get_property("visible"):
             self.on_quit()
         else:

Modified: branches/button-ui/deskbar/ui/cuemiac/CuemiacAlignedWindow.py
==============================================================================
--- branches/button-ui/deskbar/ui/cuemiac/CuemiacAlignedWindow.py	(original)
+++ branches/button-ui/deskbar/ui/cuemiac/CuemiacAlignedWindow.py	Thu Jan 24 16:27:05 2008
@@ -1,131 +1,136 @@
-import gtk, gnomeapplet, gobject
+import gtk
+import gnomeapplet
+import gobject
+import logging
+
+LOGGER = logging.getLogger(__name__)
 
 class CuemiacAlignedWindow (gtk.Window):
-	"""
-	Borderless window aligning itself to a given widget.
-	Use CuemiacWindow.update_position() to align it.
-	"""
-	def __init__(self, widgetToAlignWith, applet, window_type=gtk.WINDOW_TOPLEVEL):
-		"""
-		alignment should be one of
-			gnomeapplet.ORIENT_{DOWN,UP,LEFT,RIGHT}
-		
-		Call CuemiacWindow.update_position () to position the window.
-		"""
-		gtk.Window.__init__(self, window_type)
-		self.set_decorated (False)
-
-		# Skip the taskbar, and the pager, stick and stay on top
-		self.stick()
-		self.set_keep_above(True)
-		self.set_skip_pager_hint(True)
-		self.set_skip_taskbar_hint(True)
-		self.set_border_width (1)
-				
-		self.widgetToAlignWith = widgetToAlignWith
-		self.applet = applet
-		self.alignment = applet.get_orient ()
-
-		self.realize_status = None
-		self.connect ("realize", lambda win : self.__register_realize ())
-		self.connect ("delete-event", self.on_delete_event)
-		self.connect ("size-allocate", self.__resize_event)
-	
-	def on_delete_event(self, window, event):
-		# Since all users of this class expect it to remain open and alive
-		# We must catch deletion events (for example alt-f4) and just hide the window
-		self.hide()
-		return True
-		
-	def __resize_event (self, widget, allocation):
-		# Update position, cause the size might have changed for the window
-		self.update_position ()
-	
-	def update_position (self):
-		"""
-		Calculates the position and moves the window to it.
-		IMPORATNT: widgetToAlignWith should be realized!
-		"""
-		if self.realize_status == None:
-			self.realize_status = False
-			self.realize ()
-			return
-		
-		if self.realize_status == False:
-			return
-		
-		if not (self.widgetToAlignWith.flags() & gtk.REALIZED):
-                        print "WARNING: CuemiacAlignedWindow.update_position() widgetToAlignWith is not realized."
-                        return
-			
-		# Get our own dimensions & position
-		(wx, wy) = self.window.get_origin ()
-		(ax, ay) = self.widgetToAlignWith.window.get_origin ()
-
-		(ww, wh) = self.window.get_size ()
-		(aw, ah) = self.widgetToAlignWith.window.get_size ()
-
-		screen = self.get_screen()
-		monitor = screen.get_monitor_geometry (screen.get_monitor_at_window (self.applet.window))
-		
-		if self.alignment == gnomeapplet.ORIENT_LEFT:
-				x = ax - ww
-				y = ay
-
-				if (y + wh > monitor.y + monitor.height):
-					y = monitor.y + monitor.height - wh
-
-				if (y < 0):
-					y = 0
-				
-				if (y + wh > monitor.height / 2):
-					gravity = gtk.gdk.GRAVITY_SOUTH_WEST	
-				else:
-					gravity = gtk.gdk.GRAVITY_NORTH_WEST
-					
-		elif self.alignment == gnomeapplet.ORIENT_RIGHT:
-				x = ax + aw
-				y = ay
-
-				if (y + wh > monitor.y + monitor.height):
-					y = monitor.y + monitor.height - wh
-				
-				if (y < 0):
-					y = 0
-				
-				if (y + wh > monitor.height / 2):
-					gravity = gtk.gdk.GRAVITY_SOUTH_EAST
-				else:
-					gravity = gtk.gdk.GRAVITY_NORTH_EAST
-
-		elif self.alignment == gnomeapplet.ORIENT_DOWN:
-				x = ax
-				y = ay + ah
-
-				if (x + ww > monitor.x + monitor.width):
-					x = monitor.x + monitor.width - ww
-
-				if (x < 0):
-					x = 0
-
-				gravity = gtk.gdk.GRAVITY_NORTH_WEST
-		elif self.alignment == gnomeapplet.ORIENT_UP:
-				x = ax
-				y = ay - wh
-
-				if (x + ww > monitor.x + monitor.width):
-					x = monitor.x + monitor.width - ww
-
-				if (x < 0):
-					x = 0
-
-				gravity = gtk.gdk.GRAVITY_SOUTH_WEST
-		
-		self.move(x, y)
-		self.set_gravity(gravity)
-	
-	def __register_realize (self):
-		self.realize_status = True
-		self.update_position()
-		
+    """
+    Borderless window aligning itself to a given widget.
+    Use CuemiacWindow.update_position() to align it.
+    """
+    def __init__(self, widgetToAlignWith, applet, window_type=gtk.WINDOW_TOPLEVEL):
+        """
+        alignment should be one of
+            gnomeapplet.ORIENT_{DOWN,UP,LEFT,RIGHT}
+        
+        Call CuemiacWindow.update_position () to position the window.
+        """
+        gtk.Window.__init__(self, window_type)
+        self.set_decorated (False)
+
+        # Skip the taskbar, and the pager, stick and stay on top
+        self.stick()
+        self.set_keep_above(True)
+        self.set_skip_pager_hint(True)
+        self.set_skip_taskbar_hint(True)
+        self.set_border_width (1)
+                
+        self.widgetToAlignWith = widgetToAlignWith
+        self.applet = applet
+        self.alignment = applet.get_orient ()
+
+        self.realize_status = None
+        self.connect ("realize", lambda win : self.__register_realize ())
+        self.connect ("delete-event", self.on_delete_event)
+        self.connect ("size-allocate", self.__resize_event)
+    
+    def on_delete_event(self, window, event):
+        # Since all users of this class expect it to remain open and alive
+        # We must catch deletion events (for example alt-f4) and just hide the window
+        self.hide()
+        return True
+        
+    def __resize_event (self, widget, allocation):
+        # Update position, cause the size might have changed for the window
+        self.update_position ()
+    
+    def update_position (self):
+        """
+        Calculates the position and moves the window to it.
+        IMPORATNT: widgetToAlignWith should be realized!
+        """
+        if self.realize_status == None:
+            self.realize_status = False
+            self.realize ()
+            return
+        
+        if self.realize_status == False:
+            return
+        
+        if not (self.widgetToAlignWith.flags() & gtk.REALIZED):
+            LOGGER.warning("CuemiacAlignedWindow.update_position() widgetToAlignWith is not realized.")
+            return
+            
+        # Get our own dimensions & position
+        (wx, wy) = self.window.get_origin ()
+        (ax, ay) = self.widgetToAlignWith.window.get_origin ()
+
+        (ww, wh) = self.window.get_size ()
+        (aw, ah) = self.widgetToAlignWith.window.get_size ()
+
+        screen = self.get_screen()
+        monitor = screen.get_monitor_geometry (screen.get_monitor_at_window (self.applet.window))
+        
+        if self.alignment == gnomeapplet.ORIENT_LEFT:
+            x = ax - ww
+            y = ay
+            
+            if (y + wh > monitor.y + monitor.height):
+                y = monitor.y + monitor.height - wh
+            
+            if (y < 0):
+                y = 0
+            
+            if (y + wh > monitor.height / 2):
+                gravity = gtk.gdk.GRAVITY_SOUTH_WEST    
+            else:
+                gravity = gtk.gdk.GRAVITY_NORTH_WEST
+                    
+        elif self.alignment == gnomeapplet.ORIENT_RIGHT:
+            x = ax + aw
+            y = ay
+            
+            if (y + wh > monitor.y + monitor.height):
+                y = monitor.y + monitor.height - wh
+            
+            if (y < 0):
+                y = 0
+            
+            if (y + wh > monitor.height / 2):
+                gravity = gtk.gdk.GRAVITY_SOUTH_EAST
+            else:
+                gravity = gtk.gdk.GRAVITY_NORTH_EAST
+
+        elif self.alignment == gnomeapplet.ORIENT_DOWN:
+            x = ax
+            y = ay + ah
+            
+            if (x + ww > monitor.x + monitor.width):
+                x = monitor.x + monitor.width - ww
+            
+            if (x < 0):
+                x = 0
+            
+            gravity = gtk.gdk.GRAVITY_NORTH_WEST
+        elif self.alignment == gnomeapplet.ORIENT_UP:
+            x = ax
+            y = ay - wh
+            
+            if (x + ww > monitor.x + monitor.width):
+                x = monitor.x + monitor.width - ww
+            
+            if (x < 0):
+                x = 0
+            
+            gravity = gtk.gdk.GRAVITY_SOUTH_WEST
+        
+        self.move(x, y)
+        self.set_gravity(gravity)
+    
+    def __register_realize (self):
+        self.realize_status = True
+        self.update_position()
+        
 gobject.type_register (CuemiacAlignedWindow)



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