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