[PythonCE] a wxPython script that behaves like a CE application

Matt S. sleepingbull at gmail.com
Wed Feb 28 22:15:58 CET 2007


Hi,

So I now thankfully have a simple wxPython script that creates a frame,
etc...  Now I want it to act like a well-behaved CE application.
Ultimately, I'd like to post it to the wiki (at least as a hack).   Hope the
formatting in this email comes through alright!  Any help is greatly
appreciated.

>From what I've learned recently, I want the script to:

   1. start up the program without a shell, [see "\nopcceshell" registry
   arg]
   2. and a simple tap on a unique icon for the program from the Start >
   Programs menu, Task bar, or File Explorer, etc. [make a shortcut in
   "\Windows\Start Menu\Programs"]
   3. be minimized by the Smart Close button [no problem here]
   4. then be uniquely iconized to the Start/Task Menu [sort of
   accomplished by #2]
   5. and finally be brought forward again (maximized) when either the
   user again clicks on the Task menu (or any other shortcut to the script)
   [use win32gui.SetForegroundWindow(hwnd)]
   6. (for now, trying to keep it simple, I'm not going to worry about
   the hibernation, memory events that could cause spurious problems)
   [wxEVT_ACTIVATE, etc.]

I'm attaching the following script which almost accomplishes (5).  How to
accomplish (1-4) can be pieced together elsewhere.  The main problem the
script now has are:

   - if "\nopcceshell" is used, the busy clock persists [previous post
   but in example] but the running script is brought forward as expected.
   - if the pcceshell is used, and one calls
   [_pcceshell_support.Busy(0)], then the call on line 31, [frame_class =
   win32gui.GetClassName(frame.GetHandle())], returns the PythonCE shell
   and not the frame of the script.

Best regards,
Matt

PS: In case the attachment gets scrubbed, simple_ce.py:

import sys #, os, os.path, time
> import win32gui
>
> window_handle_file = 'window_handle.txt'
>
> def buildUI(window_handle_file):
>     # Write a file to save the window handle info
>     f = open(window_handle_file, 'wb')
>
>     # Start building the interface...
>     import wx
>
>     class SingleAppFrame(wx.Frame):
>         def __init__(self,parent,id,title):
>             wx.Frame.__init__(self,parent,-1, title, size = ( 300, 300))
>             self.Centre()
>
>     class SingleApp(wx.App):
>         def OnInit(self):
>     ##       Not implemented for PPC?
>     #        name = "SingleApp-%s" % (wx.GetUserId())
>     ##        self.name = "SingleApp-%s" % (wx.GetUserId())
>     #        self.instance = wx.SingleInstanceChecker(name)
>     #        if self.instance.IsAnotherRunning():
>     #            wx.MessageBox("Another instance is running", "ERROR")
>     #            return False
>             frame = SingleAppFrame(None, -1, "SingleApp")
>
>             frame.Show()
>             # Now get the window handle of the frame.
>             frame_class = win32gui.GetClassName(frame.GetHandle())
>             print frame_class
>             active_window = frame.GetHandle()
>             f.write(str(active_window))
>             f.close()
>             return True
>
>     app = SingleApp(redirect=False)
>     app.MainLoop()
>
>
> if sys.platform == 'win32':
>     pass
> elif sys.platform == 'Pocket PC':
>     # This gets rid of annoying pin/progress wheel. ala Luke.
>     try:
>         import _pcceshell_support
>     except ImportError:
>         pass
>     else:
>         _pcceshell_support.Busy(0)
> else:
>     print 'This operating system (%s) is not recognized.'%(sys.platform)
>
> try:
>     f = open(window_handle_file, 'rb')
>     #f.write('win32gui\n')
>     #SW_MAXIMIZE
>     #win32gui.GetClassName(frame.GetHandle())
>     if sys.platform == 'win32':
>         # If Window is minimized, this will maximize it.
>         window = win32gui.FindWindow('wxWindowClassNR', 'SingleApp')
>         window = win32gui.SetForegroundWindow(window)#'SW_MAXIMIZE')
> #        window = win32gui.ShowWindow(window, 1)#'SW_MAXIMIZE')# This
> doesn't set the window to the foreground.
>         print window
>     else:
>         ##########################################
>         # Unfortunately, when I use the following to bring the
>         # frame forward, I instead get the pcceshell (labeled PythonCE)
> shell.
>         # If I don't use the pcceshell, by altering the registry with,
>         # \nopcceshell,
>         # Then I get the busy clock and the frame window that I want!
>         ##########################################
>         hwnd = int(f.readline())
>         print hwnd
>         window = win32gui.SetForegroundWindow(hwnd)#'SW_MAXIMIZE')
>
>         ## Just other options but not exactly what I wanted.
>         #window = win32gui.SetForegroundWindow(window)#'SW_MAXIMIZE')
>
>         #window = win32gui.FindWindow('PythonClassNameNR', 'SingleApp')
>         #window = win32gui.ShowWindow(hwnd, 1)#window, 1)#'SW_MAXIMIZE')
>         #win32gui.SetActiveWindow(hwnd)#window, 1)#'SW_MAXIMIZE')
>
>     # Now, if the window was successfully shown, we'll be done here.
>     # Otherwise, fire up the app...
>     if window == 0: # Will be zero if window not brought to foreground.
>         'No window available, re-starting app'
>     else:
>         print 'The app should be visible!'
> except:
>
>     buildUI(window_handle_file)
>

On 2/26/07, Matt S. <sleepingbull at gmail.com> wrote:
>
>
> Regarding new info I have about solving this problem,
>
> I'm thinking I either need to implement a WindowProc function that
> processes messages sent to the window,
>
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windowprocedures/windowprocedurereference/windowprocedurefunctions/windowproc.asp
>
> or, hope that the WS_NONAVDONEBUTTON gets supported by wx and then ported
> to the PPC (or learn to compile, etc. myself),
>
> http://msdn2.microsoft.com/en-us/library/aa458799.aspx
>
>
>
> On 2/23/07, Luke Dunstan <coder_infidel at hotmail.com> wrote:
> >
> >  As with any Pocket PC application (written in Python or otherwise), the
> > X "close" button merely hides a window and does not destroy it. The Pocket
> > PC platform is intended so that users don't need to "close" applications as
> > such, and if you open enough other applications that the memory starts to
> > become full, the OS will actually close (WM_CLOSE) some of the applications
> > that were hidden in the background. If you try clicking the X button on
> > any of the Microsoft's Pocket PC applications, e.g. Pocket Word, and
> > then look in the task manager you will notice that it is still running.
> >
> > You may be able to capture the event as WM_SHOWWINDOW.
> >
> > As with any Python program on the PC, your script is not a process but
> > is just a text file that is interpreted by the python.exe process.
> >
> > Luke
> >
> >
> > ----- Original Message -----
> >  *From:* Matt S. <sleepingbull at gmail.com>
> > *To:* pythonce at python.org
> > *Sent:* Thursday, February 22, 2007 2:12 PM
> > *Subject:* [PythonCE] wxPython, handling close events
> >
> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/pythonce/attachments/20070228/412eb4a2/attachment-0001.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: simple_ce.py
Type: text/x-python
Size: 3462 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonce/attachments/20070228/412eb4a2/attachment-0001.py 


More information about the PythonCE mailing list