source: sasview/src/sas/sasgui/perspectives/invariant/invariant_widgets.py @ 7cbbacd

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 7cbbacd was d85c194, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago

Remaining modules refactored

  • Property mode set to 100644
File size: 6.1 KB
RevLine 
[d7a39e5]1################################################################################
[78a205a]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.
[d7a39e5]5#
[78a205a]6# See the license text in license.txt
[d7a39e5]7#
[78a205a]8# copyright 2009, University of Tennessee
[d7a39e5]9################################################################################
10
[518d35d]11import wx
[cacbd7d]12from wx.lib.scrolledpanel import ScrolledPanel
[518d35d]13
[cacbd7d]14WIDTH = 400
[9cec2dd]15HEIGHT = 350
16
17class DialogPanel(ScrolledPanel):
18    def __init__(self, *args, **kwds):
19        ScrolledPanel.__init__(self, *args, **kwds)
20        self.SetupScrolling()
[78a205a]21
[518d35d]22class InvTextCtrl(wx.TextCtrl):
23    """
[d7a39e5]24    Text control for model and fit parameters.
25    Binds the appropriate events for user interactions.
[518d35d]26    """
27    def __init__(self, *args, **kwds):
28        wx.TextCtrl.__init__(self, *args, **kwds)
[78a205a]29        # # Set to True when the mouse is clicked while
30        # the whole string is selected
[4e1c362]31        self.full_selection = False
[78a205a]32        # # Call back for EVT_SET_FOCUS events
[518d35d]33        _on_set_focus_callback = None
[4e1c362]34
[518d35d]35        # Bind appropriate events
36        self.Bind(wx.EVT_LEFT_UP, self._highlight_text)
37        self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus)
[78a205a]38
[518d35d]39    def _on_set_focus(self, event):
40        """
[d7a39e5]41        Catch when the text control is set in focus to highlight the whole
42        text if necessary
[78a205a]43
[d7a39e5]44        :param event: mouse event
[518d35d]45        """
46        event.Skip()
47        self.full_selection = True
[78a205a]48
[518d35d]49    def _highlight_text(self, event):
50        """
[d7a39e5]51        Highlight text of a TextCtrl only of no text has be selected
[78a205a]52
[d7a39e5]53        :param event: mouse event
[518d35d]54        """
55        # Make sure the mouse event is available to other listeners
56        event.Skip()
[78a205a]57        control = event.GetEventObject()
[518d35d]58        if self.full_selection:
59            self.full_selection = False
60            # Check that we have a TextCtrl
61            if issubclass(control.__class__, wx.TextCtrl):
[78a205a]62                # Check whether text has been selected,
[518d35d]63                # if not, select the whole string
64                (start, end) = control.GetSelection()
[4a2b054]65                if start == end:
66                    control.SetSelection(-1, -1)
[78a205a]67
[518d35d]68
69class OutputTextCtrl(wx.TextCtrl):
70    """
[d7a39e5]71    Text control used to display outputs.
[78a205a]72    No editing allowed. The background is
[d7a39e5]73    grayed out. User can't select text.
[518d35d]74    """
75    def __init__(self, *args, **kwds):
76        wx.TextCtrl.__init__(self, *args, **kwds)
77        self.SetEditable(False)
78        self.SetBackgroundColour(self.GetParent().GetBackgroundColour())
[78a205a]79
[518d35d]80        # Bind to mouse event to avoid text highlighting
81        # The event will be skipped once the call-back
82        # is called.
[78a205a]83
[518d35d]84        self.Bind(wx.EVT_MOUSE_EVENTS, self._click)
[4e1c362]85
[78a205a]86
[518d35d]87    def _click(self, event):
88        """
[d7a39e5]89        Prevent further handling of the mouse event
90        by not calling Skip().
[78a205a]91        """
[518d35d]92        pass
[78a205a]93
[cacbd7d]94class DataDialog(wx.Dialog):
95    """
96    Allow file selection at loading time
97    """
98    def __init__(self, data_list, parent=None, text='', *args, **kwds):
[9cec2dd]99        kwds['size'] = (WIDTH, HEIGHT)
100        kwds['title'] = "Data Selection"
[cacbd7d]101        wx.Dialog.__init__(self, parent, *args, **kwds)
102        self.list_of_ctrl = []
103        self._sizer_main = wx.BoxSizer(wx.VERTICAL)
104        self._sizer_txt = wx.BoxSizer(wx.VERTICAL)
105        self._sizer_button = wx.BoxSizer(wx.HORIZONTAL)
106        self._choice_sizer = wx.GridBagSizer(5, 5)
[9cec2dd]107        self._panel = DialogPanel(self, style=wx.RAISED_BORDER,
[78a205a]108                                  size=(WIDTH - 20, HEIGHT / 3))
[9cec2dd]109        self.SetSizer(self._sizer_main)
[cacbd7d]110        self.__do_layout(data_list, text=text)
[9cec2dd]111        self.Layout()
[78a205a]112
[cacbd7d]113    def __do_layout(self, data_list, text=''):
114        """
115        layout the dialog
116        """
[78a205a]117        # add text
[cacbd7d]118        if text.strip() == "":
119            text = "This Perspective does not allow multiple data !\n"
120            text += "Please select only one Data.\n"
[9cec2dd]121        text_ctrl = wx.TextCtrl(self, -1, str(text), style=wx.TE_MULTILINE,
[78a205a]122                                size=(-1, HEIGHT / 3))
[9cec2dd]123        text_ctrl.SetEditable(False)
[78a205a]124        self._sizer_txt.Add(text_ctrl, 1, wx.EXPAND | wx.ALL, 10)
[cacbd7d]125        iy = 0
126        ix = 0
[78a205a]127        rbox = wx.RadioButton(self._panel, -1, str(data_list[0].name),
128                              (10, 10), style=wx.RB_GROUP)
[cacbd7d]129        rbox.SetValue(True)
130        self.list_of_ctrl.append((rbox, data_list[0]))
131        self._choice_sizer.Add(rbox, (iy, ix), (1, 1),
[78a205a]132                               wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
[cacbd7d]133        for i in range(1, len(data_list)):
134            iy += 1
[78a205a]135            rbox = wx.RadioButton(self._panel, -1,
[cacbd7d]136                                  str(data_list[i].name), (10, 10))
137            rbox.SetValue(False)
138            self.list_of_ctrl.append((rbox, data_list[i]))
139            self._choice_sizer.Add(rbox, (iy, ix),
[78a205a]140                                   (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
[cacbd7d]141        self._panel.SetSizer(self._choice_sizer)
[78a205a]142        # add sizer
143        self._sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
[cacbd7d]144        button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
145        self._sizer_button.Add(button_cancel, 0,
[78a205a]146                               wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10)
[cacbd7d]147        button_OK = wx.Button(self, wx.ID_OK, "Ok")
148        button_OK.SetFocus()
149        self._sizer_button.Add(button_OK, 0,
[78a205a]150                               wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10)
[cacbd7d]151        static_line = wx.StaticLine(self, -1)
[78a205a]152
153        self._sizer_txt.Add(self._panel, 0, wx.EXPAND | wx.ALL, 5)
154        self._sizer_main.Add(self._sizer_txt, 0, wx.EXPAND | wx.ALL, 5)
[cacbd7d]155        self._sizer_main.Add(static_line, 0, wx.EXPAND, 0)
[78a205a]156        self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND | wx.ALL, 10)
157
[cacbd7d]158    def get_data(self):
159        """
160        return the selected data
161        """
162        for item in self.list_of_ctrl:
163            rbox, data = item
164            if rbox.GetValue():
[78a205a]165                return data
Note: See TracBrowser for help on using the repository browser.