[Commits] (john) Hooked up TreeListControl

commits at osafoundation.org commits at osafoundation.org
Mon Jan 5 19:23:18 PST 2004


Commit by: john
Modified files:
osaf/chandler/Chandler/parcels/OSAF/framework/blocks/MenuBlocks.py 1.2 1.3
osaf/chandler/Chandler/parcels/OSAF/framework/blocks/Controller.py 1.4 1.5
osaf/chandler/Chandler/parcels/OSAF/framework/blocks/ContainerBlocks.py 1.20 1.21
osaf/chandler/Chandler/parcels/OSAF/framework/blocks/Block.py 1.11 1.12
osaf/chandler/Chandler/application/ApplicationNew.py 1.18 1.19

Log message:
Hooked up TreeListControl


ViewCVS links:
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/parcels/OSAF/framework/blocks/MenuBlocks.py.diff?r1=text&tr1=1.2&r2=text&tr2=1.3
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/parcels/OSAF/framework/blocks/Controller.py.diff?r1=text&tr1=1.4&r2=text&tr2=1.5
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/parcels/OSAF/framework/blocks/ContainerBlocks.py.diff?r1=text&tr1=1.20&r2=text&tr2=1.21
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/parcels/OSAF/framework/blocks/Block.py.diff?r1=text&tr1=1.11&r2=text&tr2=1.12
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/application/ApplicationNew.py.diff?r1=text&tr1=1.18&r2=text&tr2=1.19

Index: osaf/chandler/Chandler/parcels/OSAF/framework/blocks/MenuBlocks.py
diff -u osaf/chandler/Chandler/parcels/OSAF/framework/blocks/MenuBlocks.py:1.2 osaf/chandler/Chandler/parcels/OSAF/framework/blocks/MenuBlocks.py:1.3
--- osaf/chandler/Chandler/parcels/OSAF/framework/blocks/MenuBlocks.py:1.2	Fri Jan  2 17:17:37 2004
+++ osaf/chandler/Chandler/parcels/OSAF/framework/blocks/MenuBlocks.py	Mon Jan  5 19:23:16 2004
@@ -222,7 +222,7 @@
             nor can we use wxWindows api's to distinguish them from each other.
             """
             assert self.hasAttributeValue('event')
-            id = self.event.getwxID()
+            id = Block.getwxID(self.event)
             if self.menuItemKind == "Normal":
                 kind = wxITEM_NORMAL
             elif self.menuItemKind == "Check":

Index: osaf/chandler/Chandler/parcels/OSAF/framework/blocks/Block.py
diff -u osaf/chandler/Chandler/parcels/OSAF/framework/blocks/Block.py:1.11 osaf/chandler/Chandler/parcels/OSAF/framework/blocks/Block.py:1.12
--- osaf/chandler/Chandler/parcels/OSAF/framework/blocks/Block.py:1.11	Fri Jan  2 08:19:42 2004
+++ osaf/chandler/Chandler/parcels/OSAF/framework/blocks/Block.py	Mon Jan  5 19:23:16 2004
@@ -47,7 +47,7 @@
                 member (event)
             for child in block.childrenBlocks:
                 broadcast (child, methodName, event)
-            
+
         event = notification.data['event']
         """
           Find the controller for the window with the focus
@@ -105,43 +105,46 @@
                         return
             block = block.parentBlock
 
+    IdToUUID = []               # A list mapping Ids to UUIDS
+    UUIDtoIds = {}              # A dictionary mapping UUIDS to Ids
 
-class BlockEvent(Event):
-
-    commandIDs = []
     MINIMUM_WX_ID = 2500
     MAXIMUM_WX_ID = 4999
 
-
-    def wxIDToEvent (theClass, wxID):
+    def wxIDToObject (theClass, wxID):
         """
-          Given a wxWindows commandID, returns the corresponding
-        Chandler event object
+          Given a wxWindows Id, returns the corresponding Chandler block
         """
-        return Globals.repository.find (theClass.commandIDs [wxID - theClass.MINIMUM_WX_ID])
+        return Globals.repository.find (theClass.IdToUUID [wxID - theClass.MINIMUM_WX_ID])
  
-    wxIDToEvent = classmethod (wxIDToEvent)
+    wxIDToObject = classmethod (wxIDToObject)
     
 
-    def getwxID (self):
+    def getwxID (theClass, object):
         """
-          wxWindows needs a integer for a command id. Commands between
+          wxWindows needs a integer for a id. Commands between
         wxID_LOWEST and wxID_HIGHEST are reserved. wxPython doesn't export
         wxID_LOWEST and wxID_HIGHEST, which are 4999 and 5999 respectively.
         Passing -1 for an ID will allocate a new ID starting with 0. So
         I will use the range starting at 2500 for our events.
           I'll store the ID for an event in the association and the
         wxApplication keeps a list, named commandIDs with allows us to
-        look up the UUID of an event given it's ID
+        look up the UUID of a block given it's Id
         """
-        UUID = self.getUUID()
+        UUID = object.getUUID()
         try:
-            id = Globals.association [UUID]
+            id = Block.UUIDtoIds [UUID]
         except KeyError:
-            length = len (BlockEvent.commandIDs)
-            BlockEvent.commandIDs.append (UUID)
-            id = length + BlockEvent.MINIMUM_WX_ID
-            assert (id <= BlockEvent.MAXIMUM_WX_ID)
-            assert not Globals.association.has_key (UUID)
-            Globals.association [UUID] = id
+            length = len (Block.IdToUUID)
+            Block.IdToUUID.append (UUID)
+            id = length + Block.MINIMUM_WX_ID
+            assert (id <= Block.MAXIMUM_WX_ID)
+            assert not Block.UUIDtoIds.has_key (UUID)
+            Block.UUIDtoIds [UUID] = id
         return id
+    getwxID = classmethod (getwxID)
+
+    
+class BlockEvent(Event):
+    pass
+

Index: osaf/chandler/Chandler/parcels/OSAF/framework/blocks/Controller.py
diff -u osaf/chandler/Chandler/parcels/OSAF/framework/blocks/Controller.py:1.4 osaf/chandler/Chandler/parcels/OSAF/framework/blocks/Controller.py:1.5
--- osaf/chandler/Chandler/parcels/OSAF/framework/blocks/Controller.py:1.4	Wed Dec 17 13:14:38 2003
+++ osaf/chandler/Chandler/parcels/OSAF/framework/blocks/Controller.py	Mon Jan  5 19:23:16 2004
@@ -1,5 +1,6 @@
 
 from Block import Block
+from ContainerBlocks import *
 import application.Globals as Globals
 from wxPython.wx import *
 
@@ -21,3 +22,15 @@
     def on_chandler_Paste_UpdateUI (self, notification):
         notification.data ['Enable'] = False
 
+    def on_chandler_GetTreeListData (self, notification):
+        node = notification.data['node']
+        data = node.GetData()
+        if data:
+            if data == 'root':
+                for child in Globals.repository.getRoots():
+                    node.AddChildNode (child, child.getItemName(), child.hasChildren())
+            else:
+                for child in data.iterChildren(load=False):
+                    node.AddChildNode (child, child.getItemName(), child.hasChildren())
+        else:
+            node.AddRootNode ('root', '//', True)

Index: osaf/chandler/Chandler/application/ApplicationNew.py
diff -u osaf/chandler/Chandler/application/ApplicationNew.py:1.18 osaf/chandler/Chandler/application/ApplicationNew.py:1.19
--- osaf/chandler/Chandler/application/ApplicationNew.py:1.18	Mon Jan  5 18:14:27 2004
+++ osaf/chandler/Chandler/application/ApplicationNew.py	Mon Jan  5 19:23:17 2004
@@ -1,5 +1,5 @@
-__version__ = "$Revision: 1.18 $"
-__date__ = "$Date: 2004/01/06 02:14:27 $"
+__version__ = "$Revision: 1.19 $"
+__date__ = "$Date: 2004/01/06 03:23:17 $"
 __copyright__ = "Copyright (c) 2003 Open Source Applications Foundation"
 __license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -173,13 +173,13 @@
         from OSAF.framework.blocks.Block import Block
         
         topDocument = Globals.repository.find('//parcels/OSAF/templates/top/TopDocument')
+
         if topDocument:
             self.mainFrame = MainFrame()
             assert isinstance (topDocument, Block)
             Globals.topController = topDocument.findController()
             self.menuParent = None
             self.mainFrame.counterpartUUID = topDocument.getUUID()
-            topDocument.render (self.mainFrame, self.mainFrame)
 
             events = Globals.repository.find('//parcels/OSAF/framework/blocks/Events')
             names = []
@@ -190,6 +190,8 @@
                                                    Globals.topController.getUUID(),
                                                    Globals.topController.dispatchEvent)
 
+            topDocument.render (self.mainFrame, self.mainFrame)
+
             self.mainFrame.Show()
         return true                     #indicates we succeeded with initialization
 
@@ -200,13 +202,13 @@
         Our events have ids between MINIMUM_WX_ID and MAXIMUM_WX_ID
         """
         from OSAF.framework.blocks.Controller import Controller
-        from OSAF.framework.blocks.Block import BlockEvent
+        from OSAF.framework.blocks.Block import Block, BlockEvent
         from OSAF.framework.notifications.Notification import Notification
 
         wxID = event.GetId()
-        if wxID >= BlockEvent.MINIMUM_WX_ID and wxID <= BlockEvent.MAXIMUM_WX_ID:
+        if wxID >= Block.MINIMUM_WX_ID and wxID <= Block.MAXIMUM_WX_ID:
 
-            blockEvent = BlockEvent.wxIDToEvent (wxID)
+            blockEvent = Block.wxIDToObject (wxID)
             data = {'event':blockEvent}
             if event.GetEventType() == wxEVT_UPDATE_UI:
                 data ['type'] = 'UpdateUI'

Index: osaf/chandler/Chandler/parcels/OSAF/framework/blocks/ContainerBlocks.py
diff -u osaf/chandler/Chandler/parcels/OSAF/framework/blocks/ContainerBlocks.py:1.20 osaf/chandler/Chandler/parcels/OSAF/framework/blocks/ContainerBlocks.py:1.21
--- osaf/chandler/Chandler/parcels/OSAF/framework/blocks/ContainerBlocks.py:1.20	Mon Jan  5 18:14:26 2004
+++ osaf/chandler/Chandler/parcels/OSAF/framework/blocks/ContainerBlocks.py	Mon Jan  5 19:23:16 2004
@@ -2,6 +2,8 @@
 from Block import Block
 from wxPython.wx import *
 from wxPython.gizmos import *
+from OSAF.framework.notifications.Notification import Notification
+
 
 class Font(wxFont):
     def __init__(self, characterStyle):
@@ -83,6 +85,7 @@
             flag = wxALIGN_BOTTOM | wxALIGN_RIGHT
         return flag
 
+
     def Calculate_wxBorder (self):
         border = 0
         spacerRequired = False
@@ -103,6 +106,7 @@
         
         return int (border)
 
+
 class BoxContainer(RectContainer):
     def renderOneBlock (self, parent, parentWindow):
         if self.orientationEnum == 'Horizontal':
@@ -120,6 +124,12 @@
             parent.Add(sizer, 1, self.Calculate_wxFlag(), self.Calculate_wxBorder())
         return sizer, sizer, parentWindow
 
+ 
+class TabbedContainer(RectContainer):
+    def renderOneBlock (self, parent, parentWindow):
+        return None, None, None
+
+
 class Button(RectContainer):
     def renderOneBlock(self, parent, parentWindow):
 #        assert isinstance (parent, wxSizerPtr) #must be in a container
@@ -146,13 +156,10 @@
             parent.Add(button, int(self.stretchFactor), 
                        self.Calculate_wxFlag(), self.Calculate_wxBorder())
         return button, None, None
-        
+    
+
 class ComboBox(RectContainer):
     def renderOneBlock(self, parent, parentWindow):
-        id = 0
-        if self.hasAttributeValue ("itemSelected"):  # Repository bug/feature -- DJA
-            id = self.event.getwxID()
-
 #        assert isinstance (parent, wxSizerPtr) #must be in a container
         comboBox = wxComboBox(parentWindow, -1, self.selection, 
                               wxDefaultPosition,
@@ -163,6 +170,7 @@
                        self.Calculate_wxFlag(), self.Calculate_wxBorder())
         return comboBox, None, None
 
+    
 class EditText(RectContainer):
     def __init__(self, *arguments, **keywords):
         super (EditText, self).__init__ (*arguments, **keywords)
@@ -373,15 +381,71 @@
     def renderOneBlock (self, parent, parentWindow):
         return None, None, None
     
+class TreeNode:
+    def __init__(self, nodeId, treeList):
+        self.nodeId = nodeId
+        self.treeList = treeList
+
+
+    def AddChildNode (self, data, title, hasChildren):
+        childNodeId = self.treeList.AppendItem (self.nodeId,
+                                                title,
+                                                -1,
+                                                -1,
+                                                wxTreeItemData (data))
+        self.treeList.SetItemHasChildren (childNodeId, hasChildren)
+
+
+    def AddRootNode (self, data, title, hasChildren):
+        rootNodeId = self.treeList.AddRoot (title, -1, -1, wxTreeItemData (data))
+        self.treeList.SetItemHasChildren (rootNodeId, hasChildren)
+        #self.treeList.Expand (rootNodeId)
+
+                                             
+    def GetData (self):
+        if self.nodeId:
+            return self.treeList.GetPyData (self.nodeId)
+        else:
+            return None        
+
+
+class wxTreeList(wxTreeListCtrl):
+
+    def __init__(self, *arguments, **keywords):
+        wxTreeListCtrl.__init__ (self, *arguments, **keywords)
+        EVT_TREE_ITEM_EXPANDING(self, self.GetId(), self.OnExpanding)
+ 
+
+    def OnExpanding(self, event):
+        """
+          Load the items in the tree only when they are visible.
+        """
+        arguments = {'node':TreeNode (event.GetItem(), self),
+                     'event':Globals.repository.find('//parcels/OSAF/framework/blocks/Events/GetTreeListData'),
+                     'type':'Normal'}
+        notification = Notification('chandler/GetTreeListData', None, None)
+        notification.SetData(arguments)
+        Globals.notificationManager.PostNotification(notification)
+
+
 class TreeList(RectContainer):
     def renderOneBlock(self, parent, parentWindow):
-        treeList = wxTreeListCtrl(parentWindow)
+        treeList = wxTreeList(parentWindow, Block.getwxID(self))
         info = wxTreeListColumnInfo()
         for x in range(len(self.columnHeadings)):
             info.SetText(self.columnHeadings[x])
             info.SetWidth(self.columnWidths[x])
             treeList.AddColumnInfo(info)
-        
-        if isinstance (parent, wxSizerPtr):
-            parent.Add(treeList, 1, self.Calculate_wxFlag(), self.Calculate_wxBorder())
+
+        arguments = {'node':TreeNode (None, treeList),
+                     'event':Globals.repository.find('//parcels/OSAF/framework/blocks/Events/GetTreeListData'),
+                     'type':'Normal'}
+        notification = Notification("chandler/GetTreeListData", None, None)
+        notification.SetData(arguments)
+        Globals.notificationManager.PostNotification(notification)
+
+
+        parent.Add(treeList, 1, self.Calculate_wxFlag(), self.Calculate_wxBorder())
         return treeList, None, None
+
+



More information about the Commits mailing list