]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/wx/lib/customtreectrl.py
removed contrib files from the scripts
[wxWidgets.git] / wxPython / wx / lib / customtreectrl.py
index 76f35017115fe4421dbbcf9b129adff8e1f14ff1..3b93746092aa900b36902706c823b0ed174f01b9 100644 (file)
@@ -3,7 +3,7 @@
 # Inspired By And Heavily Based On wxGenericTreeCtrl.
 #
 # Andrea Gavana, @ 17 May 2006
-# Latest Revision: 26 May 2006, 22.30 CET
+# Latest Revision: 01 Apr 2007, 22.30 CET
 #
 #
 # TODO List
@@ -134,8 +134,8 @@ CustomTreeCtrl has been tested on the following platforms:
   * Mac OS (Thanks to John Jackson).
 
 
-Latest Revision: Andrea Gavana @ 26 May 2006, 22.30 CET
-Version 0.8
+Latest Revision: Andrea Gavana @ 01 Apr 2007, 22.30 CET
+Version 1.0
 
 """
 
@@ -1736,7 +1736,7 @@ def EventFlagsToSelType(style, shiftDown=False, ctrlDown=False):
 class CustomTreeCtrl(wx.PyScrolledWindow):
 
     def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize,
-                 style=0, ctstyle=TR_DEFAULT_STYLE, validator=wx.DefaultValidator,
+                 style=TR_DEFAULT_STYLE, ctstyle=0, validator=wx.DefaultValidator,
                  name="CustomTreeCtrl"):
         """
         Default class constructor.
@@ -1749,9 +1749,8 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
 
         size: window size. If the default size (-1, -1) is specified then the window is sized appropriately.
 
-        style: the underlying wx.ScrolledWindow style
+        style: the underlying wx.ScrolledWindow style + CustomTreeCtrl window style. This can be one of:
         
-        ctstyle: CustomTreeCtrl window style. This can be one of:
             TR_NO_BUTTONS
             TR_HAS_BUTTONS                          # draw collapsed/expanded btns
             TR_NO_LINES                             # don't draw lines at all
@@ -1769,10 +1768,14 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             TR_AUTO_CHECK_PARENT                    # only meaningful for checkboxes
             TR_AUTO_TOGGLE_CHILD                    # only meaningful for checkboxes
 
+        ctstyle: kept for backward compatibility.
+        
         validator: window validator.
 
         name: window name.
         """
+
+        style = style | ctstyle
         
         self._current = self._key_current = self._anchor = self._select_me = None
         self._hasFocus = False
@@ -1790,7 +1793,9 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         btnshadow = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNSHADOW)
         self._hilightUnfocusedBrush = wx.Brush(btnshadow)
         r, g, b = btnshadow.Red(), btnshadow.Green(), btnshadow.Blue()
-        backcolour = ((r >> 1) - 20, (g >> 1) - 20, (b >> 1) - 20)
+        backcolour = (max((r >> 1) - 20, 0),
+                      max((g >> 1) - 20, 0),
+                      max((b >> 1) - 20, 0))
         backcolour = wx.Colour(backcolour[0], backcolour[1], backcolour[2])
         self._hilightUnfocusedBrush2 = wx.Brush(backcolour)
 
@@ -1871,14 +1876,14 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         self._itemWithWindow = []
         
         if wx.Platform == "__WXMAC__":
-            ctstyle &= ~TR_LINES_AT_ROOT
-            ctstyle |= TR_NO_LINES
+            style &= ~TR_LINES_AT_ROOT
+            style |= TR_NO_LINES
             
             platform, major, minor = wx.GetOsVersion()
             if major < 10:
-                ctstyle |= TR_ROW_LINES
+                style |= TR_ROW_LINES
 
-        self._windowStyle = ctstyle
+        self._windowStyle = style
 
         # Create the default check image list        
         self.SetImageListCheck(13, 13)
@@ -2368,7 +2373,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         return item.GetText()
     
 
-    def GetItemImage(self, item, which):
+    def GetItemImage(self, item, which=TreeItemIcon_Normal):
         """Returns the item image."""
 
         if not item:
@@ -3303,7 +3308,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         event = TreeEvent(wxEVT_TREE_DELETE_ITEM, self.GetId())
         event._item = item
         event.SetEventObject(self)
-        self.ProcessEvent(event)
+        self.GetEventHandler().ProcessEvent(event)
 
 
     def IsDescendantOf(self, parent, item):
@@ -3448,7 +3453,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         event._item = item
         event.SetEventObject(self)
 
-        if self.ProcessEvent(event) and not event.IsAllowed():
+        if self.GetEventHandler().ProcessEvent(event) and not event.IsAllowed():
             # cancelled by program
             return
     
@@ -3462,11 +3467,11 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             self.HideWindows()
             
         event.SetEventType(wxEVT_TREE_ITEM_EXPANDED)
-        self.ProcessEvent(event)
+        self.GetEventHandler().ProcessEvent(event)
 
 
-    def ExpandAll(self, item):
-        """Expands all the items."""
+    def ExpandAllChildren(self, item):
+        """Expands all the items children of the input item."""
 
         if not item:
             raise Exception("\nERROR: Invalid Tree Item. ")
@@ -3479,10 +3484,17 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         child, cookie = self.GetFirstChild(item)
         
         while child:
-            self.ExpandAll(child)
+            self.ExpandAllChildren(child)
             child, cookie = self.GetNextChild(item, cookie)
         
 
+    def ExpandAll(self):
+        """Expands all CustomTreeCtrl items."""
+
+        if self._anchor:
+            self.ExpandAllChildren(self._anchor)
+            
+
     def Collapse(self, item):
         """
         Collapse an item, sending a EVT_TREE_ITEM_COLLAPSING and
@@ -3501,7 +3513,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         event = TreeEvent(wxEVT_TREE_ITEM_COLLAPSING, self.GetId())
         event._item = item
         event.SetEventObject(self)
-        if self.ProcessEvent(event) and not event.IsAllowed():
+        if self.GetEventHandler().ProcessEvent(event) and not event.IsAllowed():
             # cancelled by program
             return
     
@@ -3515,7 +3527,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             self.HideWindows()
             
         event.SetEventType(wxEVT_TREE_ITEM_COLLAPSED)
-        self.ProcessEvent(event)
+        self.GetEventHandler().ProcessEvent(event)
 
 
     def CollapseAndReset(self, item):
@@ -3576,7 +3588,8 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         # the tree might not have the root item at all
         if rootItem:
             self.UnselectAllChildren(rootItem)
-        
+
+        self.Unselect()        
 
     # Recursive function !
     # To stop we must have crt_item<last_item
@@ -3956,21 +3969,22 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         self._imageListNormal = imageList
         self._ownsImageListNormal = False
         self._dirty = True
+        
         # Don't do any drawing if we're setting the list to NULL,
         # since we may be in the process of deleting the tree control.
         if imageList:
             self.CalculateLineHeight()
 
-        # We gray out the image list to use the grayed icons with disabled items
-        self._grayedImageList = wx.ImageList(16, 16, True, 0)
-        
-        for ii in xrange(imageList.GetImageCount()):
-            
-            bmp = imageList.GetBitmap(ii)
-            image = wx.ImageFromBitmap(bmp)
-            image = GrayOut(image)
-            newbmp = wx.BitmapFromImage(image)
-            self._grayedImageList.Add(newbmp)
+            # We gray out the image list to use the grayed icons with disabled items
+            sz = imageList.GetSize(0)
+            self._grayedImageList = wx.ImageList(sz[0], sz[1], True, 0)
+
+            for ii in xrange(imageList.GetImageCount()):
+                bmp = imageList.GetBitmap(ii)
+                image = wx.ImageFromBitmap(bmp)
+                image = GrayOut(image)
+                newbmp = wx.BitmapFromImage(image)
+                self._grayedImageList.Add(newbmp)
         
 
     def SetStateImageList(self, imageList):
@@ -4400,6 +4414,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         if wnd:
             wndx = wcheck + image_w + item.GetX() + text_w + 4
             xa, ya = self.CalcScrolledPosition((0, item.GetY()))
+            wndx += xa
             if not wnd.IsShown():
                 wnd.Show()
             if wnd.GetPosition() != (wndx, ya):
@@ -4438,7 +4453,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                     # draw line down to last child
                     origY += self.GetLineHeight(children[0])>>1
                     oldY += self.GetLineHeight(children[n-1])>>1
+                    oldPen = dc.GetPen()
+                    dc.SetPen(self._dottedPen)
                     dc.DrawLine(3, origY, 3, oldY)
+                    dc.SetPen(oldPen)
                 
             return y
         
@@ -5731,4 +5749,6 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         attr.font  = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
         return attr
 
+    GetClassDefaultAttributes = classmethod(GetClassDefaultAttributes)
 
+