- Revision
- 16022
- Author
- pje
- Date
- 2007-12-03 11:58:08 -0800 (Mon, 03 Dec 2007)
Log Message
[APP] Make the example frame a class, integrating the custom bridges and
moving another layout class out to ocap.wxui.layout.
moving another layout class out to ocap.wxui.layout.
Modified Paths
Diff
Modified: branches/rearchitecture/Chandler-Debugging/ocap/debugging/py_crust.py (16021 => 16022)
--- branches/rearchitecture/Chandler-Debugging/ocap/debugging/py_crust.py 2007-12-03 19:14:27 UTC (rev 16021) +++ branches/rearchitecture/Chandler-Debugging/ocap/debugging/py_crust.py 2007-12-03 19:58:08 UTC (rev 16022) @@ -10,7 +10,7 @@ """Launch a PyCrust window, putting `app` in its locals""" from wx.py.crust import CrustFrame frame = CrustFrame() - frame.Show(True) + frame.Show(True) # Link the PyCrust's locals to the debugger's variables from ocap.debugging import Debugger @@ -52,7 +52,7 @@ # self.cell = float(self.widget.GetValue()) def addAppTool(self, label, imageName, cellValue): from ocap.wxui.image import get_raw_image - + toolId = wx.NewId() tool = self.widget.AddRadioTool(toolId, wx.BitmapFromImage(get_raw_image(imageName)), @@ -61,10 +61,10 @@ # Eek, without the next two lines, wx doesn't draw # the labels on the unselected tools. Probably we are # not calling tb.Realize() at the right time [grant]. - self.widget.ToggleTool(toolId, True) - self.widget.ToggleTool(toolId, False) + #self.widget.ToggleTool(toolId, True) + #self.widget.ToggleTool(toolId, False) self.widget.Bind(wx.EVT_TOOL, self.OnToolEvent, id=toolId) - + def OnToolEvent(self, event): for tool in self.widget.ToolBarTools: if tool.GetId() == event.GetId(): @@ -80,39 +80,20 @@ -class ActiveViewBridge(trellis.Component): - trellis.values( - widget = None, - active_view = None - ) - - @trellis.observer - def changeActive(self): - if self.widget is not None: - self.widget.Freeze() - for child in self.widget.GetChildren(): - if child.Name == self.active_view: - child.SetSize(self.widget.GetSize()) - child.Show() - else: - child.Hide() - self.widget.Thaw() + @classmethod + def with_tools(cls, widget, cell, tools): + tb = cls(widget=widget, cell=cell) + for label, imageName, value in tools: + tb.addAppTool(label, imageName, value) + widget.Realize() + return tb -class PreviewAndMinicalendarSizer(layout.Boxer, trellis.Component): - widgets = trellis.value(trellis.List()) - - @trellis.rule - def ideal_height(self): - return sum(widget.ideal_height for widget in self.widgets) +def set_widget(widget, **kw): + for k, v in kw.iteritems(): + setattr(widget, k, v) + return widget - @trellis.rule - def height(self): - return sum(widget.height for widget in self.widgets) - - def Add(self, widget, *args, **kwargs): - self.widgets.append(widget) - super(PreviewAndMinicalendarSizer, self).Add(widget, *args, **kwargs) @@ -121,151 +102,169 @@ -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.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( - 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, - summary, calendar_main) - frame = wx.Frame(parent=None, title='Example', size=(700, 685)) - frame.MenuBar = wx.MenuBar() - frame.MenuBar.Append(wx.Menu(), "&File") - frame.CreateStatusBar() - frame.BackgroundColour = (212, 208, 200, 255) - tb = Toolbar(frame, - style = wx.TB_FLAT|wx.TB_TEXT|wx.TB_HORIZONTAL|wx.TB_MAC_NATIVE_SELECT - ) - tb.SetToolBitmapSize((32,32)) - tb.SetToolSeparation(20) - ia = interaction.Application() - app_cells = trellis.Cells(ia) - tbBridge = ToolbarBridge(widget=tb, cell=app_cells['filter']) - tbBridge.addAppTool("All", 'ApplicationBarAll.png', None) - tbBridge.addAppTool("Mail", 'ApplicationBarMail.png', 'mail') - tbBridge.addAppTool("Tasks", 'ApplicationBarTask.png', 'tasks') - tbBridge.addAppTool("Calendar", 'ApplicationBarEvent.png', 'calendar') - - splitterStyle = wx.SP_LIVE_UPDATE | wx.NO_BORDER | wx.SP_3DSASH - - main_splitter = layout.ProportionalSplitter(frame, style=splitterStyle) - child_splitter = layout.ProportionalSplitter(main_splitter, style=splitterStyle) - main_splitter.SetMinimumPaneSize(50) - child_splitter.SetMinimumPaneSize(1) - tb.Realize() - sb = sidebar.SidebarPresentation(child_splitter, ia.sidebar, - filter=app_cells['filter']) +class BrowsingFrame(trellis.Component): + trellis.rules( + splitterStyle = lambda self: ( + wx.SP_LIVE_UPDATE | wx.NO_BORDER | wx.SP_3DSASH + ), + frame = lambda self: set_widget( + wx.Frame(parent=None, title='Example', size=(700, 685)), + MenuBar = self.menu_bar, BackgroundColour=(212, 208, 200, 255), + ), + main_splitter = lambda self: set_widget( + layout.ProportionalSplitter(self.frame, style=self.splitterStyle), + MinimumPaneSize = 50 + ), + child_splitter = lambda self: set_widget( + layout.ProportionalSplitter( + self.main_splitter, style=self.splitterStyle + ), + MinimumPaneSize = 1 + ), + toolbar = lambda self: set_widget( + Toolbar(self.frame, style = wx.TB_FLAT|wx.TB_TEXT|wx.TB_HORIZONTAL + | wx.TB_MAC_NATIVE_SELECT), + ToolBitmapSize = (32,32), ToolSeparation = 20 + ), + tb_bridge = lambda self: ToolbarBridge.with_tools( + self.toolbar, trellis.Cells(self.app)['filter'], [ + ("All", 'ApplicationBarAll.png', None), + ("Mail", 'ApplicationBarMail.png', 'mail'), + ("Tasks", 'ApplicationBarTask.png', 'tasks'), + ("Calendar", 'ApplicationBarEvent.png', 'calendar'), + ] + ), + main_view = lambda self: set_widget( + wx.Panel(self.main_splitter), + BackgroundColour=wx.WHITE, Sizer=wx.BoxSizer() + ), + ) - mc_and_preview = wx.Panel(child_splitter) - mc = minicalendar.WXMiniCalendarPresentation(mc_and_preview, ia) - preview = preview.WXPreviewAreaPresentation(mc_and_preview, ia) - mc_sizer = PreviewAndMinicalendarSizer(wx.VERTICAL) - mc_sizer.Add(preview, 0, flag=wx.EXPAND) - mc_sizer.Add(mc, 1, flag=wx.EXPAND) - mc_and_preview.SetSizerAndFit(mc_sizer) - main_view = wx.Panel(main_splitter) - main_view.SetBackgroundColour(wx.WHITE) - main_view.Sizer = wx.BoxSizer() - - sum = summary.SummaryPresentation(main_view, ia.sidebar[0].items) - sum.View.Name = 'list' - cal = calendar_main.CalendarPresentation(main_view, - many_days=ia.all_days, - range_start=app_cells['selected_date'], - range_mode=app_cells['range_mode'], - ) - - main_view.Sizer.Add(sum.View, 1, flag=wx.EXPAND) - main_view.Sizer.Add(cal.widget, 1, flag=wx.EXPAND) - - avBridge = ActiveViewBridge(widget=main_view, - active_view=app_cells['active_view']) - # keep the bridges around so they don't get garbage collected - bridges = {'ActiveView' : avBridge, 'Toolbar' : tbBridge} - 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) - ) + @trellis.rule + def menu_bar(self): + mb = wx.MenuBar() + mb.Append(wx.Menu(), "&File") + return mb + app = trellis.value(None) + @trellis.observer + def changeActiveView(self): + self.main_view.Freeze() + for child in self.main_view.GetChildren(): + if child.Name == self.app.active_view: + child.SetSize(self.main_view.GetSize()) + child.Show() + else: + child.Hide() + self.main_view.Sizer.Layout() + self.main_view.Thaw() + trellis.values( + app = None, + 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 (and the + # start/end methods) doesn't seem to break anything. + for s in (self.main_splitter, self.child_splitter): + 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 - frame.Sizer = (tb / layout.Space(0, 4) / main_splitter) - frame.Sizer.Layout() - main_splitter.Show() - child_splitter.Show() - tb.Realize() - frame.Show() - main_splitter.update_sash(.24) # ugh - child_splitter.update_sash(.5) - Debugger(app).variables.update( - frame = frame, - splitter = main_splitter, sidebar=sb, summary=sum, bridges=bridges - ) - #from wx.lib.inspection import InspectionTool - #InspectionTool().Show() + @trellis.rule + def adjust_split(self): + if not self.resizing: + splitter = self.child_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( + splitter.update_sash, + float(height - bottom.ideal_height) / height + ) + def __init__(self, app): + from ocap.chandler import (interaction, sidebar, minicalendar, preview, + summary, calendar_main) + self.app = interaction.Application() + self.frame.CreateStatusBar() + app_cells = trellis.Cells(self.app) + sb = sidebar.SidebarPresentation(self.child_splitter, self.app.sidebar, + filter=app_cells['filter']) + mc_and_preview = wx.Panel(self.child_splitter) + mc = minicalendar.WXMiniCalendarPresentation(mc_and_preview, self.app) + preview = preview.WXPreviewAreaPresentation(mc_and_preview, self.app) + mc_sizer = layout.AutoSizingBoxer(wx.VERTICAL) + mc_sizer.Add(preview, 0, flag=wx.EXPAND) + mc_sizer.Add(mc, 1, flag=wx.EXPAND) + mc_and_preview.SetSizerAndFit(mc_sizer) + sum = summary.SummaryPresentation(self.main_view, self.app.sidebar[0].items) + sum.View.Name = 'list' + cal = calendar_main.CalendarPresentation(self.main_view, + many_days=self.app.all_days, + range_start=app_cells['selected_date'], + range_mode=app_cells['range_mode'], + ) + self.main_view.Sizer.Add(sum.View, 1, flag=wx.EXPAND) + self.main_view.Sizer.Add(cal.widget, 1, flag=wx.EXPAND) + self.main_splitter.SplitVertically(self.child_splitter, self.main_view) + self.child_splitter.SplitHorizontally(sb.GetView(), mc_and_preview) + self.frame.Sizer = ( + self.toolbar / layout.Space(0, 4) / self.main_splitter + ) + self.frame.Sizer.Layout() + self.main_splitter.Show() + self.child_splitter.Show() + self.frame.Show() + self.main_splitter.update_sash(.24) # ugh + self.child_splitter.update_sash(.5) + #from wx.lib.inspection import InspectionTool + #InspectionTool().Show() + #Debugger(app).variables.update( + # frame = self.frame, + # splitter = self.main_splitter, sidebar=sb, summary=sum + #) +ExampleFrame = BrowsingFrame @@ -285,3 +284,4 @@ +
Modified: branches/rearchitecture/Chandler-Platform/ocap/wxui/layout.py (16021 => 16022)
--- branches/rearchitecture/Chandler-Platform/ocap/wxui/layout.py 2007-12-03 19:14:27 UTC (rev 16021) +++ branches/rearchitecture/Chandler-Platform/ocap/wxui/layout.py 2007-12-03 19:58:08 UTC (rev 16022) @@ -1,5 +1,10 @@ import wx +from peak.events import trellis +__all__ = [ + 'Boxable', 'Space', 'Boxer', 'AutoSizingBoxer', 'ProportionalSplitter', +] + class Boxable(object): """Mixin for something that can be added to a box sizer""" @@ -34,11 +39,6 @@ - - - - - class Boxer(wx.BoxSizer, Boxable): def __or__(self, other): @@ -61,18 +61,25 @@ super(Boxer, self).addToSizer(self) +class AutoSizingBoxer(Boxer, trellis.Component): + widgets = trellis.value(trellis.List()) + @trellis.rule + def ideal_height(self): + return sum(widget.ideal_height for widget in self.widgets) + @trellis.rule + def height(self): + return sum(widget.height for widget in self.widgets) + def Add(self, widget, *args, **kwargs): + self.widgets.append(widget) + super(AutoSizingBoxer, self).Add(widget, *args, **kwargs) - - - - class ProportionalSplitter(wx.SplitterWindow, Boxable): """A Proportionally-resizing wx.SplitterWindow"""
_______________________________________________ Commits mailing list [email protected] http://lists.osafoundation.org/mailman/listinfo/commits
