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)
    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")
     
    Justin, Aug 26, 2004
    #1
    1. Advertising

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

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

    --
    Richie Hindle
     
    Richie Hindle, Aug 26, 2004
    #2
    1. Advertising

  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
    #3
  4. Justin

    Tim Williams Guest

    DNS.DiscoverNameServer query

    (Relative Newbie)

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

    I have googled

    TIA
     
    Tim Williams, Aug 27, 2004
    #4
  5. Justin

    Michael Fuhr Guest

    Re: DNS.DiscoverNameServer query

    "Tim Williams" <> writes:

    > 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']

    --
    Michael Fuhr
    http://www.fuhr.org/~mfuhr/
     
    Michael Fuhr, Aug 27, 2004
    #5
    1. Advertising

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
    Replies:
    2
    Views:
    458
    Steven Bethard
    Feb 16, 2005
  2. Kent Johnson
    Replies:
    7
    Views:
    915
    Jan Niklas Fingerle
    Feb 12, 2006
  3. , India
    Replies:
    2
    Views:
    12,705
    Juha Nieminen
    Sep 15, 2007
  4. Trans
    Replies:
    6
    Views:
    144
    Michael P. Soulier
    Jan 5, 2007
  5. Ramchandra Apte
    Replies:
    17
    Views:
    342
    Manuel Pégourié-Gonnard
    Sep 30, 2012
Loading...

Share This Page