wxPython Widget Inspection Tool
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:
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.
The tools in the inspection tool's toolbar provide the following features:
Refresh: Rebuilds the widget tree on the left side of the tool, attempting to reselect the same item if it still exists. You would want to use this if any items in your GUI have been added or removed since the last time the tool was refreshed.
Find: After you click on this button you can then click on any widget in the application and the inspection tool will attempt to locate that item in the tree and select it. You can even click on items in the inspection tool itself since it is also running within your application.
Sizers: Toggle the display of sizers in the tree.
Expand: Expand all nodes in the widget tree.
Collapse: Collapse all nodes in the widget tree except those needed to show the current item.
Highlight: Highlight in the live window the item that is currently selected in the widget tree. Top-level windows will be flickered, and other items will have borders drawn around them for a few seconds, as shown in the screenshot below.
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.