From f68dd16b1cbc628e77e2e0d914334b696c8579a1 Mon Sep 17 00:00:00 2001 From: "benjamin.jakimow@geo.hu-berlin.de" <q8DTkxUg-BB> Date: Wed, 14 Mar 2018 14:09:43 +0100 Subject: [PATCH] changed PlotStyle defaults --- test/test_mapvisualization.py | 1 - test/test_plotstyling.py | 6 ++--- timeseriesviewer/plotstyling.py | 41 +++++++++++++++++++-------------- timeseriesviewer/utils.py | 2 ++ 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/test/test_mapvisualization.py b/test/test_mapvisualization.py index c2a6c781..ba4c2cb1 100644 --- a/test/test_mapvisualization.py +++ b/test/test_mapvisualization.py @@ -50,4 +50,3 @@ class testclassDialogTest(unittest.TestCase): if __name__ == "__main__": unittest.main() -app.exec_() \ No newline at end of file diff --git a/test/test_plotstyling.py b/test/test_plotstyling.py index 29876118..2951f9fe 100644 --- a/test/test_plotstyling.py +++ b/test/test_plotstyling.py @@ -54,7 +54,6 @@ class TestPlotStyling(unittest.TestCase): s1.markerPen.setColor(QColor('yellow')) s2 = PlotStyle(plotStyle=s1) - self.assertEqual(s1,s2) @@ -67,8 +66,9 @@ class TestPlotStyling(unittest.TestCase): d.setPlotStyle(s1) except Exception: self.fail('Unable to initialize PlotStyleDialog') - - self.assertEqual(s1, d.plotStyle()) + s2 = d.plotStyle() + self.assertIsInstance(s2, PlotStyle) + self.assertEqual(s1, s2) try: btn = PlotStyleButton() diff --git a/timeseriesviewer/plotstyling.py b/timeseriesviewer/plotstyling.py index df330f92..b3039ae5 100644 --- a/timeseriesviewer/plotstyling.py +++ b/timeseriesviewer/plotstyling.py @@ -63,7 +63,7 @@ class PlotStyle(QObject): super(PlotStyle,self).__init__(**kwds) self.markerSymbol = MARKERSYMBOLS[0].mValue - self.markerSize = 10 + self.markerSize = 5 self.markerBrush = QBrush() self.markerBrush.setColor(Qt.green) self.markerBrush.setStyle(Qt.SolidPattern) @@ -71,11 +71,13 @@ class PlotStyle(QObject): self.backgroundColor = Qt.black self.markerPen = QPen() - self.markerPen.setStyle(Qt.SolidLine) + self.markerPen.setStyle(Qt.NoPen) self.markerPen.setColor(Qt.white) + self.linePen = QPen() self.linePen.setStyle(Qt.NoPen) + self.linePen.setWidth(0) self.linePen.setColor(QColor(74, 75, 75)) self.mIsVisible = True @@ -213,7 +215,7 @@ class PlotStyleWidget(QWidget, loadUI('plotstylewidget.ui')): self.sbMarkerSize.valueChanged.connect(self.refreshPreview) self.sbMarkerPenWidth.valueChanged.connect(self.refreshPreview) self.sbLinePenWidth.valueChanged.connect(self.refreshPreview) - + self.mLastPlotStyle = None self.setPlotStyle(PlotStyle()) self.refreshPreview() @@ -239,7 +241,7 @@ class PlotStyleWidget(QWidget, loadUI('plotstylewidget.ui')): def setPlotStyle(self, style): assert isinstance(style, PlotStyle) #set widget values - + self.mLastPlotStyle = style self.mBlockUpdates = True self.sbMarkerSize.setValue(style.markerSize) #self._setComboBoxToValue(self.cbMarkerSymbol, style.markerSymbol) @@ -272,7 +274,8 @@ class PlotStyleWidget(QWidget, loadUI('plotstylewidget.ui')): return icon def plotStyle(self): - style = PlotStyle() + style = PlotStyle(plotStyle=self.mLastPlotStyle) + #read plotstyle values from widgets style.markerSize = self.sbMarkerSize.value() symbol = currentComboBoxValue(self.cbMarkerSymbol) @@ -281,17 +284,19 @@ class PlotStyleWidget(QWidget, loadUI('plotstylewidget.ui')): assert isinstance(style.markerBrush, QBrush) assert isinstance(style.linePen, QPen) - style.markerPen = pg.mkPen(color=self.btnMarkerPenColor.color(), - width=self.sbMarkerPenWidth.value(), - style=currentComboBoxValue(self.cbMarkerPenStyle)) - + style.markerPen.setColor(self.btnMarkerPenColor.color()) + style.markerPen.setWidth(self.sbMarkerPenWidth.value()) + style.markerPen.setStyle(currentComboBoxValue(self.cbMarkerPenStyle)) - style.markerBrush.setColor(self.btnMarkerBrushColor.color()) style.markerBrush.setColor(self.btnMarkerBrushColor.color()) - style.linePen = pg.mkPen(color=self.btnLinePenColor.color(), - width=self.sbLinePenWidth.value(), - style=currentComboBoxValue(self.cbLinePenStyle)) + + #style.linePen = pg.mkPen(color=self.btnLinePenColor.color(), + # width=self.sbLinePenWidth.value(), + # style=currentComboBoxValue(self.cbLinePenStyle)) + style.linePen.setColor(self.btnLinePenColor.color()) + style.linePen.setWidth(self.sbLinePenWidth.value()) + style.linePen.setStyle(currentComboBoxValue(self.cbLinePenStyle)) return style @@ -379,11 +384,11 @@ class PlotStyleDialog(QgsDialog): buttonBar = QHBoxLayout() #buttonBar.addWidget(self.btCancel) #buttonBar.addWidget(self.btOk) - if plotStyle: - self.setPlotStyle(plotStyle) l = self.layout() l.addWidget(self.w) l.addLayout(buttonBar) + if isinstance(plotStyle, PlotStyle): + self.setPlotStyle(plotStyle) #self.setLayout(l) @@ -409,10 +414,12 @@ if __name__ == '__main__': assert isinstance(s2, PlotStyle) #btn = QgsSymbolButton() + #btn = QgsSymbolButton() + #btn.show() d = PlotStyleDialog() d.exec_() - btn = PlotStyleButton() - btn.show() + #btn = PlotStyleButton() + #btn.show() qgsApp.exec_() qgsApp.exitQgis() diff --git a/timeseriesviewer/utils.py b/timeseriesviewer/utils.py index eb35f91c..6bfc0799 100644 --- a/timeseriesviewer/utils.py +++ b/timeseriesviewer/utils.py @@ -685,6 +685,7 @@ def loadUIFormClass(pathUi, from_imports=False, resourceSuffix=''): #remove new-lines. this prevents uic.loadUiType(buffer, resource_suffix=RC_SUFFIX) #to mess up the *.ui xml + f = open(pathUi, 'r') txt = ''.join(f.readlines()) f.close() @@ -734,6 +735,7 @@ def loadUIFormClass(pathUi, from_imports=False, resourceSuffix=''): FORM_CLASS, _ = uic.loadUiType(pathUi, resource_suffix=RC_SUFFIX) buffer.close() + buffer = None FORM_CLASSES[pathUi] = FORM_CLASS #remove temporary added directories from python path -- GitLab