WXPython: call a function with no binding or handler

I am building a small python program and I would like it to check for its ini file at startup: if the ini file it's not there then open a file dialog and write a line of it with the folder selected in the dialog.

I am using WXPython and I can't figure how to call a function while the program is running in the simplest possible way...

here's the code:

# A very simple wxPython example.  Just a wx.Frame, wx.Panel,
# wx.StaticText, wx.Button, and a wx.BoxSizer, but it shows the basic
# structure of any wxPython application.

import wx
import os

class MyFrame(wx.Frame):
    This is MyFrame.  It just shows a few controls on a wxPanel,
    and has a simple menu.
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title,
                          pos=(150, 150), size=(350, 250))

        menuBar = wx.MenuBar()

        filemenu = wx.Menu()
        aboutmenu = wx.Menu()

        filemenu.Append(wx.ID_OPEN, "Ch&oisissez le dossier de travail\tCtrl-O", "Choisissez le dossier")
        filemenu.Append(wx.ID_EXIT, "&Quitter\tCtrl-Q", "Quitter")

        aboutmenu.Append(wx.ID_ABOUT, "Aide de Pic Portier\tF1", "Aide de Pic Portier")
        aboutmenu.Append(wx.ID_ABOUT, "A propos de &Pic Portier\tCtrl-P", "A propos de Pic Portier")

        self.Bind(wx.EVT_MENU, self.OnTimeToClose, id=wx.ID_EXIT)
        self.Bind(wx.EVT_MENU, self.OnFileOpenMenu, id=wx.ID_OPEN)

        menuBar.Append(filemenu, "&Fichier")
        menuBar.Append(aboutmenu, "&Aide")



        panel = wx.Panel(self)

        text = wx.StaticText(panel, -1, "Es tu pret?")
        text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
        funbtn = wx.Button(panel, -1, "Just for fun...")
        btn = wx.Button(panel, -1, "Quitter")

        self.Bind(wx.EVT_BUTTON, self.OnTimeToClose, btn)
        self.Bind(wx.EVT_BUTTON, self.OnFunButton, funbtn)

        # Use a sizer to layout the controls, stacked vertically and with
        # a 10 pixel border around each
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(text, 0, wx.ALL, 10)
        sizer.Add(btn, 0, wx.ALL, 10)
        sizer.Add(funbtn, 0, wx.ALL, 10)

        # And also use a sizer to manage the size of the panel such
        # that it fills the frame
        sizer = wx.BoxSizer()
        sizer.Add(panel, 1, wx.EXPAND)

        # Check for ini file

    def OnTimeToClose(self, evt):
        """Event handler for the button click."""
        print "See ya later!"

    def OnFunButton(self, evt):
        """Event handler for the button click."""
        print "Having fun yet?"

    def OnFileOpenMenu(self, evt):
        # Args below are: parent, question, dialog title, default answer
        dd = wx.DirDialog(None, "Select directory to open", "~/", 0, (10, 10), wx.Size(400, 300))

        # This function returns the button pressed to close the dialog
        ret = dd.ShowModal()

        # Let's check if user clicked OK or pressed ENTER
        if ret == wx.ID_OK:
            wx.MessageBox('You selected: %s\n' % dd.GetPath(), 'Info',
            wx.OK | wx.ICON_INFORMATION)
        # The dialog is not in the screen anymore, but it's still in memory
        #for you to access it's values. remove it from there.
        return dd.GetPath()

    def ConfigFileCheck(self, evt):

        from ConfigParser import SafeConfigParser

        configfilename = "picportier.ini"
        scriptpath = os.path.abspath(os.path.dirname(__file__))
        configfile = os.path.join(scriptpath, configfilename)
            with open(configfile):
                parser = SafeConfigParser()
                pic_portier_working_folder = parser.get('picportier', 'working_folder')
        except IOError:
            if not os.path.isfile(configfile):
                pic_portier_working_folder = self.OnFileOpenMenu(None)
                configfilename = "picportier.ini"
                scriptpath = os.path.abspath(os.path.dirname(__file__))
                configfile = os.path.join(scriptpath, configfilename)
                except TypeError:
                    wx.MessageBox('Missing ini file', 'Info',
                    wx.OK | wx.ICON_INFORMATION)
                f = open(configfile, 'w')
                f.write('[picportier]\nworking_folder = '+pic_portier_working_folder+'\\')
                wx.MessageBox('Ini file creation successful', 'Info',
                wx.OK | wx.ICON_INFORMATION)

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, "Cosmonet - Pic Portier")

        print "Print statements go to this stdout window by default."

        return True

app = MyApp(redirect=True)

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ltpittAuthor Commented:

self.yourfunction(None) :)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ltpittAuthor Commented:
It worked
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.