How to use Widget Inspection Tool - WIT (Phoenix)

Keywords : Inspection tool, Widget.


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.

img_sample_one.png

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.


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:

img_sample_two.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.


Download source

source.zip


Additional Information

Link :

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


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...

How to use Widget Inspection Tool - WIT (Phoenix) (last edited 2020-12-13 13:28:20 by Ecco)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.