- 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
- Location:
- src/sas/qtgui
- Files:
-
- 8 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 -
src/sas/qtgui/Calculators/UI/DataOperationUtilityUI.ui
rd5c5d3d rf0bb711 12 12 </property> 13 13 <property name="sizePolicy"> 14 <sizepolicy hsizetype=" MinimumExpanding" vsizetype="MinimumExpanding">14 <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> 15 15 <horstretch>0</horstretch> 16 16 <verstretch>0</verstretch> … … 19 19 <property name="minimumSize"> 20 20 <size> 21 <width>95 0</width>21 <width>951</width> 22 22 <height>425</height> 23 23 </size> … … 25 25 <property name="maximumSize"> 26 26 <size> 27 <width> 1000</width>28 <height> 500</height>27 <width>951</width> 28 <height>425</height> 29 29 </size> 30 30 </property> -
src/sas/qtgui/MainWindow/DataExplorer.py
rd5c5d3d rf0bb711 281 281 # Use 'while' so the row count is forced at every iteration 282 282 deleted_indices = [] 283 # deleted_names = [] 283 284 while ind < self.model.rowCount(): 284 285 ind += 1 285 286 item = self.model.item(ind) 287 286 288 if item and item.isCheckable() and item.checkState() == QtCore.Qt.Checked: 287 289 # Delete these rows from the model 290 # deleted_names.append(self.model.item(ind).text()) 288 291 deleted_indices.append(item) 292 289 293 self.model.removeRow(ind) 290 294 # Decrement index since we just deleted it … … 293 297 # Let others know we deleted data 294 298 self.communicator.dataDeletedSignal.emit(deleted_indices) 299 300 # update stored_data 301 # self.manager.delete_by_name(deleted_names) 302 295 303 296 304 def deleteTheory(self, event): -
src/sas/qtgui/MainWindow/DataManager.py
rdc5ef15 rf0bb711 275 275 del self.stored_data[id] 276 276 277 278 277 def get_by_name(self, name_list=None): 279 278 """ -
src/sas/qtgui/MainWindow/GuiManager.py
rd5c5d3d rf0bb711 534 534 """ 535 535 """ 536 self.communicate.sendDataToPanel .emit(self._data_manager.get_all_data())536 self.communicate.sendDataToPanelSignal.emit(self._data_manager.get_all_data()) 537 537 538 538 self.DataOperation.show() -
src/sas/qtgui/Plotting/Plotter.py
rd5c5d3d rf0bb711 58 58 self.title(title=value.name) 59 59 60 def plot(self, data=None, color=None, marker=None, hide_error=False , show_legend=True):60 def plot(self, data=None, color=None, marker=None, hide_error=False): 61 61 """ 62 62 Add a new plot of self._data to the chart. … … 145 145 146 146 # Now add the legend with some customizations. 147 if show_legend: 148 149 150 147 148 self.legend = ax.legend(loc='upper right', shadow=True) 149 if self.legend: 150 self.legend.set_picker(True) 151 151 152 152 # Current labels for axes -
src/sas/qtgui/Utilities/GuiUtils.py
rd5c5d3d rf0bb711 144 144 # custom open_path 145 145 open_folder = custom_config.DEFAULT_OPEN_FOLDER 146 if open_folder !=None and os.path.isdir(open_folder):146 if open_folder is not None and os.path.isdir(open_folder): 147 147 DEFAULT_OPEN_FOLDER = os.path.abspath(open_folder) 148 148 else: … … 231 231 232 232 # Send data to Data Operation Utility panel 233 sendDataToPanel = QtCore.pyqtSignal(dict)233 sendDataToPanelSignal = QtCore.pyqtSignal(dict) 234 234 235 235 # Send result of Data Operation Utility panel to Data Explorer … … 528 528 has_errors = False 529 529 if has_errors: 530 if data.dx !=None and data.dx != []:530 if data.dx is not None and data.dx != []: 531 531 out.write("<X> <Y> <dY> <dX>\n") 532 532 else: … … 537 537 for i in range(len(data.x)): 538 538 if has_errors: 539 if data.dx !=None and data.dx != []:539 if data.dx is not None and data.dx != []: 540 540 if data.dx[i] != None: 541 541 out.write("%g %g %g %g\n" % (data.x[i], -
src/sas/qtgui/Utilities/UnitTesting/GuiUtilsTest.py
rd5c5d3d rf0bb711 69 69 'progressBarUpdateSignal', 70 70 'activeGraphName', 71 'sendDataToPanel ',71 'sendDataToPanelSignal', 72 72 'updateModelFromDataOperationPanelSignal' 73 73 ]
Note: See TracChangeset
for help on using the changeset viewer.