conduit r1598 - in trunk: . conduit/gtkui



Author: jstowers
Date: Tue Jul 29 22:59:27 2008
New Revision: 1598
URL: http://svn.gnome.org/viewvc/conduit?rev=1598&view=rev

Log:
	* conduit/gtkui/Canvas.py: Expand the canvas when more conduits
	get added. Fixes #516646, #517877
	* conduit/gtkui/UI.py: Account for Canvas scrolled window on DND.


Modified:
   trunk/   (props changed)
   trunk/ChangeLog
   trunk/conduit/gtkui/Canvas.py
   trunk/conduit/gtkui/UI.py

Modified: trunk/conduit/gtkui/Canvas.py
==============================================================================
--- trunk/conduit/gtkui/Canvas.py	(original)
+++ trunk/conduit/gtkui/Canvas.py	Tue Jul 29 22:59:27 2008
@@ -105,6 +105,44 @@
         self.model = None
         
         log.info("Goocanvas version: %s" % str(goocanvas.pygoocanvas_version))
+        
+    def _setup_popup_menus(self, dataproviderPopupXML, conduitPopupXML):
+        """
+        Sets up the popup menus and their callbacks
+
+        @param conduitPopupXML: The menu which is popped up when the user right
+        clicks on a conduit
+        @type conduitPopupXML: C{gtk.glade.XML}
+        @param dataproviderPopupXML: The menu which is popped up when the user right
+        clicks on a dataprovider
+        @type dataproviderPopupXML: C{gtk.glade.XML}
+        """
+
+        self.dataproviderMenu = dataproviderPopupXML.get_widget("DataProviderMenu")
+        self.configureMenuItem = dataproviderPopupXML.get_widget("configure")
+
+        self.conduitMenu = conduitPopupXML.get_widget("ConduitMenu")
+        self.twoWayMenuItem = conduitPopupXML.get_widget("two_way_sync")
+        self.slowSyncMenuItem = conduitPopupXML.get_widget("slow_sync")
+        self.autoSyncMenuItem = conduitPopupXML.get_widget("auto_sync")
+
+        self.twoWayMenuItem.connect("toggled", self.on_two_way_sync_toggle)
+        self.slowSyncMenuItem.connect("toggled", self.on_slow_sync_toggle)
+        self.autoSyncMenuItem.connect("toggled", self.on_auto_sync_toggle)
+
+        #connect the conflict popups
+        self.policyWidgets = {}
+        for policyName in Conduit.CONFLICT_POLICY_NAMES:
+            for policyValue in Conduit.CONFLICT_POLICY_VALUES:
+                widgetName = "%s_%s" % (policyName,policyValue)
+                #store the widget and connect to toggled signal
+                widget = conduitPopupXML.get_widget(widgetName)
+                widget.connect("toggled", self.on_policy_toggle, policyName, policyValue)
+                self.policyWidgets[widgetName] = widget
+                
+        #connect the menu callbacks
+        conduitPopupXML.signal_autoconnect(self)
+        dataproviderPopupXML.signal_autoconnect(self)
 
     def _show_welcome_message(self):
         """
@@ -153,11 +191,14 @@
         return items
 
     def _canvas_resized(self, widget, allocation):
-        self.set_bounds(0,0,allocation.width,allocation.height)
+        self.set_bounds(
+                    0,0,
+                    allocation.width,
+                    self._get_minimum_canvas_size(allocation.height)
+                    )
         for i in self._get_child_conduit_canvas_items():
             i.set_width(allocation.width)
 
-
     def _on_conduit_button_press(self, view, target, event):
         """
         Handle button clicks on conduits
@@ -235,6 +276,36 @@
         for i in self._get_child_conduit_canvas_items():
             y = y + i.get_height()
         return y
+        
+    def _get_minimum_canvas_size(self, allocH=None):
+        if not allocH:
+            allocH = self.get_allocation().height
+    
+        bottom = self._get_bottom_of_conduits_coord()
+        return max(bottom + ConduitCanvasItem.WIDGET_HEIGHT + 20, allocH)
+        
+    def _remove_overlap(self):
+        """
+        Moves the ConduitCanvasItems to stop them overlapping visually
+        """
+        items = self._get_child_conduit_canvas_items()
+        if len(items) > 0:
+            #special case where the top one was deleted
+            top = items[0].get_top()-(LINE_WIDTH/2)
+            if top != 0.0:
+                for item in items:
+                    #translate all those below
+                    item.translate(0,-top)
+            else:
+                for i in xrange(0, len(items)):
+                    try:
+                        overlap = items[i].get_bottom() - items[i+1].get_top()
+                        if overlap != 0.0:
+                            #translate all those below
+                            for item in items[i+1:]:
+                                item.translate(0,overlap)
+                    except IndexError: 
+                        break
 
     def on_conduit_removed(self, sender, conduitRemoved):
         for item in self._get_child_conduit_canvas_items():
@@ -248,6 +319,14 @@
         self._remove_overlap()
         self._show_welcome_message()
 
+        c_x,c_y,c_w,c_h = self.get_bounds()
+        self.set_bounds(
+                    0,
+                    0,
+                    c_w,
+                    self._get_minimum_canvas_size()
+                    )
+
     def on_conduit_added(self, sender, conduitAdded):
         """
         Creates a ConduitCanvasItem for the new conduit
@@ -277,6 +356,12 @@
         conduitAdded.connect("dataprovider-removed", self.on_dataprovider_removed, conduitCanvasItem)
 
         self._show_welcome_message()
+        self.set_bounds(
+                    0,
+                    0,
+                    c_w,
+                    self._get_minimum_canvas_size()
+                    )
 
     def on_dataprovider_removed(self, sender, dataproviderRemoved, conduitCanvasItem):
         for item in self._get_child_dataprovider_canvas_items():
@@ -304,30 +389,6 @@
         self._remove_overlap()
         self._show_welcome_message()
 
-    def _remove_overlap(self):
-        """
-        Moves the ConduitCanvasItems to stop them overlapping visually
-        """
-        items = self._get_child_conduit_canvas_items()
-        if len(items) > 0:
-            #special case where the top one was deleted
-            top = items[0].get_top()-(LINE_WIDTH/2)
-            if top != 0.0:
-                for item in items:
-                    #translate all those below
-                    item.translate(0,-top)
-            else:
-                for i in xrange(0, len(items)):
-                    try:
-                        overlap = items[i].get_bottom() - items[i+1].get_top()
-                        if overlap != 0.0:
-                            #translate all those below
-                            for item in items[i+1:]:
-                                item.translate(0,overlap)
-                    except IndexError: 
-                        break
-
-
     def get_sync_set(self):
         return self.model
 
@@ -345,44 +406,6 @@
         context.drag_status(gtk.gdk.ACTION_COPY, time)
         return True
 
-    def _setup_popup_menus(self, dataproviderPopupXML, conduitPopupXML):
-        """
-        Sets up the popup menus and their callbacks
-
-        @param conduitPopupXML: The menu which is popped up when the user right
-        clicks on a conduit
-        @type conduitPopupXML: C{gtk.glade.XML}
-        @param dataproviderPopupXML: The menu which is popped up when the user right
-        clicks on a dataprovider
-        @type dataproviderPopupXML: C{gtk.glade.XML}
-        """
-
-        self.dataproviderMenu = dataproviderPopupXML.get_widget("DataProviderMenu")
-        self.configureMenuItem = dataproviderPopupXML.get_widget("configure")
-
-        self.conduitMenu = conduitPopupXML.get_widget("ConduitMenu")
-        self.twoWayMenuItem = conduitPopupXML.get_widget("two_way_sync")
-        self.slowSyncMenuItem = conduitPopupXML.get_widget("slow_sync")
-        self.autoSyncMenuItem = conduitPopupXML.get_widget("auto_sync")
-
-        self.twoWayMenuItem.connect("toggled", self.on_two_way_sync_toggle)
-        self.slowSyncMenuItem.connect("toggled", self.on_slow_sync_toggle)
-        self.autoSyncMenuItem.connect("toggled", self.on_auto_sync_toggle)
-
-        #connect the conflict popups
-        self.policyWidgets = {}
-        for policyName in Conduit.CONFLICT_POLICY_NAMES:
-            for policyValue in Conduit.CONFLICT_POLICY_VALUES:
-                widgetName = "%s_%s" % (policyName,policyValue)
-                #store the widget and connect to toggled signal
-                widget = conduitPopupXML.get_widget(widgetName)
-                widget.connect("toggled", self.on_policy_toggle, policyName, policyValue)
-                self.policyWidgets[widgetName] = widget
-                
-        #connect the menu callbacks
-        conduitPopupXML.signal_autoconnect(self)
-        dataproviderPopupXML.signal_autoconnect(self)        
-
     def on_delete_conduit_clicked(self, widget):
         """
         Delete a conduit and all its associated dataproviders

Modified: trunk/conduit/gtkui/UI.py
==============================================================================
--- trunk/conduit/gtkui/UI.py	(original)
+++ trunk/conduit/gtkui/UI.py	Tue Jul 29 22:59:27 2008
@@ -446,9 +446,17 @@
         #FIXME: DnD should be cancelled in the Treeview on the drag-begin 
         #signal and NOT here
         if dataproviderKey != "":
+            #adjust for scrolled window offset
+            scroll = self.canvasSW.get_vadjustment().get_value()
+
             #Add a new instance if the dataprovider to the canvas.
             new = conduit.GLOBALS.moduleManager.get_module_wrapper_with_instance(dataproviderKey)
-            self.canvas.add_dataprovider_to_canvas(dataproviderKey, new, x, y)
+            self.canvas.add_dataprovider_to_canvas(
+                                dataproviderKey,
+                                new,
+                                x,
+                                int(scroll) + y
+                                )
         
         context.finish(True, True, etime)
         return



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