(HELP) wxPython: Update other panels from event triggered in another panel

Reply

Join Date: Nov 2008
Posts: 2
Reputation: sangpenakluk is an unknown quantity at this point 
Solved Threads: 0
sangpenakluk sangpenakluk is offline Offline
Newbie Poster

(HELP) wxPython: Update other panels from event triggered in another panel

 
0
  #1
Nov 10th, 2008
Hello!! I desperately need help on event triggering across panels in wxPython!

I have 2 classes that inherit wx.Panel: Leftpanel & Rightpanel
Leftpanel consists of several buttons.
Rightpanel consists of a graph (i.e. using matplotlib).

I want to make the program so that pressing the button on Leftpanel will update(redraw) the graph on Rightpanel. (=event from pressing a button of a panel will trigger another function declared in another panel).

I have googled plenty of resources, but could not find any hints.
Any help would be greatly appreciated! Thanks!
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,357
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 127
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Re: (HELP) wxPython: Update other panels from event triggered in another panel

 
0
  #2
Nov 10th, 2008
sample code will help explain more. Also search for something like calling one method from another place in this forum.

What I know is you use their common parent as reference (SB can correct me if I'm wrong!)
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 2
Reputation: sangpenakluk is an unknown quantity at this point 
Solved Threads: 0
sangpenakluk sangpenakluk is offline Offline
Newbie Poster

Re: (HELP) wxPython: Update other panels from event triggered in another panel

 
0
  #3
Nov 18th, 2008
Thanks for the reply. Here I'm attaching my code.
Explanation:
LeftPanel has a button which if pressed, will call the event handler on_button described in another class (RightPanel).

The question is:
How do you make a program which has one button in a panel(=left panel) which calls to a function in another panel(=right panel)?
The purpose of doing this is that I want to make a program that has 2 panels: one showing only buttons & textboxes and the other one showing a graph. Whenever the user changes a value in boxes/buttons in left panel, the graph in the right panel also changes.

When executing the program below I got an error:
TypeError: unbound method on_button() must be called with RightPanel instance as first argument (got CommandEvent instance instead)

Help would be greatly appreaciated! Thank you guys!

  1.  
  2. import wx
  3.  
  4. class RightPanel(wx.Panel):
  5. def __init__(self, parent):
  6. wx.Panel.__init__(self, parent)
  7.  
  8. def on_button(self, event):
  9. self.calculate()
  10.  
  11. def calculate(self):
  12. # Another calculation here
  13. print 1+1
  14.  
  15. class LeftPanel(wx.Panel):
  16. def __init__(self, parent):
  17. wx.Panel.__init__(self, parent)
  18.  
  19. # A Button
  20. self.button = wx.Button(self, -1, 'Calculate!')
  21.  
  22. # If the button is pressed, call on_button on the other class
  23. self.Bind(wx.EVT_BUTTON, RightPanel.on_button, self.button)
  24.  
  25. class Frame(wx.Frame):
  26. def __init__(self):
  27. wx.Frame.__init__(self, None, -1, "Testing")
  28. self.left_panel = LeftPanel(self)
  29. self.right_panel = RightPanel(self)
  30.  
  31. # Panel sizer
  32. self.panelsizer = wx.BoxSizer(wx.HORIZONTAL)
  33. self.panelsizer.Add(self.left_panel, 0, wx.LEFT | wx.TOP | wx.EXPAND)
  34. self.panelsizer.Add(self.right_panel, 1, wx.LEFT | wx.TOP | wx.EXPAND)
  35. self.SetSizer(self.panelsizer)
  36. self.panelsizer.Fit(self)
  37.  
  38. if __name__ == '__main__':
  39. app = wx.PySimpleApp()
  40. app.frame = Frame()
  41. app.frame.Show()
  42. app.MainLoop()
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,357
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 127
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Re: (HELP) wxPython: Update other panels from event triggered in another panel

 
0
  #4
Nov 18th, 2008
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC