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