Attachment 'metronome0.py'

Download

   1 import wx
   2 
   3 mspm = 60*1000 # milliseconds per minute
   4 
   5 class MFrame(wx.Frame):
   6     def __init__(self,):
   7         wx.Frame.__init__(self,None)
   8         #define the components
   9         self.go = wx.Button(self,wx.ID_ANY,"Start")
  10         self.stop = wx.Button(self,wx.ID_ANY,"Stop")
  11         self.bpm = wx.SpinCtrl(self,wx.ID_ANY,value="120",min=0,max=240)
  12 
  13         #do the layout
  14         sizer = wx.BoxSizer(wx.VERTICAL)
  15         sizer.Add(wx.StaticText(self,wx.ID_ANY,"Set the beats per minute"))
  16         sizer.Add(self.bpm)
  17         sizer.Add(self.go)
  18         sizer.Add(self.stop)
  19         self.SetSizerAndFit(sizer)
  20         self.Layout()
  21         
  22         #Bind events
  23         self.Bind(wx.EVT_BUTTON,self.Start,self.go)
  24         self.Bind(wx.EVT_BUTTON,self.Stop,self.stop)
  25         self.Bind(wx.EVT_TIMER,self.Tick)
  26 
  27     def Start(self,evt):
  28         self.timer=wx.Timer(self)
  29         self.timer.Start(mspm/float(self.bpm.GetValue()))
  30         print "go!"
  31         self.go.Enable(False)
  32         self.stop.Enable(True)
  33 
  34     def Stop(self,evt):
  35         self.timer.Stop()
  36         print "stop!"
  37         del self.timer
  38         self.go.Enable(True)
  39         self.stop.Enable(False)
  40 
  41     def Tick(self,evt):
  42         print "tick",self.timer.GetInterval(),wx.GetElapsedTime()
  43         sound = wx.Sound('tick2.wav')
  44         sound.Play(wx.SOUND_ASYNC)
  45         wx.YieldIfNeeded()
  46         
  47 class TestApp(wx.App):
  48     def OnInit(self):
  49         mainframe = MFrame()
  50         self.SetTopWindow(mainframe)
  51         mainframe.Show()
  52         return 1
  53 
  54 
  55 app = TestApp(0)
  56 app.MainLoop()

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-10-04 09:16:02, 1.6 KB) [[attachment:metronome0.py]]
  • [get | view] (2009-10-04 09:16:02, 2.6 KB) [[attachment:metronome1.py]]
  • [get | view] (2009-10-04 09:16:02, 3.2 KB) [[attachment:metronome2.py]]
  • [get | view] (2009-10-04 09:16:02, 100.1 KB) [[attachment:metronomewavfiles.zip]]
  • [get | view] (2009-10-04 09:16:02, 5.0 KB) [[attachment:mnome0.png]]
  • [get | view] (2009-10-04 09:16:02, 6.7 KB) [[attachment:mnome1.png]]
  • [get | view] (2009-10-04 09:16:02, 7.6 KB) [[attachment:mnome2.png]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.