1 | """ |
---|
2 | This software was developed by the University of Tennessee as part of the |
---|
3 | Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
4 | project funded by the US National Science Foundation. |
---|
5 | |
---|
6 | See the license text in license.txt |
---|
7 | |
---|
8 | copyright 2009, University of Tennessee |
---|
9 | """ |
---|
10 | |
---|
11 | """ |
---|
12 | Text controls for input/output of the main Invariant panel |
---|
13 | @author: Dr. Mahtieu Doucet |
---|
14 | """ |
---|
15 | |
---|
16 | import wx |
---|
17 | import os |
---|
18 | |
---|
19 | class InvTextCtrl(wx.TextCtrl): |
---|
20 | """ |
---|
21 | Text control for model and fit parameters. |
---|
22 | Binds the appropriate events for user interactions. |
---|
23 | """ |
---|
24 | def __init__(self, *args, **kwds): |
---|
25 | |
---|
26 | wx.TextCtrl.__init__(self, *args, **kwds) |
---|
27 | |
---|
28 | ## Set to True when the mouse is clicked while the whole string is selected |
---|
29 | full_selection = False |
---|
30 | ## Call back for EVT_SET_FOCUS events |
---|
31 | _on_set_focus_callback = None |
---|
32 | # Bind appropriate events |
---|
33 | self.Bind(wx.EVT_LEFT_UP, self._highlight_text) |
---|
34 | self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus) |
---|
35 | |
---|
36 | def _on_set_focus(self, event): |
---|
37 | """ |
---|
38 | Catch when the text control is set in focus to highlight the whole |
---|
39 | text if necessary |
---|
40 | @param event: mouse event |
---|
41 | """ |
---|
42 | event.Skip() |
---|
43 | self.full_selection = True |
---|
44 | |
---|
45 | def _highlight_text(self, event): |
---|
46 | """ |
---|
47 | Highlight text of a TextCtrl only of no text has be selected |
---|
48 | @param event: mouse event |
---|
49 | """ |
---|
50 | # Make sure the mouse event is available to other listeners |
---|
51 | event.Skip() |
---|
52 | control = event.GetEventObject() |
---|
53 | if self.full_selection: |
---|
54 | self.full_selection = False |
---|
55 | # Check that we have a TextCtrl |
---|
56 | if issubclass(control.__class__, wx.TextCtrl): |
---|
57 | # Check whether text has been selected, |
---|
58 | # if not, select the whole string |
---|
59 | (start, end) = control.GetSelection() |
---|
60 | if start==end: |
---|
61 | control.SetSelection(-1,-1) |
---|
62 | |
---|
63 | class OutputTextCtrl(wx.TextCtrl): |
---|
64 | """ |
---|
65 | Text control used to display outputs. |
---|
66 | No editing allowed. The background is |
---|
67 | grayed out. User can't select text. |
---|
68 | """ |
---|
69 | def __init__(self, *args, **kwds): |
---|
70 | wx.TextCtrl.__init__(self, *args, **kwds) |
---|
71 | self.SetEditable(False) |
---|
72 | self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) |
---|
73 | |
---|
74 | # Bind to mouse event to avoid text highlighting |
---|
75 | # The event will be skipped once the call-back |
---|
76 | # is called. |
---|
77 | self.Bind(wx.EVT_MOUSE_EVENTS, self._click) |
---|
78 | |
---|
79 | def _click(self, event): |
---|
80 | """ |
---|
81 | Prevent further handling of the mouse event |
---|
82 | by not calling Skip(). |
---|
83 | """ |
---|
84 | pass |
---|
85 | |
---|