1

I am not a complete beginner, but I am by no means an expert (perhaps I know enough to be dangerous? :) ). I tried googling an answer and doing my own troubleshooting for about 2 hours before posting this. There may well exist an explanation for this, I might be using the wrong terminology. Hopefully I have explained the issue well enough below.

I've been using wxFormBuilder to manage the GUI aspects of my applications and all has been going well. However I now need to add a WebView object, which is not catered for in the menu of objects that can be added using wxFormBuilder.

For overcoming this, I thought that I should be able to specify the missing object in the Inherited class file and then write a line to have it added to an existing Sizer that is defined in the Generated class file. I considered manually adding it to the Generated code file, but if I need make changes and regenerate the file, I would lose the code I manually wrote.

Creating the new WebView object in the Inherited Class is fine, but I cannot work out how to reference the Sizer in order to add it.

Here is an excerpt from my Inherited Class

import wx
import wx.html2
import isdPhoneQueueGui  #My Generated Class

class isdPhoneQueueMain(isdPhoneQueueGui.isdPhoneQueue):
    def __init__(self, parent):
        isdPhoneQueueGui.isdPhoneQueue.__init__(self,parent)
        self.myPage = wx.html2.WebView.New(self.myPanel)
        #STUCK HERE - WHAT SCOPE TO USE: to add "myPage" object to existing Sizer "mySizer"???

And from my Generated Class (just showing the definiton of "mySizer" etc)

class isdPhoneQueue ( wx.Frame ):    
    def __init__( self, parent ):
        wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"ISD Phone Queue", pos = wx.DefaultPosition, size = wx.Size( 1024,768 ), style = wx.CAPTION|wx.MAXIMIZE_BOX|wx.MINIMIZE_BOX|wx.SYSTEM_MENU|wx.TAB_TRAVERSAL )
        mySizer = wx.BoxSizer( wx.VERTICAL )
        self.myPanel = wx.Panel( self.m_notebook1, wx.ID_ANY, wx.DefaultPosition, wx.Size( 1024,768 ), wx.TAB_TRAVERSAL )
        self.myPanel.SetSizer( mySizer )

I have various ways of referencing mySizer in the Inherited Class, but have failed to workout the correct way to reference it.

I initially thought to try it as in the Generated Class:

mySizer.Add(self.myPage, 1, wx.EXPAND, 10)

but this gives "NameError: global name 'mySizer' is not defined".

I then tried various combinations of referencing prefixes, none of which worked:

isdPhoneQueueGui.mySizer.Add(self.myPage, 1, wx.EXPAND, 10)
self.isdPhoneQueueGui.mySizer.Add(self.myPage, 1, wx.EXPAND, 10)
isdPhoneQueue.mySizer.Add(self.myPage, 1, wx.EXPAND, 10)
self.isdPhoneQueue.mySizer.Add(self.myPage, 1, wx.EXPAND, 10)

Thanks in advance for any assistance.

4

1 回答 1

0

在该例程运行后,变量“mySizer”isdPhoneQueue.__init__()不可用,因为它是一个局部变量。对它所引用的 sizer 的引用被分配给面板 self.myPanel - 这就是它保留的地方。

因此,您可以在继承的类构造函数中使用

the_sizer = self.myPanel.GetSizer()

...因为 myPanel 是您可以访问的继承成员变量。

于 2014-02-27T08:10:53.897 回答