Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 52 additions & 80 deletions freecad/plot/PlotGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,154 +27,126 @@
import FreeCAD
import FreeCADGui

QT_TRANSLATE_NOOP = FreeCAD.Qt.QT_TRANSLATE_NOOP

FreeCADGui.addLanguagePath(os.path.join(os.path.dirname(__file__),
"resources/translations"))
FreeCADGui.addIconPath(os.path.join(os.path.dirname(__file__),
"resources/icons"))
FreeCADGui.addLanguagePath(
os.path.join(os.path.dirname(__file__), "resources", "translations")
)
FreeCADGui.addIconPath(os.path.join(os.path.dirname(__file__), "resources", "icons"))


class Save:
def Activated(self):
from freecad.plot import plotSave

plotSave.load()

def GetResources(self):
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': 'Plot_Save',
'MenuText': MenuText,
'ToolTip': ToolTip}
MenuText = QT_TRANSLATE_NOOP("Plot_SaveFig", "Save plot")
ToolTip = QT_TRANSLATE_NOOP("Plot_SaveFig", "Save the plot as an image file")
return {"Pixmap": "Plot_Save", "MenuText": MenuText, "ToolTip": ToolTip}


class Axes:
def Activated(self):
from freecad.plot import plotAxes

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': 'Plot_Axes',
'MenuText': MenuText,
'ToolTip': ToolTip}
MenuText = QT_TRANSLATE_NOOP("Plot_Axes", "Configure axes")
ToolTip = QT_TRANSLATE_NOOP("Plot_Axes", "Configure the axes parameters")
return {"Pixmap": "Plot_Axes", "MenuText": MenuText, "ToolTip": ToolTip}


class Series:
def Activated(self):
from freecad.plot import plotSeries

plotSeries.load()

def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
"Plot_Series",
"Configure series")
ToolTip = QtCore.QT_TRANSLATE_NOOP(
"Plot_Series",
"Configure series drawing style and label")
return {'Pixmap': 'Plot_Series',
'MenuText': MenuText,
'ToolTip': ToolTip}
MenuText = QT_TRANSLATE_NOOP("Plot_Series", "Configure series")
ToolTip = QT_TRANSLATE_NOOP(
"Plot_Series", "Configure series drawing style and label"
)
return {"Pixmap": "Plot_Series", "MenuText": MenuText, "ToolTip": ToolTip}


class Grid:
def Activated(self):
from FreeCAD.Plot import Plot

plt = Plot.getPlot()
if not plt:
msg = QtGui.QApplication.translate(
msg = App.Qt.translate(
"plot_console",
"The grid must be activated on top of a plot document",
None)
None,
)
FreeCAD.Console.PrintError(msg + "\n")
return
flag = plt.isGrid()
Plot.grid(not flag)

def GetResources(self):
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': 'Plot_Grid',
'MenuText': MenuText,
'ToolTip': ToolTip}
MenuText = QT_TRANSLATE_NOOP("Plot_Grid", "Show/Hide grid")
ToolTip = QT_TRANSLATE_NOOP("Plot_Grid", "Show/Hide grid on selected plot")
return {"Pixmap": "Plot_Grid", "MenuText": MenuText, "ToolTip": ToolTip}


class Legend:
def Activated(self):
from FreeCAD.Plot import Plot

plt = Plot.getPlot()
if not plt:
msg = QtGui.QApplication.translate(
msg = App.Qt.translate(
"plot_console",
"The legend must be activated on top of a plot document",
None)
None,
)
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': 'Plot_Legend',
'MenuText': MenuText,
'ToolTip': ToolTip}
MenuText = QT_TRANSLATE_NOOP("Plot_Legend", "Show/Hide legend")
ToolTip = QT_TRANSLATE_NOOP("Plot_Legend", "Show/Hide legend on selected plot")
return {"Pixmap": "Plot_Legend", "MenuText": MenuText, "ToolTip": ToolTip}


class Labels:
def Activated(self):
from freecad.plot import plotLabels

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': 'Plot_Labels',
'MenuText': MenuText,
'ToolTip': ToolTip}
MenuText = QT_TRANSLATE_NOOP("Plot_Labels", "Set labels")
ToolTip = QT_TRANSLATE_NOOP("Plot_Labels", "Set title and axes labels")
return {"Pixmap": "Plot_Labels", "MenuText": MenuText, "ToolTip": ToolTip}


class Positions:
def Activated(self):
from freecad.plot import plotPositions

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': 'Plot_Positions',
'MenuText': MenuText,
'ToolTip': ToolTip}


FreeCADGui.addCommand('Plot_SaveFig', Save())
FreeCADGui.addCommand('Plot_Axes', Axes())
FreeCADGui.addCommand('Plot_Series', Series())
FreeCADGui.addCommand('Plot_Grid', Grid())
FreeCADGui.addCommand('Plot_Legend', Legend())
FreeCADGui.addCommand('Plot_Labels', Labels())
FreeCADGui.addCommand('Plot_Positions', Positions())
MenuText = QT_TRANSLATE_NOOP("Plot_Positions", "Set positions and sizes")
ToolTip = QT_TRANSLATE_NOOP(
"Plot_Positions", "Set labels and legend positions and sizes"
)
return {"Pixmap": "Plot_Positions", "MenuText": MenuText, "ToolTip": ToolTip}


FreeCADGui.addCommand("Plot_SaveFig", Save())
FreeCADGui.addCommand("Plot_Axes", Axes())
FreeCADGui.addCommand("Plot_Series", Series())
FreeCADGui.addCommand("Plot_Grid", Grid())
FreeCADGui.addCommand("Plot_Legend", Legend())
FreeCADGui.addCommand("Plot_Labels", Labels())
FreeCADGui.addCommand("Plot_Positions", Positions())
47 changes: 25 additions & 22 deletions freecad/plot/init_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,52 +48,55 @@
elif len(sorted_style_list) == 1:
matplotlib.style.use(sorted_style_list[0])
else:
from PySide import QtCore, QtGui
msg = QtGui.QApplication.translate(
"plot_console",
"matplotlib style sheets not found",
None)
FreeCAD.Console.PrintWarning(msg + '\n')
FreeCAD.Console.PrintWarning(
FreeCAD.Qt.translate("plot_console", "matplotlib style sheets not found") + "\n"
)
matplotlib.rcParams["figure.facecolor"] = "efefef"
matplotlib.rcParams["axes.facecolor"] = "efefef"

plt.ion()

__dir__ = os.path.dirname(__file__)


class PlotWorkbench(Gui.Workbench):
"""Workbench of Plot module."""

def __init__(self):
self.__class__.Icon = os.path.join(__dir__, "resources", "icons", "Plot_Workbench.svg")
self.__class__.MenuText = "Plot"
self.__class__.ToolTip = "The Plot module is used to edit/save output plots performed by other tools"
Gui.addLanguagePath(os.path.join(__dir__, "resources", "translations"))
Gui.updateLocale()
self.__class__.Icon = os.path.join(
__dir__, "resources", "icons", "Plot_Workbench.svg"
)
self.__class__.MenuText = FreeCAD.Qt.translate("Workbench", "Plot")
self.__class__.ToolTip = FreeCAD.Qt.translate(
"Workbench",
"The Plot module is used to edit/save output plots performed by other tools",
)

import freecad.plot.PlotGui

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)
QT_TRANSLATE_NOOP = FreeCAD.Qt.QT_TRANSLATE_NOOP

self.appendToolbar(QT_TRANSLATE_NOOP("Plot", "Plot edition tools"), cmdlst)
self.appendMenu(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)
FreeCAD.Console.PrintMessage(msg + '\n')
FreeCAD.Console.PrintMessage(
FreeCAD.Qt.translate(
"plot_console", "matplotlib not found, Plot module will be disabled"
)
+ "\n"
)


Gui.addWorkbench(PlotWorkbench())
Loading