commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r8340 - in trunk/gnue-designer/src: forms/PagePainter forms/PageP


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

Author: jcater
Date: 2006-04-03 10:30:16 -0500 (Mon, 03 Apr 2006)
New Revision: 8340

Added:
   trunk/gnue-designer/src/forms/PagePainter/skins/
   trunk/gnue-designer/src/forms/PagePainter/skins/__init__.py
   trunk/gnue-designer/src/forms/PagePainter/skins/common.py
   trunk/gnue-designer/src/forms/PagePainter/skins/default.py
   trunk/gnue-designer/src/forms/PagePainter/skins/term.py
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
Log:
misc display fixes

Modified: trunk/gnue-designer/src/forms/PagePainter/PagePainter.py
===================================================================
--- trunk/gnue-designer/src/forms/PagePainter/PagePainter.py    2006-04-03 
05:40:54 UTC (rev 8339)
+++ trunk/gnue-designer/src/forms/PagePainter/PagePainter.py    2006-04-03 
15:30:16 UTC (rev 8340)
@@ -33,16 +33,16 @@
 #--------------------------------------------------------------------------
 from gnue.designer.base.EditorBase import EditorBase
 
+from skins import common
+# TODO: This will eventually be settable
+from skins.default import getWidgetSkinClass
+
 #--------------------------------------------------------------------------
 # External Imports
 #--------------------------------------------------------------------------
 import wx
 
 
-xscale = 0
-yscale = 0
-
-
 # ===========================================================================
 # The PagePainter class
 # ===========================================================================
@@ -72,26 +72,25 @@
         # Determine text extents
         dc = wx.PaintDC(self)
         dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT))
-        global xscale, yscale
-
-        if not xscale:
+        
+        if not common.char_x_scale:
             for char in string.digits + string.letters:
                 w, h = dc.GetTextExtent(char)
-                xscale = max(xscale, w)
-                yscale = max(yscale, h)
+                common.char_x_scale = max(common.char_x_scale, w)
+                common.char_y_scale = max(common.char_y_scale, h)
 
             # Make the scale slightly larger, so that input widgets
             # are bigger than text labels.
-            #xscale += 4
-            yscale += 2
+            #common.char_x_scale += 4
+            common.char_y_scale += 2
 
-        canvas.set_grid_scale(xscale, yscale)
+        canvas.set_grid_scale(common.char_x_scale, common.char_y_scale)
 
         # Draw initial objects
-        self.object.walk(self.inventoryObject)
+        self.object.walk(self.inventory)
 
 
-    def inventoryObject(self, object):
+    def inventory(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.
@@ -99,8 +98,9 @@
             x = object['Char:x']
             y = object['Char:y']
         except:
-            print "Not inventorying %s" % object
-            return
+            if not object._type == 'GFPage':
+                print "Not inventorying %s" % object
+                return
 
         canvas = self.canvas
 
@@ -109,12 +109,7 @@
         widget = cls(object, canvas)
         canvas.add(widget)
 
-        # Debugging...
-        widget.set_selected(True)
 
-        print "Added %s" % object._type
-
-
     def __objectSelected(self, object):
         pass
 
@@ -129,9 +124,9 @@
 
 
 
-# ===========================================================================
+# ==========================================================================
 # SimpleCanvas implementations
-# ===========================================================================
+# ==========================================================================
 #
 # These will be reorganized into a separate file once design is completed.
 #
@@ -139,160 +134,18 @@
 import cPickle
 
 from gnue.designer.ui.wx.uihelpers.doccanvas.canvas import DocumentCanvas
-from gnue.designer.ui.wx.uihelpers.doccanvas.widget import DocumentWidget
-from gnue.designer.ui.wx.uihelpers.doccanvas.colors import colorIndex
 
-#--------------------------------------------------------------------------
-# form widgets
-#--------------------------------------------------------------------------
 
-def getWidgetSkinClass(object):
-    if object._type == 'GFLabel':
-        cls = LabelWidget
-    elif object._type == 'GFEntry':
-           cls = EntryWidget
-    elif object._type == 'GFBox':
-        cls = BoxWidget
-    else:
-        cls = UnknownWidget
-
-    return cls
-
-
-class FormWidget(DocumentWidget):
-    """
-    A DocumentWidget specific to the forms document type
-    """
-
-    # If Char:height or Char:width aren't specified, assume...
-    char_default_height = 1
-    char_default_width = 10
-
-    # Specific widgets can redefine these if they can't go smaller or larger
-    # than a certain size (e.g., labels are always 1 char high)
-    char_min_height = 1
-    char_min_width = 1
-    char_max_height = 99999999
-    char_max_width = 99999999
-
-    # Compensation for the border drawn around objects if selected
-    border_compensation = 4
-
-
-    def calc_metrics(self):
-
-        canvas = self.canvas
-
-        object = self.gobject
-
-        # This gives us an offset onto the current drawing canvas
-        # accounting for any workspace margins.
-        documentX = canvas.document_origin_x
-        documentY = canvas.document_origin_y
-
-        # Right now, only Char positioning is supported.
-        x = object['Char:x']
-        y = object['Char:y']
-
-        try:
-            w = object['Char:width']
-        except KeyError:
-            w =  self.char_default_width
-
-        try:
-            h = object['Char:height']
-        except KeyError:
-            h =  self.char_default_height
-
-        # Convert from Char positions into wx positions
-        x *= xscale
-        y *= yscale
-        w *= xscale
-        h *= yscale
-
-        # Used to figure in compensation needed for selection box
-        # decorations and borders
-        compensation = self.border_compensation
-
-        # 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_area = wx.Rect(x + documentX  - compensation,
-                                      y + documentY - compensation,
-                                      w + compensation * 2,
-                                      h  + compensation * 2)
-
-        # Save the area, relative to the canvas, of the area
-        # that the widget sans decorations occupy on the
-        self.hit_test_area = wx.Rect(x  + documentX,
-                                       y + documentY,
-                                       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
-
-
-
-class LabelWidget(FormWidget):
-
-    char_max_height = 1
-
-    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))
-        # Center each character in its cell
-        for char in object.text:
-            cw, ch = dc.GetTextExtent(char)
-            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']))
-        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_area.Get()
-        dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT))
-        dc.DrawRoundedRectangle(x,y,w,h, 4)
-
-
-#==========================================================================
+# ==========================================================================
 # Canvas implementation
-#==========================================================================
+# ==========================================================================
 class PagePainterCanvas(DocumentCanvas):
 
     def __init__(self, *args, **parms):
         DocumentCanvas.__init__(self, *args, **parms)
 
-        self.document_origin_x = xscale * 2
-        self.document_origin_y = yscale * 2
+        self.document_origin_x = common.char_x_scale * 2
+        self.document_origin_y = common.char_y_scale * 2
 
 
 

Added: trunk/gnue-designer/src/forms/PagePainter/skins/__init__.py
===================================================================


Property changes on: trunk/gnue-designer/src/forms/PagePainter/skins/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: trunk/gnue-designer/src/forms/PagePainter/skins/common.py
===================================================================
--- trunk/gnue-designer/src/forms/PagePainter/skins/common.py   2006-04-03 
05:40:54 UTC (rev 8339)
+++ trunk/gnue-designer/src/forms/PagePainter/skins/common.py   2006-04-03 
15:30:16 UTC (rev 8340)
@@ -0,0 +1,116 @@
+#
+# Copyright 2001-2006 Free Software Foundation
+#
+# This file is part of GNU Enterprise
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2, or(at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+
+from gnue.designer.ui.wx.uihelpers.doccanvas.widget import DocumentWidget
+from gnue.designer.ui.wx.uihelpers.doccanvas.colors import colorIndex
+
+import wx
+
+#--------------------------------------------------------------------------
+# Globals
+#--------------------------------------------------------------------------
+# These are set by PagePainter.py on first run.
+char_x_scale = 0
+char_y_scale = 0
+
+__all__ = ['FormWidget','char_x_scale', 'char_y_scale']
+
+class FormWidget(DocumentWidget):
+    """
+    A DocumentWidget specific to the forms document type
+    """
+
+    # If Char:height or Char:width aren't specified, assume...
+    char_default_height = 1
+    char_default_width = 10
+
+    # Specific widgets can redefine these if they can't go smaller or larger
+    # than a certain size (e.g., labels are always 1 char high)
+    char_min_height = 1
+    char_min_width = 1
+    char_max_height = 99999999
+    char_max_width = 99999999
+
+    # Compensation for the border drawn around objects if selected
+    border_compensation = 4
+
+
+    def calc_metrics(self):
+
+        canvas = self.canvas
+
+        object = self.gobject
+
+        # This gives us an offset onto the current drawing canvas
+        # accounting for any workspace margins.
+        documentX = canvas.document_origin_x
+        documentY = canvas.document_origin_y
+
+        # Right now, only Char positioning is supported.
+        try: 
+          x = object['Char:x']
+          y = object['Char:y']
+        except: 
+          x = y = 0
+
+        try:
+            w = object['Char:width']
+        except KeyError:
+            w =  self.char_default_width
+
+        try:
+            h = object['Char:height']
+        except KeyError:
+            h =  self.char_default_height
+
+        # Convert from Char positions into wx positions
+        x *= char_x_scale
+        y *= char_y_scale
+        w *= char_x_scale
+        h *= char_y_scale
+
+        # Used to figure in compensation needed for selection box
+        # decorations and borders
+        compensation = self.border_compensation
+
+        # 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_area = wx.Rect(x + documentX  - compensation,
+                                    y + documentY - compensation,
+                                    w + compensation * 2,
+                                    h  + compensation * 2)
+
+        # Save the area, relative to the canvas, of the area
+        # that the widget sans decorations occupy on the
+        self.hit_test_area = wx.Rect(x  + documentX,
+                                     y + documentY,
+                                     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
+


Property changes on: trunk/gnue-designer/src/forms/PagePainter/skins/common.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: trunk/gnue-designer/src/forms/PagePainter/skins/default.py
===================================================================
--- trunk/gnue-designer/src/forms/PagePainter/skins/default.py  2006-04-03 
05:40:54 UTC (rev 8339)
+++ trunk/gnue-designer/src/forms/PagePainter/skins/default.py  2006-04-03 
15:30:16 UTC (rev 8340)
@@ -0,0 +1,174 @@
+#
+# Copyright 2001-2006 Free Software Foundation
+#
+# This file is part of GNU Enterprise
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2, or(at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+
+
+"""
+Implement the default, simple GUI skin
+"""
+
+from common import FormWidget
+import common
+
+from gnue.designer.ui.wx.uihelpers.doccanvas.colors import colorIndex
+
+import wx 
+
+# --------------------------------------------------------------------------
+# form widgets
+# --------------------------------------------------------------------------
+
+def getWidgetSkinClass(object):
+    if object._type == 'GFLabel':
+        cls = LabelWidget
+    elif object._type == 'GFEntry':
+           cls = EntryWidget
+    elif object._type == 'GFPage':
+           cls = PageWidget
+    elif object._type == 'GFBox':
+        cls = BoxWidget
+    else:
+        cls = UnknownWidget
+
+    return cls
+
+
+# --------------------------------------------------------------------------
+# Page 
+# --------------------------------------------------------------------------
+class PageWidget(FormWidget):
+    def calc_metrics(self):
+
+        canvas = self.canvas
+
+        object = self.gobject.findParentOfType('GFLayout')
+
+        # This gives us an offset onto the current drawing canvas
+        # accounting for any workspace margins.
+        documentX = canvas.document_origin_x
+        documentY = canvas.document_origin_y
+
+        # Right now, only Char positioning is supported.
+        x = 0
+        y = 0
+        w = object['Char:width']
+        h = object['Char:height']
+
+        # Convert from Char positions into wx positions
+        w *= common.char_x_scale
+        h *= common.char_y_scale
+
+        # Used to figure in compensation needed for selection box
+        # decorations and borders
+        compensation = self.border_compensation
+
+        # 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_area = wx.Rect(x + documentX  - compensation,
+                                    y + documentY - compensation,
+                                    w + compensation * 2,
+                                    h  + compensation * 2)
+
+        # Save the area, relative to the canvas, of the area
+        # that the widget sans decorations occupy on the
+        self.hit_test_area = wx.Rect(x  + documentX,
+                                     y + documentY,
+                                     w, h)
+        self.hit_test_exclusions = [
+              wx.Rect(x + documentX+common.char_x_scale,
+                      y + documentY + common.char_y_scale,
+                      w - common.char_x_scale * 2, 
+                      h - common.char_y_scale * 2) ]
+
+        # Save the area, relative to being drawn in a context at (0,0)
+        self.draw_area = wx.Rect(compensation, compensation, w, h)
+
+
+    def draw_widget(self, dc):
+        dc.SetPen(wx.Pen(colorIndex['widget']))
+        dc.SetBrush(wx.Brush(colorIndex['panel'], style=wx.CROSSDIAG_HATCH))
+        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,w,h, 4)
+
+
+# --------------------------------------------------------------------------
+# Label
+# --------------------------------------------------------------------------
+class LabelWidget(FormWidget):
+
+    char_max_height = 1
+
+    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))
+        # Center each character in its cell
+        for char in object.text:
+            cw, ch = dc.GetTextExtent(char)
+            dc.DrawText(char, 
+                        x + (common.char_x_scale - cw) // 2, 
+                        y + 1)
+            x += common.char_x_scale
+
+
+# --------------------------------------------------------------------------
+# Entry
+# --------------------------------------------------------------------------
+class EntryWidget(FormWidget):
+    def draw_widget(self, dc):
+        dc.SetPen(wx.Pen(colorIndex['widget']))
+        dc.SetBrush(wx.Brush(colorIndex['widgetback']))
+        x,y,w,h = self.draw_area.Get()
+        dc.DrawRoundedRectangle(x,y,w,h, 1)
+
+
+# --------------------------------------------------------------------------
+# Box
+# --------------------------------------------------------------------------
+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 + common.char_y_scale // 2 + 1, 
+         w, h - common.char_y_scale, common.char_x_scale//3)
+
+
+# --------------------------------------------------------------------------
+# Unknown/unimplemented widgets
+# --------------------------------------------------------------------------
+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_area.Get()
+        dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT))
+        dc.DrawRoundedRectangle(x,y,w,h, 4)
+
+


Property changes on: trunk/gnue-designer/src/forms/PagePainter/skins/default.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: trunk/gnue-designer/src/forms/PagePainter/skins/term.py
===================================================================
--- trunk/gnue-designer/src/forms/PagePainter/skins/term.py     2006-04-03 
05:40:54 UTC (rev 8339)
+++ trunk/gnue-designer/src/forms/PagePainter/skins/term.py     2006-04-03 
15:30:16 UTC (rev 8340)
@@ -0,0 +1,35 @@
+#
+# Copyright 2001-2006 Free Software Foundation
+#
+# This file is part of GNU Enterprise
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2, or(at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+
+
+"""
+Implement a character-based (console or terminal) skin
+(i.e., simulate what the screen would look like on an 
+ncurses screen. 
+"""
+
+from common import FormWidget
+
+from gnue.designer.ui.wx.uihelpers.doccanvas.colors import colorIndex
+
+
+# TODO
\ No newline at end of file


Property changes on: trunk/gnue-designer/src/forms/PagePainter/skins/term.py
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/canvas.py
===================================================================
--- trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/canvas.py 2006-04-03 
05:40:54 UTC (rev 8339)
+++ trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/canvas.py 2006-04-03 
15:30:16 UTC (rev 8340)
@@ -38,20 +38,24 @@
               'move': wx.CURSOR_HAND,
              }
 
+GRID_OFF = 0
+GRID_LINES = 1
+GRID_DOTS = 2
+
 # ===================================================================
 # The canvas to draw on
 # ===================================================================
 class DocumentCanvas(wx.ScrolledWindow):
 
     # TODO: make this a preference setting or toolbar icon
-    showRuler = True
-    gridStyle = 1  # (can be 0=None, 1 = dashed lines, 2=dots)
+    show_ruler = True
+    grid_style = GRID_LINES  # (can be 0=None, 1 = dashed lines, 2=dots)
 
     def __init__(self, *arguments, **keywords):
         super(DocumentCanvas, self).__init__(*arguments, **keywords)
 
         if not colorIndex:
-          buildColorIndex()
+            buildColorIndex()
 
         self.ordered_widget_list = []
 
@@ -61,15 +65,15 @@
 
         # Screen refreshing
         self.__selection_area = None
-        self.__refresh_batch = 0
+        self.__refresh_batch = 0       # This is a counter
 
-        # Mouse events
+        # Mouse event defaults
         self.__mouse_hot_spots = []
         self.__current_cursor = None
-        self.__mouse_mode = 'normal'
-        self.__mouse_click_function = None
+        self.__mouse_mode = 'normal'         # See set_mouse_mode()
+        self.__mouse_click_function = None   # See __wx_on_mouse()
         self.__mouse_current_action = ""
-        self.__mouse_move_buffer = None
+        self.__mouse_move_buffer = None      # See __start_moving()
         self.__mouse_move_area = None
         self.__hide_selection_frame = False
 
@@ -79,6 +83,7 @@
             item.Destroy()
         self.ordered_widget_list = None
 
+
     def set_mouse_mode(self, mode='normal', function=None):
         """
         mode       String that is one of:
@@ -107,17 +112,64 @@
         self.__mouse_click_function = method
 
 
+    # ---------------------------------------------------------------
+    # Grid support
+    # ---------------------------------------------------------------
     def set_grid_scale(self, x, y):
-      """
-      Sets the grid x,y spacing
-      """
-      self.grid_x_spacing = x
-      self.grid_y_spacing = y
+        """
+        Sets the grid x,y spacing
+        """
+        self.grid_x_spacing = x
+        self.grid_y_spacing = y
 
+    def set_grid_style(self, style):
+        """
+        Sets the grid style (GRID_OFF, GRID_LINES, GRID_DOTS)
+        """
+        self.grid_style = style
 
+
+    # ---------------------------------------------------------------
+    # Refresh the canvas on screen
+    # ---------------------------------------------------------------
+    def begin_refresh_batch(self):
+        """
+        When several refresh_scrolled_areas will be called sequentially, 
+        you can call this first to have them all batched together into 
+        one update, making the application look more responsive. 
+        
+        Call end_refresh_batch() to apply the updates. 
+        """
+        self.__refresh_batch += 1
+        self.__refresh_batch_area = wx.Rect()
+
+    def end_refresh_batch(self):
+        """
+        End the batching of update requests
+        """
+        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, area.GetWidth(), area.GetHeight()));
+
+
     def refresh_selection(self):
         """
-        call this method when the selection list has changed
+        Call this method when the selection list has changed
         so we can recalculate the selection area
         """
 
@@ -173,31 +225,9 @@
         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, area.GetWidth(), area.GetHeight()));
-
-
+    # ---------------------------------------------------------------
+    # Painting/drawing logic
+    # ---------------------------------------------------------------
     def __wx_on_paint(self, event):
         """
         Catch the wx OnPaint event and draw the canvas and any widgets
@@ -269,24 +299,25 @@
 
       dcOriginX, dcOriginY = dc.GetDeviceOrigin()
 
-      for widget in self.ordered_widget_list:
-        refresh_area = widget.refresh_area
+      # Draw widgets (in the reverse order they are stored in our list)
+      for widget in self.ordered_widget_list[::-1]:
+          refresh_area = widget.refresh_area
 
-        (objectX, objectY,
-         objectWidth, objectHeight) = refresh_area.Get()
+          (objectX, objectY,
+           objectWidth, objectHeight) = refresh_area.Get()
 
-        # Calculate the area, offset by the scrollwindow's origin
-        area = wx.Rect(objectX - scrollWindowOriginX,
+          # Calculate the area, offset by the scrollwindow's origin
+          area = wx.Rect(objectX - scrollWindowOriginX,
                          objectY - scrollWindowOriginY,
                          objectWidth, objectHeight)
 
 
-        if (updateRegion.ContainsRect(area) != wx.OutRegion and
-            widget.visible):
+          if (updateRegion.ContainsRect(area) != wx.OutRegion and
+              widget.visible):
 
-            dc.SetDeviceOrigin(objectX + dcOriginX, objectY + dcOriginY)
-            widget.draw(dc)
-            dc.SetDeviceOrigin(dcOriginX, dcOriginY)
+              dc.SetDeviceOrigin(objectX + dcOriginX, objectY + dcOriginY)
+              widget.draw(dc)
+              dc.SetDeviceOrigin(dcOriginX, dcOriginY)
 
 
       # Draw a box around all the selected widgets
@@ -352,7 +383,7 @@
         #
         # Draw the grid
         #
-        if self.gridStyle == 1:
+        if self.grid_style == 1:
             SOLIDSPACING = 4
             w, h = self.GetClientSizeTuple()
             pen1 = wx.Pen(colorIndex['workspaceGrid'], 1, wx.SHORT_DASH)
@@ -382,7 +413,7 @@
                     dc.SetPen(pen1)
                     switchToMainPen = False
 
-        elif self.gridStyle == 2:
+        elif self.grid_style == 2:
             SOLIDSPACING = 4
             w, h = self.GetClientSizeTuple()
             pen1 = wx.Pen(colorIndex['workspaceGrid'], 1, wx.SOLID)
@@ -500,7 +531,6 @@
                     return True
 
 
-
         elif event.LeftUp():
 
             if mode == 'normal':
@@ -545,9 +575,8 @@
         return False
 
 
-
     # ---------------------------------------------------------------
-    #
+    # Hit Tests
     # ---------------------------------------------------------------
     def select_hit_test(self, x, y):
         """
@@ -823,7 +852,6 @@
 
         dc.EndDrawing()
 
-
     def __stop_rubberband(self, x, y):
         """
         Stops the rubberband box, returning a wx.Rect indicating
@@ -842,6 +870,7 @@
       """
         Handle default behavior of copy and move
       """
+      # TODO: this is left over from SimpleCanvas.py... not used yet. 
       if result == wx.DragMove or result == wx.DragCopy:
           if(self.internalDnDItem != None) and(result == wx.DragMove):
               assert(self.ordered_widget_list.count(self.internalDnDItem) == 1)
@@ -883,7 +912,7 @@
         """
         Add a DocumentWidget to the canvas
         """
-        self.ordered_widget_list.insert(0, widget)
+        self.ordered_widget_list.insert(0,widget)
         widget.force_canvas_refresh()
 
 
@@ -896,7 +925,9 @@
         self.refresh_scrolled_area(refresh_area)
         widget.Destroy()
 
-
+    # ---------------------------------------------------------------
+    # Local mouse events
+    # ---------------------------------------------------------------
     def selected_from_canvas(self, widgets):
         """
         Called when mode is "normal" and widgets have been selected
@@ -918,4 +949,5 @@
         Called when mode is 'picker' and the widget has
         been selected from a mouse click.
         """
-        assert(False)
\ No newline at end of file
+        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-03 
05:40:54 UTC (rev 8339)
+++ trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/colors.py 2006-04-03 
15:30:16 UTC (rev 8340)
@@ -37,3 +37,14 @@
   colorIndex['text'] = wx.BLACK
   colorIndex['widget'] = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWFRAME)
   colorIndex['widgetback'] = wx.WHITE
+
+def buildTermColorIndex(): 
+  colorIndex['selectionframe'] = wx.BLUE # 
wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT)
+  colorIndex['selectedframe'] = wx.BLUE # 
wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT)
+  colorIndex['workspace'] = 
wx.SystemSettings_GetColour(wx.SYS_COLOUR_APPWORKSPACE)
+  colorIndex['workspaceGrid'] = wx.Colour(240,240,240) # TODO: ???
+  colorIndex['panel'] = wx.BLACK
+  colorIndex['text'] = wx.WHITE
+  colorIndex['widget'] = wx.TRANSPARENT
+  colorIndex['widgetback'] = wx.WHITE
+  
\ No newline at end of file





reply via email to

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