Specific request with code example (encapsulation) __init__ problems

Discussion in 'Python' started by Justin, Aug 26, 2004.

  1. Justin

    Justin Guest

    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)

    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)

    def changelabel(self):
    self.rb.SetLabel(1, "test change")
    Justin, Aug 26, 2004
    1. Advertisements

  2. Re: Specific request with code example (encapsulation) __init__problems

    > 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

    Richie Hindle
    Richie Hindle, Aug 26, 2004
    1. Advertisements

  3. Re: Specific request with code example (encapsulation) __init__problems

    > 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.

    Richie Hindle
    Richie Hindle, Aug 27, 2004
  4. Tim Williams

    Tim Williams Guest

    DNS.DiscoverNameServer query

    (Relative Newbie)

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

    I have googled

    Tim Williams, Aug 27, 2004
  5. Michael Fuhr

    Michael Fuhr Guest

    Re: DNS.DiscoverNameServer query

    "Tim Williams" <> writes:

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

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

    Michael Fuhr
    Michael Fuhr, Aug 27, 2004
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven Bethard
    Steven Bethard
    Feb 16, 2005
  2. Kent Johnson
    Jan Niklas Fingerle
    Feb 12, 2006
  3. , India
    Juha Nieminen
    Sep 15, 2007
  4. Trans
    Michael P. Soulier
    Jan 5, 2007
  5. Ramchandra Apte
    Manuel Pégourié-Gonnard
    Sep 30, 2012

Share This Page