473,394 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Event handling across classes

Hi there, just wondering if i could have a pointer inthe right direction here...

Sorry about the massive code posting - is that a wrong thing to do?

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. from Initials import *
  4. import wx
  5. import os
  6. from Wizard import *
  7.  
  8. class MainFrame(wx.Frame):
  9.     def __init__(self, parent, title):
  10.         wx.Frame.__init__(self, parent, -1, title)
  11.  
  12.         icon = wx.Icon("icon.ico", wx.BITMAP_TYPE_ICO)
  13.         self.SetIcon(icon)
  14.  
  15.  
  16.         ### Create Main Panel & Sizer ###
  17.         self.mainPanel = wx.Panel(self)
  18.         self.mainPanel.SetBackgroundColour((225,245,255))
  19.         mainSizer = wx.BoxSizer(wx.VERTICAL)
  20.  
  21.  
  22.         ### Create Various Panels ###
  23.         titlePanel = TitlePanel(self.mainPanel, wx.HORIZONTAL)
  24.         controlPanel = ControlPanel(self.mainPanel, wx.HORIZONTAL)
  25.         actionPanel = ActionPanel(self.mainPanel, wx.HORIZONTAL)
  26.  
  27.         mainSizer.Add(titlePanel.panel, 2, wx.ALIGN_LEFT | wx.EXPAND | wx.ALL, 5)
  28.         mainSizer.Add(controlPanel.panel, 5, wx.EXPAND | wx.LEFT | wx.RIGHT, 5)
  29.         mainSizer.Add(actionPanel.panel, 2, wx.EXPAND | wx.ALL, 5)
  30.  
  31.         self.mainPanel.SetSizer(mainSizer)
  32.         mainSizer.Fit(self)                # Fit frame to neccessary size
  33.         mainSizer.SetSizeHints(self)       # Prevents frame from getting smaller than min.
  34.  
  35. ### NewPanel Class - All panels are derived from this class.
  36. ### Created with orientation information for sizer wx.HORIZONTAL or wx.VERTICAL
  37.  
  38. class NewPanel():
  39.     def __init__(self, parent, Orientation):
  40.         self.panel = wx.Panel(parent)
  41.         self.sizer = wx.BoxSizer(Orientation)
  42.  
  43.         self.AddItems()
  44.  
  45.         self.panel.SetSizer(self.sizer)
  46.         self.sizer.Fit(self.panel)                # Fit frame to neccessary size
  47.         self.sizer.SetSizeHints(self.panel)       # Prevents frame from getting smaller than min.
  48.  
  49. class TitlePanel(NewPanel):
  50.  
  51.     def AddItems(self):
  52.  
  53.         self.image = wx.Image("DPT.jpg", wx.BITMAP_TYPE_ANY)
  54.         self.bitmap = wx.StaticBitmap(self.panel, -1, wx.BitmapFromImage(self.image))
  55.  
  56.         self.label = wx.StaticText(self.panel, -1, "Sequence Driven Controller")
  57.         self.label.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, True))
  58.         self.label.SetForegroundColour('#00009F')
  59.  
  60.         self.currentTractor = wx.StaticText(self.panel, -1, "Current Tractor:\n"
  61.                                        "%s" %tractor)
  62.         self.currentTractor.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))
  63.         self.currentTractor.SetForegroundColour('#00009F')
  64.  
  65.         self.sizer.Add(self.bitmap, 1, wx.ALIGN_CENTER)
  66.         self.sizer.Add(self.label, 3, wx.ALIGN_CENTER | wx.LEFT, 15)
  67.         self.sizer.Add(self.currentTractor, 2, wx.ALIGN_CENTER)
  68.  
  69.  
  70. class ControlPanel(NewPanel):
  71.  
  72.     def AddItems(self):
  73.  
  74.         self.automaticPanel = AutomaticPanel(self.panel, wx.VERTICAL)
  75.         self.modePanel = ModePanel(self.panel, wx.VERTICAL)
  76.         self.manualPanel = ManualPanel(self.panel, wx.HORIZONTAL)        
  77.  
  78.         self.sizer.Add(self.automaticPanel.panel, 6, wx.EXPAND)
  79.         self.sizer.Add(self.modePanel.panel, 3, wx.EXPAND | wx.LEFT | wx.RIGHT, 5)
  80.         self.sizer.Add(self.manualPanel.panel, 5, wx.EXPAND)
  81.  
  82.  
  83. class AutomaticPanel(NewPanel):
  84.  
  85.     def AddItems(self):
  86.  
  87.         self.box = wx.StaticBox(self.panel, -1, 'Automatic Control')
  88.         self.box.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  89.         self.sizer = wx.StaticBoxSizer(self.box, wx.VERTICAL)
  90.  
  91.         self.directionPanel = DirectionPanel(self.panel, wx.HORIZONTAL)
  92.  
  93.         self.speedSlider = wx.Slider(self.panel, -1, 0, 0, 10,
  94.                                  style = wx.HORIZONTAL | wx.SL_AUTOTICKS)
  95.         self.speedSlider.SetTickFreq(1, 1)
  96.         self.panel.Bind(wx.EVT_SLIDER, self.OnSpeedSlider, self.speedSlider)
  97.  
  98.         self.judderPanel = JudderPanel(self.panel, wx.HORIZONTAL)
  99.  
  100.         self.sizer.Add(self.directionPanel.panel, 1, wx.ALIGN_CENTER | wx.EXPAND)
  101.         self.sizer.Add(self.speedSlider, 1, wx.ALIGN_CENTER | wx.EXPAND)
  102.         self.sizer.Add(self.judderPanel.panel, 1, wx.ALIGN_CENTER | wx.EXPAND)
  103.  
  104.     def OnSpeedSlider (self, event):
  105.         Speed = self.speedSlider.GetValue()
  106.         self.judderPanel.speedLabel.SetLabel("Speed = %d" % Speed)
  107.  
  108.  
  109. class DirectionPanel(NewPanel):
  110.  
  111.     def AddItems(self):
  112.  
  113.         self.forwardsRadio = wx.RadioButton(self.panel, -1, "Forwards")
  114.         self.stationaryRadio = wx.RadioButton(self.panel, -1, "Stationary")
  115.         self.backwardsRadio = wx.RadioButton(self.panel, -1, "Backwards")
  116.  
  117.         self.sizer.Add(self.forwardsRadio, 1, wx.EXPAND)
  118.         self.sizer.Add(self.stationaryRadio, 1, wx.EXPAND)
  119.         self.sizer.Add(self.backwardsRadio, 1, wx.EXPAND)
  120.  
  121.         self.stationaryRadio.SetValue(True)
  122.  
  123.  
  124. class JudderPanel(NewPanel):
  125.  
  126.     def AddItems(self):
  127.  
  128.         self.speedLabel = wx.StaticText(self.panel, -1, "Speed = %d" %Speed)
  129.         self.speedLabel.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  130.         self.speedLabel.SetForegroundColour('#00009F')
  131.  
  132.         self.judderToggle = wx.ToggleButton(self.panel, -1, "Judder")
  133.         self.panel.Bind(wx.EVT_TOGGLEBUTTON, self.OnJudderToggle, self.judderToggle)
  134.  
  135.         self.sizer.Add(self.speedLabel, 1, wx.ALIGN_CENTER | wx.LEFT, 15)    
  136.         self.sizer.Add(self.judderToggle, 1, wx.ALIGN_CENTER | wx.EXPAND | wx.ALL, 10)
  137.  
  138.     def OnJudderToggle(self, event):
  139.         pass
  140.  
  141. class ModePanel(NewPanel):
  142.  
  143.     def AddItems(self):
  144.  
  145.         self.box = wx.StaticBox(self.panel, -1, 'Mode')
  146.         self.box.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  147.         self.sizer = wx.StaticBoxSizer(self.box, wx.VERTICAL)
  148.  
  149.         self.automaticToggle = wx.ToggleButton(self.panel, -1, "Auto.")
  150.         self.automaticToggle.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  151.         self.panel.Bind(wx.EVT_TOGGLEBUTTON, self.OnAutomaticToggle, self.automaticToggle)
  152.  
  153.         self.manualToggle = wx.ToggleButton(self.panel, -1, "Man.")
  154.         self.manualToggle.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  155.         self.panel.Bind(wx.EVT_TOGGLEBUTTON, self.OnManualToggle, self.manualToggle)
  156.  
  157.         self.sizer.Add(self.automaticToggle, 1, wx.EXPAND | wx.ALL, 10)
  158.         self.sizer.Add(self.manualToggle, 1, wx.EXPAND | wx.ALL, 10)
  159.  
  160.     def OnAutomaticToggle(self, event):
  161.         pass
  162.  
  163.     def OnManualToggle(self, event):
  164.         pass
  165.  
  166.  
  167. class ManualPanel(NewPanel):
  168.  
  169.     def AddItems(self):
  170.  
  171.         self.box = wx.StaticBox(self.panel, -1, 'Manual Control')
  172.         self.box.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  173.         self.sizer = wx.StaticBoxSizer(self.box, wx.HORIZONTAL)
  174.  
  175.         self.bristlePanel = BristlePanel(self.panel, wx.VERTICAL)
  176.         self.cylinderPanel = CylinderPanel(self.panel, wx.VERTICAL)
  177.  
  178.         self.sizer.Add(self.bristlePanel.panel, 1, wx.EXPAND)
  179.         self.sizer.Add(self.cylinderPanel.panel, 1, wx.EXPAND)
  180.  
  181.  
  182. class BristlePanel(NewPanel):
  183.  
  184.     def AddItems(self):
  185.  
  186.         self.bristleCheckBox = []
  187.  
  188.         for x in range(0, Bristles):
  189.             self.bristleCheckBox.insert(x, (wx.CheckBox(self.panel, -1, "Bristle %d" % (x+1))))
  190.             self.sizer.Add(self.bristleCheckBox[x], 1, wx.ALIGN_CENTER_HORIZONTAL)        
  191.  
  192.  
  193. class CylinderPanel(NewPanel):
  194.  
  195.     def AddItems(self):
  196.  
  197.         self.cylinderCheckBox = []
  198.  
  199.         for x in range(0, Cylinders):
  200.             self.cylinderCheckBox.insert(x, (wx.CheckBox(self.panel, -1, "Cylinder %d" % (x+1))))
  201.             self.sizer.Add(self.cylinderCheckBox[x], 1, wx.ALIGN_CENTER_HORIZONTAL)
  202.  
  203.  
  204. class ActionPanel(NewPanel):
  205.  
  206.     def AddItems(self):
  207.  
  208.         self.goButton = wx.Button(self.panel, -1, "GO")
  209.         self.goButton.SetBackgroundColour('green')
  210.         self.goButton.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  211.  
  212.         self.stopButton = wx.Button(self.panel, -1, "STOP")
  213.         self.stopButton.SetBackgroundColour('red')
  214.         self.stopButton.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  215.         self.panel.Bind(wx.EVT_BUTTON, self.OnStopButton, self.stopButton)
  216.  
  217.         self.sizer.Add(self.goButton, 1, wx.EXPAND)
  218.         self.sizer.Add(self.stopButton, 1, wx.EXPAND)
  219.  
  220.     def OnGoButton(self, event):
  221.         pass
  222.  
  223.     def OnStopButton(self, event):
  224.         Speed = 0
  225. #        frame.mainPanel.controlPanel.automaticPanel.judderPanel.speedLabel.SetLabel("Speed = %d" % Speed)
  226.  
  227.  
  228. class wxPyApp(wx.App):
  229.     def OnInit(self):
  230.         frame = MainFrame(None, "DPT - Sequence Driven Controller")
  231.         self.SetTopWindow(frame)
  232.         frame.Show(True)
  233.         frame.Center(wx.BOTH)
  234.         return True
  235.  
  236. if __name__ == '__main__':          # Only runs if program is being executed, not imported
  237.     app = wxPyApp(redirect=True)
  238.     app.MainLoop()
  239.  
  240.  
  241.  

My problem is that i cannot figure out how to make the OnStopButton event change the speedLabel in the JudderPanel.

I want to keep this program as modular as possible.

If anyone has any ideas it would be greatly appreciated :-)


Thanks,


Mark
Nov 23 '06 #1
12 1872
bartonc
6,596 Expert 4TB
Hi there, just wondering if i could have a pointer inthe right direction here...

Sorry about the massive code posting - is that a wrong thing to do?
Nope, in fact, it's awesome! I'm exited to see that somebody is using wx! Let me take a look and get back to you...

My problem is that i cannot figure out how to make the OnStopButton event change the speedLabel in the JudderPanel.

I want to keep this program as modular as possible.

If anyone has any ideas it would be greatly appreciated :-)


Thanks,


Mark
Nov 23 '06 #2
Nope, in fact, it's awesome! I'm exited to see that somebody is using wx! Let me take a look and get back to you...
:-) Thanks a lot - much appreciated!

wx is amazing! I tried building a GUI on VC++ a few months back and it nearly killed me! lol - the wxPython / Widgets library combined with Python coding makes the whole things SOOOOOOOO much easier!

There are two files that i havnt included... Wizard.py & Initials.py, if you need the code for those aswell then let me know and i will get them up.

Thanks again!


Mark
Nov 23 '06 #3
bartonc
6,596 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. from Initials import *
  2. import wx
  3. import os
  4. from Wizard import *
  5.  
  6. class MainFrame(wx.Frame):
  7.     def __init__(self, parent, title):
  8.         wx.Frame.__init__(self, parent, -1, title)
  9.  
  10.         icon = wx.Icon("icon.ico", wx.BITMAP_TYPE_ICO)
  11.         self.SetIcon(icon)
  12.  
  13.  
  14.         ### Create Main Panel & Sizer ###
  15.         self.mainPanel = wx.Panel(self)
  16.         self.mainPanel.SetBackgroundColour((225,245,255))
  17.         mainSizer = wx.BoxSizer(wx.VERTICAL)
  18.  
  19.  
  20.         ### Create Various Panels ###
  21.         titlePanel = TitlePanel(self.mainPanel, wx.HORIZONTAL)
  22.         controlPanel = ControlPanel(self.mainPanel, wx.HORIZONTAL)
  23.         actionPanel = ActionPanel(self.mainPanel, wx.HORIZONTAL)
  24. ###########
  25.         actionPanel.SetWorkerFunc(controlPanel.GetWorker())
  26. ###########
  27.  
  28.         mainSizer.Add(titlePanel.panel, 2, wx.ALIGN_LEFT | wx.EXPAND | wx.ALL, 5)
  29.         mainSizer.Add(controlPanel.panel, 5, wx.EXPAND | wx.LEFT | wx.RIGHT, 5)
  30.         mainSizer.Add(actionPanel.panel, 2, wx.EXPAND | wx.ALL, 5)
  31.  
  32.         self.mainPanel.SetSizer(mainSizer)
  33.         mainSizer.Fit(self)                # Fit frame to neccessary size
  34.         mainSizer.SetSizeHints(self)       # Prevents frame from getting smaller than min.
  35.  
  36. ### NewPanel Class - All panels are derived from this class.
  37. ### Created with orientation information for sizer wx.HORIZONTAL or wx.VERTICAL
  38.  
  39. class NewPanel():
  40.     def __init__(self, parent, Orientation):
  41.         self.panel = wx.Panel(parent)
  42.         self.sizer = wx.BoxSizer(Orientation)
  43.  
  44.         self.AddItems()
  45.  
  46.         self.panel.SetSizer(self.sizer)
  47.         self.sizer.Fit(self.panel)                # Fit frame to neccessary size
  48.         self.sizer.SetSizeHints(self.panel)       # Prevents frame from getting smaller than min.
  49.  
  50. class TitlePanel(NewPanel):
  51.  
  52.     def AddItems(self):
  53.  
  54.         self.image = wx.Image("DPT.jpg", wx.BITMAP_TYPE_ANY)
  55.         self.bitmap = wx.StaticBitmap(self.panel, -1, wx.BitmapFromImage(self.image))
  56.  
  57.         self.label = wx.StaticText(self.panel, -1, "Sequence Driven Controller")
  58.         self.label.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, True))
  59.         self.label.SetForegroundColour('#00009F')
  60.  
  61.         self.currentTractor = wx.StaticText(self.panel, -1, "Current Tractor:\n"
  62.                                        "%s" %tractor)
  63.         self.currentTractor.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))
  64.         self.currentTractor.SetForegroundColour('#00009F')
  65.  
  66.         self.sizer.Add(self.bitmap, 1, wx.ALIGN_CENTER)
  67.         self.sizer.Add(self.label, 3, wx.ALIGN_CENTER | wx.LEFT, 15)
  68.         self.sizer.Add(self.currentTractor, 2, wx.ALIGN_CENTER)
  69.  
  70.  
  71. class ControlPanel(NewPanel):
  72.  
  73.     def AddItems(self):
  74.  
  75.         self.automaticPanel = AutomaticPanel(self.panel, wx.VERTICAL)
  76.         self.modePanel = ModePanel(self.panel, wx.VERTICAL)
  77.         self.manualPanel = ManualPanel(self.panel, wx.HORIZONTAL)        
  78.  
  79.         self.sizer.Add(self.automaticPanel.panel, 6, wx.EXPAND)
  80.         self.sizer.Add(self.modePanel.panel, 3, wx.EXPAND | wx.LEFT | wx.RIGHT, 5)
  81.         self.sizer.Add(self.manualPanel.panel, 5, wx.EXPAND)
  82.  
  83.  
  84. #################
  85.     def GetWorker(self):
  86.         return self.automaticPanel.GetWorker()
  87.  
  88.  
  89.  
  90. class AutomaticPanel(NewPanel):
  91.  
  92.     def AddItems(self):
  93.  
  94.         self.box = wx.StaticBox(self.panel, -1, 'Automatic Control')
  95.         self.box.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  96.         self.sizer = wx.StaticBoxSizer(self.box, wx.VERTICAL)
  97.  
  98.         self.directionPanel = DirectionPanel(self.panel, wx.HORIZONTAL)
  99.  
  100.         self.speedSlider = wx.Slider(self.panel, -1, 0, 0, 10,
  101.                                  style = wx.HORIZONTAL | wx.SL_AUTOTICKS)
  102.         self.speedSlider.SetTickFreq(1, 1)
  103.         self.panel.Bind(wx.EVT_SLIDER, self.OnSpeedSlider, self.speedSlider)
  104.  
  105.         self.judderPanel = JudderPanel(self.panel, wx.HORIZONTAL)
  106.  
  107.         self.sizer.Add(self.directionPanel.panel, 1, wx.ALIGN_CENTER | wx.EXPAND)
  108.         self.sizer.Add(self.speedSlider, 1, wx.ALIGN_CENTER | wx.EXPAND)
  109.         self.sizer.Add(self.judderPanel.panel, 1, wx.ALIGN_CENTER | wx.EXPAND)
  110.  
  111.     def OnSpeedSlider (self, event):
  112.         Speed = self.speedSlider.GetValue()
  113.         self.judderPanel.speedLabel.SetLabel("Speed = %d" % Speed)
  114.  
  115. #################
  116.     def GetWorker(self):
  117.         return self.judderPanel.GetWorker()
  118.  
  119.  
  120.  
  121. class DirectionPanel(NewPanel):
  122.  
  123.     def AddItems(self):
  124.  
  125.         self.forwardsRadio = wx.RadioButton(self.panel, -1, "Forwards")
  126.         self.stationaryRadio = wx.RadioButton(self.panel, -1, "Stationary")
  127.         self.backwardsRadio = wx.RadioButton(self.panel, -1, "Backwards")
  128.  
  129.         self.sizer.Add(self.forwardsRadio, 1, wx.EXPAND)
  130.         self.sizer.Add(self.stationaryRadio, 1, wx.EXPAND)
  131.         self.sizer.Add(self.backwardsRadio, 1, wx.EXPAND)
  132.  
  133.         self.stationaryRadio.SetValue(True)
  134.  
  135.  
  136. class JudderPanel(NewPanel):
  137.  
  138.     def AddItems(self):
  139.  
  140.         self.speedLabel = wx.StaticText(self.panel, -1, "Speed = %d" %Speed)
  141.         self.speedLabel.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  142.         self.speedLabel.SetForegroundColour('#00009F')
  143.  
  144.         self.judderToggle = wx.ToggleButton(self.panel, -1, "Judder")
  145.         self.panel.Bind(wx.EVT_TOGGLEBUTTON, self.OnJudderToggle, self.judderToggle)
  146.  
  147.         self.sizer.Add(self.speedLabel, 1, wx.ALIGN_CENTER | wx.LEFT, 15)    
  148.         self.sizer.Add(self.judderToggle, 1, wx.ALIGN_CENTER | wx.EXPAND | wx.ALL, 10)
  149.  
  150.     def OnJudderToggle(self, event):
  151.         pass
  152.  
  153. #################
  154.     def GetWorker(self):
  155.         return self.WorkerFunc
  156.  
  157.     def WorkerFunc(self):
  158.        pass
  159.  
  160. class ModePanel(NewPanel):
  161.  
  162.     def AddItems(self):
  163.  
  164.         self.box = wx.StaticBox(self.panel, -1, 'Mode')
  165.         self.box.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  166.         self.sizer = wx.StaticBoxSizer(self.box, wx.VERTICAL)
  167.  
  168.         self.automaticToggle = wx.ToggleButton(self.panel, -1, "Auto.")
  169.         self.automaticToggle.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  170.         self.panel.Bind(wx.EVT_TOGGLEBUTTON, self.OnAutomaticToggle, self.automaticToggle)
  171.  
  172.         self.manualToggle = wx.ToggleButton(self.panel, -1, "Man.")
  173.         self.manualToggle.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  174.         self.panel.Bind(wx.EVT_TOGGLEBUTTON, self.OnManualToggle, self.manualToggle)
  175.  
  176.         self.sizer.Add(self.automaticToggle, 1, wx.EXPAND | wx.ALL, 10)
  177.         self.sizer.Add(self.manualToggle, 1, wx.EXPAND | wx.ALL, 10)
  178.  
  179.     def OnAutomaticToggle(self, event):
  180.         pass
  181.  
  182.     def OnManualToggle(self, event):
  183.         pass
  184.  
  185.  
  186. class ManualPanel(NewPanel):
  187.  
  188.     def AddItems(self):
  189.  
  190.         self.box = wx.StaticBox(self.panel, -1, 'Manual Control')
  191.         self.box.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  192.         self.sizer = wx.StaticBoxSizer(self.box, wx.HORIZONTAL)
  193.  
  194.         self.bristlePanel = BristlePanel(self.panel, wx.VERTICAL)
  195.         self.cylinderPanel = CylinderPanel(self.panel, wx.VERTICAL)
  196.  
  197.         self.sizer.Add(self.bristlePanel.panel, 1, wx.EXPAND)
  198.         self.sizer.Add(self.cylinderPanel.panel, 1, wx.EXPAND)
  199.  
  200.  
  201. class BristlePanel(NewPanel):
  202.  
  203.     def AddItems(self):
  204.  
  205.         self.bristleCheckBox = []
  206.  
  207.         for x in range(0, Bristles):
  208.             self.bristleCheckBox.insert(x, (wx.CheckBox(self.panel, -1, "Bristle %d" % (x+1))))
  209.             self.sizer.Add(self.bristleCheckBox[x], 1, wx.ALIGN_CENTER_HORIZONTAL)        
  210.  
  211.  
  212. class CylinderPanel(NewPanel):
  213.  
  214.     def AddItems(self):
  215.  
  216.         self.cylinderCheckBox = []
  217.  
  218.         for x in range(0, Cylinders):
  219.             self.cylinderCheckBox.insert(x, (wx.CheckBox(self.panel, -1, "Cylinder %d" % (x+1))))
  220.             self.sizer.Add(self.cylinderCheckBox[x], 1, wx.ALIGN_CENTER_HORIZONTAL)
  221.  
  222.  
  223. class ActionPanel(NewPanel):
  224.  
  225.     def AddItems(self):
  226.  
  227.         self.goButton = wx.Button(self.panel, -1, "GO")
  228.         self.goButton.SetBackgroundColour('green')
  229.         self.goButton.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  230.  
  231.         self.stopButton = wx.Button(self.panel, -1, "STOP")
  232.         self.stopButton.SetBackgroundColour('red')
  233.         self.stopButton.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  234.         self.panel.Bind(wx.EVT_BUTTON, self.OnStopButton, self.stopButton)
  235.  
  236.         self.sizer.Add(self.goButton, 1, wx.EXPAND)
  237.         self.sizer.Add(self.stopButton, 1, wx.EXPAND)
  238.  
  239. #################
  240.     def SetWorkerFunc(self, worker):
  241.         self.worker = worker
  242.  
  243.  
  244.     def OnGoButton(self, event):
  245.         pass
  246.  
  247.     def OnStopButton(self, event):
  248.         Speed = 0
  249. #################
  250.         self.worker(Speed)
  251. #        frame.mainPanel.controlPanel.automaticPanel.judderPanel.speedLabel.SetLabel("Speed = %d" % Speed)
  252.  
  253.  
  254. class wxPyApp(wx.App):
  255.     def OnInit(self):
  256.         frame = MainFrame(None, "DPT - Sequence Driven Controller")
  257.         self.SetTopWindow(frame)
  258.         frame.Show(True)
  259.         frame.Center(wx.BOTH)
  260.         return True
  261.  
  262. if __name__ == '__main__':          # Only runs if program is being executed, not imported
  263.     app = wxPyApp(redirect=True)
  264.     app.MainLoop()
  265.  
  266.  
  267.  
Then, if there are a lot of (more than 1) workers that need to be called, the controler keeps a list (which may be empty) of workers. Then calls them like so:
Expand|Select|Wrap|Line Numbers
  1. def __init__(self, .....):
  2.     self.workerList = []
  3. def AddWorkerFunc(self, workerFunc):
  4.     self.workerList.append(workerFunc)
  5. def UpdateWorkers(self):
  6.     for workerFunc in workerList:
  7.         workerFunc(data)
  8.  
Nov 23 '06 #4
bartonc
6,596 Expert 4TB
Wow just made the 10000 char limit! couldn't squeeze this in:

As you probably suspect, events are one way to handle this. I prefer a more "in my control" approach. As in the Model-View-Control model, I like to have "givers" (of actions or data) and "takers". I actually prefer terms like server/client or publisher/subscriber for data, but you get the idea...

So I'll just hack something in here to show you what I mean:


One question that I have for you is: Why is NewPanel not derived from wxPanel the same way that mainFrame is derived from wxFrame? If it were, all the self.panel refs would simply be self.
Nov 23 '06 #5
bartonc
6,596 Expert 4TB
:-) Thanks a lot - much appreciated!

wx is amazing! I tried building a GUI on VC++ a few months back and it nearly killed me! lol - the wxPython / Widgets library combined with Python coding makes the whole things SOOOOOOOO much easier!

There are two files that i havnt included... Wizard.py & Initials.py, if you need the code for those aswell then let me know and i will get them up.

Thanks again!


Mark
Nope, I didn't run this. I just hacked some code in to give you an idea.
It may seem convoluted, but I think that's mostly because the panels are nested so deeply. Let me know what you think,
Barton

PS Welcome to thescripts! I hope you keep posting (snippets of code are OK too). If there's not enough info in the initial post, we'll always ask for more instead of guessing at your intent.
Nov 23 '06 #6
Nope, I didn't run this. I just hacked some code in to give you an idea.
It may seem convoluted, but I think that's mostly because the panels are nested so deeply. Let me know what you think,
Barton

PS Welcome to thescripts! I hope you keep posting (snippets of code are OK too). If there's not enough info in the initial post, we'll always ask for more instead of guessing at your intent.

Wow - thanks for the quick reply...

I should really have inherited wx.Panel when i made NewPanel - i may go back and change that. Would there be any real benefit to that other than maybe a couple of lines of code?

About the nesting. This is my second itteration of the program. The first was truely UGLY! hehe... I had everything built inside the MainFrame class... not a pretty sight! So after some reading up on refactorising i basically split everything up so that every single panel is a class... have a gone a step too far there do you think?

I tried to avoid deep nesting but it seems that it has happened anyway... i cant seem to see a way around it whilst trying to keep the kind of layout i want for the final UI.

I think i get what you are suggesting... i'll go away and have a proper look and see if i can get that working :-)


Thanks again for the help! Much appreciated


Mark
Nov 23 '06 #7
Just followed the data path through... but of a maze isnt it :-s didnt realise the nesting had gotten so deep...

This could get quite messy once i start having more things interacting with other things...


Mark
Nov 23 '06 #8
bartonc
6,596 Expert 4TB
Wow - thanks for the quick reply...

I should really have inherited wx.Panel when i made NewPanel - i may go back and change that. Would there be any real benefit to that other than maybe a couple of lines of code?

About the nesting. This is my second itteration of the program. The first was truely UGLY! hehe... I had everything built inside the MainFrame class... not a pretty sight! So after some reading up on refactorising i basically split everything up so that every single panel is a class... have a gone a step too far there do you think?

I tried to avoid deep nesting but it seems that it has happened anyway... i cant seem to see a way around it whilst trying to keep the kind of layout i want for the final UI.

I think i get what you are suggesting... i'll go away and have a proper look and see if i can get that working :-)


Thanks again for the help! Much appreciated


Mark
I don't think there is much operational benefit (internally a class member reference causes a lookup, but self still has to be searched for (I think). The real benefits are that self is 4 letter to type and self.panel is over twice as much typing and your subclass can be passed to frame method that expect panels.
I believe a good rule-of-thumb for refactoring is 7 plus or minus 3. Which means that more that 10 widgets on a panel gets REALLY ugly. Since I use Boa Constructor (which still has a hard time with user panels) to build my frames for me, I'm having a hard time sticking to this rule. I don't think that it's going too far to put every panel in its own module and import it into the main frame/app module. Boa even splits the app creation into its own module.
So, you read up on refactoring... Was that Robin Dunn's book? Keep posting,
Barton
Nov 23 '06 #9
I don't think there is much operational benefit (internally a class member reference causes a lookup, but self still has to be searched for (I think). The real benefits are that self is 4 letter to type and self.panel is over twice as much typing and your subclass can be passed to frame method that expect panels.
I believe a good rule-of-thumb for refactoring is 7 plus or minus 3. Which means that more that 10 widgets on a panel gets REALLY ugly. Since I use Boa Constructor (which still has a hard time with user panels) to build my frames for me, I'm having a hard time sticking to this rule. I don't think that it's going too far to put every panel in its own module and import it into the main frame/app module. Boa even splits the app creation into its own module.
So, you read up on refactoring... Was that Robin Dunn's book? Keep posting,
Barton

wxPython In Action - Noel Rappin & Robin Dunn... correct :-)

It's pretty much been my bible for the past few weeks! Its a really good reference book but there arent many examples of BIG code... if you get what i mean?

When you say 7 +- 3 widgets... am i right in thinking that means

Main.1st level.2nd level..... 7th level?

If thats the case i reckon im just about ok! :-)

I think i might as well leave the NewPanel as is if it doesnt make any operational difference... if i have a bit of time nearer my deadline and am actually finished then i may go back for completeness. As is though ive got everything pretty much built, just a case of filling the actual function into the skeleton.

Mark
Nov 23 '06 #10
bartonc
6,596 Expert 4TB
wxPython In Action - Noel Rappin & Robin Dunn... correct :-)

It's pretty much been my bible for the past few weeks! Its a really good reference book but there arent many examples of BIG code... if you get what i mean?

When you say 7 +- 3 widgets... am i right in thinking that means

Main.1st level.2nd level..... 7th level?

If thats the case i reckon im just about ok! :-)

I think i might as well leave the NewPanel as is if it doesnt make any operational difference... if i have a bit of time nearer my deadline and am actually finished then i may go back for completeness. As is though ive got everything pretty much built, just a case of filling the actual function into the skeleton.

Mark
Yep, that's the book "wxPython In Action". BTW are you on Linux or Windows (it is sooo cool that it doesn't matter)?
I'd say 4 to 10 widgets per panel (nesting is another matter). I'll bet you could flatten out the structure by putting sizers to good use. They nest well and are fully automated. Having a GUI builder like wxGlade (comes with Stani's Python Editor) or Boa (complete IDE) would let you play with these things without writing ANY code.
Nov 23 '06 #11
Yep, that's the book "wxPython In Action". BTW are you on Linux or Windows (it is sooo cool that it doesn't matter)?
I'd say 4 to 10 widgets per panel (nesting is another matter). I'll bet you could flatten out the structure by putting sizers to good use. They nest well and are fully automated. Having a GUI builder like wxGlade (comes with Stani's Python Editor) or Boa (complete IDE) would let you play with these things without writing ANY code.
I played around with Glade but for some reason it wasnt working properly on my computer - and Boa never got close to working... blame it on Windows :-p

Right - i'm going to give that data passing thing a go.

Thanks again for all the help - no doubt i'll be back in a day or two! lol

All the best,


Mark
Nov 23 '06 #12
bartonc
6,596 Expert 4TB
I played around with Glade but for some reason it wasnt working properly on my computer - and Boa never got close to working... blame it on Windows :-p

Right - i'm going to give that data passing thing a go.

Thanks again for all the help - no doubt i'll be back in a day or two! lol

All the best,


Mark
BTW I'm on Windows XP
Nov 23 '06 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
3
by: boxboy | last post by:
I am hoping someone from Microsoft could shed some insight into this question. Why did microsoft decide to use a verb based naming convtion for events rather such as Close and Click for rather...
8
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that...
7
by: Dee | last post by:
I have 11 numeric fields on a form which are all inter related. When any field changes after update, all need recalculation. Each field has an after update event procedure. Each of which runs...
4
by: rawCoder | last post by:
Hi all, How Can You Raise Events Asynchronously ? Now for the details ... I want to do inter modular communication using events in such a way that the contributing modules need not...
4
by: hillcountry74 | last post by:
Hi, I'm a newbie and trying to understand event handling in c#. I have understood handling events using delelgate objects. But not this method- "Event handling by overriding the virtual...
2
by: andla | last post by:
Hi, How does events fire in a datagrid. I know about the problem if turning the viewstate off the events wil not fire properly even if I rebind the control in every postback. S then I started...
3
by: johncee | last post by:
Greetings, I created a base class that has a datagrid. I've made it generic as possible so that any derived classes pass some info to the base constructor (including a SQL select stmt) &...
5
by: Richard Grant | last post by:
Hi, I need to "save" in a variable the event handler sub of a control's event, then perform some process, and finally "restore" the originally saved event handler. Example in pseudo-code: 1)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.