[Tutor] how to access deep classes

2009-11-20 Thread John
Hi,
I'm not to sure I can explain myself.  But I need to ask because I do not 
understand how it works or what is possible.

class A (wx.Panel);
   def__init__(...)

class B(wx.PyPanel):

   def __init__(..):
 self.pages = A(...)

class C (B)
  def __init__(...)

I can't change the code in either class A or class B.  But I want to add a 
property to class A in class C.  Is that possible?

Something like

wxpanelFontSize = property(_getwxpanelFontSize, _setwxpanelFontSize, None, '')

Or is there another way to get the same thing done?

Johnf

   
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to access deep classes

2009-11-20 Thread Lie Ryan

John wrote:

Hi,
I'm not to sure I can explain myself.  But I need to ask because I do not 
understand how it works or what is possible.


class A (wx.Panel);
   def__init__(...)

class B(wx.PyPanel):

   def __init__(..):
 self.pages = A(...)

class C (B)
  def __init__(...)

I can't change the code in either class A or class B.  But I want to add a 
property to class A in class C.  Is that possible?


Something like

wxpanelFontSize = property(_getwxpanelFontSize, _setwxpanelFontSize, None, '')

Or is there another way to get the same thing done?



Is this what you want?

class C(B):
@property
def wxpanelFontSize(self):
return self.pages.wxpanelFontSize
@wxpanelFontSize.setter
def wxpanelFontSize(self, value):
self.pages.wxpanelFontSize = value

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to access deep classes

2009-11-20 Thread John
On Friday 20 November 2009 04:48:59 am Lie Ryan wrote:
 Is this what you want?

 class C(B):
     �...@property
      def wxpanelFontSize(self):
          return self.pages.wxpanelFontSize
     �...@wxpanelfontsize.setter
      def wxpanelFontSize(self, value):
          self.pages.wxpanelFontSize = value

Maybe? @property is called a decorator.  But from what I'm reading I don't see 
how it's different from what a normal property def is like:
wxpanelFontSize = property(_getwxpanelFontSize, _setwxpanelFontSize, None, '')

I'm trying to set the font size of a text control in a class that provides no 
way to set the font size.  But in the back of my head I think all wx text 
items have FontSize.  Maybe I'm thinking about this incorrectly.  I think 
your saying that from class C I can set the font size if I have access to the 
underlying wx text control.  

Johnf

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to access deep classes

2009-11-20 Thread Alan Gauld

John jfabi...@yolo.com wrote


class A (wx.Panel);
  def__init__(...)

class B(wx.PyPanel):

  def __init__(..):
self.pages = A(...)

class C (B)
 def __init__(...)

I can't change the code in either class A or class B.  But I want to add 
a

property to class A in class C.  Is that possible?


You need to distinguish between classes and instances thereof.

You can add attributes to instances of A, and you can access the
instance because it is stored in self.pages of C. (You can actually add
attributes and methods to the class too, after it is defined but I wouldn't
recommend that since it gets  very confusing if you duplicate a name
added to an instance elsewhere!)

So you can, within C's methods do

self.pages.foo = 66

which adds a new foo attribute to the instance of A stored in pages.
Just be careful you don't have any code anywhere that relies on the
content of A instances (eg pickle/unpickle type things).

wxpanelFontSize = property(_getwxpanelFontSize, _setwxpanelFontSize, 
None, '')


Sorry, the connection to A is not clear.

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to access deep classes

2009-11-20 Thread John
On Friday 20 November 2009 09:48:38 am Alan Gauld wrote:
 John jfabi...@yolo.com wrote

  class A (wx.Panel);
def__init__(...)
 
  class B(wx.PyPanel):
 
def __init__(..):
  self.pages = A(...)
 
  class C (B)
   def __init__(...)
 
  I can't change the code in either class A or class B.  But I want to add
  a
  property to class A in class C.  Is that possible?

 You need to distinguish between classes and instances thereof.

 You can add attributes to instances of A, and you can access the
 instance because it is stored in self.pages of C. (You can actually add
 attributes and methods to the class too, after it is defined but I wouldn't
 recommend that since it gets  very confusing if you duplicate a name
 added to an instance elsewhere!)

 So you can, within C's methods do

 self.pages.foo = 66

 which adds a new foo attribute to the instance of A stored in pages.
 Just be careful you don't have any code anywhere that relies on the
 content of A instances (eg pickle/unpickle type things).

  wxpanelFontSize = property(_getwxpanelFontSize, _setwxpanelFontSize,
  None, '')

 Sorry, the connection to A is not clear.

Thanks - for your help.

Johnf
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor