]>
Commit | Line | Data |
---|---|---|
ea839c29 VZ |
1 | #---------------------------------------------------------------------------- |
2 | # Name: wx.lib.mixins.inspect | |
3 | # Purpose: A mix-in class that can add PyCrust-based inspection of the app | |
4 | # | |
5 | # Author: Robin Dunn | |
6 | # | |
7 | # Created: 21-Nov-2006 | |
8 | # RCS-ID: $Id$ | |
9 | # Copyright: (c) 2006 by Total Control Software | |
10 | # Licence: wxWindows license | |
11 | #---------------------------------------------------------------------------- | |
12 | ||
13 | # NOTE: This class is based on ideas sent to the wxPython-users | |
359ed0f8 | 14 | # mail-list by Dan Eloff. |
ea839c29 VZ |
15 | |
16 | import wx.py | |
17 | ||
18 | class InspectionMixin(object): | |
19 | """ | |
20 | This class is intended to be used as a mix-in with the wx.App | |
21 | object. When used it will add the ability to popup a PyCrust | |
22 | window where the widget under the mouse cursor will be loaded into | |
23 | the shell's namespace as 'win'. | |
24 | ||
25 | To use this class simply derive a class from wx.App and | |
26 | InspectionMixin and then call the Init() method from the app's | |
27 | OnInit. | |
359ed0f8 RD |
28 | """ |
29 | def Init(self, pos=(-1, -1), size=(-1, -1)): | |
ea839c29 VZ |
30 | """ |
31 | Make the event binding that will activate the PyCrust window. | |
32 | """ | |
33 | self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPress) | |
34 | self._crust = None | |
359ed0f8 RD |
35 | self._pos = pos |
36 | self._size = size | |
ea839c29 VZ |
37 | |
38 | ||
39 | def OnKeyPress(self, evt): | |
40 | """ | |
41 | Event handler | |
42 | """ | |
43 | if evt.AltDown() and evt.CmdDown() and evt.KeyCode == ord('I'): | |
44 | self.ShowShell() | |
45 | else: | |
46 | evt.Skip() | |
47 | ||
48 | ||
49 | def ShowShell(self): | |
50 | """ | |
51 | Show the PyCrust window. | |
52 | """ | |
53 | if not self._crust: | |
359ed0f8 RD |
54 | self._crust = wx.py.crust.CrustFrame(self.GetTopWindow(), |
55 | pos = self._pos, size = self._size) | |
ea839c29 VZ |
56 | self._crust.shell.interp.locals['app'] = self |
57 | win = wx.FindWindowAtPointer() | |
58 | self._crust.shell.interp.locals['win'] = win | |
59 | self._crust.Show() |