Share Pastebin
Guest
Public paste!

mlk

By: a guest | Sep 28th, 2008 | Syntax: Python | Size: 1.24 KB | Hits: 276 | Expires: Never
Copy text to clipboard
  1. from peak.events.trellis import *
  2.  
  3. class Counter(Component):
  4.     value = attr(0)
  5.  
  6.     @perform
  7.     def show(self):
  8.         print 'VALUE:', self.value
  9.  
  10. class UIModel(Component):
  11.     counter = attr()
  12.     clicked = attr(resetting_to=False)
  13.  
  14.     @maintain
  15.     def inc(self):
  16.         if self.clicked:
  17.             self.counter.value += 1
  18.  
  19.  
  20. ######################################################
  21. ######################################################
  22.  
  23. class Controller(Component):
  24.     ui = attr()
  25.     title = attr()
  26.  
  27.     def __init__(self, **kw):
  28.         Component.__init__(self, **kw)
  29.         import wx
  30.         self.app = wx.PySimpleApp()
  31.         self.frame = wx.Frame(None)
  32.         self.button = wx.Button(self.frame, label="Increase")
  33.         self.button.Bind(wx.EVT_BUTTON, self.on_click)
  34.         self.frame.Show()
  35.  
  36.     def run(self):
  37.         self.app.MainLoop()
  38.  
  39.     def on_click(self, evt):
  40.         self.ui.clicked = True
  41.  
  42.     @perform
  43.     def set_title(self):
  44.         self.frame.Title = unicode(self.title)
  45.  
  46. ######################################################
  47. ######################################################
  48.  
  49. c = Counter()
  50. ui = UIModel(counter=c)
  51. ctrl = Controller(ui=ui, title=c.__cells__['value'])
  52. ctrl.run()