Title: [commits] (pje) [16008] [APP] Move splitters, boxers, etc to ocap.wxui.layout module; get rid
Revision
16008
Author
pje
Date
2007-12-03 10:10:42 -0800 (Mon, 03 Dec 2007)

Log Message

[APP] Move splitters, boxers, etc to ocap.wxui.layout module; get rid
of specialized splitter subclasses by using a bridge.

Modified Paths

Added Paths

Diff

Modified: branches/rearchitecture/Chandler-Debugging/ocap/debugging/py_crust.py (16007 => 16008)

--- branches/rearchitecture/Chandler-Debugging/ocap/debugging/py_crust.py	2007-12-03 18:10:24 UTC (rev 16007)
+++ branches/rearchitecture/Chandler-Debugging/ocap/debugging/py_crust.py	2007-12-03 18:10:42 UTC (rev 16008)
@@ -4,8 +4,8 @@
 from ocap.debugging import Debugger
 from ocap import runtime
 import peak.events.trellis as trellis
+from ocap.wxui import layout
 
-
 def LaunchPyCrust(app):
     """Launch a PyCrust window, putting `app` in its locals"""
     from wx.py.crust import CrustFrame
@@ -31,90 +31,7 @@
 
 
 
-
-
-
-
-
-
-
-
-
-class Boxable(object):
-    """Mixin for something that can be added to a box sizer"""
-
-    __slots__ = ()
-
-    def addToSizer(self, other):
-        other.Add(self)
-
-    def __or__(self, other):
-        return Boxer() | self | other
-
-    def __div__(self, other):
-        return (Boxer(wx.VERTICAL) / self) / other
-
-
-class Space(wx.Size, Boxable):
-    """A space that's addable to a box sizer"""
-    
-
-class Boxer(wx.BoxSizer, Boxable):
-
-    def __or__(self, other):
-        if self.Orientation == wx.HORIZONTAL:
-            other.addToSizer(self)
-            return self
-        return super(Boxer, self).__or__(other)
-
-    def __div__(self, other):
-        if self.Orientation == wx.VERTICAL:
-            other.addToSizer(self)
-            return self
-        return super(Boxer, self).__div__(other)
-
-    def addToSizer(self, other):
-        if other.Orientation == self.Orientation:
-            for item in self.Children:
-                other.AddItem(item)
-        else:
-            super(Boxer, self).addToSizer(self)
-
-
-class ProportionalSplitter(wx.SplitterWindow, Boxable):
-    """A Proportionally-resizing wx.SplitterWindow"""
-
-    def __init__(self, *args, **kw):
-        super(ProportionalSplitter, self).__init__(*args, **kw)
-        self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGING, self.OnChanging)
-        self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.OnSashPositionChanged)
-
-    def OnChanging(self, evt):
-        self.changing = True
-
-    def OnSashPositionChanged(self, evt):
-        self.update_gravity(evt.SashPosition)
-        self.changing = False
-        return True
-
-    def get_size(self):
-        if self.SplitMode == wx.SPLIT_HORIZONTAL:
-            return self.Size.height - self.SashSize
-        else:
-            return self.Size.width - self.SashSize
-        
-    def update_gravity(self, position):        
-        self.SashGravity = float(position)/self.get_size()
-
-    def update_sash(self, gravity):
-        pos = self.SashPosition = int(gravity * self.get_size())
-        self.update_gravity(pos)
-
-    def addToSizer(self, other):
-        other.Add(self, 1, flag=wx.EXPAND)
-
-
-class Toolbar(wx.ToolBar, Boxable):
+class Toolbar(wx.ToolBar, layout.Boxable):
     """A boxable toolbar"""
 
     def addToSizer(self, other):
@@ -161,6 +78,8 @@
             if tool.ClientData == value:
                 self.widget.ToggleTool(tool.GetId(), True)
 
+
+
 class ActiveViewBridge(trellis.Component):
     trellis.values(
         widget = None,
@@ -179,7 +98,8 @@
                     child.Hide()
             self.widget.Thaw()
 
-class PreviewAndMinicalendarSizer(Boxer, trellis.Component):
+
+class PreviewAndMinicalendarSizer(layout.Boxer, trellis.Component):
     widgets = trellis.value(trellis.List())
     
     @trellis.rule
@@ -194,35 +114,54 @@
         self.widgets.append(widget)
         super(PreviewAndMinicalendarSizer, self).Add(widget, *args, **kwargs)
 
-# global cell for tracking changes in splitters
-changing_cell = trellis.Cell(value=False)
-class ChangeTrackingSplitter(ProportionalSplitter, trellis.Component):
-    changing = trellis.value(False)
-    def __init__(self, *args, **kw):
-        super(ChangeTrackingSplitter, self).__init__(*args, **kw)
-        self.changing = changing_cell
-        
 
-class BottomTrackingSplitter(ChangeTrackingSplitter):
 
-    bottom = trellis.value(None)
-    
-    def SplitHorizontally(self, top, bottom, *args, **kwargs):
-        self.bottom = bottom.Sizer
-        super(BottomTrackingSplitter, self).SplitHorizontally(
-            top, bottom, *args, **kwargs
-        )
-    
+
+
+
+
+
+class BottomAdjuster(trellis.Component):
+    trellis.values(
+        splitter = None,
+        track_splitters = (),
+        resizing = False,
+    )
+
+    @trellis.observer
+    def bindEvents(self):
+        # XXX is this even necessary?  Could we just bind these events at
+        # frame level?  Do we need the events at all?  Taking this out
+        # doesn't seem to break anything.
+        for s in self.track_splitters:
+            s.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGING, self.start_resizing)
+            s.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.end_resizing)
+
+    def start_resizing(self, evt):
+        self.resizing = True
+
+    def end_resizing(self, evt):
+        self.resizing = False
+        return True
+
     @trellis.rule
     def adjust_split(self):
-        if not self.changing:
-            bottom = self.bottom
-            height = self.Size.height
+        if not self.resizing:
+            splitter = self.splitter
+            bottom = splitter.Window2.Sizer
+            height = splitter.Size.height
             if (height > 0 and bottom is not None and 
                 bottom.height != bottom.ideal_height):
-                trellis.on_commit(self.update_sash, float(height - bottom.ideal_height) / height)
+                trellis.on_commit(
+                    splitter.update_sash,
+                    float(height - bottom.ideal_height) / height
+                )
 
 
+
+
+
+
 def ExampleFrame(app):
     """Create a demo frame, suitable for experimenting"""
     from ocap.chandler import (interaction, sidebar, minicalendar, preview,
@@ -249,8 +188,9 @@
     tbBridge.addAppTool("Calendar", 'ApplicationBarEvent.png', 'calendar')
     
     splitterStyle = wx.SP_LIVE_UPDATE | wx.NO_BORDER | wx.SP_3DSASH
-    main_splitter = ChangeTrackingSplitter(frame, style=splitterStyle)
-    child_splitter = BottomTrackingSplitter(main_splitter, style=splitterStyle)
+    
+    main_splitter = layout.ProportionalSplitter(frame, style=splitterStyle)
+    child_splitter = layout.ProportionalSplitter(main_splitter, style=splitterStyle)
 
     main_splitter.SetMinimumPaneSize(50)
     child_splitter.SetMinimumPaneSize(1) 
@@ -260,6 +200,9 @@
     sb = sidebar.SidebarPresentation(child_splitter, ia.sidebar,
                                      filter=app_cells['filter'])
 
+
+
+
     mc_and_preview = wx.Panel(child_splitter)
     mc = minicalendar.WXMiniCalendarPresentation(mc_and_preview, ia)
     preview = preview.WXPreviewAreaPresentation(mc_and_preview, ia)
@@ -291,8 +234,17 @@
 
     main_splitter.SplitVertically(child_splitter, main_view)
     child_splitter.SplitHorizontally(sb.GetView(), mc_and_preview)
+    child_splitter.bridge = BottomAdjuster(
+        splitter=child_splitter, track_splitters = (main_splitter, child_splitter)
+    )
 
-    frame.Sizer = (tb / Space(0, 4) / main_splitter)
+
+
+
+
+
+
+    frame.Sizer = (tb / layout.Space(0, 4) / main_splitter)
     frame.Sizer.Layout()
     main_splitter.Show()
     child_splitter.Show()
@@ -316,3 +268,20 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

Added: branches/rearchitecture/Chandler-Platform/ocap/wxui/layout.py (16007 => 16008)

--- branches/rearchitecture/Chandler-Platform/ocap/wxui/layout.py	2007-12-03 18:10:24 UTC (rev 16007)
+++ branches/rearchitecture/Chandler-Platform/ocap/wxui/layout.py	2007-12-03 18:10:42 UTC (rev 16008)
@@ -0,0 +1,116 @@
+import wx
+
+class Boxable(object):
+    """Mixin for something that can be added to a box sizer"""
+
+    __slots__ = ()
+
+    def addToSizer(self, other):
+        other.Add(self)
+
+    def __or__(self, other):
+        return Boxer() | self | other
+
+    def __div__(self, other):
+        return (Boxer(wx.VERTICAL) / self) / other
+
+
+class Space(wx.Size, Boxable):
+    """A space that's addable to a box sizer"""
+    
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+class Boxer(wx.BoxSizer, Boxable):
+
+    def __or__(self, other):
+        if self.Orientation == wx.HORIZONTAL:
+            other.addToSizer(self)
+            return self
+        return super(Boxer, self).__or__(other)
+
+    def __div__(self, other):
+        if self.Orientation == wx.VERTICAL:
+            other.addToSizer(self)
+            return self
+        return super(Boxer, self).__div__(other)
+
+    def addToSizer(self, other):
+        if other.Orientation == self.Orientation:
+            for item in self.Children:
+                other.AddItem(item)
+        else:
+            super(Boxer, self).addToSizer(self)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+class ProportionalSplitter(wx.SplitterWindow, Boxable):
+    """A Proportionally-resizing wx.SplitterWindow"""
+
+    def __init__(self, *args, **kw):
+        super(ProportionalSplitter, self).__init__(*args, **kw)
+        self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGING, self.OnChanging)
+        self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.OnSashPositionChanged)
+
+    def OnChanging(self, evt):
+        self.changing = True
+
+    def OnSashPositionChanged(self, evt):
+        self.update_gravity(evt.SashPosition)
+        self.changing = False
+        return True
+
+    def get_size(self):
+        if self.SplitMode == wx.SPLIT_HORIZONTAL:
+            return self.Size.height - self.SashSize
+        else:
+            return self.Size.width - self.SashSize
+        
+    def update_gravity(self, position):        
+        self.SashGravity = float(position)/self.get_size()
+
+    def update_sash(self, gravity):
+        pos = self.SashPosition = int(gravity * self.get_size())
+        self.update_gravity(pos)
+
+    def addToSizer(self, other):
+        other.Add(self, 1, flag=wx.EXPAND)
+
+
+
+
+
+
+
+
+
+
Property changes on: branches/rearchitecture/Chandler-Platform/ocap/wxui/layout.py
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native




_______________________________________________
Commits mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/commits

Reply via email to