Skip to content

Node with matplotlib widget saving error #480

@d-ryabov-biomsu

Description

@d-ryabov-biomsu

Hi, thank you for such a good project!
I created a node with a Matplotlib widget using the Qt5 backend. If I try to save an image using the matplotlib toolbar below the canvas, a dialog window appears inside the node, and all my interface freezes. So I have to kill my program. It was expected a new window would appear for saving the image.

Image

Code for creating a custom matplotlib widget and node:

from NodeGraphQt import BaseNode, NodeBaseWidget
from Qt import QtWidgets
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
import matplotlib.pyplot as plt

class TemplatePlotWidget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super().__init__()
        
        highlightColor = str('white')
        self.setFixedSize(600, 400)
        self.mainLayout = QtWidgets.QVBoxLayout(self)   
        self.mainLayout.setSpacing(10)
        self.figure = plt.figure(facecolor=highlightColor)
        self.canvas = FigureCanvas(self.figure)
        
        self.toolbar = NavigationToolbar(self.canvas, self)
        self.mainLayout.addWidget(self.canvas)
        self.mainLayout.addWidget(self.toolbar)
    
        
class TemplatePlotWidgetWrapper(NodeBaseWidget):
    def __init__(self, parent=None, fretData=None):
        super().__init__(parent)
        self.plot_widget = TemplatePlotWidget(parent=parent)
        self.set_custom_widget(self.plot_widget)
        self.fretData=fretData
    
        self.plot_widget.figure.clf()

    def get_value(self):
        return self.fretData
    
    def set_value(self, fretData):
        self.fretData = fretData
                
             
class BGPlotterNode(BaseNode):
    __identifier__ = 'nodes.custom'
    NODE_NAME = 'BGPlotterNode'
    
    def __init__(self):
        super().__init__() 
        
        self.plot_widget = TemplatePlotWidgetWrapper(parent=self.view)
        self.plot_widget.set_name('plotter')
        self.add_custom_widget(self.plot_widget, tab='custom')

package versions:
NodeGraphQt version: 0.6.43
Qt.py version: 1.4.7
Python version: 3.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions