Changeset d744767 in sasview for src/sas/qtgui/Plotting
- Timestamp:
- Mar 16, 2018 2:05:42 PM (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:
- 47bf906
- Parents:
- 477c473 (diff), e4c475b7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- src/sas/qtgui/Plotting
- Files:
-
- 44 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Plotting/AddText.py
r83eb5208 r53c771e 1 from PyQt4 import QtGui 1 from PyQt5 import QtCore 2 from PyQt5 import QtGui 3 from PyQt5 import QtWidgets 2 4 3 5 import sas.sasview … … 5 7 from sas.qtgui.Plotting.UI.AddTextUI import Ui_AddText 6 8 7 class AddText(Qt Gui.QDialog, Ui_AddText):9 class AddText(QtWidgets.QDialog, Ui_AddText): 8 10 """ Simple GUI for a single line text query """ 9 11 def __init__(self, parent=None): … … 29 31 Pop up the standard Qt Font change dialog 30 32 """ 31 self._font, ok = Qt Gui.QFontDialog.getFont(parent=self)33 self._font, ok = QtWidgets.QFontDialog.getFont(parent=self) 32 34 if ok: 33 35 self.textEdit.setFont(self._font) … … 38 40 """ 39 41 # Pick up the chosen color 40 self._color = Qt Gui.QColorDialog.getColor(parent=self)42 self._color = QtWidgets.QColorDialog.getColor(parent=self) 41 43 # Update the text control 42 44 palette = QtGui.QPalette() -
src/sas/qtgui/Plotting/Arrow3D.py
- Property mode changed from 100755 to 100644
rfef38e8 rcee5c78 29 29 self.base = base 30 30 31 if base !=None:31 if base is not None: 32 32 # To turn the updating off during dragging 33 33 base.canvas.mpl_connect('button_press_event', self.on_left_down) … … 59 59 return 60 60 xs3d, ys3d, zs3d = self._verts3d 61 for i in xrange(len(xs3d)):61 for i in range(len(xs3d)): 62 62 xs, ys, _ = proj3d.proj_transform(xs3d[i], ys3d[i], zs3d[i], renderer.M) 63 63 self.set_positions((xs[0], ys[0]), (xs[1], ys[1])) -
src/sas/qtgui/Plotting/Binder.py
- Property mode changed from 100755 to 100644
rdc5ef15 rcee5c78 24 24 return self.artist is not other.artist 25 25 26 def __ nonzero__(self):26 def __bool__(self): 27 27 return self.artist is not None 28 28 … … 61 61 ] 62 62 except: 63 print "bypassing scroll_event: wrong matplotlib version"63 print("bypassing scroll_event: wrong matplotlib version") 64 64 self._connections = [ 65 65 canvas.mpl_connect('motion_notify_event', self._onMotion), … … 121 121 for cid in self._connections: self.canvas.mpl_disconnect(cid) 122 122 except: 123 logging.error("Error disconnection canvas: %s" % sys.exc_ value)123 logging.error("Error disconnection canvas: %s" % sys.exc_info()[1]) 124 124 self._connections = [] 125 125 … … 185 185 # Check that the trigger is valid 186 186 if trigger not in self._actions: 187 raise ValueError ,"%s invalid --- valid triggers are %s"\188 % (trigger, ", ".join(self.events)) 187 raise ValueError("%s invalid --- valid triggers are %s"\ 188 % (trigger, ", ".join(self.events))) 189 189 190 190 # Register the trigger callback … … 201 201 """ 202 202 if action not in self.events: 203 raise ValueError , "Trigger expects " + ", ".join(self.events)203 raise ValueError("Trigger expects " + ", ".join(self.events)) 204 204 205 205 # Tag the event with modifiers … … 233 233 """ 234 234 # TODO: sort by zorder of axes then by zorder within axes 235 self._artists.sort(cmp=lambda x, y: cmp(y.zorder, x.zorder)) 235 #self._artists.sort(cmp=lambda x, y: cmp(y.zorder, x.zorder)) 236 #self._artists.sort(cmp=lambda x, y: y.zorder.__gt__(x.zorder)) 236 237 found = Selection() 237 238 for artist in self._artists: -
src/sas/qtgui/Plotting/BoxSum.py
rcd2cc745 rd6b8a1d 2 2 Allows users to modify the box slicer parameters. 3 3 """ 4 from PyQt4 import QtGui 5 from PyQt4 import QtCore 4 from PyQt5 import QtCore 5 from PyQt5 import QtGui 6 from PyQt5 import QtWidgets 7 8 import sas.qtgui.Utilities.GuiUtils as GuiUtils 6 9 7 10 # Local UI … … 9 12 from sas.qtgui.Plotting.UI.BoxSumUI import Ui_BoxSumUI 10 13 11 class BoxSum(QtGui.QDialog, Ui_BoxSumUI): 12 apply_signal = QtCore.pyqtSignal(tuple, str) 14 class BoxSum(QtWidgets.QDialog, Ui_BoxSumUI): 13 15 def __init__(self, parent=None, model=None): 14 16 super(BoxSum, self).__init__() … … 17 19 assert isinstance(model, QtGui.QStandardItemModel) 18 20 19 self.txtBoxHeight.setValidator( QtGui.QDoubleValidator())20 self.txtBoxWidth.setValidator( QtGui.QDoubleValidator())21 self.txtCenterX.setValidator( QtGui.QDoubleValidator())22 self.txtCenterY.setValidator( QtGui.QDoubleValidator())21 self.txtBoxHeight.setValidator(GuiUtils.DoubleValidator()) 22 self.txtBoxWidth.setValidator(GuiUtils.DoubleValidator()) 23 self.txtCenterX.setValidator(GuiUtils.DoubleValidator()) 24 self.txtCenterY.setValidator(GuiUtils.DoubleValidator()) 23 25 24 26 self.model = model 25 self.mapper = Qt Gui.QDataWidgetMapper()27 self.mapper = QtWidgets.QDataWidgetMapper() 26 28 self.mapper.setModel(self.model) 27 29 … … 31 33 self.mapper.addMapping(self.txtCenterX, 2) 32 34 self.mapper.addMapping(self.txtCenterY, 3) 33 self.mapper.addMapping(self.lblAvg, 4, "text")34 self.mapper.addMapping(self.lblAvgErr, 5, "text")35 self.mapper.addMapping(self.lblSum, 6, "text")36 self.mapper.addMapping(self.lblSumErr, 7, "text")37 self.mapper.addMapping(self.lblNumPoints, 8, "text")35 self.mapper.addMapping(self.lblAvg, 4, b"text") 36 self.mapper.addMapping(self.lblAvgErr, 5, b"text") 37 self.mapper.addMapping(self.lblSum, 6, b"text") 38 self.mapper.addMapping(self.lblSumErr, 7, b"text") 39 self.mapper.addMapping(self.lblNumPoints, 8, b"text") 38 40 39 41 # Populate the widgets with data from the first column … … 42 44 self.setFixedSize(self.minimumSizeHint()) 43 45 46 # Handle the Apply button click 47 self.buttonBox.button(QtWidgets.QDialogButtonBox.Close).clicked.connect(self.onClose) 48 49 def onClose(self): 50 """ 51 close the window containing this panel 52 """ 53 self.close() 54 -
src/sas/qtgui/Plotting/ColorMap.py
rdc5ef15 rd6b8a1d 2 2 Allows users to change the range of the current graph 3 3 """ 4 from PyQt4 import QtGui 5 from PyQt4 import QtCore 4 from PyQt5 import QtCore 5 from PyQt5 import QtGui 6 from PyQt5 import QtWidgets 6 7 import sas.qtgui.path_prepare 7 8 … … 10 11 import numpy 11 12 12 from matplotlib.backends.backend_qt 4agg import FigureCanvasQTAgg as FigureCanvas13 from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas 13 14 from sas.qtgui.Plotting.PlotterData import Data2D 14 from sas.qtgui.Utilities.GuiUtils import formatNumber 15 from rangeSlider import RangeSlider15 from sas.qtgui.Utilities.GuiUtils import formatNumber, DoubleValidator 16 from .rangeSlider import RangeSlider 16 17 17 18 DEFAULT_MAP = 'jet' … … 21 22 from sas.qtgui.Plotting.UI.ColorMapUI import Ui_ColorMapUI 22 23 23 class ColorMap(Qt Gui.QDialog, Ui_ColorMapUI):24 class ColorMap(QtWidgets.QDialog, Ui_ColorMapUI): 24 25 apply_signal = QtCore.pyqtSignal(tuple, str) 25 26 def __init__(self, parent=None, cmap=None, vmin=0.0, vmax=100.0, data=None): … … 50 51 51 52 # Initialize validators on amplitude textboxes 52 validator_min = QtGui.QDoubleValidator(self.txtMinAmplitude)53 validator_min = DoubleValidator(self.txtMinAmplitude) 53 54 validator_min.setNotation(0) 54 55 self.txtMinAmplitude.setValidator(validator_min) 55 validator_max = QtGui.QDoubleValidator(self.txtMaxAmplitude)56 validator_max = DoubleValidator(self.txtMaxAmplitude) 56 57 validator_max.setNotation(0) 57 58 self.txtMaxAmplitude.setValidator(validator_max) … … 71 72 72 73 # Handle the Reset button click 73 self.buttonBox.button(Qt Gui.QDialogButtonBox.Reset).clicked.connect(self.onReset)74 self.buttonBox.button(QtWidgets.QDialogButtonBox.Reset).clicked.connect(self.onReset) 74 75 75 76 # Handle the Apply button click 76 self.buttonBox.button(Qt Gui.QDialogButtonBox.Apply).clicked.connect(self.onApply)77 self.buttonBox.button(QtWidgets.QDialogButtonBox.Apply).clicked.connect(self.onApply) 77 78 78 79 # Handle the amplitude setup … … 161 162 self.slider.setOrientation(QtCore.Qt.Horizontal) 162 163 163 self.slider_label = Qt Gui.QLabel()164 self.slider_label = QtWidgets.QLabel() 164 165 self.slider_label.setText("Drag the sliders to adjust color range.") 165 166 … … 192 193 self.canvas = FigureCanvas(self.fig) 193 194 194 layout = Qt Gui.QVBoxLayout()195 layout = QtWidgets.QVBoxLayout() 195 196 layout.addWidget(self.slider_label) 196 197 layout.addWidget(self.slider) -
src/sas/qtgui/Plotting/ConvertUnits.py
re7a0b2f rd744767 4 4 """ 5 5 import re 6 import string7 6 8 7 def convertUnit(power, unit): … … 11 10 """ 12 11 if power != 0: 13 if string.find(unit,"^") != -1: # if the unit contains a powerer ^12 if unit.find("^") != -1: # if the unit contains a powerer ^ 14 13 toks = re.split("\^", unit) 15 if string.find(toks[0],"/") != -1 or \16 string.find(toks[0],"-") != -1:14 if toks[0].find("/") != -1 or \ 15 toks[0].find("-") != -1: 17 16 if power == 1: 18 17 unit = unit … … 20 19 unit = "(" + unit + ")" + "^{" + str(power) + "}" 21 20 else: 22 if string.find(toks[1],"{") != -1: # if found a {21 if toks[1].find("{") != -1: # if found a { 23 22 find_power_toks = re.split("{", toks[1]) 24 if string.find(find_power_toks[1],"}") != -1: # found }23 if find_power_toks[1].find("}") != -1: # found } 25 24 unit_toks = re.split("}", find_power_toks[1]) 26 if string.find(unit_toks[0],".") != -1:25 if unit_toks[0].find(".") != -1: 27 26 powerer = float(unit_toks[0]) * power 28 elif string.find(unit_toks[0],"/") != -1:27 elif unit_toks[0].find("/") != -1: 29 28 power_toks = re.split("/", unit_toks[0]) 30 29 powerer = power * int(power_toks[0])\ … … 42 41 unit = toks[0] + "^{" + str(powerer) + "}" 43 42 else: 44 raise ValueError , "missing } in unit expression"43 raise ValueError("missing } in unit expression") 45 44 else: # no powerer 46 45 if power != 1: 47 46 unit = "(" + unit + ")" + "^{" + str(power) + "}" 48 47 else: 49 raise ValueError , "empty unit ,enter a powerer different from zero"48 raise ValueError("empty unit ,enter a powerer different from zero") 50 49 return unit 51 50 … … 68 67 unit8 = "m/s^{4}" # x^2 (m/s^{4})^{2} 69 68 70 print "this unit1 %s ,its powerer %s , and value %s" % (unit1, 1, convert_unit(1, unit1))71 print "this unit2 %s ,its powerer %s , and value %s" % (unit2, 1, convert_unit(1, unit2))72 print "this unit3 %s ,its powerer %s , and value %s" % (unit3, 2, convert_unit(2, unit3))73 print "this unit4 %s ,its powerer %s , and value %s" % (unit4, -1, convert_unit(-1, unit4))74 print "this unit5 %s ,its powerer %s , and value %s" % (unit5, 2, convert_unit(2, unit5))75 print "this unit6 %s ,its powerer %s , and value %s" % (unit6, 2, convert_unit(2, unit6))76 print "this unit7 %s ,its powerer %s , and value %s" % (unit7, -1, convert_unit(-1, unit7))77 print "this unit8 %s ,its powerer %s , and value %s" % (unit8, 2, convert_unit(2, unit8))78 print "this unit9 %s ,its powerer %s , and value %s" % (unit9, 2, convert_unit(2, unit9))69 print("this unit1 %s ,its powerer %s , and value %s" % (unit1, 1, convert_unit(1, unit1))) 70 print("this unit2 %s ,its powerer %s , and value %s" % (unit2, 1, convert_unit(1, unit2))) 71 print("this unit3 %s ,its powerer %s , and value %s" % (unit3, 2, convert_unit(2, unit3))) 72 print("this unit4 %s ,its powerer %s , and value %s" % (unit4, -1, convert_unit(-1, unit4))) 73 print("this unit5 %s ,its powerer %s , and value %s" % (unit5, 2, convert_unit(2, unit5))) 74 print("this unit6 %s ,its powerer %s , and value %s" % (unit6, 2, convert_unit(2, unit6))) 75 print("this unit7 %s ,its powerer %s , and value %s" % (unit7, -1, convert_unit(-1, unit7))) 76 print("this unit8 %s ,its powerer %s , and value %s" % (unit8, 2, convert_unit(2, unit8))) 77 print("this unit9 %s ,its powerer %s , and value %s" % (unit9, 2, convert_unit(2, unit9))) 79 78 80 79 -
src/sas/qtgui/Plotting/DataTransform.py
re7a0b2f rd744767 24 24 """ 25 25 if not x > 0: 26 raise ValueError , "Transformation only accepts positive values."26 raise ValueError("Transformation only accepts positive values.") 27 27 else: 28 28 return x … … 50 50 """ 51 51 if not x >= 0: 52 raise ValueError , "square root of a negative value "52 raise ValueError("square root of a negative value ") 53 53 else: 54 54 return math.sqrt(x) … … 76 76 """ 77 77 if not x >= 0: 78 raise ValueError , "double square root of a negative value "78 raise ValueError("double square root of a negative value ") 79 79 else: 80 80 return math.sqrt(math.sqrt(x)) … … 90 90 """ 91 91 if not x > 0: 92 raise ValueError , "Log(x)of a negative value "92 raise ValueError("Log(x)of a negative value ") 93 93 else: 94 94 return math.log(x) … … 100 100 return 1 / x 101 101 else: 102 raise ValueError , "cannot divide by zero"102 raise ValueError("cannot divide by zero") 103 103 104 104 … … 109 109 return 1 / math.sqrt(y) 110 110 else: 111 raise ValueError , "transform.toOneOverSqrtX: cannot be computed"111 raise ValueError("transform.toOneOverSqrtX: cannot be computed") 112 112 113 113 … … 118 118 return math.log(y * (x ** 2)) 119 119 else: 120 raise ValueError , "transform.toLogYX2: cannot be computed"120 raise ValueError("transform.toLogYX2: cannot be computed") 121 121 122 122 … … 127 127 return math.log(math.pow(x, 4) * y) 128 128 else: 129 raise ValueError , "transform.toLogYX4: input error"129 raise ValueError("transform.toLogYX4: input error") 130 130 131 131 … … 149 149 """ 150 150 if not (x * y) > 0: 151 raise ValueError , "Log(X*Y)of a negative value "151 raise ValueError("Log(X*Y)of a negative value ") 152 152 else: 153 153 return math.log(x * y) … … 162 162 163 163 """ 164 if dx ==None:164 if dx is None: 165 165 dx = 0 166 166 return dx … … 175 175 176 176 """ 177 if dx ==None:177 if dx is None: 178 178 dx = 0 179 179 return dx … … 188 188 189 189 """ 190 if dx !=None:190 if dx is not None: 191 191 err = 2 * x * dx 192 192 return math.fabs(err) … … 204 204 """ 205 205 if x > 0: 206 if dx !=None:206 if dx is not None: 207 207 err = dx / (2 * math.sqrt(x)) 208 208 else: … … 211 211 else: 212 212 msg = "transform.errFromX2: can't compute error of negative x" 213 raise ValueError , msg213 raise ValueError(msg) 214 214 215 215 … … 222 222 223 223 """ 224 if dx !=None:224 if dx is not None: 225 225 err = 4 * math.pow(x, 3) * dx 226 226 return math.fabs(err) … … 238 238 """ 239 239 if x > 0: 240 if dx !=None:240 if dx is not None: 241 241 err = dx / (4 * math.pow(x, 3 / 4)) 242 242 else: … … 245 245 else: 246 246 msg = "transform.errFromX4: can't compute error of negative x" 247 raise ValueError , msg247 raise ValueError(msg) 248 248 249 249 … … 256 256 257 257 """ 258 if dx ==None:258 if dx is None: 259 259 dx = 0 260 260 … … 264 264 msg = "Transformation does not accept" 265 265 msg += " point that are consistent with zero." 266 raise ValueError , msg266 raise ValueError(msg) 267 267 if x != 0: 268 268 dx = dx / (x * math.log(10)) 269 269 else: 270 raise ValueError , "errToLogX: divide by zero"270 raise ValueError("errToLogX: divide by zero") 271 271 return dx 272 272 … … 280 280 281 281 """ 282 if dx ==None:282 if dx is None: 283 283 dx = 0 284 284 … … 287 287 dx = dx / x 288 288 else: 289 raise ValueError , "errToLogX: divide by zero"289 raise ValueError("errToLogX: divide by zero") 290 290 return dx 291 291 … … 294 294 """ 295 295 """ 296 if dx ==None:297 dx = 0 298 if dy ==None:296 if dx is None: 297 dx = 0 298 if dy is None: 299 299 dy = 0 300 300 err = math.sqrt((2 * x * y * dx) ** 2 + ((x ** 2) * dy) ** 2) … … 312 312 msg = "Transformation does not accept point " 313 313 msg += " that are consistent with zero." 314 raise ValueError , msg314 raise ValueError(msg) 315 315 if x != 0 and y != 0: 316 if dx ==None:316 if dx is None: 317 317 dx = 0 318 if dy ==None:318 if dy is None: 319 319 dy = 0 320 320 err = (dx / x) ** 2 + (dy / y) ** 2 321 321 else: 322 raise ValueError , "cannot compute this error"322 raise ValueError("cannot compute this error") 323 323 324 324 return math.sqrt(math.fabs(err)) … … 335 335 msg = "Transformation does not accept point" 336 336 msg += " that are consistent with zero." 337 raise ValueError , msg337 raise ValueError(msg) 338 338 if x > 0 and y > 0: 339 if dx ==None:339 if dx is None: 340 340 dx = 0 341 if dy ==None:341 if dy is None: 342 342 dy = 0 343 343 err = (2.0 * dx / x) ** 2 + (dy / y) ** 2 344 344 else: 345 raise ValueError , "cannot compute this error"345 raise ValueError("cannot compute this error") 346 346 return math.sqrt(math.fabs(err)) 347 347 … … 353 353 """ 354 354 if x != 0: 355 if dx ==None:355 if dx is None: 356 356 dx = 0 357 357 err = dx / x ** 2 358 358 else: 359 raise ValueError , "Cannot compute this error"359 raise ValueError("Cannot compute this error") 360 360 return math.fabs(err) 361 361 … … 367 367 """ 368 368 if x > 0: 369 if dx ==None:369 if dx is None: 370 370 dx = 0 371 371 err = -1 / 2 * math.pow(x, -3.0 / 2.0) * dx 372 372 else: 373 raise ValueError , "Cannot compute this error"373 raise ValueError("Cannot compute this error") 374 374 return math.fabs(err) 375 375 … … 387 387 msg = "Transformation does not accept point " 388 388 msg += " that are consistent with zero." 389 raise ValueError , msg390 if dx ==None:391 dx = 0 392 if dy ==None:389 raise ValueError(msg) 390 if dx is None: 391 dx = 0 392 if dy is None: 393 393 dy = 0 394 394 err = math.sqrt((4.0 * dx / x) ** 2 + (dy / y) ** 2) … … 406 406 # within errors 407 407 408 if dx ==None:409 dx = 0 410 if dy ==None:408 if dx is None: 409 dx = 0 410 if dy is None: 411 411 dy = 0 412 412 err = math.sqrt((dy * pow(x, 4)) ** 2 + (4 * y * dx * math.pow(x, 3)) ** 2) -
src/sas/qtgui/Plotting/Fittings.py
radc49fc rcee5c78 22 22 self.model = model 23 23 self.name = name 24 if not value ==None:24 if value is not None: 25 25 self.model.setParam(self.name, value) 26 26 … … 97 97 # Testing implementation 98 98 # Fit a Line model 99 from LineModel import LineModel99 from .LineModel import LineModel 100 100 line = LineModel() 101 101 cstA = Parameter(line, 'A', event.cstA) … … 104 104 chisqr, out, cov = sasfit(line, [cstA, cstB], event.x, y, 0) 105 105 # print "Output parameters:", out 106 print "The right answer is [70.0, 1.0]"107 print chisqr, out, cov106 print("The right answer is [70.0, 1.0]") 107 print(chisqr, out, cov) 108 108 -
src/sas/qtgui/Plotting/LineModel.py
re7a0b2f rb3e8629 81 81 elif x.__class__.__name__ == 'tuple': 82 82 msg = "Tuples are not allowed as input to BaseComponent models" 83 raise ValueError , msg83 raise ValueError(msg) 84 84 else: 85 85 return self._line(x) … … 103 103 elif x.__class__.__name__ == 'tuple': 104 104 msg = "Tuples are not allowed as input to BaseComponent models" 105 raise ValueError , msg105 raise ValueError(msg) 106 106 else: 107 107 return self._line(x) -
src/sas/qtgui/Plotting/LinearFit.py
rdc5ef15 re4c475b7 4 4 import re 5 5 import numpy 6 from PyQt4 import QtGui 7 from PyQt4 import QtCore 8 9 from sas.qtgui.Utilities.GuiUtils import formatNumber 6 from PyQt5 import QtCore 7 from PyQt5 import QtGui 8 from PyQt5 import QtWidgets 9 10 from sas.qtgui.Utilities.GuiUtils import formatNumber, DoubleValidator 10 11 11 12 from sas.qtgui.Plotting import Fittings 12 13 from sas.qtgui.Plotting import DataTransform 13 14 from sas.qtgui.Plotting.LineModel import LineModel 15 import sas.qtgui.Utilities.GuiUtils as GuiUtils 14 16 15 17 # Local UI … … 17 19 from sas.qtgui.Plotting.UI.LinearFitUI import Ui_LinearFitUI 18 20 19 class LinearFit(QtGui.QDialog, Ui_LinearFitUI): 21 class LinearFit(QtWidgets.QDialog, Ui_LinearFitUI): 22 updatePlot = QtCore.pyqtSignal(tuple) 20 23 def __init__(self, parent=None, 21 24 data=None, … … 41 44 self.y_is_log = self.yLabel == "log10(y)" 42 45 43 self.txtFitRangeMin.setValidator( QtGui.QDoubleValidator())44 self.txtFitRangeMax.setValidator( QtGui.QDoubleValidator())46 self.txtFitRangeMin.setValidator(DoubleValidator()) 47 self.txtFitRangeMax.setValidator(DoubleValidator()) 45 48 46 49 # Default values in the line edits … … 54 57 self.txtRangeMin.setText(str(max_range[0])) 55 58 self.txtRangeMax.setText(str(max_range[1])) 56 self.txtFitRangeMin.setText(str(fit_range[0])) 57 self.txtFitRangeMax.setText(str(fit_range[1])) 59 # Assure nice display of ranges 60 fr_min = GuiUtils.formatNumber(fit_range[0]) 61 fr_max = GuiUtils.formatNumber(fit_range[1]) 62 self.txtFitRangeMin.setText(str(fr_min)) 63 self.txtFitRangeMax.setText(str(fr_max)) 58 64 59 65 # cast xLabel into html … … 79 85 Overwrite default fit range label to correspond to actual unit 80 86 """ 81 assert(isinstance(label, basestring))87 assert(isinstance(label, str)) 82 88 self.lblRange.setText(label) 83 89 … … 111 117 # Set the qmin and qmax in the panel that matches the 112 118 # transformed min and max 113 #value_xmin = X_VAL_DICT[self.xLabel].floatTransform(xmin)114 #value_xmax = X_VAL_DICT[self.xLabel].floatTransform(xmax)115 116 119 value_xmin = self.floatInvTransform(xmin) 117 120 value_xmax = self.floatInvTransform(xmax) … … 156 159 y_model = self.model.run(xmin) 157 160 tempx.append(xminView) 158 tempy.append(numpy.power(10 , y_model) if self.y_is_log else y_model)161 tempy.append(numpy.power(10.0, y_model) if self.y_is_log else y_model) 159 162 160 163 # load tempy with the maximum transformation 161 164 y_model = self.model.run(xmax) 162 165 tempx.append(xmaxView) 163 tempy.append(numpy.power(10 , y_model) if self.y_is_log else y_model)166 tempy.append(numpy.power(10.0, y_model) if self.y_is_log else y_model) 164 167 165 168 # Set the fit parameter display when FitDialog is opened again … … 177 180 self.txtChi2.setText(formatNumber(self.Chivalue)) 178 181 179 #self.parent.updatePlot.emit((tempx, tempy)) 180 self.parent.emit(QtCore.SIGNAL('updatePlot'), (tempx, tempy)) 182 self.updatePlot.emit((tempx, tempy)) 181 183 182 184 def origData(self): … … 195 197 for i in range(len(x)) if x[i] >= xmin_check] 196 198 else: 197 tempy = map(numpy.log10, y)198 tempdy = map(lambda t1,t2:DataTransform.errToLogX(t1,0,t2,0),y,dy)199 tempy = list(map(numpy.log10, y)) 200 tempdy = list(map(lambda t1,t2:DataTransform.errToLogX(t1,0,t2,0),y,dy)) 199 201 else: 200 202 tempy = y … … 246 248 return numpy.sqrt(numpy.sqrt(x)) 247 249 elif self.xLabel == "log10(x)": 248 return numpy.power(10 , x)250 return numpy.power(10.0, x) 249 251 elif self.xLabel == "ln(x)": 250 252 return numpy.exp(x) 251 253 elif self.xLabel == "log10(x^(4))": 252 return numpy.sqrt(numpy.sqrt(numpy.power(10 , x)))254 return numpy.sqrt(numpy.sqrt(numpy.power(10.0, x))) 253 255 return x 254 256 -
src/sas/qtgui/Plotting/MaskEditor.py
rdc5ef15 r4992ff2 1 from PyQt4 import QtGui 1 from PyQt5 import QtCore 2 from PyQt5 import QtGui 3 from PyQt5 import QtWidgets 2 4 3 5 from sas.qtgui.Plotting.PlotterData import Data2D … … 8 10 from sas.qtgui.Plotting.Plotter2D import Plotter2DWidget 9 11 10 class MaskEditor(Qt Gui.QDialog, Ui_MaskEditorUI):12 class MaskEditor(QtWidgets.QDialog, Ui_MaskEditorUI): 11 13 def __init__(self, parent=None, data=None): 12 14 super(MaskEditor, self).__init__() … … 23 25 self.plotter.data = self.data 24 26 25 layout = Qt Gui.QHBoxLayout()27 layout = QtWidgets.QHBoxLayout() 26 28 layout.setContentsMargins(0, 0, 0, 0) 27 29 self.frame.setLayout(layout) -
src/sas/qtgui/Plotting/PlotHelper.py
- Property mode changed from 100644 to 100755
r83eb5208 rb3e8629 35 35 Returns a list of IDs for all currently active plots 36 36 """ 37 return this._plots.keys()37 return list(this._plots.keys()) 38 38 39 39 def plotById(plot_id): … … 48 48 """ 49 49 plot_id = None 50 for key in this._plots.keys():50 for key in list(this._plots.keys()): 51 51 if this._plots[key] == plot: 52 52 plot_id = key -
src/sas/qtgui/Plotting/PlotProperties.py
rcd2cc745 r53c771e 1 from PyQt4 import QtGui 1 from PyQt5 import QtCore 2 from PyQt5 import QtGui 3 from PyQt5 import QtWidgets 2 4 3 5 from sas.qtgui.Plotting.PlotUtilities import COLORS, SHAPES … … 6 8 from sas.qtgui.Plotting.UI.PlotPropertiesUI import Ui_PlotPropertiesUI 7 9 8 class PlotProperties(Qt Gui.QDialog, Ui_PlotPropertiesUI):10 class PlotProperties(QtWidgets.QDialog, Ui_PlotPropertiesUI): 9 11 """ Dialog for modification of single plot properties """ 10 12 def __init__(self, … … 26 28 27 29 # Fill out the color combobox 28 self.cbColor.addItems( COLORS.keys()[:-1])30 self.cbColor.addItems(list(COLORS.keys())[:-1]) 29 31 # data1d.custom_color can now be a simple integer, 30 32 # specifying COLORS dict index or a string containing … … 34 36 else: 35 37 # Need the Custom entry here. "Custom" is always last. 36 self.cbColor.addItems([ COLORS.keys()[-1]])37 self.cbColor.setCurrentIndex( COLORS.keys().index("Custom"))38 self.cbColor.addItems([list(COLORS.keys())[-1]]) 39 self.cbColor.setCurrentIndex(list(COLORS.keys()).index("Custom")) 38 40 39 41 # Fill out the marker combobox 40 self.cbShape.addItems( SHAPES.keys())42 self.cbShape.addItems(list(SHAPES.keys())) 41 43 try: 42 44 self.cbShape.setCurrentIndex(self._marker) … … 76 78 """ 77 79 # Pick up the chosen color 78 proposed_color = Qt Gui.QColorDialog.getColor(parent=self)80 proposed_color = QtWidgets.QColorDialog.getColor(parent=self) 79 81 # Update the text control 80 82 if proposed_color.isValid(): … … 83 85 # Add Custom to the color combo box 84 86 self.cbColor.addItems(["Custom"]) 85 self.cbColor.setCurrentIndex( COLORS.keys().index("Custom"))87 self.cbColor.setCurrentIndex(list(COLORS.keys()).index("Custom")) 86 88 # unblock currentIndexChanged 87 89 self.cbColor.blockSignals(False) -
src/sas/qtgui/Plotting/PlotUtilities.py
r83eb5208 rcee5c78 161 161 """ 162 162 # No image matrix given 163 if image ==None or numpy.ndim(image) != 2 \163 if image is None or numpy.ndim(image) != 2 \ 164 164 or numpy.isfinite(image).all() \ 165 or weights ==None:165 or weights is None: 166 166 return image 167 167 # Get bin size in y and x directions … … 273 273 # Check if it's within the range 274 274 if 0 <= color <=6: 275 color = COLORS.values()[color]275 color = list(COLORS.values())[color] 276 276 # Check if it's an RGB string 277 277 elif isinstance(color, str): -
src/sas/qtgui/Plotting/Plottables.py
- Property mode changed from 100755 to 100644
rbed08e7 rcee5c78 239 239 selected_color = None 240 240 selected_plottable = None 241 for p in self.plottables.keys():241 for p in list(self.plottables.keys()): 242 242 if plottable.id == p.id: 243 243 selected_plottable = p … … 384 384 385 385 """ 386 raise NotImplemented , "Not a valid transform"386 raise NotImplemented("Not a valid transform") 387 387 388 388 # Related issues … … 512 512 label_dict[collection[0]] = basename 513 513 else: 514 for i in xrange(len(collection)):514 for i in range(len(collection)): 515 515 label_dict[collection[i]] = "%s %d" % (basename, i) 516 516 return label_dict … … 684 684 msg = "Plottable.View: Given x and dx are not" 685 685 msg += " of the same length" 686 raise ValueError , msg686 raise ValueError(msg) 687 687 # Check length of y array 688 688 if not len(y) == len(x): 689 689 msg = "Plottable.View: Given y " 690 690 msg += "and x are not of the same length" 691 raise ValueError , msg691 raise ValueError(msg) 692 692 693 693 if not dy is None and not len(dy) == 0 and not len(y) == len(dy): 694 694 msg = "Plottable.View: Given y and dy are not of the same " 695 695 msg += "length: len(y)=%s, len(dy)=%s" % (len(y), len(dy)) 696 raise ValueError , msg696 raise ValueError(msg) 697 697 self.x = [] 698 698 self.y = [] … … 729 729 msg = "Plottable.View: transformed x " 730 730 msg += "and y are not of the same length" 731 raise ValueError , msg731 raise ValueError(msg) 732 732 if has_err_x and not (len(self.x) == len(self.dx)): 733 733 msg = "Plottable.View: transformed x and dx" 734 734 msg += " are not of the same length" 735 raise ValueError , msg735 raise ValueError(msg) 736 736 if has_err_y and not (len(self.y) == len(self.dy)): 737 737 msg = "Plottable.View: transformed y" 738 738 msg += " and dy are not of the same length" 739 raise ValueError , msg739 raise ValueError(msg) 740 740 # Check that negative values are not plot on x and y axis for 741 741 # log10 transformation … … 809 809 except: 810 810 logging.error("check_data_logX: skipping point x %g", self.x[i]) 811 logging.error(sys.exc_ value)811 logging.error(sys.exc_info()[1]) 812 812 self.x = tempx 813 813 self.y = tempy … … 839 839 except: 840 840 logging.error("check_data_logY: skipping point %g", self.y[i]) 841 logging.error(sys.exc_ value)841 logging.error(sys.exc_info()[1]) 842 842 843 843 self.x = tempx … … 862 862 if self.dy is None: 863 863 self.dy = numpy.zeros(len(self.y)) 864 if xmin != None and xmax !=None:864 if xmin is not None and xmax is not None: 865 865 for i in range(len(self.x)): 866 866 if self.x[i] >= xmin and self.x[i] <= xmax: … … 1101 1101 Plottable.__init__(self) 1102 1102 msg = "Theory1D is no longer supported, please use Data1D and change symbol.\n" 1103 raise DeprecationWarning , msg1103 raise DeprecationWarning(msg) 1104 1104 1105 1105 class PlottableFit1D(Plottable): -
src/sas/qtgui/Plotting/Plotter.py
rf0bb711 reb1a386 1 from PyQt4 import QtGui 2 from PyQt4 import QtCore 1 from PyQt5 import QtCore 2 from PyQt5 import QtGui 3 from PyQt5 import QtWidgets 4 3 5 import functools 4 6 import copy … … 39 41 self.fit_result.name = "Fit" 40 42 41 # Add a slot for receiving update signal from LinearFit42 # NEW style signals43 #self.updatePlot = QtCore.pyqtSignal(tuple)44 # self.updatePlot.connect(self.onFitDisplay)45 # OLD style signals46 QtCore.QObject.connect(self, QtCore.SIGNAL('updatePlot'), self.onFitDisplay)47 48 43 @property 49 44 def data(self): … … 54 49 """ data setter """ 55 50 self._data = value 56 self.xLabel = "%s(%s)"%(value._xaxis, value._xunit) 57 self.yLabel = "%s(%s)"%(value._yaxis, value._yunit) 51 if value._xunit: 52 self.xLabel = "%s(%s)"%(value._xaxis, value._xunit) 53 else: 54 self.xLabel = "%s"%(value._xaxis) 55 if value._yunit: 56 self.yLabel = "%s(%s)"%(value._yaxis, value._yunit) 57 else: 58 self.yLabel = "%s"%(value._yaxis) 59 60 if value.scale == 'linear' or value.isSesans: 61 self.xscale = 'linear' 62 self.yscale = 'linear' 58 63 self.title(title=value.name) 59 64 … … 85 90 # Try name first 86 91 try: 87 marker = PlotUtilities.SHAPES[marker]92 marker = dict(PlotUtilities.SHAPES)[marker] 88 93 except KeyError: 89 marker = PlotUtilities.SHAPES.values()[marker]94 marker = list(PlotUtilities.SHAPES.values())[marker] 90 95 91 96 assert marker is not None … … 165 170 166 171 # refresh canvas 167 self.canvas.draw ()172 self.canvas.draw_idle() 168 173 169 174 def createContextMenu(self): … … 203 208 Adds operations on all plotted sets of data to the context menu 204 209 """ 205 for id in self.plot_dict.keys():210 for id in list(self.plot_dict.keys()): 206 211 plot = self.plot_dict[id] 207 212 … … 269 274 Show a dialog allowing axes rescaling 270 275 """ 271 if self.properties.exec_() == Qt Gui.QDialog.Accepted:276 if self.properties.exec_() == QtWidgets.QDialog.Accepted: 272 277 self.xLogLabel, self.yLogLabel = self.properties.getValues() 273 278 self.xyTransform(self.xLogLabel, self.yLogLabel) … … 277 282 Show a dialog allowing adding custom text to the chart 278 283 """ 279 if self.addText.exec_() == QtGui.QDialog.Accepted: 280 # Retrieve the new text, its font and color 281 extra_text = self.addText.text() 282 extra_font = self.addText.font() 283 extra_color = self.addText.color() 284 285 # Place the text on the screen at (0,0) 286 pos_x = self.x_click 287 pos_y = self.y_click 288 289 # Map QFont onto MPL font 290 mpl_font = FontProperties() 291 mpl_font.set_size(int(extra_font.pointSize())) 292 mpl_font.set_family(str(extra_font.family())) 293 mpl_font.set_weight(int(extra_font.weight())) 294 # MPL style names 295 styles = ['normal', 'italic', 'oblique'] 296 # QFont::Style maps directly onto the above 297 try: 298 mpl_font.set_style(styles[extra_font.style()]) 299 except: 300 pass 301 302 if len(extra_text) > 0: 303 new_text = self.ax.text(str(pos_x), 304 str(pos_y), 305 extra_text, 306 color=extra_color, 307 fontproperties=mpl_font) 308 # Update the list of annotations 309 self.textList.append(new_text) 310 self.canvas.draw_idle() 284 if self.addText.exec_() != QtWidgets.QDialog.Accepted: 285 return 286 287 # Retrieve the new text, its font and color 288 extra_text = self.addText.text() 289 extra_font = self.addText.font() 290 extra_color = self.addText.color() 291 292 # Place the text on the screen at the click location 293 pos_x = self.x_click 294 pos_y = self.y_click 295 296 # Map QFont onto MPL font 297 mpl_font = FontProperties() 298 mpl_font.set_size(int(extra_font.pointSize())) 299 mpl_font.set_family(str(extra_font.family())) 300 mpl_font.set_weight(int(extra_font.weight())) 301 # MPL style names 302 styles = ['normal', 'italic', 'oblique'] 303 # QFont::Style maps directly onto the above 304 try: 305 mpl_font.set_style(styles[extra_font.style()]) 306 except: 307 pass 308 309 if len(extra_text) > 0: 310 new_text = self.ax.text(pos_x, 311 pos_y, 312 extra_text, 313 color=extra_color, 314 fontproperties=mpl_font) 315 316 # Update the list of annotations 317 self.textList.append(new_text) 318 self.canvas.draw() 311 319 312 320 def onRemoveText(self): … … 319 327 txt = self.textList[num_text - 1] 320 328 text_remove = txt.get_text() 321 txt.remove() 329 try: 330 txt.remove() 331 except ValueError: 332 # Text got already deleted somehow 333 pass 322 334 self.textList.remove(txt) 323 335 … … 329 341 """ 330 342 # min and max of data 331 if self.setRange.exec_() == Qt Gui.QDialog.Accepted:343 if self.setRange.exec_() == QtWidgets.QDialog.Accepted: 332 344 x_range = self.setRange.xrange() 333 345 y_range = self.setRange.yrange() … … 363 375 xlabel=self.xLogLabel, 364 376 ylabel=self.yLogLabel) 365 if fit_dialog.exec_() == QtGui.QDialog.Accepted: 377 fit_dialog.updatePlot.connect(self.onFitDisplay) 378 if fit_dialog.exec_() == QtWidgets.QDialog.Accepted: 366 379 return 367 380 … … 388 401 Deletes the selected plot from the chart 389 402 """ 390 if id not in self.plot_dict.keys():403 if id not in list(self.plot_dict.keys()): 391 404 return 392 405 … … 440 453 marker_size=marker_size, 441 454 legend=legend) 442 if plotPropertiesWidget.exec_() == Qt Gui.QDialog.Accepted:455 if plotPropertiesWidget.exec_() == QtWidgets.QDialog.Accepted: 443 456 # Update Data1d 444 457 selected_plot.markersize = plotPropertiesWidget.markersize() … … 479 492 """ 480 493 # Transform all the plots on the chart 481 for id in self.plot_dict.keys():494 for id in list(self.plot_dict.keys()): 482 495 current_plot = self.plot_dict[id] 483 496 if current_plot.id == "fit": … … 614 627 """ 615 628 ax = event.inaxes 616 if ax ==None:629 if ax is None: 617 630 return 618 631 # Event occurred inside a plotting area … … 649 662 step = event.step 650 663 651 if ax !=None:664 if ax is not None: 652 665 # Event occurred inside a plotting area 653 666 lo, hi = ax.get_xlim() … … 697 710 698 711 699 class Plotter(Qt Gui.QDialog, PlotterWidget):712 class Plotter(QtWidgets.QDialog, PlotterWidget): 700 713 def __init__(self, parent=None, quickplot=False): 701 714 702 Qt Gui.QDialog.__init__(self)715 QtWidgets.QDialog.__init__(self) 703 716 PlotterWidget.__init__(self, parent=self, manager=parent, quickplot=quickplot) 704 717 icon = QtGui.QIcon() -
src/sas/qtgui/Plotting/Plotter2D.py
rf4a1433 rd6b8a1d 3 3 import pylab 4 4 import functools 5 6 from PyQt4 import QtGui 7 from PyQt4 import QtCore 5 import logging 6 7 from PyQt5 import QtCore 8 from PyQt5 import QtGui 9 from PyQt5 import QtWidgets 8 10 9 11 DEFAULT_CMAP = pylab.cm.jet 12 13 #import sys 14 #print("SYS.PATH = ", sys.path) 15 import matplotlib as mpl 16 mpl.use("Qt5Agg") 17 10 18 from mpl_toolkits.mplot3d import Axes3D 11 19 … … 116 124 """ 117 125 # Toggle the scale 118 zmin_temp = self.zmin 126 zmin_temp = self.zmin if self.zmin else MIN_Z 119 127 zmax_temp = self.zmax 120 128 # self.scale predefined in the baseclass 129 # in numpy > 1.12 power(int, -int) raises ValueException 130 # "Integers to negative integer powers are not allowed." 121 131 if self.scale == 'log_{10}': 122 132 if self.zmin is not None: 123 zmin_temp = numpy.power(10 , self.zmin)133 zmin_temp = numpy.power(10.0, self.zmin) 124 134 if self.zmax is not None: 125 zmax_temp = numpy.power(10 , self.zmax)135 zmax_temp = numpy.power(10.0, self.zmax) 126 136 else: 127 137 if self.zmin is not None: … … 236 246 self.slicer_widget.close_signal.connect(slicer_closed) 237 247 # Add the plot to the workspace 238 self.manager.parent.workspace().add Window(self.slicer_widget)248 self.manager.parent.workspace().addSubWindow(self.slicer_widget) 239 249 240 250 self.slicer_widget.show() … … 281 291 new_plot.id = "Circ avg " + self.data.name 282 292 new_plot.is_data = True 283 variant_plot = QtCore.QVariant(new_plot)284 GuiUtils.updateModelItemWithPlot(self._item, variant_plot, new_plot.id) 293 GuiUtils.updateModelItemWithPlot(self._item, new_plot, new_plot.id) 294 285 295 self.manager.communicator.plotUpdateSignal.emit([new_plot]) 286 296 … … 338 348 self.boxwidget = BoxSum(self, model=self.box_sum_model) 339 349 # Add the plot to the workspace 340 self.manager.parent.workspace().add Window(self.boxwidget)350 self.manager.parent.workspace().addSubWindow(self.boxwidget) 341 351 self.boxwidget.show() 342 352 … … 366 376 color_map_dialog.apply_signal.connect(self.onApplyMap) 367 377 368 if color_map_dialog.exec_() == Qt Gui.QDialog.Accepted:378 if color_map_dialog.exec_() == QtWidgets.QDialog.Accepted: 369 379 self.onApplyMap(color_map_dialog.norm(), color_map_dialog.cmap()) 370 380 … … 504 514 505 515 506 class Plotter2D(Qt Gui.QDialog, Plotter2DWidget):516 class Plotter2D(QtWidgets.QDialog, Plotter2DWidget): 507 517 """ 508 518 Plotter widget implementation 509 519 """ 510 520 def __init__(self, parent=None, quickplot=False, dimension=2): 511 Qt Gui.QDialog.__init__(self)521 QtWidgets.QDialog.__init__(self) 512 522 Plotter2DWidget.__init__(self, manager=parent, quickplot=quickplot, dimension=dimension) 513 523 icon = QtGui.QIcon() -
src/sas/qtgui/Plotting/PlotterBase.py
r7d8bebf reb1a386 2 2 import numpy 3 3 4 from PyQt4 import QtGui 5 from PyQt4 import QtCore 6 7 # TODO: Replace the qt4agg calls below with qt5 equivalent. 8 # Requires some code modifications. 9 # https://www.boxcontrol.net/embedding-matplotlib-plot-on-pyqt5-gui.html 10 # 11 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas 12 from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar 4 from PyQt5 import QtCore 5 from PyQt5 import QtGui 6 from PyQt5 import QtWidgets, QtPrintSupport 7 8 from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas 9 from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar 13 10 14 11 import matplotlib.pyplot as plt … … 25 22 import sas.qtgui.Plotting.PlotUtilities as PlotUtilities 26 23 27 class PlotterBase(Qt Gui.QWidget):24 class PlotterBase(QtWidgets.QWidget): 28 25 def __init__(self, parent=None, manager=None, quickplot=False): 29 26 super(PlotterBase, self).__init__(parent) … … 33 30 self.quickplot = quickplot 34 31 32 #plt.style.use('ggplot') 33 #plt.style.use('seaborn-darkgrid') 34 35 35 # a figure instance to plot on 36 36 self.figure = plt.figure() … … 43 43 44 44 # Simple window for data display 45 self.txt_widget = Qt Gui.QTextEdit(None)45 self.txt_widget = QtWidgets.QTextEdit(None) 46 46 47 47 # Set the layout and place the canvas widget in it. 48 layout = QtGui.QVBoxLayout() 49 layout.setMargin(0) 48 layout = QtWidgets.QVBoxLayout() 49 # FIXME setMargin -> setContentsMargins in qt5 with 4 args 50 #layout.setContentsMargins(0) 50 51 layout.addWidget(self.canvas) 51 52 … … 105 106 self.canvas.mpl_connect('scroll_event', self.onMplWheel) 106 107 107 self.contextMenu = Qt Gui.QMenu(self)108 self.contextMenu = QtWidgets.QMenu(self) 108 109 109 110 if not quickplot: … … 139 140 def xLabel(self, xlabel=""): 140 141 """ x-label setter """ 141 self.x_label = r'$%s$'% xlabel 142 self.x_label = r'$%s$'% xlabel if xlabel else "" 142 143 143 144 @property … … 149 150 def yLabel(self, ylabel=""): 150 151 """ y-label setter """ 151 self.y_label = r'$%s$'% ylabel 152 self.y_label = r'$%s$'% ylabel if ylabel else "" 152 153 153 154 @property … … 170 171 def xscale(self, scale='linear'): 171 172 """ X-axis scale setter """ 173 self.ax.cla() 172 174 self.ax.set_xscale(scale) 173 175 self._xscale = scale … … 290 292 """ 291 293 # Define the printer 292 printer = Qt Gui.QPrinter()294 printer = QtPrintSupport.QPrinter() 293 295 294 296 # Display the print dialog 295 dialog = Qt Gui.QPrintDialog(printer)297 dialog = QtPrintSupport.QPrintDialog(printer) 296 298 dialog.setModal(True) 297 299 dialog.setWindowTitle("Print") 298 if dialog.exec_() != Qt Gui.QDialog.Accepted:300 if dialog.exec_() != QtWidgets.QDialog.Accepted: 299 301 return 300 302 301 303 painter = QtGui.QPainter(printer) 302 304 # Grab the widget screenshot 303 pmap = QtGui.QPixmap.grabWidget(self) 305 pmap = QtGui.QPixmap(self.size()) 306 self.render(pmap) 304 307 # Create a label with pixmap drawn 305 printLabel = Qt Gui.QLabel()308 printLabel = QtWidgets.QLabel() 306 309 printLabel.setPixmap(pmap) 307 310 … … 314 317 Copy MPL widget area to buffer 315 318 """ 316 bmp = QtGui.QApplication.clipboard() 317 pixmap = QtGui.QPixmap.grabWidget(self.canvas) 319 bmp = QtWidgets.QApplication.clipboard() 320 pixmap = QtGui.QPixmap(self.canvas.size()) 321 self.canvas.render(pixmap) 318 322 bmp.setPixmap(pixmap) 319 323 … … 333 337 titleWidget = WindowTitle(self, new_title=current_title) 334 338 result = titleWidget.exec_() 335 if result != Qt Gui.QDialog.Accepted:339 if result != QtWidgets.QDialog.Accepted: 336 340 return 337 341 … … 371 375 # Move the slider all the way up, if present 372 376 vertical_scroll_bar = self.txt_widget.verticalScrollBar() 373 vertical_scroll_bar.triggerAction(Qt Gui.QScrollBar.SliderToMinimum)377 vertical_scroll_bar.triggerAction(QtWidgets.QScrollBar.SliderToMinimum) 374 378 375 379 def onSavePoints(self, plot_data): -
src/sas/qtgui/Plotting/PlotterData.py
- Property mode changed from 100755 to 100644
rfef38e8 rcee5c78 54 54 self.yaxis(data1d._yaxis, data1d._yunit) 55 55 self.title = data1d.title 56 self.isSesans = data1d.isSesans 56 57 57 58 def __str__(self): … … 71 72 result.clone_without_data(length=len(self.x), clone=self) 72 73 result.copy_from_datainfo(data1d=self) 73 if self.dxw ==None:74 if self.dxw is None: 74 75 result.dxw = None 75 76 else: 76 77 result.dxw = numpy.zeros(len(self.x)) 77 if self.dxl ==None:78 if self.dxl is None: 78 79 result.dxl = None 79 80 else: … … 118 119 tot_length = len(self.x) + len(other.x) 119 120 result = self.clone_without_data(length=tot_length, clone=result) 120 if self.dy ==None or other.dy is None:121 if self.dy is None or other.dy is None: 121 122 result.dy = None 122 123 else: 123 124 result.dy = numpy.zeros(tot_length) 124 if self.dx ==None or other.dx is None:125 if self.dx is None or other.dx is None: 125 126 result.dx = None 126 127 else: 127 128 result.dx = numpy.zeros(tot_length) 128 if self.dxw ==None or other.dxw is None:129 if self.dxw is None or other.dxw is None: 129 130 result.dxw = None 130 131 else: 131 132 result.dxw = numpy.zeros(tot_length) 132 if self.dxl ==None or other.dxl is None:133 if self.dxl is None or other.dxl is None: 133 134 result.dxl = None 134 135 else: … … 141 142 result.y = numpy.append(self.y, other.y) 142 143 result.y = result.y[ind] 143 if result.dy !=None:144 if result.dy is not None: 144 145 result.dy = numpy.append(self.dy, other.dy) 145 146 result.dy = result.dy[ind] … … 238 239 result.ymin = self.ymin 239 240 result.ymax = self.ymax 240 if self.dqx_data == None or self.dqy_data ==None:241 if self.dqx_data is None or self.dqy_data is None: 241 242 result.dqx_data = None 242 243 result.dqy_data = None … … 301 302 result.ymin = self.ymin 302 303 result.ymax = self.ymax 303 if self.dqx_data == None or self.dqy_data ==None or \304 other.dqx_data == None or other.dqy_data ==None :304 if self.dqx_data is None or self.dqy_data is None or \ 305 other.dqx_data is None or other.dqy_data is None : 305 306 result.dqx_data = None 306 307 result.dqy_data = None -
src/sas/qtgui/Plotting/ScaleProperties.py
rcd2cc745 r4992ff2 1 from PyQt4 import QtGui 1 from PyQt5 import QtCore 2 from PyQt5 import QtGui 3 from PyQt5 import QtWidgets 2 4 3 5 import sas.sasview … … 20 22 view_values[5]: [0, 4], # Kratky 21 23 } 22 class ScaleProperties(Qt Gui.QDialog, Ui_scalePropertiesUI):24 class ScaleProperties(QtWidgets.QDialog, Ui_scalePropertiesUI): 23 25 def __init__(self, parent=None, init_scale_x='x', init_scale_y='y'): 24 26 super(ScaleProperties, self).__init__(parent) -
src/sas/qtgui/Plotting/SetGraphRange.py
rcd2cc745 rd6b8a1d 2 2 Allows users to change the range of the current graph 3 3 """ 4 from PyQt4 import QtGui 4 from PyQt5 import QtCore 5 from PyQt5 import QtGui 6 from PyQt5 import QtWidgets 7 8 import sas.qtgui.Utilities.GuiUtils as GuiUtils 5 9 6 10 # Local UI … … 8 12 from sas.qtgui.Plotting.UI.SetGraphRangeUI import Ui_setGraphRangeUI 9 13 10 class SetGraphRange(Qt Gui.QDialog, Ui_setGraphRangeUI):14 class SetGraphRange(QtWidgets.QDialog, Ui_setGraphRangeUI): 11 15 def __init__(self, parent=None, x_range=(0.0, 0.0), y_range=(0.0, 0.0)): 12 16 super(SetGraphRange, self).__init__() … … 16 20 assert(isinstance(y_range, tuple)) 17 21 18 self.txtXmin.setValidator( QtGui.QDoubleValidator())19 self.txtXmax.setValidator( QtGui.QDoubleValidator())20 self.txtYmin.setValidator( QtGui.QDoubleValidator())21 self.txtYmax.setValidator( QtGui.QDoubleValidator())22 self.txtXmin.setValidator(GuiUtils.DoubleValidator()) 23 self.txtXmax.setValidator(GuiUtils.DoubleValidator()) 24 self.txtYmin.setValidator(GuiUtils.DoubleValidator()) 25 self.txtYmax.setValidator(GuiUtils.DoubleValidator()) 22 26 23 27 self.txtXmin.setText(str(x_range[0])) -
src/sas/qtgui/Plotting/SlicerModel.py
r83eb5208 rd6b8a1d 1 from PyQt 4import QtGui2 from PyQt 4import QtCore1 from PyQt5 import QtGui 2 from PyQt5 import QtCore 3 3 4 4 import sas.qtgui.Utilities.GuiUtils as GuiUtils … … 19 19 self._model.removeRows( 0, self._model.rowCount() ) 20 20 # Crete/overwrite model items 21 for parameter in parameters.keys():21 for parameter in list(parameters.keys()): 22 22 item1 = QtGui.QStandardItem(parameter) 23 23 item2 = QtGui.QStandardItem(GuiUtils.formatNumber(parameters[parameter])) 24 24 self._model.appendRow([item1, item2]) 25 self._model.setHeaderData(0, QtCore.Qt.Horizontal, QtCore.QVariant("Parameter"))26 self._model.setHeaderData(1, QtCore.Qt.Horizontal, QtCore.QVariant("Value"))25 self._model.setHeaderData(0, QtCore.Qt.Horizontal, "Parameter") 26 self._model.setHeaderData(1, QtCore.Qt.Horizontal, "Value") 27 27 28 28 def setParamsFromModel(self, item): -
src/sas/qtgui/Plotting/SlicerParameters.py
rcd2cc745 re90988c 4 4 import numpy 5 5 import functools 6 from PyQt4 import QtGui 7 from PyQt4 import QtCore 8 from PyQt4 import QtWebKit 6 from PyQt5 import QtCore 7 from PyQt5 import QtGui 8 from PyQt5 import QtWidgets 9 10 import sas.qtgui.Utilities.GuiUtils as GuiUtils 9 11 10 12 # Local UI … … 12 14 from sas.qtgui.Plotting.UI.SlicerParametersUI import Ui_SlicerParametersUI 13 15 14 class SlicerParameters(Qt Gui.QDialog, Ui_SlicerParametersUI):16 class SlicerParameters(QtWidgets.QDialog, Ui_SlicerParametersUI): 15 17 """ 16 18 Interaction between the QTableView and the underlying model, … … 44 46 45 47 # Display Help on clicking the button 46 self.buttonBox.button(Qt Gui.QDialogButtonBox.Help).clicked.connect(self.onHelp)48 self.buttonBox.button(QtWidgets.QDialogButtonBox.Help).clicked.connect(self.onHelp) 47 49 48 50 # Close doesn't trigger closeEvent automatically, so force it 49 self.buttonBox.button(Qt Gui.QDialogButtonBox.Close).clicked.connect(functools.partial(self.closeEvent, None))51 self.buttonBox.button(QtWidgets.QDialogButtonBox.Close).clicked.connect(functools.partial(self.closeEvent, None)) 50 52 51 53 # Disable row number display 52 54 self.lstParams.verticalHeader().setVisible(False) 53 55 self.lstParams.setAlternatingRowColors(True) 54 self.lstParams.setSizePolicy(Qt Gui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Expanding)56 self.lstParams.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Expanding) 55 57 56 58 # Header properties for nicer display 57 59 header = self.lstParams.horizontalHeader() 58 header.set ResizeMode(QtGui.QHeaderView.Stretch)60 header.setSectionResizeMode(QtWidgets.QHeaderView.Stretch) 59 61 header.setStretchLastSection(True) 60 62 … … 84 86 Display generic data averaging help 85 87 """ 86 location = "docs/sphinx-docs/build/html" + \ 87 "/user/sasgui/guiframe/graph_help.html#d-data-averaging" 88 self.helpView = QtWebKit.QWebView() 89 self.helpView.load(QtCore.QUrl(location)) 90 self.helpView.show() 88 location = "/user/sasgui/guiframe/graph_help.html#d-data-averaging" 89 self.parent.showHelp(location) 91 90 92 91 93 class ProxyModel(Qt Gui.QIdentityProxyModel):92 class ProxyModel(QtCore.QIdentityProxyModel): 94 93 """ 95 94 Trivial proxy model with custom column edit flag … … 117 116 return flags 118 117 119 class PositiveDoubleEditor(Qt Gui.QLineEdit):118 class PositiveDoubleEditor(QtWidgets.QLineEdit): 120 119 # a signal to tell the delegate when we have finished editing 121 120 editingFinished = QtCore.Signal() … … 125 124 super(PositiveDoubleEditor, self).__init__(parent) 126 125 self.setAutoFillBackground(True) 127 validator = QtGui.QDoubleValidator()126 validator = GuiUtils.DoubleValidator() 128 127 # Don't use the scientific notation, cause 'e'. 129 validator.setNotation( QtGui.QDoubleValidator.StandardNotation)128 validator.setNotation(GuiUtils.DoubleValidator.StandardNotation) 130 129 131 130 self.setValidator(validator) … … 136 135 137 136 138 class EditDelegate(Qt Gui.QStyledItemDelegate):137 class EditDelegate(QtWidgets.QStyledItemDelegate): 139 138 refocus_signal = QtCore.pyqtSignal(int, int) 140 139 def __init__(self, parent=None, validate_method=None): … … 155 154 return self.editor 156 155 else: 157 return Qt Gui.QStyledItemDelegate.createEditor(self, parent, option, index)156 return QtWidgets.QStyledItemDelegate.createEditor(self, parent, option, index) 158 157 159 158 def setModelData(self, editor, model, index): -
src/sas/qtgui/Plotting/Slicers/AnnulusSlicer.py
- Property mode changed from 100755 to 100644
rdc5ef15 r4992ff2 1 1 import numpy 2 from PyQt4 import QtGui3 from PyQt4 import QtCore4 2 5 3 import sas.qtgui.Utilities.GuiUtils as GuiUtils 6 from BaseInteractor import BaseInteractor4 from .BaseInteractor import BaseInteractor 7 5 from sas.qtgui.Plotting.PlotterData import Data1D 8 6 from sas.qtgui.Utilities.GuiUtils import formatNumber … … 145 143 new_plot.xtransform = "x" 146 144 new_plot.ytransform = "y" 147 variant_plot = QtCore.QVariant(new_plot) 148 GuiUtils.updateModelItemWithPlot(self._item, variant_plot, new_plot.id) 145 GuiUtils.updateModelItemWithPlot(self._item, new_plot, new_plot.id) 149 146 self.base.manager.communicator.plotUpdateSignal.emit([new_plot]) 150 147 -
src/sas/qtgui/Plotting/Slicers/Arc.py
re7a0b2f rd744767 4 4 import math 5 5 6 from BaseInteractor import BaseInteractor6 from .BaseInteractor import BaseInteractor 7 7 8 8 class ArcInteractor(BaseInteractor): … … 70 70 x = [] 71 71 y = [] 72 if theta1 !=None:72 if theta1 is not None: 73 73 self.theta1 = theta1 74 if theta2 !=None:74 if theta2 is not None: 75 75 self.theta2 = theta2 76 76 while self.theta2 < self.theta1: … … 80 80 npts = int((self.theta2 - self.theta1) / (math.pi / 120)) 81 81 82 if r ==None:82 if r is None: 83 83 self.radius = math.sqrt(math.pow(self._mouse_x, 2) + \ 84 84 math.pow(self._mouse_y, 2)) -
src/sas/qtgui/Plotting/Slicers/AzimutSlicer.py
rdc5ef15 rb3e8629 5 5 # 6 6 import math 7 from BaseInteractor import BaseInteractor7 from .BaseInteractor import BaseInteractor 8 8 9 9 class SectorInteractor(BaseInteractor): … … 26 26 27 27 # Inner circle 28 from Arc import ArcInteractor28 from .Arc import ArcInteractor 29 29 self.inner_circle = ArcInteractor(self, self.base.subplot, 30 30 zorder=zorder, -
src/sas/qtgui/Plotting/Slicers/BoxSlicer.py
- Property mode changed from 100755 to 100644
rdc5ef15 r4992ff2 1 1 import numpy 2 from PyQt4 import QtGui 3 from PyQt4 import QtCore 4 5 from BaseInteractor import BaseInteractor 2 3 from .BaseInteractor import BaseInteractor 6 4 from sas.qtgui.Plotting.PlotterData import Data1D 7 5 import sas.qtgui.Utilities.GuiUtils as GuiUtils … … 136 134 if new_slab is None: 137 135 msg = "post data:cannot average , averager is empty" 138 raise ValueError , msg136 raise ValueError(msg) 139 137 self.averager = new_slab 140 138 if self.direction == "X": … … 152 150 else: 153 151 msg = "post data:no Box Average direction was supplied" 154 raise ValueError , msg152 raise ValueError(msg) 155 153 # # Average data2D given Qx or Qy 156 154 box = self.averager(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max, … … 190 188 new_plot.id = (self.averager.__name__) + self.base.data.name 191 189 new_plot.is_data = True 192 variant_plot = QtCore.QVariant(new_plot) 193 GuiUtils.updateModelItemWithPlot(self._item, variant_plot, new_plot.id) 190 GuiUtils.updateModelItemWithPlot(self._item, new_plot, new_plot.id) 194 191 195 192 if self.update_model: -
src/sas/qtgui/Plotting/Slicers/BoxSum.py
- Property mode changed from 100755 to 100644
rdc5ef15 rfbfc488 4 4 """ 5 5 import numpy 6 from PyQt 4import QtGui7 from PyQt4 import QtCore 8 from sas.qtgui.Utilities.GuiUtils import formatNumber 9 10 from BaseInteractor import BaseInteractor6 from PyQt5 import QtGui 7 8 from sas.qtgui.Utilities.GuiUtils import formatNumber, toDouble 9 10 from .BaseInteractor import BaseInteractor 11 11 from sas.sascalc.dataloader.manipulations import Boxavg 12 12 from sas.sascalc.dataloader.manipulations import Boxsum … … 110 110 parameters = self.getParams() 111 111 # Crete/overwrite model items 112 self._model.setData(self._model.index(0, 0), 113 QtCore.QVariant(formatNumber(parameters['Height']))) 114 self._model.setData(self._model.index(0, 1), 115 QtCore.QVariant(formatNumber(parameters['Width']))) 116 self._model.setData(self._model.index(0, 2), 117 QtCore.QVariant(formatNumber(parameters['center_x']))) 118 self._model.setData(self._model.index(0, 3), 119 QtCore.QVariant(formatNumber(parameters['center_y']))) 112 self._model.setData(self._model.index(0, 0), formatNumber(parameters['Height'])) 113 self._model.setData(self._model.index(0, 1), formatNumber(parameters['Width'])) 114 self._model.setData(self._model.index(0, 2), formatNumber(parameters['center_x'])) 115 self._model.setData(self._model.index(0, 3), formatNumber(parameters['center_y'])) 120 116 121 117 self.setReadOnlyParametersFromModel() … … 130 126 """ 131 127 parameters = self.getParams() 132 self._model.setData(self._model.index(0, 4), 133 QtCore.QVariant(formatNumber(parameters['avg']))) 134 self._model.setData(self._model.index(0, 5), 135 QtCore.QVariant(formatNumber(parameters['avg_error']))) 136 self._model.setData(self._model.index(0, 6), 137 QtCore.QVariant(formatNumber(parameters['sum']))) 138 self._model.setData(self._model.index(0, 7), 139 QtCore.QVariant(formatNumber(parameters['sum_error']))) 140 self._model.setData(self._model.index(0, 8), 141 QtCore.QVariant(formatNumber(parameters['num_points']))) 128 self._model.setData(self._model.index(0, 4), formatNumber(parameters['avg'])) 129 self._model.setData(self._model.index(0, 5), formatNumber(parameters['avg_error'])) 130 self._model.setData(self._model.index(0, 6), formatNumber(parameters['sum'])) 131 self._model.setData(self._model.index(0, 7), formatNumber(parameters['sum_error'])) 132 self._model.setData(self._model.index(0, 8), formatNumber(parameters['num_points'])) 142 133 143 134 def setParamsFromModel(self): … … 146 137 """ 147 138 params = {} 148 params["Height"] = float(self.model().item(0, 0).text())149 params["Width"] = float(self.model().item(0, 1).text())150 params["center_x"] = float(self.model().item(0, 2).text())151 params["center_y"] = float(self.model().item(0, 3).text())139 params["Height"] = toDouble(self.model().item(0, 0).text()) 140 params["Width"] = toDouble(self.model().item(0, 1).text()) 141 params["center_x"] = toDouble(self.model().item(0, 2).text()) 142 params["center_y"] = toDouble(self.model().item(0, 3).text()) 152 143 self.update_model = False 153 144 self.setParams(params) … … 362 353 Draw the new roughness on the graph. 363 354 """ 364 if center_x !=None:355 if center_x is not None: 365 356 self.x = center_x 366 if center_y !=None:357 if center_y is not None: 367 358 self.y = center_y 368 359 self.center_marker.set(xdata=[self.x], ydata=[self.y]) -
src/sas/qtgui/Plotting/Slicers/SectorSlicer.py
- Property mode changed from 100755 to 100644
rdc5ef15 rd6b8a1d 3 3 """ 4 4 import numpy 5 from PyQt4 import QtGui 6 from PyQt4 import QtCore 7 8 from BaseInteractor import BaseInteractor 5 import logging 6 7 from .BaseInteractor import BaseInteractor 9 8 from sas.qtgui.Plotting.PlotterData import Data1D 10 9 import sas.qtgui.Utilities.GuiUtils as GuiUtils … … 125 124 data = self.base.data 126 125 # If we have no data, just return 127 if data ==None:126 if data is None: 128 127 return 129 128 # Averaging … … 132 131 phimin = -self.left_line.phi + self.main_line.theta 133 132 phimax = self.left_line.phi + self.main_line.theta 134 if nbins ==None:133 if nbins is None: 135 134 nbins = 20 136 135 sect = SectorQ(r_min=0.0, r_max=radius, … … 168 167 new_plot.id = "SectorQ" + self.base.data.name 169 168 new_plot.is_data = True 170 variant_plot = QtCore.QVariant(new_plot)171 GuiUtils.updateModelItemWithPlot(self._item, variant_plot, new_plot.id) 169 GuiUtils.updateModelItemWithPlot(self._item, new_plot, new_plot.id) 170 172 171 self.base.manager.communicator.plotUpdateSignal.emit([new_plot]) 173 172 … … 230 229 msg = "Phi left and phi right are different" 231 230 msg += " %f, %f" % (self.left_line.phi, self.right_line.phi) 232 raise ValueError , msg231 raise ValueError(msg) 233 232 params["Phi [deg]"] = self.main_line.theta * 180 / numpy.pi 234 233 params["Delta_Phi [deg]"] = numpy.fabs(self.left_line.phi * 180 / numpy.pi) … … 349 348 self.left_moving = left 350 349 theta3 = 0 351 if phi !=None:350 if phi is not None: 352 351 self.phi = phi 353 if delta ==None:352 if delta is None: 354 353 delta = 0 355 354 if right: … … 361 360 self.theta = mline.theta + self.phi 362 361 363 if mline !=None:362 if mline is not None: 364 363 if delta != 0: 365 364 self.theta2 = mline + delta … … 509 508 """ 510 509 511 if theta !=None:510 if theta is not None: 512 511 self.theta = theta 513 512 x1 = self.radius * numpy.cos(self.theta) -
src/sas/qtgui/Plotting/UnitTesting/AddTextTest.py
r464cd07 r53c771e 1 1 import sys 2 2 import unittest 3 from mock import MagicMock3 from unittest.mock import MagicMock 4 4 5 from PyQt 4 import QtGui5 from PyQt5 import QtGui, QtWidgets 6 6 7 7 # set up import paths … … 11 11 from sas.qtgui.Plotting.AddText import AddText 12 12 13 if not Qt Gui.QApplication.instance():14 app = Qt Gui.QApplication(sys.argv)13 if not QtWidgets.QApplication.instance(): 14 app = QtWidgets.QApplication(sys.argv) 15 15 16 16 class AddTextTest(unittest.TestCase): … … 27 27 def testDefaults(self): 28 28 '''Test the GUI in its default state''' 29 self.assertIsInstance(self.widget, Qt Gui.QDialog)29 self.assertIsInstance(self.widget, QtWidgets.QDialog) 30 30 self.assertIsInstance(self.widget._font, QtGui.QFont) 31 31 self.assertEqual(self.widget._color, "black") … … 34 34 '''Test the QFontDialog output''' 35 35 font_1 = QtGui.QFont("Helvetica", 15) 36 Qt Gui.QFontDialog.getFont = MagicMock(return_value=(font_1, True))36 QtWidgets.QFontDialog.getFont = MagicMock(return_value=(font_1, True)) 37 37 # Call the method 38 38 self.widget.onFontChange(None) … … 42 42 # See that rejecting the dialog doesn't modify the font 43 43 font_2 = QtGui.QFont("Arial", 9) 44 Qt Gui.QFontDialog.getFont = MagicMock(return_value=(font_2, False))44 QtWidgets.QFontDialog.getFont = MagicMock(return_value=(font_2, False)) 45 45 # Call the method 46 46 self.widget.onFontChange(None) … … 51 51 ''' Test the QColorDialog output''' 52 52 new_color = QtGui.QColor("red") 53 Qt Gui.QColorDialog.getColor = MagicMock(return_value=new_color)53 QtWidgets.QColorDialog.getColor = MagicMock(return_value=new_color) 54 54 # Call the method 55 55 self.widget.onColorChange(None) -
src/sas/qtgui/Plotting/UnitTesting/BoxSumTest.py
r464cd07 r53c771e 1 1 import sys 2 2 import unittest 3 from mock import MagicMock3 from unittest.mock import MagicMock 4 4 5 from PyQt 4 import QtGui6 from PyQt 4import QtCore5 from PyQt5 import QtGui,QtWidgets 6 from PyQt5 import QtCore 7 7 8 8 # set up import paths … … 12 12 from sas.qtgui.Plotting.BoxSum import BoxSum 13 13 14 if not Qt Gui.QApplication.instance():15 app = Qt Gui.QApplication(sys.argv)14 if not QtWidgets.QApplication.instance(): 15 app = QtWidgets.QApplication(sys.argv) 16 16 17 17 class BoxSumTest(unittest.TestCase): … … 23 23 parameters = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] 24 24 for index, parameter in enumerate(parameters): 25 model.setData(model.index(0, index), 26 QtCore.QVariant(parameter)) 25 model.setData(model.index(0, index),parameter) 27 26 self.widget = BoxSum(None, model=model) 28 27 … … 34 33 def testDefaults(self): 35 34 '''Test the GUI in its default state''' 36 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(0), Qt Gui.QLineEdit)37 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(1), Qt Gui.QLineEdit)38 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(2), Qt Gui.QLineEdit)39 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(3), Qt Gui.QLineEdit)40 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(4), Qt Gui.QLabel)41 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(5), Qt Gui.QLabel)42 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(6), Qt Gui.QLabel)43 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(7), Qt Gui.QLabel)44 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(8), Qt Gui.QLabel)35 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(0), QtWidgets.QLineEdit) 36 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(1), QtWidgets.QLineEdit) 37 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(2), QtWidgets.QLineEdit) 38 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(3), QtWidgets.QLineEdit) 39 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(4), QtWidgets.QLabel) 40 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(5), QtWidgets.QLabel) 41 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(6), QtWidgets.QLabel) 42 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(7), QtWidgets.QLabel) 43 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(8), QtWidgets.QLabel) 45 44 46 45 -
src/sas/qtgui/Plotting/UnitTesting/ColorMapTest.py
r464cd07 r53c771e 3 3 import numpy 4 4 5 from PyQt 4 import QtGui6 from mock import MagicMock5 from PyQt5 import QtGui, QtWidgets 6 from unittest.mock import MagicMock 7 7 import matplotlib as mpl 8 8 … … 18 18 from sas.qtgui.Plotting.ColorMap import ColorMap 19 19 20 if not Qt Gui.QApplication.instance():21 app = Qt Gui.QApplication(sys.argv)20 if not QtWidgets.QApplication.instance(): 21 app = QtWidgets.QApplication(sys.argv) 22 22 23 23 class ColorMapTest(unittest.TestCase): … … 48 48 def testDefaults(self): 49 49 '''Test the GUI in its default state''' 50 self.assertIsInstance(self.widget, Qt Gui.QDialog)50 self.assertIsInstance(self.widget, QtWidgets.QDialog) 51 51 52 52 self.assertEqual(self.widget._cmap_orig, "jet") 53 self.assertEqual(len(self.widget.all_maps), 1 44)54 self.assertEqual(len(self.widget.maps), 72)55 self.assertEqual(len(self.widget.rmaps), 72)53 self.assertEqual(len(self.widget.all_maps), 160) 54 self.assertEqual(len(self.widget.maps), 80) 55 self.assertEqual(len(self.widget.rmaps), 80) 56 56 57 57 self.assertEqual(self.widget.lblWidth.text(), "0") … … 60 60 self.assertEqual(self.widget.lblStopRadius.text(), "-1") 61 61 self.assertFalse(self.widget.chkReverse.isChecked()) 62 self.assertEqual(self.widget.cbColorMap.count(), 72)63 self.assertEqual(self.widget.cbColorMap.currentIndex(), 6 0)62 self.assertEqual(self.widget.cbColorMap.count(), 80) 63 self.assertEqual(self.widget.cbColorMap.currentIndex(), 64) 64 64 65 65 # validators … … 70 70 self.assertEqual(self.widget.txtMinAmplitude.text(), "0") 71 71 self.assertEqual(self.widget.txtMaxAmplitude.text(), "100") 72 self.assertIsInstance(self.widget.slider, Qt Gui.QSlider)72 self.assertIsInstance(self.widget.slider, QtWidgets.QSlider) 73 73 74 74 def testOnReset(self): … … 111 111 112 112 # Check the combobox 113 self.assertEqual(self.widget.cbColorMap.currentIndex(), 5 5)113 self.assertEqual(self.widget.cbColorMap.currentIndex(), 59) 114 114 self.assertFalse(self.widget.chkReverse.isChecked()) 115 115 … … 118 118 self.widget.initMapCombobox() 119 119 # Check the combobox 120 self.assertEqual(self.widget.cbColorMap.currentIndex(), 56)120 self.assertEqual(self.widget.cbColorMap.currentIndex(), 60) 121 121 self.assertTrue(self.widget.chkReverse.isChecked()) 122 122 -
src/sas/qtgui/Plotting/UnitTesting/LinearFitTest.py
r464cd07 r53c771e 3 3 import numpy 4 4 5 from PyQt4 import QtGui 6 from mock import MagicMock 5 from PyQt5 import QtGui, QtWidgets 6 from unittest.mock import MagicMock 7 8 from UnitTesting.TestUtils import QtSignalSpy 7 9 8 10 # set up import paths … … 15 17 from sas.qtgui.Plotting.LinearFit import LinearFit 16 18 17 if not Qt Gui.QApplication.instance():18 app = Qt Gui.QApplication(sys.argv)19 if not QtWidgets.QApplication.instance(): 20 app = QtWidgets.QApplication(sys.argv) 19 21 20 22 class LinearFitTest(unittest.TestCase): … … 36 38 def testDefaults(self): 37 39 '''Test the GUI in its default state''' 38 self.assertIsInstance(self.widget, Qt Gui.QDialog)40 self.assertIsInstance(self.widget, QtWidgets.QDialog) 39 41 self.assertEqual(self.widget.windowTitle(), "Linear Fit") 40 42 self.assertEqual(self.widget.txtA.text(), "1") … … 48 50 '''Test the fitting wrapper ''' 49 51 # Catch the update signal 50 self.widget.parent.emit = MagicMock() 52 #self.widget.updatePlot.emit = MagicMock() 53 #self.widget.updatePlot.emit = MagicMock() 54 spy_update = QtSignalSpy(self.widget, self.widget.updatePlot) 51 55 52 56 # Set some initial values … … 57 61 # Run the fitting 58 62 self.widget.fit(None) 59 return_values = self.widget.parent.emit.call_args[0][1] 63 64 # Expected one spy instance 65 self.assertEqual(spy_update.count(), 1) 66 67 return_values = spy_update.called()[0]['args'][0] 60 68 # Compare 61 self.assert ItemsEqual(return_values[0], [1.0, 3.0])69 self.assertCountEqual(return_values[0], [1.0, 3.0]) 62 70 self.assertAlmostEqual(return_values[1][0], 10.004054329, 6) 63 71 self.assertAlmostEqual(return_values[1][1], 12.030439848, 6) … … 66 74 self.widget.x_is_log = True 67 75 self.widget.fit(None) 68 return_values = self.widget.parent.emit.call_args[0][1] 76 self.assertEqual(spy_update.count(), 2) 77 return_values = spy_update.called()[1]['args'][0] 69 78 # Compare 70 self.assert ItemsEqual(return_values[0], [1.0, 3.0])79 self.assertCountEqual(return_values[0], [1.0, 3.0]) 71 80 self.assertAlmostEqual(return_values[1][0], 9.987732937, 6) 72 81 self.assertAlmostEqual(return_values[1][1], 11.84365082, 6) … … 81 90 x, y, dy = self.widget.origData() 82 91 83 self.assert ItemsEqual(x, orig_x)92 self.assertCountEqual(x, orig_x) 84 93 self.assertEqual(y[0], orig_y[0]) 85 94 self.assertAlmostEqual(y[1], orig_y[1], 8) … … 98 107 x, y, dy = self.widget.origData() 99 108 100 self.assert ItemsEqual(x, orig_x)101 self.assert ItemsEqual(y, orig_y)102 self.assert ItemsEqual(dy, orig_dy)109 self.assertCountEqual(x, orig_x) 110 self.assertCountEqual(y, orig_y) 111 self.assertCountEqual(dy, orig_dy) 103 112 104 113 # x, log(y) … … 111 120 x, y, dy = self.widget.origData() 112 121 113 self.assert ItemsEqual(x, orig_x)122 self.assertCountEqual(x, orig_x) 114 123 self.assertEqual(y[0], orig_y[0]) 115 124 self.assertAlmostEqual(y[1], orig_y[1], 8) -
src/sas/qtgui/Plotting/UnitTesting/PlotPropertiesTest.py
r464cd07 r53c771e 1 1 import sys 2 2 import unittest 3 from mock import MagicMock3 from unittest.mock import MagicMock 4 4 5 from PyQt 4 import QtGui5 from PyQt5 import QtGui, QtWidgets 6 6 7 7 # set up import paths … … 11 11 from sas.qtgui.Plotting.PlotProperties import PlotProperties 12 12 13 if not Qt Gui.QApplication.instance():14 app = Qt Gui.QApplication(sys.argv)13 if not QtWidgets.QApplication.instance(): 14 app = QtWidgets.QApplication(sys.argv) 15 15 16 16 class PlotPropertiesTest(unittest.TestCase): … … 32 32 def testDefaults(self): 33 33 '''Test the GUI in its default state''' 34 self.assertIsInstance(self.widget, Qt Gui.QDialog)34 self.assertIsInstance(self.widget, QtWidgets.QDialog) 35 35 self.assertEqual(self.widget.windowTitle(), "Modify Plot Properties") 36 36 … … 56 56 '''Test the response to color change event''' 57 57 # Accept the new color 58 Qt Gui.QColorDialog.getColor = MagicMock(return_value=QtGui.QColor(255, 0, 255))58 QtWidgets.QColorDialog.getColor = MagicMock(return_value=QtGui.QColor(255, 0, 255)) 59 59 60 60 self.widget.onColorChange() … … 72 72 # Cancel the dialog now 73 73 bad_color = QtGui.QColor() # constructs an invalid color 74 Qt Gui.QColorDialog.getColor = MagicMock(return_value=bad_color)74 QtWidgets.QColorDialog.getColor = MagicMock(return_value=bad_color) 75 75 self.widget.onColorChange() 76 76 -
src/sas/qtgui/Plotting/UnitTesting/Plotter2DTest.py
rb2a5042 r53c771e 4 4 import platform 5 5 6 from PyQt 4 import QtGui7 from PyQt 4import QtCore8 from matplotlib.backends.backend_qt 4agg import FigureCanvasQTAgg as FigureCanvas9 from mock import MagicMock6 from PyQt5 import QtGui, QtWidgets, QtPrintSupport 7 from PyQt5 import QtCore 8 from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas 9 from unittest.mock import MagicMock 10 10 from mpl_toolkits.mplot3d import Axes3D 11 11 … … 20 20 import sas.qtgui.Plotting.Plotter2D as Plotter2D 21 21 22 if not Qt Gui.QApplication.instance():23 app = Qt Gui.QApplication(sys.argv)22 if not QtWidgets.QApplication.instance(): 23 app = QtWidgets.QApplication(sys.argv) 24 24 25 25 class Plotter2DTest(unittest.TestCase): … … 53 53 def tearDown(self): 54 54 '''destroy''' 55 self.plotter.figure.clf() 55 56 self.plotter = None 56 57 … … 73 74 74 75 self.assertTrue(FigureCanvas.draw_idle.called) 76 self.plotter.figure.clf() 75 77 76 78 def testCalculateDepth(self): … … 94 96 self.plotter.show() 95 97 96 Qt Gui.QDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Accepted)98 QtWidgets.QDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Accepted) 97 99 98 100 # Just this one plot … … 100 102 101 103 # Check that exec_ got called 102 self.assertTrue(Qt Gui.QDialog.exec_.called)104 self.assertTrue(QtWidgets.QDialog.exec_.called) 103 105 104 106 self.assertEqual(self.plotter.cmap, "jet") 105 107 self.assertAlmostEqual(self.plotter.vmin, 0.1, 6) 106 108 self.assertAlmostEqual(self.plotter.vmax, 1e+20, 6) 109 self.plotter.figure.clf() 107 110 108 111 def testOnToggleScale(self): … … 115 118 116 119 self.assertTrue(FigureCanvas.draw_idle.called) 120 self.plotter.figure.clf() 117 121 118 122 def testOnBoxSum(self): … … 135 139 self.assertTrue(self.plotter.boxwidget.isVisible()) 136 140 self.assertIsInstance(self.plotter.boxwidget.model, QtGui.QStandardItemModel) 141 self.plotter.figure.clf() 137 142 138 143 def testContextMenuQuickPlot(self): … … 151 156 # Trigger Print Image and make sure the method is called 152 157 self.assertEqual(actions[1].text(), "Print Image") 153 Qt Gui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Rejected)158 QtPrintSupport.QPrintDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Rejected) 154 159 actions[1].trigger() 155 self.assertTrue(Qt Gui.QPrintDialog.exec_.called)160 self.assertTrue(QtPrintSupport.QPrintDialog.exec_.called) 156 161 157 162 # Trigger Copy to Clipboard and make sure the method is called … … 176 181 def done(): 177 182 self.clipboard_called = True 178 QtCore.QObject.connect(Qt Gui.qApp.clipboard(), QtCore.SIGNAL("dataChanged()"), done)183 QtCore.QObject.connect(QtWidgets.qApp.clipboard(), QtCore.SIGNAL("dataChanged()"), done) 179 184 actions[2].trigger() 180 Qt Gui.qApp.processEvents()185 QtWidgets.qApp.processEvents() 181 186 # Make sure clipboard got updated. 182 187 self.assertTrue(self.clipboard_called) 188 self.plotter.figure.clf() 183 189 184 190 def testShowNoPlot(self): … … 200 206 self.assertFalse(FigureCanvas.draw_idle.called) 201 207 self.assertFalse(FigureCanvas.draw.called) 208 self.plotter.figure.clf() 202 209 203 210 def testShow3DPlot(self): … … 220 227 self.assertTrue(Axes3D.plot_surface.called) 221 228 self.assertTrue(FigureCanvas.draw.called) 229 self.plotter.figure.clf() 222 230 223 231 def testShow2DPlot(self): … … 238 246 zmax=None) 239 247 self.assertTrue(FigureCanvas.draw_idle.called) 248 self.plotter.figure.clf() 240 249 241 250 -
src/sas/qtgui/Plotting/UnitTesting/PlotterBaseTest.py
rb2a5042 rdd150ef 2 2 import unittest 3 3 import platform 4 from mock import patch,MagicMock4 from unittest.mock import MagicMock 5 5 6 from PyQt 4 import QtGui6 from PyQt5 import QtGui, QtWidgets, QtPrintSupport 7 7 import matplotlib.pyplot as plt 8 from matplotlib.backends.backend_qt 4agg import FigureCanvasQTAgg as FigureCanvas9 from matplotlib.backends.backend_qt 4agg import NavigationToolbar2QT as NavigationToolbar8 from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas 9 from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar 10 10 11 11 ####### TEMP … … 21 21 import sas.qtgui.Plotting.PlotterBase as PlotterBase 22 22 23 if not Qt Gui.QApplication.instance():24 app = Qt Gui.QApplication(sys.argv)23 if not QtWidgets.QApplication.instance(): 24 app = QtWidgets.QApplication(sys.argv) 25 25 26 26 class PlotterBaseTest(unittest.TestCase): … … 45 45 def testDefaults(self): 46 46 """ default method variables values """ 47 self.assertIsInstance(self.plotter, Qt Gui.QWidget)47 self.assertIsInstance(self.plotter, QtWidgets.QWidget) 48 48 self.assertIsInstance(self.plotter.canvas, FigureCanvas) 49 49 self.assertIsInstance(self.plotter.toolbar, NavigationToolbar) … … 94 94 ''' test the workspace print ''' 95 95 QtGui.QPainter.end = MagicMock() 96 Qt Gui.QLabel.render = MagicMock()96 QtWidgets.QLabel.render = MagicMock() 97 97 98 98 # First, let's cancel printing 99 Qt Gui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Rejected)99 QtPrintSupport.QPrintDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Rejected) 100 100 self.plotter.onImagePrint() 101 101 self.assertFalse(QtGui.QPainter.end.called) 102 self.assertFalse(Qt Gui.QLabel.render.called)102 self.assertFalse(QtWidgets.QLabel.render.called) 103 103 104 104 # Let's print now 105 Qt Gui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Accepted)105 QtPrintSupport.QPrintDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Accepted) 106 106 self.plotter.onImagePrint() 107 107 self.assertTrue(QtGui.QPainter.end.called) 108 self.assertTrue(Qt Gui.QLabel.render.called)108 self.assertTrue(QtWidgets.QLabel.render.called) 109 109 110 110 def testOnClipboardCopy(self): … … 141 141 # Trigger Print Image and make sure the method is called 142 142 self.assertEqual(actions[1].text(), "Print Image") 143 Qt Gui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Rejected)143 QtPrintSupport.QPrintDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Rejected) 144 144 actions[1].trigger() 145 self.assertTrue(Qt Gui.QPrintDialog.exec_.called)145 self.assertTrue(QtPrintSupport.QPrintDialog.exec_.called) 146 146 147 147 # Trigger Copy to Clipboard and make sure the method is called … … 154 154 def done(): 155 155 self.clipboard_called = True 156 QtCore.QObject.connect(Qt Gui.qApp.clipboard(), QtCore.SIGNAL("dataChanged()"), done)156 QtCore.QObject.connect(QtWidgets.qApp.clipboard(), QtCore.SIGNAL("dataChanged()"), done) 157 157 actions[2].trigger() 158 Qt Gui.qApp.processEvents()158 QtWidgets.qApp.processEvents() 159 159 # Make sure clipboard got updated. 160 160 self.assertTrue(self.clipboard_called) … … 163 163 """ Test changing the plot title""" 164 164 # Mock the modal dialog's response 165 Qt Gui.QDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Accepted)165 QtWidgets.QDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Accepted) 166 166 self.plotter.show() 167 167 # Assure the original title is none -
src/sas/qtgui/Plotting/UnitTesting/PlotterTest.py
rb2a5042 r63319b0 3 3 import platform 4 4 5 from PyQt 4 import QtGui6 from PyQt 4import QtCore7 from matplotlib.backends.backend_qt 4agg import FigureCanvasQTAgg as FigureCanvas8 from mock import MagicMock9 from mock import patch5 from PyQt5 import QtGui, QtWidgets, QtPrintSupport 6 from PyQt5 import QtCore 7 from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas 8 from unittest.mock import MagicMock 9 from unittest.mock import patch 10 10 11 11 ####### TEMP … … 21 21 import sas.qtgui.Plotting.Plotter as Plotter 22 22 23 if not Qt Gui.QApplication.instance():24 app = Qt Gui.QApplication(sys.argv)23 if not QtWidgets.QApplication.instance(): 24 app = QtWidgets.QApplication(sys.argv) 25 25 26 26 … … 50 50 self.assertEqual(self.plotter.data, self.data) 51 51 self.assertEqual(self.plotter._title, self.data.name) 52 self.assertEqual(self.plotter.xLabel, " $()$")53 self.assertEqual(self.plotter.yLabel, " $()$")52 self.assertEqual(self.plotter.xLabel, "") 53 self.assertEqual(self.plotter.yLabel, "") 54 54 55 55 def testPlotWithErrors(self): … … 57 57 self.plotter.data = self.data 58 58 self.plotter.show() 59 FigureCanvas.draw = MagicMock()59 FigureCanvas.draw_idle = MagicMock() 60 60 61 61 self.plotter.plot(hide_error=False) 62 62 63 63 self.assertEqual(self.plotter.ax.get_xscale(), 'log') 64 self.assertTrue(FigureCanvas.draw.called) 64 self.assertTrue(FigureCanvas.draw_idle.called) 65 66 self.plotter.figure.clf() 65 67 66 68 def testPlotWithoutErrors(self): … … 68 70 self.plotter.data = self.data 69 71 self.plotter.show() 70 FigureCanvas.draw = MagicMock()72 FigureCanvas.draw_idle = MagicMock() 71 73 72 74 self.plotter.plot(hide_error=True) 73 75 74 76 self.assertEqual(self.plotter.ax.get_yscale(), 'log') 75 self.assertTrue(FigureCanvas.draw.called) 77 self.assertTrue(FigureCanvas.draw_idle.called) 78 self.plotter.figure.clf() 79 80 def testPlotWithSesans(self): 81 """ Ensure that Sesans data is plotted in linear cooredinates""" 82 data = Data1D(x=[1.0, 2.0, 3.0], 83 y=[10.0, 11.0, 12.0], 84 dx=[0.1, 0.2, 0.3], 85 dy=[0.1, 0.2, 0.3]) 86 data.title = "Sesans data" 87 data.name = "Test Sesans" 88 data.isSesans = True 89 data.id = 2 90 91 self.plotter.data = data 92 self.plotter.show() 93 FigureCanvas.draw_idle = MagicMock() 94 95 self.plotter.plot(hide_error=True) 96 97 self.assertEqual(self.plotter.ax.get_xscale(), 'linear') 98 self.assertEqual(self.plotter.ax.get_yscale(), 'linear') 99 self.assertTrue(FigureCanvas.draw_idle.called) 76 100 77 101 def testCreateContextMenuQuick(self): … … 89 113 # Trigger Print Image and make sure the method is called 90 114 self.assertEqual(actions[1].text(), "Print Image") 91 Qt Gui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Rejected)115 QtPrintSupport.QPrintDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Rejected) 92 116 actions[1].trigger() 93 self.assertTrue(Qt Gui.QPrintDialog.exec_.called)117 self.assertTrue(QtPrintSupport.QPrintDialog.exec_.called) 94 118 95 119 # Trigger Copy to Clipboard and make sure the method is called … … 104 128 # Trigger Change Scale and make sure the method is called 105 129 self.assertEqual(actions[6].text(), "Change Scale") 106 self.plotter.properties.exec_ = MagicMock(return_value=Qt Gui.QDialog.Rejected)130 self.plotter.properties.exec_ = MagicMock(return_value=QtWidgets.QDialog.Rejected) 107 131 actions[6].trigger() 108 132 self.assertTrue(self.plotter.properties.exec_.called) … … 114 138 def done(): 115 139 self.clipboard_called = True 116 QtCore.QObject.connect(Qt Gui.qApp.clipboard(), QtCore.SIGNAL("dataChanged()"), done)140 QtCore.QObject.connect(QtWidgets.qApp.clipboard(), QtCore.SIGNAL("dataChanged()"), done) 117 141 actions[2].trigger() 118 Qt Gui.qApp.processEvents()142 QtWidgets.qApp.processEvents() 119 143 # Make sure clipboard got updated. 120 144 self.assertTrue(self.clipboard_called) … … 136 160 self.assertEqual(len(self.plotter.plot_dict), 1) 137 161 self.assertEqual(len(self.plotter.ax.collections), 1) 162 self.plotter.figure.clf() 138 163 139 164 def testAddText(self): … … 153 178 self.plotter.addText.color = MagicMock(return_value = test_color) 154 179 # Return OK from the dialog 155 self.plotter.addText.exec_ = MagicMock(return_value = Qt Gui.QDialog.Accepted)180 self.plotter.addText.exec_ = MagicMock(return_value = QtWidgets.QDialog.Accepted) 156 181 # Add text to graph 157 182 self.plotter.onAddText() … … 163 188 self.assertEqual(self.plotter.textList[0].get_fontproperties().get_family()[0], 'Arial') 164 189 self.assertEqual(self.plotter.textList[0].get_fontproperties().get_size(), 16) 190 self.plotter.figure.clf() 165 191 166 192 def testOnRemoveText(self): … … 172 198 self.plotter.addText.textEdit.setText(test_text) 173 199 # Return OK from the dialog 174 self.plotter.addText.exec_ = MagicMock(return_value = Qt Gui.QDialog.Accepted)200 self.plotter.addText.exec_ = MagicMock(return_value = QtWidgets.QDialog.Accepted) 175 201 # Add text to graph 202 self.plotter.x_click = 1.0 203 self.plotter.y_click = 5.0 176 204 self.plotter.onAddText() 177 205 self.plotter.show() … … 188 216 self.plotter.onRemoveText() 189 217 self.assertEqual(self.plotter.textList, []) 218 self.plotter.figure.clf() 190 219 191 220 def testOnSetGraphRange(self): … … 195 224 self.plotter.plot(self.data) 196 225 self.plotter.show() 197 self.plotter.setRange.exec_ = MagicMock(return_value = Qt Gui.QDialog.Accepted)226 self.plotter.setRange.exec_ = MagicMock(return_value = QtWidgets.QDialog.Accepted) 198 227 self.plotter.setRange.xrange = MagicMock(return_value = new_x) 199 228 self.plotter.setRange.yrange = MagicMock(return_value = new_y) … … 204 233 self.assertEqual(self.plotter.ax.get_xlim(), new_x) 205 234 self.assertEqual(self.plotter.ax.get_ylim(), new_y) 235 self.plotter.figure.clf() 206 236 207 237 def testOnResetGraphRange(self): … … 215 245 216 246 # mock setRange methods 217 self.plotter.setRange.exec_ = MagicMock(return_value = Qt Gui.QDialog.Accepted)247 self.plotter.setRange.exec_ = MagicMock(return_value = QtWidgets.QDialog.Accepted) 218 248 self.plotter.setRange.xrange = MagicMock(return_value = new_x) 219 249 self.plotter.setRange.yrange = MagicMock(return_value = new_y) … … 228 258 self.assertNotEqual(self.plotter.ax.get_xlim(), new_x) 229 259 self.assertNotEqual(self.plotter.ax.get_ylim(), new_y) 260 self.plotter.figure.clf() 230 261 231 262 def testOnLinearFit(self): … … 233 264 self.plotter.plot(self.data) 234 265 self.plotter.show() 235 Qt Gui.QDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Accepted)266 QtWidgets.QDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Accepted) 236 267 237 268 # Just this one plot 238 self.assertEqual(len( self.plotter.plot_dict.keys()), 1)269 self.assertEqual(len(list(self.plotter.plot_dict.keys())), 1) 239 270 self.plotter.onLinearFit(1) 240 271 241 272 # Check that exec_ got called 242 self.assertTrue(QtGui.QDialog.exec_.called) 273 self.assertTrue(QtWidgets.QDialog.exec_.called) 274 self.plotter.figure.clf() 243 275 244 276 def testOnRemovePlot(self): … … 260 292 261 293 # Assure we have two sets 262 self.assertEqual(len( self.plotter.plot_dict.keys()), 2)294 self.assertEqual(len(list(self.plotter.plot_dict.keys())), 2) 263 295 264 296 # Delete one set 265 297 self.plotter.onRemovePlot(2) 266 298 # Assure we have two sets 267 self.assertEqual(len( self.plotter.plot_dict.keys()), 1)299 self.assertEqual(len(list(self.plotter.plot_dict.keys())), 1) 268 300 269 301 self.plotter.manager = MagicMock() … … 272 304 self.plotter.onRemovePlot(1) 273 305 # Assure we have no plots 274 self.assertEqual(len( self.plotter.plot_dict.keys()), 0)306 self.assertEqual(len(list(self.plotter.plot_dict.keys())), 0) 275 307 # Assure the plotter window is closed 276 308 self.assertFalse(self.plotter.isVisible()) 277 309 self.plotter.figure.clf() 278 310 279 311 def testRemovePlot(self): … … 306 338 # The hide_error flag should also remain 307 339 self.assertTrue(self.plotter.plot_dict[2].hide_error) 340 self.plotter.figure.clf() 308 341 309 342 def testOnToggleHideError(self): … … 336 369 # The hide_error flag should toggle 337 370 self.assertEqual(self.plotter.plot_dict[2].hide_error, not error_status) 371 self.plotter.figure.clf() 338 372 339 373 def testOnFitDisplay(self): … … 352 386 self.plotter.plot.assert_called_with(data=self.plotter.fit_result, 353 387 hide_error=True, marker='-') 388 self.plotter.figure.clf() 354 389 355 390 def testReplacePlot(self): … … 361 396 xl = self.plotter.ax.xaxis.label.get_text() 362 397 yl = self.plotter.ax.yaxis.label.get_text() 363 self.assertEqual(xl, " $()$")364 self.assertEqual(yl, " $()$")398 self.assertEqual(xl, "") 399 self.assertEqual(yl, "") 365 400 366 401 # Prepare new data … … 389 424 # The hide_error flag should be as set 390 425 self.assertEqual(self.plotter.plot_dict[2].hide_error, error_status) 426 self.plotter.figure.clf() 391 427 392 428 def notestOnModifyPlot(self): … … 408 444 with patch('sas.qtgui.Plotting.PlotProperties.PlotProperties') as mock: 409 445 instance = mock.return_value 410 Qt Gui.QDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Accepted)446 QtWidgets.QDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Accepted) 411 447 instance.symbol.return_value = 7 412 448 413 449 self.plotter.onModifyPlot(2) 450 self.plotter.figure.clf() 414 451 415 452 -
src/sas/qtgui/Plotting/UnitTesting/ScalePropertiesTest.py
r464cd07 r53c771e 2 2 import unittest 3 3 4 from PyQt 4 import QtGui4 from PyQt5 import QtGui, QtWidgets 5 5 6 6 # set up import paths … … 10 10 from sas.qtgui.Plotting.ScaleProperties import ScaleProperties 11 11 12 if not Qt Gui.QApplication.instance():13 app = Qt Gui.QApplication(sys.argv)12 if not QtWidgets.QApplication.instance(): 13 app = QtWidgets.QApplication(sys.argv) 14 14 15 15 class ScalePropertiesTest(unittest.TestCase): … … 27 27 def testDefaults(self): 28 28 '''Test the GUI in its default state''' 29 self.assertIsInstance(self.widget, Qt Gui.QDialog)29 self.assertIsInstance(self.widget, QtWidgets.QDialog) 30 30 self.assertEqual(self.widget.windowTitle(), "Scale Properties") 31 31 self.assertEqual(self.widget.cbX.count(), 6) -
src/sas/qtgui/Plotting/UnitTesting/SetGraphRangeTest.py
r464cd07 r53c771e 2 2 import unittest 3 3 4 from PyQt 4 import QtGui4 from PyQt5 import QtGui, QtWidgets 5 5 6 6 # set up import paths … … 10 10 from sas.qtgui.Plotting.SetGraphRange import SetGraphRange 11 11 12 if not Qt Gui.QApplication.instance():13 app = Qt Gui.QApplication(sys.argv)12 if not QtWidgets.QApplication.instance(): 13 app = QtWidgets.QApplication(sys.argv) 14 14 15 15 class SetGraphRangeTest(unittest.TestCase): … … 27 27 def testDefaults(self): 28 28 '''Test the GUI in its default state''' 29 self.assertIsInstance(self.widget, Qt Gui.QDialog)29 self.assertIsInstance(self.widget, QtWidgets.QDialog) 30 30 self.assertEqual(self.widget.windowTitle(), "Set Graph Range") 31 self.assertIsInstance(self.widget.txtXmin, Qt Gui.QLineEdit)31 self.assertIsInstance(self.widget.txtXmin, QtWidgets.QLineEdit) 32 32 self.assertIsInstance(self.widget.txtXmin.validator(), QtGui.QDoubleValidator) 33 33 -
src/sas/qtgui/Plotting/UnitTesting/SlicerModelTest.py
r464cd07 r53c771e 1 1 import sys 2 2 import unittest 3 from mock import MagicMock3 from unittest.mock import MagicMock 4 4 5 from PyQt 4 import QtGui6 from PyQt 4import QtCore5 from PyQt5 import QtGui, QtWidgets 6 from PyQt5 import QtCore 7 7 8 8 # set up import paths … … 12 12 from sas.qtgui.Plotting.SlicerModel import SlicerModel 13 13 14 if not Qt Gui.QApplication.instance():15 app = Qt Gui.QApplication(sys.argv)14 if not QtWidgets.QApplication.instance(): 15 app = QtWidgets.QApplication(sys.argv) 16 16 17 17 class SlicerModelTest(unittest.TestCase): -
src/sas/qtgui/Plotting/UnitTesting/SlicerParametersTest.py
r464cd07 r725d9c06 1 1 import sys 2 2 import unittest 3 from mock import MagicMock 3 import webbrowser 4 from unittest.mock import MagicMock 4 5 5 from PyQt4 import QtGui 6 from PyQt4 import QtCore 7 from PyQt4 import QtTest 8 from PyQt4 import QtWebKit 9 10 from mock import MagicMock 6 from PyQt5 import QtGui, QtWidgets 7 from PyQt5 import QtCore 8 from PyQt5 import QtTest 11 9 12 10 # set up import paths … … 18 16 from sas.qtgui.Plotting.SlicerParameters import SlicerParameters 19 17 20 if not Qt Gui.QApplication.instance():21 app = Qt Gui.QApplication(sys.argv)18 if not QtWidgets.QApplication.instance(): 19 app = QtWidgets.QApplication(sys.argv) 22 20 23 21 class SlicerParametersTest(unittest.TestCase): … … 39 37 '''Test the GUI in its default state''' 40 38 #self.widget.mapper 41 self.assertIsInstance(self.widget.proxy, Qt Gui.QIdentityProxyModel)42 self.assertIsInstance(self.widget.lstParams.itemDelegate(), Qt Gui.QStyledItemDelegate)39 self.assertIsInstance(self.widget.proxy, QtCore.QIdentityProxyModel) 40 self.assertIsInstance(self.widget.lstParams.itemDelegate(), QtWidgets.QStyledItemDelegate) 43 41 self.assertTrue(self.widget.lstParams.model().columnReadOnly(0)) 44 42 self.assertFalse(self.widget.lstParams.model().columnReadOnly(1)) … … 64 62 spy_close = QtSignalSpy(self.widget, self.widget.close_signal) 65 63 # Click on the "Close" button 66 QtTest.QTest.mouseClick(self.widget.buttonBox.button(Qt Gui.QDialogButtonBox.Close), QtCore.Qt.LeftButton)64 QtTest.QTest.mouseClick(self.widget.buttonBox.button(QtWidgets.QDialogButtonBox.Close), QtCore.Qt.LeftButton) 67 65 # Check the signal 68 66 self.assertEqual(spy_close.count(), 1) … … 70 68 self.assertFalse(self.widget.isVisible()) 71 69 72 def testOnHelp(self):70 def notestOnHelp(self): 73 71 ''' Assure clicking on help returns QtWeb view on requested page''' 74 72 self.widget.show() 75 73 76 #Mock the QWebView method 77 QtWebKit.QWebView.show = MagicMock() 78 QtWebKit.QWebView.load = MagicMock() 74 #Mock the webbrowser.open method 75 webbrowser.open = MagicMock() 79 76 80 77 # Invoke the action … … 82 79 83 80 # Check if show() got called 84 self.assertTrue( QtWebKit.QWebView.show.called)81 self.assertTrue(webbrowser.open.called) 85 82 86 83 # Assure the filename is correct 87 self.assertIn("graph_help.html", QtWebKit.QWebView.load.call_args[0][0].toString())84 self.assertIn("graph_help.html", webbrowser.open.call_args[0][0]) 88 85 89 86 def testSetModel(self): -
src/sas/qtgui/Plotting/UnitTesting/WindowTitleTest.py
r464cd07 r53c771e 2 2 import unittest 3 3 4 from PyQt 4 import QtGui4 from PyQt5 import QtGui, QtWidgets 5 5 6 6 # set up import paths … … 10 10 from sas.qtgui.Plotting.WindowTitle import WindowTitle 11 11 12 if not Qt Gui.QApplication.instance():13 app = Qt Gui.QApplication(sys.argv)12 if not QtWidgets.QApplication.instance(): 13 app = QtWidgets.QApplication(sys.argv) 14 14 15 15 class WindowTitleTest(unittest.TestCase): … … 27 27 '''Test the GUI in its default state''' 28 28 self.widget.show() 29 self.assertIsInstance(self.widget, Qt Gui.QDialog)29 self.assertIsInstance(self.widget, QtWidgets.QDialog) 30 30 self.assertEqual(self.widget.windowTitle(), "Modify Window Title") 31 31 … … 33 33 '''Modify the title''' 34 34 self.widget.show() 35 Qt Gui.qApp.processEvents()35 QtWidgets.qApp.processEvents() 36 36 # make sure we have the pre-set title 37 37 self.assertEqual(self.widget.txtTitle.text(), "some title") … … 39 39 self.widget.txtTitle.clear() 40 40 self.widget.txtTitle.setText("5 elephants") 41 Qt Gui.qApp.processEvents()41 QtWidgets.qApp.processEvents() 42 42 # Retrieve value 43 43 new_title = self.widget.title() -
src/sas/qtgui/Plotting/WindowTitle.py
r83eb5208 r4992ff2 3 3 from "Graph_n" to any ASCII text. 4 4 """ 5 from PyQt 4 import QtGui5 from PyQt5 import QtWidgets 6 6 7 7 from sas.qtgui.Plotting.UI.WindowTitleUI import Ui_WindowTitle 8 8 9 class WindowTitle(Qt Gui.QDialog, Ui_WindowTitle):9 class WindowTitle(QtWidgets.QDialog, Ui_WindowTitle): 10 10 """ Simple GUI for a single line text query """ 11 11 def __init__(self, parent=None, new_title=""): -
src/sas/qtgui/Plotting/rangeSlider.py
- Property mode changed from 100755 to 100644
r83eb5208 r7969b9c 23 23 """ 24 24 25 from PyQt4 import QtGui, QtCore 26 27 class RangeSlider(QtGui.QSlider): 25 from PyQt5 import QtCore 26 from PyQt5 import QtGui 27 from PyQt5 import QtWidgets 28 29 class RangeSlider(QtWidgets.QSlider): 28 30 """ A slider for ranges. 29 31 … … 46 48 self._high = self.maximum() 47 49 48 self.pressed_control = Qt Gui.QStyle.SC_None49 self.hover_control = Qt Gui.QStyle.SC_None50 self.pressed_control = QtWidgets.QStyle.SC_None 51 self.hover_control = QtWidgets.QStyle.SC_None 50 52 self.click_offset = 0 51 53 … … 87 89 88 90 painter = QtGui.QPainter(self) 89 style = Qt Gui.QApplication.style()91 style = QtWidgets.QApplication.style() 90 92 91 93 for i, value in enumerate([self._low, self._high]): 92 opt = Qt Gui.QStyleOptionSlider()94 opt = QtWidgets.QStyleOptionSlider() 93 95 self.initStyleOption(opt) 94 96 … … 107 109 slider_max = gr.bottom() - handle_length + 1 108 110 109 opt.subControls = Qt Gui.QStyle.SC_SliderGroove | QtGui.QStyle.SC_SliderHandle111 opt.subControls = QtWidgets.QStyle.SC_SliderGroove | QtWidgets.QStyle.SC_SliderHandle 110 112 111 113 # draw the first slider with inverted appearance, then the second … … 131 133 # do not highlight the second part when has focus to avoid 132 134 # drawing of partially overlapped semi-transparent backgrounds 133 opt.state &= ~Qt Gui.QStyle.State_HasFocus135 opt.state &= ~QtWidgets.QStyle.State_HasFocus 134 136 135 137 opt.sliderValue = 0 … … 157 159 158 160 if self.tickPosition() != self.NoTicks: 159 opt.subControls |= Qt Gui.QStyle.SC_SliderTickmarks161 opt.subControls |= QtWidgets.QStyle.SC_SliderTickmarks 160 162 161 163 if self.pressed_control: 162 164 opt.activeSubControls = self.pressed_control 163 opt.state |= Qt Gui.QStyle.State_Sunken165 opt.state |= QtWidgets.QStyle.State_Sunken 164 166 else: 165 167 opt.activeSubControls = self.hover_control 166 168 167 style.drawComplexControl(Qt Gui.QStyle.CC_Slider, opt, painter, self)169 style.drawComplexControl(QtWidgets.QStyle.CC_Slider, opt, painter, self) 168 170 169 171 … … 171 173 event.accept() 172 174 173 style = Qt Gui.QApplication.style()175 style = QtWidgets.QApplication.style() 174 176 button = event.button() 175 177 … … 181 183 182 184 if button: 183 opt = Qt Gui.QStyleOptionSlider()185 opt = QtWidgets.QStyleOptionSlider() 184 186 self.initStyleOption(opt) 185 187 … … 206 208 207 209 if self.active_slider == 0: 208 self.pressed_control = Qt Gui.QStyle.SC_SliderHandle210 self.pressed_control = QtWidgets.QStyle.SC_SliderHandle 209 211 self.click_offset = self.__pixelPosToRangeValue(self.__pick(event.pos())) 210 212 self.triggerAction(self.SliderMove) … … 215 217 216 218 def mouseReleaseEvent(self, event): 217 if self.pressed_control != Qt Gui.QStyle.SC_SliderHandle:219 if self.pressed_control != QtWidgets.QStyle.SC_SliderHandle: 218 220 event.ignore() 219 221 return 220 222 221 223 self.setSliderDown(False) 222 return Qt Gui.QSlider.mouseReleaseEvent(self, event)224 return QtWidgets.QSlider.mouseReleaseEvent(self, event) 223 225 224 226 def mouseMoveEvent(self, event): 225 if self.pressed_control != Qt Gui.QStyle.SC_SliderHandle:227 if self.pressed_control != QtWidgets.QStyle.SC_SliderHandle: 226 228 event.ignore() 227 229 return … … 229 231 event.accept() 230 232 new_pos = self.__pixelPosToRangeValue(self.__pick(event.pos())) 231 opt = Qt Gui.QStyleOptionSlider()233 opt = QtWidgets.QStyleOptionSlider() 232 234 self.initStyleOption(opt) 233 235 … … 262 264 self.setHighValue( new_pos ) 263 265 264 if self.hasTracking():265 self.emit(QtCore.SIGNAL('sliderMoved(int)'), new_pos)266 267 266 268 267 def __pick(self, pt): … … 274 273 275 274 def __pixelPosToRangeValue(self, pos): 276 opt = Qt Gui.QStyleOptionSlider()275 opt = QtWidgets.QStyleOptionSlider() 277 276 self.initStyleOption(opt) 278 style = Qt Gui.QApplication.style()277 style = QtWidgets.QApplication.style() 279 278 280 279 gr = style.subControlRect(style.CC_Slider, opt, style.SC_SliderGroove, self)
Note: See TracChangeset
for help on using the changeset viewer.