[f0bb711] | 1 | import time |
---|
| 2 | import logging |
---|
| 3 | import re |
---|
| 4 | import copy |
---|
| 5 | |
---|
[4992ff2] | 6 | from PyQt5 import QtCore |
---|
| 7 | from PyQt5 import QtGui |
---|
| 8 | from PyQt5 import QtWidgets |
---|
[d5c5d3d] | 9 | |
---|
| 10 | from sas.qtgui.Plotting.PlotterData import Data1D |
---|
| 11 | from sas.qtgui.Plotting.Plotter import PlotterWidget |
---|
| 12 | from sas.qtgui.Plotting.PlotterData import Data2D |
---|
| 13 | from sas.qtgui.Plotting.Plotter2D import Plotter2DWidget |
---|
| 14 | import sas.qtgui.Utilities.GuiUtils as GuiUtils |
---|
| 15 | |
---|
[b3e8629] | 16 | from .UI.DataOperationUtilityUI import Ui_DataOperationUtility |
---|
[d5c5d3d] | 17 | |
---|
| 18 | BG_WHITE = "background-color: rgb(255, 255, 255);" |
---|
| 19 | BG_RED = "background-color: rgb(244, 170, 164);" |
---|
| 20 | |
---|
[f0bb711] | 21 | |
---|
[4992ff2] | 22 | class DataOperationUtilityPanel(QtWidgets.QDialog, Ui_DataOperationUtility): |
---|
[d5c5d3d] | 23 | def __init__(self, parent=None): |
---|
| 24 | super(DataOperationUtilityPanel, self).__init__() |
---|
| 25 | self.setupUi(self) |
---|
| 26 | self.manager = parent |
---|
| 27 | self.communicator = self.manager.communicator() |
---|
| 28 | |
---|
| 29 | # To store input datafiles |
---|
| 30 | self.filenames = None |
---|
| 31 | self.list_data_items = [] |
---|
| 32 | self.data1 = None |
---|
| 33 | self.data2 = None |
---|
| 34 | # To store the result |
---|
| 35 | self.output = None |
---|
| 36 | |
---|
| 37 | # To update content of comboboxes with files loaded in DataExplorer |
---|
[f0bb711] | 38 | self.communicator.sendDataToPanelSignal.connect(self.updateCombobox) |
---|
[d5c5d3d] | 39 | |
---|
| 40 | # change index of comboboxes |
---|
| 41 | self.cbData1.currentIndexChanged.connect(self.onSelectData1) |
---|
| 42 | self.cbData2.currentIndexChanged.connect(self.onSelectData2) |
---|
| 43 | self.cbOperator.currentIndexChanged.connect(self.onSelectOperator) |
---|
| 44 | |
---|
| 45 | # edit Coefficient text edit |
---|
| 46 | self.txtNumber.textChanged.connect(self.onInputCoefficient) |
---|
| 47 | self.txtOutputData.textChanged.connect(self.onCheckOutputName) |
---|
| 48 | |
---|
| 49 | # push buttons |
---|
[f0bb711] | 50 | self.cmdClose.clicked.connect(self.onClose) |
---|
[d5c5d3d] | 51 | self.cmdHelp.clicked.connect(self.onHelp) |
---|
| 52 | self.cmdCompute.clicked.connect(self.onCompute) |
---|
| 53 | self.cmdReset.clicked.connect(self.onReset) |
---|
| 54 | |
---|
| 55 | self.cmdCompute.setEnabled(False) |
---|
| 56 | |
---|
| 57 | # validator for coefficient |
---|
[d6b8a1d] | 58 | self.txtNumber.setValidator(GuiUtils.DoubleValidator()) |
---|
[d5c5d3d] | 59 | |
---|
[4992ff2] | 60 | self.layoutOutput = QtWidgets.QHBoxLayout() |
---|
| 61 | self.layoutData1 = QtWidgets.QHBoxLayout() |
---|
| 62 | self.layoutData2 = QtWidgets.QHBoxLayout() |
---|
[d5c5d3d] | 63 | |
---|
[f0bb711] | 64 | # Create default layout for initial graphs (when they are still empty) |
---|
[d5c5d3d] | 65 | self.newPlot(self.graphOutput, self.layoutOutput) |
---|
| 66 | self.newPlot(self.graphData1, self.layoutData1) |
---|
| 67 | self.newPlot(self.graphData2, self.layoutData2) |
---|
| 68 | |
---|
| 69 | # Flag to enable Compute pushbutton |
---|
| 70 | self.data2OK = False |
---|
| 71 | self.data1OK = False |
---|
| 72 | |
---|
| 73 | def updateCombobox(self, filenames): |
---|
| 74 | """ Function to fill comboboxes with names of datafiles loaded in |
---|
| 75 | DataExplorer. For Data2, there is the additional option of choosing |
---|
| 76 | a number to apply to data1 """ |
---|
| 77 | self.filenames = filenames |
---|
| 78 | |
---|
[b3e8629] | 79 | if list(filenames.keys()): |
---|
[d5c5d3d] | 80 | # clear contents of comboboxes |
---|
| 81 | self.cbData1.clear() |
---|
| 82 | self.cbData1.addItems(['Select Data']) |
---|
| 83 | self.cbData2.clear() |
---|
| 84 | self.cbData2.addItems(['Select Data', 'Number']) |
---|
| 85 | |
---|
| 86 | list_datafiles = [] |
---|
| 87 | |
---|
[b3e8629] | 88 | for key_id in list(filenames.keys()): |
---|
[f0bb711] | 89 | if filenames[key_id].get_data().title: |
---|
[d5c5d3d] | 90 | # filenames with titles |
---|
[f0bb711] | 91 | new_title = filenames[key_id].get_data().title |
---|
[d5c5d3d] | 92 | list_datafiles.append(new_title) |
---|
| 93 | self.list_data_items.append(new_title) |
---|
| 94 | |
---|
| 95 | else: |
---|
| 96 | # filenames without titles by removing time.time() |
---|
[f0bb711] | 97 | new_title = re.sub('\d{10}\.\d{2}', '', str(key_id)) |
---|
[d5c5d3d] | 98 | self.list_data_items.append(new_title) |
---|
| 99 | list_datafiles.append(new_title) |
---|
| 100 | |
---|
| 101 | # update contents of comboboxes |
---|
| 102 | self.cbData1.addItems(list_datafiles) |
---|
| 103 | self.cbData2.addItems(list_datafiles) |
---|
| 104 | |
---|
| 105 | def onHelp(self): |
---|
| 106 | """ |
---|
| 107 | Bring up the Data Operation Utility Documentation whenever |
---|
| 108 | the HELP button is clicked. |
---|
| 109 | Calls Documentation Window with the path of the location within the |
---|
| 110 | documentation tree (after /doc/ ....". |
---|
| 111 | """ |
---|
[aed0532] | 112 | location = "/user/qtgui/Calculators/data_operator_help.html" |
---|
[e90988c] | 113 | self.manager.showHelp(location) |
---|
[d5c5d3d] | 114 | |
---|
| 115 | def onClose(self): |
---|
| 116 | """ Close dialog """ |
---|
| 117 | self.onReset() |
---|
[1420066] | 118 | |
---|
| 119 | self.cbData1.clear() |
---|
| 120 | self.cbData1.addItems(['No Data Available']) |
---|
| 121 | self.cbData2.clear() |
---|
| 122 | self.cbData2.addItems(['No Data Available']) |
---|
[d5c5d3d] | 123 | self.close() |
---|
| 124 | |
---|
[1420066] | 125 | |
---|
[d5c5d3d] | 126 | def onCompute(self): |
---|
| 127 | """ perform calculation """ |
---|
[0c468bf] | 128 | # set operator to be applied |
---|
| 129 | operator = self.cbOperator.currentText() |
---|
| 130 | # calculate and send data to DataExplorer |
---|
| 131 | output = None |
---|
| 132 | try: |
---|
| 133 | data1 = self.data1 |
---|
| 134 | data2 = self.data2 |
---|
[fbfc488] | 135 | output = eval("data1 %s data2" % operator) |
---|
| 136 | except Exception as ex: |
---|
| 137 | logging.error(ex) |
---|
| 138 | return |
---|
[0c468bf] | 139 | |
---|
| 140 | self.output = output |
---|
| 141 | |
---|
| 142 | # if outputname was unused, write output result to it |
---|
| 143 | # and display plot |
---|
| 144 | if self.onCheckOutputName(): |
---|
| 145 | # add outputname to self.filenames |
---|
| 146 | self.list_data_items.append(str(self.txtOutputData.text())) |
---|
| 147 | # send result to DataExplorer |
---|
| 148 | self.onPrepareOutputData() |
---|
| 149 | # plot result |
---|
| 150 | self.updatePlot(self.graphOutput, self.layoutOutput, self.output) |
---|
[d5c5d3d] | 151 | |
---|
| 152 | def onPrepareOutputData(self): |
---|
| 153 | """ Prepare datasets to be added to DataExplorer and DataManager """ |
---|
| 154 | new_item = GuiUtils.createModelItemWithPlot( |
---|
[cee5c78] | 155 | self.output, |
---|
[d5c5d3d] | 156 | name=self.txtOutputData.text()) |
---|
| 157 | |
---|
| 158 | new_datalist_item = {str(self.txtOutputData.text()) + str(time.time()): |
---|
| 159 | self.output} |
---|
| 160 | self.communicator. \ |
---|
| 161 | updateModelFromDataOperationPanelSignal.emit(new_item, new_datalist_item) |
---|
| 162 | |
---|
| 163 | def onSelectOperator(self): |
---|
[f0bb711] | 164 | """ Change GUI when operator changed """ |
---|
[d5c5d3d] | 165 | self.lblOperatorApplied.setText(self.cbOperator.currentText()) |
---|
| 166 | self.newPlot(self.graphOutput, self.layoutOutput) |
---|
| 167 | |
---|
| 168 | def onReset(self): |
---|
| 169 | """ |
---|
| 170 | Reset Panel to its initial state (default values) keeping |
---|
| 171 | the names of loaded data |
---|
| 172 | """ |
---|
| 173 | self.txtNumber.setText('1.0') |
---|
| 174 | self.txtOutputData.setText('MyNewDataName') |
---|
| 175 | |
---|
| 176 | self.txtNumber.setEnabled(False) |
---|
| 177 | self.cmdCompute.setEnabled(False) |
---|
| 178 | |
---|
| 179 | self.cbData1.setCurrentIndex(0) |
---|
| 180 | self.cbData2.setCurrentIndex(0) |
---|
| 181 | self.cbOperator.setCurrentIndex(0) |
---|
| 182 | |
---|
| 183 | self.data1OK = False |
---|
| 184 | self.data2OK = False |
---|
| 185 | |
---|
| 186 | # Empty graphs |
---|
| 187 | self.newPlot(self.graphOutput, self.layoutOutput) |
---|
| 188 | self.newPlot(self.graphData1, self.layoutData1) |
---|
| 189 | self.newPlot(self.graphData2, self.layoutData2) |
---|
| 190 | |
---|
| 191 | def onSelectData1(self): |
---|
| 192 | """ Plot for selection of Data1 """ |
---|
| 193 | choice_data1 = str(self.cbData1.currentText()) |
---|
| 194 | |
---|
| 195 | wrong_choices = ['No Data Available', 'Select Data', ''] |
---|
| 196 | |
---|
| 197 | if choice_data1 in wrong_choices: |
---|
| 198 | # check validity of choice: input = filename |
---|
| 199 | self.newPlot(self.graphData1, self.layoutData1) |
---|
| 200 | self.data1 = None |
---|
| 201 | self.data1OK = False |
---|
[0c468bf] | 202 | self.cmdCompute.setEnabled(False) # self.onCheckChosenData()) |
---|
[d5c5d3d] | 203 | return |
---|
| 204 | |
---|
| 205 | else: |
---|
| 206 | self.data1OK = True |
---|
| 207 | # get Data1 |
---|
[f0bb711] | 208 | key_id1 = self._findId(choice_data1) |
---|
| 209 | self.data1 = self._extractData(key_id1) |
---|
[d5c5d3d] | 210 | # plot Data1 |
---|
| 211 | self.updatePlot(self.graphData1, self.layoutData1, self.data1) |
---|
| 212 | # plot default for output graph |
---|
| 213 | self.newPlot(self.graphOutput, self.layoutOutput) |
---|
[0c468bf] | 214 | # Enable Compute button only if Data2 is defined and data compatible |
---|
| 215 | self.cmdCompute.setEnabled(self.onCheckChosenData()) |
---|
[f0bb711] | 216 | |
---|
[d5c5d3d] | 217 | def onSelectData2(self): |
---|
| 218 | """ Plot for selection of Data2 """ |
---|
| 219 | choice_data2 = str(self.cbData2.currentText()) |
---|
| 220 | wrong_choices = ['No Data Available', 'Select Data', ''] |
---|
| 221 | |
---|
| 222 | if choice_data2 in wrong_choices: |
---|
| 223 | self.newPlot(self.graphData2, self.layoutData2) |
---|
| 224 | self.txtNumber.setEnabled(False) |
---|
| 225 | self.data2OK = False |
---|
[f0bb711] | 226 | self.onCheckChosenData() |
---|
[0c468bf] | 227 | self.cmdCompute.setEnabled(False) |
---|
[d5c5d3d] | 228 | return |
---|
| 229 | |
---|
| 230 | elif choice_data2 == 'Number': |
---|
| 231 | self.data2OK = True |
---|
| 232 | self.txtNumber.setEnabled(True) |
---|
| 233 | self.data2 = float(self.txtNumber.text()) |
---|
| 234 | |
---|
[0c468bf] | 235 | # Enable Compute button only if Data1 defined and compatible data |
---|
| 236 | self.cmdCompute.setEnabled(self.onCheckChosenData()) |
---|
[d5c5d3d] | 237 | # Display value of coefficient in graphData2 |
---|
| 238 | self.updatePlot(self.graphData2, self.layoutData2, self.data2) |
---|
| 239 | # plot default for output graph |
---|
| 240 | self.newPlot(self.graphOutput, self.layoutOutput) |
---|
[f0bb711] | 241 | self.onCheckChosenData() |
---|
[d5c5d3d] | 242 | |
---|
| 243 | else: |
---|
| 244 | self.txtNumber.setEnabled(False) |
---|
[0c468bf] | 245 | self.data2OK = True |
---|
[f0bb711] | 246 | key_id2 = self._findId(choice_data2) |
---|
| 247 | self.data2 = self._extractData(key_id2) |
---|
[0c468bf] | 248 | self.cmdCompute.setEnabled(self.onCheckChosenData()) |
---|
| 249 | |
---|
[d5c5d3d] | 250 | # plot Data2 |
---|
| 251 | self.updatePlot(self.graphData2, self.layoutData2, self.data2) |
---|
| 252 | # plot default for output graph |
---|
| 253 | self.newPlot(self.graphOutput, self.layoutOutput) |
---|
| 254 | |
---|
| 255 | def onInputCoefficient(self): |
---|
| 256 | """ Check input of number when a coefficient is required |
---|
| 257 | for operation """ |
---|
| 258 | if self.txtNumber.isModified(): |
---|
| 259 | input_to_check = str(self.txtNumber.text()) |
---|
| 260 | |
---|
| 261 | if input_to_check is None or input_to_check is '': |
---|
| 262 | msg = 'DataOperation: Number requires a float number' |
---|
[7d9c83c] | 263 | logging.warning(msg) |
---|
[7fb471d] | 264 | self.txtNumber.setStyleSheet(BG_RED) |
---|
[d5c5d3d] | 265 | |
---|
| 266 | elif float(self.txtNumber.text()) == 0.: |
---|
| 267 | # should be check that 0 is not chosen |
---|
| 268 | msg = 'DataOperation: Number requires a non zero number' |
---|
[7d9c83c] | 269 | logging.warning(msg) |
---|
[7fb471d] | 270 | self.txtNumber.setStyleSheet(BG_RED) |
---|
[d5c5d3d] | 271 | |
---|
| 272 | else: |
---|
[7fb471d] | 273 | self.txtNumber.setStyleSheet(BG_WHITE) |
---|
[d5c5d3d] | 274 | self.data2 = float(self.txtNumber.text()) |
---|
| 275 | self.updatePlot(self.graphData2, self.layoutData2, self.data2) |
---|
| 276 | |
---|
| 277 | def onCheckChosenData(self): |
---|
[0c468bf] | 278 | """ check that data1 and data2 are compatible """ |
---|
[d5c5d3d] | 279 | |
---|
[0c468bf] | 280 | if not all([self.data1OK, self.data2OK]): |
---|
[d5c5d3d] | 281 | return False |
---|
| 282 | else: |
---|
[0c468bf] | 283 | if self.cbData2.currentText() == 'Number': |
---|
[7fb471d] | 284 | self.cbData1.setStyleSheet(BG_WHITE) |
---|
| 285 | self.cbData2.setStyleSheet(BG_WHITE) |
---|
[0c468bf] | 286 | return True |
---|
| 287 | |
---|
| 288 | elif self.data1.__class__.__name__ != self.data2.__class__.__name__: |
---|
[7fb471d] | 289 | self.cbData1.setStyleSheet(BG_RED) |
---|
| 290 | self.cbData2.setStyleSheet(BG_RED) |
---|
[b3e8629] | 291 | print(self.data1.__class__.__name__ != self.data2.__class__.__name__) |
---|
[7d9c83c] | 292 | logging.warning('Cannot compute data of different dimensions') |
---|
[0c468bf] | 293 | return False |
---|
| 294 | |
---|
| 295 | elif self.data1.__class__.__name__ == 'Data1D'\ |
---|
| 296 | and (len(self.data2.x) != len(self.data1.x) or |
---|
| 297 | not all(i == j for i, j in zip(self.data1.x, self.data2.x))): |
---|
[7d9c83c] | 298 | logging.warning('Cannot compute 1D data of different lengths') |
---|
[7fb471d] | 299 | self.cbData1.setStyleSheet(BG_RED) |
---|
| 300 | self.cbData2.setStyleSheet(BG_RED) |
---|
[0c468bf] | 301 | return False |
---|
| 302 | |
---|
| 303 | elif self.data1.__class__.__name__ == 'Data2D' \ |
---|
| 304 | and (len(self.data2.qx_data) != len(self.data1.qx_data) \ |
---|
| 305 | or len(self.data2.qy_data) != len(self.data1.qy_data) |
---|
| 306 | or not all(i == j for i, j in |
---|
| 307 | zip(self.data1.qx_data, self.data2.qx_data)) |
---|
| 308 | or not all(i == j for i, j in |
---|
| 309 | zip(self.data1.qy_data, self.data2.qy_data)) |
---|
| 310 | ): |
---|
[7fb471d] | 311 | self.cbData1.setStyleSheet(BG_RED) |
---|
| 312 | self.cbData2.setStyleSheet(BG_RED) |
---|
[7d9c83c] | 313 | logging.warning('Cannot compute 2D data of different lengths') |
---|
[0c468bf] | 314 | return False |
---|
| 315 | |
---|
| 316 | else: |
---|
[7fb471d] | 317 | self.cbData1.setStyleSheet(BG_WHITE) |
---|
| 318 | self.cbData2.setStyleSheet(BG_WHITE) |
---|
[0c468bf] | 319 | return True |
---|
[d5c5d3d] | 320 | |
---|
| 321 | def onCheckOutputName(self): |
---|
| 322 | """ Check that name of output does not already exist """ |
---|
| 323 | name_to_check = str(self.txtOutputData.text()) |
---|
[7fb471d] | 324 | self.txtOutputData.setStyleSheet(BG_WHITE) |
---|
[d5c5d3d] | 325 | |
---|
| 326 | if name_to_check is None or name_to_check == '': |
---|
[7fb471d] | 327 | self.txtOutputData.setStyleSheet(BG_RED) |
---|
[7d9c83c] | 328 | logging.warning('No output name') |
---|
[d5c5d3d] | 329 | return False |
---|
| 330 | |
---|
| 331 | elif name_to_check in self.list_data_items: |
---|
[7fb471d] | 332 | self.txtOutputData.setStyleSheet(BG_RED) |
---|
[7d9c83c] | 333 | logging.warning('The Output data name already exists') |
---|
[d5c5d3d] | 334 | return False |
---|
| 335 | |
---|
| 336 | else: |
---|
[7fb471d] | 337 | self.txtOutputData.setStyleSheet(BG_WHITE) |
---|
[d5c5d3d] | 338 | return True |
---|
| 339 | |
---|
| 340 | # ######## |
---|
| 341 | # Modification of inputs |
---|
| 342 | # ######## |
---|
| 343 | def _findId(self, name): |
---|
| 344 | """ find id of name in list of filenames """ |
---|
[b3e8629] | 345 | isinstance(name, str) |
---|
[d5c5d3d] | 346 | |
---|
[b3e8629] | 347 | for key_id in list(self.filenames.keys()): |
---|
[d5c5d3d] | 348 | # data with title |
---|
[f0bb711] | 349 | if self.filenames[key_id].get_data().title: |
---|
| 350 | input = self.filenames[key_id].get_data().title |
---|
[d5c5d3d] | 351 | # data without title |
---|
| 352 | else: |
---|
[f0bb711] | 353 | input = str(key_id) |
---|
[d5c5d3d] | 354 | if name in input: |
---|
[f0bb711] | 355 | return key_id |
---|
[d5c5d3d] | 356 | |
---|
[f0bb711] | 357 | def _extractData(self, key_id): |
---|
[d5c5d3d] | 358 | """ Extract data from file with id contained in list of filenames """ |
---|
[f0bb711] | 359 | data_complete = self.filenames[key_id].get_data() |
---|
[d5c5d3d] | 360 | dimension = data_complete.__class__.__name__ |
---|
| 361 | |
---|
[f0bb711] | 362 | if dimension in ('Data1D', 'Data2D'): |
---|
| 363 | return copy.deepcopy(data_complete) |
---|
[d5c5d3d] | 364 | |
---|
| 365 | else: |
---|
[7d9c83c] | 366 | logging.warning('Error with data format') |
---|
[d5c5d3d] | 367 | return |
---|
| 368 | |
---|
| 369 | # ######## |
---|
| 370 | # PLOTS |
---|
| 371 | # ######## |
---|
| 372 | def newPlot(self, graph, layout): |
---|
| 373 | """ Create template for graphs with default '?' layout""" |
---|
[4992ff2] | 374 | assert isinstance(graph, QtWidgets.QGraphicsView) |
---|
| 375 | assert isinstance(layout, QtWidgets.QHBoxLayout) |
---|
[d5c5d3d] | 376 | |
---|
| 377 | # clear layout |
---|
| 378 | if layout.count() > 0: |
---|
| 379 | item = layout.takeAt(0) |
---|
| 380 | layout.removeItem(item) |
---|
| 381 | |
---|
| 382 | layout.setContentsMargins(0, 0, 0, 0) |
---|
[f0bb711] | 383 | layout.addWidget(self.prepareSubgraphWithData("?")) |
---|
[d5c5d3d] | 384 | |
---|
| 385 | graph.setLayout(layout) |
---|
| 386 | |
---|
| 387 | def updatePlot(self, graph, layout, data): |
---|
| 388 | """ plot data in graph after clearing its layout """ |
---|
| 389 | |
---|
[4992ff2] | 390 | assert isinstance(graph, QtWidgets.QGraphicsView) |
---|
| 391 | assert isinstance(layout, QtWidgets.QHBoxLayout) |
---|
[d5c5d3d] | 392 | |
---|
| 393 | # clear layout |
---|
| 394 | if layout.count() > 0: |
---|
| 395 | item = layout.takeAt(0) |
---|
| 396 | layout.removeItem(item) |
---|
| 397 | |
---|
| 398 | layout.setContentsMargins(0, 0, 0, 0) |
---|
| 399 | |
---|
| 400 | if isinstance(data, Data2D): |
---|
| 401 | # plot 2D data |
---|
| 402 | plotter2D = Plotter2DWidget(self, quickplot=True) |
---|
| 403 | plotter2D.data = data |
---|
| 404 | plotter2D.scale = 'linear' |
---|
| 405 | |
---|
| 406 | plotter2D.ax.tick_params(axis='x', labelsize=8) |
---|
| 407 | plotter2D.ax.tick_params(axis='y', labelsize=8) |
---|
| 408 | |
---|
| 409 | # Draw zero axis lines. |
---|
| 410 | plotter2D.ax.axhline(linewidth=1) |
---|
| 411 | plotter2D.ax.axvline(linewidth=1) |
---|
| 412 | |
---|
| 413 | graph.setLayout(layout) |
---|
| 414 | layout.addWidget(plotter2D) |
---|
| 415 | # remove x- and ylabels |
---|
| 416 | plotter2D.y_label = '' |
---|
| 417 | plotter2D.x_label = '' |
---|
| 418 | plotter2D.plot(show_colorbar=False) |
---|
| 419 | plotter2D.show() |
---|
| 420 | |
---|
| 421 | elif isinstance(data, Data1D): |
---|
| 422 | # plot 1D data |
---|
| 423 | plotter = PlotterWidget(self, quickplot=True) |
---|
[42787fb] | 424 | data.scale = 'linear' |
---|
[d5c5d3d] | 425 | plotter.data = data |
---|
[42787fb] | 426 | plotter.showLegend = False |
---|
[d5c5d3d] | 427 | graph.setLayout(layout) |
---|
| 428 | layout.addWidget(plotter) |
---|
| 429 | |
---|
| 430 | plotter.ax.tick_params(axis='x', labelsize=8) |
---|
| 431 | plotter.ax.tick_params(axis='y', labelsize=8) |
---|
| 432 | |
---|
[f0bb711] | 433 | plotter.plot(hide_error=True, marker='.') |
---|
[d5c5d3d] | 434 | |
---|
| 435 | plotter.show() |
---|
| 436 | |
---|
| 437 | elif float(data) and self.cbData2.currentText() == 'Number': |
---|
| 438 | # display value of coefficient (to be applied to Data1) |
---|
| 439 | # in graphData2 |
---|
[f0bb711] | 440 | layout.addWidget(self.prepareSubgraphWithData(data)) |
---|
[d5c5d3d] | 441 | |
---|
[f0bb711] | 442 | graph.setLayout(layout) |
---|
[d5c5d3d] | 443 | |
---|
[f0bb711] | 444 | def prepareSubgraphWithData(self, data): |
---|
| 445 | """ Create graphics view containing scene with string """ |
---|
[4992ff2] | 446 | scene = QtWidgets.QGraphicsScene() |
---|
[f0bb711] | 447 | scene.addText(str(data)) |
---|
[d5c5d3d] | 448 | |
---|
[4992ff2] | 449 | subgraph = QtWidgets.QGraphicsView() |
---|
[f0bb711] | 450 | subgraph.setScene(scene) |
---|
| 451 | |
---|
| 452 | return subgraph |
---|