Re-Created branch form 0, to avoid conflicts
This commit is contained in:
committed by
wmayer
parent
6c21b74b4b
commit
d7c5054c14
309
src/Mod/Plot/plotSeries/TaskPanel.py
Normal file
309
src/Mod/Plot/plotSeries/TaskPanel.py
Normal file
@@ -0,0 +1,309 @@
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2011, 2012 *
|
||||
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
# FreeCAD modules
|
||||
import FreeCAD as App
|
||||
import FreeCADGui as Gui
|
||||
# Qt library
|
||||
from PyQt4 import QtGui,QtCore
|
||||
# Module
|
||||
import Plot
|
||||
from plotUtils import Paths, Translator
|
||||
# matplotlib
|
||||
import matplotlib
|
||||
from matplotlib.lines import Line2D
|
||||
import matplotlib.colors as Colors
|
||||
|
||||
class TaskPanel:
|
||||
def __init__(self):
|
||||
self.ui = Paths.modulePath() + "/plotSeries/TaskPanel.ui"
|
||||
self.skip = False
|
||||
self.item = 0
|
||||
self.plt = None
|
||||
|
||||
def accept(self):
|
||||
return True
|
||||
|
||||
def reject(self):
|
||||
return True
|
||||
|
||||
def clicked(self, index):
|
||||
pass
|
||||
|
||||
def open(self):
|
||||
pass
|
||||
|
||||
def needsFullSpace(self):
|
||||
return True
|
||||
|
||||
def isAllowedAlterSelection(self):
|
||||
return False
|
||||
|
||||
def isAllowedAlterView(self):
|
||||
return True
|
||||
|
||||
def isAllowedAlterDocument(self):
|
||||
return False
|
||||
|
||||
def helpRequested(self):
|
||||
pass
|
||||
|
||||
def setupUi(self):
|
||||
mw = self.getMainWindow()
|
||||
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||
form.items = form.findChild(QtGui.QListWidget, "items")
|
||||
form.label = form.findChild(QtGui.QLineEdit, "label")
|
||||
form.isLabel = form.findChild(QtGui.QCheckBox, "isLabel")
|
||||
form.style = form.findChild(QtGui.QComboBox, "lineStyle")
|
||||
form.marker = form.findChild(QtGui.QComboBox, "markers")
|
||||
form.width = form.findChild(QtGui.QDoubleSpinBox, "lineWidth")
|
||||
form.size = form.findChild(QtGui.QSpinBox, "markerSize")
|
||||
form.color = form.findChild(QtGui.QPushButton, "color")
|
||||
form.remove = form.findChild(QtGui.QPushButton, "remove")
|
||||
self.form = form
|
||||
self.retranslateUi()
|
||||
self.fillStyles()
|
||||
self.updateUI()
|
||||
QtCore.QObject.connect(form.items, QtCore.SIGNAL("currentRowChanged(int)"),self.onItem)
|
||||
QtCore.QObject.connect(form.label, QtCore.SIGNAL("editingFinished()"),self.onData)
|
||||
QtCore.QObject.connect(form.isLabel,QtCore.SIGNAL("stateChanged(int)"),self.onData)
|
||||
QtCore.QObject.connect(form.style, QtCore.SIGNAL("currentIndexChanged(int)"),self.onData)
|
||||
QtCore.QObject.connect(form.marker, QtCore.SIGNAL("currentIndexChanged(int)"),self.onData)
|
||||
QtCore.QObject.connect(form.width, QtCore.SIGNAL("valueChanged(double)"),self.onData)
|
||||
QtCore.QObject.connect(form.size, QtCore.SIGNAL("valueChanged(int)"),self.onData)
|
||||
QtCore.QObject.connect(form.color, QtCore.SIGNAL("pressed()"),self.onColor)
|
||||
QtCore.QObject.connect(form.remove, QtCore.SIGNAL("pressed()"),self.onRemove)
|
||||
QtCore.QObject.connect(Plot.getMdiArea(),QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"),self.onMdiArea)
|
||||
return False
|
||||
|
||||
def getMainWindow(self):
|
||||
"returns the main window"
|
||||
# using QtGui.qApp.activeWindow() isn't very reliable because if another
|
||||
# widget than the mainwindow is active (e.g. a dialog) the wrong widget is
|
||||
# returned
|
||||
toplevel = QtGui.qApp.topLevelWidgets()
|
||||
for i in toplevel:
|
||||
if i.metaObject().className() == "Gui::MainWindow":
|
||||
return i
|
||||
raise Exception("No main window found")
|
||||
|
||||
def retranslateUi(self):
|
||||
""" Set user interface locale strings.
|
||||
"""
|
||||
self.form.setWindowTitle(Translator.translate("Set positions and sizes"))
|
||||
self.form.isLabel.setText(Translator.translate("No label"))
|
||||
self.form.remove.setText(Translator.translate("Remove serie"))
|
||||
self.form.findChild(QtGui.QLabel, "styleLabel").setText(Translator.translate("Line style"))
|
||||
self.form.findChild(QtGui.QLabel, "markerLabel").setText(Translator.translate("Marker"))
|
||||
|
||||
def fillStyles(self):
|
||||
""" Fill style combo boxes. """
|
||||
# Line styles
|
||||
linestyles = Line2D.lineStyles.keys()
|
||||
for i in range(0,len(linestyles)):
|
||||
style = linestyles[i]
|
||||
string = "\'" + str(style) + "\' (" + Line2D.lineStyles[style] + ")"
|
||||
self.form.style.addItem(string)
|
||||
# Markers
|
||||
markers = Line2D.markers.keys()
|
||||
for i in range(0,len(markers)):
|
||||
marker = markers[i]
|
||||
string = "\'" + str(marker) + "\' (" + Line2D.markers[marker] + ")"
|
||||
self.form.marker.addItem(string)
|
||||
|
||||
def onItem(self, row):
|
||||
""" Executed when selected item is modified. """
|
||||
if not self.skip:
|
||||
self.skip = True
|
||||
# Get selected item
|
||||
self.item = row
|
||||
# Call to update
|
||||
self.updateUI()
|
||||
self.skip = False
|
||||
|
||||
def onData(self):
|
||||
""" Executed when 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 = Line2D.lineStyles.keys()
|
||||
serie.line.set_linestyle(linestyles[style])
|
||||
marker = self.form.marker.currentIndex()
|
||||
markers = 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 onColor(self):
|
||||
""" Executed when color pallete 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(%d, %d, %d);" % (col.red(),
|
||||
col.green(), col.blue()))
|
||||
serie.line.set_color((col.redF(), col.greenF(), col.blueF()))
|
||||
plt.update()
|
||||
|
||||
def onRemove(self):
|
||||
""" Executed when 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 onMdiArea(self, subWin):
|
||||
""" Executed when window is selected on mdi area.
|
||||
@param subWin Selected window.
|
||||
"""
|
||||
plt = Plot.getPlot()
|
||||
if plt != subWin:
|
||||
self.updateUI()
|
||||
|
||||
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 == 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)
|
||||
linestyles = Line2D.lineStyles.keys()
|
||||
for i in range(0,len(linestyles)):
|
||||
style = linestyles[i]
|
||||
if style == serie.line.get_linestyle():
|
||||
self.form.style.setCurrentIndex(i)
|
||||
self.form.marker.setCurrentIndex(0)
|
||||
markers = Line2D.markers.keys()
|
||||
for i in range(0,len(markers)):
|
||||
marker = markers[i]
|
||||
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(%d, %d, %d);" % (int(color[0]*255),
|
||||
int(color[1]*255), int(color[2]*255)))
|
||||
self.skip = False
|
||||
|
||||
def setList(self):
|
||||
""" Setup UI controls values if possible """
|
||||
self.form.items.clear()
|
||||
series = Plot.series()
|
||||
for i in range(0,len(series)):
|
||||
serie = series[i]
|
||||
string = 'serie ' + str(i) + ': '
|
||||
if serie.name == 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 createTask():
|
||||
panel = TaskPanel()
|
||||
Gui.Control.showDialog(panel)
|
||||
if panel.setupUi():
|
||||
Gui.Control.closeDialog(panel)
|
||||
return None
|
||||
return panel
|
||||
154
src/Mod/Plot/plotSeries/TaskPanel.ui
Normal file
154
src/Mod/Plot/plotSeries/TaskPanel.ui
Normal file
@@ -0,0 +1,154 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TaskPanel</class>
|
||||
<widget class="QWidget" name="TaskPanel">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>296</width>
|
||||
<height>336</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>336</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Configure series</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QListWidget" name="items">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0" colspan="4">
|
||||
<widget class="QLineEdit" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>2</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<widget class="QDoubleSpinBox" name="lineWidth">
|
||||
<property name="minimum">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>9999.000000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.500000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="styleLabel">
|
||||
<property name="text">
|
||||
<string>Line style</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="5">
|
||||
<widget class="QPushButton" name="remove">
|
||||
<property name="text">
|
||||
<string>Remove serie</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="3">
|
||||
<widget class="QComboBox" name="lineStyle">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="markerLabel">
|
||||
<property name="text">
|
||||
<string>Markers</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<widget class="QCheckBox" name="isLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>No label</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="3">
|
||||
<widget class="QComboBox" name="markers">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="5">
|
||||
<widget class="QPushButton" name="color">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="4">
|
||||
<widget class="QSpinBox" name="markerSize">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>9999</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
36
src/Mod/Plot/plotSeries/__init__.py
Normal file
36
src/Mod/Plot/plotSeries/__init__.py
Normal file
@@ -0,0 +1,36 @@
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2011, 2012 *
|
||||
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
# FreeCAD modules
|
||||
import FreeCAD
|
||||
import FreeCADGui
|
||||
|
||||
# Qt libraries
|
||||
from PyQt4 import QtGui,QtCore
|
||||
|
||||
# Main object
|
||||
import TaskPanel
|
||||
|
||||
def load():
|
||||
""" Loads the tool """
|
||||
TaskPanel.createTask()
|
||||
Reference in New Issue
Block a user