[378d2eb] | 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 | import wx |
---|
[d0923a3] | 11 | import sys |
---|
| 12 | CHILD_FRAME = wx.MDIChildFrame |
---|
| 13 | if sys.platform.count("win32") < 1: |
---|
| 14 | if sys.platform.count("darwin") < 1: |
---|
| 15 | CHILD_FRAME = wx.Frame |
---|
[378d2eb] | 16 | |
---|
| 17 | class InputTextCtrl(wx.TextCtrl): |
---|
| 18 | """ |
---|
| 19 | Text control for model and fit parameters. |
---|
| 20 | Binds the appropriate events for user interactions. |
---|
| 21 | """ |
---|
[943cacb] | 22 | def __init__(self, parent = None, *args, **kwds): |
---|
[378d2eb] | 23 | |
---|
[943cacb] | 24 | wx.TextCtrl.__init__(self, parent, *args, **kwds) |
---|
[378d2eb] | 25 | |
---|
[b0ab6cb] | 26 | ## Set to True when the mouse is clicked while the whole |
---|
| 27 | #string is selected |
---|
| 28 | self.full_selection = False |
---|
[378d2eb] | 29 | ## Call back for EVT_SET_FOCUS events |
---|
| 30 | _on_set_focus_callback = None |
---|
| 31 | # Bind appropriate events |
---|
| 32 | self.Bind(wx.EVT_LEFT_UP, self._highlight_text) |
---|
| 33 | self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus) |
---|
[943cacb] | 34 | self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter ) |
---|
[378d2eb] | 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() |
---|
[b0ab6cb] | 60 | if start == end: |
---|
| 61 | control.SetSelection(-1, -1) |
---|
[378d2eb] | 62 | |
---|
[b7e0fff] | 63 | |
---|
| 64 | class InterActiveOutputTextCtrl(wx.TextCtrl): |
---|
[378d2eb] | 65 | """ |
---|
| 66 | Text control used to display outputs. |
---|
| 67 | No editing allowed. The background is |
---|
| 68 | grayed out. User can't select text. |
---|
| 69 | """ |
---|
| 70 | def __init__(self, *args, **kwds): |
---|
| 71 | wx.TextCtrl.__init__(self, *args, **kwds) |
---|
| 72 | self.SetEditable(False) |
---|
| 73 | self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) |
---|
| 74 | |
---|
[b7e0fff] | 75 | class OutputTextCtrl(InterActiveOutputTextCtrl): |
---|
| 76 | """ |
---|
| 77 | Text control used to display outputs. |
---|
| 78 | No editing allowed. The background is |
---|
| 79 | grayed out. User can't select text. |
---|
| 80 | """ |
---|
| 81 | def __init__(self, *args, **kwds): |
---|
| 82 | InterActiveOutputTextCtrl.__init__(self, *args, **kwds) |
---|
| 83 | self.SetEditable(False) |
---|
| 84 | self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) |
---|
| 85 | |
---|
[378d2eb] | 86 | # Bind to mouse event to avoid text highlighting |
---|
| 87 | # The event will be skipped once the call-back |
---|
| 88 | # is called. |
---|
| 89 | self.Bind(wx.EVT_MOUSE_EVENTS, self._click) |
---|
| 90 | |
---|
| 91 | def _click(self, event): |
---|
| 92 | """ |
---|
| 93 | Prevent further handling of the mouse event |
---|
| 94 | by not calling Skip(). |
---|
| 95 | """ |
---|
| 96 | pass |
---|
[b7e0fff] | 97 | |
---|
| 98 | |
---|