wxTaskBarIcon used in demo example from wxPython2.8-win32-docs-demos

Hi,

I don't understand from where come "FRAME" in "self.frame = frame"
I can't find to be used "frame" like argument.
Class DemoTaskBarIcon is used this way "self.tbicon =
DemoTaskBarIcon(self)"

class DemoTaskBarIcon(wx.TaskBarIcon):
    TBMENU_RESTORE = wx.NewId()
    TBMENU_CLOSE = wx.NewId()
    TBMENU_CHANGE = wx.NewId()
    TBMENU_REMOVE = wx.NewId()

    def __init__(self, frame):
        wx.TaskBarIcon.__init__(self)
        self.frame = frame

Thanks in advance from your answer!

You have to go check the parent class (
wx.TaskBarIcon ) to see from where it comes.

But basically you have to pass that frame to the widget constructor, and thus once you have constructed it probably the programmer is needing it somewhere later so he does the self.frame=frame “trick” to be able to use that frame somewhere else around the class. Dont know if thats what you are asking, its simple OOP.

···

2012/3/30 Deni Didro qrabota@gmail.com

Hi,

I don’t understand from where come “FRAME” in “self.frame = frame”

I can’t find to be used “frame” like argument.

Class DemoTaskBarIcon is used this way "self.tbicon =

DemoTaskBarIcon(self)"

class DemoTaskBarIcon(wx.TaskBarIcon):

TBMENU_RESTORE = wx.NewId()

TBMENU_CLOSE   = wx.NewId()

TBMENU_CHANGE  = wx.NewId()

TBMENU_REMOVE  = wx.NewId()



def __init__(self, frame):

    wx.TaskBarIcon.__init__(self)

    self.frame = frame

Thanks in advance from your answer!

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en


monoBOT

Visite mi sitio(Visit my site): monobotblog.alvarezalonso.es

On Fri, Mar 30, 2012 at 3:13 AM, Deni Didro

I don't understand from where come "FRAME" in "self.frame = frame"
I can't find to be used "frame" like argument.
Class DemoTaskBarIcon is used this way "self.tbicon =
DemoTaskBarIcon(self)"

the DemoTaskBarIcon __Init__ specifies:

  def __init__(self, frame):

this is a method, so in this case, "self" is the object being
initialized (the new DemoTaskBarIcon object). It is filled in
automatically by python, so this __init__ takes one argument, "frame",
presumabley teh frame you want the TaskBarIcon user with.

when it is called:

"self.tbicon = DemoTaskBarIcon(self)"

then "self" is defined in the calling scope -- I presume this is in a
wx.Frame __init__, (or other method) and thus "self" is a frame -- teh
one you want the Icon for.

the trick here is that the name used when calling a funciton is
independent of the the name used in funtion itself:

def f(a):
    return a+ 2

when I call it, I can call it with whatever input name I want:

In [75]: f(23)
Out[75]: 25

In [76]: a = 2

In [77]: b = 3

In [78]: f(a)
Out[78]: 4

In [79]: f(b)
Out[79]: 5

so this trick it identifying what is what is to look at the name in
the current scope.

HTH,

  -Chris

···

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Hi Deni,

Hi,

I don't understand from where come "FRAME" in "self.frame = frame"
I can't find to be used "frame" like argument.
Class DemoTaskBarIcon is used this way "self.tbicon =
DemoTaskBarIcon(self)"

'self' at that point (line 1678 in the wxPython demo) refers to the wxPythonDemo(wx.Frame).

class DemoTaskBarIcon(wx.TaskBarIcon):
     TBMENU_RESTORE = wx.NewId()
     TBMENU_CLOSE = wx.NewId()
     TBMENU_CHANGE = wx.NewId()
     TBMENU_REMOVE = wx.NewId()

     def __init__(self, frame):

When it gets to here the first parameter to DemoTaskBarIcon will be in the "frame" parameter and self is refering to "DemoTaskBarIcon".

Or maybe do a google on "python self".

Werner

···

On 30/03/2012 12:13, Deni Didro wrote: