[PythonCE] code examples for the Wiki

Jeff Bauer jbauer@rubic.com
Mon, 07 Oct 2002 08:56:12 -0500


Kudos to Telion for setting up a CE Wiki page.  I
offered him a link to a demonstration I did at
IPC-7 in Houston.  It was a CE device running
a web server using Python and Bobo.  I no longer
have the code available and Bobo's since morphed
into Zope long ago.

Furthermore, I'm no longer running anything on
a CE device, but I do like to see efforts
continue to move in this direction.  I offered
Telion to post some quickie examples of CE
Python code.  I'd like to encourage other members
of this list to do the same.  I think our example
code should be posted onto the Wiki, which
might eventually become the foundation for
a set of cookbook recipes (with due acknowledgement
to ActiveState for sponsoring the original idea).

Anyhow, here are some trivial examples from my
notes:

1. Send a quick popup message to the user:

>>> import win32sys
>>> win32sys.MessageBox(0, "My Message", "My Title", 1)
>>> win32sys.MessageBeep()

2. Launch another CE application from Python:

>>> import win32sh
>>> win32sh.ShellExecuteEx(0, 0, "", "\\Windows\\calc.exe",
                          "", "\\Windows", 1)

3. Launch a shortcut from Python:

>>> import win32sh
>>> win32sh.SHGetShortcutTarget("\\tmp\\Expenses.lnk")
>>> win32sh.ShellExecuteEx(0,0,"","\\tmp\\Expenses.lnk","","",1)

4. Obtaining the IP address from a connected CE device:

>>> import socket
>>> hostname = socket.gethostname()
>>> ip = socket.gethostbyname(hostname)
>>> print ip
192.168.55.101

Since I don't have a CE environment to work on, someone
should test these before posting these to the Wiki.  Please 
consider adding your own code examples.

Jeff Bauer
Rubicon Research