The Holy Grail - Introspection on hotkey

I did something which I think is very cool. I created a base app class
that puts a sleeper PyCrust into a wxPython App that derives from it
when a debug constant is defined. The magic is that when you press
ALT+SHIFT+I you get PyCrust pop up (change the position if you use it,
I set this up to popup on my second monitor) and app will be the
application object, but win is the object the mouse pointer was over.
I find this exceptionally cool to dig into my app and find out what's
going on, or just to try things out.

class Application(wx.App):
    if DEBUG:
        def OnInit(self):
            wx.InitAllImageHandlers()
            self.crust = py.crust.CrustFrame()
            self.crust.SetPosition((-1250,40))
            self.crust.SetSize((1150, 900))
            self.crust.shell.interp.locals['app'] = self

            self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPress)

            return True

        def OnKeyPress(self, event):
            if event.AltDown() and event.KeyCode == ord('I'):
                win = wx.FindWindowAtPointer()
                self.crust.shell.interp.locals['win'] = win
                self.crust.Show(True)
            else:
                event.Skip()

I was amazed it was this easy. Don't forget to change the position and
call OnInit from the derived App class should you use this. Anyway
just thought it was too cool not to share, even if it might be "been
there done that" for many people here.

I can't figure out how to close PyCrust when the application exits. I
have an OnExit() method, but calling self.crust.Close() from there
doesn't do anything other than cause a GC error (maybe because
.Close() triggers a close event?)

-Dan

Dan Eloff wrote:

I did something which I think is very cool. I created a base app class
that puts a sleeper PyCrust into a wxPython App that derives from it
when a debug constant is defined. The magic is that when you press
ALT+SHIFT+I you get PyCrust pop up (change the position if you use it,
I set this up to popup on my second monitor) and app will be the
application object, but win is the object the mouse pointer was over.
I find this exceptionally cool to dig into my app and find out what's
going on, or just to try things out.

Yes, it's a very good idea. I've adapted it to be a mix-in class in the wx.lib.mixins.inspect module, and have changed the activation key to Ctrl-Alt-I (or Cmd-Alt-I on the Mac).

I can't figure out how to close PyCrust when the application exits.

Just make the parent window of the Crust frame be self.GetTopWindow(). Then the Crust frame will close when whatever is set as the top window closes. That should cover most cases, and for the rest the Crust frame can just be brought back again with another Ctrl-Alt-I.

···

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

Is this going to be in some 2.6.x or only later in 2.7.something ?

If not, could a kind soul add this recipe to the wxPython wiki ?

Karsten

···

On Tue, Nov 21, 2006 at 10:40:56AM -0800, Robin Dunn wrote:

Yes, it's a very good idea. I've adapted it to be a mix-in class in the
wx.lib.mixins.inspect module, and have changed the activation key to
Ctrl-Alt-I (or Cmd-Alt-I on the Mac).

--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

evt.KeyCode is a property now (the method remains for backwards
compatability). Many wx classes have been updated in this way. If
you're backporting this to an older version of wxPython, then you will
need to make the change above.

···

On 12/13/06, Don Taylor <nospamformeSVP@gmail.com> wrote:

Robin Dunn wrote:

> The module is in cvs
> here:http://cvs.wxwidgets.org/viewcvs.cgi/wxWidgets/wxPython/wx/lib/mixins/inspect.py?rev=1.1&content-type=text/vnd.viewcvs-markup
>
I think that there is an error in this line in OnKeyPress():

         if evt.AltDown() and evt.CmdDown() and evt.KeyCode == ord('I'):

maybe it should read:

         if evt.AltDown() and evt.CmdDown() and evt.KeyCode() == ord('I'):

Don.