[518d35d] | 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 InvTextCtrl(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 | |
---|
| 57 | class OutputTextCtrl(wx.TextCtrl): |
---|
| 58 | """ |
---|
| 59 | Text control used to display outputs. |
---|
| 60 | No editing allowed. The background is |
---|
| 61 | grayed out. User can't select text. |
---|
| 62 | """ |
---|
| 63 | def __init__(self, *args, **kwds): |
---|
| 64 | wx.TextCtrl.__init__(self, *args, **kwds) |
---|
| 65 | self.SetEditable(False) |
---|
| 66 | self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) |
---|
| 67 | |
---|
| 68 | # Bind to mouse event to avoid text highlighting |
---|
| 69 | # The event will be skipped once the call-back |
---|
| 70 | # is called. |
---|
| 71 | self.Bind(wx.EVT_MOUSE_EVENTS, self._click) |
---|
| 72 | |
---|
| 73 | def _click(self, event): |
---|
| 74 | """ |
---|
| 75 | Prevent further handling of the mouse event |
---|
| 76 | by not calling Skip(). |
---|
| 77 | """ |
---|
| 78 | pass |
---|
| 79 | |
---|