Python, How to invoke an instance method from inside a another Class -
i have python gui frame has 1 upperpanel , vertical splitterwindow. each panel in splitterwindow created 2 panel classes, 1 listbox , other 1 grid. each class has several buttons.
is there way keep button connect event.bind
, function code inside class , make work, because, presently i'm getting following error:
attributeerror: 'panel' object has no attribute 'm_dirpicker1'
i know best practice in reported situation.
this example short example of have wrote:
class frame ( wx.frame ): ... self.m_datapanel = wx.panel( self, wx.id_any, wx.defaultposition, wx.defaultsize, wx.tab_traversal ) self.m_filespanel = source_panel( self.m_splitter1) self.m_gridpanel = data_viewer( self.m_splitter1) class source_panel ( wx.panel ): ... # connect events self.m_listbox.bind( wx.evt_listbox_dclick, self.m_listboxonlistboxdclick ) self.m_clearbutton.bind( wx.evt_button, self.m_clearbuttononbuttonclick ) self.m_importbutton.bind( wx.evt_button, self.m_importbuttononbuttonclick ) self.m_showdata.bind( wx.evt_button, self.m_showdataonbuttonclick ) def __del__( self ): pass # virtual event handlers, overide them in derived class def m_listboxonlistboxdclick( self, event ): event.skip() def m_clearbuttononbuttonclick( self, event ): event.skip() def m_importbuttononbuttonclick( self, event ): src_directory = frame.m_datapanel.m_dirpicker1.gettextctrlvalue() def m_showdataonbuttonclick( self, event ): event.skip() class data_viewer ( wx.panel ): ...
i'm going assume source_panel
instance child of myframe
instance (i'm going refer frame
myframe
avoid confusion wx.frame
base class).
in case, parent
attribute of source_panel
instance should refer parent myframe
.
then can call:
self.parent.m_datapanel.m_dirpicker1.gettextctrlvalue()
Comments
Post a Comment