0

I have multiple panels in my app, that reside in a wx.Notebook. For sake of illustration, let's assume I have a panel called LaunchPanel in a file called launchTab, and a panel called ScanPanel in a file called scanTab.

I have a button on ScanPanel that can lockup the GUI for a while, so I am currently disabling every widget on the panel itself when the long-running-task kicks off. This all works fine. But I want to disable other things in the other panels now that may conflict if the user goes trigger happy with the left mouse button. I found that you can disable a panel with panel.Disable(), but I don't know how to, for instance, call Disable for the panel in LaunchPanel from within ScanPanel.

I've tried import launchTab from within launchTab to get access to ScanPanel:

import launchTab
...
launchTab.LaunchPanel.Disable()

but get this error: TypeError: unbound method Disable() must be called with LaunchPanel instance as first argument (got nothing instead)

I think the answer is a pubsub, but I don't know how to set one up to muck with the panel, I've only ever used them to update a widget...? There's an immense amount of sourcecode at the moment, so I don't want to paste all of it, but I can provide more clarification if it is needed.

Help? Thoughts?

EDIT PER BELOW ANSWER:

So -- I'm not quite sure I understand... there's the following components to the app. myAppGUI.py:

class myNotebook(wx.Notebook):
 """
 The core layout for the app -- notebook pages are slotted here
 """
 #----------------------------------------------------------------------
 def __init__(self, parent):
 wx.Notebook.__init__(self, parent, id=wx.ID_ANY, style=wx.BK_DEFAULT)
 self.AddPage(launchTab.LaunchPanel(self), "Launch")
 self.AddPage(scanTab.ScanPanel(self), "Scan")
 self.AddPage(extractTab.ExtractPanel(self), "Extract")
 self.AddPage(virtualsTab.VirtualsPanel(self), "Virtuals")

This is the main file that launches all my other notebook tabs. Then, I have, launchTab:

class LaunchPanel(wx.Panel):
"""
Launch Tab for finding and launching databases
"""
#----------------------------------------------------------------------
def __init__(self, parent):
 """"""
 wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
 super(LaunchPanel, self)
 self.initialize()
def initialize(self):
 global sizer
 panel = self
 sizer = wx.GridBagSizer(11, 3)
 <snip>

And then I have, scanTab:

class ScanPanel(wx.Panel):
 """
 Scan Tab for running Sonospy Database Scans, Updates and Repairs
 """
 #----------------------------------------------------------------------
 def __init__(self, parent):
 """"""
 wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
 panel = self
 sizer = wx.GridBagSizer(6, 5)
 self.launchPanelRef = None

I've tried the answer below, but I think since my init is using parent=parent (which I took off sample code somewhere else to get it working originally), I get the following error:

File "gui/scanTab.py", line 223, in __init__
 launchPanel = launchTab.LaunchPanel()
TypeError: __init__() takes exactly 2 arguments (1 given)

When you say to put:

def main():
 scanPanel = ScanPanel()
 launchPanel = LaunchPanel()
 scanPanel.setInstanceLaunchPanel(launchPanel)

Does that go within scanTab? And is launchPanelRef the name of the panel I want to control in this case?

Sorry -- I'm easily confused. :)

-Chow

asked Aug 20, 2011 at 15:08
2
  • See additions based on your additions. You would benefit from some Python Object Orientated tutorials. Commented Aug 20, 2011 at 22:13
  • Heh. I would benefit from a lot of things. I'm one of those folks that learns by doing -- I've got plenty of books on the topic, and my Python experience is about 4 weeks old right now. :) Commented Aug 20, 2011 at 22:40

1 Answer 1

2

The error you are getting is because you are calling a method of a class without an instance of an object of that class.

You need to pass the instance of your LaunchPanel class (your LaunchPanel object), into your ScanPanel class.

class ScanPanel:
 def __init__:
 self.launchPanelRef = None
 <snip>
 def setInstanceLaunchPanel(launchPanelRef):
 self.launchPanelRef = launchPanelRef
def main():
 scanPanel = ScanPanel()
 launchPanel = LaunchPanel()
 scanPanel.setInstanceLaunchPanel(launchPanel)

Now within ScanPanel you have a reference to your launchPanel object that you can call disable on.

Does that make any sense?

EDITS

I am guessing you want to be able to disable the "launchPanel" from the "scanPanel", right? You need to add the setInstanceLaunchPanel to the scan panel. All it does it allow you to store a reference to the launch panel. This means that within the scan panel you'll be able to control the launch panel instance.

class myNotebook(wx.Notebook):
 """
 The core layout for the app -- notebook pages are slotted here
 """
 #----------------------------------------------------------------------
 def __init__(self, parent):
 wx.Notebook.__init__(self, parent, id=wx.ID_ANY, style=wx.BK_DEFAULT)
 launchPanel = launchTab.LauchPanel(self) #init launchPanel
 scanPanel = scanTab.ScanPanel(self) #init scanPanel
 scanPanel.setInstanceLaunchPanel(launchPanel) #store reference to launchPanel in scanPanel
 self.AddPage(launchPanel, "Launch") #add launchPanel to notebook
 self.AddPage(scanPanel, "Scan") #add scanPanel to notebook
 self.AddPage(extractTab.ExtractPanel(self), "Extract") #init extractPanel and add to notebook
 self.AddPage(virtualsTab.VirtualsPanel(self), "Virtuals")
answered Aug 20, 2011 at 16:08
Sign up to request clarification or add additional context in comments.

1 Comment

Definitely works in storing the references to the panels themselves. I couldn't get the panel to Disable() on self.launchRef.Disable(), even through it didn't error out. I also tried to modify a text control on the launchTab panel from within ScanPanel and it updated but wouldn't redraw the panel. Accepting the answer as it did, in fact, store relevant info, but I am going to need to learn a bunch more to pull this off. Thanks for your help. I did try launchPanelRef.Update() and .Refresh()

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.