fteinz
fteinz

Reputation: 1095

Python call parent class attribute

I make some experiences in Python especially in wxpython from EventGhost but I have some generally problem with classes. I have watched around and tried a lot but have no success.

My problem is that I want to close my Gui from a button inside my "MyDialog()" class:

class ShowInputDialog(eg.ActionBase):
    name = "Show Input Dialog"  
    description = "Show an input dialog that allows you to create an EventGhost event that you can then use to trigger AutoRemote messages or notifications"
    def __call__(self):
        class MyDialog():
            def __init__(self):

                ########################Main Dialog###########################
                no_sys_menu = wx.CLIP_CHILDREN | wx.STAY_ON_TOP | wx.FRAME_NO_TASKBAR | wx.NO_BORDER | wx.FRAME_SHAPED
                self.Dialog = wx.Frame(None, wx.ID_ANY, "Hello World", style=no_sys_menu, size=(400,600))

                ########################Header###########################
                Header = wx.Panel(self.Dialog, wx.ID_ANY, size=(400,600)) 
                HeaderSizer = wx.GridSizer(rows=1, cols=2, hgap=5, vgap=5)

                HeaderSizer.Add(wx.StaticText(Header, label="Hello World"), flag=wx.ALIGN_CENTER_VERTICAL)

                button = wx.Button(Header, label='close')
                button.Bind(wx.EVT_BUTTON, self.close)
                HeaderSizer.Add(button, 0, wx.ALIGN_RIGHT, 0)

                Header.SetSizer(HeaderSizer) 

                upDownSizer = wx.BoxSizer(wx.VERTICAL)
                upDownSizer.Add(Header, 0, flag=wx.EXPAND)            
                self.Dialog.SetSizer(upDownSizer) 

                self.Dialog.Fit()
                self.Dialog.Show()


            def close(self, event):
                self.Close()
                print "see you soon"

        wx.CallAfter(MyDialog)  

if I call "close" from my button I get

AttributeError: MyDialog instance has no attribute 'Close'

but how to call "Close"? I Have read about to super the init of "MyDialog" but have no success doing that and also don't know if this would clear my problem.

Thanks and be not so hard to a noob

Upvotes: 0

Views: 71

Answers (1)

Joran Beasley
Joran Beasley

Reputation: 113968

self is your own class, it is not a wx Class ... if you want it to have the attributes of a wx.Dialog you need to inherit from wx.Dialog

the easiest solution is probably to just call close on self.Dialog which appears to be your actual instance of a dialog

def close(self, event):
     self.Dialog.Close()
     print "see you soon"

Upvotes: 1

Related Questions