Freezes window created with wxPython if use pyHook

This code works fine, however when I press minimize or close button,
window of program freezes on some time. The reason may be in the
HookMouse, without it, window minimize and close fine. Why?

import wx
import pyHook

class myFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'My Frame')
        self.tc=wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.DefaultSize,
        wx.TE_MULTILINE|wx.TE_NOHIDESEL|wx.TE_READONLY)

        self.hm = pyHook.HookManager()
        self.hm.KeyDown = self.OnKeyboardEvent

        self.hm.HookKeyboard()
        self.hm.MouseLeftDown=self.OnKeyboardEvent
        self.hm.HookMouse()

        wx.EVT_CLOSE(self, self.OnClose)

    def OnGetAO(self, event):
        self.tc.Value+=event.MessageName+"\n"

    def OnKeyboardEvent(self, event):
        wx.CallAfter(self.OnGetAO, event)

    def OnClose(self, event):
        del self.hm
        self.Destroy()

if __name__ == '__main__':
    app = wx.PySimpleApp(0)
    frame = myFrame()
    app.SetTopWindow(frame)
    frame.Show()
    app.MainLoop()

This code works fine, however when I press minimize or close button,
window of program freezes on some time. The reason may be in the
HookMouse, without it, window minimize and close fine. Why?

import wx
import pyHook

class myFrame(wx.Frame):
     def __init__(self):
         wx.Frame.__init__(self, None, -1, 'My Frame')
         self.tc=wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.DefaultSize,
         wx.TE_MULTILINE|wx.TE_NOHIDESEL|wx.TE_READONLY)

         self.hm = pyHook.HookManager()
         self.hm.KeyDown = self.OnKeyboardEvent

         self.hm.HookKeyboard()
         self.hm.MouseLeftDown=self.OnKeyboardEvent
         self.hm.HookMouse()

         wx.EVT_CLOSE(self, self.OnClose)

     def OnGetAO(self, event):
         self.tc.Value+=event.MessageName+"\n"

     def OnKeyboardEvent(self, event):
         wx.CallAfter(self.OnGetAO, event)

Try adding a "return True" here. That should cause pyHook to tell the system to continue processing the event normally after your handler has been run. IOW, to not block the default processing of the event.

···

On 2/8/12 5:28 AM, Ambyte wrote:

     def OnClose(self, event):
         del self.hm
         self.Destroy()

if __name__ == '__main__':
     app = wx.PySimpleApp(0)
     frame = myFrame()
     app.SetTopWindow(frame)
     frame.Show()
     app.MainLoop()

--
Robin Dunn
Software Craftsman

I added “return True” but problem has not disappeared.

If remove all unnecessary and leave only self.hm.HookMouse() (code below), the problem also remains

import wx
import pyHook

class myFrame(wx.Frame):
def init(self):
wx.Frame.init(self, None, -1, ‘My Frame’)
self.tc=wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.DefaultSize,
wx.TE_MULTILINE|wx.TE_NOHIDESEL|wx.TE_READONLY)

    [self.hm](http://self.hm/) = pyHook.HookManager() 
    self.hm.HookMouse() 

    wx.EVT_CLOSE(self, self.OnClose) 

def OnClose(self, event): 
    del [self.hm](http://self.hm/) 
    self.Destroy() 

if name == ‘main’:
app = wx.PySimpleApp(0)
frame = myFrame()
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()

Have you tried asking on the pyHook forum?

···

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=enhttp://sourceforge.net/forum/forum.php?forum_id=850395