[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 |
---|
[b0ab6cb] | 11 | #import os |
---|
[378d2eb] | 12 | |
---|
| 13 | class InputTextCtrl(wx.TextCtrl): |
---|
| 14 | """ |
---|
| 15 | Text control for model and fit parameters. |
---|
| 16 | Binds the appropriate events for user interactions. |
---|
| 17 | """ |
---|
| 18 | def __init__(self, *args, **kwds): |
---|
| 19 | |
---|
| 20 | wx.TextCtrl.__init__(self, *args, **kwds) |
---|
| 21 | |
---|
[b0ab6cb] | 22 | ## Set to True when the mouse is clicked while the whole |
---|
| 23 | #string is selected |
---|
| 24 | self.full_selection = False |
---|
[378d2eb] | 25 | ## Call back for EVT_SET_FOCUS events |
---|
| 26 | _on_set_focus_callback = None |
---|
| 27 | # Bind appropriate events |
---|
| 28 | self.Bind(wx.EVT_LEFT_UP, self._highlight_text) |
---|
| 29 | self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus) |
---|
| 30 | |
---|
| 31 | def _on_set_focus(self, event): |
---|
| 32 | """ |
---|
| 33 | Catch when the text control is set in focus to highlight the whole |
---|
| 34 | text if necessary |
---|
| 35 | @param event: mouse event |
---|
| 36 | """ |
---|
| 37 | event.Skip() |
---|
| 38 | self.full_selection = True |
---|
| 39 | |
---|
| 40 | def _highlight_text(self, event): |
---|
| 41 | """ |
---|
| 42 | Highlight text of a TextCtrl only of no text has be selected |
---|
| 43 | @param event: mouse event |
---|
| 44 | """ |
---|
| 45 | # Make sure the mouse event is available to other listeners |
---|
| 46 | event.Skip() |
---|
| 47 | control = event.GetEventObject() |
---|
| 48 | if self.full_selection: |
---|
| 49 | self.full_selection = False |
---|
| 50 | # Check that we have a TextCtrl |
---|
| 51 | if issubclass(control.__class__, wx.TextCtrl): |
---|
| 52 | # Check whether text has been selected, |
---|
| 53 | # if not, select the whole string |
---|
| 54 | (start, end) = control.GetSelection() |
---|
[b0ab6cb] | 55 | if start == end: |
---|
| 56 | control.SetSelection(-1, -1) |
---|
[378d2eb] | 57 | |
---|
[b7e0fff] | 58 | |
---|
| 59 | class InterActiveOutputTextCtrl(wx.TextCtrl): |
---|
[378d2eb] | 60 | """ |
---|
| 61 | Text control used to display outputs. |
---|
| 62 | No editing allowed. The background is |
---|
| 63 | grayed out. User can't select text. |
---|
| 64 | """ |
---|
| 65 | def __init__(self, *args, **kwds): |
---|
| 66 | wx.TextCtrl.__init__(self, *args, **kwds) |
---|
| 67 | self.SetEditable(False) |
---|
| 68 | self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) |
---|
| 69 | |
---|
[b7e0fff] | 70 | class OutputTextCtrl(InterActiveOutputTextCtrl): |
---|
| 71 | """ |
---|
| 72 | Text control used to display outputs. |
---|
| 73 | No editing allowed. The background is |
---|
| 74 | grayed out. User can't select text. |
---|
| 75 | """ |
---|
| 76 | def __init__(self, *args, **kwds): |
---|
| 77 | InterActiveOutputTextCtrl.__init__(self, *args, **kwds) |
---|
| 78 | self.SetEditable(False) |
---|
| 79 | self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) |
---|
| 80 | |
---|
[378d2eb] | 81 | # Bind to mouse event to avoid text highlighting |
---|
| 82 | # The event will be skipped once the call-back |
---|
| 83 | # is called. |
---|
| 84 | self.Bind(wx.EVT_MOUSE_EVENTS, self._click) |
---|
| 85 | |
---|
| 86 | def _click(self, event): |
---|
| 87 | """ |
---|
| 88 | Prevent further handling of the mouse event |
---|
| 89 | by not calling Skip(). |
---|
| 90 | """ |
---|
| 91 | pass |
---|
[b7e0fff] | 92 | |
---|
| 93 | |
---|