Changeset f0bb711 in sasview for src/sas/qtgui/Calculators/DataOperationUtilityPanel.py
- Timestamp:
- Oct 19, 2017 8:25:24 AM (7 years ago)
- Branches:
- 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
- Children:
- 0c468bf
- Parents:
- d5c5d3d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Calculators/DataOperationUtilityPanel.py
rd5c5d3d rf0bb711 1 import time 2 import logging 3 import re 4 import copy 5 1 6 from PyQt4 import QtGui 2 7 from PyQt4 import QtCore … … 6 11 from sas.qtgui.Plotting.PlotterData import Data2D 7 12 from sas.qtgui.Plotting.Plotter2D import Plotter2DWidget 8 9 13 import sas.qtgui.Utilities.GuiUtils as GuiUtils 14 10 15 from UI.DataOperationUtilityUI import Ui_DataOperationUtility 11 12 import time13 import logging14 import re15 16 16 17 BG_WHITE = "background-color: rgb(255, 255, 255);" 17 18 BG_RED = "background-color: rgb(244, 170, 164);" 19 18 20 19 21 class DataOperationUtilityPanel(QtGui.QDialog, Ui_DataOperationUtility): … … 33 35 34 36 # To update content of comboboxes with files loaded in DataExplorer 35 self.communicator.sendDataToPanel .connect(self.updateCombobox)37 self.communicator.sendDataToPanelSignal.connect(self.updateCombobox) 36 38 37 39 # change index of comboboxes … … 45 47 46 48 # push buttons 47 self.cmdClose.clicked.connect(self.onClose) # accept)49 self.cmdClose.clicked.connect(self.onClose) 48 50 self.cmdHelp.clicked.connect(self.onHelp) 49 51 self.cmdCompute.clicked.connect(self.onCompute) … … 55 57 self.txtNumber.setValidator(QtGui.QDoubleValidator()) 56 58 57 # Add "?" to initial graphs (when they are still empty)58 59 self.layoutOutput = QtGui.QHBoxLayout() 59 60 self.layoutData1 = QtGui.QHBoxLayout() 60 61 self.layoutData2 = QtGui.QHBoxLayout() 61 62 63 # Create default layout for initial graphs (when they are still empty) 62 64 self.newPlot(self.graphOutput, self.layoutOutput) 63 65 self.newPlot(self.graphData1, self.layoutData1) … … 83 85 list_datafiles = [] 84 86 85 for id in filenames.keys():86 if filenames[ id].get_data().title != '':87 for key_id in filenames.keys(): 88 if filenames[key_id].get_data().title: 87 89 # filenames with titles 88 new_title = filenames[ id].get_data().title90 new_title = filenames[key_id].get_data().title 89 91 list_datafiles.append(new_title) 90 92 self.list_data_items.append(new_title) … … 92 94 else: 93 95 # filenames without titles by removing time.time() 94 new_title = re.sub('\d{10}\.\d{2}', '', str( id))96 new_title = re.sub('\d{10}\.\d{2}', '', str(key_id)) 95 97 self.list_data_items.append(new_title) 96 98 list_datafiles.append(new_title) … … 161 163 162 164 def onSelectOperator(self): 163 """ Change GUI when operator changed """165 """ Change GUI when operator changed """ 164 166 self.lblOperatorApplied.setText(self.cbOperator.currentText()) 165 167 self.newPlot(self.graphOutput, self.layoutOutput) … … 183 185 self.data1 = None 184 186 self.data2 = None 187 self.filenames = None 188 self.list_data_items = [] 185 189 186 190 self.data1OK = False … … 204 208 self.data1OK = False 205 209 self.cmdCompute.setEnabled(False) 206 # logging.info('Choose a file for Data1')210 self.onCheckChosenData() 207 211 return 208 212 … … 211 215 self.cmdCompute.setEnabled(self.data2OK) 212 216 self.data1OK = True 217 self.onCheckChosenData() 213 218 # get Data1 214 id1 = self._findId(choice_data1)215 self.data1 = self._extractData( id1)219 key_id1 = self._findId(choice_data1) 220 self.data1 = self._extractData(key_id1) 216 221 # plot Data1 217 222 self.updatePlot(self.graphData1, self.layoutData1, self.data1) … … 219 224 self.newPlot(self.graphOutput, self.layoutOutput) 220 225 226 221 227 def onSelectData2(self): 222 228 """ Plot for selection of Data2 """ … … 228 234 self.txtNumber.setEnabled(False) 229 235 self.data2OK = False 230 # logging.info('Choose a file or a number for Data2')236 self.onCheckChosenData() 231 237 return 232 238 … … 242 248 # plot default for output graph 243 249 self.newPlot(self.graphOutput, self.layoutOutput) 250 self.onCheckChosenData() 244 251 245 252 else: … … 247 254 self.data2OK = True 248 255 self.txtNumber.setEnabled(False) 249 id2 = self._findId(choice_data2)250 self.data2 = self._extractData( id2)256 key_id2 = self._findId(choice_data2) 257 self.data2 = self._extractData(key_id2) 251 258 # plot Data2 252 259 self.updatePlot(self.graphData2, self.layoutData2, self.data2) 253 260 # plot default for output graph 254 261 self.newPlot(self.graphOutput, self.layoutOutput) 262 self.onCheckChosenData() 255 263 256 264 def onInputCoefficient(self): … … 323 331 if name_to_check is None or name_to_check == '': 324 332 self.txtOutputData.setStyleSheet(QtCore.QString(BG_RED)) 325 logging.info(' no output name')333 logging.info('No output name') 326 334 return False 327 335 328 336 elif name_to_check in self.list_data_items: 329 337 self.txtOutputData.setStyleSheet(QtCore.QString(BG_RED)) 330 logging.info('The Output Data Name already exists')338 logging.info('The Output data name already exists') 331 339 return False 332 340 … … 342 350 isinstance(name, basestring) 343 351 344 for id in self.filenames.keys():352 for key_id in self.filenames.keys(): 345 353 # data with title 346 if self.filenames[ id].get_data().title:347 input = self.filenames[ id].get_data().title354 if self.filenames[key_id].get_data().title: 355 input = self.filenames[key_id].get_data().title 348 356 # data without title 349 357 else: 350 input = str( id)358 input = str(key_id) 351 359 if name in input: 352 return id353 354 def _extractData(self, id):360 return key_id 361 362 def _extractData(self, key_id): 355 363 """ Extract data from file with id contained in list of filenames """ 356 data_complete = self.filenames[ id].get_data()364 data_complete = self.filenames[key_id].get_data() 357 365 dimension = data_complete.__class__.__name__ 358 366 359 if dimension == 'Data1D': 360 data_set = Data1D(x=data_complete.x, 361 y=data_complete.y, 362 dx=data_complete.dx, 363 dy=data_complete.dy) 364 365 elif dimension == 'Data2D': 366 data_set = Data2D(image=data_complete.data, 367 err_image=data_complete.err_data, 368 mask=data_complete.mask, 369 qx_data=data_complete.qx_data, 370 qy_data=data_complete.qy_data, 371 dqx_data=data_complete.dqx_data, 372 dqy_data=data_complete.dqy_data, 373 q_data=data_complete.q_data, 374 xmin=data_complete.xmin, 375 xmax=data_complete.xmax, 376 ymin=data_complete.ymin, 377 ymax=data_complete.ymax, 378 zmin=data_complete.zmin, 379 zmax=data_complete.zmax) 367 if dimension in ('Data1D', 'Data2D'): 368 return copy.deepcopy(data_complete) 380 369 381 370 else: 382 371 logging.info('Error with data format') 383 372 return 384 385 return data_set386 373 387 374 # ######## … … 399 386 400 387 layout.setContentsMargins(0, 0, 0, 0) 401 402 # define default content: '?' 403 scene = QtGui.QGraphicsScene() 404 scene.addText("?") 405 406 subgraph = QtGui.QGraphicsView() 407 subgraph.setScene(scene) 408 409 layout.addWidget(subgraph) 388 layout.addWidget(self.prepareSubgraphWithData("?")) 410 389 411 390 graph.setLayout(layout) … … 456 435 plotter.ax.tick_params(axis='y', labelsize=8) 457 436 458 plotter.plot(hide_error=True, marker='.', show_legend=False) 437 plotter.plot(hide_error=True, marker='.') 438 # plotter.legend = None 459 439 460 440 plotter.show() … … 463 443 # display value of coefficient (to be applied to Data1) 464 444 # in graphData2 465 scene = QtGui.QGraphicsScene() 466 scene.addText(str(data)) 467 468 subgraph = QtGui.QGraphicsView() 469 subgraph.setScene(scene) 470 471 layout.addWidget(subgraph) 445 layout.addWidget(self.prepareSubgraphWithData(data)) 472 446 473 447 graph.setLayout(layout) 448 449 def prepareSubgraphWithData(self, data): 450 """ Create graphics view containing scene with string """ 451 scene = QtGui.QGraphicsScene() 452 scene.addText(str(data)) 453 454 subgraph = QtGui.QGraphicsView() 455 subgraph.setScene(scene) 456 457 return subgraph
Note: See TracChangeset
for help on using the changeset viewer.