rebased (regenerated) branch from master
This commit is contained in:
parent
1e135aa367
commit
11278f34f3
|
@ -21,26 +21,42 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
class PlotWorkbench ( Workbench ):
|
|
||||||
""" @brief Workbench of Plot module. Here toolbars & icons are append. """
|
|
||||||
from plotUtils import Paths
|
|
||||||
import PlotGui
|
|
||||||
|
|
||||||
Icon = 'Icon.svg'
|
class PlotWorkbench(Workbench):
|
||||||
MenuText = "Plot"
|
"""Workbench of Plot module."""
|
||||||
ToolTip = "The Plot module is used to edit/save output plots performed by other tools"
|
from plotUtils import Paths
|
||||||
|
import PlotGui
|
||||||
|
|
||||||
|
Icon = 'Icon.svg'
|
||||||
|
MenuText = "Plot"
|
||||||
|
ToolTip = ("The Plot module is used to edit/save output plots performed "
|
||||||
|
"by other tools")
|
||||||
|
|
||||||
|
def Initialize(self):
|
||||||
|
from PySide import QtCore, QtGui
|
||||||
|
cmdlst = ["Plot_SaveFig",
|
||||||
|
"Plot_Axes",
|
||||||
|
"Plot_Series",
|
||||||
|
"Plot_Grid",
|
||||||
|
"Plot_Legend",
|
||||||
|
"Plot_Labels",
|
||||||
|
"Plot_Positions"]
|
||||||
|
self.appendToolbar(str(QtCore.QT_TRANSLATE_NOOP(
|
||||||
|
"Plot",
|
||||||
|
"Plot edition tools")), cmdlst)
|
||||||
|
self.appendMenu(str(QtCore.QT_TRANSLATE_NOOP(
|
||||||
|
"Plot",
|
||||||
|
"Plot")), cmdlst)
|
||||||
|
try:
|
||||||
|
import matplotlib
|
||||||
|
except ImportError:
|
||||||
|
from PySide import QtCore, QtGui
|
||||||
|
msg = QtGui.QApplication.translate(
|
||||||
|
"plot_console",
|
||||||
|
"matplotlib not found, Plot module will be disabled",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8)
|
||||||
|
FreeCAD.Console.PrintMessage(msg + '\n')
|
||||||
|
|
||||||
def Initialize(self):
|
|
||||||
from PyQt4 import QtCore, QtGui
|
|
||||||
cmdlst = ["Plot_SaveFig", "Plot_Axes", "Plot_Series", "Plot_Grid", "Plot_Legend", "Plot_Labels", "Plot_Positions"]
|
|
||||||
self.appendToolbar(str(QtCore.QT_TRANSLATE_NOOP("Plot", "Plot edition tools")),cmdlst)
|
|
||||||
self.appendMenu(str(QtCore.QT_TRANSLATE_NOOP("Plot", "Plot")),cmdlst)
|
|
||||||
try:
|
|
||||||
import matplotlib
|
|
||||||
except ImportError:
|
|
||||||
from PyQt4 import QtCore, QtGui
|
|
||||||
msg = QtGui.QApplication.translate("plot_console", "matplotlib not found, Plot module will be disabled",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8)
|
|
||||||
FreeCAD.Console.PrintMessage(msg + '\n')
|
|
||||||
|
|
||||||
Gui.addWorkbench(PlotWorkbench())
|
Gui.addWorkbench(PlotWorkbench())
|
||||||
|
|
|
@ -21,301 +21,409 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
# FreeCAD
|
|
||||||
import FreeCAD
|
import FreeCAD
|
||||||
|
|
||||||
# PyQt4
|
import PySide
|
||||||
from PyQt4 import QtCore, QtGui
|
from PySide import QtCore, QtGui
|
||||||
|
|
||||||
# Matplot lib
|
|
||||||
try:
|
try:
|
||||||
import matplotlib
|
import matplotlib
|
||||||
import matplotlib.pyplot as plt
|
matplotlib.use('Qt4Agg')
|
||||||
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
|
matplotlib.rcParams['backend.qt4']='PySide'
|
||||||
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
|
import matplotlib.pyplot as plt
|
||||||
from matplotlib.figure import Figure
|
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
|
||||||
|
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
|
||||||
|
from matplotlib.figure import Figure
|
||||||
except ImportError:
|
except ImportError:
|
||||||
msg = QtGui.QApplication.translate("plot_console", "matplotlib not found, so Plot module can not be loaded",
|
msg = QtGui.QApplication.translate(
|
||||||
None,QtGui.QApplication.UnicodeUTF8)
|
"plot_console",
|
||||||
FreeCAD.Console.PrintMessage(msg + '\n')
|
"matplotlib not found, so Plot module can not be loaded",
|
||||||
raise ImportError("matplotlib not installed")
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8)
|
||||||
|
FreeCAD.Console.PrintMessage(msg + '\n')
|
||||||
|
raise ImportError("matplotlib not installed")
|
||||||
|
|
||||||
|
|
||||||
def getMainWindow():
|
def getMainWindow():
|
||||||
""" getMainWindow(): Gets FreeCAD main window. """
|
""" Return the FreeCAD main window. """
|
||||||
toplevel = QtGui.qApp.topLevelWidgets()
|
toplevel = QtGui.qApp.topLevelWidgets()
|
||||||
for i in toplevel:
|
for i in toplevel:
|
||||||
if i.metaObject().className() == "Gui::MainWindow":
|
if i.metaObject().className() == "Gui::MainWindow":
|
||||||
return i
|
return i
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def getMdiArea():
|
def getMdiArea():
|
||||||
""" getMdiArea(): Gets FreeCAD MdiArea. """
|
""" Return FreeCAD MdiArea. """
|
||||||
mw = getMainWindow()
|
mw = getMainWindow()
|
||||||
if not mw:
|
if not mw:
|
||||||
return None
|
return None
|
||||||
return mw.findChild(QtGui.QMdiArea)
|
childs = mw.children()
|
||||||
|
for c in childs:
|
||||||
|
if isinstance(c, PySide.QtGui.QMdiArea):
|
||||||
|
return c
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def getPlot():
|
def getPlot():
|
||||||
""" getPlot(): Gets selected Plot document if exist. """
|
""" Return the selected Plot document if exist. """
|
||||||
# Get active tab
|
# Get active tab
|
||||||
mdi = getMdiArea()
|
mdi = getMdiArea()
|
||||||
if not mdi:
|
if not mdi:
|
||||||
return None
|
return None
|
||||||
sub = mdi.activeSubWindow()
|
sub = mdi.activeSubWindow()
|
||||||
if not sub:
|
if not sub:
|
||||||
return None
|
return None
|
||||||
# Explore childrens looking for Plot class
|
# Explore childrens looking for Plot class
|
||||||
for i in sub.children():
|
for i in sub.children():
|
||||||
if i.metaObject().className() == "Plot":
|
if i.metaObject().className() == "Plot":
|
||||||
return i
|
return i
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def figure(winTitle="plot"):
|
def figure(winTitle="plot"):
|
||||||
""" figure(winTitle="plot"): Create a new plot subwindow.\n winTitle = Tab title. """
|
"""Create a new plot subwindow/tab.
|
||||||
mdi = getMdiArea()
|
|
||||||
if not mdi:
|
Keyword arguments:
|
||||||
return None
|
winTitle -- Plot tab title.
|
||||||
win = Plot(winTitle)
|
"""
|
||||||
sub=mdi.addSubWindow(win)
|
mdi = getMdiArea()
|
||||||
sub.show()
|
if not mdi:
|
||||||
return win
|
return None
|
||||||
|
win = Plot(winTitle)
|
||||||
|
sub = mdi.addSubWindow(win)
|
||||||
|
sub.show()
|
||||||
|
return win
|
||||||
|
|
||||||
|
|
||||||
|
def plot(x, y, name=None):
|
||||||
|
"""Plots a new serie (as line plot)
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
x -- X values
|
||||||
|
y -- Y values
|
||||||
|
name -- Data serie name (for legend).
|
||||||
|
"""
|
||||||
|
# Get active plot, or create another one if don't exist
|
||||||
|
plt = getPlot()
|
||||||
|
if not plt:
|
||||||
|
plt = figure()
|
||||||
|
# Call to plot
|
||||||
|
return plt.plot(x, y, name)
|
||||||
|
|
||||||
def plot(x,y,name=None):
|
|
||||||
""" plot(x,y,name=None): Plots a new serie (as line plot)\n x = X values\n y = Y values\n name = Serie name (for legend). """
|
|
||||||
# Get active plot, or create another one if don't exist
|
|
||||||
plt = getPlot()
|
|
||||||
if not plt:
|
|
||||||
plt = figure()
|
|
||||||
# Call to plot
|
|
||||||
return plt.plot(x,y,name)
|
|
||||||
|
|
||||||
def series():
|
def series():
|
||||||
""" lines(): Get all lines from selected plot. """
|
"""Return all the lines from a selected plot."""
|
||||||
plt = getPlot()
|
plt = getPlot()
|
||||||
if not plt:
|
if not plt:
|
||||||
return []
|
return []
|
||||||
return plt.series
|
return plt.series
|
||||||
|
|
||||||
|
|
||||||
def removeSerie(index):
|
def removeSerie(index):
|
||||||
""" removeSerie(index): Removes a serie from plot.\n index = Index of serie to remove. """
|
"""Remove a data serie from the active plot.
|
||||||
# Get active series
|
|
||||||
plt = getPlot()
|
Keyword arguments:
|
||||||
if not plt:
|
index -- Index of the serie to remove.
|
||||||
return
|
"""
|
||||||
plots = plt.series
|
# Get active series
|
||||||
if not plots:
|
plt = getPlot()
|
||||||
return
|
if not plt:
|
||||||
# Remove line from plot
|
return
|
||||||
axes = plots[index].axes
|
plots = plt.series
|
||||||
axes.lines.pop(plots[index].lid)
|
if not plots:
|
||||||
# Remove serie from list
|
return
|
||||||
del plt.series[index]
|
# Remove line from plot
|
||||||
# Update GUI
|
axes = plots[index].axes
|
||||||
plt.update()
|
axes.lines.pop(plots[index].lid)
|
||||||
|
# Remove serie from list
|
||||||
|
del plt.series[index]
|
||||||
|
# Update GUI
|
||||||
|
plt.update()
|
||||||
|
|
||||||
|
|
||||||
def legend(status=True, pos=None, fontsize=None):
|
def legend(status=True, pos=None, fontsize=None):
|
||||||
""" legend(status=True): Show/Hide legend.\n status = True if legend must be shown, False otherwise.\n pos = Legend position.\n fontsize = Font size """
|
"""Show/Hide the legend from the active plot.
|
||||||
plt = getPlot()
|
|
||||||
if not plt:
|
Keyword arguments:
|
||||||
return
|
status -- True if legend must be shown, False otherwise.
|
||||||
plt.legend = status
|
pos -- Legend position.
|
||||||
if fontsize:
|
fontsize -- Font size
|
||||||
plt.legSiz = fontsize
|
"""
|
||||||
# Hide all legends
|
plt = getPlot()
|
||||||
for axes in plt.axesList:
|
if not plt:
|
||||||
axes.legend_ = None
|
return
|
||||||
# Legend must be activated on last axes
|
plt.legend = status
|
||||||
axes = plt.axesList[-1]
|
if fontsize:
|
||||||
if status:
|
plt.legSiz = fontsize
|
||||||
# Setup legend handles and names
|
# Hide all legends
|
||||||
lines = series()
|
for axes in plt.axesList:
|
||||||
handles = []
|
axes.legend_ = None
|
||||||
names = []
|
# Legend must be activated on last axes
|
||||||
for l in lines:
|
axes = plt.axesList[-1]
|
||||||
if l.name != None:
|
if status:
|
||||||
handles.append(l.line)
|
# Setup legend handles and names
|
||||||
names.append(l.name)
|
lines = series()
|
||||||
# Show the legend (at selected position or at best)
|
handles = []
|
||||||
if pos:
|
names = []
|
||||||
l = axes.legend(handles, names, bbox_to_anchor=pos)
|
for l in lines:
|
||||||
plt.legPos = pos
|
if l.name is not None:
|
||||||
else:
|
handles.append(l.line)
|
||||||
l = axes.legend(handles, names, loc='best')
|
names.append(l.name)
|
||||||
# Update canvas in order to compute legend data
|
# Show the legend (at selected position or at best)
|
||||||
plt.canvas.draw()
|
if pos:
|
||||||
# Get resultant position
|
l = axes.legend(handles, names, bbox_to_anchor=pos)
|
||||||
fax = axes.get_frame().get_extents()
|
plt.legPos = pos
|
||||||
fl = l.get_frame()
|
else:
|
||||||
plt.legPos = ((fl._x+fl._width-fax.x0) / fax.width, (fl._y+fl._height-fax.y0) / fax.height)
|
l = axes.legend(handles, names, loc='best')
|
||||||
# Set fontsize
|
# Update canvas in order to compute legend data
|
||||||
for t in l.get_texts():
|
plt.canvas.draw()
|
||||||
t.set_fontsize(plt.legSiz)
|
# Get resultant position
|
||||||
plt.update()
|
fax = axes.get_frame().get_extents()
|
||||||
|
fl = l.get_frame()
|
||||||
|
plt.legPos = (
|
||||||
|
(fl._x + fl._width - fax.x0) / fax.width,
|
||||||
|
(fl._y + fl._height - fax.y0) / fax.height)
|
||||||
|
# Set fontsize
|
||||||
|
for t in l.get_texts():
|
||||||
|
t.set_fontsize(plt.legSiz)
|
||||||
|
plt.update()
|
||||||
|
|
||||||
|
|
||||||
def grid(status=True):
|
def grid(status=True):
|
||||||
""" grid(status=True): Show/Hide grid.\n status = True if grid must be shown, False otherwise. """
|
"""Show/Hide the grid from the active plot.
|
||||||
plt = getPlot()
|
|
||||||
if not plt:
|
Keyword arguments:
|
||||||
return
|
status -- True if grid must be shown, False otherwise.
|
||||||
plt.grid = status
|
"""
|
||||||
axes = plt.axes
|
plt = getPlot()
|
||||||
axes.grid(status)
|
if not plt:
|
||||||
plt.update()
|
return
|
||||||
|
plt.grid = status
|
||||||
|
axes = plt.axes
|
||||||
|
axes.grid(status)
|
||||||
|
plt.update()
|
||||||
|
|
||||||
|
|
||||||
def title(string):
|
def title(string):
|
||||||
""" title(string): Setup plot title.\n string = Title to set. """
|
"""Setup the plot title.
|
||||||
plt = getPlot()
|
|
||||||
if not plt:
|
Keyword arguments:
|
||||||
return
|
string -- Plot title.
|
||||||
axes = plt.axes
|
"""
|
||||||
axes.set_title(string)
|
plt = getPlot()
|
||||||
plt.update()
|
if not plt:
|
||||||
|
return
|
||||||
|
axes = plt.axes
|
||||||
|
axes.set_title(string)
|
||||||
|
plt.update()
|
||||||
|
|
||||||
|
|
||||||
def xlabel(string):
|
def xlabel(string):
|
||||||
""" xlabel(string): Setup x label.\n string = Title to set. """
|
"""Setup the x label.
|
||||||
plt = getPlot()
|
|
||||||
if not plt:
|
Keyword arguments:
|
||||||
return
|
string -- Title to set.
|
||||||
axes = plt.axes
|
"""
|
||||||
axes.set_xlabel(string)
|
plt = getPlot()
|
||||||
plt.update()
|
if not plt:
|
||||||
|
return
|
||||||
|
axes = plt.axes
|
||||||
|
axes.set_xlabel(string)
|
||||||
|
plt.update()
|
||||||
|
|
||||||
|
|
||||||
def ylabel(string):
|
def ylabel(string):
|
||||||
""" ylabel(string): Setup y label.\n string = Title to set. """
|
"""Setup the y label.
|
||||||
plt = getPlot()
|
|
||||||
if not plt:
|
Keyword arguments:
|
||||||
return
|
string -- Title to set.
|
||||||
axes = plt.axes
|
"""
|
||||||
axes.set_ylabel(string)
|
plt = getPlot()
|
||||||
plt.update()
|
if not plt:
|
||||||
|
return
|
||||||
|
axes = plt.axes
|
||||||
|
axes.set_ylabel(string)
|
||||||
|
plt.update()
|
||||||
|
|
||||||
|
|
||||||
def axesList():
|
def axesList():
|
||||||
""" axesList(): Gets plot axes list. """
|
"""Return the plot axes sets list. """
|
||||||
plt = getPlot()
|
plt = getPlot()
|
||||||
if not plt:
|
if not plt:
|
||||||
return []
|
return []
|
||||||
return plt.axesList
|
return plt.axesList
|
||||||
|
|
||||||
|
|
||||||
def axes():
|
def axes():
|
||||||
""" axes(): Gets active plot axes. """
|
"""Return the active plot axes."""
|
||||||
plt = getPlot()
|
plt = getPlot()
|
||||||
if not plt:
|
if not plt:
|
||||||
return None
|
return None
|
||||||
return plt.axes
|
return plt.axes
|
||||||
|
|
||||||
|
|
||||||
def addNewAxes(rect=None, frameon=True, patchcolor='none'):
|
def addNewAxes(rect=None, frameon=True, patchcolor='none'):
|
||||||
""" addNewAxes(pos=None, frameon=True): Add new axes to plot, setting it as active one.\n rect = Axes area, None to copy last axes data.\n frameon = True to show frame, False otherwise.\n patchcolor = Patch color, 'none' for transparent plot. """
|
"""Add new axes to plot, setting it as the active one.
|
||||||
plt = getPlot()
|
|
||||||
if not plt:
|
Keyword arguments:
|
||||||
return None
|
rect -- Axes area, None to copy from the last axes data.
|
||||||
fig = plt.fig
|
frameon -- True to show frame, False otherwise.
|
||||||
if rect == None:
|
patchcolor -- Patch color, 'none' for transparent plot.
|
||||||
rect = plt.axes.get_position()
|
"""
|
||||||
ax = fig.add_axes(rect, frameon=frameon)
|
plt = getPlot()
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
if not plt:
|
||||||
ax.spines['top'].set_color('none')
|
return None
|
||||||
ax.yaxis.set_ticks_position('left')
|
fig = plt.fig
|
||||||
ax.spines['right'].set_color('none')
|
if rect is None:
|
||||||
ax.patch.set_facecolor(patchcolor)
|
rect = plt.axes.get_position()
|
||||||
plt.axesList.append(ax)
|
ax = fig.add_axes(rect, frameon=frameon)
|
||||||
plt.setActiveAxes(-1)
|
ax.xaxis.set_ticks_position('bottom')
|
||||||
plt.update()
|
ax.spines['top'].set_color('none')
|
||||||
return ax
|
ax.yaxis.set_ticks_position('left')
|
||||||
|
ax.spines['right'].set_color('none')
|
||||||
|
ax.patch.set_facecolor(patchcolor)
|
||||||
|
plt.axesList.append(ax)
|
||||||
|
plt.setActiveAxes(-1)
|
||||||
|
plt.update()
|
||||||
|
return ax
|
||||||
|
|
||||||
|
|
||||||
def save(path, figsize=None, dpi=None):
|
def save(path, figsize=None, dpi=None):
|
||||||
""" save(path): Save plot.\n path = Destination file path.\n figsize = w,h figure size tuple in inches.\n dpi = Dots per inch."""
|
"""Save plot.
|
||||||
plt = getPlot()
|
|
||||||
if not plt:
|
Keyword arguments:
|
||||||
return
|
path -- Destination file path.
|
||||||
# Backup figure options
|
figsize -- w,h figure size tuple in inches.
|
||||||
fig = plt.fig
|
dpi -- Dots per inch.
|
||||||
sizeBack = fig.get_size_inches()
|
"""
|
||||||
dpiBack = fig.get_dpi()
|
plt = getPlot()
|
||||||
# Save figure with new options
|
if not plt:
|
||||||
if figsize:
|
return
|
||||||
fig.set_size_inches(figsize[0], figsize[1])
|
# Backup figure options
|
||||||
if dpi:
|
fig = plt.fig
|
||||||
fig.set_dpi(dpi)
|
sizeBack = fig.get_size_inches()
|
||||||
plt.canvas.print_figure(path)
|
dpiBack = fig.get_dpi()
|
||||||
# Restore figure options
|
# Save figure with new options
|
||||||
fig.set_size_inches(sizeBack[0], sizeBack[1])
|
if figsize:
|
||||||
fig.set_dpi(dpiBack)
|
fig.set_size_inches(figsize[0], figsize[1])
|
||||||
plt.update()
|
if dpi:
|
||||||
|
fig.set_dpi(dpi)
|
||||||
|
plt.canvas.print_figure(path)
|
||||||
|
# Restore figure options
|
||||||
|
fig.set_size_inches(sizeBack[0], sizeBack[1])
|
||||||
|
fig.set_dpi(dpiBack)
|
||||||
|
plt.update()
|
||||||
|
|
||||||
|
|
||||||
class Line():
|
class Line():
|
||||||
def __init__(self, axes, x, y, name):
|
def __init__(self, axes, x, y, name):
|
||||||
""" __init__(axes, x, y, name): Construct new plot serie.\n axes = Active axes\n x = X values\n y = Y values\n name = Serie name (for legend). """
|
"""Construct a new plot serie.
|
||||||
self.axes = axes
|
|
||||||
self.x = x
|
|
||||||
self.y = y
|
|
||||||
self.name = name
|
|
||||||
self.lid = len(axes.lines)
|
|
||||||
self.line, = axes.plot(x,y)
|
|
||||||
|
|
||||||
def setp(self, prop, value):
|
Keyword arguments:
|
||||||
""" setp(prop, value): Change line property value.\n prop = Property name.\n value = New property value. """
|
axes -- Active axes
|
||||||
plt.setp(self.line, prop, value)
|
x -- X values
|
||||||
|
y -- Y values
|
||||||
|
name -- Data serie name (for legend).
|
||||||
|
"""
|
||||||
|
self.axes = axes
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
self.name = name
|
||||||
|
self.lid = len(axes.lines)
|
||||||
|
self.line, = axes.plot(x, y)
|
||||||
|
|
||||||
|
def setp(self, prop, value):
|
||||||
|
"""Change a line property value.
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
prop -- Property name.
|
||||||
|
value -- New property value.
|
||||||
|
"""
|
||||||
|
plt.setp(self.line, prop, value)
|
||||||
|
|
||||||
|
def getp(self, prop):
|
||||||
|
"""Get line property value.
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
prop -- Property name.
|
||||||
|
"""
|
||||||
|
return plt.getp(self.line, prop)
|
||||||
|
|
||||||
def getp(self, prop):
|
|
||||||
""" getp(prop): Get property value.\n prop = Property name."""
|
|
||||||
return plt.getp(self.line, prop)
|
|
||||||
|
|
||||||
class Plot(QtGui.QWidget):
|
class Plot(QtGui.QWidget):
|
||||||
def __init__(self, winTitle="plot", parent = None, flags = QtCore.Qt.WindowFlags(0)):
|
def __init__(self,
|
||||||
""" __init__(winTitle="plot", parent = None, flags = Qt.WindowFlags(0)): Construct a new plot widget.\n winTitle = Tab title.\n parent = Widget parent.\n flags = QWidget flags"""
|
winTitle="plot",
|
||||||
QtGui.QWidget.__init__(self, parent, flags)
|
parent=None,
|
||||||
self.setWindowTitle(winTitle)
|
flags=QtCore.Qt.WindowFlags(0)):
|
||||||
# Create matplotlib canvas
|
"""Construct a new plot widget.
|
||||||
self.fig = Figure()
|
|
||||||
self.canvas = FigureCanvas(self.fig)
|
|
||||||
self.canvas.setParent(self)
|
|
||||||
# Get axes
|
|
||||||
self.axes = self.fig.add_subplot(111)
|
|
||||||
self.axesList = [self.axes]
|
|
||||||
self.axes.xaxis.set_ticks_position('bottom')
|
|
||||||
self.axes.spines['top'].set_color('none')
|
|
||||||
self.axes.yaxis.set_ticks_position('left')
|
|
||||||
self.axes.spines['right'].set_color('none')
|
|
||||||
# Setup layout
|
|
||||||
vbox = QtGui.QVBoxLayout()
|
|
||||||
vbox.addWidget(self.canvas)
|
|
||||||
self.setLayout(vbox)
|
|
||||||
# Active series
|
|
||||||
self.series = []
|
|
||||||
# Indicators
|
|
||||||
self.skip = False
|
|
||||||
self.legend = False
|
|
||||||
self.legPos = (1.0,1.0)
|
|
||||||
self.legSiz = 14
|
|
||||||
self.grid = False
|
|
||||||
|
|
||||||
def plot(self, x, y, name=None):
|
Keyword arguments:
|
||||||
""" plot(self, x, y, name=None): Plot a new line and return it.\n x = X values\n y = Y values\n name = Serie name (for legend). """
|
winTitle -- Tab title.
|
||||||
l = Line(self.axes, x, y, name)
|
parent -- Widget parent.
|
||||||
self.series.append(l)
|
flags -- QWidget flags
|
||||||
# Update window
|
"""
|
||||||
self.update()
|
QtGui.QWidget.__init__(self, parent, flags)
|
||||||
return l
|
self.setWindowTitle(winTitle)
|
||||||
|
# Create matplotlib canvas
|
||||||
|
self.fig = Figure()
|
||||||
|
self.canvas = FigureCanvas(self.fig)
|
||||||
|
self.canvas.setParent(self)
|
||||||
|
# Get axes
|
||||||
|
self.axes = self.fig.add_subplot(111)
|
||||||
|
self.axesList = [self.axes]
|
||||||
|
self.axes.xaxis.set_ticks_position('bottom')
|
||||||
|
self.axes.spines['top'].set_color('none')
|
||||||
|
self.axes.yaxis.set_ticks_position('left')
|
||||||
|
self.axes.spines['right'].set_color('none')
|
||||||
|
# Setup layout
|
||||||
|
vbox = QtGui.QVBoxLayout()
|
||||||
|
vbox.addWidget(self.canvas)
|
||||||
|
self.setLayout(vbox)
|
||||||
|
# Active series
|
||||||
|
self.series = []
|
||||||
|
# Indicators
|
||||||
|
self.skip = False
|
||||||
|
self.legend = False
|
||||||
|
self.legPos = (1.0, 1.0)
|
||||||
|
self.legSiz = 14
|
||||||
|
self.grid = False
|
||||||
|
|
||||||
def update(self):
|
def plot(self, x, y, name=None):
|
||||||
""" update(): Updates plot. """
|
"""Plot a new line and return it.
|
||||||
if not self.skip:
|
|
||||||
self.skip = True
|
|
||||||
if self.legend:
|
|
||||||
legend(self.legend, self.legPos, self.legSiz)
|
|
||||||
self.canvas.draw()
|
|
||||||
self.skip = False
|
|
||||||
|
|
||||||
def isGrid(self):
|
Keyword arguments:
|
||||||
""" isGrid(): Return True if Grid is active, False otherwise. """
|
x -- X values
|
||||||
return bool(self.grid)
|
y -- Y values
|
||||||
|
name -- Serie name (for legend). """
|
||||||
|
l = Line(self.axes, x, y, name)
|
||||||
|
self.series.append(l)
|
||||||
|
# Update window
|
||||||
|
self.update()
|
||||||
|
return l
|
||||||
|
|
||||||
def isLegend(self):
|
def update(self):
|
||||||
""" isLegend(): Return True if Legend is active, False otherwise. """
|
"""Update the plot, redrawing the canvas."""
|
||||||
return bool(self.legend)
|
if not self.skip:
|
||||||
|
self.skip = True
|
||||||
|
if self.legend:
|
||||||
|
legend(self.legend, self.legPos, self.legSiz)
|
||||||
|
self.canvas.draw()
|
||||||
|
self.skip = False
|
||||||
|
|
||||||
def setActiveAxes(self, index):
|
def isGrid(self):
|
||||||
""" setActiveAxes(index): Change current active axes.\n index = Index of the new active axes. """
|
"""Return True if Grid is active, False otherwise."""
|
||||||
self.axes = self.axesList[index]
|
return bool(self.grid)
|
||||||
self.fig.sca(self.axes)
|
|
||||||
|
|
||||||
|
def isLegend(self):
|
||||||
|
"""Return True if Legend is active, False otherwise."""
|
||||||
|
return bool(self.legend)
|
||||||
|
|
||||||
|
def setActiveAxes(self, index):
|
||||||
|
"""Change the current active axes.
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
index -- Index of the new active axes set.
|
||||||
|
"""
|
||||||
|
self.axes = self.axesList[index]
|
||||||
|
self.fig.sca(self.axes)
|
||||||
|
|
|
@ -21,126 +21,163 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
import PySide
|
||||||
import FreeCAD, FreeCADGui, os
|
from PySide import QtCore, QtGui
|
||||||
|
import FreeCAD
|
||||||
|
import FreeCADGui
|
||||||
|
import os
|
||||||
|
|
||||||
# Load resources
|
|
||||||
import Plot_rc
|
import Plot_rc
|
||||||
|
|
||||||
|
|
||||||
FreeCADGui.addLanguagePath(":/Plot/translations")
|
FreeCADGui.addLanguagePath(":/Plot/translations")
|
||||||
FreeCADGui.addIconPath(":/Plot/icons")
|
FreeCADGui.addIconPath(":/Plot/icons")
|
||||||
|
|
||||||
"""
|
|
||||||
# Setup tranlations
|
|
||||||
from plotUtils import Paths
|
|
||||||
path = Paths.translationsPath()
|
|
||||||
FreeCADGui.addLanguagePath(path)
|
|
||||||
import os
|
|
||||||
import FreeCAD
|
|
||||||
translator = QtCore.QTranslator()
|
|
||||||
dirList=os.listdir(path)
|
|
||||||
for fname in dirList:
|
|
||||||
valid = translator.load(os.path.join(path, fname))
|
|
||||||
if valid:
|
|
||||||
QtGui.QApplication.installTranslator(translator)
|
|
||||||
"""
|
|
||||||
|
|
||||||
class Save:
|
class Save:
|
||||||
def Activated(self):
|
def Activated(self):
|
||||||
import plotSave
|
import plotSave
|
||||||
plotSave.load()
|
plotSave.load()
|
||||||
|
|
||||||
|
def GetResources(self):
|
||||||
|
# from plotUtils import Paths
|
||||||
|
# IconPath = Paths.iconsPath() + "/Save.svg"
|
||||||
|
MenuText = QtCore.QT_TRANSLATE_NOOP(
|
||||||
|
"Plot_SaveFig",
|
||||||
|
"Save plot")
|
||||||
|
ToolTip = QtCore.QT_TRANSLATE_NOOP(
|
||||||
|
"Plot_SaveFig",
|
||||||
|
"Save the plot as an image file")
|
||||||
|
return {'Pixmap': 'Save',
|
||||||
|
'MenuText': MenuText,
|
||||||
|
'ToolTip': ToolTip}
|
||||||
|
|
||||||
def GetResources(self):
|
|
||||||
# from plotUtils import Paths
|
|
||||||
# IconPath = Paths.iconsPath() + "/Save.svg"
|
|
||||||
MenuText = QtCore.QT_TRANSLATE_NOOP("Plot_SaveFig", "Save plot")
|
|
||||||
ToolTip = QtCore.QT_TRANSLATE_NOOP("Plot_SaveFig", "Save plot as image file")
|
|
||||||
return {'Pixmap' : 'Save', 'MenuText': MenuText, 'ToolTip': ToolTip}
|
|
||||||
|
|
||||||
class Axes:
|
class Axes:
|
||||||
def Activated(self):
|
def Activated(self):
|
||||||
import plotAxes
|
import plotAxes
|
||||||
plotAxes.load()
|
plotAxes.load()
|
||||||
|
|
||||||
|
def GetResources(self):
|
||||||
|
MenuText = QtCore.QT_TRANSLATE_NOOP(
|
||||||
|
"Plot_Axes",
|
||||||
|
"Configure axes")
|
||||||
|
ToolTip = QtCore.QT_TRANSLATE_NOOP(
|
||||||
|
"Plot_Axes",
|
||||||
|
"Configure the axes parameters")
|
||||||
|
return {'Pixmap': 'Axes',
|
||||||
|
'MenuText': MenuText,
|
||||||
|
'ToolTip': ToolTip}
|
||||||
|
|
||||||
def GetResources(self):
|
|
||||||
# from plotUtils import Paths
|
|
||||||
# IconPath = Paths.iconsPath() + "/Axes.svg"
|
|
||||||
MenuText = QtCore.QT_TRANSLATE_NOOP("Plot_Axes", "Configure axes")
|
|
||||||
ToolTip = QtCore.QT_TRANSLATE_NOOP("Plot_Axes", "Configure axes parameters")
|
|
||||||
return {'Pixmap' : 'Axes', 'MenuText': MenuText, 'ToolTip': ToolTip}
|
|
||||||
|
|
||||||
class Series:
|
class Series:
|
||||||
def Activated(self):
|
def Activated(self):
|
||||||
import plotSeries
|
import plotSeries
|
||||||
plotSeries.load()
|
plotSeries.load()
|
||||||
|
|
||||||
|
def GetResources(self):
|
||||||
|
# from plotUtils import Paths
|
||||||
|
# IconPath = Paths.iconsPath() + "/Series.svg"
|
||||||
|
MenuText = QtCore.QT_TRANSLATE_NOOP(
|
||||||
|
"Plot_Series",
|
||||||
|
"Configure series")
|
||||||
|
ToolTip = QtCore.QT_TRANSLATE_NOOP(
|
||||||
|
"Plot_Series",
|
||||||
|
"Configure series drawing style and label")
|
||||||
|
return {'Pixmap': 'Series',
|
||||||
|
'MenuText': MenuText,
|
||||||
|
'ToolTip': ToolTip}
|
||||||
|
|
||||||
def GetResources(self):
|
|
||||||
# from plotUtils import Paths
|
|
||||||
# IconPath = Paths.iconsPath() + "/Series.svg"
|
|
||||||
MenuText = QtCore.QT_TRANSLATE_NOOP("Plot_Series", "Configure series")
|
|
||||||
ToolTip = QtCore.QT_TRANSLATE_NOOP("Plot_Series", "Configure series drawing style and label")
|
|
||||||
return {'Pixmap' : 'Series', 'MenuText': MenuText, 'ToolTip': ToolTip}
|
|
||||||
|
|
||||||
class Grid:
|
class Grid:
|
||||||
def Activated(self):
|
def Activated(self):
|
||||||
import Plot
|
import Plot
|
||||||
plt = Plot.getPlot()
|
plt = Plot.getPlot()
|
||||||
if not plt:
|
if not plt:
|
||||||
msg = QtGui.QApplication.translate("plot_console", "Grid must be activated on top of a plot document",
|
msg = QtGui.QApplication.translate(
|
||||||
None,QtGui.QApplication.UnicodeUTF8)
|
"plot_console",
|
||||||
FreeCAD.Console.PrintError(msg+"\n")
|
"The grid must be activated on top of a plot document",
|
||||||
return
|
None,
|
||||||
flag = plt.isGrid()
|
QtGui.QApplication.UnicodeUTF8)
|
||||||
Plot.grid(not flag)
|
FreeCAD.Console.PrintError(msg + "\n")
|
||||||
|
return
|
||||||
|
flag = plt.isGrid()
|
||||||
|
Plot.grid(not flag)
|
||||||
|
|
||||||
|
def GetResources(self):
|
||||||
|
# from plotUtils import Paths
|
||||||
|
# IconPath = Paths.iconsPath() + "/Grid.svg"
|
||||||
|
MenuText = QtCore.QT_TRANSLATE_NOOP(
|
||||||
|
"Plot_Grid",
|
||||||
|
"Show/Hide grid")
|
||||||
|
ToolTip = QtCore.QT_TRANSLATE_NOOP(
|
||||||
|
"Plot_Grid",
|
||||||
|
"Show/Hide grid on selected plot")
|
||||||
|
return {'Pixmap': 'Grid',
|
||||||
|
'MenuText': MenuText,
|
||||||
|
'ToolTip': ToolTip}
|
||||||
|
|
||||||
def GetResources(self):
|
|
||||||
# from plotUtils import Paths
|
|
||||||
# IconPath = Paths.iconsPath() + "/Grid.svg"
|
|
||||||
MenuText = QtCore.QT_TRANSLATE_NOOP("Plot_Grid", "Show/Hide grid")
|
|
||||||
ToolTip = QtCore.QT_TRANSLATE_NOOP("Plot_Grid", "Show/Hide grid on selected plot")
|
|
||||||
return {'Pixmap' : 'Grid', 'MenuText': MenuText, 'ToolTip': ToolTip}
|
|
||||||
|
|
||||||
class Legend:
|
class Legend:
|
||||||
def Activated(self):
|
def Activated(self):
|
||||||
import Plot
|
import Plot
|
||||||
plt = Plot.getPlot()
|
plt = Plot.getPlot()
|
||||||
if not plt:
|
if not plt:
|
||||||
msg = QtGui.QApplication.translate("plot_console", "Legend must be activated on top of a plot document",
|
msg = QtGui.QApplication.translate(
|
||||||
None,QtGui.QApplication.UnicodeUTF8)
|
"plot_console",
|
||||||
FreeCAD.Console.PrintError(msg+"\n")
|
"The legend must be activated on top of a plot document",
|
||||||
return
|
None,
|
||||||
flag = plt.isLegend()
|
QtGui.QApplication.UnicodeUTF8)
|
||||||
Plot.legend(not flag)
|
FreeCAD.Console.PrintError(msg + "\n")
|
||||||
|
return
|
||||||
|
flag = plt.isLegend()
|
||||||
|
Plot.legend(not flag)
|
||||||
|
|
||||||
|
def GetResources(self):
|
||||||
|
MenuText = QtCore.QT_TRANSLATE_NOOP(
|
||||||
|
"Plot_Legend",
|
||||||
|
"Show/Hide legend")
|
||||||
|
ToolTip = QtCore.QT_TRANSLATE_NOOP(
|
||||||
|
"Plot_Legend",
|
||||||
|
"Show/Hide legend on selected plot")
|
||||||
|
return {'Pixmap': 'Legend',
|
||||||
|
'MenuText': MenuText,
|
||||||
|
'ToolTip': ToolTip}
|
||||||
|
|
||||||
def GetResources(self):
|
|
||||||
# from plotUtils import Paths
|
|
||||||
# IconPath = Paths.iconsPath() + "/Legend.svg"
|
|
||||||
MenuText = QtCore.QT_TRANSLATE_NOOP("Plot_Legend", "Show/Hide legend")
|
|
||||||
ToolTip = QtCore.QT_TRANSLATE_NOOP("Plot_Legend", "Show/Hide legend on selected plot")
|
|
||||||
return {'Pixmap' : 'Legend', 'MenuText': MenuText, 'ToolTip': ToolTip}
|
|
||||||
|
|
||||||
class Labels:
|
class Labels:
|
||||||
def Activated(self):
|
def Activated(self):
|
||||||
import plotLabels
|
import plotLabels
|
||||||
plotLabels.load()
|
plotLabels.load()
|
||||||
|
|
||||||
|
def GetResources(self):
|
||||||
|
MenuText = QtCore.QT_TRANSLATE_NOOP(
|
||||||
|
"Plot_Labels",
|
||||||
|
"Set labels")
|
||||||
|
ToolTip = QtCore.QT_TRANSLATE_NOOP(
|
||||||
|
"Plot_Labels",
|
||||||
|
"Set title and axes labels")
|
||||||
|
return {'Pixmap': 'Labels',
|
||||||
|
'MenuText': MenuText,
|
||||||
|
'ToolTip': ToolTip}
|
||||||
|
|
||||||
def GetResources(self):
|
|
||||||
# from plotUtils import Paths
|
|
||||||
# IconPath = Paths.iconsPath() + "/Labels.svg"
|
|
||||||
MenuText = QtCore.QT_TRANSLATE_NOOP("Plot_Labels", "Set labels")
|
|
||||||
ToolTip = QtCore.QT_TRANSLATE_NOOP("Plot_Labels", "Set title and axes labels")
|
|
||||||
return {'Pixmap' : 'Labels', 'MenuText': MenuText, 'ToolTip': ToolTip}
|
|
||||||
|
|
||||||
class Positions:
|
class Positions:
|
||||||
def Activated(self):
|
def Activated(self):
|
||||||
import plotPositions
|
import plotPositions
|
||||||
plotPositions.load()
|
plotPositions.load()
|
||||||
|
|
||||||
|
def GetResources(self):
|
||||||
|
MenuText = QtCore.QT_TRANSLATE_NOOP(
|
||||||
|
"Plot_Positions",
|
||||||
|
"Set positions and sizes")
|
||||||
|
ToolTip = QtCore.QT_TRANSLATE_NOOP(
|
||||||
|
"Plot_Positions",
|
||||||
|
"Set labels and legend positions and sizes")
|
||||||
|
return {'Pixmap': 'Positions',
|
||||||
|
'MenuText': MenuText,
|
||||||
|
'ToolTip': ToolTip}
|
||||||
|
|
||||||
def GetResources(self):
|
|
||||||
# from plotUtils import Paths
|
|
||||||
# IconPath = Paths.iconsPath() + "/Positions.svg"
|
|
||||||
MenuText = QtCore.QT_TRANSLATE_NOOP("Plot_Positions", "Set positions and sizes")
|
|
||||||
ToolTip = QtCore.QT_TRANSLATE_NOOP("Plot_Positions", "Set labels and legend positions and sizes")
|
|
||||||
return {'Pixmap' : 'Positions', 'MenuText': MenuText, 'ToolTip': ToolTip}
|
|
||||||
|
|
||||||
FreeCADGui.addCommand('Plot_SaveFig', Save())
|
FreeCADGui.addCommand('Plot_SaveFig', Save())
|
||||||
FreeCADGui.addCommand('Plot_Axes', Axes())
|
FreeCADGui.addCommand('Plot_Axes', Axes())
|
||||||
|
@ -149,4 +186,3 @@ FreeCADGui.addCommand('Plot_Grid', Grid())
|
||||||
FreeCADGui.addCommand('Plot_Legend', Legend())
|
FreeCADGui.addCommand('Plot_Legend', Legend())
|
||||||
FreeCADGui.addCommand('Plot_Labels', Labels())
|
FreeCADGui.addCommand('Plot_Labels', Labels())
|
||||||
FreeCADGui.addCommand('Plot_Positions', Positions())
|
FreeCADGui.addCommand('Plot_Positions', Positions())
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# WARNING! All changes made in this file will be lost!
|
# WARNING! All changes made in this file will be lost!
|
||||||
|
|
||||||
from PyQt4 import QtCore
|
from PySide import QtCore
|
||||||
|
|
||||||
qt_resource_data = "\
|
qt_resource_data = "\
|
||||||
\x00\x00\x00\x10\
|
\x00\x00\x00\x10\
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -21,16 +21,9 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
# FreeCAD modules
|
|
||||||
import FreeCAD
|
|
||||||
import FreeCADGui
|
|
||||||
|
|
||||||
# Qt libraries
|
|
||||||
from PyQt4 import QtGui,QtCore
|
|
||||||
|
|
||||||
# Main object
|
|
||||||
import TaskPanel
|
import TaskPanel
|
||||||
|
|
||||||
|
|
||||||
def load():
|
def load():
|
||||||
""" Loads the tool """
|
"""Load the tool"""
|
||||||
TaskPanel.createTask()
|
TaskPanel.createTask()
|
||||||
|
|
|
@ -1,225 +1,322 @@
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
#* *
|
#* *
|
||||||
#* Copyright (c) 2011, 2012 *
|
#* Copyright (c) 2011, 2012 *
|
||||||
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||||
#* *
|
#* *
|
||||||
#* This program is free software; you can redistribute it and/or modify *
|
#* This program is free software; you can redistribute it and/or modify *
|
||||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||||
#* as published by the Free Software Foundation; either version 2 of *
|
#* as published by the Free Software Foundation; either version 2 of *
|
||||||
#* the License, or (at your option) any later version. *
|
#* the License, or (at your option) any later version. *
|
||||||
#* for detail see the LICENCE text file. *
|
#* for detail see the LICENCE text file. *
|
||||||
#* *
|
#* *
|
||||||
#* This program is distributed in the hope that it will be useful, *
|
#* This program is distributed in the hope that it will be useful, *
|
||||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
#* GNU Library General Public License for more details. *
|
#* GNU Library General Public License for more details. *
|
||||||
#* *
|
#* *
|
||||||
#* You should have received a copy of the GNU Library General Public *
|
#* You should have received a copy of the GNU Library General Public *
|
||||||
#* License along with this program; if not, write to the Free Software *
|
#* License along with this program; if not, write to the Free Software *
|
||||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||||
#* USA *
|
#* USA *
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
# FreeCAD modules
|
|
||||||
import FreeCAD as App
|
import FreeCAD as App
|
||||||
import FreeCADGui as Gui
|
import FreeCADGui as Gui
|
||||||
# Qt library
|
|
||||||
from PyQt4 import QtGui,QtCore
|
from PySide import QtGui, QtCore
|
||||||
# Module
|
|
||||||
import Plot
|
import Plot
|
||||||
from plotUtils import Paths
|
from plotUtils import Paths
|
||||||
|
|
||||||
|
|
||||||
class TaskPanel:
|
class TaskPanel:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ui = Paths.modulePath() + "/plotLabels/TaskPanel.ui"
|
self.ui = Paths.modulePath() + "/plotLabels/TaskPanel.ui"
|
||||||
self.skip = False
|
self.skip = False
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reject(self):
|
def reject(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def clicked(self, index):
|
def clicked(self, index):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def needsFullSpace(self):
|
def needsFullSpace(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def isAllowedAlterSelection(self):
|
def isAllowedAlterSelection(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def isAllowedAlterView(self):
|
def isAllowedAlterView(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def isAllowedAlterDocument(self):
|
def isAllowedAlterDocument(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def helpRequested(self):
|
def helpRequested(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def setupUi(self):
|
def setupUi(self):
|
||||||
mw = self.getMainWindow()
|
mw = self.getMainWindow()
|
||||||
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
form.axId = form.findChild(QtGui.QSpinBox, "axesIndex")
|
form.axId = self.widget(QtGui.QSpinBox, "axesIndex")
|
||||||
form.title = form.findChild(QtGui.QLineEdit, "title")
|
form.title = self.widget(QtGui.QLineEdit, "title")
|
||||||
form.titleSize = form.findChild(QtGui.QSpinBox, "titleSize")
|
form.titleSize = self.widget(QtGui.QSpinBox, "titleSize")
|
||||||
form.xLabel = form.findChild(QtGui.QLineEdit, "titleX")
|
form.xLabel = self.widget(QtGui.QLineEdit, "titleX")
|
||||||
form.xSize = form.findChild(QtGui.QSpinBox, "xSize")
|
form.xSize = self.widget(QtGui.QSpinBox, "xSize")
|
||||||
form.yLabel = form.findChild(QtGui.QLineEdit, "titleY")
|
form.yLabel = self.widget(QtGui.QLineEdit, "titleY")
|
||||||
form.ySize = form.findChild(QtGui.QSpinBox, "ySize")
|
form.ySize = self.widget(QtGui.QSpinBox, "ySize")
|
||||||
self.form = form
|
self.form = form
|
||||||
self.retranslateUi()
|
self.retranslateUi()
|
||||||
# Look for active axes if can
|
# Look for active axes if can
|
||||||
axId = 0
|
axId = 0
|
||||||
plt = Plot.getPlot()
|
plt = Plot.getPlot()
|
||||||
if plt:
|
if plt:
|
||||||
while plt.axes != plt.axesList[axId]:
|
while plt.axes != plt.axesList[axId]:
|
||||||
axId = axId + 1
|
axId = axId + 1
|
||||||
form.axId.setValue(axId)
|
form.axId.setValue(axId)
|
||||||
self.updateUI()
|
self.updateUI()
|
||||||
QtCore.QObject.connect(form.axId, QtCore.SIGNAL('valueChanged(int)'),self.onAxesId)
|
QtCore.QObject.connect(form.axId,
|
||||||
QtCore.QObject.connect(form.title, QtCore.SIGNAL("editingFinished()"),self.onLabels)
|
QtCore.SIGNAL('valueChanged(int)'),
|
||||||
QtCore.QObject.connect(form.xLabel, QtCore.SIGNAL("editingFinished()"),self.onLabels)
|
self.onAxesId)
|
||||||
QtCore.QObject.connect(form.yLabel, QtCore.SIGNAL("editingFinished()"),self.onLabels)
|
QtCore.QObject.connect(form.title,
|
||||||
QtCore.QObject.connect(form.titleSize,QtCore.SIGNAL("valueChanged(int)"),self.onFontSizes)
|
QtCore.SIGNAL("editingFinished()"),
|
||||||
QtCore.QObject.connect(form.xSize, QtCore.SIGNAL("valueChanged(int)"),self.onFontSizes)
|
self.onLabels)
|
||||||
QtCore.QObject.connect(form.ySize, QtCore.SIGNAL("valueChanged(int)"),self.onFontSizes)
|
QtCore.QObject.connect(form.xLabel,
|
||||||
QtCore.QObject.connect(Plot.getMdiArea(),QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"),self.onMdiArea)
|
QtCore.SIGNAL("editingFinished()"),
|
||||||
return False
|
self.onLabels)
|
||||||
|
QtCore.QObject.connect(form.yLabel,
|
||||||
|
QtCore.SIGNAL("editingFinished()"),
|
||||||
|
self.onLabels)
|
||||||
|
QtCore.QObject.connect(form.titleSize,
|
||||||
|
QtCore.SIGNAL("valueChanged(int)"),
|
||||||
|
self.onFontSizes)
|
||||||
|
QtCore.QObject.connect(form.xSize,
|
||||||
|
QtCore.SIGNAL("valueChanged(int)"),
|
||||||
|
self.onFontSizes)
|
||||||
|
QtCore.QObject.connect(form.ySize,
|
||||||
|
QtCore.SIGNAL("valueChanged(int)"),
|
||||||
|
self.onFontSizes)
|
||||||
|
QtCore.QObject.connect(
|
||||||
|
Plot.getMdiArea(),
|
||||||
|
QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"),
|
||||||
|
self.onMdiArea)
|
||||||
|
return False
|
||||||
|
|
||||||
def getMainWindow(self):
|
def getMainWindow(self):
|
||||||
"returns the main window"
|
toplevel = QtGui.qApp.topLevelWidgets()
|
||||||
# using QtGui.qApp.activeWindow() isn't very reliable because if another
|
for i in toplevel:
|
||||||
# widget than the mainwindow is active (e.g. a dialog) the wrong widget is
|
if i.metaObject().className() == "Gui::MainWindow":
|
||||||
# returned
|
return i
|
||||||
toplevel = QtGui.qApp.topLevelWidgets()
|
raise Exception("No main window found")
|
||||||
for i in toplevel:
|
|
||||||
if i.metaObject().className() == "Gui::MainWindow":
|
|
||||||
return i
|
|
||||||
raise Exception("No main window found")
|
|
||||||
|
|
||||||
def retranslateUi(self):
|
def widget(self, class_id, name):
|
||||||
""" Set user interface locale strings.
|
"""Return the selected widget.
|
||||||
"""
|
|
||||||
self.form.setWindowTitle(QtGui.QApplication.translate("plot_labels", "Set labels",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.findChild(QtGui.QLabel, "axesLabel").setText(QtGui.QApplication.translate("plot_labels", "Active axes",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.findChild(QtGui.QLabel, "titleLabel").setText(QtGui.QApplication.translate("plot_labels", "Title",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.findChild(QtGui.QLabel, "xLabel").setText(QtGui.QApplication.translate("plot_labels", "X label",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.findChild(QtGui.QLabel, "yLabel").setText(QtGui.QApplication.translate("plot_labels", "Y label",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.axId.setToolTip(QtGui.QApplication.translate("plot_labels", "Index of the active axes",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.title.setToolTip(QtGui.QApplication.translate("plot_labels", "Title (associated to active axes)",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.titleSize.setToolTip(QtGui.QApplication.translate("plot_labels", "Title font size",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.xLabel.setToolTip(QtGui.QApplication.translate("plot_labels", "X axis title",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.xSize.setToolTip(QtGui.QApplication.translate("plot_labels", "X axis title font size",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.yLabel.setToolTip(QtGui.QApplication.translate("plot_labels", "Y axis title",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.ySize.setToolTip(QtGui.QApplication.translate("plot_labels", "Y axis title font size",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
|
|
||||||
def onAxesId(self, value):
|
Keyword arguments:
|
||||||
""" Executed when axes index is modified. """
|
class_id -- Class identifier
|
||||||
if not self.skip:
|
name -- Name of the widget
|
||||||
self.skip = True
|
"""
|
||||||
# UI control in some special plot cases
|
mw = self.getMainWindow()
|
||||||
plt = Plot.getPlot()
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
if not plt:
|
return form.findChild(class_id, name)
|
||||||
self.updateUI()
|
|
||||||
self.skip = False
|
|
||||||
return
|
|
||||||
# UI control in most cases
|
|
||||||
self.form.axId.setMaximum(len(plt.axesList))
|
|
||||||
if self.form.axId.value() >= len(plt.axesList):
|
|
||||||
self.form.axId.setValue(len(plt.axesList)-1)
|
|
||||||
# Send new control to Plot instance
|
|
||||||
plt.setActiveAxes(self.form.axId.value())
|
|
||||||
self.updateUI()
|
|
||||||
self.skip = False
|
|
||||||
|
|
||||||
def onLabels(self):
|
def retranslateUi(self):
|
||||||
""" Executed when labels have been modified. """
|
""" Set the user interface locale strings.
|
||||||
plt = Plot.getPlot()
|
"""
|
||||||
if not plt:
|
self.form.setWindowTitle(QtGui.QApplication.translate(
|
||||||
self.updateUI()
|
"plot_labels",
|
||||||
return
|
"Set labels",
|
||||||
# Set labels
|
None,
|
||||||
Plot.title(unicode(self.form.title.text()))
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
Plot.xlabel(unicode(self.form.xLabel.text()))
|
self.widget(QtGui.QLabel, "axesLabel").setText(
|
||||||
Plot.ylabel(unicode(self.form.yLabel.text()))
|
QtGui.QApplication.translate("plot_labels",
|
||||||
plt.update()
|
"Active axes",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QLabel, "titleLabel").setText(
|
||||||
|
QtGui.QApplication.translate("plot_labels",
|
||||||
|
"Title",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QLabel, "xLabel").setText(
|
||||||
|
QtGui.QApplication.translate("plot_labels",
|
||||||
|
"X label",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QLabel, "yLabel").setText(
|
||||||
|
QtGui.QApplication.translate("plot_labels",
|
||||||
|
"Y label",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QSpinBox, "axesIndex").setToolTip(QtGui.QApplication.translate(
|
||||||
|
"plot_labels",
|
||||||
|
"Index of the active axes",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QLineEdit, "title").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_labels",
|
||||||
|
"Title (associated to active axes)",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QSpinBox, "titleSize").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_labels",
|
||||||
|
"Title font size",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QLineEdit, "titleX").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_labels",
|
||||||
|
"X axis title",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QSpinBox, "xSize").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_labels",
|
||||||
|
"X axis title font size",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QLineEdit, "titleY").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_labels",
|
||||||
|
"Y axis title",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QSpinBox, "ySize").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_labels",
|
||||||
|
"Y axis title font size",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
|
||||||
def onFontSizes(self, value):
|
def onAxesId(self, value):
|
||||||
""" Executed when font sizes have been modified. """
|
""" Executed when axes index is modified. """
|
||||||
# Get apply environment
|
if not self.skip:
|
||||||
plt = Plot.getPlot()
|
self.skip = True
|
||||||
if not plt:
|
# No active plot case
|
||||||
self.updateUI()
|
plt = Plot.getPlot()
|
||||||
return
|
if not plt:
|
||||||
# Set font sizes
|
self.updateUI()
|
||||||
ax = plt.axes
|
self.skip = False
|
||||||
ax.title.set_fontsize(self.form.titleSize.value())
|
return
|
||||||
ax.xaxis.label.set_fontsize(self.form.xSize.value())
|
# Get again all the subwidgets (to avoid PySide Pitfalls)
|
||||||
ax.yaxis.label.set_fontsize(self.form.ySize.value())
|
mw = self.getMainWindow()
|
||||||
plt.update()
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
|
form.axId = self.widget(QtGui.QSpinBox, "axesIndex")
|
||||||
|
|
||||||
def onMdiArea(self, subWin):
|
form.axId.setMaximum(len(plt.axesList))
|
||||||
""" Executed when window is selected on mdi area.
|
if form.axId.value() >= len(plt.axesList):
|
||||||
@param subWin Selected window.
|
form.axId.setValue(len(plt.axesList) - 1)
|
||||||
"""
|
# Send new control to Plot instance
|
||||||
plt = Plot.getPlot()
|
plt.setActiveAxes(form.axId.value())
|
||||||
if plt != subWin:
|
self.updateUI()
|
||||||
self.updateUI()
|
self.skip = False
|
||||||
|
|
||||||
|
def onLabels(self):
|
||||||
|
""" Executed when labels have been modified. """
|
||||||
|
plt = Plot.getPlot()
|
||||||
|
if not plt:
|
||||||
|
self.updateUI()
|
||||||
|
return
|
||||||
|
# Get again all the subwidgets (to avoid PySide Pitfalls)
|
||||||
|
mw = self.getMainWindow()
|
||||||
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
|
form.title = self.widget(QtGui.QLineEdit, "title")
|
||||||
|
form.xLabel = self.widget(QtGui.QLineEdit, "titleX")
|
||||||
|
form.yLabel = self.widget(QtGui.QLineEdit, "titleY")
|
||||||
|
|
||||||
|
Plot.title(unicode(form.title.text()))
|
||||||
|
Plot.xlabel(unicode(form.xLabel.text()))
|
||||||
|
Plot.ylabel(unicode(form.yLabel.text()))
|
||||||
|
plt.update()
|
||||||
|
|
||||||
|
def onFontSizes(self, value):
|
||||||
|
""" Executed when font sizes have been modified. """
|
||||||
|
# Get apply environment
|
||||||
|
plt = Plot.getPlot()
|
||||||
|
if not plt:
|
||||||
|
self.updateUI()
|
||||||
|
return
|
||||||
|
# Get again all the subwidgets (to avoid PySide Pitfalls)
|
||||||
|
mw = self.getMainWindow()
|
||||||
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
|
form.titleSize = self.widget(QtGui.QSpinBox, "titleSize")
|
||||||
|
form.xSize = self.widget(QtGui.QSpinBox, "xSize")
|
||||||
|
form.ySize = self.widget(QtGui.QSpinBox, "ySize")
|
||||||
|
|
||||||
|
ax = plt.axes
|
||||||
|
ax.title.set_fontsize(form.titleSize.value())
|
||||||
|
ax.xaxis.label.set_fontsize(form.xSize.value())
|
||||||
|
ax.yaxis.label.set_fontsize(form.ySize.value())
|
||||||
|
plt.update()
|
||||||
|
|
||||||
|
def onMdiArea(self, subWin):
|
||||||
|
""" Executed when window is selected on mdi area.
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
subWin -- Selected window.
|
||||||
|
"""
|
||||||
|
plt = Plot.getPlot()
|
||||||
|
if plt != subWin:
|
||||||
|
self.updateUI()
|
||||||
|
|
||||||
|
def updateUI(self):
|
||||||
|
""" Setup UI controls values if possible """
|
||||||
|
# Get again all the subwidgets (to avoid PySide Pitfalls)
|
||||||
|
mw = self.getMainWindow()
|
||||||
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
|
form.axId = self.widget(QtGui.QSpinBox, "axesIndex")
|
||||||
|
form.title = self.widget(QtGui.QLineEdit, "title")
|
||||||
|
form.titleSize = self.widget(QtGui.QSpinBox, "titleSize")
|
||||||
|
form.xLabel = self.widget(QtGui.QLineEdit, "titleX")
|
||||||
|
form.xSize = self.widget(QtGui.QSpinBox, "xSize")
|
||||||
|
form.yLabel = self.widget(QtGui.QLineEdit, "titleY")
|
||||||
|
form.ySize = self.widget(QtGui.QSpinBox, "ySize")
|
||||||
|
|
||||||
|
plt = Plot.getPlot()
|
||||||
|
form.axId.setEnabled(bool(plt))
|
||||||
|
form.title.setEnabled(bool(plt))
|
||||||
|
form.titleSize.setEnabled(bool(plt))
|
||||||
|
form.xLabel.setEnabled(bool(plt))
|
||||||
|
form.xSize.setEnabled(bool(plt))
|
||||||
|
form.yLabel.setEnabled(bool(plt))
|
||||||
|
form.ySize.setEnabled(bool(plt))
|
||||||
|
if not plt:
|
||||||
|
return
|
||||||
|
# Ensure that active axes is correct
|
||||||
|
index = min(form.axId.value(), len(plt.axesList) - 1)
|
||||||
|
form.axId.setValue(index)
|
||||||
|
# Store data before starting changing it.
|
||||||
|
|
||||||
|
ax = plt.axes
|
||||||
|
t = ax.get_title()
|
||||||
|
x = ax.get_xlabel()
|
||||||
|
y = ax.get_ylabel()
|
||||||
|
tt = ax.title.get_fontsize()
|
||||||
|
xx = ax.xaxis.label.get_fontsize()
|
||||||
|
yy = ax.yaxis.label.get_fontsize()
|
||||||
|
# Set labels
|
||||||
|
form.title.setText(t)
|
||||||
|
form.xLabel.setText(x)
|
||||||
|
form.yLabel.setText(y)
|
||||||
|
# Set font sizes
|
||||||
|
form.titleSize.setValue(tt)
|
||||||
|
form.xSize.setValue(xx)
|
||||||
|
form.ySize.setValue(yy)
|
||||||
|
|
||||||
def updateUI(self):
|
|
||||||
""" Setup UI controls values if possible """
|
|
||||||
plt = Plot.getPlot()
|
|
||||||
self.form.axId.setEnabled(bool(plt))
|
|
||||||
self.form.title.setEnabled(bool(plt))
|
|
||||||
self.form.titleSize.setEnabled(bool(plt))
|
|
||||||
self.form.xLabel.setEnabled(bool(plt))
|
|
||||||
self.form.xSize.setEnabled(bool(plt))
|
|
||||||
self.form.yLabel.setEnabled(bool(plt))
|
|
||||||
self.form.ySize.setEnabled(bool(plt))
|
|
||||||
if not plt:
|
|
||||||
return
|
|
||||||
# Ensure that active axes is correct
|
|
||||||
index = min(self.form.axId.value(), len(plt.axesList)-1)
|
|
||||||
self.form.axId.setValue(index)
|
|
||||||
# Store data before starting changing it.
|
|
||||||
ax = plt.axes
|
|
||||||
t = ax.get_title()
|
|
||||||
x = ax.get_xlabel()
|
|
||||||
y = ax.get_ylabel()
|
|
||||||
tt = ax.title.get_fontsize()
|
|
||||||
xx = ax.xaxis.label.get_fontsize()
|
|
||||||
yy = ax.yaxis.label.get_fontsize()
|
|
||||||
# Set labels
|
|
||||||
self.form.title.setText(t)
|
|
||||||
self.form.xLabel.setText(x)
|
|
||||||
self.form.yLabel.setText(y)
|
|
||||||
# Set font sizes
|
|
||||||
self.form.titleSize.setValue(tt)
|
|
||||||
self.form.xSize.setValue(xx)
|
|
||||||
self.form.ySize.setValue(yy)
|
|
||||||
|
|
||||||
def createTask():
|
def createTask():
|
||||||
panel = TaskPanel()
|
panel = TaskPanel()
|
||||||
Gui.Control.showDialog(panel)
|
Gui.Control.showDialog(panel)
|
||||||
if panel.setupUi():
|
if panel.setupUi():
|
||||||
Gui.Control.closeDialog(panel)
|
Gui.Control.closeDialog(panel)
|
||||||
return None
|
return None
|
||||||
return panel
|
return panel
|
||||||
|
|
|
@ -21,16 +21,9 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
# FreeCAD modules
|
|
||||||
import FreeCAD
|
|
||||||
import FreeCADGui
|
|
||||||
|
|
||||||
# Qt libraries
|
|
||||||
from PyQt4 import QtGui,QtCore
|
|
||||||
|
|
||||||
# Main object
|
|
||||||
import TaskPanel
|
import TaskPanel
|
||||||
|
|
||||||
|
|
||||||
def load():
|
def load():
|
||||||
""" Loads the tool """
|
"""Load the tool"""
|
||||||
TaskPanel.createTask()
|
TaskPanel.createTask()
|
||||||
|
|
|
@ -1,234 +1,301 @@
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
#* *
|
#* *
|
||||||
#* Copyright (c) 2011, 2012 *
|
#* Copyright (c) 2011, 2012 *
|
||||||
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||||
#* *
|
#* *
|
||||||
#* This program is free software; you can redistribute it and/or modify *
|
#* This program is free software; you can redistribute it and/or modify *
|
||||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||||
#* as published by the Free Software Foundation; either version 2 of *
|
#* as published by the Free Software Foundation; either version 2 of *
|
||||||
#* the License, or (at your option) any later version. *
|
#* the License, or (at your option) any later version. *
|
||||||
#* for detail see the LICENCE text file. *
|
#* for detail see the LICENCE text file. *
|
||||||
#* *
|
#* *
|
||||||
#* This program is distributed in the hope that it will be useful, *
|
#* This program is distributed in the hope that it will be useful, *
|
||||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
#* GNU Library General Public License for more details. *
|
#* GNU Library General Public License for more details. *
|
||||||
#* *
|
#* *
|
||||||
#* You should have received a copy of the GNU Library General Public *
|
#* You should have received a copy of the GNU Library General Public *
|
||||||
#* License along with this program; if not, write to the Free Software *
|
#* License along with this program; if not, write to the Free Software *
|
||||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||||
#* USA *
|
#* USA *
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
# FreeCAD modules
|
|
||||||
import FreeCAD as App
|
import FreeCAD as App
|
||||||
import FreeCADGui as Gui
|
import FreeCADGui as Gui
|
||||||
# Qt library
|
|
||||||
from PyQt4 import QtGui,QtCore
|
from PySide import QtGui, QtCore
|
||||||
# Module
|
|
||||||
import Plot
|
import Plot
|
||||||
from plotUtils import Paths
|
from plotUtils import Paths
|
||||||
|
|
||||||
|
|
||||||
class TaskPanel:
|
class TaskPanel:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ui = Paths.modulePath() + "/plotPositions/TaskPanel.ui"
|
self.ui = Paths.modulePath() + "/plotPositions/TaskPanel.ui"
|
||||||
self.skip = False
|
self.skip = False
|
||||||
self.item = 0
|
self.item = 0
|
||||||
self.names = []
|
self.names = []
|
||||||
self.objs = []
|
self.objs = []
|
||||||
self.plt = None
|
self.plt = None
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reject(self):
|
def reject(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def clicked(self, index):
|
def clicked(self, index):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def needsFullSpace(self):
|
def needsFullSpace(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def isAllowedAlterSelection(self):
|
def isAllowedAlterSelection(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def isAllowedAlterView(self):
|
def isAllowedAlterView(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def isAllowedAlterDocument(self):
|
def isAllowedAlterDocument(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def helpRequested(self):
|
def helpRequested(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def setupUi(self):
|
def setupUi(self):
|
||||||
mw = self.getMainWindow()
|
mw = self.getMainWindow()
|
||||||
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
form.items = form.findChild(QtGui.QListWidget, "items")
|
form.items = self.widget(QtGui.QListWidget, "items")
|
||||||
form.x = form.findChild(QtGui.QDoubleSpinBox, "x")
|
form.x = self.widget(QtGui.QDoubleSpinBox, "x")
|
||||||
form.y = form.findChild(QtGui.QDoubleSpinBox, "y")
|
form.y = self.widget(QtGui.QDoubleSpinBox, "y")
|
||||||
form.s = form.findChild(QtGui.QDoubleSpinBox, "size")
|
form.s = self.widget(QtGui.QDoubleSpinBox, "size")
|
||||||
self.form = form
|
self.form = form
|
||||||
self.retranslateUi()
|
self.retranslateUi()
|
||||||
self.updateUI()
|
self.updateUI()
|
||||||
QtCore.QObject.connect(form.items, QtCore.SIGNAL("currentRowChanged(int)"),self.onItem)
|
QtCore.QObject.connect(
|
||||||
QtCore.QObject.connect(form.x, QtCore.SIGNAL("valueChanged(double)"),self.onData)
|
form.items,
|
||||||
QtCore.QObject.connect(form.y, QtCore.SIGNAL("valueChanged(double)"),self.onData)
|
QtCore.SIGNAL("currentRowChanged(int)"),
|
||||||
QtCore.QObject.connect(form.s, QtCore.SIGNAL("valueChanged(double)"),self.onData)
|
self.onItem)
|
||||||
QtCore.QObject.connect(Plot.getMdiArea(),QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"),self.onMdiArea)
|
QtCore.QObject.connect(
|
||||||
return False
|
form.x,
|
||||||
|
QtCore.SIGNAL("valueChanged(double)"),
|
||||||
|
self.onData)
|
||||||
|
QtCore.QObject.connect(
|
||||||
|
form.y,
|
||||||
|
QtCore.SIGNAL("valueChanged(double)"),
|
||||||
|
self.onData)
|
||||||
|
QtCore.QObject.connect(
|
||||||
|
form.s,
|
||||||
|
QtCore.SIGNAL("valueChanged(double)"),
|
||||||
|
self.onData)
|
||||||
|
QtCore.QObject.connect(
|
||||||
|
Plot.getMdiArea(),
|
||||||
|
QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"),
|
||||||
|
self.onMdiArea)
|
||||||
|
return False
|
||||||
|
|
||||||
def getMainWindow(self):
|
def getMainWindow(self):
|
||||||
"returns the main window"
|
toplevel = QtGui.qApp.topLevelWidgets()
|
||||||
# using QtGui.qApp.activeWindow() isn't very reliable because if another
|
for i in toplevel:
|
||||||
# widget than the mainwindow is active (e.g. a dialog) the wrong widget is
|
if i.metaObject().className() == "Gui::MainWindow":
|
||||||
# returned
|
return i
|
||||||
toplevel = QtGui.qApp.topLevelWidgets()
|
raise Exception("No main window found")
|
||||||
for i in toplevel:
|
|
||||||
if i.metaObject().className() == "Gui::MainWindow":
|
|
||||||
return i
|
|
||||||
raise Exception("No main window found")
|
|
||||||
|
|
||||||
def retranslateUi(self):
|
def widget(self, class_id, name):
|
||||||
""" Set user interface locale strings.
|
"""Return the selected widget.
|
||||||
"""
|
|
||||||
self.form.setWindowTitle(QtGui.QApplication.translate("plot_positions", "Set positions and sizes",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.findChild(QtGui.QLabel, "posLabel").setText(QtGui.QApplication.translate("plot_positions", "Position",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.findChild(QtGui.QLabel, "sizeLabel").setText(QtGui.QApplication.translate("plot_positions", "Size",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.items.setToolTip(QtGui.QApplication.translate("plot_positions", "List of modificable items",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.x.setToolTip(QtGui.QApplication.translate("plot_positions", "X item position",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.y.setToolTip(QtGui.QApplication.translate("plot_positions", "Y item position",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.s.setToolTip(QtGui.QApplication.translate("plot_positions", "Item size",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
|
|
||||||
def onItem(self, row):
|
Keyword arguments:
|
||||||
""" Executed when selected item is modified. """
|
class_id -- Class identifier
|
||||||
# Get selected item
|
name -- Name of the widget
|
||||||
self.item = row
|
"""
|
||||||
# Call to update
|
mw = self.getMainWindow()
|
||||||
self.updateUI()
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
|
return form.findChild(class_id, name)
|
||||||
|
|
||||||
def onData(self, value):
|
def retranslateUi(self):
|
||||||
""" Executed when selected item data is modified. """
|
"""Set the user interface locale strings."""
|
||||||
plt = Plot.getPlot()
|
self.form.setWindowTitle(QtGui.QApplication.translate(
|
||||||
if not plt:
|
"plot_positions",
|
||||||
self.updateUI()
|
"Set positions and sizes",
|
||||||
return
|
None,
|
||||||
if not self.skip:
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
self.skip = True
|
self.widget(QtGui.QLabel, "posLabel").setText(
|
||||||
name = self.names[self.item]
|
QtGui.QApplication.translate(
|
||||||
obj = self.objs[self.item]
|
"plot_positions",
|
||||||
x = self.form.x.value()
|
"Position",
|
||||||
y = self.form.y.value()
|
None,
|
||||||
s = self.form.s.value()
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
# x/y labels only have one position control
|
self.widget(QtGui.QLabel, "sizeLabel").setText(
|
||||||
if name.find('x label') >= 0:
|
QtGui.QApplication.translate(
|
||||||
self.form.y.setValue(x)
|
"plot_positions",
|
||||||
elif name.find('y label') >= 0:
|
"Size",
|
||||||
self.form.x.setValue(y)
|
None,
|
||||||
# title and labels only have one size control
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
if name.find('title') >= 0 or name.find('label') >= 0:
|
self.widget(QtGui.QListWidget, "items").setToolTip(
|
||||||
obj.set_position((x,y))
|
QtGui.QApplication.translate(
|
||||||
obj.set_size(s)
|
"plot_positions",
|
||||||
# legend have all controls
|
"List of modificable items",
|
||||||
else:
|
None,
|
||||||
Plot.legend(plt.legend, (x,y), s)
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
plt.update()
|
self.widget(QtGui.QDoubleSpinBox, "x").setToolTip(
|
||||||
self.skip = False
|
QtGui.QApplication.translate(
|
||||||
|
"plot_positions",
|
||||||
|
"X item position",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QDoubleSpinBox, "y").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_positions",
|
||||||
|
"Y item position",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QDoubleSpinBox, "size").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_positions",
|
||||||
|
"Item size",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
|
||||||
def onMdiArea(self, subWin):
|
def onItem(self, row):
|
||||||
""" Executed when window is selected on mdi area.
|
""" Executed when selected item is modified. """
|
||||||
@param subWin Selected window.
|
self.item = row
|
||||||
"""
|
self.updateUI()
|
||||||
plt = Plot.getPlot()
|
|
||||||
if plt != subWin:
|
|
||||||
self.updateUI()
|
|
||||||
|
|
||||||
def updateUI(self):
|
def onData(self, value):
|
||||||
""" Setup UI controls values if possible """
|
""" Executed when selected item data is modified. """
|
||||||
plt = Plot.getPlot()
|
plt = Plot.getPlot()
|
||||||
self.form.items.setEnabled(bool(plt))
|
if not plt:
|
||||||
self.form.x.setEnabled(bool(plt))
|
self.updateUI()
|
||||||
self.form.y.setEnabled(bool(plt))
|
return
|
||||||
self.form.s.setEnabled(bool(plt))
|
mw = self.getMainWindow()
|
||||||
if not plt:
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
self.plt = plt
|
form.items = self.widget(QtGui.QListWidget, "items")
|
||||||
self.form.items.clear()
|
form.x = self.widget(QtGui.QDoubleSpinBox, "x")
|
||||||
return
|
form.y = self.widget(QtGui.QDoubleSpinBox, "y")
|
||||||
# Refill items list only if Plot instance have been changed
|
form.s = self.widget(QtGui.QDoubleSpinBox, "size")
|
||||||
if self.plt != plt:
|
if not self.skip:
|
||||||
self.plt = plt
|
self.skip = True
|
||||||
self.plt.update() # Update plot in order to put legend in correct place
|
name = self.names[self.item]
|
||||||
self.setList()
|
obj = self.objs[self.item]
|
||||||
# Get data for controls
|
x = form.x.value()
|
||||||
name = self.names[self.item]
|
y = form.y.value()
|
||||||
obj = self.objs[self.item]
|
s = form.s.value()
|
||||||
if name.find('title') >= 0 or name.find('label') >= 0:
|
# x/y labels only have one position control
|
||||||
p = obj.get_position()
|
if name.find('x label') >= 0:
|
||||||
x = p[0]
|
form.y.setValue(x)
|
||||||
y = p[1]
|
elif name.find('y label') >= 0:
|
||||||
s = obj.get_size()
|
form.x.setValue(y)
|
||||||
if name.find('x label') >= 0:
|
# title and labels only have one size control
|
||||||
self.form.y.setEnabled(False)
|
if name.find('title') >= 0 or name.find('label') >= 0:
|
||||||
self.form.y.setValue(x)
|
obj.set_position((x, y))
|
||||||
elif name.find('y label') >= 0:
|
obj.set_size(s)
|
||||||
self.form.x.setEnabled(False)
|
# legend have all controls
|
||||||
self.form.x.setValue(y)
|
else:
|
||||||
else:
|
Plot.legend(plt.legend, (x, y), s)
|
||||||
x = plt.legPos[0]
|
plt.update()
|
||||||
y = plt.legPos[1]
|
self.skip = False
|
||||||
s = obj.get_texts()[-1].get_fontsize()
|
|
||||||
# Send it to controls
|
def onMdiArea(self, subWin):
|
||||||
self.form.x.setValue(x)
|
"""Executed when a new window is selected on the mdi area.
|
||||||
self.form.y.setValue(y)
|
|
||||||
self.form.s.setValue(s)
|
Keyword arguments:
|
||||||
|
subWin -- Selected window.
|
||||||
|
"""
|
||||||
|
plt = Plot.getPlot()
|
||||||
|
if plt != subWin:
|
||||||
|
self.updateUI()
|
||||||
|
|
||||||
|
def updateUI(self):
|
||||||
|
"""Setup the UI control values if it is possible."""
|
||||||
|
mw = self.getMainWindow()
|
||||||
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
|
form.items = self.widget(QtGui.QListWidget, "items")
|
||||||
|
form.x = self.widget(QtGui.QDoubleSpinBox, "x")
|
||||||
|
form.y = self.widget(QtGui.QDoubleSpinBox, "y")
|
||||||
|
form.s = self.widget(QtGui.QDoubleSpinBox, "size")
|
||||||
|
plt = Plot.getPlot()
|
||||||
|
form.items.setEnabled(bool(plt))
|
||||||
|
form.x.setEnabled(bool(plt))
|
||||||
|
form.y.setEnabled(bool(plt))
|
||||||
|
form.s.setEnabled(bool(plt))
|
||||||
|
if not plt:
|
||||||
|
self.plt = plt
|
||||||
|
form.items.clear()
|
||||||
|
return
|
||||||
|
# Refill items list only if Plot instance have been changed
|
||||||
|
if self.plt != plt:
|
||||||
|
self.plt = plt
|
||||||
|
self.plt.update()
|
||||||
|
self.setList()
|
||||||
|
# Get data for controls
|
||||||
|
name = self.names[self.item]
|
||||||
|
obj = self.objs[self.item]
|
||||||
|
if name.find('title') >= 0 or name.find('label') >= 0:
|
||||||
|
p = obj.get_position()
|
||||||
|
x = p[0]
|
||||||
|
y = p[1]
|
||||||
|
s = obj.get_size()
|
||||||
|
if name.find('x label') >= 0:
|
||||||
|
form.y.setEnabled(False)
|
||||||
|
form.y.setValue(x)
|
||||||
|
elif name.find('y label') >= 0:
|
||||||
|
form.x.setEnabled(False)
|
||||||
|
form.x.setValue(y)
|
||||||
|
else:
|
||||||
|
x = plt.legPos[0]
|
||||||
|
y = plt.legPos[1]
|
||||||
|
s = obj.get_texts()[-1].get_fontsize()
|
||||||
|
# Send it to controls
|
||||||
|
form.x.setValue(x)
|
||||||
|
form.y.setValue(y)
|
||||||
|
form.s.setValue(s)
|
||||||
|
|
||||||
|
def setList(self):
|
||||||
|
""" Setup UI controls values if possible """
|
||||||
|
mw = self.getMainWindow()
|
||||||
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
|
form.items = self.widget(QtGui.QListWidget, "items")
|
||||||
|
form.x = self.widget(QtGui.QDoubleSpinBox, "x")
|
||||||
|
form.y = self.widget(QtGui.QDoubleSpinBox, "y")
|
||||||
|
form.s = self.widget(QtGui.QDoubleSpinBox, "size")
|
||||||
|
# Clear lists
|
||||||
|
self.names = []
|
||||||
|
self.objs = []
|
||||||
|
# Fill lists with available objects
|
||||||
|
if self.plt:
|
||||||
|
# Axes data
|
||||||
|
for i in range(0, len(self.plt.axesList)):
|
||||||
|
ax = self.plt.axesList[i]
|
||||||
|
# Each axes have title, xaxis and yaxis
|
||||||
|
self.names.append('title (axes {})'.format(i))
|
||||||
|
self.objs.append(ax.title)
|
||||||
|
self.names.append('x label (axes {})'.format(i))
|
||||||
|
self.objs.append(ax.xaxis.get_label())
|
||||||
|
self.names.append('y label (axes {})'.format(i))
|
||||||
|
self.objs.append(ax.yaxis.get_label())
|
||||||
|
# Legend if exist
|
||||||
|
ax = self.plt.axesList[-1]
|
||||||
|
if ax.legend_:
|
||||||
|
self.names.append('legend')
|
||||||
|
self.objs.append(ax.legend_)
|
||||||
|
# Send list to widget
|
||||||
|
form.items.clear()
|
||||||
|
for name in self.names:
|
||||||
|
form.items.addItem(name)
|
||||||
|
# Ensure that selected item is correct
|
||||||
|
if self.item >= len(self.names):
|
||||||
|
self.item = len(self.names) - 1
|
||||||
|
form.items.setCurrentIndex(self.item)
|
||||||
|
|
||||||
def setList(self):
|
|
||||||
""" Setup UI controls values if possible """
|
|
||||||
# Clear lists
|
|
||||||
self.names = []
|
|
||||||
self.objs = []
|
|
||||||
# Fill lists with available objects
|
|
||||||
if self.plt:
|
|
||||||
# Axes data
|
|
||||||
for i in range(0,len(self.plt.axesList)):
|
|
||||||
ax = self.plt.axesList[i]
|
|
||||||
# Each axes have title, xaxis and yaxis
|
|
||||||
self.names.append('title (axes %d)' % (i))
|
|
||||||
self.objs.append(ax.title)
|
|
||||||
self.names.append('x label (axes %d)' % (i))
|
|
||||||
self.objs.append(ax.xaxis.get_label())
|
|
||||||
self.names.append('y label (axes %d)' % (i))
|
|
||||||
self.objs.append(ax.yaxis.get_label())
|
|
||||||
# Legend if exist
|
|
||||||
ax = self.plt.axesList[-1]
|
|
||||||
if ax.legend_:
|
|
||||||
self.names.append('legend')
|
|
||||||
self.objs.append(ax.legend_)
|
|
||||||
# Send list to widget
|
|
||||||
self.form.items.clear()
|
|
||||||
for name in self.names:
|
|
||||||
self.form.items.addItem(name)
|
|
||||||
# Ensure that selected item is correct
|
|
||||||
if self.item >= len(self.names):
|
|
||||||
self.item = len(self.names)-1
|
|
||||||
self.form.items.setCurrentIndex(self.item)
|
|
||||||
|
|
||||||
def createTask():
|
def createTask():
|
||||||
panel = TaskPanel()
|
panel = TaskPanel()
|
||||||
Gui.Control.showDialog(panel)
|
Gui.Control.showDialog(panel)
|
||||||
if panel.setupUi():
|
if panel.setupUi():
|
||||||
Gui.Control.closeDialog(panel)
|
Gui.Control.closeDialog(panel)
|
||||||
return None
|
return None
|
||||||
return panel
|
return panel
|
||||||
|
|
|
@ -21,16 +21,9 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
# FreeCAD modules
|
|
||||||
import FreeCAD
|
|
||||||
import FreeCADGui
|
|
||||||
|
|
||||||
# Qt libraries
|
|
||||||
from PyQt4 import QtGui,QtCore
|
|
||||||
|
|
||||||
# Main object
|
|
||||||
import TaskPanel
|
import TaskPanel
|
||||||
|
|
||||||
|
|
||||||
def load():
|
def load():
|
||||||
""" Loads the tool """
|
"""Load the tool"""
|
||||||
TaskPanel.createTask()
|
TaskPanel.createTask()
|
||||||
|
|
|
@ -1,163 +1,235 @@
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
#* *
|
#* *
|
||||||
#* Copyright (c) 2011, 2012 *
|
#* Copyright (c) 2011, 2012 *
|
||||||
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||||
#* *
|
#* *
|
||||||
#* This program is free software; you can redistribute it and/or modify *
|
#* This program is free software; you can redistribute it and/or modify *
|
||||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||||
#* as published by the Free Software Foundation; either version 2 of *
|
#* as published by the Free Software Foundation; either version 2 of *
|
||||||
#* the License, or (at your option) any later version. *
|
#* the License, or (at your option) any later version. *
|
||||||
#* for detail see the LICENCE text file. *
|
#* for detail see the LICENCE text file. *
|
||||||
#* *
|
#* *
|
||||||
#* This program is distributed in the hope that it will be useful, *
|
#* This program is distributed in the hope that it will be useful, *
|
||||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
#* GNU Library General Public License for more details. *
|
#* GNU Library General Public License for more details. *
|
||||||
#* *
|
#* *
|
||||||
#* You should have received a copy of the GNU Library General Public *
|
#* You should have received a copy of the GNU Library General Public *
|
||||||
#* License along with this program; if not, write to the Free Software *
|
#* License along with this program; if not, write to the Free Software *
|
||||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||||
#* USA *
|
#* USA *
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
import os
|
import os
|
||||||
# FreeCAD modules
|
|
||||||
import FreeCAD as App
|
import FreeCAD as App
|
||||||
import FreeCADGui as Gui
|
import FreeCADGui as Gui
|
||||||
# Qt library
|
|
||||||
from PyQt4 import QtGui,QtCore
|
from PySide import QtGui, QtCore
|
||||||
# Module
|
|
||||||
import Plot
|
import Plot
|
||||||
from plotUtils import Paths
|
from plotUtils import Paths
|
||||||
|
|
||||||
|
|
||||||
class TaskPanel:
|
class TaskPanel:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ui = Paths.modulePath() + "/plotSave/TaskPanel.ui"
|
self.ui = Paths.modulePath() + "/plotSave/TaskPanel.ui"
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
plt = Plot.getPlot()
|
plt = Plot.getPlot()
|
||||||
if not plt:
|
if not plt:
|
||||||
msg = QtGui.QApplication.translate("plot_console", "Plot document must be selected in order to save it",
|
msg = QtGui.QApplication.translate(
|
||||||
None,QtGui.QApplication.UnicodeUTF8)
|
"plot_console",
|
||||||
App.Console.PrintError(msg+"\n")
|
"Plot document must be selected in order to save it",
|
||||||
return False
|
None,
|
||||||
path = unicode(self.form.path.text())
|
QtGui.QApplication.UnicodeUTF8)
|
||||||
size = (self.form.sizeX.value(), self.form.sizeY.value())
|
App.Console.PrintError(msg + "\n")
|
||||||
dpi = self.form.dpi.value()
|
return False
|
||||||
Plot.save(path, size, dpi)
|
mw = self.getMainWindow()
|
||||||
return True
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
|
form.path = self.widget(QtGui.QLineEdit, "path")
|
||||||
|
form.sizeX = self.widget(QtGui.QDoubleSpinBox, "sizeX")
|
||||||
|
form.sizeY = self.widget(QtGui.QDoubleSpinBox, "sizeY")
|
||||||
|
form.dpi = self.widget(QtGui.QSpinBox, "dpi")
|
||||||
|
path = unicode(form.path.text())
|
||||||
|
size = (form.sizeX.value(), form.sizeY.value())
|
||||||
|
dpi = form.dpi.value()
|
||||||
|
Plot.save(path, size, dpi)
|
||||||
|
return True
|
||||||
|
|
||||||
def reject(self):
|
def reject(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def clicked(self, index):
|
def clicked(self, index):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def needsFullSpace(self):
|
def needsFullSpace(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def isAllowedAlterSelection(self):
|
def isAllowedAlterSelection(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def isAllowedAlterView(self):
|
def isAllowedAlterView(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def isAllowedAlterDocument(self):
|
def isAllowedAlterDocument(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def helpRequested(self):
|
def helpRequested(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def setupUi(self):
|
def setupUi(self):
|
||||||
mw = self.getMainWindow()
|
mw = self.getMainWindow()
|
||||||
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
form.path = form.findChild(QtGui.QLineEdit, "path")
|
form.path = self.widget(QtGui.QLineEdit, "path")
|
||||||
form.pathButton = form.findChild(QtGui.QPushButton, "pathButton")
|
form.pathButton = self.widget(QtGui.QPushButton, "pathButton")
|
||||||
form.sizeX = form.findChild(QtGui.QDoubleSpinBox, "sizeX")
|
form.sizeX = self.widget(QtGui.QDoubleSpinBox, "sizeX")
|
||||||
form.sizeY = form.findChild(QtGui.QDoubleSpinBox, "sizeY")
|
form.sizeY = self.widget(QtGui.QDoubleSpinBox, "sizeY")
|
||||||
form.dpi = form.findChild(QtGui.QSpinBox, "dpi")
|
form.dpi = self.widget(QtGui.QSpinBox, "dpi")
|
||||||
self.form = form
|
self.form = form
|
||||||
self.retranslateUi()
|
self.retranslateUi()
|
||||||
QtCore.QObject.connect(form.pathButton,QtCore.SIGNAL("pressed()"),self.onPathButton)
|
QtCore.QObject.connect(
|
||||||
QtCore.QObject.connect(Plot.getMdiArea(),QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"),self.onMdiArea)
|
form.pathButton,
|
||||||
home = os.getenv('USERPROFILE') or os.getenv('HOME')
|
QtCore.SIGNAL("pressed()"),
|
||||||
form.path.setText(os.path.join(home,"plot.png"))
|
self.onPathButton)
|
||||||
self.updateUI()
|
QtCore.QObject.connect(
|
||||||
return False
|
Plot.getMdiArea(),
|
||||||
|
QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"),
|
||||||
|
self.onMdiArea)
|
||||||
|
home = os.getenv('USERPROFILE') or os.getenv('HOME')
|
||||||
|
form.path.setText(os.path.join(home, "plot.png"))
|
||||||
|
self.updateUI()
|
||||||
|
return False
|
||||||
|
|
||||||
def getMainWindow(self):
|
def getMainWindow(self):
|
||||||
"returns the main window"
|
toplevel = QtGui.qApp.topLevelWidgets()
|
||||||
# using QtGui.qApp.activeWindow() isn't very reliable because if another
|
for i in toplevel:
|
||||||
# widget than the mainwindow is active (e.g. a dialog) the wrong widget is
|
if i.metaObject().className() == "Gui::MainWindow":
|
||||||
# returned
|
return i
|
||||||
toplevel = QtGui.qApp.topLevelWidgets()
|
raise Exception("No main window found")
|
||||||
for i in toplevel:
|
|
||||||
if i.metaObject().className() == "Gui::MainWindow":
|
|
||||||
return i
|
|
||||||
raise Exception("No main window found")
|
|
||||||
|
|
||||||
def retranslateUi(self):
|
def widget(self, class_id, name):
|
||||||
""" Set user interface locale strings.
|
"""Return the selected widget.
|
||||||
"""
|
|
||||||
self.form.setWindowTitle(QtGui.QApplication.translate("plot_save", "Save figure",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.findChild(QtGui.QLabel, "sizeLabel").setText(QtGui.QApplication.translate("plot_save", "Inches",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.findChild(QtGui.QLabel, "dpiLabel").setText(QtGui.QApplication.translate("plot_save", "Dots per Inch",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.path.setToolTip(QtGui.QApplication.translate("plot_save", "Output image file path",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.pathButton.setToolTip(QtGui.QApplication.translate("plot_save", "Show a file selection dialog",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.sizeX.setToolTip(QtGui.QApplication.translate("plot_save", "X image size",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.sizeY.setToolTip(QtGui.QApplication.translate("plot_save", "Y image size",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.dpi.setToolTip(QtGui.QApplication.translate("plot_save", "Dots per point, with size will define output image resolution",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
|
|
||||||
def updateUI(self):
|
Keyword arguments:
|
||||||
""" Setup UI controls values if possible """
|
class_id -- Class identifier
|
||||||
plt = Plot.getPlot()
|
name -- Name of the widget
|
||||||
self.form.path.setEnabled(bool(plt))
|
"""
|
||||||
self.form.pathButton.setEnabled(bool(plt))
|
mw = self.getMainWindow()
|
||||||
self.form.sizeX.setEnabled(bool(plt))
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
self.form.sizeY.setEnabled(bool(plt))
|
return form.findChild(class_id, name)
|
||||||
self.form.dpi.setEnabled(bool(plt))
|
|
||||||
if not plt:
|
|
||||||
return
|
|
||||||
fig = plt.fig
|
|
||||||
size = fig.get_size_inches()
|
|
||||||
dpi = fig.get_dpi()
|
|
||||||
self.form.sizeX.setValue(size[0])
|
|
||||||
self.form.sizeY.setValue(size[1])
|
|
||||||
self.form.dpi.setValue(dpi)
|
|
||||||
|
|
||||||
def onPathButton(self):
|
def retranslateUi(self):
|
||||||
""" Executed when path button is pressed.
|
"""Set the user interface locale strings."""
|
||||||
"""
|
self.form.setWindowTitle(QtGui.QApplication.translate(
|
||||||
path = self.form.path.text()
|
"plot_save",
|
||||||
file_choices = "Portable Network Graphics (*.png)|*.png;;Portable Document Format (*.pdf)|*.pdf;;PostScript (*.ps)|*.ps;;Encapsulated PostScript (*.eps)|*.eps"
|
"Save figure",
|
||||||
path = QtGui.QFileDialog.getSaveFileName(None, 'Save figure', path, file_choices)
|
None,
|
||||||
if path:
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
self.form.path.setText(path)
|
self.widget(QtGui.QLabel, "sizeLabel").setText(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_save",
|
||||||
|
"Inches",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QLabel, "dpiLabel").setText(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_save",
|
||||||
|
"Dots per Inch",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QLineEdit, "path").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_save",
|
||||||
|
"Output image file path",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QPushButton, "pathButton").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_save",
|
||||||
|
"Show a file selection dialog",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QDoubleSpinBox, "sizeX").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_save",
|
||||||
|
"X image size",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QDoubleSpinBox, "sizeY").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_save",
|
||||||
|
"Y image size",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QSpinBox, "dpi").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_save",
|
||||||
|
"Dots per point, with size will define output image"
|
||||||
|
" resolution",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
|
||||||
|
def updateUI(self):
|
||||||
|
""" Setup UI controls values if possible """
|
||||||
|
mw = self.getMainWindow()
|
||||||
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
|
form.path = self.widget(QtGui.QLineEdit, "path")
|
||||||
|
form.pathButton = self.widget(QtGui.QPushButton, "pathButton")
|
||||||
|
form.sizeX = self.widget(QtGui.QDoubleSpinBox, "sizeX")
|
||||||
|
form.sizeY = self.widget(QtGui.QDoubleSpinBox, "sizeY")
|
||||||
|
form.dpi = self.widget(QtGui.QSpinBox, "dpi")
|
||||||
|
plt = Plot.getPlot()
|
||||||
|
form.path.setEnabled(bool(plt))
|
||||||
|
form.pathButton.setEnabled(bool(plt))
|
||||||
|
form.sizeX.setEnabled(bool(plt))
|
||||||
|
form.sizeY.setEnabled(bool(plt))
|
||||||
|
form.dpi.setEnabled(bool(plt))
|
||||||
|
if not plt:
|
||||||
|
return
|
||||||
|
fig = plt.fig
|
||||||
|
size = fig.get_size_inches()
|
||||||
|
dpi = fig.get_dpi()
|
||||||
|
form.sizeX.setValue(size[0])
|
||||||
|
form.sizeY.setValue(size[1])
|
||||||
|
form.dpi.setValue(dpi)
|
||||||
|
|
||||||
|
def onPathButton(self):
|
||||||
|
"""Executed when the path selection button is pressed."""
|
||||||
|
mw = self.getMainWindow()
|
||||||
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
|
form.path = self.widget(QtGui.QLineEdit, "path")
|
||||||
|
path = form.path.text()
|
||||||
|
file_choices = ("Portable Network Graphics (*.png)|*.png;;"
|
||||||
|
"Portable Document Format (*.pdf)|*.pdf;;"
|
||||||
|
"PostScript (*.ps)|*.ps;;"
|
||||||
|
"Encapsulated PostScript (*.eps)|*.eps")
|
||||||
|
path = QtGui.QFileDialog.getSaveFileName(None,
|
||||||
|
'Save figure',
|
||||||
|
path,
|
||||||
|
file_choices)
|
||||||
|
if path:
|
||||||
|
form.path.setText(path)
|
||||||
|
|
||||||
|
def onMdiArea(self, subWin):
|
||||||
|
"""Executed when a new window is selected on the mdi area.
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
subWin -- Selected window.
|
||||||
|
"""
|
||||||
|
plt = Plot.getPlot()
|
||||||
|
if plt != subWin:
|
||||||
|
self.updateUI()
|
||||||
|
|
||||||
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 createTask():
|
def createTask():
|
||||||
panel = TaskPanel()
|
panel = TaskPanel()
|
||||||
Gui.Control.showDialog(panel)
|
Gui.Control.showDialog(panel)
|
||||||
if panel.setupUi():
|
if panel.setupUi():
|
||||||
Gui.Control.closeDialog(panel)
|
Gui.Control.closeDialog(panel)
|
||||||
return None
|
return None
|
||||||
return panel
|
return panel
|
||||||
|
|
|
@ -21,16 +21,9 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
# FreeCAD modules
|
|
||||||
import FreeCAD
|
|
||||||
import FreeCADGui
|
|
||||||
|
|
||||||
# Qt libraries
|
|
||||||
from PyQt4 import QtGui,QtCore
|
|
||||||
|
|
||||||
# Main object
|
|
||||||
import TaskPanel
|
import TaskPanel
|
||||||
|
|
||||||
|
|
||||||
def load():
|
def load():
|
||||||
""" Loads the tool """
|
"""Load the tool"""
|
||||||
TaskPanel.createTask()
|
TaskPanel.createTask()
|
||||||
|
|
|
@ -1,332 +1,462 @@
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
#* *
|
#* *
|
||||||
#* Copyright (c) 2011, 2012 *
|
#* Copyright (c) 2011, 2012 *
|
||||||
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||||
#* *
|
#* *
|
||||||
#* This program is free software; you can redistribute it and/or modify *
|
#* This program is free software; you can redistribute it and/or modify *
|
||||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||||
#* as published by the Free Software Foundation; either version 2 of *
|
#* as published by the Free Software Foundation; either version 2 of *
|
||||||
#* the License, or (at your option) any later version. *
|
#* the License, or (at your option) any later version. *
|
||||||
#* for detail see the LICENCE text file. *
|
#* for detail see the LICENCE text file. *
|
||||||
#* *
|
#* *
|
||||||
#* This program is distributed in the hope that it will be useful, *
|
#* This program is distributed in the hope that it will be useful, *
|
||||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
#* GNU Library General Public License for more details. *
|
#* GNU Library General Public License for more details. *
|
||||||
#* *
|
#* *
|
||||||
#* You should have received a copy of the GNU Library General Public *
|
#* You should have received a copy of the GNU Library General Public *
|
||||||
#* License along with this program; if not, write to the Free Software *
|
#* License along with this program; if not, write to the Free Software *
|
||||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||||
#* USA *
|
#* USA *
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
# FreeCAD modules
|
|
||||||
import FreeCAD as App
|
import FreeCAD as App
|
||||||
import FreeCADGui as Gui
|
import FreeCADGui as Gui
|
||||||
# Qt library
|
|
||||||
from PyQt4 import QtGui,QtCore
|
from PySide import QtGui, QtCore
|
||||||
# Module
|
|
||||||
import Plot
|
import Plot
|
||||||
from plotUtils import Paths
|
from plotUtils import Paths
|
||||||
# matplotlib
|
|
||||||
import matplotlib
|
import matplotlib
|
||||||
from matplotlib.lines import Line2D
|
from matplotlib.lines import Line2D
|
||||||
import matplotlib.colors as Colors
|
import matplotlib.colors as Colors
|
||||||
|
|
||||||
|
|
||||||
class TaskPanel:
|
class TaskPanel:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ui = Paths.modulePath() + "/plotSeries/TaskPanel.ui"
|
self.ui = Paths.modulePath() + "/plotSeries/TaskPanel.ui"
|
||||||
self.skip = False
|
self.skip = False
|
||||||
self.item = 0
|
self.item = 0
|
||||||
self.plt = None
|
self.plt = None
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reject(self):
|
def reject(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def clicked(self, index):
|
def clicked(self, index):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def needsFullSpace(self):
|
def needsFullSpace(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def isAllowedAlterSelection(self):
|
def isAllowedAlterSelection(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def isAllowedAlterView(self):
|
def isAllowedAlterView(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def isAllowedAlterDocument(self):
|
def isAllowedAlterDocument(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def helpRequested(self):
|
def helpRequested(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def setupUi(self):
|
def setupUi(self):
|
||||||
mw = self.getMainWindow()
|
mw = self.getMainWindow()
|
||||||
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
form.items = form.findChild(QtGui.QListWidget, "items")
|
form.items = self.widget(QtGui.QListWidget, "items")
|
||||||
form.label = form.findChild(QtGui.QLineEdit, "label")
|
form.label = self.widget(QtGui.QLineEdit, "label")
|
||||||
form.isLabel = form.findChild(QtGui.QCheckBox, "isLabel")
|
form.isLabel = self.widget(QtGui.QCheckBox, "isLabel")
|
||||||
form.style = form.findChild(QtGui.QComboBox, "lineStyle")
|
form.style = self.widget(QtGui.QComboBox, "lineStyle")
|
||||||
form.marker = form.findChild(QtGui.QComboBox, "markers")
|
form.marker = self.widget(QtGui.QComboBox, "markers")
|
||||||
form.width = form.findChild(QtGui.QDoubleSpinBox, "lineWidth")
|
form.width = self.widget(QtGui.QDoubleSpinBox, "lineWidth")
|
||||||
form.size = form.findChild(QtGui.QSpinBox, "markerSize")
|
form.size = self.widget(QtGui.QSpinBox, "markerSize")
|
||||||
form.color = form.findChild(QtGui.QPushButton, "color")
|
form.color = self.widget(QtGui.QPushButton, "color")
|
||||||
form.remove = form.findChild(QtGui.QPushButton, "remove")
|
form.remove = self.widget(QtGui.QPushButton, "remove")
|
||||||
self.form = form
|
self.form = form
|
||||||
self.retranslateUi()
|
self.retranslateUi()
|
||||||
self.fillStyles()
|
self.fillStyles()
|
||||||
self.updateUI()
|
self.updateUI()
|
||||||
QtCore.QObject.connect(form.items, QtCore.SIGNAL("currentRowChanged(int)"),self.onItem)
|
QtCore.QObject.connect(
|
||||||
QtCore.QObject.connect(form.label, QtCore.SIGNAL("editingFinished()"),self.onData)
|
form.items,
|
||||||
QtCore.QObject.connect(form.isLabel,QtCore.SIGNAL("stateChanged(int)"),self.onData)
|
QtCore.SIGNAL("currentRowChanged(int)"),
|
||||||
QtCore.QObject.connect(form.style, QtCore.SIGNAL("currentIndexChanged(int)"),self.onData)
|
self.onItem)
|
||||||
QtCore.QObject.connect(form.marker, QtCore.SIGNAL("currentIndexChanged(int)"),self.onData)
|
QtCore.QObject.connect(
|
||||||
QtCore.QObject.connect(form.width, QtCore.SIGNAL("valueChanged(double)"),self.onData)
|
form.label,
|
||||||
QtCore.QObject.connect(form.size, QtCore.SIGNAL("valueChanged(int)"),self.onData)
|
QtCore.SIGNAL("editingFinished()"),
|
||||||
QtCore.QObject.connect(form.color, QtCore.SIGNAL("pressed()"),self.onColor)
|
self.onData)
|
||||||
QtCore.QObject.connect(form.remove, QtCore.SIGNAL("pressed()"),self.onRemove)
|
QtCore.QObject.connect(
|
||||||
QtCore.QObject.connect(Plot.getMdiArea(),QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"),self.onMdiArea)
|
form.isLabel,
|
||||||
return False
|
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):
|
def getMainWindow(self):
|
||||||
"returns the main window"
|
toplevel = QtGui.qApp.topLevelWidgets()
|
||||||
# using QtGui.qApp.activeWindow() isn't very reliable because if another
|
for i in toplevel:
|
||||||
# widget than the mainwindow is active (e.g. a dialog) the wrong widget is
|
if i.metaObject().className() == "Gui::MainWindow":
|
||||||
# returned
|
return i
|
||||||
toplevel = QtGui.qApp.topLevelWidgets()
|
raise Exception("No main window found")
|
||||||
for i in toplevel:
|
|
||||||
if i.metaObject().className() == "Gui::MainWindow":
|
|
||||||
return i
|
|
||||||
raise Exception("No main window found")
|
|
||||||
|
|
||||||
def retranslateUi(self):
|
def widget(self, class_id, name):
|
||||||
""" Set user interface locale strings.
|
"""Return the selected widget.
|
||||||
"""
|
|
||||||
self.form.setWindowTitle(QtGui.QApplication.translate("plot_series", "Configure series",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.isLabel.setText(QtGui.QApplication.translate("plot_series", "No label",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.remove.setText(QtGui.QApplication.translate("plot_series", "Remove serie",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.findChild(QtGui.QLabel, "styleLabel").setText(QtGui.QApplication.translate("plot_series", "Line style",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.findChild(QtGui.QLabel, "markerLabel").setText(QtGui.QApplication.translate("plot_series", "Marker",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.items.setToolTip(QtGui.QApplication.translate("plot_series", "List of available series",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.label.setToolTip(QtGui.QApplication.translate("plot_series", "Line title",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.isLabel.setToolTip(QtGui.QApplication.translate("plot_series", "If checked serie will not be considered for legend",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.style.setToolTip(QtGui.QApplication.translate("plot_series", "Line style",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.marker.setToolTip(QtGui.QApplication.translate("plot_series", "Marker style",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.width.setToolTip(QtGui.QApplication.translate("plot_series", "Line width",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.size.setToolTip(QtGui.QApplication.translate("plot_series", "Marker size",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.color.setToolTip(QtGui.QApplication.translate("plot_series", "Line and marker color",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
self.form.remove.setToolTip(QtGui.QApplication.translate("plot_series", "Removes this serie",
|
|
||||||
None,QtGui.QApplication.UnicodeUTF8))
|
|
||||||
|
|
||||||
def fillStyles(self):
|
Keyword arguments:
|
||||||
""" Fill style combo boxes. """
|
class_id -- Class identifier
|
||||||
# Line styles
|
name -- Name of the widget
|
||||||
linestyles = Line2D.lineStyles.keys()
|
"""
|
||||||
for i in range(0,len(linestyles)):
|
mw = self.getMainWindow()
|
||||||
style = linestyles[i]
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
string = "\'" + str(style) + "\' (" + Line2D.lineStyles[style] + ")"
|
return form.findChild(class_id, name)
|
||||||
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):
|
def retranslateUi(self):
|
||||||
""" Executed when selected item is modified. """
|
"""Set the user interface locale strings."""
|
||||||
if not self.skip:
|
self.form.setWindowTitle(QtGui.QApplication.translate(
|
||||||
self.skip = True
|
"plot_series",
|
||||||
# Get selected item
|
"Configure series",
|
||||||
self.item = row
|
None,
|
||||||
# Call to update
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
self.updateUI()
|
self.widget(QtGui.QCheckBox, "isLabel").setText(
|
||||||
self.skip = False
|
QtGui.QApplication.translate(
|
||||||
|
"plot_series",
|
||||||
|
"No label",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QPushButton, "remove").setText(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_series",
|
||||||
|
"Remove serie",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QLabel, "styleLabel").setText(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_series",
|
||||||
|
"Line style",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QLabel, "markerLabel").setText(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_series",
|
||||||
|
"Marker",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QListWidget, "items").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_series",
|
||||||
|
"List of available series",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QLineEdit, "label").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_series",
|
||||||
|
"Line title",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QCheckBox, "isLabel").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_series",
|
||||||
|
"If checked serie will not be considered for legend",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QComboBox, "lineStyle").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_series",
|
||||||
|
"Line style",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QComboBox, "markers").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_series",
|
||||||
|
"Marker style",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QDoubleSpinBox, "lineWidth").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_series",
|
||||||
|
"Line width",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QSpinBox, "markerSize").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_series",
|
||||||
|
"Marker size",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QPushButton, "color").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_series",
|
||||||
|
"Line and marker color",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.widget(QtGui.QPushButton, "remove").setToolTip(
|
||||||
|
QtGui.QApplication.translate(
|
||||||
|
"plot_series",
|
||||||
|
"Removes this serie",
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
|
||||||
def onData(self):
|
def fillStyles(self):
|
||||||
""" Executed when selected item data is modified. """
|
"""Fill the style combo boxes with the availabel ones."""
|
||||||
if not self.skip:
|
mw = self.getMainWindow()
|
||||||
self.skip = True
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
plt = Plot.getPlot()
|
form.style = self.widget(QtGui.QComboBox, "lineStyle")
|
||||||
if not plt:
|
form.marker = self.widget(QtGui.QComboBox, "markers")
|
||||||
self.updateUI()
|
# Line styles
|
||||||
return
|
linestyles = Line2D.lineStyles.keys()
|
||||||
# Ensure that selected serie exist
|
for i in range(0, len(linestyles)):
|
||||||
if self.item >= len(Plot.series()):
|
style = linestyles[i]
|
||||||
self.updateUI()
|
string = "\'" + str(style) + "\'"
|
||||||
return
|
string += " (" + Line2D.lineStyles[style] + ")"
|
||||||
# Set label
|
form.style.addItem(string)
|
||||||
serie = Plot.series()[self.item]
|
# Markers
|
||||||
if(self.form.isLabel.isChecked()):
|
markers = Line2D.markers.keys()
|
||||||
serie.name = None
|
for i in range(0, len(markers)):
|
||||||
self.form.label.setEnabled(False)
|
marker = markers[i]
|
||||||
else:
|
string = "\'" + str(marker) + "\'"
|
||||||
serie.name = self.form.label.text()
|
string += " (" + Line2D.markers[marker] + ")"
|
||||||
self.form.label.setEnabled(True)
|
form.marker.addItem(string)
|
||||||
# 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):
|
def onItem(self, row):
|
||||||
""" Executed when color pallete is requested. """
|
"""Executed when the selected item is modified."""
|
||||||
plt = Plot.getPlot()
|
if not self.skip:
|
||||||
if not plt:
|
self.skip = True
|
||||||
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):
|
self.item = row
|
||||||
""" 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):
|
self.updateUI()
|
||||||
""" Executed when window is selected on mdi area.
|
self.skip = False
|
||||||
@param subWin Selected window.
|
|
||||||
"""
|
|
||||||
plt = Plot.getPlot()
|
|
||||||
if plt != subWin:
|
|
||||||
self.updateUI()
|
|
||||||
|
|
||||||
def updateUI(self):
|
def onData(self):
|
||||||
""" Setup UI controls values if possible """
|
"""Executed when the selected item data is modified."""
|
||||||
plt = Plot.getPlot()
|
if not self.skip:
|
||||||
self.form.items.setEnabled(bool(plt))
|
self.skip = True
|
||||||
self.form.label.setEnabled(bool(plt))
|
plt = Plot.getPlot()
|
||||||
self.form.isLabel.setEnabled(bool(plt))
|
if not plt:
|
||||||
self.form.style.setEnabled(bool(plt))
|
self.updateUI()
|
||||||
self.form.marker.setEnabled(bool(plt))
|
return
|
||||||
self.form.width.setEnabled(bool(plt))
|
mw = self.getMainWindow()
|
||||||
self.form.size.setEnabled(bool(plt))
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
self.form.color.setEnabled(bool(plt))
|
form.label = self.widget(QtGui.QLineEdit, "label")
|
||||||
self.form.remove.setEnabled(bool(plt))
|
form.isLabel = self.widget(QtGui.QCheckBox, "isLabel")
|
||||||
if not plt:
|
form.style = self.widget(QtGui.QComboBox, "lineStyle")
|
||||||
self.plt = plt
|
form.marker = self.widget(QtGui.QComboBox, "markers")
|
||||||
self.form.items.clear()
|
form.width = self.widget(QtGui.QDoubleSpinBox, "lineWidth")
|
||||||
return
|
form.size = self.widget(QtGui.QSpinBox, "markerSize")
|
||||||
self.skip = True
|
# Ensure that selected serie exist
|
||||||
# Refill list
|
if self.item >= len(Plot.series()):
|
||||||
if self.plt != plt or len(Plot.series()) != self.form.items.count():
|
self.updateUI()
|
||||||
self.plt = plt
|
return
|
||||||
self.setList()
|
# Set label
|
||||||
# Ensure that have series
|
serie = Plot.series()[self.item]
|
||||||
if not len(Plot.series()):
|
if(form.isLabel.isChecked()):
|
||||||
self.form.label.setEnabled(False)
|
serie.name = None
|
||||||
self.form.isLabel.setEnabled(False)
|
form.label.setEnabled(False)
|
||||||
self.form.style.setEnabled(False)
|
else:
|
||||||
self.form.marker.setEnabled(False)
|
serie.name = form.label.text()
|
||||||
self.form.width.setEnabled(False)
|
form.label.setEnabled(True)
|
||||||
self.form.size.setEnabled(False)
|
# Set line style and marker
|
||||||
self.form.color.setEnabled(False)
|
style = form.style.currentIndex()
|
||||||
self.form.remove.setEnabled(False)
|
linestyles = Line2D.lineStyles.keys()
|
||||||
return
|
serie.line.set_linestyle(linestyles[style])
|
||||||
# Set label
|
marker = form.marker.currentIndex()
|
||||||
serie = Plot.series()[self.item]
|
markers = Line2D.markers.keys()
|
||||||
if serie.name == None:
|
serie.line.set_marker(markers[marker])
|
||||||
self.form.isLabel.setChecked(True)
|
# Set line width and marker size
|
||||||
self.form.label.setEnabled(False)
|
serie.line.set_linewidth(form.width.value())
|
||||||
self.form.label.setText("")
|
serie.line.set_markersize(form.size.value())
|
||||||
else:
|
plt.update()
|
||||||
self.form.isLabel.setChecked(False)
|
# Regenerate series labels
|
||||||
self.form.label.setText(serie.name)
|
self.setList()
|
||||||
# Set line style and marker
|
self.skip = False
|
||||||
self.form.style.setCurrentIndex(0)
|
|
||||||
linestyles = Line2D.lineStyles.keys()
|
def onColor(self):
|
||||||
for i in range(0,len(linestyles)):
|
""" Executed when color pallete is requested. """
|
||||||
style = linestyles[i]
|
plt = Plot.getPlot()
|
||||||
if style == serie.line.get_linestyle():
|
if not plt:
|
||||||
self.form.style.setCurrentIndex(i)
|
self.updateUI()
|
||||||
self.form.marker.setCurrentIndex(0)
|
return
|
||||||
markers = Line2D.markers.keys()
|
mw = self.getMainWindow()
|
||||||
for i in range(0,len(markers)):
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
marker = markers[i]
|
form.color = self.widget(QtGui.QPushButton, "color")
|
||||||
if marker == serie.line.get_marker():
|
|
||||||
self.form.marker.setCurrentIndex(i)
|
# Ensure that selected serie exist
|
||||||
# Set line width and marker size
|
if self.item >= len(Plot.series()):
|
||||||
self.form.width.setValue(serie.line.get_linewidth())
|
self.updateUI()
|
||||||
self.form.size.setValue(serie.line.get_markersize())
|
return
|
||||||
# Set color
|
# Show widget to select color
|
||||||
color = Colors.colorConverter.to_rgb(serie.line.get_color())
|
col = QtGui.QColorDialog.getColor()
|
||||||
self.form.color.setStyleSheet("background-color: rgb(%d, %d, %d);" % (int(color[0]*255),
|
# Send color to widget and serie
|
||||||
int(color[1]*255), int(color[2]*255)))
|
if col.isValid():
|
||||||
self.skip = False
|
serie = plt.series[self.item]
|
||||||
|
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()
|
||||||
|
|
||||||
|
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 onMdiArea(self, subWin):
|
||||||
|
"""Executed when a new window is selected on the mdi area.
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
subWin -- Selected window.
|
||||||
|
"""
|
||||||
|
plt = Plot.getPlot()
|
||||||
|
if plt != subWin:
|
||||||
|
self.updateUI()
|
||||||
|
|
||||||
|
def updateUI(self):
|
||||||
|
""" Setup UI controls values if possible """
|
||||||
|
mw = self.getMainWindow()
|
||||||
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
|
form.items = self.widget(QtGui.QListWidget, "items")
|
||||||
|
form.label = self.widget(QtGui.QLineEdit, "label")
|
||||||
|
form.isLabel = self.widget(QtGui.QCheckBox, "isLabel")
|
||||||
|
form.style = self.widget(QtGui.QComboBox, "lineStyle")
|
||||||
|
form.marker = self.widget(QtGui.QComboBox, "markers")
|
||||||
|
form.width = self.widget(QtGui.QDoubleSpinBox, "lineWidth")
|
||||||
|
form.size = self.widget(QtGui.QSpinBox, "markerSize")
|
||||||
|
form.color = self.widget(QtGui.QPushButton, "color")
|
||||||
|
form.remove = self.widget(QtGui.QPushButton, "remove")
|
||||||
|
plt = Plot.getPlot()
|
||||||
|
form.items.setEnabled(bool(plt))
|
||||||
|
form.label.setEnabled(bool(plt))
|
||||||
|
form.isLabel.setEnabled(bool(plt))
|
||||||
|
form.style.setEnabled(bool(plt))
|
||||||
|
form.marker.setEnabled(bool(plt))
|
||||||
|
form.width.setEnabled(bool(plt))
|
||||||
|
form.size.setEnabled(bool(plt))
|
||||||
|
form.color.setEnabled(bool(plt))
|
||||||
|
form.remove.setEnabled(bool(plt))
|
||||||
|
if not plt:
|
||||||
|
self.plt = plt
|
||||||
|
form.items.clear()
|
||||||
|
return
|
||||||
|
self.skip = True
|
||||||
|
# Refill list
|
||||||
|
if self.plt != plt or len(Plot.series()) != form.items.count():
|
||||||
|
self.plt = plt
|
||||||
|
self.setList()
|
||||||
|
# Ensure that have series
|
||||||
|
if not len(Plot.series()):
|
||||||
|
form.label.setEnabled(False)
|
||||||
|
form.isLabel.setEnabled(False)
|
||||||
|
form.style.setEnabled(False)
|
||||||
|
form.marker.setEnabled(False)
|
||||||
|
form.width.setEnabled(False)
|
||||||
|
form.size.setEnabled(False)
|
||||||
|
form.color.setEnabled(False)
|
||||||
|
form.remove.setEnabled(False)
|
||||||
|
return
|
||||||
|
# Set label
|
||||||
|
serie = Plot.series()[self.item]
|
||||||
|
if serie.name is None:
|
||||||
|
form.isLabel.setChecked(True)
|
||||||
|
form.label.setEnabled(False)
|
||||||
|
form.label.setText("")
|
||||||
|
else:
|
||||||
|
form.isLabel.setChecked(False)
|
||||||
|
form.label.setText(serie.name)
|
||||||
|
# Set line style and marker
|
||||||
|
form.style.setCurrentIndex(0)
|
||||||
|
linestyles = Line2D.lineStyles.keys()
|
||||||
|
for i in range(0, len(linestyles)):
|
||||||
|
style = linestyles[i]
|
||||||
|
if style == serie.line.get_linestyle():
|
||||||
|
form.style.setCurrentIndex(i)
|
||||||
|
form.marker.setCurrentIndex(0)
|
||||||
|
markers = Line2D.markers.keys()
|
||||||
|
for i in range(0, len(markers)):
|
||||||
|
marker = markers[i]
|
||||||
|
if marker == serie.line.get_marker():
|
||||||
|
form.marker.setCurrentIndex(i)
|
||||||
|
# Set line width and marker size
|
||||||
|
form.width.setValue(serie.line.get_linewidth())
|
||||||
|
form.size.setValue(serie.line.get_markersize())
|
||||||
|
# Set color
|
||||||
|
color = Colors.colorConverter.to_rgb(serie.line.get_color())
|
||||||
|
form.color.setStyleSheet("background-color: rgb({}, {}, {});".format(
|
||||||
|
int(color[0] * 255),
|
||||||
|
int(color[1] * 255),
|
||||||
|
int(color[2] * 255)))
|
||||||
|
self.skip = False
|
||||||
|
|
||||||
|
def setList(self):
|
||||||
|
"""Setup the UI control values if it is possible."""
|
||||||
|
mw = self.getMainWindow()
|
||||||
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
|
form.items = self.widget(QtGui.QListWidget, "items")
|
||||||
|
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
|
||||||
|
form.items.addItem(string)
|
||||||
|
# Ensure that selected item is correct
|
||||||
|
if len(series) and self.item >= len(series):
|
||||||
|
self.item = len(series) - 1
|
||||||
|
form.items.setCurrentIndex(self.item)
|
||||||
|
|
||||||
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():
|
def createTask():
|
||||||
panel = TaskPanel()
|
panel = TaskPanel()
|
||||||
Gui.Control.showDialog(panel)
|
Gui.Control.showDialog(panel)
|
||||||
if panel.setupUi():
|
if panel.setupUi():
|
||||||
Gui.Control.closeDialog(panel)
|
Gui.Control.closeDialog(panel)
|
||||||
return None
|
return None
|
||||||
return panel
|
return panel
|
||||||
|
|
|
@ -21,16 +21,9 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
# FreeCAD modules
|
|
||||||
import FreeCAD
|
|
||||||
import FreeCADGui
|
|
||||||
|
|
||||||
# Qt libraries
|
|
||||||
from PyQt4 import QtGui,QtCore
|
|
||||||
|
|
||||||
# Main object
|
|
||||||
import TaskPanel
|
import TaskPanel
|
||||||
|
|
||||||
|
|
||||||
def load():
|
def load():
|
||||||
""" Loads the tool """
|
"""Load the tool"""
|
||||||
TaskPanel.createTask()
|
TaskPanel.createTask()
|
||||||
|
|
|
@ -21,11 +21,13 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
import FreeCAD, FreeCADGui, os
|
import FreeCAD
|
||||||
|
import FreeCADGui
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def modulePath():
|
def modulePath():
|
||||||
"""returns the current Plot module path
|
"""returns the current Plot module path."""
|
||||||
@return Module path"""
|
|
||||||
path1 = FreeCAD.ConfigGet("AppHomePath") + "Mod/Plot"
|
path1 = FreeCAD.ConfigGet("AppHomePath") + "Mod/Plot"
|
||||||
path2 = FreeCAD.ConfigGet("UserAppData") + "Mod/Plot"
|
path2 = FreeCAD.ConfigGet("UserAppData") + "Mod/Plot"
|
||||||
if os.path.exists(path2):
|
if os.path.exists(path2):
|
||||||
|
@ -33,29 +35,14 @@ def modulePath():
|
||||||
else:
|
else:
|
||||||
return path1
|
return path1
|
||||||
|
|
||||||
|
|
||||||
def iconsPath():
|
def iconsPath():
|
||||||
"""returns the current Plot module icons path
|
"""returns the current Plot module icons path."""
|
||||||
@return Icons path"""
|
|
||||||
path = modulePath() + "/resources/icons"
|
path = modulePath() + "/resources/icons"
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
def translationsPath():
|
def translationsPath():
|
||||||
"""returns the current Plot module translations path
|
"""returns the current Plot module translations path."""
|
||||||
@return Icons path"""
|
|
||||||
path = modulePath() + "/resources/translations"
|
path = modulePath() + "/resources/translations"
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def getPathFromFile(fileName):
|
|
||||||
""" Gets the directory path from a file name
|
|
||||||
@param fileName Name of the file
|
|
||||||
@return Directory path.
|
|
||||||
"""
|
|
||||||
if not fileName:
|
|
||||||
return ''
|
|
||||||
i = 1
|
|
||||||
try:
|
|
||||||
while 1:
|
|
||||||
i = fileName.index("/", i+1)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
return fileName[0:i+1]
|
|
||||||
|
|
|
@ -20,6 +20,3 @@
|
||||||
#* USA *
|
#* USA *
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
# Empty file to treat the folder as a package
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user