wxPython Widget Inspection Tool

WITscreenshot.png

This is a screen shot of the wxPython Widget Inspection Tool in action, being run with one of the samples from the wxPython demo. Notice how the tree is showing all of the widgets and sizers in the application, how some of the common properties of the selected item are shown, and how you can interact with the live widget or sizer in an interactive interpreter. In the interpreter the name 'obj' will always refer to the item currently selected in the tree, so this makes it easy to call methods or look at properties of an item you are interested in.

You can add an inspection tool to your own application with just these two lines of code:

   1 import wx.lib.inspection
   2 wx.lib.inspection.InspectionTool().Show()

A good place for that code is in some menu item handler, or even just right before the call to MainLoop if you want it to always be shown.

You can also structure your application so that the inspection tool is activated via a hot-key, and it will also preselect the item under the mouse cursor when the tool is shown. This is accomplished by adding a mixin class to your own application class. For example:

   1 import wx
   2 import wx.lib.mixins.inspection
   3 
   4 class MyFrame(wx.Frame):
   5     pass
   6  
   7 class MyApp(wx.App, wx.lib.mixins.inspection.InspectionMixin):
   8     def OnInit(self):
   9         self.Init()  # initialize the inspection tool
  10         frame = MyFrame(None, title="This is a test")
  11         frame.Show()
  12         self.SetTopWindow(frame)
  13         return True
  14 
  15 app = MyApp()
  16 app.MainLoop()

The default hot-key when you use the inspection tool mixin like this is Ctrl-Alt-I, or Cmd-Alt-I on Mac, but that can be changed by passing non-default parameters to the Init method. The default position and size can also be changed.

Toolbar buttons

The tools in the inspection tool's toolbar provide the following features:

WITscreenshot2.png

This screenshot shows how the widget inspection tool highlights a wx.FlexGridSizer, with a border drawn around the whole sizer, and dividing lines that highlight the rows and columns as defined by the sizer.

Widget Inspection Tool (last edited 2008-06-26 16:01:18 by 69-30-77-125)