Run wxPython app automatically on startup

Hi all

I am trying to figure out how to run my wxPython app automatically on
startup - Linux only (FC5).

On a separate track I am figuring out how to set up a diskless workstation.
Eventually I will combine the two, so that I can have a diskless workstation
that just runs my app. It will be ideal for point-of-sale and similar
systems.

My question relates to running the app automatically on startup. Bear in
mind that I don't really know what I am doing, so any advice as to the
*correct* way to do it will be most welcome. However, after some googling I
have got something that looks promising, but I have a specific question.

I am separating the steps of 'logging in automatically', and 'running a gui
program automatically', so the following commands are run after I have
logged into a text-based console -

  X :0 < /dev/null > /dev/null 2>&1 &
  exec demo.py --display :0 &

This brings up a gui screen with just the wxPython demo running. It seems to
run fine.

If I change the second line to exec myapp.py instead of demo.py, I get the
following error (I typed this, so I hope there are no typos) -

Traceback (most recent call last):
  File "./myapp.py", line 1135, in ?
    app = MyApp(False)
  File "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/_core.py",
line 7700, in __init__
    self.BootstrapApp()
  File "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/_core.py",
line 7352, in _BootStrapApp
    return _core_.PyApp__BootstrapApp(*args, **kwargs)
SystemError: wxEntryStart failed, unable to initialize wxWidgets! (Is
DISPLAY set properly?)

As far as I can see the essentials are the same as Main.py (called from
demo.py) -

import wx

class MyApp(wx.App):
    def OnInit(self):
        frame = MainFrame()
        frame.CentreOnScreen()
        frame.Show(False)
        self.SetTopWindow(frame)
        return True

app = MyApp(False)
app.MainLoop()

Any suggestions will be appreciated.

Thanks

Frank Millman

I guess this is a little off-topic, but I'll see if I can help you.

I am separating the steps of 'logging in automatically', and 'running a gui
program automatically', so the following commands are run after I have
logged into a text-based console -

  X :0 < /dev/null > /dev/null 2>&1 &
  exec demo.py --display :0 &

To start X automatically, look into using runlevel 5. To test this, before running X above, type "init 5" as root and see what happens. You can type "runlevel" by itself and the second number it gives you will be the current runlevel. Runlevel 5 was always used by RedHat to start X on boot and it may be the same with FC5. If the "init 5" line starts X, then to make the change permanent, edit /etc/inittab and find the line that looks like "id:3:initdefault:". Change the 3 to 5. The next time you reboot, your system will use runlevel 5.

Now, X probably came up asking for a login and password. You'll have to figure out how to re-configure FC5 to login as a default user. This is not terribly difficult. There are some scripts that control the start of X that can be found in places like /etc/init.d, /etc/rc.d/rc5.d, and /etc/X11. They, by default, probably start something called xdm, gdm, or kdm. I don't have an FC5 box handy to look this up for you, sorry. Ask the question "how do I automatically login a user in X on boot up in FC5?" on an FC5-related mailing list. Someone should be able to tell you.

If I change the second line to exec myapp.py instead of demo.py, I get the
following error (I typed this, so I hope there are no typos) -

Try setting the DISPLAY variable before running the command and then leave off the --display option.
bash:
   export DISPLAY=":0.0"

See if you have a file called .xinitrc or .xsession in your home directory. Add your "exec app.py &" command there and it will automatically be started for you. You won't need the DISPLAY bit if you do this. If you don't have both files, create one or the other and edit it. Make a sym-link to the other.

pico -w .xinitrc
ln -s .xinitrc .xsession

You'll probably have to copy/call your system's default .xsession/.xinitrc file (which you can find by digging through the scripts found in those directories I mentioned earlier) into/from yours. This file is used to start your window manager. Although, if you are only trying to have a single app present and available, you can run the app.py with a size equivalent to your screen size and with no window manager running, the only thing a user may do is to run the app. You could even wrap the app in a script that relaunches it upon close/crash. If you do this, take out the '&' from the command since X needs one process to be running in the foreground or else it quits.

I know this is all incomplete, but you're asking for quite a bit of knowledge here. I hope this will be enough to get you started and in the right direction.

R.

PGP.sig (186 Bytes)

···

On Aug 23, 2006, at 8:06 AM, Frank Millman wrote: