How to use Widget Inspection Tool - WIT (Phoenix)
Keywords : Inspection tool, Widget.
Contents
Introduction :
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.
Demonstrating :
Tested py3.x, wx4.x and Win10.
Are you ready to use some samples ?
Test, modify, correct, complete, improve and share your discoveries !
Sample one
1 # sample_one.py
2
3 import wx
4 import wx.lib.mixins.inspection
5
6 # class MyFrame
7 # class MyApp
8
9 #---------------------------------------------------------------------------
10
11 class MyFrame(wx.Frame):
12 def __init__(self):
13 wx.Frame.__init__(self, None, title="Widget Inspection Tool - WIT")
14
15 #------------
16
17 self.SetIcon(wx.Icon("icons/wxwin.ico"))
18
19 #---------------------------------------------------------------------------
20
21 class MyApp(wx.App, wx.lib.mixins.inspection.InspectionMixin):
22 def OnInit(self):
23
24 # Initialize the inspection tool.
25 self.Init()
26
27 #------------
28
29 frame = MyFrame()
30 frame.Show()
31 self.SetTopWindow(frame)
32
33 return True
34
35 #---------------------------------------------------------------------------
36
37 def main():
38 app = MyApp(redirect=False)
39 app.MainLoop()
40
41 #---------------------------------------------------------------------------
42
43 if __name__ == "__main__" :
44 main()
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:
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.
Filling: Toggle the display of the PyFilling portion of the PyCrust window at the bottom of the inspection tool.
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.
Download source
Additional Information
Link :
- - - - -
https://wiki.wxpython.org/TitleIndex
Thanks to
Robin Dunn, the wxPython community...
About this page
Date(d/m/y) Person (bot) Comments :
14/06/20 - Ecco (Updated page for wxPython Phoenix).
Comments
- blah, blah, blah...