]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/mixins/inspection.py
1 #----------------------------------------------------------------------------
2 # Name: wx.lib.mixins.inspection
3 # Purpose: A mix-in class that can add PyCrust-based inspection of the
4 # app's widgets and sizers.
10 # Copyright: (c) 2006 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------------
14 # NOTE: This class was originally based on ideas sent to the
15 # wxPython-users mail list by Dan Eloff.
18 from wx
.lib
.inspection
import InspectionTool
21 #----------------------------------------------------------------------------
23 class InspectionMixin(object):
25 This class is intended to be used as a mix-in with the wx.App
26 class. When used it will add the ability to popup a
27 InspectionFrame window where the widget under the mouse cursor
28 will be selected in the tree and loaded into the shell's namespace
29 as 'obj'. The default key sequence to activate the inspector is
30 Ctrl-Alt-I (or Cmd-Alt-I on Mac) but this can be changed via
31 parameters to the `Init` method, or the application can call
32 `ShowInspectionTool` from other event handlers if desired.
34 To use this class simply derive a class from wx.App and
35 InspectionMixin and then call the `Init` method from the app's
38 def Init(self
, pos
=wx
.DefaultPosition
, size
=wx
.Size(850,700),
39 config
=None, locals=None,
40 alt
=True, cmd
=True, shift
=False, keyCode
=ord('I')):
42 Make the event binding that will activate the InspectionFrame window.
44 self
.Bind(wx
.EVT_KEY_DOWN
, self
._OnKeyPress
)
48 self
._keyCode
= keyCode
49 InspectionTool().Init(pos
, size
, config
, locals, self
)
51 def _OnKeyPress(self
, evt
):
53 Event handler, check for our hot-key. Normally it is
54 Ctrl-Alt-I but that can be changed by what is passed to the
57 if evt
.AltDown() == self
._alt
and \
58 evt
.CmdDown() == self
._cmd
and \
59 evt
.ShiftDown() == self
._shift
and \
60 evt
.GetKeyCode() == self
._keyCode
:
61 self
.ShowInspectionTool()
66 def ShowInspectionTool(self
):
68 Show the Inspection tool, creating it if neccesary, setting it
69 to display the widget under the cursor.
71 # get the current widget under the mouse
72 wnd
= wx
.FindWindowAtPointer()
73 InspectionTool().Show(wnd
)
76 #---------------------------------------------------------------------------
78 class InspectableApp(wx
.App
, InspectionMixin
):
80 A simple mix of wx.App and InspectionMixin that can be used stand-alone.
87 #---------------------------------------------------------------------------