[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 |
---|
| 17 | |
---|
| 18 | class InvTextCtrl(wx.TextCtrl): |
---|
| 19 | """ |
---|
[d7a39e5] | 20 | Text control for model and fit parameters. |
---|
| 21 | Binds the appropriate events for user interactions. |
---|
[518d35d] | 22 | """ |
---|
| 23 | def __init__(self, *args, **kwds): |
---|
| 24 | |
---|
| 25 | wx.TextCtrl.__init__(self, *args, **kwds) |
---|
| 26 | |
---|
| 27 | ## Set to True when the mouse is clicked while the whole string is selected |
---|
| 28 | full_selection = False |
---|
| 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) |
---|
| 34 | |
---|
| 35 | def _on_set_focus(self, event): |
---|
| 36 | """ |
---|
[d7a39e5] | 37 | Catch when the text control is set in focus to highlight the whole |
---|
| 38 | text if necessary |
---|
| 39 | |
---|
| 40 | :param event: mouse event |
---|
| 41 | |
---|
[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 |
---|
| 51 | |
---|
[518d35d] | 52 | """ |
---|
| 53 | # Make sure the mouse event is available to other listeners |
---|
| 54 | event.Skip() |
---|
| 55 | control = event.GetEventObject() |
---|
| 56 | if self.full_selection: |
---|
| 57 | self.full_selection = False |
---|
| 58 | # Check that we have a TextCtrl |
---|
| 59 | if issubclass(control.__class__, wx.TextCtrl): |
---|
| 60 | # Check whether text has been selected, |
---|
| 61 | # if not, select the whole string |
---|
| 62 | (start, end) = control.GetSelection() |
---|
| 63 | if start==end: |
---|
| 64 | control.SetSelection(-1,-1) |
---|
| 65 | |
---|
| 66 | class OutputTextCtrl(wx.TextCtrl): |
---|
| 67 | """ |
---|
[d7a39e5] | 68 | Text control used to display outputs. |
---|
| 69 | No editing allowed. The background is |
---|
| 70 | grayed out. User can't select text. |
---|
[518d35d] | 71 | """ |
---|
| 72 | def __init__(self, *args, **kwds): |
---|
| 73 | wx.TextCtrl.__init__(self, *args, **kwds) |
---|
| 74 | self.SetEditable(False) |
---|
| 75 | self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) |
---|
| 76 | |
---|
| 77 | # Bind to mouse event to avoid text highlighting |
---|
| 78 | # The event will be skipped once the call-back |
---|
| 79 | # is called. |
---|
| 80 | self.Bind(wx.EVT_MOUSE_EVENTS, self._click) |
---|
| 81 | |
---|
| 82 | def _click(self, event): |
---|
| 83 | """ |
---|
[d7a39e5] | 84 | Prevent further handling of the mouse event |
---|
| 85 | by not calling Skip(). |
---|
[518d35d] | 86 | """ |
---|
| 87 | pass |
---|
| 88 | |
---|