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