All pastes #819529 Raw Edit

Stormy

public python v1 · immutable
·published 2007-12-17 00:58 UTC
rendered paste body
#!/usr/bin/pythonimport wximport timeimport threadingID_set_button = 1ID_zero_pump = 2ID_zero_totals = 3ID_nozel1 = 4ID_nozel2 = 5ID_set_text = 6ID_set_spin = 7ID_text_pump_status = 8ID_text_pump_petrol = 9ID_text_pump_price = 10ID_text_totals_petrol = 11ID_text_totals_takings = 12pump_petrol = 0runthread = 0class Monitor(threading.Thread):	def run(self):		print runthread    		while runthread:    			print "lol"    			sleep(1)     		print "thread finsihed"class MyFrame(wx.Frame):	def __init__(self, parent, id, title):		wx.Frame.__init__(self, parent, id, title)		menubar = wx.MenuBar()		file = wx.Menu()		file.Append(22, '&Quit', 'Exit')		menubar.Append(file, '&File')		self.SetMenuBar(menubar)				heading = wx.Font(9, wx.NORMAL, wx.NORMAL, wx.BOLD)				#--- TOP LEFT CONTENT ---------------------------------------------------				self.text_pump_status = wx.StaticText(self, ID_text_pump_status , "Ready");		self.text_pump_petrol = wx.StaticText(self, ID_text_pump_petrol , "00.0 litres")		self.text_pump_price  = wx.StaticText(self, ID_text_pump_price , "0000.00")		self.text_totals_petrol  = wx.StaticText(self, ID_text_totals_petrol , "00.0 litres")		self.text_totals_takings = wx.StaticText(self, ID_text_totals_takings , "0000.00")		a1cont = [		wx.StaticText(self, -1, "Pump details"),		wx.StaticText(self, -1, ""),		wx.StaticText(self, -1, "  Status:"),		self.text_pump_status,		wx.StaticText(self, -1, "  Petrol dispensed:"),		self.text_pump_petrol,		wx.StaticText(self, -1, "  Price:"),		self.text_pump_price,		wx.StaticText(self, -1, "Today's totals"),		wx.StaticText(self, -1, ""),		wx.StaticText(self, -1, "  Petrol:"),		self.text_totals_petrol,		wx.StaticText(self, -1, "  Takings:"),		self.text_totals_takings		]		#--- BOTTOM LEFT CONTENT ------------------------------------------------				buttonset = wx.Button(self, ID_set_button, "set",style=wx.EXPAND)		buttonset.SetMinSize((40, 26)) 		b1acont = [		wx.StaticText(self, -1, "Pence per litre:",style=wx.EXPAND),		wx.TextCtrl(self, ID_set_text, "000.00",style=wx.EXPAND),		wx.SpinButton(self, ID_set_spin,style=wx.EXPAND),		buttonset		]		b1bcont = [		wx.Button(self, ID_zero_pump, "Zero pump",style=wx.EXPAND),		wx.Button(self, ID_zero_totals, "Zero today's totals",style=wx.EXPAND)		]				#--- TOP RIGHT CONTENT --------------------------------------------------		c1cont = [		wx.StaticText(self, -1, "  Amount to pay:"),		wx.StaticText(self, -1, "000.00"),		wx.StaticText(self, -1, "  Litres"),		wx.StaticText(self, -1, "00.0"),		wx.StaticText(self, -1, "  Pence per litre"),		wx.StaticText(self, -1, "000.00")		]		#--- BOTTOM RIGHT CONTENT -----------------------------------------------		self.d1b1 = wx.ToggleButton(self, ID_nozel1, 'Take nozel',style=wx.EXPAND)		self.d1b1.SetMinSize((128,32));		self.d1b2 = wx.ToggleButton(self, ID_nozel2, "Squeese",style=wx.EXPAND)		self.d1b2.SetMinSize((128,32)); 				d1cont = [self.d1b1,self.d1b2]								#--- MAIN LAYOUT --------------------------------------------------------				# Set up root sizer		sizer0 = wx.GridSizer(2, 2, 0, 8)				# Set up quadrants		temp = wx.StaticBox( self, id, "Console display" )		temp.SetFont(heading)		sizera = wx.StaticBoxSizer( temp, wx.VERTICAL )				temp = wx.StaticBox( self, id, "Console controls" )		temp.SetFont(heading)		sizerb = wx.StaticBoxSizer( temp, wx.VERTICAL )				temp = wx.StaticBox( self, id, "Pump display" )		temp.SetFont(heading)		sizerc = wx.StaticBoxSizer( temp, wx.VERTICAL )				temp = wx.StaticBox( self, id, "Pump controls" )		temp.SetFont(heading)		sizerd = wx.StaticBoxSizer( temp, wx.VERTICAL )						#Set up lower-level sizers		sizera1 = wx.GridSizer(9, 2, 3, 3)		sizerb1 = wx.BoxSizer(wx.VERTICAL)		sizerb1a = wx.BoxSizer(wx.HORIZONTAL)		sizerb1b = wx.BoxSizer(wx.HORIZONTAL)		sizerc1 = wx.GridSizer(3, 2, 3, 3)		sizerd1 = wx.BoxSizer(wx.HORIZONTAL)				#Add content to lower-level sizers		sizera1.AddMany(a1cont)		sizerb1.AddMany([sizerb1a, (sizerb1b,0,wx.ALIGN_CENTER_HORIZONTAL)])		sizerb1a.AddMany(b1acont)		sizerb1b.AddMany(b1bcont)		sizerc1.AddMany(c1cont)		sizerd1.AddMany(d1cont)				#Add lower-level sizers to quadrants		sizera.Add(sizera1)		sizerb.Add(sizerb1, flag=wx.EXPAND)		sizerc.Add(sizerc1)		sizerd.Add(sizerd1, flag=wx.ALIGN_CENTER_HORIZONTAL)				#Add quadrants to root sizer		sizer0.Add(sizera, flag=wx.EXPAND)		sizer0.Add(sizerc, flag=wx.EXPAND )		sizer0.Add(sizerb, flag=wx.EXPAND )		sizer0.Add(sizerd, flag=wx.EXPAND )		#label_1 = wx.StaticText(self, -1, "label_1")		#label_2 = wx.StaticText(self, -1, "label_2")		#label_3 = wx.StaticText(self, -1, "label_3")		#label_4 = wx.StaticText(self, -1, "label_4")						#sizer0.Add(label_2, 0, 0, 0)		#sizer0Monitor.start().Add(label_3, 0, 0, 0)		#sizer0.Add(label_4, 0, 0, 0)										self.SetSize((528, 350))		self.SetSizer(sizer0)		self.Centre()				#--- SETUP EVENT HANDLERS -----------------------------------------------		self.Bind(wx.EVT_BUTTON, self.OnSet, id=ID_set_button)		self.Bind(wx.EVT_BUTTON, self.OnSetSpin, id=ID_set_spin)		self.Bind(wx.EVT_BUTTON, self.OnZeroPump, id=ID_zero_pump)		self.Bind(wx.EVT_BUTTON, self.OnZeroTotals, id=ID_zero_totals)		self.Bind(wx.EVT_TOGGLEBUTTON, self.OnNozel1, id=ID_nozel1)		self.Bind(wx.EVT_TOGGLEBUTTON, self.OnNozel2, id=ID_nozel2)	def OnSet(self, event):		print "onSet"	def OnSetSpin(self, event):		print "onSetSpin"	def OnZeroPump(self, event):		print "onZeroPump"	def OnZeroTotals(self, event):		print "onZeroTotals"	def OnNozel1(self, event):		if self.text_pump_status.GetLabel() == "In Use":			if pump_petrol == 0:				self.text_pump_status.SetLabel("Ready")			else:				self.text_pump_status.SetLabel("Out of Use")		else:			self.text_pump_status.SetLabel("In Use")					def OnNozel2(self, event):		#if self.d1b2.GetValue:			#print "started"			#runthread = 1			#print runthread			#thread = Monitor()			#thread.start()			#print "fin"		#else:			#print "set to zero"			#runthread = 0		if runthread:			runthread=0			print "set to 0"		else:			runthread=1			print "set to 1"		class MyApp(wx.App):	def OnInit(self):		frame = MyFrame(None, -1, 'Petrol')		frame.Show(True)		return Trueapp = MyApp(0)app.MainLoop()