Changeset 8b21fa7 in sasview for src/sas/perspectives/pr/pr_widgets.py
- Timestamp:
- Mar 6, 2015 2:05:50 PM (10 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- b1e609c
- Parents:
- c1c14ba
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/perspectives/pr/pr_widgets.py
r79492222 r8b21fa7 3 3 #This software was developed by the University of Tennessee as part of the 4 4 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 5 #project funded by the US National Science Foundation. 5 #project funded by the US National Science Foundation. 6 6 # 7 7 #See the license text in license.txt … … 26 26 ScrolledPanel.__init__(self, *args, **kwds) 27 27 self.SetupScrolling() 28 29 28 29 30 30 class PrTextCtrl(wx.TextCtrl): 31 31 """ … … 34 34 """ 35 35 def __init__(self, *args, **kwds): 36 36 37 37 wx.TextCtrl.__init__(self, *args, **kwds) 38 38 39 39 ## Set to True when the mouse is clicked while the whole string is selected 40 40 self.full_selection = False … … 49 49 Catch when the text control is set in focus to highlight the whole 50 50 text if necessary 51 51 52 52 :param event: mouse event 53 53 54 54 """ 55 55 event.Skip() 56 56 self.full_selection = True 57 57 58 58 def _highlight_text(self, event): 59 59 """ 60 60 Highlight text of a TextCtrl only of no text has be selected 61 61 62 62 :param event: mouse event 63 63 64 64 """ 65 65 # Make sure the mouse event is available to other listeners 66 66 event.Skip() 67 control 67 control = event.GetEventObject() 68 68 if self.full_selection: 69 69 self.full_selection = False 70 70 # Check that we have a TextCtrl 71 71 if issubclass(control.__class__, wx.TextCtrl): 72 # Check whether text has been selected, 72 # Check whether text has been selected, 73 73 # if not, select the whole string 74 74 (start, end) = control.GetSelection() 75 if start ==end:76 control.SetSelection(-1, -1)75 if start == end: 76 control.SetSelection(-1, -1) 77 77 78 78 class OutputTextCtrl(wx.TextCtrl): 79 79 """ 80 80 Text control used to display outputs. 81 No editing allowed. The background is 81 No editing allowed. The background is 82 82 grayed out. User can't select text. 83 83 """ … … 88 88 self.SetEditable(False) 89 89 self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) 90 90 91 91 # Bind to mouse event to avoid text highlighting 92 92 # The event will be skipped once the call-back 93 93 # is called. 94 94 self.Bind(wx.EVT_MOUSE_EVENTS, self._click) 95 95 96 96 def _click(self, event): 97 97 """ 98 98 Prevent further handling of the mouse event 99 99 by not calling Skip(). 100 """ 100 """ 101 101 pass 102 102 103 103 104 104 class DataFileTextCtrl(OutputTextCtrl): … … 106 106 Text control used to display only the file name 107 107 given a full path. 108 108 109 109 :TODO: now that we no longer choose the data file from the panel, 110 110 it's no longer necessary to pass around the file path. That code 111 should be refactored away and simplified. 111 should be refactored away and simplified. 112 112 """ 113 113 def __init__(self, *args, **kwds): … … 116 116 OutputTextCtrl.__init__(self, *args, **kwds) 117 117 self._complete_path = None 118 118 119 119 def SetValue(self, value): 120 120 """ … … 122 122 """ 123 123 self._complete_path = str(value) 124 file = os.path.basename(self._complete_path)125 OutputTextCtrl.SetValue(self, file )126 124 file_path = os.path.basename(self._complete_path) 125 OutputTextCtrl.SetValue(self, file_path) 126 127 127 def GetValue(self): 128 128 """ … … 130 130 """ 131 131 return self._complete_path 132 133 134 135 132 133 136 134 def load_error(error=None): 137 135 """ 138 136 Pop up an error message. 139 137 140 138 :param error: details error message to be displayed 141 139 """ 142 140 message = "The data file you selected could not be loaded.\n" 143 141 message += "Make sure the content of your file is properly formatted.\n\n" 144 142 145 143 if error is not None: 146 144 message += "When contacting the DANSE team, mention the" 147 145 message += " following:\n%s" % str(error) 148 146 149 147 dial = wx.MessageDialog(None, message, 'Error Loading File', 150 148 wx.OK | wx.ICON_EXCLAMATION) 151 dial.ShowModal() 152 153 149 dial.ShowModal() 150 151 154 152 class DataDialog(wx.Dialog): 155 153 """ … … 166 164 self._choice_sizer = wx.GridBagSizer(5, 5) 167 165 self._panel = DialogPanel(self, style=wx.RAISED_BORDER, 168 size=(WIDTH-20, HEIGHT/3))169 166 size=(WIDTH - 20, HEIGHT / 3)) 167 170 168 self.__do_layout(data_list, text=text) 171 172 169 173 170 def __do_layout(self, data_list, text=''): 174 171 """ 175 172 layout the dialog 176 173 """ 177 #if not data_list or len(data_list) <= 1:178 # return179 174 #add text 180 175 if text.strip() == "": … … 182 177 text += "Please select only one Data.\n" 183 178 text_ctrl = wx.TextCtrl(self, -1, str(text), style=wx.TE_MULTILINE, 184 size=(-1, HEIGHT /3))179 size=(-1, HEIGHT / 3)) 185 180 text_ctrl.SetEditable(False) 186 self._sizer_txt.Add(text_ctrl , 1, wx.EXPAND|wx.ALL, 10)181 self._sizer_txt.Add(text_ctrl, 1, wx.EXPAND | wx.ALL, 10) 187 182 iy = 0 188 183 ix = 0 189 rbox = wx.RadioButton(self._panel, -1, str(data_list[0].name), 190 (10, 10), style=wx.RB_GROUP)184 rbox = wx.RadioButton(self._panel, -1, str(data_list[0].name), 185 (10, 10), style=wx.RB_GROUP) 191 186 rbox.SetValue(True) 192 187 self.list_of_ctrl.append((rbox, data_list[0])) 193 188 self._choice_sizer.Add(rbox, (iy, ix), (1, 1), 194 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)189 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 195 190 for i in range(1, len(data_list)): 196 191 iy += 1 197 rbox = wx.RadioButton(self._panel, -1, 192 rbox = wx.RadioButton(self._panel, -1, 198 193 str(data_list[i].name), (10, 10)) 199 194 rbox.SetValue(False) 200 195 self.list_of_ctrl.append((rbox, data_list[i])) 201 196 self._choice_sizer.Add(rbox, (iy, ix), 202 (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)197 (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 203 198 self._panel.SetSizer(self._choice_sizer) 204 199 #add sizer 205 self._sizer_button.Add((20, 20), 1, wx.EXPAND |wx.ADJUST_MINSIZE, 0)200 self._sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 206 201 button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") 207 202 self._sizer_button.Add(button_cancel, 0, 208 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)209 button_ OK= wx.Button(self, wx.ID_OK, "Ok")210 button_ OK.SetFocus()211 self._sizer_button.Add(button_ OK, 0,212 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)203 wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 204 button_ok = wx.Button(self, wx.ID_OK, "Ok") 205 button_ok.SetFocus() 206 self._sizer_button.Add(button_ok, 0, 207 wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 213 208 static_line = wx.StaticLine(self, -1) 214 215 self._sizer_txt.Add(self._panel, 0, wx.EXPAND |wx.ALL, 5)216 self._sizer_main.Add(self._sizer_txt, 0, wx.EXPAND |wx.ALL, 5)209 210 self._sizer_txt.Add(self._panel, 0, wx.EXPAND | wx.ALL, 5) 211 self._sizer_main.Add(self._sizer_txt, 0, wx.EXPAND | wx.ALL, 5) 217 212 self._sizer_main.Add(static_line, 0, wx.EXPAND, 0) 218 self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND |wx.ALL, 10)213 self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND | wx.ALL, 10) 219 214 self.SetSizer(self._sizer_main) 220 215 221 216 def get_data(self): 222 217 """ … … 226 221 rbox, data = item 227 222 if rbox.GetValue(): 228 return data 229 230 231 232 223 return data
Note: See TracChangeset
for help on using the changeset viewer.