From 3ca5cc5eb4e74d5c709186185428effef384c53b Mon Sep 17 00:00:00 2001 From: Lars Bittrich Date: Fri, 15 Mar 2019 12:29:07 +0100 Subject: [PATCH] moved and renamed Legend from analysisWidgets to colorlegend in main module where it is imported --- analysis/analysisview.py | 6 ++---- analysis/analysisWidgets.py => colorlegend.py | 10 +++++++++- gepard.py | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) rename analysis/analysisWidgets.py => colorlegend.py (89%) diff --git a/analysis/analysisview.py b/analysis/analysisview.py index bab7b06..81a56d4 100644 --- a/analysis/analysisview.py +++ b/analysis/analysisview.py @@ -822,15 +822,13 @@ class ParticleAnalysis(QtWidgets.QMainWindow): self.parent.contouritem.colorList = colorList self.parent.contouritem.update() - self.parent.imparent.legend.items = legendItems - self.parent.imparent.legend.update() + self.parent.imparent.legend.setTextColorItems(legendItems) self.parent.imparent.legend.show() else: self.parent.contouritem.colorList = [] self.parent.contouritem.update() - self.parent.imparent.legend.items = [] - self.parent.imparent.legend.update() + self.parent.imparent.legend.setTextColorItems([]) self.parent.imparent.legend.hide() def show_hide_labels(self): diff --git a/analysis/analysisWidgets.py b/colorlegend.py similarity index 89% rename from analysis/analysisWidgets.py rename to colorlegend.py index 9e92745..ae7885c 100644 --- a/analysis/analysisWidgets.py +++ b/colorlegend.py @@ -24,7 +24,7 @@ import numpy as np WX, WY = 1024, 200 -class Legend(QtWidgets.QMdiSubWindow): +class ColorLegend(QtWidgets.QMdiSubWindow): def __init__(self, parent=None): super().__init__(parent) @@ -38,6 +38,14 @@ class Legend(QtWidgets.QMdiSubWindow): self.fontSize = 15 self.spacer = 10 + def setTextColorItems(self, items): + for text, color in items: + print(text, color) + assert type(text)==str or type(text)==np.str_, "items must be tuples of text and QColor" + assert type(color)==QtGui.QColor or type(color)==QtCore.Qt.GlobalColor, "items must be tuples of text and QColor" + self.items = items + self.update() + def mousePressEvent(self, event): if event.button()==QtCore.Qt.LeftButton: self.drag = event.pos() diff --git a/gepard.py b/gepard.py index ec8856c..79d3827 100755 --- a/gepard.py +++ b/gepard.py @@ -23,7 +23,7 @@ from sampleview import SampleView from scalebar import ScaleBar from ramancom.ramancontrol import defaultPath from ramancom.ramanSwitch import RamanSwitch -from analysis.analysisWidgets import Legend +from colorlegend import ColorLegend import os from pathlib import Path @@ -39,7 +39,7 @@ class MeasureParticleWindow(QtWidgets.QMainWindow): self.view.imparent = self self.view.ScalingChanged.connect(self.scalingChanged) self.scalebar = ScaleBar(self) - self.legend = Legend(self) + self.legend = ColorLegend(self) self.ramanSwitch = RamanSwitch(self) self.view.ScalingChanged.connect(self.scalebar.updateScale) -- GitLab