commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r8334 - trunk/gnue-designer/src/uidrivers/wx/uihelpers/documentca


From: jcater
Subject: [gnue] r8334 - trunk/gnue-designer/src/uidrivers/wx/uihelpers/documentcanvas
Date: Mon, 3 Apr 2006 18:24:50 -0500 (CDT)

Author: jcater
Date: 2006-04-01 00:31:13 -0600 (Sat, 01 Apr 2006)
New Revision: 8334

Modified:
   trunk/gnue-designer/src/uidrivers/wx/uihelpers/documentcanvas/canvas.py
Log:
added missing comments/documentation

Modified: 
trunk/gnue-designer/src/uidrivers/wx/uihelpers/documentcanvas/canvas.py
===================================================================
--- trunk/gnue-designer/src/uidrivers/wx/uihelpers/documentcanvas/canvas.py     
2006-04-01 06:18:29 UTC (rev 8333)
+++ trunk/gnue-designer/src/uidrivers/wx/uihelpers/documentcanvas/canvas.py     
2006-04-01 06:31:13 UTC (rev 8334)
@@ -281,185 +281,190 @@
 
         # Add hotspot markers for the selection box
         if not xor:
-          add_hotspot((wx.Rect(x, y, 1, h), 'resize-left'))
-          add_hotspot((wx.Rect(x, y, w, 1), 'resize-top'))
-          add_hotspot((wx.Rect(x + w - 1, y, 1, h), 'resize-right'))
-          add_hotspot((wx.Rect(x, y + h - 1, w, 1), 'resize-bottom'))
-          add_hotspot((wx.Rect(x + 1, y + 1, w - 1, h - 1), 'move'))
+            add_hotspot((wx.Rect(x, y, 1, h), 'resize-left'))
+            add_hotspot((wx.Rect(x, y, w, 1), 'resize-top'))
+            add_hotspot((wx.Rect(x + w - 1, y, 1, h), 'resize-right'))
+            add_hotspot((wx.Rect(x, y + h - 1, w, 1), 'resize-bottom'))
+            add_hotspot((wx.Rect(x + 1, y + 1, w - 1, h - 1), 'move'))
 
 
     def draw_background(self, dc):
-      """
-      Draw a background (with grid if appropriate)
-      """
-      dc.SetBackgroundMode(wx.TRANSPARENT)
-      dc.Clear()
-      #
-      # Draw the grid
-      #
-      if self.gridStyle == 1:
-        SOLIDSPACING = 4
-        w, h = self.GetClientSizeTuple()
-        pen1 = wx.Pen(colorIndex['workspaceGrid'], 1, wx.SHORT_DASH)
-        pen2 = wx.Pen(colorIndex['workspaceGrid'], 1, wx.SOLID)
-        dc.SetPen(pen1)
+        """
+        Draw a background (with grid if appropriate)
+        """
+        dc.SetBackgroundMode(wx.TRANSPARENT)
+        dc.Clear()
+        #
+        # Draw the grid
+        #
+        if self.gridStyle == 1:
+            SOLIDSPACING = 4
+            w, h = self.GetClientSizeTuple()
+            pen1 = wx.Pen(colorIndex['workspaceGrid'], 1, wx.SHORT_DASH)
+            pen2 = wx.Pen(colorIndex['workspaceGrid'], 1, wx.SOLID)
+            dc.SetPen(pen1)
 
-        # Draw vertical grid lines
-        switchToMainPen = False
-        for x in xrange(self.grid_x_spacing,w,self.grid_x_spacing):
-          if not x % SOLIDSPACING:
-            switchToMainPen = True
-            dc.SetPen(pen2)
-          dc.DrawLine(x,0,x,h-1)
-          if switchToMainPen:
-            dc.SetPen(pen1)
+            # Draw vertical grid lines
             switchToMainPen = False
+            for x in xrange(self.grid_x_spacing,w,self.grid_x_spacing):
+                if not x % SOLIDSPACING:
+                    switchToMainPen = True
+                    dc.SetPen(pen2)
+                dc.DrawLine(x,0,x,h-1)
+                if switchToMainPen:
+                    dc.SetPen(pen1)
+                    switchToMainPen = False
 
 
-        # Draw horizontal grid lines
-        switchToMainPen = False
-        for y in xrange(self.grid_y_spacing, h, self.grid_y_spacing):
-          if not y % SOLIDSPACING:
-            switchToMainPen = True
-            dc.SetPen(pen2)
-          dc.DrawLine(0, y, w, y)
-          if switchToMainPen:
-            dc.SetPen(pen1)
+            # Draw horizontal grid lines
             switchToMainPen = False
+            for y in xrange(self.grid_y_spacing, h, self.grid_y_spacing):
+                if not y % SOLIDSPACING:
+                    switchToMainPen = True
+                    dc.SetPen(pen2)
+                dc.DrawLine(0, y, w, y)
+                if switchToMainPen:
+                    dc.SetPen(pen1)
+                    switchToMainPen = False
 
-      elif self.gridStyle == 2:
-        SOLIDSPACING = 4
-        w, h = self.GetClientSizeTuple()
-        pen1 = wx.Pen(colorIndex['workspaceGrid'], 1, wx.SOLID)
-        pen2 = wx.Pen(colorIndex['workspaceGrid'], 1, wx.SOLID)
-        dc.SetPen(pen1)
+        elif self.gridStyle == 2:
+            SOLIDSPACING = 4
+            w, h = self.GetClientSizeTuple()
+            pen1 = wx.Pen(colorIndex['workspaceGrid'], 1, wx.SOLID)
+            pen2 = wx.Pen(colorIndex['workspaceGrid'], 1, wx.SOLID)
+            dc.SetPen(pen1)
 
 
-        dc.SetPen(pen2)
-        for x in xrange(self.grid_x_spacing,w,self.grid_x_spacing):
-          for y in xrange(self.grid_y_spacing, h, self.grid_y_spacing):
-            dc.DrawPoint(x,y)
+            dc.SetPen(pen2)
+            for x in xrange(self.grid_x_spacing,w,self.grid_x_spacing):
+                for y in xrange(self.grid_y_spacing, h, self.grid_y_spacing):
+                    dc.DrawPoint(x,y)
 
-        # Draw vertical grid lines
-        for x in 
xrange(self.grid_x_spacing*SOLIDSPACING,w,self.grid_x_spacing*SOLIDSPACING):
-          dc.DrawLine(x,0,x,h-1)
+            # Draw vertical grid lines
+            for x in xrange(self.grid_x_spacing*SOLIDSPACING, w,
+                            self.grid_x_spacing*SOLIDSPACING):
+                dc.DrawLine(x,0,x,h-1)
 
 
-        # Draw horizontal grid lines
-        for y in xrange(self.grid_y_spacing*SOLIDSPACING, h, 
self.grid_y_spacing*SOLIDSPACING):
-          dc.DrawLine(0, y, w, y)
+            # Draw horizontal grid lines
+            for y in xrange(self.grid_y_spacing*SOLIDSPACING, h,
+                            self.grid_y_spacing*SOLIDSPACING):
+                dc.DrawLine(0, y, w, y)
 
 
 
     def __wx_on_erase_background(self, event):
-      """
-      Override __wx_on_erase_background to avoid erasing background. Instead
-      implement OnDrawBackground to draw/erase the background. This
-      design alternative will eliminate flicker
-      """
-      pass
+        """
+        Override __wx_on_erase_background to avoid erasing background. Instead
+        implement OnDrawBackground to draw/erase the background. This
+        design alternative will eliminate flicker
+        """
+        pass
 
 
     # ---------------------------------------------------------------
     # Mouse events
     # ---------------------------------------------------------------
     def __wx_on_mouse_event(self, event):
-      x, y = event.GetPositionTuple()
-      x, y = self.CalcUnscrolledPosition(x, y)
+        """
+        Process any wx.MouseEvents
+        """
+        x, y = event.GetPositionTuple()
+        x, y = self.CalcUnscrolledPosition(x, y)
 
-      mode = self.__mouse_mode
-      current_action = self.__mouse_current_action
+        mode = self.__mouse_mode
+        current_action = self.__mouse_current_action
 
-      if event.Dragging():
-          if mode == 'select':
-              if current_action == 'rubberband':
-                  self.__update_rubberband(x,y)
+        if event.Dragging():
+            if mode == 'select':
+                if current_action == 'rubberband':
+                    self.__update_rubberband(x,y)
 
-              elif current_action == 'move':
-                  self.__update_moving(x,y)
+                elif current_action == 'move':
+                    self.__update_moving(x,y)
 
-              elif current_action == 'resize':
-                  self.__update_resizing(x,y)
+                elif current_action == 'resize':
+                    self.__update_resizing(x,y)
 
 
-      elif event.Moving():
-          cursor = None
-          if  mode == 'select':
-              if not current_action:
-                  # No previous action. Should we change the cursor?
-                  for rect, position in self.__mouse_hot_spots:
-                      if rect.InsideXY(x, y):
-                          cursor = cursor_map[position]
-                          break
-                  if not cursor:
-                      cursor = wx.CURSOR_ARROW
+        elif event.Moving():
+            cursor = None
+            if  mode == 'select':
+                if not current_action:
+                    # No previous action. Should we change the cursor?
+                    for rect, position in self.__mouse_hot_spots:
+                        if rect.InsideXY(x, y):
+                            cursor = cursor_map[position]
+                            break
+                    if not cursor:
+                        cursor = wx.CURSOR_ARROW
 
-                  if cursor != self.__current_cursor:
-                      self.SetCursor(wx.StockCursor(cursor))
+                    if cursor != self.__current_cursor:
+                        self.SetCursor(wx.StockCursor(cursor))
 
-                  return True
+                    return True
 
 
-      elif event.LeftDown():
+        elif event.LeftDown():
 
-          if mode == 'select':
+            if mode == 'select':
 
-              if not current_action:
-                  # No previous action.
-                  new_action = None
+                if not current_action:
+                    # No previous action.
+                    new_action = None
 
-                  # Check to see if a currently selected area has been
-                  # clicked, and whether it will be moved or resized:
-                  for rect, action in self.__mouse_hot_spots:
-                      if rect.InsideXY(x, y):
-                          new_action = action
-                          break
+                    # Check to see if a currently selected area has been
+                    # clicked, and whether it will be moved or resized:
+                    for rect, action in self.__mouse_hot_spots:
+                        if rect.InsideXY(x, y):
+                            new_action = action
+                            break
 
-                  # 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
+                    # 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
 
-                  # Finally, assume we're creating a rubberband selector
-                  if not new_action:
-                      new_action = 'rubberband'
-                      self.__start_rubberband(x, y)
+                    # Finally, assume we're creating a rubberband selector
+                    if not new_action:
+                        new_action = 'rubberband'
+                        self.__start_rubberband(x, y)
 
-                  elif new_action == 'move':
-                      self.__start_moving(x,y)
+                    elif new_action == 'move':
+                        self.__start_moving(x,y)
 
-                  elif new_action.startswith('resize-'):
-                      self.__start_resizing(x, y,
-                                      new_action.split('-')[1])
-                      new_action = 'resize'
+                    elif new_action.startswith('resize-'):
+                        self.__start_resizing(x, y,
+                                        new_action.split('-')[1])
+                        new_action = 'resize'
 
-                  self.__mouse_current_action = new_action
+                    self.__mouse_current_action = new_action
 
-                  return True
+                    return True
 
 
 
-      elif event.LeftUp():
+        elif event.LeftUp():
 
-          if mode == 'select':
+            if mode == 'select':
 
-              if current_action == 'rubberband':
-                  self.__stop_rubberband()
+                if current_action == 'rubberband':
+                    self.__stop_rubberband()
 
-              elif current_action == 'move':
-                  self.__stop_moving()
+                elif current_action == 'move':
+                    self.__stop_moving()
 
-              elif current_action == 'resize':
-                  self.__stop_resizing()
+                elif current_action == 'resize':
+                    self.__stop_resizing()
 
-              self.__mouse_current_action = ''
+                self.__mouse_current_action = ''
 
-              return True
+                return True
 
 
-      return False
+        return False
 
 
 
@@ -468,22 +473,28 @@
     # Get all selected widgets
     # ---------------------------------------------------------------
     def get_selected_widgets(self):
-      """
-      Return a list of the currently selected widgets
-      """
-      results = []
-      append = results.append
-      for widget in self.ordered_widget_list:
-          if widget.selected:
-             append(widget)
+        """
+        Return a list of the currently selected widgets
+        """
+        results = []
+        append = results.append
+        for widget in self.ordered_widget_list:
+            if widget.selected:
+                append(widget)
 
-      return results
+        return results
 
 
     # ---------------------------------------------------------------
     # Support for visual moving hints
     # ---------------------------------------------------------------
     def __start_moving(self, x, y):
+        """
+        Create the "moving" feedback. We do this by drawing the widgets
+        to be moved on an off-screen bitmap context and then blitting
+        this to the main display context as the mouse moves.
+        """
+
         self.CaptureMouse()
         self.__mouse_move_items = widgets = self.get_selected_widgets()
         bounds = wx.Rect()
@@ -533,6 +544,10 @@
 
 
     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)
@@ -540,6 +555,9 @@
 
 
     def __stop_moving(self):
+        """
+        Erase the "moving" feedback
+        """
         self.ReleaseMouse()
         old_bounds = self.__mouse_move_bounds
         self.__mouse_move_buffer = None
@@ -556,6 +574,9 @@
     # Support for visual resizing hints
     # ---------------------------------------------------------------
     def __start_resizing(self, x, y, orientation):
+        """
+        Start the resizing feedback (a XOR'd rubberband box)
+        """
         self.__mouse_resize_orientation = orientation
         self.CaptureMouse()
         self.__hide_selection_frame = True
@@ -567,14 +588,21 @@
         ##self.__update_resizing(x,y)
 
     def __update_resizing(self, x, y):
+        """
+        Update the resizing feedback by deleting the old feedback
+        and drawing the new one.
+        """
         orientation = self.__mouse_resize_orientation
         dc = wx.ClientDC(self)
         dc.BeginDrawing()
 
+        # If there's an existing frame, remove it first.
         if self.__mouse_resize_last_bounds:
             self.__draw_selection_box(dc,
                        *self.__mouse_resize_last_bounds + [True])
 
+        # If x is None, then we're only erasing the old,
+        # not drawing a new frame.
         if x is not None:
             dx = x - self.__mouse_resize_start_x
             dy = y - self.__mouse_resize_start_y
@@ -584,6 +612,8 @@
             ox2 = ox + ow - 1
             oy2 = oy + oh - 1
 
+            # The anchor point and changable points
+            # varie based on the resize orientation.
             if orientation == 'left':
                 ox += dx
             elif orientation == 'right':
@@ -611,11 +641,13 @@
             self.__mouse_resize_last_bounds = last = [ox, oy, ow, oh]
             self.__draw_selection_box(dc, *last + [True])
 
+        dc.EndDrawing()
 
 
-        dc.EndDrawing()
-
     def __stop_resizing(self):
+        """
+        Erase the resizing feedback
+        """
         self.ReleaseMouse()
         self.__update_resizing(None, None)
         self.__hide_selection_frame = False
@@ -706,31 +738,31 @@
     # ---------------------------------------------------------------
 
     def deselect_all(self):
-      """
-      Mark all selected objects as not selected. Only Refresh the objects
-      that change, don't call Update.
-      """
-      for widget in self.get_selected_widgets():
-          if (widget.selected):
-              widget.selected = False
-              widget.force_canvas_refresh()
+        """
+        Mark all selected objects as not selected. Only Refresh the objects
+        that change, don't call Update.
+        """
+        for widget in self.get_selected_widgets():
+            if (widget.selected):
+                widget.selected = False
+                widget.force_canvas_refresh()
 
     def add(self, widget):
-      """
-      Add a DocumentWidget to the canvas
-      """
-      self.ordered_widget_list.insert(0, widget)
-      widget.force_canvas_refresh()
+        """
+        Add a DocumentWidget to the canvas
+        """
+        self.ordered_widget_list.insert(0, widget)
+        widget.force_canvas_refresh()
 
 
     def remove(self, widget):
-      """
-      Remove a DocumentWidget from the canvas
-      """
-      self.ordered_widget_list.remove(widget)
-      bounds = widget.refresh_bounds
-      self.refresh_scrolled_rect(refresh_bounds)
-      widget.Destroy()
+        """
+        Remove a DocumentWidget from the canvas
+        """
+        self.ordered_widget_list.remove(widget)
+        bounds = widget.refresh_bounds
+        self.refresh_scrolled_rect(refresh_bounds)
+        widget.Destroy()
 
 
 





reply via email to

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