pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Python pastebin - collaborative debugging tool View Help


Posted by mlk on Sun 28 Sep 15:36
report abuse | download | new post

  1. from peak.events.trellis import *
  2. from peak.events.activity import *
  3. from time import time
  4.  
  5. class Progress(Component):
  6.     started = attr(False)
  7.     started_time = attr(None)
  8.     completed = attr(0)
  9.  
  10.     @compute
  11.     def time_passed(self):
  12.         if self.started_time:
  13.             bool(Time[0.1])
  14.             return (time() - self.started_time)
  15.  
  16.     @compute
  17.     def time_remaining(self):
  18.         if self.time_passed and self.completed:
  19.             return  self.time_passed * ((1 - self.completed) / self.completed)
  20.  
  21.     @maintain
  22.     def on_start(self):
  23.         if self.started:
  24.             self.started_time = time()
  25.  
  26.  
  27. ######################################################
  28. ######################################################
  29.  
  30.  
  31. import wx
  32.  
  33. class WxProgressWindow(Component):
  34.     progress = make(Progress)
  35.  
  36.     def __init__(self):
  37.         self.app = wx.PySimpleApp()
  38.         self.frame = wx.Frame(None)
  39.         self.pbar = wx.Gauge(self.frame, range=1000)
  40.         self.frame.Show()
  41.  
  42.     @perform
  43.     def on_progress(self):
  44.         self.pbar.Value = 1000 * self.progress.completed
  45.  
  46. class WxProgressWindowPlus(WxProgressWindow):
  47.     def __init__(self):
  48.         WxProgressWindow.__init__(self)
  49.         self.text = wx.StaticText(self.frame)
  50.         sz = self.frame.Sizer = wx.BoxSizer(orient=wx.VERTICAL)
  51.         sz.AddWindow(self.pbar, flag=wx.GROW)
  52.         sz.AddWindow(self.text, flag=wx.GROW)
  53.  
  54.     @perform
  55.     def on_progress_plus(self):
  56.         tp = self.progress.time_passed
  57.         tr = self.progress.time_remaining
  58.         if tp is None:
  59.             txt = "Not started"
  60.         else:
  61.             txt = "Seconds passed: %.1f" % tp
  62.             if tr:
  63.                 txt += "; Seconds remaining: %.1f" % tr
  64.         self.text.Label = txt
  65.         self.frame.Layout()
  66.  
  67.  
  68. ######################################################
  69. ######################################################
  70.  
  71. class SteadyIncrease(Component):
  72.     subject = make(int)
  73.     increment = attr(1)
  74.  
  75.     @task
  76.     def increase(self):
  77.         next = True
  78.         while True:
  79.             while not next:
  80.                 yield Pause
  81.             next = Time[1]
  82.             self.subject += self.increment
  83.  
  84. ######################################################
  85. ######################################################
  86.  
  87. win = WxProgressWindowPlus()
  88. win.progress.started = True
  89. #win.progress.completed = 0.5
  90.  
  91. EventLoop <<= WXEventLoop
  92.  
  93. autoinc = SteadyIncrease(subject=win.progress.__cells__['completed'], increment=0.1)
  94.  
  95. EventLoop.run()

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post