FilterEvent in wxApp

I am trying to modify my app to have a variety of TopFrames and I wanted
to move everything they shared into the wxApp part of the app. The catch
is that I want to be able to process arbitrary events but the wxApp
class is not behaving as documented. The key, I think, is that
FilterEvent is not getting called though apparently these events are
getting handled somewhere. What am I missing?

Thanks,
Sam

from wxPython.wx import *
wxEVT_INVOKE = wxNewEventType()

class InvokeEvent(wxPyEvent):
    def __init__(self, func, args, kwargs):
        wxPyEvent.__init__(self)
        self.SetEventType(wxEVT_INVOKE)
        self.func = func
        self.args = args
        self.kwargs = kwargs
class aFrame(wxFrame):
    def __init__(self, parent, id, title, func):
        wxFrame.__init__(self, parent, -1, title, size = (700, 400),

style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
        EVT_CLOSE(self, self.OnCloseWindow)
        self.func = func
        menuBar = wxMenuBar()
        menu1 = wxMenu()
        menuBar.Append(menu1,"&Something")

        self.SetMenuBar(menuBar)
    def OnCloseWindow(self, event):
        self.Destroy()
        self.func()
class anApp(wxApp):
    def __init__(self):
        wxApp.__init__(self)
    def OnInit(self):
        self.SetExitOnFrameDelete(False)
        frame = aFrame(None, -1, "Test Frame", self.DoSomethingLater)
        frame.Show(True)
        return True
    def FilterEvent(self, event):
        print '.',
        if event.GetEventType == wxEVT_INVOKE:
            print 'Event is of EVT_INVOKE TYPE'
            apply(event.func, event.args, event.kwargs)
            return True
        else: return -1
    def invokeLater(self, func, args = [], kwargs = {}):
        #self.wxPostEvent( InvokeEvent(func, args, kwargs))
        print self.ProcessEvent( InvokeEvent(func, args, kwargs))
    def DoSomething(self, event):
        frame = aFrame(None, -1, "Test Frame 2", self.DoSomethingLater)
        frame.Show(True)
        self.SetTopWindow(frame)
    def DoSomethingLater(self):
        self.invokeLater(self.DoSomething)
def main():
    print 'init'
    app = anApp()
    print 'loop'
    app.MainLoop()
    return
if __name__ == '__main__':
    main()

Hi all,
i want to backup an outputfile written in python, but don't know how to do
this.
what is the command for this?
the output file excists, but i want to save the same file to another
filename, for backup, via a wxbutton, or radiobutton....
anyone?

Stephan

import shutil

shutil.copyfile('file1', 'file2')

-Mark

···

On Sun, 2003-06-29 at 07:20, Stephan Huijgen wrote:

Hi all,
i want to backup an outputfile written in python, but don't know how to do
this.
what is the command for this?
the output file excists, but i want to save the same file to another
filename, for backup, via a wxbutton, or radiobutton....
anyone?

Sam Hendley wrote:

I am trying to modify my app to have a variety of TopFrames and I wanted
to move everything they shared into the wxApp part of the app. The catch
is that I want to be able to process arbitrary events but the wxApp
class is not behaving as documented. The key, I think, is that
FilterEvent is not getting called though apparently these events are
getting handled somewhere. What am I missing?

Since FilterEvent would be called for absolutley every event in the application I didn't think it was worth to overhead in the 99.9% of the applications that don't use it. If it was implemented then each time any event happend then before it could be dispatched to a handler, or even just ignored to allow the system to process it, then the FilterEvent wrapper would have to aquire the interpreter lock and check for the existence of "FilterEvent" method object in the derived python class, then call it if present...

OTOH, I suppose that I could provide another wxApp derived class that does provide the ability to override FilterEvent. Then if you need it you just derive from that class instead of wxApp. I'll think about this some more...

···

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

Thanks, I figured that was probably what was going on. I still dont
know how to get the functionality I need. I wanted to seperate the
handling of the data from the GUI so I moved all the key functions
into the wxApp part of the code and the call after functionality is
the only one I really need to create. Right now I juryrigged it so
that it uses GetTopWindow().invokLater, and just make all of my main
frames and dialogs have this function and register to recieve the
event. Is there a better way to do this? Actually do you think I would
be better off moving these functions to a plain wxWindow class? Is
this a good idea if I never plan to show the window?
Thanks
Sam
Quoting Robin Dunn <robin@alldunn.com>:

···

Sam Hendley wrote:
> I am trying to modify my app to have a variety of TopFrames and I
wanted
> to move everything they shared into the wxApp part of the app. The
catch
> is that I want to be able to process arbitrary events but the
wxApp
> class is not behaving as documented. The key, I think, is that
> FilterEvent is not getting called though apparently these events
are
> getting handled somewhere. What am I missing?
>

Since FilterEvent would be called for absolutley every event in the
application I didn't think it was worth to overhead in the 99.9% of
the
applications that don't use it. If it was implemented then each time

any event happend then before it could be dispatched to a handler, or

even just ignored to allow the system to process it, then the
FilterEvent wrapper would have to aquire the interpreter lock and
check
for the existence of "FilterEvent" method object in the derived
python
class, then call it if present...

OTOH, I suppose that I could provide another wxApp derived class that

does provide the ability to override FilterEvent. Then if you need
it
you just derive from that class instead of wxApp. I'll think about
this
some more...

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

---------------------------------------------------------------------
To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwindows.org

shendley@email.unc.edu wrote:

Thanks, I figured that was probably what was going on. I still dont know how to get the functionality I need. I wanted to seperate the handling of the data from the GUI so I moved all the key functions into the wxApp part of the code and the call after functionality is the only one I really need to create. Right now I juryrigged it so that it uses GetTopWindow().invokLater, and just make all of my main frames and dialogs have this function and register to recieve the event. Is there a better way to do this? Actually do you think I would be better off moving these functions to a plain wxWindow class? Is this a good idea if I never plan to show the window?

You may want to look at the evtmgr and pubsub modules in the library. They will let you use the Publish/Subscribe pattern to implement a loose coupling between your gui and the main app code. Window events that are registered with the EventManager are turned into published messages that any handler in your program can subscribe to and recieve notifications when they occur.

···

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