]> git.saurik.com Git - wxWidgets.git/commitdiff
collapsing tool panels
authorRoman Rolinsky <rolinsky@femagsoft.com>
Fri, 16 Mar 2007 14:14:49 +0000 (14:14 +0000)
committerRoman Rolinsky <rolinsky@femagsoft.com>
Fri, 16 Mar 2007 14:14:49 +0000 (14:14 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44849 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

wxPython/wx/tools/XRCed/tools.py

index e0e3ac86d2e124527be049950215ec6b7f756596..45687f850adbb49ec88b0dc2d1b175e1a2822439 100644 (file)
@@ -87,11 +87,11 @@ class Tools(wx.Panel):
 
              (ID_NEW.UNKNOWN, images.getToolUnknownBitmap())]
             ]
+        self.boxes = {}
         for grp in groups:
             self.AddGroup(grp[0])
             for b in grp[1:]:
                 self.AddButton(b[0], b[1], g.pullDownMenu.createMap[b[0]])
-        self.SetAutoLayout(True)
         self.SetSizerAndFit(self.sizer)
         # Allow to be resized in vertical direction only
         self.SetSizeHints(self.GetSize()[0], -1)
@@ -114,13 +114,19 @@ class Tools(wx.Panel):
 
     def AddGroup(self, name):
         # Each group is inside box
-        box = wx.StaticBox(self, -1, name, style=wx.WANTS_CHARS)
+        id = wx.NewId()
+        box = wx.StaticBox(self, id, '[+] '+name, style=wx.WANTS_CHARS)
+        box.show = True
+        box.name = name
+        box.gnum = len(self.groups)
         box.SetFont(g.smallerFont())
+        box.Bind(wx.EVT_LEFT_DOWN, self.OnClickBox)
         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
         boxSizer.Add((0, 4))
+        self.boxes[id] = box
         self.curSizer = wx.GridSizer(0, 3)
         boxSizer.Add(self.curSizer)
-        self.sizer.Add(boxSizer, 0, wx.TOP | wx.LEFT | wx.RIGHT, 4)
+        self.sizer.Add(boxSizer, 0, wx.TOP | wx.LEFT | wx.RIGHT | wx.EXPAND, 4)
         self.groups.append((box,{}))
 
     # Enable/disable group
@@ -129,6 +135,12 @@ class Tools(wx.Panel):
         grp[0].Enable(enable)
         for b in grp[1].values(): b.Enable(enable)
 
+    # Show/hide group
+    def ShowGroup(self, gnum, show = True):
+        grp = self.groups[gnum]
+        grp[0].show = show
+        for b in grp[1].values(): b.Show(show)
+
     # Enable/disable group item
     def EnableGroupItem(self, gnum, id, enable = True):
         grp = self.groups[gnum]
@@ -140,6 +152,14 @@ class Tools(wx.Panel):
         for id in ids:
             grp[1][id].Enable(enable)
 
+    def OnClickBox(self, evt):
+        box = self.boxes[evt.GetId()]
+        # Collapse/restore static box, change label
+        self.ShowGroup(box.gnum, not box.show)
+        if box.show: box.SetLabel('[+] ' + box.name)
+        else: box.SetLabel('[-] ' + box.name)
+        self.Layout()
+
     # Process key events
     def OnKeyDown(self, evt):
         if evt.GetKeyCode() == wx.WXK_CONTROL: