Calling MyDialog from another program

Trying to keep the gui seperate from the main program. Have no problems
with the wxFrame class created with wxGlade. I made a wxDialog though
to get some input from the user.

It works fine when I put the controls in the gui script. But would like to
keep the button events and functions in the main program like with
the wxFrame controls.

Just can't seem to access them this way though.

I guess a sample would be in order:

Gui.py

···

**********************************
class MyFrame(wxFrame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = wxDEFAULT_FRAME_STYLE
        wxFrame.__init__(self, *args, **kwds)
  .......

class MyDialog(wxDialog):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyDialog.__init__
        kwds["style"] = wxDEFAULT_DIALOG_STYLE
        wxDialog.__init__(self, *args, **kwds)
  ........

class MyApp(wxApp):
    def OnInit(self):
        wxInitAllImageHandlers()
        frame_1 = MyFrame(None, -1, "")
        self.SetTopWindow(frame_1)
        frame_1.Show(1)
        return 1

# end of class MyApp

if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()
********************************

Main.py
*****************************
class MyApp(wxApp):

  def OnInit(self):
    # Display the main frame of the App
    frame = MyFrame(None,-1,"")
    frame.Show(True)
    self.frame = frame
    EVT_BUTTON....
    EVT_BUTTON...

  def......

  def.....

class MyAdd (not working right)
  def... (trying to show the dialog from gui.py and keep controls here.)

def main():
  app = MyApp(0)
  app.MainLoop()
  
if __name__ == '__main__':
  main()

****************************

Tried adding a class instance (or is it inheritance?) to the Main.py to work
with the MyDialog class created. Just can't seem to get it right.

I can either put the controls in the gui.py and make it work, but want them in same
program with the Frame controls (Main.py). Or I can make MyDialog show from the main.py
but then can't make the controls work. I guess you could say I am confused right now.
Any help. Just let me know if need more info. You guys have been a big help so far.

Dave

David wrote:

Trying to keep the gui seperate from the main program. Have no problems
with the wxFrame class created with wxGlade. I made a wxDialog though
to get some input from the user.

It works fine when I put the controls in the gui script. But would like to
keep the button events and functions in the main program like with
the wxFrame controls.

Just can't seem to access them this way though.

Maybe I am missing something and don't understand your problem, but why can't you just use import to load the things you need from the module they are defined in to the module where you want to use them?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!