#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: new
#
# Created: 13/06/2012
# Copyright: (c) new 2012
# Licence: <your licence>
#-------------------------------------------------------------------------------
#!/usr/bin/env python
import wx
import os
import time
import threading
import sys
class Mainwindow(wx.Frame):
def __init__(self,parent,title):
wx.Frame.__init__(self,parent,title=title)
self.setupworker()
self.initialize()
def initialize(self):
sizer = wx.GridBagSizer()
self.entry = wx.TextCtrl(self,-1,value=u"Enter text here.")
sizer.Add(self.entry,(0,0),(1,1),wx.EXPAND)
self.Bind(wx.EVT_TEXT_ENTER, self.OnPressEnter, self.entry)
button = wx.Button(self,-1,label="Click me !")
sizer.Add(button, (0,1))
self.Bind(wx.EVT_BUTTON, self.OnButtonClick, button)
self.label = wx.StaticText(self,-1,label=u'Hello !')
self.label.SetBackgroundColour(wx.BLUE)
self.label.SetForegroundColour(wx.WHITE)
sizer.Add( self.label, (1,0),(1,2), wx.EXPAND )
startbutton = wx.Button(self,-1,label="Start worker")
sizer.Add(startbutton, (3,1))
self.Bind(wx.EVT_BUTTON, self.startworker, startbutton)
stopbutton = wx.Button(self,-1,label="Stop worker")
sizer.Add(stopbutton, (3,2))
self.Bind(wx.EVT_BUTTON, self.stopworker, stopbutton)
sizer.AddGrowableCol(0)
self.SetSizerAndFit(sizer)
self.Center()
self.Show(True)
def OnButtonClick(self,event):
print "You clicked the button !"
self.label.SetLabel(self.entry.GetValue()+"You clicked the button")
self.entry.SetFocus()
self.entry.SetSelection(-1,-1)
def OnPressEnter(self,event):
print "You pressed enter !"
self.label.SetLabel(self.entry.GetValue()+"You presses enter")
self.entry.SetFocus()
self.entry.SetSelection(-1,-1)
def onabout(self,event):
dlg = wx.MessageDialog(self,"A small text editor","about simple editor")
dlg.ShowModal()
dlg.Destroy
def onexit(self,event):
self.counter.stop()
self.Close(True)
def setupworker(self):
self.worker = counter()
self.worker.start()
def startworker(self,event):
self.worker.go()
def stopworker(self,event):
self.worker.stop()
class counter(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.running = False
self.counter = 0
def run(self):
while True:
time.sleep(.05)
while self.running:
self.counter += 1
print self.counter
time.sleep(5)
def go(self):
print "starting counter"
self.running = True
def stop(self):
print "stopping counter"
self.running = False
def getresults(self):
print self.counter
return self.counter
app = wx.App(False)
frame = Mainwindow(None,"Main window Title")
app.MainLoop()
sys.exit()