]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/mixins/inspection.py
Patch from Andrea that fixes the following problems/issues:
[wxWidgets.git] / 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.
5 #
6 # Author: Robin Dunn
7 #
8 # Created: 21-Nov-2006
9 # RCS-ID: $Id$
10 # Copyright: (c) 2006 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------------
13
14 # NOTE: This class was originally based on ideas sent to the
15 # wxPython-users mail list by Dan Eloff.
16
17 import wx
18 from wx.lib.inspection import InspectionTool
19
20
21 #----------------------------------------------------------------------------
22
23 class InspectionMixin(object):
24 """
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.
33
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
36 OnInit.
37 """
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')):
41 """
42 Make the event binding that will activate the InspectionFrame window.
43 """
44 self.Bind(wx.EVT_KEY_DOWN, self._OnKeyPress)
45 self._alt = alt
46 self._cmd = cmd
47 self._shift = shift
48 self._keyCode = keyCode
49 InspectionTool().Init(pos, size, config, locals, self)
50
51 def _OnKeyPress(self, evt):
52 """
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
55 Init method.
56 """
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()
62 else:
63 evt.Skip()
64
65
66 def ShowInspectionTool(self):
67 """
68 Show the Inspection tool, creating it if neccesary, setting it
69 to display the widget under the cursor.
70 """
71 # get the current widget under the mouse
72 wnd = wx.FindWindowAtPointer()
73 InspectionTool().Show(wnd)
74
75
76 #---------------------------------------------------------------------------
77
78 class InspectableApp(wx.App, InspectionMixin):
79 """
80 A simple mix of wx.App and InspectionMixin that can be used stand-alone.
81 """
82
83 def OnInit(self):
84 self.Init()
85 return True
86
87 #---------------------------------------------------------------------------
88