diff --git a/CHANGELOG.md b/CHANGELOG.md index 96187f61..f9660b44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ CHANGELOG for FlatCAM beta ================================================= +15.12.2020 + +- modified the way that the plotcanvas widget is added + 14.12.2020 - added new functionality: centering in origin for a selection of objects diff --git a/appGUI/GUIElements.py b/appGUI/GUIElements.py index a7df898d..ebb07b16 100644 --- a/appGUI/GUIElements.py +++ b/appGUI/GUIElements.py @@ -2663,7 +2663,7 @@ class FCDetachableTab(QtWidgets.QTabWidget): From here: https://stackoverflow.com/questions/47267195/in-pyqt4-is-it-possible-to-detach-tabs-from-a-qtabwidget """ - tab_detached = QtCore.pyqtSignal(str) + tab_detached = QtCore.pyqtSignal(QtWidgets.QWidget, str) tab_attached = QtCore.pyqtSignal(str) def __init__(self, protect=None, protect_by_name=None, parent=None): @@ -2845,7 +2845,7 @@ class FCDetachableTab(QtWidgets.QTabWidget): # Create a reference to maintain access to the detached tab self.detachedTabs[name] = detachedTab - self.tab_detached.emit(name) + self.tab_detached.emit(detachedTab, name) def attachTab(self, contentWidget, name, icon, insertAt=None): """ @@ -3033,8 +3033,16 @@ class FCDetachableTab(QtWidgets.QTabWidget): self.setObjectName(name) self.setWindowTitle(name) + # create a widget to be set as centraWidget + self.c_widget = QtWidgets.QWidget() + self.central_layout = QtWidgets.QVBoxLayout() + self.c_widget.setLayout(self.central_layout) + + # add our widget to the central layout self.contentWidget = contentWidget - self.setCentralWidget(self.contentWidget) + self.central_layout.addWidget(self.contentWidget) + + self.setCentralWidget(self.c_widget) self.contentWidget.show() self.windowDropFilter = self.WindowDropFilter() diff --git a/appGUI/PlotCanvas.py b/appGUI/PlotCanvas.py index 1f8f6fd9..0bc45273 100644 --- a/appGUI/PlotCanvas.py +++ b/appGUI/PlotCanvas.py @@ -31,13 +31,12 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): Class handling the plotting area in the application. """ - def __init__(self, container, fcapp): + def __init__(self, fcapp): """ The constructor configures the VisPy figure that will contain all plots, creates the base axes and connects events to the plotting area. - :param container: The parent container in which to draw plots. :rtype: PlotCanvas """ @@ -51,9 +50,6 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): self.fcapp = fcapp - # Parent container - self.container = container - settings = QtCore.QSettings("Open Source", "FlatCAM") if settings.contains("theme"): theme = settings.value('theme', type=str) @@ -131,9 +127,6 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): self.create_native() self.native.setParent(self.fcapp.ui) - # - self.container.addWidget(self.native) - # ## AXIS # ## self.v_line = InfiniteLine(pos=0, color=(0.70, 0.3, 0.3, 0.8), vertical=True, parent=self.view.scene) @@ -212,12 +205,21 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): self.c = None self.big_cursor = None + + # Parent container + # self.container = container + # Keep VisPy canvas happy by letting it be "frozen" again. self.freeze() + + # fit everything into view self.fit_view() self.graph_event_connect('mouse_wheel', self.on_mouse_scroll) + # + # self.container.addWidget(self.native) + def on_toggle_axis(self, signal=None, state=None, silent=None): if not state: state = not self.axis_enabled diff --git a/appGUI/PlotCanvasLegacy.py b/appGUI/PlotCanvasLegacy.py index 24767a74..e3104b23 100644 --- a/appGUI/PlotCanvasLegacy.py +++ b/appGUI/PlotCanvasLegacy.py @@ -132,13 +132,12 @@ class PlotCanvasLegacy(QtCore.QObject): double_click = QtCore.pyqtSignal(object) - def __init__(self, container, app): + def __init__(self, app): """ The constructor configures the Matplotlib figure that will contain all plots, creates the base axes and connects events to the plotting area. - :param container: The parent container in which to draw plots. :rtype: PlotCanvas """ @@ -220,7 +219,7 @@ class PlotCanvasLegacy(QtCore.QObject): self.y_margin = 25 # Pixels # Parent container - self.container = container + # self.container = container # Plots go onto a single matplotlib.figure self.figure = Figure(dpi=50) @@ -257,10 +256,6 @@ class PlotCanvasLegacy(QtCore.QObject): self.adjust_axes(-10, -10, 100, 100) # self.canvas.set_can_focus(True) # For key press - # Attach to parent - # self.container.attach(self.canvas, 0, 0, 600, 400) - self.container.addWidget(self.canvas) # Qt - # Copy a bitmap of the canvas for quick animation. # Update every time the canvas is re-drawn. self.background = self.canvas.copy_from_bbox(self.axes.bbox) @@ -334,6 +329,11 @@ class PlotCanvasLegacy(QtCore.QObject): } """) + # Attach to parent + self.native = self.canvas # for API compatibility with 3D plotcanvas + # self.container.attach(self.canvas, 0, 0, 600, 400) + # self.container.addWidget(self.canvas) # Qt + def on_toggle_axis(self, signal=None, state=None, silent=None): if not state: state = not self.axis_enabled diff --git a/app_Main.py b/app_Main.py index 3ec4be55..969c9726 100644 --- a/app_Main.py +++ b/app_Main.py @@ -1121,6 +1121,9 @@ class App(QtCore.QObject): if self.plotcanvas == 'fail': return + # add he PlotCanvas setup to the UI + self.on_plotcanvas_add(self.plotcanvas, self.ui.right_layout) + # Storage for shapes, storage that can be used by FlatCAm tools for utility geometry # VisPy visuals if self.is_legacy is False: @@ -1545,7 +1548,7 @@ class App(QtCore.QObject): # ########################################################################################################### self.log.debug("END of constructor. Releasing control.") self.log.debug("... Resistance is futile. You will be assimilated ...") - self.log.debug("... I disagree. We will not be vaccinated ... We are free!\n") + self.log.debug("... I disagree. While we live and breath, we can be free!\n") # ########################################################################################################### # ########################################## SHOW GUI ####################################################### @@ -8049,10 +8052,10 @@ class App(QtCore.QObject): if self.is_legacy is True or modifier == QtCore.Qt.ControlModifier: self.is_legacy = True self.defaults["global_graphic_engine"] = "2D" - plotcanvas = PlotCanvasLegacy(plot_container, self) + plotcanvas = PlotCanvasLegacy(self) else: try: - plotcanvas = PlotCanvas(plot_container, self) + plotcanvas = PlotCanvas(self) except Exception as er: msg_txt = traceback.format_exc() self.log.debug("App.on_plotcanvas_setup() failed -> %s" % str(er)) @@ -8092,6 +8095,18 @@ class App(QtCore.QObject): return plotcanvas + def on_plotcanvas_add(self, plotcanvas_obj, container): + """ + + :param plotcanvas_obj: the class that setup the canvas + :type plotcanvas_obj: class + :param container: a layout where to add the native widget of the plotcanvas_obj class + :type container: + :return: Nothing + :rtype: None + """ + container.addWidget(plotcanvas_obj.native) + def on_zoom_fit(self): """ Callback for zoom-fit request. This can be either from the corresponding