Specific request with code example (encapsulation) __init__ problems

J

Justin

On the advice of some members of this group I have decided to post a
very specific question / problem with a code example. My problem is
that my wxWidgets are created in the __init__ function of a panel.
(This is the way wx demos showed, I am brand new so I copies what they
did) my problem is now it appears that my widgets are completely
encapsulated within this __init__ class and I cannot get at them. Here
is an example of me trying to change the labels on a radiobox (all the
code that doesn't matter has been taken out) you can see it all if you
like. If the indentation is hard to understand due to the posting
syntax please let me know. And thanks for your help in advance.
The indentation quickly is 1 class "Gmainpanel" two functions
"__init__()" and changelabel()

class Gmainpanel(wx.Panel):
__shared_state = {}
def __init__(self, parent):
self.__dict__ = self.__shared_state
wx.Panel.__init__(self, parent, -1)

#Make the Radiobox
label_pickle = open("labels.dat", "r")
labellist = cPickle.load(label_pickle)
label_pickle.close()

sizer = wx.BoxSizer(wx.HORIZONTAL)

self.rb = wx.RadioBox(self,-1, "QuickSites", (10, 215), (425,
70),labellist , 5,wx.RA_SPECIFY_COLS)

self.Bind(wx.EVT_RADIOBOX, EvtRadioBox, self.rb)

self.rb.SetToolTip(wx.ToolTip("You can select a specific
service to search"))
sizer.Add(self.rb, 0, wx.ALL, 20)
self.rb.SetSizer(sizer)

def changelabel(self):
self.rb.SetLabel(1, "test change")
 
R

Richie Hindle

[Justin]
my problem is now it appears that my widgets are completely
encapsulated within this __init__ class and I cannot get at them.

That's not true if you say "self.x = y", as you have done with self.rb in
your posted example. I don't know why your code doesn't work - you seem to
be doing the right thing, and if I modify your Gobblewx_7public_.py to match
your posted example then it all works.

Here's what I did: I downloaded Gobblewx_7public_.py (a couple of days ago,
when you first mentioned it) changed 'rb' to 'self.rb' throughout the
Gmainpanel.__init__ function (lines 484-493), and added the line:

self.rb.SetItemLabel(1, "test change")

as the first line of the yousuredlg function (line 571). When I fill in the
form and hit "Download files", the label changes.

Note that it's SetItemLabel, not SetLabel, which implies that you never
called your changelabel function, or you didn't look at the resulting
traceback...
 
R

Richie Hindle

Thanks I finally got it working. Big help.

Glad to hear it!
What's the difference between SetLabel and SetItemLabel. Below is a
paste form the wx manual and it didn't contain that function

Either you have an old version of the manual or you didn't read the whole
entry for wxRadioBox::SetLabel. The wxWindows 2.5.1 manual says:
wxRadioBox::SetLabel

[...]

wxPython note: In place of a single overloaded method name, wxPython
implements the following methods:

SetLabel(string) Sets the radiobox label.
SetItemLabel(n, string) Sets a label for a radio button.
 
T

Tim Williams

(Relative Newbie)

How can I see which nameservers a DNS.DiscoverNameServera() finds?

I have googled

TIA
 
M

Michael Fuhr

Tim Williams said:
How can I see which nameservers a DNS.DiscoverNameServera() finds?

import DNS
DNS.DiscoverNameServers()
print DNS.defaults['server']
# or
req = DNS.DnsRequest()
print req.defaults['server']
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top