Changeset 4a2b054 in sasview for invariantview/perspectives
- Timestamp:
- Nov 22, 2010 10:36:42 AM (14 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:
- 32c0841
- Parents:
- cbaa2f4
- Location:
- invariantview/perspectives/invariant
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
invariantview/perspectives/invariant/__init__.py
r85a24d9 r4a2b054 24 24 media_path = os.path.join(path, media) 25 25 if os.path.isdir(media_path): 26 module_media_path = os.path.join(media_path,'invariant_media')27 28 29 26 module_media_path = os.path.join(media_path, 'invariant_media') 27 if os.path.isdir(module_media_path): 28 return module_media_path 29 return media_path 30 30 31 31 raise RuntimeError('Could not find invariant media files') … … 39 39 40 40 """ 41 data_files = []41 data_files = [] 42 42 path = get_data_path(media="media") 43 43 for f in findall(path): -
invariantview/perspectives/invariant/help_panel.py
rd7a39e5 r4a2b054 19 19 explanation = help() 20 20 21 label_explain = wx.StaticText(self, -1, explanation, size=(350, 320))21 label_explain = wx.StaticText(self, -1, explanation, size=(350, 320)) 22 22 23 23 vbox.Add(label_explain, 0, wx.ALL|wx.EXPAND, 15) … … 51 51 splitter = MultiSplitterWindow(self, style=wx.SP_LIVE_UPDATE) 52 52 rpanel = wx.Panel(splitter, -1) 53 lpanel = wx.Panel(splitter, -1, style=wx.BORDER_SUNKEN)53 lpanel = wx.Panel(splitter, -1, style=wx.BORDER_SUNKEN) 54 54 55 55 vbox = wx.BoxSizer(wx.VERTICAL) … … 66 66 vbox.Add(header, 0, wx.EXPAND) 67 67 68 vboxl = wx.BoxSizer(wx.VERTICAL)68 vboxl = wx.BoxSizer(wx.VERTICAL) 69 69 headerl = wx.Panel(lpanel, -1, size=(-1, 20)) 70 70 … … 81 81 self.lhelp = html.HtmlWindow(lpanel, -1, style=wx.NO_BORDER) 82 82 self.rhelp = html.HtmlWindow(rpanel, -1, style=wx.NO_BORDER, 83 size=(500, -1))83 size=(500, -1)) 84 84 import sans.perspectives.invariant as invariant 85 85 path = invariant.get_data_path(media='media') 86 self.path = os.path.join(path,"invariant_help.html")86 self.path = os.path.join(path,"invariant_help.html") 87 87 88 88 self.rhelp.LoadPage(self.path) 89 page ="""<html>89 page = """<html> 90 90 <body> 91 91 <ul> … … 93 93 </ul> 94 94 </body> 95 </html>""" %self.path95 </html>""" % self.path 96 96 97 97 self.lhelp.SetPage(page) 98 self.lhelp.Bind(wx.html.EVT_HTML_LINK_CLICKED, self.OnLinkClicked)98 self.lhelp.Bind(wx.html.EVT_HTML_LINK_CLICKED, self.OnLinkClicked) 99 99 100 vbox.Add(self.rhelp, 1, wx.EXPAND)100 vbox.Add(self.rhelp, 1, wx.EXPAND) 101 101 vboxl.Add(self.lhelp, 1, wx.EXPAND) 102 102 rpanel.SetSizer(vbox) … … 105 105 106 106 vbox1 = wx.BoxSizer(wx.HORIZONTAL) 107 vbox1.Add(splitter, 1,wx.EXPAND)107 vbox1.Add(splitter, 1, wx.EXPAND) 108 108 splitter.AppendWindow(lpanel, 200) 109 109 splitter.AppendWindow(rpanel) … … 121 121 122 122 class ViewApp(wx.App): 123 """ 124 """ 123 125 def OnInit(self): 126 """ 127 """ 124 128 frame = HelpWindow(None, -1, 'HelpWindow') 125 129 frame.Show(True) -
invariantview/perspectives/invariant/invariant.py
r7a07864 r4a2b054 11 11 #copyright 2009, University of Tennessee 12 12 ################################################################################ 13 import os13 #import os 14 14 import sys 15 15 import wx 16 16 import copy 17 import logging, time 18 from sans.invariant import invariant 17 import logging 18 #import time 19 #from sans.invariant import invariant 19 20 20 21 from DataLoader.data_info import Data1D as LoaderData1D 21 from sans.guiframe.dataFitting import Theory1D, Data1D 22 23 from sans.guicomm.events import NewPlotEvent, StatusEvent 22 from sans.guiframe.dataFitting import Theory1D 23 from sans.guiframe.dataFitting import Data1D 24 25 from sans.guicomm.events import NewPlotEvent 24 26 from sans.guicomm.events import ERR_DATA 25 27 from invariant_state import Reader as reader … … 142 144 self.graph = graph 143 145 invariant_option = "Compute invariant" 144 invariant_hint = "Will displays the invariant panel for futher computation" 146 invariant_hint = "Will displays the invariant panel for" 147 invairant_hint += " futher computation" 145 148 146 149 for item in self.graph.plottables: … … 148 151 if issubclass(item.__class__,LoaderData1D): 149 152 150 if item.name !="$I_{obs}(q)$" and item.name !="$P_{fit}(r)$": 153 if item.name != "$I_{obs}(q)$" and \ 154 item.name != " $P_{fit}(r)$": 151 155 if hasattr(item, "group_id"): 152 156 return [[invariant_option, 153 invariant_hint, self._compute_invariant]] 157 invariant_hint, 158 self._compute_invariant]] 154 159 return [] 155 160 … … 220 225 """ 221 226 self.panel = event.GetEventObject() 222 Plugin.on_perspective(self, event=event)227 Plugin.on_perspective(self, event=event) 223 228 for plottable in self.panel.graph.plottables: 224 229 if plottable.name == self.panel.graph.selected_plottable: 225 ## put the errors values back to the model if the errors were hiden226 ## before sending them to the fit engine227 if len(self.err_dy) >0:230 ## put the errors values back to the model if the errors 231 ## were hiden before sending them to the fit engine 232 if len(self.err_dy) > 0: 228 233 dy = plottable.dy 229 234 if plottable.name in self.err_dy.iterkeys(): … … 260 265 self.state_reader.write(filepath, current_plottable, state) 261 266 else: 262 raise RuntimeError, "invariant.save_file: the data being saved is not a DataLoader.data_info.Data1D object" 267 msg = "invariant.save_file: the data being saved is" 268 msg += " not a DataLoader.data_info.Data1D object" 269 raise RuntimeError, msg 263 270 264 271 def set_state(self, state, datainfo=None): … … 273 280 274 281 if datainfo is None: 275 raise RuntimeError, "invariant.set_state: datainfo parameter cannot be None in standalone mode" 276 277 datainfo.meta_data['invstate'].file = datainfo.meta_data['invstate'].file 278 datainfo.name = datainfo.meta_data['invstate'].file 279 datainfo.filename = datainfo.meta_data['invstate'].file 282 msg = "invariant.set_state: datainfo parameter cannot" 283 msg += " be None in standalone mode" 284 raise RuntimeError, msg 285 286 name = datainfo.meta_data['invstate'].file 287 datainfo.meta_data['invstate'].file = name 288 datainfo.name = name 289 datainfo.filename = name 280 290 self.__data = datainfo 281 291 self.__data.group_id = datainfo.filename … … 300 310 after a .inv/.svs file is loaded 301 311 """ 302 self.invariant_panel.set_state(state=self.temp_state,data=self.__data) 312 self.invariant_panel.set_state(state=self.temp_state, 313 data=self.__data) 303 314 self.temp_state = None 304 315 … … 312 323 :param name: Data's name to use for the legend 313 324 """ 314 import copy325 #import copy 315 326 if data is None: 316 327 new_plot = Theory1D(x=[], y=[], dy=None) 317 328 else: 318 scale = self.invariant_panel.get_scale()329 scale = self.invariant_panel.get_scale() 319 330 background = self.invariant_panel.get_background() 320 331 … … 335 346 if data != None: 336 347 name_head = name.split('-') 337 if name_head[0] =='Low':348 if name_head[0] == 'Low': 338 349 self.invariant_panel.state.theory_lowQ = copy.deepcopy(new_plot) 339 elif name_head[0] =='High':350 elif name_head[0] == 'High': 340 351 self.invariant_panel.state.theory_highQ = copy.deepcopy(new_plot) 341 352 342 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=self.__data.name)) 353 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, 354 title=self.__data.name)) 343 355 344 356 def plot_data(self, scale, background): … … 354 366 if new_plot != None: 355 367 self.invariant_panel.state.data = copy.deepcopy(new_plot) 356 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=new_plot.name)) 357 368 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, 369 title=new_plot.name)) 370 -
invariantview/perspectives/invariant/invariant_details.py
rd7a39e5 r4a2b054 2 2 import wx 3 3 import sys 4 5 4 import numpy 6 from sans.guiframe.utils import format_number, check_float 5 from sans.guiframe.utils import format_number 6 from sans.guiframe.utils import check_float 7 7 from invariant_widgets import OutputTextCtrl 8 8 # Dimensions related to chart … … 16 16 DEFAULT_QSTAR = 1.0 17 17 18 if sys.platform.count("win32") >0:18 if sys.platform.count("win32") > 0: 19 19 _STATICBOX_WIDTH = 450 20 20 PANEL_WIDTH = 500 … … 28 28 29 29 30 31 30 class InvariantContainer(wx.Object): 32 31 """ … … 84 83 else: 85 84 try: 86 self.qstar_low_percent = float(self.qstar_low)/float(self.qstar_total) 85 self.qstar_low_percent = float(self.qstar_low)\ 86 /float(self.qstar_total) 87 87 except: 88 88 self.qstar_low_percent = 'error' … … 92 92 else: 93 93 try: 94 self.qstar_high_percent = float(self.qstar_high)/float(self.qstar_total) 94 self.qstar_high_percent = float(self.qstar_high)\ 95 /float(self.qstar_total) 95 96 except: 96 97 self.qstar_high_percent = 'error' … … 105 106 return 106 107 if self.qstar_total == 0: 107 self.existing_warning = True 108 self.warning_msg = "Invariant is zero. \n" 109 self.warning_msg += "The calculations are likely to be unreliable!\n" 110 return 108 self.existing_warning = True 109 self.warning_msg = "Invariant is zero. \n" 110 self.warning_msg += "The calculations are likely " 111 self.warning_msg += "to be unreliable!\n" 112 return 111 113 #warning to the user when the extrapolated invariant is greater than %5 112 114 msg = '' … … 117 119 if self.qstar_low_percent == 'error': 118 120 self.existing_warning = True 119 msg = 'Error occurred when computing extrapolated invariant at low-Q region.\n' 120 elif self.qstar_low_percent is not None and self.qstar_low_percent >= 0.05: 121 msg = "Error occurred when computing extrapolated invariant" 122 msg += " at low-Q region.\n" 123 elif self.qstar_low_percent is not None and \ 124 self.qstar_low_percent >= 0.05: 121 125 self.existing_warning = True 122 126 msg += "Extrapolated contribution at Low Q is higher " … … 124 128 if self.qstar_high_percent == 'error': 125 129 self.existing_warning = True 126 msg += 'Error occurred when computing extrapolated invariant at high-Q region.\n' 127 elif self.qstar_high_percent is not None and self.qstar_high_percent >= 0.05: 130 msg += 'Error occurred when computing extrapolated' 131 msg += ' invariant at high-Q region.\n' 132 elif self.qstar_high_percent is not None and \ 133 self.qstar_high_percent >= 0.05: 128 134 self.existing_warning = True 129 135 msg += "Extrapolated contribution at High Q is higher " … … 139 145 self.warning_msg = '' 140 146 self.warning_msg += msg 141 self.warning_msg += "The calculations are likely to be unreliable!\n" 147 self.warning_msg += "The calculations are likely to be" 148 self.warning_msg += " unreliable!\n" 142 149 else: 143 150 self.warning_msg = "No Details on calculations available...\n" … … 150 157 title="Invariant Details", 151 158 size=(PANEL_WIDTH, PANEL_HEIGHT)): 152 wx.Dialog.__init__(self, parent=parent, id=id, title=title,size=size)159 wx.Dialog.__init__(self, parent=parent, id=id, title=title, size=size) 153 160 154 161 #Font size … … 184 191 Define main sizers needed for this panel 185 192 """ 186 #Box sizers must be defined first before defining buttons/textctrls (MAC). 193 #Box sizers must be defined first before defining buttons/textctrls 194 # (MAC). 187 195 self.main_sizer = wx.BoxSizer(wx.VERTICAL) 188 196 #Sizer related to chart 189 197 chart_box = wx.StaticBox(self, -1, "Invariant Chart") 190 198 self.chart_sizer = wx.StaticBoxSizer(chart_box, wx.VERTICAL) 191 self.chart_sizer.SetMinSize((PANEL_WIDTH - 50, 110))199 self.chart_sizer.SetMinSize((PANEL_WIDTH - 50, 110)) 192 200 #Sizer related to invariant values 193 201 self.invariant_sizer = wx.GridBagSizer(4, 4) … … 196 204 wx.HORIZONTAL) 197 205 198 self.invariant_box_sizer.SetMinSize((PANEL_WIDTH - 50, -1))206 self.invariant_box_sizer.SetMinSize((PANEL_WIDTH - 50, -1)) 199 207 #Sizer related to warning message 200 208 warning_box = wx.StaticBox(self, -1, "Warning") 201 209 self.warning_sizer = wx.StaticBoxSizer(warning_box, wx.VERTICAL) 202 self.warning_sizer.SetMinSize((PANEL_WIDTH-50, -1))210 self.warning_sizer.SetMinSize((PANEL_WIDTH-50, -1)) 203 211 #Sizer related to button 204 212 self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) … … 221 229 invariant_txt = wx.StaticText(self, -1, 'Q* from Data ') 222 230 invariant_txt.SetToolTipString("Invariant in the data set's Q range.") 223 self.invariant_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 224 self.invariant_tcl.SetToolTipString("Invariant in the data set's Q range.") 225 self.invariant_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 226 self.invariant_err_tcl.SetToolTipString("Uncertainty on the invariant from data's range.") 231 self.invariant_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 232 hint_msg = "Invariant in the data set's Q range." 233 self.invariant_tcl.SetToolTipString(hint_msg) 234 self.invariant_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 235 hint_msg = "Uncertainty on the invariant from data's range." 236 self.invariant_err_tcl.SetToolTipString(hint_msg) 227 237 invariant_units_txt = wx.StaticText(self, -1, unit_invariant) 228 invariant_units_txt.SetToolTipString("Unit of the invariant from data's Q range") 238 hint_msg = "Unit of the invariant from data's Q range" 239 invariant_units_txt.SetToolTipString(hint_msg) 229 240 230 241 invariant_low_txt = wx.StaticText(self, -1, 'Q* from Low-Q') 231 invariant_low_txt.SetToolTipString("Extrapolated invariant from low-Q range.") 232 self.invariant_low_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 233 self.invariant_low_tcl.SetToolTipString("Extrapolated invariant from low-Q range.") 234 self.invariant_low_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 235 self.invariant_low_err_tcl.SetToolTipString("Uncertainty on the invariant from low-Q range.") 236 invariant_low_units_txt = wx.StaticText(self, -1, unit_invariant) 237 invariant_low_units_txt.SetToolTipString("Unit of the extrapolated invariant from low-Q range") 242 hint_msg = "Extrapolated invariant from low-Q range." 243 invariant_low_txt.SetToolTipString(hint_msg) 244 self.invariant_low_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 245 hint_msg = "Extrapolated invariant from low-Q range." 246 self.invariant_low_tcl.SetToolTipString(hint_msg) 247 self.invariant_low_err_tcl = OutputTextCtrl(self, -1, 248 size=(_BOX_WIDTH, -1)) 249 hint_msg = "Uncertainty on the invariant from low-Q range." 250 self.invariant_low_err_tcl.SetToolTipString(hint_msg) 251 invariant_low_units_txt = wx.StaticText(self, -1, unit_invariant) 252 hint_msg = "Unit of the extrapolated invariant from low-Q range" 253 invariant_low_units_txt.SetToolTipString(hint_msg) 238 254 239 255 invariant_high_txt = wx.StaticText(self, -1, 'Q* from High-Q') 240 invariant_high_txt.SetToolTipString("Extrapolated invariant from high-Q range") 241 self.invariant_high_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 242 self.invariant_high_tcl.SetToolTipString("Extrapolated invariant from high-Q range") 243 self.invariant_high_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 244 self.invariant_high_err_tcl.SetToolTipString("Uncertainty on the invariant from high-Q range.") 245 invariant_high_units_txt = wx.StaticText(self, -1, unit_invariant) 246 invariant_high_units_txt.SetToolTipString("Unit of the extrapolated invariant from high-Q range") 256 hint_msg = "Extrapolated invariant from high-Q range" 257 invariant_high_txt.SetToolTipString(hint_msg) 258 self.invariant_high_tcl = OutputTextCtrl(self, -1, 259 size=(_BOX_WIDTH, -1)) 260 hint_msg = "Extrapolated invariant from high-Q range" 261 self.invariant_high_tcl.SetToolTipString(hint_msg) 262 self.invariant_high_err_tcl = OutputTextCtrl(self, -1, 263 size=(_BOX_WIDTH, -1)) 264 hint_msg = "Uncertainty on the invariant from high-Q range." 265 self.invariant_high_err_tcl.SetToolTipString() 266 invariant_high_units_txt = wx.StaticText(self, -1, unit_invariant) 267 hint_msg = "Unit of the extrapolated invariant from high-Q range" 268 invariant_high_units_txt.SetToolTipString(hint_msg) 247 269 248 270 #Invariant low 249 271 iy = 0 250 272 ix = 0 251 self.invariant_sizer.Add(invariant_low_txt, (iy, ix), (1, 1),273 self.invariant_sizer.Add(invariant_low_txt, (iy, ix), (1, 1), 252 274 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 253 275 ix += 1 254 self.invariant_sizer.Add(self.invariant_low_tcl, (iy, ix), (1, 1),276 self.invariant_sizer.Add(self.invariant_low_tcl, (iy, ix), (1, 1), 255 277 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 256 278 ix += 1 257 279 self.invariant_sizer.Add( wx.StaticText(self, -1, uncertainty), 258 (iy, ix), (1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)259 ix += 1 260 self.invariant_sizer.Add(self.invariant_low_err_tcl, (iy, ix), (1, 1),280 (iy, ix), (1, 1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 281 ix += 1 282 self.invariant_sizer.Add(self.invariant_low_err_tcl, (iy, ix), (1, 1), 261 283 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 262 284 ix += 1 263 285 self.invariant_sizer.Add(invariant_low_units_txt 264 ,(iy, ix), (1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)286 ,(iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 265 287 #Invariant 266 288 iy += 1 267 289 ix = 0 268 self.invariant_sizer.Add(invariant_txt, (iy, ix), (1, 1),290 self.invariant_sizer.Add(invariant_txt, (iy, ix), (1, 1), 269 291 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 270 292 ix += 1 271 self.invariant_sizer.Add(self.invariant_tcl, (iy, ix), (1, 1),293 self.invariant_sizer.Add(self.invariant_tcl, (iy, ix), (1, 1), 272 294 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 273 295 ix += 1 274 296 self.invariant_sizer.Add(wx.StaticText(self, -1, uncertainty), 275 (iy, ix), (1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)276 ix += 1 277 self.invariant_sizer.Add(self.invariant_err_tcl, (iy, ix), (1, 1),297 (iy, ix), (1, 1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 298 ix += 1 299 self.invariant_sizer.Add(self.invariant_err_tcl, (iy, ix), (1, 1), 278 300 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 279 301 ix +=1 280 302 self.invariant_sizer.Add(invariant_units_txt 281 ,(iy, ix), (1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)303 ,(iy, ix), (1, 1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 282 304 #Invariant high 283 305 iy += 1 284 306 ix = 0 285 self.invariant_sizer.Add(invariant_high_txt, (iy, ix), (1, 1),307 self.invariant_sizer.Add(invariant_high_txt, (iy, ix), (1, 1), 286 308 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 287 309 ix += 1 288 self.invariant_sizer.Add(self.invariant_high_tcl, (iy, ix), (1, 1),310 self.invariant_sizer.Add(self.invariant_high_tcl, (iy, ix), (1, 1), 289 311 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 290 312 ix += 1 291 313 self.invariant_sizer.Add(wx.StaticText(self, -1, uncertainty), 292 (iy, ix), (1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0)293 ix += 1 294 self.invariant_sizer.Add(self.invariant_high_err_tcl, (iy, ix), (1, 1),314 (iy, ix), (1, 1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 315 ix += 1 316 self.invariant_sizer.Add(self.invariant_high_err_tcl, (iy, ix), (1, 1), 295 317 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 296 318 ix += 1 297 319 self.invariant_sizer.Add(invariant_high_units_txt 298 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 299 self.invariant_box_sizer.Add(self.invariant_sizer, 0, wx.TOP|wx.BOTTOM, 10) 320 ,(iy, ix), (1, 1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 321 self.invariant_box_sizer.Add(self.invariant_sizer, 0, 322 wx.TOP|wx.BOTTOM, 10) 300 323 301 324 def _layout_warning(self): … … 319 342 button_ok.SetToolTipString("Give Details on Computation") 320 343 self.Bind(wx.EVT_BUTTON, self.on_close, id=id) 321 self.button_sizer.AddMany([((20, 20), 0 , wx.LEFT, 350),344 self.button_sizer.AddMany([((20, 20), 0 , wx.LEFT, 350), 322 345 (button_ok, 0 , wx.RIGHT, 10)]) 323 346 def _do_layout(self): … … 341 364 Set value of txtcrtl 342 365 """ 343 self.invariant_tcl.SetValue(format_number(self.qstar_container.qstar)) 344 self.invariant_err_tcl.SetValue(format_number(self.qstar_container.qstar_err)) 345 self.invariant_low_tcl.SetValue(format_number(self.qstar_container.qstar_low)) 346 self.invariant_low_err_tcl.SetValue(format_number(self.qstar_container.qstar_low_err)) 347 self.invariant_high_tcl.SetValue(format_number(self.qstar_container.qstar_high)) 348 self.invariant_high_err_tcl.SetValue(format_number(self.qstar_container.qstar_high_err)) 366 value = format_number(self.qstar_container.qstar) 367 self.invariant_tcl.SetValue(value) 368 value = format_number(self.qstar_container.qstar_err) 369 self.invariant_err_tcl.SetValue(value) 370 value = format_number(self.qstar_container.qstar_low) 371 self.invariant_low_tcl.SetValue(value) 372 value = format_number(self.qstar_container.qstar_low_err) 373 self.invariant_low_err_tcl.SetValue(value) 374 value = format_number(self.qstar_container.qstar_high) 375 self.invariant_high_tcl.SetValue(value) 376 value = format_number(self.qstar_container.qstar_high_err) 377 self.invariant_high_err_tcl.SetValue(value) 349 378 350 379 def get_scale(self, percentage, scale_name='scale'): … … 361 390 scale = RECTANGLE_SCALE 362 391 self.warning_msg += "Receive an invalid scale for %s\n" 363 self.warning_msg += "check this value : %s\n"%(str(scale_name),str(percentage)) 392 self.warning_msg += "check this value : %s\n"%(str(scale_name), 393 str(percentage)) 364 394 return scale 365 395 … … 388 418 gc = wx.GraphicsContext.Create(dc) 389 419 except NotImplementedError: 390 dc.DrawText("This build of wxPython does not support the wx.GraphicsContext " 391 "family of classes.", 25, 25) 420 msg = "This build of wxPython does not support " 421 msg += "the wx.GraphicsContext family of classes." 422 dc.DrawText(msg, 25, 25) 392 423 return 393 424 #Start the drawing -
invariantview/perspectives/invariant/invariant_panel.py
reffce1d r4a2b054 3 3 4 4 """ 5 5 import copy 6 import time 7 import sys 8 import os 6 9 import wx 7 8 import sys,os9 10 10 from wx.lib.scrolledpanel import ScrolledPanel 11 11 from sans.invariant import invariant 12 from sans.guiframe.utils import format_number, check_float 12 from sans.guiframe.utils import format_number 13 from sans.guiframe.utils import check_float 13 14 from sans.guicomm.events import NewPlotEvent, StatusEvent 14 from invariant_details import InvariantDetailsPanel, InvariantContainer 15 from invariant_widgets import OutputTextCtrl, InvTextCtrl 15 from invariant_details import InvariantDetailsPanel 16 from invariant_details import InvariantContainer 17 from invariant_widgets import OutputTextCtrl 18 from invariant_widgets import InvTextCtrl 16 19 from invariant_state import InvariantState as IState 17 import copy,time 20 18 21 # The minimum q-value to be used when extrapolating 19 22 Q_MINIMUM = 1e-5 … … 36 39 37 40 38 if sys.platform.count("win32") >0:41 if sys.platform.count("win32") > 0: 39 42 _STATICBOX_WIDTH = 450 40 43 PANEL_WIDTH = 500 … … 58 61 ## Flag to tell the AUI manager to put this panel in the center pane 59 62 CENTER_PANE = True 60 def __init__(self, parent, data=None, manager=None, *args, **kwds):61 kwds["size"] = (PANEL_WIDTH, PANEL_HEIGHT)62 kwds["style"] = wx.FULL_REPAINT_ON_RESIZE63 def __init__(self, parent, data=None, manager=None, *args, **kwds): 64 kwds["size"] = (PANEL_WIDTH, PANEL_HEIGHT) 65 kwds["style"] = wx.FULL_REPAINT_ON_RESIZE 63 66 ScrolledPanel.__init__(self, parent=parent, *args, **kwds) 64 67 self.SetupScrolling() … … 108 111 if len(self._data.x[self._data.x==0]) > 0: 109 112 flag = True 110 msg = "Invariant: one of your q-values is zero. Delete that entry before proceeding" 113 msg = "Invariant: one of your q-values is zero. " 114 msg += "Delete that entry before proceeding" 111 115 self.hint_msg_txt.SetLabel(msg) 112 116 wx.PostEvent(self.parent, StatusEvent(status=msg, … … 137 141 self._reset_state_list() 138 142 return True 143 139 144 def set_message(self): 140 145 """ … … 147 152 self.hint_msg_txt.SetForegroundColour("red") 148 153 149 wx.PostEvent(self.parent,StatusEvent(status=msg,info="warning")) 154 wx.PostEvent(self.parent, 155 StatusEvent(status=msg,info="warning")) 150 156 else: 151 157 msg = "For more information, click on Details button." 152 158 self.hint_msg_txt.SetForegroundColour("black") 153 wx.PostEvent(self.parent,StatusEvent(status=msg,info="info")) 159 wx.PostEvent(self.parent, 160 StatusEvent(status=msg,info="info")) 154 161 self.hint_msg_txt.SetLabel(msg) 155 162 … … 178 185 if num > 0 : 179 186 self._undo_enable() 180 if num < len(state.state_list) -1:187 if num < len(state.state_list) - 1: 181 188 self._redo_enable() 182 189 … … 184 191 self.bookmark_num = len(self.state.bookmark_list) 185 192 186 total_bookmark_num = self.bookmark_num +1193 total_bookmark_num = self.bookmark_num + 1 187 194 for ind in range(1,total_bookmark_num): 188 195 #bookmark_num = ind … … 197 204 198 205 self._get_input_list() 199 #make sure that the data is reset (especially when loaded from a inv file) 206 #make sure that the data is reset (especially 207 # when loaded from a inv file) 200 208 self.state.data = self._data 201 209 … … 238 246 return float(background) 239 247 else: 240 raise ValueError, "Receive invalid value for background : %s"%(background) 248 msg = "Receive invalid value for background : %s" % (background) 249 raise ValueError, msg 241 250 242 251 def get_scale(self): … … 248 257 raise ValueError, "Need a background" 249 258 if check_float(self.scale_tcl): 250 if float(scale) <= 0.0:259 if float(scale) <= 0.0: 251 260 self.scale_tcl.SetBackgroundColour("pink") 252 261 self.scale_tcl.Refresh() 253 raise ValueError, "Receive invalid value for scale: %s"%(scale) 262 msg = "Receive invalid value for scale: %s" % (scale) 263 raise ValueError, msg 254 264 return float(scale) 255 265 else: 256 raise ValueError, "Receive invalid value for scale : %s" %(scale)266 raise ValueError, "Receive invalid value for scale : %s" % (scale) 257 267 258 268 def get_contrast(self): … … 262 272 par_str = self.contrast_tcl.GetValue().strip() 263 273 contrast = None 264 if par_str !=" " and check_float(self.contrast_tcl):274 if par_str !=" " and check_float(self.contrast_tcl): 265 275 contrast = float(par_str) 266 276 return contrast … … 284 294 par_str = self.porod_constant_tcl.GetValue().strip() 285 295 porod_const = None 286 if par_str != "" and check_float(self.porod_constant_tcl):296 if par_str != "" and check_float(self.porod_constant_tcl): 287 297 porod_const = float(par_str) 288 298 return porod_const … … 294 304 try: 295 305 v, dv = inv.get_volume_fraction_with_error(contrast=contrast, 296 306 extrapolation=extrapolation) 297 307 self.volume_tcl.SetValue(format_number(v)) 298 308 self.volume_err_tcl.SetValue(format_number(dv)) … … 300 310 self.volume_tcl.SetValue(format_number(None)) 301 311 self.volume_err_tcl.SetValue(format_number(None)) 302 msg= "Error occurred computing volume fraction: %s"%sys.exc_value 312 msg = "Error occurred computing volume " 313 msg += " fraction: %s" % sys.exc_value 303 314 wx.PostEvent(self.parent, StatusEvent(status=msg, 304 315 info="error", … … 318 329 self.surface_tcl.SetValue(format_number(None)) 319 330 self.surface_err_tcl.SetValue(format_number(None)) 320 msg = "Error occurred computing specific surface: %s"%sys.exc_value 331 msg = "Error occurred computing " 332 msg += "specific surface: %s" % sys.exc_value 321 333 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", 322 334 type="stop")) … … 338 350 self.invariant_total_tcl.SetValue(format_number(None)) 339 351 self.invariant_total_err_tcl.SetValue(format_number(None)) 340 msg= "Error occurred computing invariant using extrapolation: %s"%sys.exc_value 352 msg = "Error occurred computing invariant using" 353 msg += " extrapolation: %s" % sys.exc_value 341 354 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 342 355 … … 359 372 self.inv_container.qstar_low_err = "ERROR" 360 373 self._manager.plot_theory(name="Low-Q extrapolation") 361 msg= "Error occurred computing low-Q invariant: %s"%sys.exc_value 362 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 374 msg = "Error occurred computing low-Q " 375 msg += "invariant: %s" % sys.exc_value 376 wx.PostEvent(self.parent, 377 StatusEvent(status=msg, type="stop")) 363 378 else: 364 379 try: … … 378 393 power_high = inv.get_extrapolation_power(range='high') 379 394 self.power_high_tcl.SetValue(format_number(power_high)) 380 high_out_data = inv.get_extra_data_high(q_end=qmax_plot,npts=500) 395 high_out_data = inv.get_extra_data_high(q_end=qmax_plot, 396 npts=500) 381 397 self._manager.plot_theory(data=high_out_data, 382 398 name="High-Q extrapolation") … … 385 401 self.inv_container.qstar_high_err = "ERROR" 386 402 self._manager.plot_theory(name="High-Q extrapolation") 387 msg= "Error occurred computing high-Q invariant: %s"%sys.exc_value 388 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 403 msg = "Error occurred computing high-Q " 404 msg += "invariant: %s" % sys.exc_value 405 wx.PostEvent(self.parent, StatusEvent(status=msg, 406 type="stop")) 389 407 else: 390 408 try: … … 420 438 if low_q : 421 439 #Raise error only when qstar at low q is requested 422 msg = "Expect float for power at low q , got %s"%(power_low) 440 msg = "Expect float for power at low q, " 441 msg += " got %s" % (power_low) 423 442 raise ValueError, msg 424 443 … … 429 448 else: 430 449 if low_q: 431 msg = "Expect float for number of points at low q , got %s"%(npts_low) 450 msg = "Expect float for number of points at low q," 451 msg += " got %s" % (npts_low) 432 452 raise ValueError, msg 433 453 #Set the invariant calculator … … 454 474 if high_q : 455 475 #Raise error only when qstar at high q is requested 456 msg = "Expect float for power at high q , got %s"%(power_high) 476 msg = "Expect float for power at high q," 477 msg += " got %s" % (power_high) 457 478 raise ValueError, msg 458 479 … … 462 483 else: 463 484 if high_q: 464 msg = "Expect float for number of points at high q , got %s"%(npts_high) 485 msg = "Expect float for number of points at high q," 486 msg += " got %s" % (npts_high) 465 487 raise ValueError, msg 466 488 inv.set_extrapolation(range="high", npts=npts_high, … … 483 505 """ 484 506 if self._data == None: 485 msg = "\n\nData must be loaded first in order to perform a compution..." 507 msg = "\n\nData must be loaded first in order" 508 msg += " to perform a compution..." 486 509 wx.PostEvent(self.parent, StatusEvent(status=msg)) 487 510 # set a state for this computation for saving … … 502 525 scale = self.get_scale() 503 526 except: 504 msg = "Invariant Error: %s"%(sys.exc_value)505 wx.PostEvent(self.parent, StatusEvent(status= 527 msg = "Invariant Error: %s" % (sys.exc_value) 528 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 506 529 return 507 530 … … 516 539 inv, npts_high = self.set_extrapolation_high(inv=inv, high_q=high_q) 517 540 except: 518 msg = "Error occurred computing invariant: %s" %sys.exc_value541 msg = "Error occurred computing invariant: %s" % sys.exc_value 519 542 wx.PostEvent(self.parent, StatusEvent(status=msg, 520 543 info="warning",type="stop")) … … 532 555 533 556 except: 534 msg= "Error occurred computing invariant: %s" %sys.exc_value557 msg= "Error occurred computing invariant: %s" % sys.exc_value 535 558 wx.PostEvent(self.parent, StatusEvent(status=msg, 536 info="warning",type="stop")) 559 info="warning", 560 type="stop")) 537 561 return 538 562 … … 549 573 try: 550 574 #Compute volume and set value to txtcrtl 551 self.get_volume(inv=inv, contrast=contrast, extrapolation=extrapolation) 575 self.get_volume(inv=inv, contrast=contrast, 576 extrapolation=extrapolation) 552 577 #compute surface and set value to txtcrtl 553 578 except: 554 msg = "Error occurred computing invariant: %s" %sys.exc_value579 msg = "Error occurred computing invariant: %s" % sys.exc_value 555 580 wx.PostEvent(self.parent, StatusEvent(status=msg, 556 info="warning",type="stop")) 581 info="warning", 582 type="stop")) 557 583 try: 558 self.get_surface(inv=inv, contrast=contrast, porod_const=porod_const, 584 self.get_surface(inv=inv, contrast=contrast, 585 porod_const=porod_const, 559 586 extrapolation=extrapolation) 560 587 561 588 except: 562 msg = "Error occurred computing invariant: %s" %sys.exc_value589 msg = "Error occurred computing invariant: %s" % sys.exc_value 563 590 wx.PostEvent(self.parent, StatusEvent(status=msg, 564 info="warning",type="stop")) 591 info="warning", 592 type="stop")) 565 593 566 594 #compute percentage of each invariant … … 583 611 584 612 if event != None: 585 if not self.button_report.IsEnabled(): self.button_report.Enable(True) 586 if not self.button_save.IsEnabled(): self.button_save.Enable(True) 587 wx.PostEvent(self.parent, StatusEvent(status = '\nFinished invariant computation...')) 613 if not self.button_report.IsEnabled(): 614 self.button_report.Enable(True) 615 if not self.button_save.IsEnabled(): 616 self.button_save.Enable(True) 617 wx.PostEvent(self.parent, 618 StatusEvent(status='\nFinished invariant computation...')) 588 619 589 620 … … 594 625 : param event: undo button event 595 626 """ 596 if event != None: event.Skip() 597 if self.state.state_num <0: return 627 if event != None: 628 event.Skip() 629 if self.state.state_num < 0: 630 return 598 631 self.is_power_out = True 599 632 # get the previous state_num … … 601 634 self.get_state_by_num(state_num=str(pre_state_num)) 602 635 603 if float(pre_state_num) <= 0:636 if float(pre_state_num) <= 0: 604 637 self._undo_disable() 605 638 else: … … 617 650 : param event: redo button event 618 651 """ 619 if event != None: event.Skip() 652 if event != None: 653 event.Skip() 620 654 self.is_power_out = True 621 655 # get the next state_num … … 663 697 try: 664 698 current_state = copy.deepcopy(self.state.state_list[str(state_num)]) 665 # get the previously computed state number (computation before the state changes happened) 699 # get the previously computed state number 700 #(computation before the state changes happened) 666 701 current_compute_num = str(current_state['compute_num']) 667 702 except : … … 789 824 name = str(obj.GetName()) 790 825 value = str(obj.GetValue()) 791 rb_list = [['power_law_low','guinier'],['fit_enable_low','fix_enable_low'],['fit_enable_high','fix_enable_high']] 826 rb_list = [['power_law_low','guinier'], 827 ['fit_enable_low','fix_enable_low'], 828 ['fit_enable_high','fix_enable_high']] 792 829 793 830 try: … … 797 834 exec "self.state.saved_state['%s'] = %s" % (name, value) 798 835 799 # set the count part of radio button clicked False for the saved_state 836 # set the count part of radio button clicked 837 #False for the saved_state 800 838 for title,content in rb_list: 801 839 if name == title: … … 808 846 809 847 # Instead of changing the future, create a new future. 810 max_state_num = len(self.state.state_list) -1848 max_state_num = len(self.state.state_list) - 1 811 849 self.state.saved_state['state_num'] = max_state_num 812 850 813 self.state.saved_state['state_num'] += 1851 self.state.saved_state['state_num'] += 1 814 852 self.state.state_num = self.state.saved_state['state_num'] 815 853 self.state.state_list[str(self.state.state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) … … 825 863 Notify the compute_invariant state to self.state 826 864 827 : param state: set 'compute' when the computation is activated by the 'compute' button, else None 865 : param state: set 'compute' when the computation is 866 activated by the 'compute' button, else None 828 867 829 868 """ … … 838 877 self.state.saved_state['state_num'] = max_state_num 839 878 # A new computation is also A state 840 temp_saved_states = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 841 temp_saved_states['state_num'] +=1 879 #copy.deepcopy(self.state.saved_state) 880 temp_saved_states = self.state.clone_state() 881 temp_saved_states['state_num'] += 1 842 882 self.state.state_num = temp_saved_states['state_num'] 843 883 … … 847 887 temp_saved_states['compute_num'] = self.state.state_num 848 888 self.state.saved_state= copy.deepcopy(temp_saved_states) 849 self.state.state_list[str(self.state.state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 850 851 # A computation is a new state, so delete the states with any higher state numbers 889 #copy.deepcopy(self.state.saved_state) 890 self.state.state_list[str(self.state.state_num)] = self.state.clone_state() 891 892 # A computation is a new state, so delete the states with any higher 893 # state numbers 852 894 for i in range(self.state.state_num+1,len(self.state.state_list)): 853 895 try: … … 860 902 861 903 862 def _reset_state_list(self,data=None): 863 """ 864 Reset the state_list just before data was loading: Used in 'set_current_data()' 904 def _reset_state_list(self, data=None): 905 """ 906 Reset the state_list just before data was loading: 907 Used in 'set_current_data()' 865 908 """ 866 909 #if data == None: return 867 #temp_state = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 910 #temp_state = self.state.clone_state() 911 #copy.deepcopy(self.state.saved_state) 868 912 # Clear the list 869 913 self.state.state_list.clear() … … 882 926 883 927 # Put only the current state in the list 884 self.state.state_list[str(self.state.state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 928 #copy.deepcopy(self.state.saved_state) 929 self.state.state_list[str(self.state.state_num)] = self.state.clone_state() 885 930 self._undo_disable() 886 931 … … 927 972 self.state.saved_state['state_num'] += 1 928 973 self.state.state_num = self.state.saved_state['state_num'] 929 self.state.state_list[str(self.state.state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 974 #copy.deepcopy(self.state.saved_state) 975 self.state.state_list[str(self.state.state_num)] = self.state.clone_state() 930 976 except: 931 977 pass … … 976 1022 self.popUpMenu = wx.Menu() 977 1023 id = wx.NewId() 978 self._bmark = wx.MenuItem(self.popUpMenu,id,"BookMark"," Bookmark the panel to recall it later") 1024 self._bmark = wx.MenuItem(self.popUpMenu,id,"BookMark", 1025 " Bookmark the panel to recall it later") 979 1026 self.popUpMenu.AppendItem(self._bmark) 980 1027 self._bmark.Enable(True) … … 985 1032 def _on_bookmark(self,event): 986 1033 """ 987 Save the panel state in memory and add the list on the popup menu on bookmark context menu event 1034 Save the panel state in memory and add the list on 1035 the popup menu on bookmark context menu event 988 1036 """ 989 1037 if self._data == None: return … … 1010 1058 state = self.state.clone_state() 1011 1059 comp_state = copy.deepcopy(self.state.state_list[str(compute_num)]) 1012 self.state.bookmark_list[self.bookmark_num] = [my_time,date,state,comp_state] 1060 self.state.bookmark_list[self.bookmark_num] = [my_time, date, 1061 state,comp_state] 1013 1062 self.state.toXML(self, doc=None, entry_node=None) 1014 1063 … … 1017 1066 def _back_to_bookmark(self,event): 1018 1067 """ 1019 Bring the panel back to the state of bookmarked requested by context menu event 1068 Bring the panel back to the state of bookmarked requested by 1069 context menu event 1020 1070 and set it as a new state 1021 1071 """ … … 1032 1082 1033 1083 self.state.saved_state['state_num'] = state_num 1034 self.state.state_list[str(state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 1084 #copy.deepcopy(self.state.saved_state) 1085 self.state.state_list[str(state_num)] = self.state.clone_state() 1035 1086 self.state.state_num = state_num 1036 1087 self._undo_enable() … … 1105 1156 # Ask the user the location of the file to write to. 1106 1157 path = None 1107 dlg = wx.FileDialog(self, "Choose a file", self._default_save_location, "", "*.inv", wx.SAVE) 1158 dlg = wx.FileDialog(self, "Choose a file", 1159 self._default_save_location, "", "*.inv", wx.SAVE) 1108 1160 if dlg.ShowModal() == wx.ID_OK: 1109 1161 path = dlg.GetPath() … … 1124 1176 count_bf = self.data_cbbox.GetCount() 1125 1177 if count_bf > 1: 1126 mssg += 'Loading a new data set will reset all the work done in this panel. \n\r' 1127 mssg += 'Please make sure to save it first... \n\r' 1128 answer = wx.MessageBox(mssg, msg, wx.CANCEL|wx.OK|wx.ICON_EXCLAMATION) 1178 msg += "Loading a new data set will reset all the work" 1179 msg += " done in this panel. \n\r" 1180 mssg += "Please make sure to save it first... \n\r" 1181 answer = wx.MessageBox(mssg, msg, 1182 wx.CANCEL|wx.OK|wx.ICON_EXCLAMATION) 1129 1183 1130 1184 if answer == wx.OK: … … 1159 1213 Define main sizers needed for this panel 1160 1214 """ 1161 ## Box sizers must be defined first before defining buttons/textctrls (MAC). 1215 ## Box sizers must be defined first before 1216 #defining buttons/textctrls (MAC). 1162 1217 self.main_sizer = wx.BoxSizer(wx.VERTICAL) 1163 1218 #Sizer related to outputs … … 1193 1248 #Sizer related to extrapolation at low q range 1194 1249 high_q_box = wx.StaticBox(self, -1, "High Q") 1195 self.high_extrapolation_sizer = wx.StaticBoxSizer(high_q_box, wx.VERTICAL) 1250 self.high_extrapolation_sizer = wx.StaticBoxSizer(high_q_box, 1251 wx.VERTICAL) 1196 1252 self.high_q_sizer = wx.GridBagSizer(5,5) 1197 1253 #sizer to define outputs … … 1209 1265 """ 1210 1266 #Sizer hint 1211 hint_msg = "First open data file from 'File' menu. Then Highlight and right click on the data plot. \n" 1267 hint_msg = "First open data file from 'File' menu." 1268 hint_msg += "Then Highlight and right click on the data plot. \n" 1212 1269 hint_msg += "Finally, select 'Compute Invariant'." 1213 1270 self.hint_msg_txt = wx.StaticText(self, -1, hint_msg) 1214 1271 self.hint_msg_txt.SetForegroundColour("red") 1215 msg = "Highlight = mouse the mouse's cursor on the data until the plot's color changes to yellow" 1272 msg = "Highlight = mouse the mouse's cursor on the data until" 1273 msg += " the plot's color changes to yellow" 1216 1274 self.hint_msg_txt.SetToolTipString(msg) 1217 1275 self.hint_msg_sizer.Add(self.hint_msg_txt) … … 1219 1277 data_name_txt = wx.StaticText(self, -1, 'Data : ') 1220 1278 1221 self.data_name_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0) 1279 self.data_name_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), 1280 style=0) 1222 1281 self.data_name_tcl.SetToolTipString("Data's name.") 1223 1282 self.data_name_sizer.AddMany([(data_name_txt, 0, wx.LEFT|wx.RIGHT, 10), … … 1226 1285 data_range_txt = wx.StaticText(self, -1, 'Total Q Range (1/A): ') 1227 1286 data_min_txt = wx.StaticText(self, -1, 'Min : ') 1228 self.data_min_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0, name='data_min_tcl') 1287 self.data_min_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 1288 style=0, name='data_min_tcl') 1229 1289 self.data_min_tcl.SetToolTipString("The minimum value of q range.") 1230 1290 data_max_txt = wx.StaticText(self, -1, 'Max : ') 1231 self.data_max_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0, name='data_max_tcl') 1291 self.data_max_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 1292 style=0, name='data_max_tcl') 1232 1293 self.data_max_tcl.SetToolTipString("The maximum value of q range.") 1233 1294 self.data_range_sizer.AddMany([(data_range_txt, 0, wx.RIGHT, 10), … … 1245 1306 """ 1246 1307 background_txt = wx.StaticText(self, -1, 'Background : ') 1247 self.background_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0, name='background_tcl') 1308 self.background_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 1309 style=0, name='background_tcl') 1248 1310 wx.EVT_TEXT(self, self.background_tcl.GetId(), self._on_text) 1249 1311 background_hint_txt = "Background" … … 1251 1313 background_unit_txt = wx.StaticText(self, -1, '[1/cm]') 1252 1314 scale_txt = wx.StaticText(self, -1, 'Scale : ') 1253 self.scale_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0, name='scale_tcl') 1315 self.scale_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0, 1316 name='scale_tcl') 1254 1317 wx.EVT_TEXT(self, self.scale_tcl.GetId(), self._on_text) 1255 1318 scale_hint_txt = "Scale" … … 1266 1329 """ 1267 1330 contrast_txt = wx.StaticText(self, -1, 'Contrast : ') 1268 self.contrast_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0,name='contrast_tcl') 1331 self.contrast_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 1332 style=0,name='contrast_tcl') 1269 1333 wx.EVT_TEXT(self, self.contrast_tcl.GetId(), self._on_text) 1270 1334 contrast_hint_txt = "Contrast" … … 1273 1337 porod_const_txt = wx.StaticText(self, -1, 'Porod Constant:') 1274 1338 self.porod_constant_tcl = InvTextCtrl(self, -1, 1275 size=(_BOX_WIDTH, 20), style=0,name='porod_constant_tcl') 1339 size=(_BOX_WIDTH, 20), style=0, 1340 name='porod_constant_tcl') 1276 1341 wx.EVT_TEXT(self, self.porod_constant_tcl.GetId(), self._on_text) 1277 1342 porod_const_hint_txt = "Porod Constant" … … 1355 1420 Draw widgets related to extrapolation at low q range 1356 1421 """ 1357 self.enable_low_cbox = wx.CheckBox(self, -1, "Enable Extrapolate Low Q",name='enable_low_cbox') 1422 self.enable_low_cbox = wx.CheckBox(self, -1, 1423 "Enable Extrapolate Low Q", 1424 name='enable_low_cbox') 1358 1425 wx.EVT_CHECKBOX(self, self.enable_low_cbox.GetId(), 1359 1426 self._enable_low_q_section) 1360 1427 self.fix_enable_low = wx.RadioButton(self, -1, 'Fix', 1361 (10, 10),style=wx.RB_GROUP,name='fix_enable_low') 1428 (10, 10), style=wx.RB_GROUP, 1429 name='fix_enable_low') 1362 1430 self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, 1363 1431 id=self.fix_enable_low.GetId()) 1364 self.fit_enable_low = wx.RadioButton(self, -1, 'Fit', (10, 10),name='fit_enable_low') 1432 self.fit_enable_low = wx.RadioButton(self, -1, 'Fit', (10, 10), 1433 name='fit_enable_low') 1365 1434 self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, 1366 1435 id=self.fit_enable_low.GetId()) 1367 1436 self.guinier = wx.RadioButton(self, -1, 'Guinier', 1368 (10, 10),style=wx.RB_GROUP, name='guinier') 1437 (10, 10), style=wx.RB_GROUP, 1438 name='guinier') 1369 1439 self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, 1370 1440 id=self.guinier.GetId()) 1371 self.power_law_low = wx.RadioButton(self, -1, 'Power Law', (10, 10),name='power_law_low') 1441 self.power_law_low = wx.RadioButton(self, -1, 'Power Law', 1442 (10, 10), name='power_law_low') 1372 1443 self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, 1373 1444 id=self.power_law_low.GetId()) 1374 1445 1375 1446 npts_low_txt = wx.StaticText(self, -1, 'Npts') 1376 self.npts_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1),name='npts_low_tcl') 1447 self.npts_low_tcl = InvTextCtrl(self, -1, 1448 size=(_BOX_WIDTH*2/3, -1), 1449 name='npts_low_tcl') 1377 1450 wx.EVT_TEXT(self, self.npts_low_tcl.GetId(), self._on_text) 1378 1451 msg_hint = "Number of Q points to consider" … … 1380 1453 self.npts_low_tcl.SetToolTipString(msg_hint) 1381 1454 power_txt = wx.StaticText(self, -1, 'Power') 1382 self.power_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1),name='power_low_tcl') 1455 self.power_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1), 1456 name='power_low_tcl') 1383 1457 wx.EVT_TEXT(self, self.power_low_tcl.GetId(), self._on_text) 1384 1458 … … 1387 1461 iy = 0 1388 1462 ix = 0 1389 self.low_q_sizer.Add(self.enable_low_cbox,(iy, ix), (1,5),1463 self.low_q_sizer.Add(self.enable_low_cbox,(iy, ix), (1, 5), 1390 1464 wx.TOP|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1391 1465 iy += 1 1392 1466 ix = 0 1393 self.low_q_sizer.Add(npts_low_txt,(iy, ix), (1,1),1467 self.low_q_sizer.Add(npts_low_txt,(iy, ix), (1, 1), 1394 1468 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1395 1469 ix += 1 … … 1402 1476 iy += 1 1403 1477 ix = 0 1404 self.low_q_sizer.Add(self.power_law_low,(iy, ix), (1,2),1478 self.low_q_sizer.Add(self.power_law_low,(iy, ix), (1, 2), 1405 1479 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1406 1480 … … 1408 1482 ix = 1 1409 1483 iy += 1 1410 self.low_q_sizer.Add(self.fix_enable_low,(iy, ix), (1,1),1484 self.low_q_sizer.Add(self.fix_enable_low,(iy, ix), (1, 1), 1411 1485 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1412 1486 ix += 1 … … 1415 1489 ix = 1 1416 1490 iy += 1 1417 self.low_q_sizer.Add(power_txt,(iy, ix), (1,1),1491 self.low_q_sizer.Add(power_txt,(iy, ix), (1, 1), 1418 1492 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1419 1493 ix += 1 1420 self.low_q_sizer.Add(self.power_low_tcl, (iy, ix), (1, 1),1494 self.low_q_sizer.Add(self.power_low_tcl, (iy, ix), (1, 1), 1421 1495 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1422 1496 self.low_extrapolation_sizer.AddMany([(self.low_q_sizer, 0, … … 1466 1540 Draw widgets related to extrapolation at high q range 1467 1541 """ 1468 self.enable_high_cbox = wx.CheckBox(self, -1, "Enable Extrapolate high-Q", name='enable_high_cbox') 1542 self.enable_high_cbox = wx.CheckBox(self, -1, 1543 "Enable Extrapolate high-Q", 1544 name='enable_high_cbox') 1469 1545 wx.EVT_CHECKBOX(self, self.enable_high_cbox.GetId(), 1470 1546 self._enable_high_q_section) 1471 1547 self.fix_enable_high = wx.RadioButton(self, -1, 'Fix', 1472 (10, 10),style=wx.RB_GROUP,name='fix_enable_high') 1548 (10, 10), style=wx.RB_GROUP, 1549 name='fix_enable_high') 1473 1550 self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, 1474 1551 id=self.fix_enable_high.GetId()) 1475 self.fit_enable_high = wx.RadioButton(self, -1, 'Fit', (10, 10),name='fit_enable_high') 1552 self.fit_enable_high = wx.RadioButton(self, -1, 'Fit', (10, 10), 1553 name='fit_enable_high') 1476 1554 self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, 1477 1555 id=self.fit_enable_high.GetId()) … … 1481 1559 self.power_law_high.SetToolTipString(msg_hint) 1482 1560 npts_high_txt = wx.StaticText(self, -1, 'Npts') 1483 self.npts_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1),name='npts_high_tcl') 1561 self.npts_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1), 1562 name='npts_high_tcl') 1484 1563 wx.EVT_TEXT(self, self.npts_high_tcl.GetId(), self._on_text) 1485 1564 msg_hint = "Number of Q points to consider" … … 1487 1566 self.npts_high_tcl.SetToolTipString(msg_hint) 1488 1567 power_txt = wx.StaticText(self, -1, 'Power') 1489 self.power_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1),name='power_high_tcl') 1568 self.power_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1), 1569 name='power_high_tcl') 1490 1570 wx.EVT_TEXT(self, self.power_high_tcl.GetId(), self._on_text) 1491 1571 power_hint_txt = "Exponent to apply to the Power_law function." … … 1493 1573 iy = 0 1494 1574 ix = 0 1495 self.high_q_sizer.Add(self.enable_high_cbox, (iy, ix),(1,5),1575 self.high_q_sizer.Add(self.enable_high_cbox, (iy, ix), (1, 5), 1496 1576 wx.TOP|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1497 1577 iy += 1 1498 1578 ix = 0 1499 self.high_q_sizer.Add(npts_high_txt, (iy, ix),(1,1),1579 self.high_q_sizer.Add(npts_high_txt, (iy, ix), (1, 1), 1500 1580 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1501 1581 ix += 1 1502 self.high_q_sizer.Add(self.npts_high_tcl, (iy, ix), (1, 1),1582 self.high_q_sizer.Add(self.npts_high_tcl, (iy, ix), (1, 1), 1503 1583 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1504 1584 iy += 2 1505 1585 ix = 0 1506 self.high_q_sizer.Add(self.power_law_high, (iy, ix),(1,2),1586 self.high_q_sizer.Add(self.power_law_high, (iy, ix),(1, 2), 1507 1587 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1508 1588 … … 1510 1590 ix = 1 1511 1591 iy += 1 1512 self.high_q_sizer.Add(self.fix_enable_high,(iy, ix), (1,1),1592 self.high_q_sizer.Add(self.fix_enable_high,(iy, ix), (1, 1), 1513 1593 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1514 1594 ix += 1 1515 self.high_q_sizer.Add(self.fit_enable_high,(iy, ix), (1,1),1595 self.high_q_sizer.Add(self.fit_enable_high,(iy, ix), (1, 1), 1516 1596 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1517 1597 ix = 1 1518 1598 iy += 1 1519 self.high_q_sizer.Add(power_txt,(iy, ix), (1,1),1599 self.high_q_sizer.Add(power_txt,(iy, ix), (1, 1), 1520 1600 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1521 1601 ix += 1 1522 self.high_q_sizer.Add(self.power_high_tcl, (iy, ix), (1,1),1602 self.high_q_sizer.Add(self.power_high_tcl, (iy, ix), (1, 1), 1523 1603 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1524 1604 self.high_extrapolation_sizer.AddMany([(self.high_q_sizer, 0, … … 1534 1614 extrapolation_min_txt = wx.StaticText(self, -1, 'Min :') 1535 1615 self.extrapolation_min_tcl = OutputTextCtrl(self, -1, 1536 size=(_BOX_WIDTH, 20), style=0,name='extrapolation_min_tcl') 1616 size=(_BOX_WIDTH, 20), style=0, 1617 name='extrapolation_min_tcl') 1537 1618 self.extrapolation_min_tcl.SetValue(str(Q_MINIMUM)) 1538 self.extrapolation_min_tcl.SetToolTipString("The minimum extrapolated q value.") 1619 hint_msg = "The minimum extrapolated q value." 1620 self.extrapolation_min_tcl.SetToolTipString(hint_msg) 1539 1621 extrapolation_max_txt = wx.StaticText(self, -1, 'Max :') 1540 1622 self.extrapolation_max_tcl = OutputTextCtrl(self, -1, 1541 size=(_BOX_WIDTH, 20), style=0,name='extrapolation_max_tcl') 1623 size=(_BOX_WIDTH, 20), 1624 style=0, 1625 name='extrapolation_max_tcl') 1542 1626 self.extrapolation_max_tcl.SetValue(str(Q_MAXIMUM)) 1543 self.extrapolation_max_tcl.SetToolTipString("The maximum extrapolated q value.") 1544 self.extrapolation_range_sizer.AddMany([(extra_hint_txt, 0, wx.LEFT, 10), 1545 (extrapolation_min_txt, 0, wx.LEFT, 10), 1627 hint_msg = "The maximum extrapolated q value." 1628 self.extrapolation_max_tcl.SetToolTipString(hint_msg) 1629 self.extrapolation_range_sizer.AddMany([(extra_hint_txt, 0, 1630 wx.LEFT, 10), 1631 (extrapolation_min_txt, 0, 1632 wx.LEFT, 10), 1546 1633 (self.extrapolation_min_tcl, 1547 1634 0, wx.LEFT, 10), 1548 (extrapolation_max_txt, 0, wx.LEFT, 10), 1635 (extrapolation_max_txt, 0, 1636 wx.LEFT, 10), 1549 1637 (self.extrapolation_max_tcl, 1550 1638 0, wx.LEFT, 10), … … 1569 1657 uncertainty = "+/-" 1570 1658 volume_txt = wx.StaticText(self, -1, 'Volume Fraction ') 1571 self.volume_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='volume_tcl') 1659 self.volume_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1), 1660 name='volume_tcl') 1572 1661 wx.EVT_TEXT(self, self.volume_tcl.GetId(), self._on_out_text) 1573 1662 self.volume_tcl.SetToolTipString("Volume fraction.") 1574 self.volume_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='volume_err_tcl') 1663 self.volume_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1), 1664 name='volume_err_tcl') 1575 1665 wx.EVT_TEXT(self, self.volume_err_tcl.GetId(), self._on_out_text) 1576 self.volume_err_tcl.SetToolTipString("Uncertainty on the volume fraction.") 1666 hint_msg = "Uncertainty on the volume fraction." 1667 self.volume_err_tcl.SetToolTipString(hint_msg) 1577 1668 volume_units_txt = wx.StaticText(self, -1, unit_volume) 1578 1669 1579 1670 surface_txt = wx.StaticText(self, -1, 'Specific Surface') 1580 self.surface_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='surface_tcl') 1671 self.surface_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1), 1672 name='surface_tcl') 1581 1673 wx.EVT_TEXT(self, self.surface_tcl.GetId(), self._on_out_text) 1582 1674 self.surface_tcl.SetToolTipString("Specific surface value.") 1583 self.surface_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='surface_err_tcl') 1675 self.surface_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1), 1676 name='surface_err_tcl') 1584 1677 wx.EVT_TEXT(self, self.surface_err_tcl.GetId(), self._on_out_text) 1585 self.surface_err_tcl.SetToolTipString("Uncertainty on the specific surface.") 1678 hint_msg = "Uncertainty on the specific surface." 1679 self.surface_err_tcl.SetToolTipString(hint_msg) 1586 1680 surface_units_txt = wx.StaticText(self, -1, unit_surface) 1587 1681 iy = 0 1588 1682 ix = 0 1589 self.volume_surface_sizer.Add(volume_txt, (iy, ix), (1, 1),1683 self.volume_surface_sizer.Add(volume_txt, (iy, ix), (1, 1), 1590 1684 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1591 1685 ix += 1 1592 self.volume_surface_sizer.Add(self.volume_tcl, (iy, ix), (1, 1),1686 self.volume_surface_sizer.Add(self.volume_tcl, (iy, ix), (1, 1), 1593 1687 wx.EXPAND|wx.ADJUST_MINSIZE, 10) 1594 1688 ix += 1 … … 1596 1690 (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) 1597 1691 ix += 1 1598 self.volume_surface_sizer.Add(self.volume_err_tcl, (iy, ix), (1, 1),1692 self.volume_surface_sizer.Add(self.volume_err_tcl, (iy, ix), (1, 1), 1599 1693 wx.EXPAND|wx.ADJUST_MINSIZE, 10) 1600 1694 ix += 1 1601 self.volume_surface_sizer.Add(volume_units_txt, (iy, ix), (1, 1),1695 self.volume_surface_sizer.Add(volume_units_txt, (iy, ix), (1, 1), 1602 1696 wx.EXPAND|wx.ADJUST_MINSIZE, 10) 1603 1697 iy += 1 1604 1698 ix = 0 1605 self.volume_surface_sizer.Add(surface_txt, (iy, ix), (1, 1),1699 self.volume_surface_sizer.Add(surface_txt, (iy, ix), (1, 1), 1606 1700 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1607 1701 ix += 1 1608 self.volume_surface_sizer.Add(self.surface_tcl, (iy, ix), (1, 1),1702 self.volume_surface_sizer.Add(self.surface_tcl, (iy, ix), (1, 1), 1609 1703 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1610 1704 ix += 1 … … 1612 1706 (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1613 1707 ix += 1 1614 self.volume_surface_sizer.Add(self.surface_err_tcl, (iy, ix), (1, 1),1708 self.volume_surface_sizer.Add(self.surface_err_tcl, (iy, ix), (1, 1), 1615 1709 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1616 1710 ix += 1 1617 self.volume_surface_sizer.Add(surface_units_txt, (iy, ix), (1, 1),1711 self.volume_surface_sizer.Add(surface_units_txt, (iy, ix), (1, 1), 1618 1712 wx.EXPAND|wx.ADJUST_MINSIZE, 10) 1619 1713 … … 1625 1719 unit_invariant = '[1/(cm * A)]' 1626 1720 invariant_total_txt = wx.StaticText(self, -1, 'Invariant Total [Q*]') 1627 self.invariant_total_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='invariant_total_tcl') 1721 self.invariant_total_tcl = OutputTextCtrl(self, -1, 1722 size=(_BOX_WIDTH,-1), 1723 name='invariant_total_tcl') 1628 1724 msg_hint = "Total invariant [Q*], including extrapolated regions." 1629 1725 self.invariant_total_tcl.SetToolTipString(msg_hint) 1630 self.invariant_total_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='invariant_total_err_tcl') 1631 self.invariant_total_err_tcl.SetToolTipString("Uncertainty on invariant.") 1726 self.invariant_total_err_tcl = OutputTextCtrl(self, -1, 1727 size=(_BOX_WIDTH,-1), 1728 name='invariant_total_err_tcl') 1729 hint_msg = "Uncertainty on invariant." 1730 self.invariant_total_err_tcl.SetToolTipString(hint_msg) 1632 1731 invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant) 1633 1732 … … 1635 1734 iy = 0 1636 1735 ix = 0 1637 self.invariant_sizer.Add(invariant_total_txt, (iy, ix), (1, 1),1736 self.invariant_sizer.Add(invariant_total_txt, (iy, ix), (1, 1), 1638 1737 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1639 1738 ix += 1 1640 self.invariant_sizer.Add(self.invariant_total_tcl, (iy, ix), (1, 1),1739 self.invariant_sizer.Add(self.invariant_total_tcl, (iy, ix), (1, 1), 1641 1740 wx.EXPAND|wx.ADJUST_MINSIZE, 10) 1642 1741 ix += 1 … … 1644 1743 (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) 1645 1744 ix += 1 1646 self.invariant_sizer.Add(self.invariant_total_err_tcl, (iy, ix), (1, 1),1745 self.invariant_sizer.Add(self.invariant_total_err_tcl, (iy, ix), (1, 1), 1647 1746 wx.EXPAND|wx.ADJUST_MINSIZE, 10) 1648 1747 ix += 1 1649 self.invariant_sizer.Add(invariant_total_units_txt,(iy, ix), (1, 1),1748 self.invariant_sizer.Add(invariant_total_units_txt,(iy, ix), (1, 1), 1650 1749 wx.EXPAND|wx.ADJUST_MINSIZE, 10) 1651 1750 … … 1675 1774 #compute button 1676 1775 id = wx.NewId() 1677 self.button_calculate = wx.Button(self, id, "Compute", name ='compute_invariant' ) 1776 self.button_calculate = wx.Button(self, id, "Compute", 1777 name='compute_invariant') 1678 1778 self.button_calculate.SetToolTipString("Compute invariant") 1679 1779 self.Bind(wx.EVT_BUTTON, self.compute_invariant, id=id) … … 1681 1781 id = wx.NewId() 1682 1782 self.button_details = wx.Button(self, id, "Details?") 1683 self.button_details.SetToolTipString("Details about the results of the computation") 1783 hint_msg = "Details about the results of the computation" 1784 self.button_details.SetToolTipString(hint_msg) 1684 1785 self.Bind(wx.EVT_BUTTON, self.display_details, id=id) 1685 1786 details = "Details on Invariant Total Calculations" … … 1689 1790 wx.RIGHT|wx.BOTTOM|wx.TOP, 10), 1690 1791 (self.button_details, 0 , wx.ALL, 10), 1691 (self.button_calculate, 0 , wx.RIGHT|wx.TOP|wx.BOTTOM, 10)])#, 1792 (self.button_calculate, 0 , 1793 wx.RIGHT|wx.TOP|wx.BOTTOM, 10)])#, 1692 1794 #(self.button_undo, 0 , wx.ALL, 10), 1693 1795 #(self.button_redo, 0 , wx.ALL, 10)]) … … 1706 1808 #undo button 1707 1809 id = wx.NewId() 1708 self.button_undo = wx.BitmapButton(self, id,wx.Bitmap(self.undo_png))#wx.Button(self, id, "Undo",size=(50,20)) 1810 #wx.Button(self, id, "Undo",size=(50,20)) 1811 self.button_undo = wx.BitmapButton(self, id,wx.Bitmap(self.undo_png)) 1709 1812 self.button_undo.SetToolTipString("Undo") 1710 1813 … … 1714 1817 #redo button 1715 1818 id = wx.NewId() 1716 self.button_redo = wx.BitmapButton(self, id,wx.Bitmap(self.redo_png))#wx.Button(self, id, "Redo",size=(50,20)) 1819 #wx.Button(self, id, "Redo",size=(50,20)) 1820 self.button_redo = wx.BitmapButton(self, id,wx.Bitmap(self.redo_png)) 1717 1821 self.button_redo.SetToolTipString("Redo") 1718 1822 self.Bind(wx.EVT_BUTTON, self.redo, id=id) … … 1720 1824 #bookmark button 1721 1825 id = wx.NewId() 1722 self.button_bookmark = wx.BitmapButton(self, id,wx.Bitmap(self.bookmark_png))#wx.Button(self, id, "Undo",size=(50,20)) 1723 self.button_bookmark.SetToolTipString("Bookmark: right-click on the panel to retrieve it") 1826 #wx.Button(self, id, "Undo",size=(50,20)) 1827 self.button_bookmark = wx.BitmapButton(self, id, 1828 wx.Bitmap(self.bookmark_png)) 1829 hint_msg = "Bookmark: right-click on the panel to retrieve it" 1830 self.button_bookmark.SetToolTipString(hint_msg) 1724 1831 self.Bind(wx.EVT_BUTTON, self._on_bookmark, id=id) 1725 1832 #report button 1726 1833 id = wx.NewId() 1727 self.button_report = wx.BitmapButton(self, id,wx.Bitmap(self.report_png))#wx.Button(self, id, "Redo",size=(50,20)) 1728 self.button_report.SetToolTipString("Report the result of the computation") 1834 #wx.Button(self, id, "Redo",size=(50,20)) 1835 self.button_report = wx.BitmapButton(self, id, 1836 wx.Bitmap(self.report_png)) 1837 hint_msg = "Report the result of the computation" 1838 self.button_report.SetToolTipString(hint_msg) 1729 1839 self.Bind(wx.EVT_BUTTON, self.report, id=id) 1730 1840 #self.button_report.Disable() 1731 1841 #save button 1732 1842 id = wx.NewId() 1733 self.button_save = wx.BitmapButton(self, id,wx.Bitmap(self.save_png), name ='Save_invariant')#wx.Button(self, id, "Save", name ='Save_invariant' ) 1843 #wx.Button(self, id, "Save", name ='Save_invariant' ) 1844 self.button_save = wx.BitmapButton(self, id, wx.Bitmap(self.save_png), 1845 name='Save_invariant') 1734 1846 self.button_save.SetToolTipString("Save as a file") 1735 1847 self.Bind(wx.EVT_BUTTON, self._on_save_button, id=id) 1736 1848 self.button_save.Disable() 1737 self.save_button_sizer.AddMany([((PANEL_WIDTH/2,20), 1 , wx.EXPAND|wx.ADJUST_MINSIZE,0), 1738 (self.button_undo, 0 ,wx.LEFT|wx.ADJUST_MINSIZE, 10), 1739 (self.button_redo, 0 ,wx.LEFT|wx.ADJUST_MINSIZE, 10), 1740 (self.button_bookmark, 0 ,wx.LEFT|wx.ADJUST_MINSIZE, 10), 1741 (self.button_report, 0 ,wx.LEFT|wx.ADJUST_MINSIZE, 10), 1742 (self.button_save, 0 ,wx.LEFT|wx.ADJUST_MINSIZE, 10)]) 1849 self.save_button_sizer.AddMany([((PANEL_WIDTH/2,20), 1 , 1850 wx.EXPAND|wx.ADJUST_MINSIZE,0), 1851 (self.button_undo, 0 , 1852 wx.LEFT|wx.ADJUST_MINSIZE, 10), 1853 (self.button_redo, 0 , 1854 wx.LEFT|wx.ADJUST_MINSIZE, 10), 1855 (self.button_bookmark, 0 , 1856 wx.LEFT|wx.ADJUST_MINSIZE, 10), 1857 (self.button_report, 0 , 1858 wx.LEFT|wx.ADJUST_MINSIZE, 10), 1859 (self.button_save, 0 , 1860 wx.LEFT|wx.ADJUST_MINSIZE, 10)]) 1743 1861 def _do_layout(self): 1744 1862 """ … … 1781 1899 """ 1782 1900 """ 1783 def __init__(self, parent=None, id=1, graph=None,1784 data=None, title="Invariant", base=None):1901 def __init__(self, parent=None, id=1, graph=None, 1902 data=None, title="Invariant", base=None): 1785 1903 1786 1904 wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH +100, … … 1789 1907 self.loader = Loader() 1790 1908 import invariant 1791 1792 data= self.loader.load( "C:/ECLPS/workspace/trunk/DataLoader/test/ascii_test_3.txt")1909 path = "C:/ECLPS/workspace/trunk/DataLoader/test/ascii_test_3.txt" 1910 data= self.loader.load(path) 1793 1911 self.panel = InvariantPanel(self) 1794 1912 -
invariantview/perspectives/invariant/invariant_state.py
r5069a18 r4a2b054 1 import time, os, sys 1 """ 2 """ 3 4 import time 5 import os 6 import sys 2 7 import logging 3 8 import copy … … 8 13 from DataLoader.readers.cansas_reader import get_content 9 14 from sans.guiframe.utils import format_number 10 from sans.guiframe.dataFitting import Theory1D, Data1D 15 from sans.guiframe.dataFitting import Theory1D 16 from sans.guiframe.dataFitting import Data1D 17 11 18 INVNODE_NAME = 'invariant' 12 19 CANSAS_NS = "cansas1d/1.0" 20 13 21 # default state 14 22 list = {'file': 'None', … … 37 45 'surface_tcl':'', 38 46 'surface_err_tcl':''} 39 # list of states: This list will be filled as panel init and the number of states increases 47 # list of states: This list will be filled as panel 48 # init and the number of states increases 40 49 state_list = {} 41 50 bookmark_list = {} … … 50 59 'power_low_tcl': 0} 51 60 # list of output parameters (order sensitive) used by __str__ 52 output_list = [["qstar_low", 61 output_list = [["qstar_low", "Q* from low Q extrapolation [1/(cm*A)]"], 53 62 ["qstar_low_err", "dQ* from low Q extrapolation"], 54 63 ["qstar_low_percent", "Q* percent from low Q extrapolation"], 55 ["qstar", 64 ["qstar", "Q* from data [1/(cm*A)]"], 56 65 ["qstar_err", "dQ* from data"], 57 66 ["qstar_percent", "Q* percent from data"], 58 ["qstar_high", 67 ["qstar_high", "Q* from high Q extrapolation [1/(cm*A)]"], 59 68 ["qstar_high_err", "dQ* from high Q extrapolation"], 60 69 ["qstar_high_percent", "Q* percent from low Q extrapolation"], 61 ["qstar_total", 70 ["qstar_total", "total Q* [1/(cm*A)]"], 62 71 ["qstar_total_err", "total dQ*"], 63 72 ["volume", "volume fraction"], … … 97 106 import sans.perspectives.invariant as invariant 98 107 path = invariant.get_data_path(media='media') 99 path_report_html = os.path.join(path,"report_template.html")100 html_template =open(path_report_html,"r")108 path_report_html = os.path.join(path,"report_template.html") 109 html_template = open(path_report_html,"r") 101 110 self.template_str = html_template.read() 102 111 self.report_str = self.template_str 103 112 #self.report_str_save = None 104 113 html_template.close() 105 106 107 114 108 115 def __str__(self): … … 119 126 120 127 state_num = int(self.saved_state['state_num']) 121 state = "\n[Invariant computation for %s: " % file_name122 state += "performed at %s on %s] \n" %(my_time, date)123 state += "State No.: %d \n" % state_num128 state = "\n[Invariant computation for %s: " % file_name 129 state += "performed at %s on %s] \n" % (my_time, date) 130 state += "State No.: %d \n" % state_num 124 131 state += "\n=== Inputs ===\n" 125 132 126 133 # text ctl general inputs ( excluding extrapolation text ctl) 127 for key, value in self.input_list.iteritems():134 for key, value in self.input_list.iteritems(): 128 135 if value == '': 129 136 continue … … 131 138 max_ind = len(key_split)-1 132 139 if key_split[max_ind] == 'tcl': 133 name = ""134 if key_split[1] == 'low' or key_split[1]== 'high':140 name = "" 141 if key_split[1] == 'low' or key_split[1] == 'high': 135 142 continue 136 for ind in range(0, max_ind):137 name += " %s"%key_split[ind]138 state += "%s: %s\n" % (name.lstrip(" "),value)143 for ind in range(0, max_ind): 144 name += " %s" % key_split[ind] 145 state += "%s: %s\n" % (name.lstrip(" "), value) 139 146 140 147 # other input parameters … … 148 155 if compute_state['enable_high_cbox']: 149 156 extra_hi = 'Power law' 150 state += "\nExtrapolation: High=%s; Low=%s\n" %(extra_hi, extra_lo)157 state += "\nExtrapolation: High=%s; Low=%s\n" %(extra_hi, extra_lo) 151 158 low_off = False 152 159 high_off = False 153 for key, value in self.input_list.iteritems():160 for key, value in self.input_list.iteritems(): 154 161 key_split = key.split('_') 155 max_ind = len(key_split) -1162 max_ind = len(key_split) - 1 156 163 if key_split[max_ind] == 'tcl': 157 name = ""164 name = "" 158 165 # check each buttons whether or not ON or OFF 159 if key_split[1]== 'low' or key_split[1]== 'high': 160 if not compute_state['enable_low_cbox'] and key_split[max_ind-1] == 'low': 166 if key_split[1] == 'low' or key_split[1] == 'high': 167 if not compute_state['enable_low_cbox'] and \ 168 key_split[max_ind-1] == 'low': 161 169 low_off = True 162 170 continue 163 elif not compute_state['enable_high_cbox'] and key_split[max_ind-1]== 'high': 171 elif not compute_state['enable_high_cbox'] and \ 172 key_split[max_ind-1] == 'high': 164 173 high_off = True 165 174 continue 166 elif extra_lo == 'Guinier' and key_split[0]== 'power' and key_split[max_ind-1]== 'low': 175 elif extra_lo == 'Guinier' and key_split[0] == 'power' and \ 176 key_split[max_ind-1] == 'low': 167 177 continue 168 for ind in range(0, max_ind):169 name += " %s"%key_split[ind]178 for ind in range(0, max_ind): 179 name += " %s" % key_split[ind] 170 180 name = name.lstrip(" ") 171 181 if name == "power low" : … … 179 189 else: 180 190 name += ' (Fitted)' 181 state += "%s: %s\n" % (name,value)191 state += "%s: %s\n" % (name, value) 182 192 # Outputs 183 193 state += "\n=== Outputs ===" … … 185 195 item_split = item[0].split('_') 186 196 # Exclude the extrapolation that turned off 187 if len(item_split)>1: 188 if low_off and item_split[1] == 'low': continue 189 if high_off and item_split[1] == 'high': continue 190 max_ind = len(item_split)-1 197 if len(item_split) > 1: 198 if low_off and item_split[1] == 'low': 199 continue 200 if high_off and item_split[1] == 'high': 201 continue 202 max_ind = len(item_split) - 1 191 203 value = None 192 204 try: 193 205 # Q* outputs 194 exec "value = self.container.%s\n" % item[0]206 exec "value = self.container.%s\n" % item[0] 195 207 except: 196 208 # other outputs than Q* 197 name = item[0] +"_tcl"198 exec "value = self.saved_state['%s']" % name209 name = item[0] + "_tcl" 210 exec "value = self.saved_state['%s']" % name 199 211 200 212 # Exclude the outputs w/'' 201 if value == '': continue202 213 if value == '': 214 continue 203 215 # Error outputs 204 216 if item_split[max_ind] == 'err': 205 state += "+- %s "%format_number(value) 206 217 state += "+- %s " % format_number(value) 207 218 # Percentage outputs 208 219 elif item_split[max_ind] == 'percent': 209 220 try: 210 value = float(value) *100221 value = float(value) * 100 211 222 except: 212 223 pass 213 state += "(%s %s)" %(format_number(value),'%')224 state += "(%s %s)" % (format_number(value), '%') 214 225 # Outputs 215 226 else: 216 state += "\n%s: %s "%(item[1],format_number(value,high=True)) 227 state += "\n%s: %s " % (item[1], 228 format_number(value, high=True)) 217 229 # Include warning msg 218 230 state += "\n\nNote:\n" + self.container.warning_msg 219 220 231 return state 221 232 222 223 233 def clone_state(self): 224 234 """ … … 226 236 """ 227 237 return copy.deepcopy(self.saved_state) 228 229 238 230 239 def toXML(self, file="inv_state.inv", doc=None, entry_node=None): … … 234 243 Compatible with standalone writing, or appending to an 235 244 already existing XML document. In that case, the XML document 236 is required. An optional entry node in the XML document may also be given. 245 is required. An optional entry node in the XML document 246 may also be given. 237 247 238 248 : param file: file to write to 239 249 : param doc: XML document object [optional] 240 : param entry_node: XML node within the XML document at which we will append the data [optional] 250 : param entry_node: XML node within the XML document at which 251 we will append the data [optional] 241 252 """ 242 253 from xml.dom.minidom import getDOMImplementation 243 import time254 #import time 244 255 timestamp = time.time() 245 256 # Check whether we have to write a standalone XML file … … 266 277 # File name 267 278 element = newdoc.createElement("filename") 268 if self.file != None and self.file != '':279 if self.file != None and self.file != '': 269 280 element.appendChild(newdoc.createTextNode(str(self.file))) 270 281 else: … … 293 304 294 305 for name, value in self.state_list.iteritems(): 295 history_element = newdoc.createElement('state_' +str(name))306 history_element = newdoc.createElement('state_' + str(name)) 296 307 for state_name,state_value in value.iteritems(): 297 308 state_element = newdoc.createElement(str(state_name)) 298 state_element.appendChild(newdoc.createTextNode(str(state_value))) 309 child = newdoc.createTextNode(str(state_value)) 310 state_element.appendChild(child) 299 311 history_element.appendChild(state_element) 300 312 #history_element.appendChild(state_list_element) 301 313 history.appendChild(history_element) 302 314 303 # Bookmarks bookmark_list[self.bookmark_num] = [my_time,date,state,comp_state] 315 # Bookmarks bookmark_list[self.bookmark_num] = [\ 316 #my_time,date,state,comp_state] 304 317 bookmark = newdoc.createElement("bookmark") 305 318 top_element.appendChild(bookmark) … … 314 327 state_list_element = newdoc.createElement('state') 315 328 comp_state_list_element = newdoc.createElement('comp_state') 316 for state_name, state_value in value_list[2].iteritems():329 for state_name, state_value in value_list[2].iteritems(): 317 330 state_element = newdoc.createElement(str(state_name)) 318 state_element.appendChild(newdoc.createTextNode(str(state_value))) 331 child = newdoc.createTextNode(str(state_value)) 332 state_element.appendChild(child) 319 333 state_list_element.appendChild(state_element) 320 for comp_name, comp_value in value_list[3].iteritems():334 for comp_name, comp_value in value_list[3].iteritems(): 321 335 comp_element = newdoc.createElement(str(comp_name)) 322 336 comp_element.appendChild(newdoc.createTextNode(str(comp_value))) … … 345 359 """ 346 360 if file is not None: 347 raise RuntimeError, "InvariantSate no longer supports non-CanSAS format for invariant files" 361 msg = "InvariantSate no longer supports non-CanSAS" 362 msg += " format for invariant files" 363 raise RuntimeError, msg 348 364 349 365 if node.get('version')\ … … 361 377 timestamp = (entry.get('epoch')) 362 378 except: 363 logging.error("InvariantSate.fromXML: Could not read timestamp\n %s" % sys.exc_value) 379 msg = "InvariantSate.fromXML: Could not read" 380 msg += " timestamp\n %s" % sys.exc_value 381 logging.error(msg) 364 382 365 383 # Parse bookmarks 366 384 entry_bookmark = get_content('ns:bookmark', node) 367 385 368 for ind in range(1, len(entry_bookmark)+1):386 for ind in range(1, len(entry_bookmark) + 1): 369 387 temp_state = {} 370 388 temp_bookmark = {} … … 372 390 373 391 if entry is not None: 374 time = get_content('ns:time', entry 392 time = get_content('ns:time', entry) 375 393 val_time = str(time.text.strip()) 376 date = get_content('ns:date', entry 394 date = get_content('ns:date', entry) 377 395 val_date = str(date.text.strip()) 378 state_entry = get_content('ns:state', entry 396 state_entry = get_content('ns:state', entry) 379 397 for item in list: 380 398 381 input_field = get_content('ns:%s' % item, state_entry ) 382 val = str(input_field.text.strip()) 383 384 if input_field is not None: 385 try: 386 exec "temp_state['%s'] = %s"% (item,val) 387 except: 388 exec "temp_state['%s'] = '%s'"% (item,val) 389 390 comp_entry = get_content('ns:comp_state', entry ) 391 392 for item in list: 393 input_field = get_content('ns:%s' % item, comp_entry ) 399 input_field = get_content('ns:%s' % item, state_entry) 394 400 val = str(input_field.text.strip()) 395 401 if input_field is not None: 396 402 try: 397 exec "temp_ bookmark['%s'] = %s"% (item,val)403 exec "temp_state['%s'] = %s" % (item, val) 398 404 except: 399 exec "temp_bookmark['%s'] = '%s'"% (item,val) 405 exec "temp_state['%s'] = '%s'" % (item, val) 406 comp_entry = get_content('ns:comp_state', entry) 407 408 for item in list: 409 input_field = get_content('ns:%s' % item, comp_entry) 410 val = str(input_field.text.strip()) 411 if input_field is not None: 412 try: 413 exec "temp_bookmark['%s'] = %s" % (item, val) 414 except: 415 exec "temp_bookmark['%s'] = '%s'" % (item, val) 400 416 try: 401 exec "self.bookmark_list[%s] = [val_time,val_date,temp_state,temp_bookmark]"% ind 402 417 cmd = "self.bookmark_list[%s] = [val_time," 418 cmd += "val_date,temp_state,temp_bookmark]" 419 exec cmd % ind 403 420 except: 404 421 raise "missing components of bookmarks..." 405 406 422 # Parse histories 407 423 entry_history = get_content('ns:history', node) 408 424 409 for ind in range(0, len(entry_history)):425 for ind in range(0, len(entry_history)): 410 426 temp_state = {} 411 427 entry = get_content('ns:state_%s' % ind, entry_history) … … 418 434 if input_field is not None: 419 435 try: 420 exec "temp_state['%s'] = %s" % (item,val)436 exec "temp_state['%s'] = %s" % (item, val) 421 437 except: 422 exec "temp_state['%s'] = '%s'" % (item,val)438 exec "temp_state['%s'] = '%s'" % (item, val) 423 439 finally: 424 exec "self.state_list['%s'] = temp_state"% ind 425 440 exec "self.state_list['%s'] = temp_state" % ind 426 441 # Parse current state (ie, saved_state) 427 442 entry = get_content('ns:state', node) … … 432 447 if input_field is not None: 433 448 self.set_saved_state(name=item, value=val) 434 435 449 self.file = file_name 436 450 … … 442 456 443 457 # default string values 444 for num in range (1, 19):445 exec "s_%s = 'NA'" % str(num)458 for num in range (1, 19): 459 exec "s_%s = 'NA'" % str(num) 446 460 lines = strings.split('\n') 447 461 # get all string values from __str__() 448 for line in range(0, len(lines)):462 for line in range(0, len(lines)): 449 463 if line == 1: 450 464 s_1 = lines[1] … … 454 468 item = lines[line].split(':') 455 469 item[0] = item[0].strip() 456 if item[0] == "scale":470 if item[0] == "scale": 457 471 s_3 = item[1] 458 472 elif item[0] == "porod constant": … … 466 480 bool_0 = extra[0].split("=") 467 481 bool_1 = extra[1].split("=") 468 s_7 = " " +bool_0[0]+"Q region = "+bool_0[1]469 s_8 = " " +bool_1[0]+"Q region = "+bool_1[1]470 elif item[0] =="npts low":482 s_7 = " " + bool_0[0] + "Q region = " + bool_0[1] 483 s_8 = " " + bool_1[0] + "Q region = " + bool_1[1] 484 elif item[0] == "npts low": 471 485 s_9 = item[1] 472 elif item[0] =="npts high":486 elif item[0] == " npts high": 473 487 s_10 = item[1] 474 488 elif item[0] == "volume fraction": 475 489 val=item[1].split("+-")[0].strip() 476 490 error = item[1].split("+-")[1].strip() 477 s_17 = val +" ± "+error491 s_17 = val + " ± " + error 478 492 elif item[0] == "specific surface": 479 val =item[1].split("+-")[0].strip()493 val = item[1].split("+-")[0].strip() 480 494 error = item[1].split("+-")[1].strip() 481 s_18 = val +" ± "+error482 elif item[0].split("(")[0].strip() =="power high":495 s_18 = val + " ± " + error 496 elif item[0].split("(")[0].strip() == "power high": 483 497 s_11 = item[0]+" ="+item[1] 484 elif item[0].split("(")[0].strip() =="power low":498 elif item[0].split("(")[0].strip() == "power low": 485 499 s_12 = item[0]+" ="+item[1] 486 elif item[0].split("[")[0].strip() =="Q* from low Q extrapolation":500 elif item[0].split("[")[0].strip() == "Q* from low Q extrapolation": 487 501 #looks messy but this way the symbols +_ and % work on html 488 val =item[1].split("+-")[0].strip()502 val = item[1].split("+-")[0].strip() 489 503 error = item[1].split("+-")[1].strip() 490 504 err = error.split("%")[0].strip() 491 505 percent = error.split("%")[1].strip() 492 s_13 = val +" ± "+err+"%"+percent493 elif item[0].split("[")[0].strip() =="Q* from data":494 val =item[1].split("+-")[0].strip()506 s_13 = val + " ± " + err + "%" + percent 507 elif item[0].split("[")[0].strip() == "Q* from data": 508 val = item[1].split("+-")[0].strip() 495 509 error = item[1].split("+-")[1].strip() 496 510 err = error.split("%")[0].strip() 497 511 percent = error.split("%")[1].strip() 498 s_14 = val +" ± "+err+"%"+percent499 elif item[0].split("[")[0].strip() =="Q* from high Q extrapolation":500 val =item[1].split("+-")[0].strip()512 s_14 = val + " ± " + err + "%" + percent 513 elif item[0].split("[")[0].strip() == "Q* from high Q extrapolation": 514 val = item[1].split("+-")[0].strip() 501 515 error = item[1].split("+-")[1].strip() 502 516 err = error.split("%")[0].strip() 503 517 percent = error.split("%")[1].strip() 504 s_15 = val +" ± "+err+"%"+percent505 elif item[0].split("[")[0].strip() =="total Q*":506 val =item[1].split("+-")[0].strip()518 s_15 = val + " ± " + err + "%" + percent 519 elif item[0].split("[")[0].strip() == "total Q*": 520 val = item[1].split("+-")[0].strip() 507 521 error = item[1].split("+-")[1].strip() 508 s_16 = val +" ± "+error522 s_16 = val + " ± " + error 509 523 else: 510 524 continue … … 513 527 self.set_plot_state(extra_high=bool_0[1],extra_low=bool_1[1]) 514 528 # get ready for report with setting all the html strings 515 self.report_str = str(self.template_str)% (s_1,s_2,s_3,s_4,s_5,s_6,s_7,s_8,s_9,s_10,s_11,s_12,s_13,s_14,s_15,s_16,s_17,s_18,self.file,"%s") 516 529 self.report_str = str(self.template_str) % (s_1, s_2, 530 s_3, s_4, s_5, s_6, s_7, s_8, 531 s_9, s_10, s_11, s_12, s_13, s_14, s_15, 532 s_16, s_17, s_18, self.file, "%s") 517 533 518 534 def set_saved_state(self, name, value): … … 523 539 : param value: value of the state component 524 540 """ 525 rb_list = [['power_law_low','guinier'],['fit_enable_low','fix_enable_low'],['fit_enable_high','fix_enable_high']] 541 rb_list = [['power_law_low','guinier'], 542 ['fit_enable_low','fix_enable_low'], 543 ['fit_enable_high','fix_enable_high']] 526 544 527 545 try: 528 if value == None or value.lstrip().rstrip() == '':546 if value == None or value.lstrip().rstrip() == '': 529 547 exec "self.%s = '%s'" % (name, value) 530 exec "self.saved_state['%s'] = '%s'" % 548 exec "self.saved_state['%s'] = '%s'" % (name, value) 531 549 else: 532 550 exec 'self.%s = %s' % (name, value) 533 exec "self.saved_state['%s'] = %s" % (name, value) 534 535 536 # set the count part of radio button clicked False for the saved_state 537 for title,content in rb_list: 551 exec "self.saved_state['%s'] = %s" % (name, value) 552 # set the count part of radio button clicked 553 # False for the saved_state 554 for title, content in rb_list: 538 555 if name == title: 539 556 name = content … … 542 559 name = title 543 560 value = False 544 exec "self.saved_state['%s'] = '%s'" % 561 exec "self.saved_state['%s'] = '%s'" % (name, value) 545 562 self.state_num = self.saved_state['state_num'] 546 563 except: 547 564 pass 548 565 549 def set_plot_state(self, extra_high=False,extra_low=False):566 def set_plot_state(self, extra_high=False, extra_low=False): 550 567 """ 551 568 Build image state that wx.html understand 552 569 by plotting, putting it into wx.FileSystem image object 553 570 554 : extrap_high,extra_low: low/high extrapolations are possible extra-plots 571 : extrap_high,extra_low: low/high extrapolations 572 are possible extra-plots 555 573 """ 556 574 # some imports … … 583 601 #make python.Image object 584 602 #size 585 w, h =canvas.get_width_height()603 w, h = canvas.get_width_height() 586 604 #convert to wx.Image 587 605 wximg = wx.EmptyImage(w,h) … … 595 613 self.imgRAM = wx.MemoryFSHandler() 596 614 #AddFile, image can be retrieved with 'memory:filename' 597 self.imgRAM.AddFile('img_inv.png', wximgbmp, wx.BITMAP_TYPE_PNG)615 self.imgRAM.AddFile('img_inv.png', wximgbmp, wx.BITMAP_TYPE_PNG) 598 616 599 617 self.wximgbmp = 'memory:img_inv.png' … … 611 629 "SANSView file (*.svs)|*.svs"] 612 630 ## List of allowed extensions 613 ext =['.inv', '.INV', '.svs', 'SVS']631 ext = ['.inv', '.INV', '.svs', 'SVS'] 614 632 615 633 def __init__(self, call_back, cansas=True): … … 634 652 : return: None 635 653 """ 636 if self.cansas ==True:654 if self.cansas == True: 637 655 return self._read_cansas(path) 638 656 else: … … 666 684 # Locate the invariant node 667 685 try: 668 nodes = entry.xpath('ns:%s' % INVNODE_NAME, namespaces={'ns': CANSAS_NS}) 686 nodes = entry.xpath('ns:%s' % INVNODE_NAME, 687 namespaces={'ns': CANSAS_NS}) 669 688 # Create an empty state 670 if nodes != []:689 if nodes != []: 671 690 state = InvariantState() 672 691 state.fromXML(node=nodes[0]) 673 692 except: 674 logging.info("XML document does not contain invariant information.\n %s" % sys.exc_value) 693 msg = "XML document does not contain invariant" 694 msg += " information.\n %s" % sys.exc_value 695 logging.info(msg) 675 696 return state 676 697 … … 696 717 697 718 # Check the format version number 698 # Specifying the namespace will take care of the file format version 719 # Specifying the namespace will take care of 720 # the file format version 699 721 root = tree.getroot() 700 722 701 entry_list = root.xpath('/ns:SASroot/ns:SASentry', namespaces={'ns': CANSAS_NS}) 723 entry_list = root.xpath('/ns:SASroot/ns:SASentry', 724 namespaces={'ns': CANSAS_NS}) 702 725 703 726 for entry in entry_list: … … 716 739 717 740 # Return output consistent with the loader's api 718 if len(output) ==0:741 if len(output) == 0: 719 742 return None 720 elif len(output) ==1:743 elif len(output) == 1: 721 744 # Call back to post the new state 722 745 723 self.call_back(state=output[0].meta_data['invstate'], datainfo = output[0]) 746 self.call_back(state=output[0].meta_data['invstate'], 747 datainfo = output[0]) 724 748 return output[0] 725 749 else: … … 754 778 datainfo = DataLoader.data_info.Data1D(x=[], y=[]) 755 779 elif not issubclass(datainfo.__class__, DataLoader.data_info.Data1D): 756 raise RuntimeError, "The cansas writer expects a Data1D instance: %s" % str(datainfo.__class__.__name__) 780 msg = "The cansas writer expects a Data1D" 781 msg += " instance: %s" % str(datainfo.__class__.__name__) 782 raise RuntimeError, msg 757 783 #make sure title and data run is filled up. 758 if datainfo.title == None or datainfo.title=='': datainfo.title = datainfo.name 759 if datainfo.run_name == None or datainfo.run_name=={}: 784 if datainfo.title == None or datainfo.title == '': 785 datainfo.title = datainfo.name 786 if datainfo.run_name == None or datainfo.run_name == {}: 760 787 datainfo.run = [str(datainfo.name)] 761 788 datainfo.run_name[0] = datainfo.name 762 763 789 # Create basic XML document 764 790 doc, sasentry = self._to_xml_doc(datainfo) 765 766 791 # Add the invariant information to the XML document 767 792 if state is not None: 768 793 state.toXML(datainfo.name,doc=doc, entry_node=sasentry) 769 770 794 return doc 795 -
invariantview/perspectives/invariant/invariant_widgets.py
r4e1c362 r4a2b054 14 14 15 15 import wx 16 import os17 from invariant_state import InvariantState as IState18 import copy16 #import os 17 #from invariant_state import InvariantState as IState 18 #import copy 19 19 20 20 class InvTextCtrl(wx.TextCtrl): … … 25 25 def __init__(self, *args, **kwds): 26 26 wx.TextCtrl.__init__(self, *args, **kwds) 27 ## Set to True when the mouse is clicked while the whole string is selected 27 ## Set to True when the mouse is clicked while 28 #the whole string is selected 28 29 self.full_selection = False 29 30 ## Call back for EVT_SET_FOCUS events … … 60 61 # if not, select the whole string 61 62 (start, end) = control.GetSelection() 62 if start ==end:63 control.SetSelection(-1, -1)63 if start == end: 64 control.SetSelection(-1, -1) 64 65 65 66 66 67 67 class OutputTextCtrl(wx.TextCtrl): 68 68 """ -
invariantview/perspectives/invariant/report_dialog.py
r5b03122 r4a2b054 11 11 12 12 """ 13 Dialog report panel to show and summarize the results of the invariant calculation. 13 Dialog report panel to show and summarize the results of 14 the invariant calculation. 14 15 """ 15 16 import wx 16 import sys,os 17 import sys 18 import os 17 19 import wx.html as html 18 20 19 if sys.platform.count("win32") >0:21 if sys.platform.count("win32") > 0: 20 22 _STATICBOX_WIDTH = 450 21 23 PANEL_WIDTH = 500 … … 39 41 Initialization. The parameters added to Dialog are: 40 42 41 :param list: report_list (list of html_str, text_str, image) from invariant_state 43 :param list: report_list (list of html_str, text_str, image) 44 from invariant_state 42 45 """ 43 46 kwds["style"] = wx.RESIZE_BORDER|wx.DEFAULT_DIALOG_STYLE … … 51 54 self.SetWindowVariant(variant=FONT_VARIANT) 52 55 # report string 53 self.report_list = list56 self.report_list = list 54 57 # put image path in the report string 55 self.report_html = self.report_list[0] % "memory:img_inv.png"58 self.report_html = self.report_list[0] % "memory:img_inv.png" 56 59 # layout 57 60 self._setup_layout() … … 74 77 button_preview = wx.Button(self, id, "Preview") 75 78 button_preview.SetToolTipString("Print preview this report.") 76 button_preview.Bind(wx.EVT_BUTTON, self.onPreview, id = button_preview.GetId()) 79 button_preview.Bind(wx.EVT_BUTTON, self.onPreview, 80 id=button_preview.GetId()) 77 81 hbox.Add(button_preview) 78 82 … … 80 84 button_print = wx.Button(self, id, "Print") 81 85 button_print.SetToolTipString("Print this report.") 82 button_print.Bind(wx.EVT_BUTTON, self.onPrint, id = button_print.GetId()) 86 button_print.Bind(wx.EVT_BUTTON, self.onPrint, 87 id=button_print.GetId()) 83 88 hbox.Add(button_print) 84 89 … … 91 96 # panel for report page 92 97 panel = wx.Panel(self, -1) 93 vbox = wx.BoxSizer(wx.VERTICAL)98 vbox = wx.BoxSizer(wx.VERTICAL) 94 99 # html window 95 100 self.hwindow = html.HtmlWindow(panel,style=wx.BORDER,size=(700,500)) … … 98 103 99 104 # add panels to boxsizers 100 vbox.Add(hbox, 30)101 vbox.Add(panel, 500, wx.EXPAND|wx.ALL)105 vbox.Add(hbox, 30) 106 vbox.Add(panel, 500, wx.EXPAND|wx.ALL) 102 107 103 108 self.SetSizerAndFit(vbox) … … 105 110 self.Show(True) 106 111 107 def onSave(self, event=None):112 def onSave(self, event=None): 108 113 """ 109 114 Save 110 115 """ 111 116 #todo: complete saving fig file and as a txt file 112 dlg = wx.FileDialog(self, "Choose a file", \113 wildcard 117 dlg = wx.FileDialog(self, "Choose a file", 118 wildcard='HTML files (*.html)|*.html|'+ 114 119 'Text files (*.txt)|*.txt', 115 style =wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR)120 style=wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR) 116 121 dlg.SetFilterIndex(0) #Set .html files to be default 117 122 118 123 if dlg.ShowModal() != wx.ID_OK: 119 dlg.Destroy()120 return124 dlg.Destroy() 125 return 121 126 122 127 fName = dlg.GetPath() … … 126 131 if ext_num == 0: 127 132 ext = '.html' 128 img_ext = '_img4html.png'133 img_ext = '_img4html.png' 129 134 report_frame = self.report_list[0] 130 135 elif ext_num == 1: 131 136 ext = '.txt' 132 # changing the image extension actually changes the image format on saving 133 img_ext= '_img4txt.pdf' 137 # changing the image extension actually changes the image 138 # format on saving 139 img_ext = '_img4txt.pdf' 134 140 report = self.report_list[1] 135 141 else: … … 142 148 pic_fname = os.path.splitext(fName)[0] + img_ext 143 149 #put the image path in html string 144 if ext_num == 0: report = report_frame % pic_fname 150 if ext_num == 0: 151 report = report_frame % pic_fname 145 152 f = open(fName, 'w') 146 153 f.write(report) … … 150 157 151 158 152 def onPreview(self, event=None):159 def onPreview(self, event=None): 153 160 """ 154 161 Preview … … 156 163 : event: Preview button event 157 164 """ 158 previewh =html.HtmlEasyPrinting(name="Printing", parentWindow=self)165 previewh = html.HtmlEasyPrinting(name="Printing", parentWindow=self) 159 166 previewh.PreviewText(self.report_html) 160 161 def onPrint(self,event=None): 167 if event is not None: 168 event.Skip() 169 170 def onPrint(self, event=None): 162 171 """ 163 172 Print … … 165 174 : event: Print button event 166 175 """ 167 printh =html.HtmlEasyPrinting(name="Printing", parentWindow=self)176 printh = html.HtmlEasyPrinting(name="Printing", parentWindow=self) 168 177 printh.PrintText(self.report_html) 169 178 if event is not None: 179 event.Skip() 170 180 171 181 def OnClose(self,event=None): … … 175 185 : event: Close button event 176 186 """ 177 178 187 self.Close() 179 188 … … 188 197 f = file(filename, "wb") 189 198 # pisa requires some extra packages, see their web-site 190 pdf = pisa.CreatePDF(data,f) 191 # close the file here otherwise it will be open until quitting the application. 199 pdf = pisa.CreatePDF(data, f) 200 # close the file here otherwise it will be open until quitting 201 #the application. 192 202 f.close() 193 203
Note: See TracChangeset
for help on using the changeset viewer.