def onData(self): """Executed when the selected item data is modified.""" if not self.skip: self.skip = True plt = Plot.getPlot() if not plt: self.updateUI() return # Ensure that selected serie exist if self.item >= len(Plot.series()): self.updateUI() return # Set label serie = Plot.series()[self.item] if (self.form.isLabel.isChecked()): serie.name = None self.form.label.setEnabled(False) else: serie.name = self.form.label.text() self.form.label.setEnabled(True) # Set line style and marker style = self.form.style.currentIndex() linestyles = list(Line2D.lineStyles.keys()) serie.line.set_linestyle(linestyles[style]) marker = self.form.marker.currentIndex() markers = list(Line2D.markers.keys()) serie.line.set_marker(markers[marker]) # Set line width and marker size serie.line.set_linewidth(self.form.width.value()) serie.line.set_markersize(self.form.size.value()) plt.update() # Regenerate series labels self.setList() self.skip = False
def updateUI(self): """ Setup UI controls values if possible """ plt = Plot.getPlot() self.form.items.setEnabled(bool(plt)) self.form.label.setEnabled(bool(plt)) self.form.isLabel.setEnabled(bool(plt)) self.form.style.setEnabled(bool(plt)) self.form.marker.setEnabled(bool(plt)) self.form.width.setEnabled(bool(plt)) self.form.size.setEnabled(bool(plt)) self.form.color.setEnabled(bool(plt)) self.form.remove.setEnabled(bool(plt)) if not plt: self.plt = plt self.form.items.clear() return self.skip = True # Refill list if self.plt != plt or len(Plot.series()) != self.form.items.count(): self.plt = plt self.setList() # Ensure that have series if not len(Plot.series()): self.form.label.setEnabled(False) self.form.isLabel.setEnabled(False) self.form.style.setEnabled(False) self.form.marker.setEnabled(False) self.form.width.setEnabled(False) self.form.size.setEnabled(False) self.form.color.setEnabled(False) self.form.remove.setEnabled(False) return # Set label serie = Plot.series()[self.item] if serie.name is None: self.form.isLabel.setChecked(True) self.form.label.setEnabled(False) self.form.label.setText("") else: self.form.isLabel.setChecked(False) self.form.label.setText(serie.name) # Set line style and marker self.form.style.setCurrentIndex(0) for i, style in enumerate(Line2D.lineStyles.keys()): if style == serie.line.get_linestyle(): self.form.style.setCurrentIndex(i) self.form.marker.setCurrentIndex(0) for i, marker in enumerate(Line2D.markers.keys()): if marker == serie.line.get_marker(): self.form.marker.setCurrentIndex(i) # Set line width and marker size self.form.width.setValue(serie.line.get_linewidth()) self.form.size.setValue(serie.line.get_markersize()) # Set color color = Colors.colorConverter.to_rgb(serie.line.get_color()) self.form.color.setStyleSheet( "background-color: rgb({}, {}, {});".format( int(color[0] * 255), int(color[1] * 255), int(color[2] * 255))) self.skip = False
def onRemove(self): """Executed when the data serie must be removed.""" plt = Plot.getPlot() if not plt: self.updateUI() return # Ensure that selected serie exist if self.item >= len(Plot.series()): self.updateUI() return # Remove serie Plot.removeSerie(self.item) self.setList() self.updateUI() plt.update()
def setList(self): """Setup the UI control values if it is possible.""" mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskPanel") self.form.items = self.widget(QtGui.QListWidget, "items") self.form.items.clear() series = Plot.series() for i in range(0, len(series)): serie = series[i] string = 'serie ' + str(i) + ': ' if serie.name is None: string = string + '\"No label\"' else: string = string + serie.name self.form.items.addItem(string) # Ensure that selected item is correct if len(series) and self.item >= len(series): self.item = len(series) - 1 self.form.items.setCurrentIndex(self.item)
def onColor(self): """ Executed when color palette is requested. """ plt = Plot.getPlot() if not plt: self.updateUI() return # Ensure that selected serie exist if self.item >= len(Plot.series()): self.updateUI() return # Show widget to select color col = QtGui.QColorDialog.getColor() # Send color to widget and serie if col.isValid(): serie = plt.series[self.item] self.form.color.setStyleSheet( "background-color: rgb({}, {}, {});".format( col.red(), col.green(), col.blue())) serie.line.set_color((col.redF(), col.greenF(), col.blueF())) plt.update()