commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r8339 - in trunk/gnue-designer/src: forms/PagePainter ui/wx/uihel


From: jcater
Subject: [gnue] r8339 - in trunk/gnue-designer/src: forms/PagePainter ui/wx/uihelpers/doccanvas
Date: Mon, 3 Apr 2006 18:25:07 -0500 (CDT)

Author: jcater
Date: 2006-04-03 00:40:54 -0500 (Mon, 03 Apr 2006)
New Revision: 8339

Modified:
   trunk/gnue-designer/src/forms/PagePainter/PagePainter.py
   trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/canvas.py
   trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/colors.py
   trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/widget.py
Log:
cleaned up several display issues and mouse tracking issues

Modified: trunk/gnue-designer/src/forms/PagePainter/PagePainter.py
===================================================================
--- trunk/gnue-designer/src/forms/PagePainter/PagePainter.py    2006-04-02 
16:53:01 UTC (rev 8338)
+++ trunk/gnue-designer/src/forms/PagePainter/PagePainter.py    2006-04-03 
05:40:54 UTC (rev 8339)
@@ -18,7 +18,7 @@
 # write to the Free Software Foundation, Inc., 59 Temple Place
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
-# $Id: TriggerEditor.py 8210 2006-03-07 00:04:31Z jcater $
+# $Id$
 
 __all__ = ['PagePainter']
 
@@ -39,8 +39,8 @@
 import wx
 
 
-xscale = 1
-yscale = 1
+xscale = 0
+yscale = 0
 
 
 # ===========================================================================
@@ -48,85 +48,87 @@
 # ===========================================================================
 class PagePainter (EditorBase):
 
-  runtime_section = "FormsPagePainter"
-  icon = 'painter'
+    runtime_section = "FormsPagePainter"
+    icon = 'painter'
 
-  def init(self, object):
+    def init(self, object):
 
-    canvas = self.canvas = PagePainterCanvas(self)
-    self.document.app.ui.autoSizer(self, canvas)
+        canvas = self.canvas = PagePainterCanvas(self)
+        self.document.app.ui.autoSizer(self, canvas)
 
-    self.object = object
+        self.object = object
 
-    self.setCaption(hasattr(object,'caption') and object.caption \
-          or object.name)
+        self.setCaption(hasattr(object,'caption') and object.caption \
+            or object.name)
 
-    self.registerEventListeners({
-                       # Object stuff
-                       'ObjectSelected'      : self.__objectSelected,
-                       'ObjectCreated'       : self.__objectCreated,
-                       'ObjectModified'      : self.__objectModified,
-                       'ObjectDeleted'       : self.__objectDeleted,
-                      })
+        self.registerEventListeners({
+                        # Object stuff
+                        'ObjectSelected'      : self.__objectSelected,
+                        'ObjectCreated'       : self.__objectCreated,
+                        'ObjectModified'      : self.__objectModified,
+                        'ObjectDeleted'       : self.__objectDeleted,
+                        })
 
-    # Determine text extents
-    dc = wx.PaintDC(self)
-    dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT))
-    global xscale, yscale
+        # Determine text extents
+        dc = wx.PaintDC(self)
+        dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT))
+        global xscale, yscale
 
-    for char in string.digits + string.letters:
-      w, h = dc.GetTextExtent(char)
-      xscale = max(xscale, w)
-      yscale = max(yscale, h)
+        if not xscale:
+            for char in string.digits + string.letters:
+                w, h = dc.GetTextExtent(char)
+                xscale = max(xscale, w)
+                yscale = max(yscale, h)
 
-    # Make the scale slightly larger, so that input widgets
-    # are bigger than text labels.
-    #xscale += 4
-    yscale += 4
-    canvas.set_grid_scale(xscale, yscale)
+            # Make the scale slightly larger, so that input widgets
+            # are bigger than text labels.
+            #xscale += 4
+            yscale += 2
 
-    # Draw initial objects
-    self.object.walk(self.inventoryObject)
+        canvas.set_grid_scale(xscale, yscale)
 
+        # Draw initial objects
+        self.object.walk(self.inventoryObject)
 
-  def inventoryObject(self, object):
 
-    # Right now, we assume if an object has an x,y component, it is drawable.
-    # This won't be true when we support layout management.
-    try:
-      x = object['Char:x']
-      y = object['Char:y']
-    except:
-      print "Not inventorying %s" % object
-      return
+    def inventoryObject(self, object):
 
-    canvas = self.canvas
+        # Right now, we assume if an object has an x,y component, it is 
drawable.
+        # This won't be true when we support layout management.
+        try:
+            x = object['Char:x']
+            y = object['Char:y']
+        except:
+            print "Not inventorying %s" % object
+            return
 
-    cls = getWidgetSkinClass(object)
+        canvas = self.canvas
 
-    widget = cls(object, canvas)
-    canvas.add(widget)
+        cls = getWidgetSkinClass(object)
 
-    # Debugging...
-    widget.set_selected(True)
+        widget = cls(object, canvas)
+        canvas.add(widget)
 
-    print "Added %s" % object._type
+        # Debugging...
+        widget.set_selected(True)
 
+        print "Added %s" % object._type
 
-  def __objectSelected(self, object):
-    pass
 
-  def __objectCreated(self, object):
-    print "(Object Created)"
+    def __objectSelected(self, object):
+        pass
 
-  def __objectModified(self, object):
-    pass
+    def __objectCreated(self, object):
+        print "(Object Created)"
 
-  def __objectDeleted(self, object):
-    pass
+    def __objectModified(self, object):
+        pass
 
+    def __objectDeleted(self, object):
+        pass
 
 
+
 # ===========================================================================
 # SimpleCanvas implementations
 # ===========================================================================
@@ -149,6 +151,8 @@
         cls = LabelWidget
     elif object._type == 'GFEntry':
            cls = EntryWidget
+    elif object._type == 'GFBox':
+        cls = BoxWidget
     else:
         cls = UnknownWidget
 
@@ -203,33 +207,35 @@
         # Convert from Char positions into wx positions
         x *= xscale
         y *= yscale
-        h *= xscale
         w *= xscale
+        h *= yscale
 
         # Used to figure in compensation needed for selection box
         # decorations and borders
         compensation = self.border_compensation
 
-        # Save the bounds, relative to the canvas, of the area
+        # Save the area, relative to the canvas, of the area
         # that needs to be refreshed when this widget changes.
         # (Includes all generic decoration, like selection borders)
-        self.refresh_bounds = wx.Rect(x + documentX  - compensation,
+        self.refresh_area = wx.Rect(x + documentX  - compensation,
                                       y + documentY - compensation,
                                       w + compensation * 2,
                                       h  + compensation * 2)
 
-        # Save the bounds, relative to the canvas, of the area
+        # Save the area, relative to the canvas, of the area
         # that the widget sans decorations occupy on the
-        self.hit_test_bounds = wx.Rect(x  + documentX,
+        self.hit_test_area = wx.Rect(x  + documentX,
                                        y + documentY,
                                        w, h)
 
-        # Save the bounds, relative to being drawn in a context at (0,0)
-        self.draw_bounds = wx.Rect(compensation, compensation, w, h)
+        # Save the area, relative to being drawn in a context at (0,0)
+        self.draw_area = wx.Rect(compensation, compensation, w, h)
 
 
+    def draw_decorations(self, dc):
+        # TODO: eventually, this will show tab-order icons
+        pass
 
-  #def move(self, x, y):
 
 
 class LabelWidget(FormWidget):
@@ -238,28 +244,41 @@
 
     def draw_widget(self, dc):
         dc.SetPen(wx.Pen(colorIndex['text']))
+        dc.SetBrush(wx.Brush(wx.WHITE, style=wx.TRANSPARENT))
         object = self.gobject
-        x, y, w, h = self.draw_bounds.Get()
+        x, y, w, h = self.draw_area.Get()
         dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT))
         # Center each character in its cell
         for char in object.text:
             cw, ch = dc.GetTextExtent(char)
-            dc.DrawText(char, x + int((xscale - cw)/2), y)
+            dc.DrawText(char, x + (xscale - cw) // 2, y + 1)
             x += xscale
 
 
 class EntryWidget(FormWidget):
     def draw_widget(self, dc):
         dc.SetPen(wx.Pen(colorIndex['widget']))
-        x,y,w,h = self.draw_bounds.Get()
+        dc.SetBrush(wx.Brush(colorIndex['widgetback']))
+        x,y,w,h = self.draw_area.Get()
         dc.DrawRoundedRectangle(x,y,w,h, 1)
 
 
+class BoxWidget(FormWidget):
+    def draw_widget(self, dc):
+        dc.SetPen(wx.Pen(colorIndex['text']))
+        dc.SetBrush(wx.Brush(wx.WHITE, style=wx.TRANSPARENT))
+        object = self.gobject
+        x,y,w,h = self.draw_area.Get()
+        dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT))
+        dc.DrawRoundedRectangle(x, y + yscale // 2 + 1, w,h - yscale, 
xscale//3)
+
+
 class UnknownWidget(FormWidget):
     def draw_widget(self, dc):
         dc.SetPen(wx.Pen(colorIndex['widget']))
+        dc.SetBrush(wx.Brush(colorIndex['widget'], style=wx.CROSSDIAG_HATCH))
         object = self.gobject
-        x,y,w,h = self.draw_bounds.Get()
+        x,y,w,h = self.draw_area.Get()
         dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT))
         dc.DrawRoundedRectangle(x,y,w,h, 4)
 
@@ -273,7 +292,7 @@
         DocumentCanvas.__init__(self, *args, **parms)
 
         self.document_origin_x = xscale * 2
-        self.document_origin_y = xscale * 2
+        self.document_origin_y = yscale * 2
 
 
 

Modified: trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/canvas.py
===================================================================
--- trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/canvas.py 2006-04-02 
16:53:01 UTC (rev 8338)
+++ trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/canvas.py 2006-04-03 
05:40:54 UTC (rev 8339)
@@ -18,7 +18,7 @@
 # write to the Free Software Foundation, Inc., 59 Temple Place
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
-# $Id: TriggerEditor.py 8210 2006-03-07 00:04:31Z jcater $
+# $Id$
 
 
 import time
@@ -59,15 +59,18 @@
         self.Bind(wx.EVT_ERASE_BACKGROUND, self.__wx_on_erase_background)
         self.Bind(wx.EVT_MOUSE_EVENTS, self.__wx_on_mouse_event)
 
+        # Screen refreshing
+        self.__selection_area = None
+        self.__refresh_batch = 0
 
         # Mouse events
         self.__mouse_hot_spots = []
         self.__current_cursor = None
-        self.__mouse_mode = 'select'
+        self.__mouse_mode = 'normal'
         self.__mouse_click_function = None
         self.__mouse_current_action = ""
         self.__mouse_move_buffer = None
-        self.__mouse_move_bounds = None
+        self.__mouse_move_area = None
         self.__hide_selection_frame = False
 
 
@@ -76,11 +79,11 @@
             item.Destroy()
         self.ordered_widget_list = None
 
-    def set_mouse_mode(self, mode='select', function=None):
+    def set_mouse_mode(self, mode='normal', function=None):
         """
         mode       String that is one of:
 
-          select:  The default mouse behavior, in which existing objects
+          normal:  The default mouse behavior, in which existing objects
                    can be selected, resized, moved, etc.
 
           edit:    Clicking any object "edits" that object. (Mainly,
@@ -94,6 +97,8 @@
           delete:  Clicking an object "deletes" the object.  This mode
                    doesn't do anything ... your method should handle it.
 
+          picker:  Objects can only be "selected"... no operations permitted.
+                   (Useful for setting tab order, etc.)
 
         method     A python method to call once the target action happens.
 
@@ -109,11 +114,90 @@
       self.grid_x_spacing = x
       self.grid_y_spacing = y
 
-    def refresh_scrolled_rect(self, rect):
-        position = rect.GetPosition()
+
+    def refresh_selection(self):
+        """
+        call this method when the selection list has changed
+        so we can recalculate the selection area
+        """
+
+        # Erase the old selection box
+        if self.__selection_area:
+            self.refresh_scrolled_area(self.__selection_area)
+
+        self.__mouse_hot_spots = []
+
+        # The updateRegion is not in scrolled coordinates.
+        scrollWindowOriginX, scrollWindowOriginY = 
self.CalcUnscrolledPosition(0, 0)
+
+        selection_area = None
+
+        for widget in self.ordered_widget_list:
+            if not widget.selected:
+                continue
+
+            refresh_area = widget.refresh_area
+
+            (objectX, objectY,
+            objectWidth, objectHeight) = refresh_area.Get()
+
+            # Calculate the area, offset by the scrollwindow's origin
+            area = wx.Rect(objectX - scrollWindowOriginX,
+                            objectY - scrollWindowOriginY,
+                            objectWidth, objectHeight)
+
+
+            # Keep track of the overall area of all the selected
+            # widgets, so we can draw a selection box later
+            if selection_area is None:
+                selection_area = area
+            else:
+                selection_area = selection_area.Union(area)
+
+
+        # Draw a box around all the selected widgets
+        if selection_area:
+
+            x, y, w, h = selection_area.Get()
+
+            # Not sure why we have to do this, but it makes the
+            # box draw correctly.
+            x += 2
+            y += 2
+            w -= 4
+            h -= 4
+
+            selection_area = wx.Rect(x,y,w,h)
+            self.refresh_scrolled_area(selection_area)
+
+        self.__selection_area = selection_area
+
+
+    def begin_refresh_batch(self):
+        self.__refresh_batch += 1
+        self.__refresh_batch_area = wx.Rect()
+
+    def end_refresh_batch(self):
+        self.__refresh_batch -= 1
+        if self.__refresh_batch <= 0:
+            self.__refresh_batch = 0
+            self.refresh_scrolled_area(self.__refresh_batch_area)
+
+    def refresh_scrolled_area(self, area):
+        """
+        Signal to wx that an area needs refreshing on screen
+        """
+
+        # Are we batching updates? if so, queue it.
+        if self.__refresh_batch:
+            self.__refresh_batch_area = self.__refresh_batch_area.Union(area)
+            return
+
+        position = area.GetPosition()
         x, y = self.CalcScrolledPosition(position.x, position.y)
-        self.RefreshRect(wx.Rect(x, y, rect.GetWidth(), rect.GetHeight()));
+        self.RefreshRect(wx.Rect(x, y, area.GetWidth(), area.GetHeight()));
 
+
     def __wx_on_paint(self, event):
         """
         Catch the wx OnPaint event and draw the canvas and any widgets
@@ -165,8 +249,8 @@
                       memoryDC, bufferX, bufferY)
 
         # Draw the mouse move buffer, if applicable
-        if self.__mouse_move_bounds:
-            x,y,w,h = self.__mouse_move_bounds.Get()
+        if self.__mouse_move_area:
+            x,y,w,h = self.__mouse_move_area.Get()
             paintDC.Blit(x, y, w, h, self.__mouse_move_buffer, 0, 0,
                          wx.AND, True, 0, 0)
 
@@ -185,61 +269,32 @@
 
       dcOriginX, dcOriginY = dc.GetDeviceOrigin()
 
-      selection_bounds = None
+      for widget in self.ordered_widget_list:
+        refresh_area = widget.refresh_area
 
-      index = len(self.ordered_widget_list) - 1
-
-      while index >= 0:
-        widget = self.ordered_widget_list [index]
-        refresh_bounds = widget.refresh_bounds
-
         (objectX, objectY,
-         objectWidth, objectHeight) = refresh_bounds.Get()
+         objectWidth, objectHeight) = refresh_area.Get()
 
-        # Calculate the bounds, offset by the scrollwindow's origin
-        bounds = wx.Rect(objectX - scrollWindowOriginX,
+        # Calculate the area, offset by the scrollwindow's origin
+        area = wx.Rect(objectX - scrollWindowOriginX,
                          objectY - scrollWindowOriginY,
                          objectWidth, objectHeight)
 
 
-        # Keep track of the overall bounds of all the selected
-        # widgets, so we can draw a selection box later
-        if widget.selected:
-            if selection_bounds is None:
-                selection_bounds = bounds
-            else:
-                selection_bounds = selection_bounds.Union(bounds)
-
-        if (updateRegion.ContainsRect(bounds) != wx.OutRegion and
+        if (updateRegion.ContainsRect(area) != wx.OutRegion and
             widget.visible):
 
             dc.SetDeviceOrigin(objectX + dcOriginX, objectY + dcOriginY)
             widget.draw(dc)
             dc.SetDeviceOrigin(dcOriginX, dcOriginY)
 
-        index -= 1
 
-      # TODO: Somehow move most of this logic out of draw...
-
       # Draw a box around all the selected widgets
-      if selection_bounds is not None and not self.__hide_selection_frame:
+      if self.__selection_area is not None and not self.__hide_selection_frame:
+          x, y, w, h = self.__selection_area.Get()
+          self.__draw_selection_box(dc, x, y, w, h)
 
-          x, y, w, h = selection_bounds.Get()
 
-          # Not sure why we have to do this, but it makes the
-          # box draw correctly.
-          x += 2
-          y += 2
-          w -= 4
-          h -= 4
-
-          selection_bounds = self.__selection_bounds = wx.Rect(x,y,w,h)
-          self.__draw_selection_box(dc, x,y,w,h)
-
-      else:
-          self.__selection_bounds = None
-
-
     def __draw_selection_box(self, dc, x, y, w, h, xor=False):
 
         self.__mouse_hot_spots = []
@@ -376,7 +431,7 @@
         current_action = self.__mouse_current_action
 
         if event.Dragging():
-            if mode == 'select':
+            if mode == 'normal':
                 if current_action == 'rubberband':
                     self.__update_rubberband(x,y)
 
@@ -389,7 +444,7 @@
 
         elif event.Moving():
             cursor = None
-            if  mode == 'select':
+            if  mode == 'normal':
                 if not current_action:
                     # No previous action. Should we change the cursor?
                     for rect, position in self.__mouse_hot_spots:
@@ -407,7 +462,7 @@
 
         elif event.LeftDown():
 
-            if mode == 'select':
+            if mode == 'normal':
 
                 if not current_action:
                     # No previous action.
@@ -422,10 +477,10 @@
 
                     # Check to see if any widgets were clicked
                     if not new_action:
-                        for widget in self.ordered_widget_list:
-                            if widget.select_hit_test(x,y):
-                                new_action = 'move'
-                                break
+                        selected = self.select_hit_test(x, y)
+                        if selected:
+                            self.selected_from_canvas([selected])
+                            new_action = 'move'
 
                     # Finally, assume we're creating a rubberband selector
                     if not new_action:
@@ -433,7 +488,7 @@
                         self.__start_rubberband(x, y)
 
                     elif new_action == 'move':
-                        self.__start_moving(x,y)
+                        self.__start_moving(x, y)
 
                     elif new_action.startswith('resize-'):
                         self.__start_resizing(x, y,
@@ -448,10 +503,18 @@
 
         elif event.LeftUp():
 
-            if mode == 'select':
+            if mode == 'normal':
 
                 if current_action == 'rubberband':
-                    self.__stop_rubberband()
+                    area = self.__stop_rubberband(x, y)
+                    # if their wasn't any drag action, treat it as
+                    # a single click. Otherwise, as a drag.
+                    if area.height > 2 or area.width > 2:
+                        widgets = self.drag_hit_test(area)
+                    else:
+                        widget = self.select_hit_test(area.x, area.y)
+                        widgets = widget and [widget] or []
+                    self.selected_from_canvas(widgets)
 
                 elif current_action == 'move':
                     self.__stop_moving()
@@ -463,12 +526,50 @@
 
                 return True
 
+            elif mode == 'picker':
+                widget = self.select_hit_test(x,y)
+                if widget:
+                    widget.pick_from_canvas()
 
+            elif mode == 'edit':
+                widget = self.select_hit_test(x,y)
+                if widget:
+                    self.widget_picked(widget)
+
+            elif mode == 'create':
+                pass
+
+            elif mode == 'delete':
+                pass
+
         return False
 
 
 
+    # ---------------------------------------------------------------
+    #
+    # ---------------------------------------------------------------
+    def select_hit_test(self, x, y):
+        """
+        Return the first widget at a point
+        """
+        for widget in self.ordered_widget_list:
+            if widget.select_hit_test(x,y):
+                return widget
+        return None
 
+
+    def drag_hit_test(self, area):
+        """
+        Return a list of all widgets in a rectangle
+        """
+        widgets = []
+        append = widgets.append
+        for widget in self.ordered_widget_list:
+            if widget.drag_hit_test(area):
+                append(widget)
+        return widgets
+
     # ---------------------------------------------------------------
     # Get all selected widgets
     # ---------------------------------------------------------------
@@ -495,81 +596,102 @@
         this to the main display context as the mouse moves.
         """
 
+        self.begin_refresh_batch()
+
+        # Hide selection frame (we draw our own)
+        self.__hide_selection_frame = True
+        self.refresh_scrolled_area(self.__selection_area)
+
         self.CaptureMouse()
+
         self.__mouse_move_items = widgets = self.get_selected_widgets()
-        bounds = wx.Rect()
+
+        area = wx.Rect()
         for widget in widgets:
             widget.selected = False
             widget.visible = False
-            bounds = bounds.Union(widget.refresh_bounds)
+            area = area.Union(widget.refresh_area)
 
 
         # Create a bitmap of our widgets in an offscreen buffer
         # so we can redraw them as the mouse moves
 
-        bufferX = bounds.GetLeft()
-        bufferY = bounds.GetTop()
-        bufferWidth = bounds.GetWidth()
-        bufferHeight = bounds.GetHeight()
+        bufferX = area.GetLeft()
+        bufferY = area.GetTop()
+        bufferWidth = area.GetWidth()
+        bufferHeight = area.GetHeight()
 
         memoryDC = wx.MemoryDC()
         offscreenBuffer = wx.EmptyBitmap(bufferWidth, bufferHeight)
         maskColor = wx.WHITE
-        offscreenBuffer.SetMaskColour(maskColor)
 
         memoryDC.SelectObject(offscreenBuffer)
         memoryDC.SetDeviceOrigin(-bufferX, -bufferY)
 
         memoryDC.SetBackground(wx.Brush(maskColor))
-        memoryDC.SetBackgroundMode(wx.TRANSPARENT)
         memoryDC.Clear()
 
         for widget in widgets:
             (objectX, objectY,
-             objectWidth, objectHeight) = widget.refresh_bounds.Get()
+             objectWidth, objectHeight) = widget.refresh_area.Get()
 
             memoryDC.SetDeviceOrigin(objectX - bufferX, objectY - bufferY)
             widget.draw_widget(memoryDC)
             memoryDC.SetDeviceOrigin(0,0)
 
+        # Draw a selection box
+        sx, sy, sw, sh = self.__selection_area.Get()
+        self.__draw_selection_box(memoryDC, 2, 2, sw, sh)
+
         memoryDC.EndDrawing()
 
         self.__mouse_move_dx = x - bufferX
         self.__mouse_move_dy = y - bufferY
         self.__mouse_move_buffer = memoryDC
-        self.__mouse_move_bounds = bounds
+        self.__mouse_move_area = area
 
         # Hide the real widgets
-        self.refresh_scrolled_rect(bounds)
+        self.refresh_scrolled_area(area)
 
+        self.end_refresh_batch()
 
     def __update_moving(self, x, y):
         """
         Update the "moving" feedback by deleting the old and
         drawing the new.
         """
-        old_bounds = wx.Rect(*self.__mouse_move_bounds.Get())
-        self.__mouse_move_bounds.SetLeft(x - self.__mouse_move_dx)
-        self.__mouse_move_bounds.SetTop(y - self.__mouse_move_dy)
-        self.refresh_scrolled_rect(old_bounds.Union(self.__mouse_move_bounds))
+        old_area = wx.Rect(*self.__mouse_move_area.Get())
+        self.__mouse_move_area.SetLeft(x - self.__mouse_move_dx)
+        self.__mouse_move_area.SetTop(y - self.__mouse_move_dy)
+        self.refresh_scrolled_area(old_area.Union(self.__mouse_move_area))
 
 
     def __stop_moving(self):
         """
         Erase the "moving" feedback
         """
+
+        self.begin_refresh_batch()
+
         self.ReleaseMouse()
-        old_bounds = self.__mouse_move_bounds
+
+        self.__hide_selection_frame = False
+
+        old_area = self.__mouse_move_area
         self.__mouse_move_buffer = None
-        self.__mouse_move_bounds = None
+        self.__mouse_move_area = None
 
         for widget in self.__mouse_move_items:
             widget.selected = True
             widget.show()
 
         self.__mouse_move_items = None
-        self.refresh_scrolled_rect(old_bounds)
+        self.refresh_selection()
+        self.refresh_scrolled_area(old_area)
 
+        self.end_refresh_batch()
+
+
     # ---------------------------------------------------------------
     # Support for visual resizing hints
     # ---------------------------------------------------------------
@@ -577,16 +699,24 @@
         """
         Start the resizing feedback (a XOR'd rubberband box)
         """
+        self.begin_refresh_batch()
+
         self.__mouse_resize_orientation = orientation
         self.CaptureMouse()
+
+        # Hide the selection frame (We'll draw our own, XOR'ed out)
         self.__hide_selection_frame = True
-        self.refresh_scrolled_rect(self.__selection_bounds)
-        self.__mouse_resize_orig_bounds = self.__selection_bounds
-        self.__mouse_resize_last_bounds = None
+        self.refresh_scrolled_area(self.__selection_area)
+
+        # Set some initial variables
+        self.__mouse_resize_orig_area = self.__selection_area
+        self.__mouse_resize_last_area = None
         self.__mouse_resize_start_x = x
         self.__mouse_resize_start_y = y
         ##self.__update_resizing(x,y)
 
+        self.end_refresh_batch()
+
     def __update_resizing(self, x, y):
         """
         Update the resizing feedback by deleting the old feedback
@@ -597,9 +727,9 @@
         dc.BeginDrawing()
 
         # If there's an existing frame, remove it first.
-        if self.__mouse_resize_last_bounds:
+        if self.__mouse_resize_last_area:
             self.__draw_selection_box(dc,
-                       *self.__mouse_resize_last_bounds + [True])
+                       *self.__mouse_resize_last_area + [True])
 
         # If x is None, then we're only erasing the old,
         # not drawing a new frame.
@@ -607,7 +737,7 @@
             dx = x - self.__mouse_resize_start_x
             dy = y - self.__mouse_resize_start_y
 
-            ox, oy, ow, oh = self.__mouse_resize_orig_bounds.Get()
+            ox, oy, ow, oh = self.__mouse_resize_orig_area.Get()
 
             ox2 = ox + ow - 1
             oy2 = oy + oh - 1
@@ -638,7 +768,7 @@
             ow = ox2 - ox
             oh = oy2 - oy
 
-            self.__mouse_resize_last_bounds = last = [ox, oy, ow, oh]
+            self.__mouse_resize_last_area = last = [ox, oy, ow, oh]
             self.__draw_selection_box(dc, *last + [True])
 
         dc.EndDrawing()
@@ -651,7 +781,7 @@
         self.ReleaseMouse()
         self.__update_resizing(None, None)
         self.__hide_selection_frame = False
-        self.refresh_scrolled_rect(self.__mouse_resize_orig_bounds)
+        self.refresh_scrolled_area(self.__mouse_resize_orig_area)
 
 
     # ---------------------------------------------------------------
@@ -694,13 +824,15 @@
         dc.EndDrawing()
 
 
-    def __stop_rubberband(self):
+    def __stop_rubberband(self, x, y):
         """
-        Reset the cursor
+        Stops the rubberband box, returning a wx.Rect indicating
+        the area selected.
         """
         self.SetCursor(self.__mouse_rubberband_orig_cursor)
         self.__update_rubberband(None)
         self.ReleaseMouse()
+        return wx.RectPP(self.__mouse_rubberband_start, (x, y))
 
 
     # ---------------------------------------------------------------
@@ -715,8 +847,8 @@
               assert(self.ordered_widget_list.count(self.internalDnDItem) == 1)
 
               widget = self.ConvertDataObjectToDrawableObject(dataObject, x, 
y, True)
-              x = widget.refresh_bounds.GetLeft()
-              y = widget.refresh_bounds.GetTop()
+              x = widget.refresh_area.GetLeft()
+              y = widget.refresh_area.GetTop()
 
               self.ordered_widget_list.remove(self.internalDnDItem)
               self.ordered_widget_list.insert(0, self.internalDnDItem)
@@ -725,8 +857,8 @@
           else:
 
               widget = self.ConvertDataObjectToDrawableObject(dataObject, x, 
y, False)
-              x = widget.refresh_bounds.GetLeft()
-              y = widget.refresh_bounds.GetTop()
+              x = widget.refresh_area.GetLeft()
+              y = widget.refresh_area.GetTop()
 
               self.ordered_widget_list.insert(0, widget)
               widget.force_canvas_refresh()
@@ -734,7 +866,7 @@
 
 
     # ---------------------------------------------------------------
-    #
+    # Misc management stuff
     # ---------------------------------------------------------------
 
     def deselect_all(self):
@@ -760,9 +892,30 @@
         Remove a DocumentWidget from the canvas
         """
         self.ordered_widget_list.remove(widget)
-        bounds = widget.refresh_bounds
-        self.refresh_scrolled_rect(refresh_bounds)
+        area = widget.refresh_area
+        self.refresh_scrolled_area(refresh_area)
         widget.Destroy()
 
 
+    def selected_from_canvas(self, widgets):
+        """
+        Called when mode is "normal" and widgets have been selected
+        from a drag or click operation. The default is to call
+        widget.set_selected, but your class can override this.
+        """
+        self.begin_refresh_batch()
+        for widget in self.ordered_widget_list:
+            if widget not in widgets:
+                if widget.selected:
+                    widget.set_selected(False)
+            else:
+                if not widget.selected:
+                    widget.set_selected(True)
+        self.end_refresh_batch()
 
+    def picked_from_canvas(self, widgets):
+        """
+        Called when mode is 'picker' and the widget has
+        been selected from a mouse click.
+        """
+        assert(False)
\ No newline at end of file

Modified: trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/colors.py
===================================================================
--- trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/colors.py 2006-04-02 
16:53:01 UTC (rev 8338)
+++ trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/colors.py 2006-04-03 
05:40:54 UTC (rev 8339)
@@ -18,7 +18,7 @@
 # write to the Free Software Foundation, Inc., 59 Temple Place
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
-# $Id: TriggerEditor.py 8210 2006-03-07 00:04:31Z jcater $
+# $Id$
 
 #
 # These classes were based on SimpleCanvas from OSA's Chandler
@@ -36,4 +36,4 @@
   colorIndex['panel'] = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BACKGROUND)
   colorIndex['text'] = wx.BLACK
   colorIndex['widget'] = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWFRAME)
-
+  colorIndex['widgetback'] = wx.WHITE

Modified: trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/widget.py
===================================================================
--- trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/widget.py 2006-04-02 
16:53:01 UTC (rev 8338)
+++ trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/widget.py 2006-04-03 
05:40:54 UTC (rev 8339)
@@ -18,7 +18,7 @@
 # write to the Free Software Foundation, Inc., 59 Temple Place
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
-# $Id: TriggerEditor.py 8210 2006-03-07 00:04:31Z jcater $
+# $Id$
 
 import cPickle
 
@@ -30,9 +30,9 @@
 # ===================================================================
 # A Drawable canvas widget
 # ===================================================================
-class DocumentWidget(wx.EvtHandler):
+class DocumentWidget:
     def __init__(self, gobject, canvas):
-        super(DocumentWidget, self).__init__()
+        #super(DocumentWidget, self).__init__()
 
         self.gobject = gobject
 
@@ -41,18 +41,16 @@
         self.selected = False
 
         # Coordinates (relative to canvas) that should register hit tests
-        self.hit_test_bounds = wx.Rect()
+        self.hit_test_area = wx.Rect()
         self.hit_test_exclusions = [] # Can be a list of wx.Rect()
 
         # Coordinates (relative to canvas) to refresh on widget updates
-        self.refresh_bounds = wx.Rect()
+        self.refresh_area = wx.Rect()
 
         # Calculate defaults for the above
         self.recalc_metrics()
 
-        self.Bind(wx.EVT_MOUSE_EVENTS, self.__wx_mouse_event)
 
-
     def drag_move(self, x, y):
         self.force_canvas_refresh()
         self.recalc_metrics()
@@ -65,28 +63,6 @@
         self.force_canvas_refresh()
 
 
-    def __wx_mouse_event(self, event):
-        x, y = event.GetPositionTuple()
-        if event.ButtonDown(1):
-            if self.select_hit_test(x, y) :
-                self.canvas.DeSelectAll()
-                self.SetSelected()
-                self.canvas.Update()
-                if self.DragHitTest(x, y):
-                    self.dragStartPos =(x, y)
-            else:
-                self.dragStartPos =(x,y)
-        elif event.ButtonUp(1):
-            self.dragStartPos = None
-        elif event.Dragging() and event.LeftIsDown():
-            tolerance = 2
-            if abs(x - self.dragStartPos[0]) > tolerance or \
-               abs(y - self.dragStartPos[1]) > tolerance:
-                self.DoDrag(x, y)
-                return True
-        event.Skip()
-        return False
-
     def show(self, show=True):
       # Make sure show is a Boolean
       show = bool(show)
@@ -97,8 +73,8 @@
         self.canvas.Update()
 
     def ConvertToCanvasDeviceCoordinates(self, x, y):
-      return self.canvas.CalcScrolledPosition(self.refresh_bounds.GetLeft() + 
x,
-                                                self.refresh_bounds.GetTop() + 
y)
+      return self.canvas.CalcScrolledPosition(self.refresh_area.GetLeft() + x,
+                                                self.refresh_area.GetTop() + y)
 
     def DoDrag(self, x, y):
       """
@@ -108,7 +84,7 @@
       """
         Create the dragImage and begin dragging over the full screen
       """
-      offscreenBuffer = wx.EmptyBitmap(self.refresh_bounds.GetWidth(), 
self.refresh_bounds.GetHeight())
+      offscreenBuffer = wx.EmptyBitmap(self.refresh_area.GetWidth(), 
self.refresh_area.GetHeight())
       memoryDC = wx.MemoryDC()
       memoryDC.SelectObject(offscreenBuffer)
 
@@ -116,7 +92,7 @@
       memoryDC.Clear()
       self.draw(memoryDC)
 
-      maskBitmap = wx.EmptyBitmap(self.refresh_bounds.GetWidth(), 
self.refresh_bounds.GetHeight(), 1)
+      maskBitmap = wx.EmptyBitmap(self.refresh_area.GetWidth(), 
self.refresh_area.GetHeight(), 1)
       memoryDC.SelectObject(maskBitmap)
 
       memoryDC.SetBackground(wx.BLACK_BRUSH)
@@ -162,7 +138,6 @@
 
     def SizeDrag(self, dragRect, startDrag, endDrag):
       self.force_canvas_refresh()
-      #self.bounds = dragRect
       self.force_canvas_refresh()
 
     def set_selected(self, selected=True):
@@ -176,6 +151,7 @@
         if (selected ^ self.selected):
             self.selected = selected
             self.force_canvas_refresh()
+            self.canvas.refresh_selection()
 
 
     def recalc_metrics(self):
@@ -189,7 +165,7 @@
         """
         Signal to the canvas that are area changed
         """
-        self.canvas.refresh_scrolled_rect(self.refresh_bounds)
+        self.canvas.refresh_scrolled_area(self.refresh_area)
 
 
     def draw(self, dc):
@@ -199,17 +175,25 @@
         self.draw_widget(dc)
         if self.selected:
           self.draw_border(dc)
+        self.draw_decorations(dc)
 
 
     # ====================================================================
     # You can implement the following functions, but usually won't need to
     # ====================================================================
 
+    def draw_decorations(self, dc):
+        """
+        This method is the last draw_ method called and can be used to
+        draw decorations (such as focus order tags)
+        """
+        pass
+
     def draw_border(self, dc):
         """
         Draw a border for selected widgets
         """
-        x, y, w, h = self.hit_test_bounds.Get()
+        x, y, w, h = self.hit_test_area.Get()
         dc.SetBrush(wx.Brush(wx.BLACK, wx.TRANSPARENT))
         dc.SetPen(wx.Pen(colorIndex['selectedframe']))
         dc.DrawRectangle(3, 3, w  + 2, h + 2)
@@ -220,27 +204,26 @@
         You must implement this routine to do hit testing to identify
         the region for selecting the object.
 
-        By default, if not subclassed, we just use the bounds defined for the
+        By default, if not subclassed, we just use the area defined for the
         object.
         """
-        self.hit_test_bounds.InsideXY(x,y)
+        return self.hit_test_area.InsideXY(x,y)
 
 
-    def drag_hit_test (self, x1, y1, x2, y2):
+    def drag_hit_test (self, area):
         """
         You must implement this routine to do hit testing for dragable region
         of drawable object
 
-        By default, we use the bounds of the object.
+        By default, we use the area of the object.
         """
         # Should also take into account self.hit_test_exclusions
-        dragRect = wx.Rect((x1, y1), (x2, y2))
-        result = self.hit_test_bounds.Intersects(dragRect)
+        result = self.hit_test_area.Intersects(area)
 
         if result:
           # If the entire dragRect is in an exclusion area, return false
           for exclusion in self.hit_test_exclusions:
-            if exclusion.Intersect(dragRect) == dragRect:
+            if exclusion.Intersect(area) == area:
               return False
 
         return result
@@ -271,12 +254,17 @@
 
 
     def draw_mask(self, dc):
-      """
-      optionally implement this routine to draw a mask
-      (Not sure what this means... inherited from SimpleCanvas)
-      """
-      pass
+        """
+        optionally implement this routine to draw a mask
+        (Not sure what this means... inherited from SimpleCanvas)
+        """
+        pass
 
+    def select_from_canvas(self):
+        """
+        Called when the widget is selected from the canvas
+        """
+        self.set_selected()
 
 
     # ====================================================================
@@ -285,16 +273,14 @@
 
     def calc_metrics(self):
         """
-        Calculate hit_test_bounds, refresh_bounds, and any
-        class-specific bounds your draw_widget methods might need.
+        Calculate hit_test_area, refresh_area, and any
+        class-specific area your draw_widget methods might need.
         """
         assert(False)
 
-
     def draw_widget(self, dc):
-      """
-      You must implement this routine to do draw the actual widget
-      """
-      assert(False)
+        """
+        You must implement this routine to do draw the actual widget
+        """
+        assert(False)
 
-





reply via email to

[Prev in Thread] Current Thread [Next in Thread]