[Commits] (john) - First AttributeEditor checkin

commits at osafoundation.org commits at osafoundation.org
Thu Aug 19 12:43:57 PDT 2004


Commit by: john
Modified files:
chandler/parcels/osaf/framework/attributeEditors/__init__.py None 1.1
chandler/parcels/osaf/framework/attributeEditors/AttributeEditors.py None 1.1
chandler/parcels/osaf/framework/attributeEditors/parcel.xml None 1.1
chandler/parcels/osaf/framework/blocks/Views.py 1.38 1.39
chandler/parcels/osaf/framework/blocks/ControlBlocks.py 1.100 1.101
chandler/parcels/osaf/framework/blocks/detail/parcel.xml 1.19 1.20
chandler/parcels/osaf/views/main/SideBar.py 1.16 1.17

Log message:
- First AttributeEditor checkin

ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/attributeEditors/__init__.py?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/attributeEditors/AttributeEditors.py?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/attributeEditors/parcel.xml?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/blocks/Views.py.diff?r1=text&tr1=1.38&r2=text&tr2=1.39
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/blocks/ControlBlocks.py.diff?r1=text&tr1=1.100&r2=text&tr2=1.101
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/blocks/detail/parcel.xml.diff?r1=text&tr1=1.19&r2=text&tr2=1.20
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/views/main/SideBar.py.diff?r1=text&tr1=1.16&r2=text&tr2=1.17

Index: chandler/parcels/osaf/framework/blocks/Views.py
diff -u chandler/parcels/osaf/framework/blocks/Views.py:1.38 chandler/parcels/osaf/framework/blocks/Views.py:1.39
--- chandler/parcels/osaf/framework/blocks/Views.py:1.38	Sun Aug 15 14:29:41 2004
+++ chandler/parcels/osaf/framework/blocks/Views.py	Thu Aug 19 12:43:53 2004
@@ -1,5 +1,5 @@
-__version__ = "$Revision: 1.38 $"
-__date__ = "$Date: 2004/08/15 21:29:41 $"
+__version__ = "$Revision: 1.39 $"
+__date__ = "$Date: 2004/08/19 19:43:53 $"
 __copyright__ = "Copyright (c) 2003-2004 Open Source Applications Foundation"
 __license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -156,5 +156,6 @@
                         return
             block = block.parentBlock
         # none found, to remove dynamic additions we synch to the Active View
-        assert candidate is not None, "Couldn't find a dynamic child to synchronize with"
-        synchToDynamicBlock (candidate, False)
+        #assert candidate, "Couldn't find a dynamic child to synchronize with"
+        if candidate:
+            synchToDynamicBlock (candidate, False)

Index: chandler/parcels/osaf/framework/blocks/ControlBlocks.py
diff -u chandler/parcels/osaf/framework/blocks/ControlBlocks.py:1.100 chandler/parcels/osaf/framework/blocks/ControlBlocks.py:1.101
--- chandler/parcels/osaf/framework/blocks/ControlBlocks.py:1.100	Wed Aug 11 19:22:24 2004
+++ chandler/parcels/osaf/framework/blocks/ControlBlocks.py	Thu Aug 19 12:43:53 2004
@@ -1,5 +1,5 @@
-__version__ = "$Revision: 1.100 $"
-__date__ = "$Date: 2004/08/12 02:22:24 $"
+__version__ = "$Revision: 1.101 $"
+__date__ = "$Date: 2004/08/19 19:43:53 $"
 __copyright__ = "Copyright (c) 2003-2004 Open Source Applications Foundation"
 __license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -16,6 +16,7 @@
 import wx.grid
 import webbrowser # for opening external links
 import mx.DateTime as DateTime
+from osaf.framework.attributeEditors.AttributeEditors import AttributeEditor
 
 class Button(RectangularChild):
     def instantiateWidget(self):
@@ -201,7 +202,7 @@
         return len (self.blockItem.contents)
 
     def GetElementType (self, row, column):
-        return "string"
+        return "String"
 
     def GetColumnHeading (self, column, item):
         return self.blockItem.columnHeadings [column]
@@ -211,22 +212,20 @@
     def GetColumnCount (self):
         return len (self.blockItem.columnAttributeNames)
 
-    def GetElementValue (self, row, column):
-        item = self.blockItem.contents [row]
-        attributeName = self.blockItem.columnAttributeNames [column]
+    def GetElementType (self, row, column):
         try:
-            value = item.getAttributeValue (attributeName)
-        except AttributeError:
-            value = "Unnamed"
+            item = self.blockItem.contents[row]
+        except IndexError:
+            type = "_default"
         else:
-            if item.getAttributeAspect (attributeName, "cardinality") == "list":
-                compoundValue = value
-                value = ""
-                for part in compoundValue:
-                    if value:
-                        value = value + ", "
-                    value = value + part.getItemDisplayName()
-        return value
+            attributeName = self.blockItem.columnAttributeNames [column]
+            type = item.getAttributeAspect (attributeName, 'type').itsName
+            if type != "String":
+                type = "_default"
+        return type
+
+    def GetElementValue (self, row, column):
+        return self.blockItem.contents [row], self.blockItem.columnAttributeNames [column]
 
     def SetElementValue (self, row, column, value):
         item = self.blockItem.contents[row]
@@ -334,6 +333,8 @@
 class wxTableData(wx.grid.PyGridTableBase):
     def __init__(self, *arguments, **keywords):
         super (wxTableData, self).__init__ (*arguments, **keywords)
+        self.defaultAttribute = wx.grid.GridCellAttr()
+        self.defaultAttribute.SetReadOnly (True)
 
     def GetNumberRows (self):
         """
@@ -369,6 +370,13 @@
     def GetTypeName (self, row, column):
         return self.GetView().GetElementType (row, column)
 
+    def GetAttr (self, row, column, kind):
+        attribute = self.base_GetAttr (row, column, kind)
+        if not attribute and self.GetTypeName (row, column) == "_default":
+            attribute = self.defaultAttribute
+            attribute.IncRef()
+        return attribute
+        
 
 class wxTable(DropReceiveWidget, wx.grid.Grid):
     def __init__(self, *arguments, **keywords):
@@ -391,9 +399,10 @@
                         0-wx.SystemSettings_GetMetric(wx.SYS_HSCROLL_Y))
         self.SetCellHighlightPenWidth(0)
 
-        self.SetDefaultRenderer (ImageRenderer())
-        self.RegisterDataType ("image", ImageRenderer(), None);
-
+        self.SetDefaultRenderer (GridCellAttributeRenderer("_default"))
+        self.RegisterDataType ("String",
+                               GridCellAttributeRenderer("String"),
+                               GridCellAttributeEditor("String"))
         self.Bind(wx.EVT_SIZE, self.OnSize)
         self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.OnColumnDrag)
         self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnWXSelectionChanged)
@@ -412,6 +421,7 @@
         table before initializing it's view so GetView() returns none.
         """
         gridTable = wxTableData()
+
         self.currentRows = gridTable.GetNumberRows()
         self.currentColumns = gridTable.GetNumberCols()
 
@@ -535,63 +545,80 @@
                                  {'item':item})
 
 
-class AttributeRenderer (wx.grid.PyGridCellRenderer):
-    def Format (self, value):
-        theType = type (value)
-        
-        if theType == str:
-            return value
+class GridCellAttributeRenderer (wx.grid.PyGridCellRenderer):
+    def __init__(self, type):
+        super (GridCellAttributeRenderer, self).__init__ ()
+        self.delegate = AttributeEditor.GetAttributeEditor (type)
 
-        elif theType == type (DateTime.DateTime(0)):
-            return value.Format("%B %d, %Y    %I:%M %p")
-        
+    def SetTextColorsAndFont (self, grid, attr, dc, isSelected):
+        """
+          Set the text foreground, text background, brush and font into the dc
+        """
+        if grid.IsEnabled():
+            if isSelected:
+                dc.SetTextBackground (grid.GetSelectionBackground())
+                dc.SetTextForeground (grid.GetSelectionForeground())
+                dc.SetBrush (wx.Brush (grid.GetSelectionBackground(), wx.SOLID))
+            else:
+                dc.SetTextBackground (attr.GetBackgroundColour())
+                dc.SetTextForeground (attr.GetTextColour())
+                dc.SetBrush (wx.Brush (attr.GetBackgroundColour(), wx.SOLID))
         else:
-            result = ""
-            for piece in value:
-                result = result + ', ' + self.Format (piece)
-            return result
+            dc.SetTextBackground (wxSystemSettings_GetSystemColour(wxSYS_COLOUR_BTNFACE))
+            dc.SetTextForeground (wxSystemSettings_GetSystemColour(wxSYS_COLOUR_GRAYTEXT))
+            dc.SetBrush (wx.Brush (wxSystemSettings_GetSystemColour(wxSYS_COLOUR_BTNFACE), wxSOLID))
 
-    def Draw (self, grid, attr, dc, rect, row, col, isSelected):
+        dc.SetFont (attr.GetFont())
+
+    def Draw (self, grid, attr, dc, rect, row, column, isSelected):
         """
-          We have to set the clipping region on the grid's DC, otherwise
-          the text will draw outside the cell
+          Currently only handles left justified multiline text
+        """
+        self.SetTextColorsAndFont (grid, attr, dc, isSelected)
+        item, attributeName = grid.GetElementValue (row, column)
+        self.delegate.Draw (dc, rect, item, attributeName, isSelected)
+
 
-          SetTextColoursAndFont(grid, attr, dc, isSelected);
-      
-          grid.DrawTextRectangle(dc, grid.GetCellValue(row, col),
-                                 rect, hAlign, vAlign);
-        """
-        dc.SetClippingRect (rect)
-
-        value = grid.GetTable().GetValue (row, col)
-        formattedValue = self.Format (value)
-
-        dc.SetBackgroundMode(wx.SOLID)
-        dc.SetFont(wx.SWISS_FONT)
-
-        if isSelected:
-            dc.SetTextForeground (grid.GetSelectionForeground())
-            dc.SetTextBackground (grid.GetSelectionBackground())
-            dc.SetBrush (wx.Brush (grid.GetSelectionBackground(), wx.SOLID))
-            dc.SetPen (wx.Pen (grid.GetSelectionBackground(), 1, wx.SOLID))
+class GridCellAttributeEditor (wx.grid.PyGridCellEditor):
+    def __init__(self, type):
+        super (GridCellAttributeEditor, self).__init__ ()
+        self.delegate = AttributeEditor.GetAttributeEditor (type)
+
+    def Create (self, parent, id, evtHandler):
+        """
+          Create an edit control to edit the text
+        """
+        self.control = self.delegate.Create (parent, id)
+        self.SetControl (self.control)
+        if evtHandler:
+            self.control.PushEventHandler (evtHandler)
+
+    def PaintBackground (self, *arguments, **keywords):
+        """
+          background drawing is done by the edit control
+        """
+        pass
+
+    def BeginEdit (self, row,  column, grid):
+        item, attributeName = grid.GetElementValue (row, column)
+        self.initialValue = self.delegate.GetAttributeValue (item, attributeName)
+        self.delegate.BeginControlEdit (self.control, self.initialValue)
+
+    def EndEdit (self, row, column, grid):
+        value = self.delegate.GetControlValue (self.control)
+        if value == self.initialValue:
+            changed = False
         else:
-            dc.SetTextForeground (attr.GetTextColour())
-            dc.SetTextBackground (attr.GetBackgroundColour())
-            dc.SetBrush (wx.Brush (attr.GetBackgroundColour(), wx.SOLID))
-            dc.SetPen (wx.Pen (attr.GetBackgroundColour(), 1, wx.SOLID))
+            changed = True
+            grid.SetElementValue (row, column, value)
+        return changed
 
-        dc.DrawRectangleRect (rect)
-        dc.DrawText(formattedValue, (rect.x+1, rect.y+1))
+    def Reset (self):
+        self.delegate.SetControlValue (self.control, self.initialValue)
 
-        width, height = dc.GetTextExtent(formattedValue)
-        
-        if width > rect.width - 2:
-            width, height = dc.GetTextExtent("...")
-            x = rect.x + 1 + rect.width - 2 - width
-            dc.DrawRectangle ((x, rect.y + 1), (width + 1, height))
-            dc.DrawText ("...", (x, rect.y + 1))
+    def GetValue (self):
+        return self.delegate.GetControlValue (self.control)
 
-        dc.DestroyClippingRegion()
 
 class ImageRenderer (wx.grid.PyGridCellRenderer):
     def Draw (self, grid, attr, dc, rect, row, col, isSelected):

Index: chandler/parcels/osaf/views/main/SideBar.py
diff -u chandler/parcels/osaf/views/main/SideBar.py:1.16 chandler/parcels/osaf/views/main/SideBar.py:1.17
--- chandler/parcels/osaf/views/main/SideBar.py:1.16	Thu Jul 15 15:27:06 2004
+++ chandler/parcels/osaf/views/main/SideBar.py	Thu Aug 19 12:43:55 2004
@@ -1,5 +1,5 @@
-__version__ = "$Revision: 1.16 $"
-__date__ = "$Date: 2004/07/15 22:27:06 $"
+__version__ = "$Revision: 1.17 $"
+__date__ = "$Date: 2004/08/19 19:43:55 $"
 __copyright__ = "Copyright (c) 2003 Open Source Applications Foundation"
 __license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -14,12 +14,7 @@
             item = item.contents
         except AttributeError:
             pass
-        attributeName = self.blockItem.columnAttributeNames [column]
-        try:
-            value = item.getAttributeValue (attributeName)
-        except AttributeError:
-            value = "Unnamed"
-        return value
+        return item, self.blockItem.columnAttributeNames [column]
 
     def SetElementValue (self, row, column, value):
         view = self.blockItem.contents[row]

Index: chandler/parcels/osaf/framework/blocks/detail/parcel.xml
diff -u chandler/parcels/osaf/framework/blocks/detail/parcel.xml:1.19 chandler/parcels/osaf/framework/blocks/detail/parcel.xml:1.20
--- chandler/parcels/osaf/framework/blocks/detail/parcel.xml:1.19	Sat Aug 14 17:01:39 2004
+++ chandler/parcels/osaf/framework/blocks/detail/parcel.xml	Thu Aug 19 12:43:54 2004
@@ -1,13 +1,13 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
 
-<!-- $Revision: 1.19 $ -->
-<!-- $Date: 2004/08/15 00:01:39 $ -->
+<!-- $Revision: 1.20 $ -->
+<!-- $Date: 2004/08/19 19:43:54 $ -->
 <!-- Copyright (c) 2003-2004 Open Source Applications Foundation -->
 <!-- License: http://osafoundation.org/Chandler_0.1_license_terms.htm -->
 
 <core:Parcel describes="//parcels/osaf/framework/blocks/detail"
              itsName="detail"
-	         itemClass="osaf.framework.blocks.detail.Detail.DetailParcel"
+             itemClass="osaf.framework.blocks.detail.Detail.DetailParcel"
              xmlns="http://osafoundation.org/parcels/osaf/framework/blocks"
              xmlns:core="http://osafoundation.org/parcels/core"
              xmlns:blocks="http://osafoundation.org/parcels/osaf/framework/blocks"



More information about the Commits mailing list