conduit r1620 - in trunk: . conduit/gtkui conduit/hildonui



Author: jstowers
Date: Sat Aug  2 07:31:33 2008
New Revision: 1620
URL: http://svn.gnome.org/viewvc/conduit?rev=1620&view=rev

Log:
	* conduit/gtkui/Canvas.py:
	* conduit/hildonui/Canvas.py: Refactor the welcome message handling to
	allow the welcome message to look like an empty conduit.


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

Modified: trunk/conduit/gtkui/Canvas.py
==============================================================================
--- trunk/conduit/gtkui/Canvas.py	(original)
+++ trunk/conduit/gtkui/Canvas.py	Sat Aug  2 07:31:33 2008
@@ -25,24 +25,6 @@
 
 class _StyleMixin:
 
-    STYLES = (
-        "fg",
-        "bg",
-        "light",
-        "dark",
-        "mid",
-        "text",
-        "base",
-        "text_aa"
-        )
-    STYLE_STATES = (
-        "normal",
-        "active",
-        "prelight",
-        "selected",
-        "insensitive"
-        )
-        
     def _get_colors_and_state(self, styleName, stateName):
         style = self.get_gtk_style()
         if style:
@@ -212,8 +194,23 @@
         
         #Show a friendly welcome message on the canvas the first time the
         #application is launched
-        self.welcomeMessage = None
-        self._show_welcome_message()
+        self.welcome = None
+        self._maybe_show_welcome()
+        
+    def _show_hint(self, conduitCanvasItem, dataproviderCanvasItem, newItem):
+        if not self.msg:
+            return
+            
+        if newItem == conduitCanvasItem:
+            self.msg.new_from_text_and_icon(
+                            gtk.STOCK_INFO,
+                            "Conduit Created",
+                            timeout=4).show_all()
+        elif newItem == dataproviderCanvasItem:
+            self.msg.new_from_text_and_icon(
+                            gtk.STOCK_INFO,
+                            "Dataprovider Created",
+                            timeout=4).show_all()
         
     def _update_for_theme(self, *args):
         if not self.get_gtk_style() or self._changing_style:
@@ -224,8 +221,8 @@
                 "background_color_rgb",
                 self.get_style_color_int_rgb("bg","normal")
                 )
-        if self.welcomeMessage:
-            self.welcomeMessage.set_property(
+        if self.welcome:
+            self.welcome.set_property(
                 "fill_color_rgba",
                 self.get_style_color_int_rgba("text","normal")
                 )
@@ -269,41 +266,44 @@
         conduitPopupXML.signal_autoconnect(self)
         dataproviderPopupXML.signal_autoconnect(self)
 
-    def _show_welcome_message(self):
-        """
-        Adds a friendly welcome message to the canvas.
+    def _delete_welcome(self):
+        idx = self.root.find_child(self.welcome)
+        if idx != -1:
+            self.root.remove_child(idx)
+        self.welcome = None
         
-        Does so only if there are no conduits, otherwise it would just
-        get in the way.
-        """
-        if self.welcomeMessage == None:
-            c_x,c_y,c_w,c_h = self.get_bounds()
-            self.welcomeMessage = goocanvas.Text(  
-                                    x=c_w/2, 
-                                    y=c_w/3, 
-                                    width=3*c_w/5, 
-                                    text=self.WELCOME_MESSAGE, 
-                                    anchor=gtk.ANCHOR_CENTER,
-                                    alignment=pango.ALIGN_CENTER,
-                                    font="Sans 10",
-                                    fill_color_rgba=self.get_style_color_int_rgba("text","normal"),
-                                    )
+    def _create_welcome(self):
+        c_x,c_y,c_w,c_h = self.get_bounds()
+        self.welcome = ConduitCanvasItem(
+                                parent=self.root, 
+                                model=None,
+                                width=c_w
+                                )
 
-        idx = self.root.find_child(self.welcomeMessage)
+    def _maybe_show_welcome(self):
+        """
+        Adds a friendly welcome to the canvas. Only does so only if 
+        there are no conduits, otherwise it would just get in the way.
+        """
         if self.model == None or (self.model != None and self.model.num_conduits() == 0):
-            if idx == -1:
-                self.root.add_child(self.welcomeMessage,-1)
-        else:
-            if idx != -1:
-                self.root.remove_child(idx)
-                self.welcomeMessage = None
+            if self.welcome == None:
+                self._create_welcome()
+            if self.msg:
+                self.msg.new_from_text_and_icon(
+                                gtk.STOCK_INFO,
+                                self.WELCOME_MESSAGE,
+                                timeout=0).show_all()
+
+        elif self.welcome:
+            self._delete_welcome()
 
     def _get_child_conduit_canvas_items(self):
         items = []
         for i in range(0, self.root.get_n_children()):
             condItem = self.root.get_child(i)
             if isinstance(condItem, ConduitCanvasItem):
-                items.append(condItem)
+                if condItem != self.welcome:
+                    items.append(condItem)
         return items
 
     def _get_child_dataprovider_canvas_items(self):
@@ -443,7 +443,7 @@
                     log.warn("Error finding item")
         self._remove_overlap()
 
-        self._show_welcome_message()
+        self._maybe_show_welcome()
         c_x,c_y,c_w,c_h = self.get_bounds()
         self.set_bounds(
                     0,
@@ -479,19 +479,15 @@
         conduitAdded.connect("dataprovider-added", self.on_dataprovider_added, conduitCanvasItem)
         conduitAdded.connect("dataprovider-removed", self.on_dataprovider_removed, conduitCanvasItem)
 
-        self._show_welcome_message()
+        self._maybe_show_welcome()
         self.set_bounds(
                     0,
                     0,
                     c_w,
                     self._get_minimum_canvas_size()
                     )
-                    
-        self.msg.new_from_text_and_icon(
-                        gtk.STOCK_INFO,
-                        "Conduit Created",
-                        "Add another dataprovider to synchronize",
-                        timeout=4).show_all()
+
+        self._show_hint(conduitCanvasItem, None, conduitCanvasItem)
 
     def on_dataprovider_removed(self, sender, dataproviderRemoved, conduitCanvasItem):
         for item in self._get_child_dataprovider_canvas_items():
@@ -516,6 +512,8 @@
         item.connect('button-press-event', self._on_dataprovider_button_press)
         conduitCanvasItem.add_dataprovider_canvas_item(item)
         self._remove_overlap()
+        
+        self._show_hint(conduitCanvasItem, item, item)
 
     def get_sync_set(self):
         return self.model
@@ -623,6 +621,7 @@
         @type y: C{int}
         @returns: The conduit that the dataprovider was added to
         """
+        parent = None
         existing = self.get_item_at(x,y,False)
         c_x,c_y,c_w,c_h = self.get_bounds()
 
@@ -631,19 +630,29 @@
             trySourceFirst = True
         else:
             trySourceFirst = False
-
-        if existing == None:
-            cond = Conduit.Conduit(self.sync_manager)
-            cond.add_dataprovider(dataproviderWrapper, trySourceFirst)
-            self.model.add_conduit(cond)
-
-        else:
+            
+        #recurse up the canvas objects to determine if we have been dropped
+        #inside an existing conduit
+        if existing:
             parent = existing.get_parent()
-            while parent != None and not isinstance(parent, ConduitCanvasItem):
+            while parent != None and not parent == self.welcome and not isinstance(parent, ConduitCanvasItem):
                 parent = parent.get_parent()
+
+        #if we were dropped on the welcome message we first remove that
+        if parent and parent == self.welcome:
+            self._delete_welcome()
+            #ensure a new conduit is created
+            parent = None
+
+        if parent != None:
+            #we were dropped on an existing conduit            
+            parent.model.add_dataprovider(dataproviderWrapper, trySourceFirst)
+            return
             
-            if parent != None:
-                parent.model.add_dataprovider(dataproviderWrapper, trySourceFirst)
+        #create a new conduit
+        cond = Conduit.Conduit(self.sync_manager)
+        cond.add_dataprovider(dataproviderWrapper, trySourceFirst)
+        self.model.add_conduit(cond)
 
     def clear_canvas(self):
         self.model.clear()
@@ -810,16 +819,17 @@
 
     DIVIDER = False
     FLAT_BOX = True
-    WIDGET_HEIGHT = 100
+    WIDGET_HEIGHT = 73.0
     SIDE_PADDING = 10.0
     LINE_WIDTH = 2.0
 
     def __init__(self, parent, model, width):
         _CanvasItem.__init__(self, parent, model)
 
-        self.model.connect("parameters-changed", self._on_conduit_parameters_changed)
-        self.model.connect("dataprovider-changed", self._on_conduit_dataprovider_changed)
-        self.model.connect("sync-progress", self._on_conduit_progress)
+        if self.model:
+            self.model.connect("parameters-changed", self._on_conduit_parameters_changed)
+            self.model.connect("dataprovider-changed", self._on_conduit_dataprovider_changed)
+            self.model.connect("sync-progress", self._on_conduit_progress)
 
         self.sourceItem = None
         self.sinkDpItems = []

Modified: trunk/conduit/hildonui/Canvas.py
==============================================================================
--- trunk/conduit/hildonui/Canvas.py	(original)
+++ trunk/conduit/hildonui/Canvas.py	Sat Aug  2 07:31:33 2008
@@ -34,8 +34,9 @@
         #setup the canvas
         conduit.gtkui.Canvas.Canvas.__init__(self,
                                 parentWindow,typeConverter,syncManager,
-                                #menus are set in _setup_popup_menus
-                                None,None)
+                                None,None,  #menus are set in _setup_popup_menus
+                                None        #no message hints in hildon
+                                )
         self.position = -1
         
     def _update_for_theme(self, *args):
@@ -47,6 +48,20 @@
         # conduit context menu
         self.conduitMenu = ConduitMenu(self)
         
+    def _create_welcome(self):
+        c_x,c_y,c_w,c_h = self.get_bounds()
+        self.welcome = goocanvas.Text(  
+                            x=c_w/2, 
+                            y=c_w/3, 
+                            width=3*c_w/5, 
+                            text=self.WELCOME_MESSAGE, 
+                            anchor=gtk.ANCHOR_CENTER,
+                            alignment=pango.ALIGN_CENTER,
+                            font="Sans 10",
+                            fill_color="black",
+                            )
+        self.root.add_child(self.welcome,-1)
+        
     def _on_conduit_button_press(self, view, target, event):        
         log.debug("Clicked View: %s" % view.model)
 



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