예제 #1
0
    def buildWidget(self):
        """Create the widget and populate it."""
        
        self._currentFigure = None

        # Create enclosing widget and UI
        self._widget = QWidget()
        self._ui = Ui_EditFigureDialog()
        self._ui.setupUi(self._widget)
        
        self.setModels()

        # Connect signals for buttons at top of widget
        self._ui.addFigureButton.clicked.connect(self.createFigure)
        self._ui.showFigureButton.clicked.connect(self.showFigure)
        self._ui.deleteFigureButton.clicked.connect(self.deleteFigure)

        # Setup figure tab
        self._figureTab = QFigureOptionsWidget(self._widget)
        figureOW = Ui_FigureOptionsWidget()
        figureOW.setupUi(self._figureTab)
        self._figureTab.setUiObject(figureOW)
        self._figureTab.setEditFigureDialogModule(self)
        self._ui.tabWidget.insertTab(0, self._figureTab, "Figure")

        # Setup plot tab
        self._plotTab = QPlotOptionsWidget(self._widget)
        plotOW = Ui_PlotOptionsWidget()
        plotOW.setupUi(self._plotTab)
        self._plotTab.setUiObject(plotOW)
        self._plotTab.setEditFigureDialogModule(self)
        self._plotTab.initPlotSelector()
        self._plotTab.initSubWidgets()
        self._ui.tabWidget.insertTab(1, self._plotTab, "Plot")

        # If the number of rows or columns is changed, then we need to refresh the plot list
        # It's simpler to just always check this when the Apply button is pressed
        figureOW.buttons.button(QDialogButtonBox.Apply).clicked.connect(self._plotTab.refreshPlotSelector)


        # Make sure that the figure tab is initially displayed
        self._ui.tabWidget.setCurrentIndex(0)
예제 #2
0
class EditFigureDialog(Module):
    """Module to display the Edit Figure dialog window."""

    def __init__(self):
        Module.__init__(self)

    def buildWidget(self):
        """Create the widget and populate it."""
        
        self._currentFigure = None

        # Create enclosing widget and UI
        self._widget = QWidget()
        self._ui = Ui_EditFigureDialog()
        self._ui.setupUi(self._widget)
        
        self.setModels()

        # Connect signals for buttons at top of widget
        self._ui.addFigureButton.clicked.connect(self.createFigure)
        self._ui.showFigureButton.clicked.connect(self.showFigure)
        self._ui.deleteFigureButton.clicked.connect(self.deleteFigure)

        # Setup figure tab
        self._figureTab = QFigureOptionsWidget(self._widget)
        figureOW = Ui_FigureOptionsWidget()
        figureOW.setupUi(self._figureTab)
        self._figureTab.setUiObject(figureOW)
        self._figureTab.setEditFigureDialogModule(self)
        self._ui.tabWidget.insertTab(0, self._figureTab, "Figure")

        # Setup plot tab
        self._plotTab = QPlotOptionsWidget(self._widget)
        plotOW = Ui_PlotOptionsWidget()
        plotOW.setupUi(self._plotTab)
        self._plotTab.setUiObject(plotOW)
        self._plotTab.setEditFigureDialogModule(self)
        self._plotTab.initPlotSelector()
        self._plotTab.initSubWidgets()
        self._ui.tabWidget.insertTab(1, self._plotTab, "Plot")

        # If the number of rows or columns is changed, then we need to refresh the plot list
        # It's simpler to just always check this when the Apply button is pressed
        figureOW.buttons.button(QDialogButtonBox.Apply).clicked.connect(self._plotTab.refreshPlotSelector)


        # Make sure that the figure tab is initially displayed
        self._ui.tabWidget.setCurrentIndex(0)

    def setModels(self):
        # Setup figure list
        self._figureListModel = FigureListModel(self._app.figures())
        self._ui.figureSelector.setModel(self._figureListModel)
        self._ui.figureSelector.currentIndexChanged[int].connect(self.changeCurrentFigure)
        self._app.figures().figureAdded.connect(self._figureListModel.doReset)
        self._app.figures().figureRemoved.connect(self._figureListModel.doReset)
        self._app.figures().figureRenamed.connect(self.updateFigureSelectorBox)

    #
    # Handlers for the three buttons at the top of the widget
    #
    def createFigure(self):
        figure = Figure("NewFigure")
        self._app.figures().addFigure(figure)

        # Select figure
        self._ui.figureSelector.setCurrentIndex(self._ui.figureSelector.model().rowCount() - 1)

    def showFigure(self):
        """Display the figure, in case it got hidden."""
        
        if self.currentFigure():
            self.currentFigure().showFigure()

    def deleteFigure(self):
        """
        Delete button has been pressed.  Make sure the user really wants
        to delete the figure.
        """
        
        figure = self.currentFigure()
        
        # Make sure we are on a valid figure
        if not figure:
            return False
        
        # Ask user if they really want to delete the figure
        questionMessage = QMessageBox()
        questionMessage.setIcon(QMessageBox.Question)
        questionMessage.setText("You are about to delete a figure.")
        questionMessage.setInformativeText("Are you sure this is what you want to do?")
        questionMessage.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
        questionMessage.setDefaultButton(QMessageBox.No)
        answer = questionMessage.exec_()

        if answer == QMessageBox.Yes:
            figure.hideFigure()
            self._app.figures().removeFigure(figure)
            self.changeCurrentFigure(0)
            self.updateFigureSelectorIndex(0)

    #
    # Get current items
    #
    def currentFigure(self):
        return self._currentFigure

    def changeCurrentFigure(self, index):
        if index < 0:
            return
        
        self._currentFigure = self._ui.figureSelector.model().getFigure(index)
        self._figureTab.resetUi()
        self._plotTab.setFigure(self._currentFigure)

    # Update figure selector combo boxes
    def updateFigureSelectorBox(self):
        # Figure name may have changed, so we'll reset the figure combo box
        # But keep the same figure selected
        figure = self.currentFigure()

        # We are not actually changing the current figure, so we will disconnect this signal for the moment
        self._ui.figureSelector.currentIndexChanged[int].disconnect(self.changeCurrentFigure)

        currentFigureIndex = self._ui.figureSelector.currentIndex()
        self._ui.figureSelector.model().doReset()
        self._ui.figureSelector.setCurrentIndex(currentFigureIndex)
        
        self._ui.figureSelector.currentIndexChanged[int].connect(self.changeCurrentFigure)
    
    def updateFigureSelectorIndex(self, index):
        """
        Programmatically change the selected entry in the figure selector box.
        This is useful for deleting figures and also for loading a project.
        """

        if index < 0:
            return

        self._ui.figureSelector.setCurrentIndex(index)


    """Module-required methods"""
    def getMenuNameToAddTo(self):
        return "menuPlot"

    def prepareMenuItem(self, menu):
        menu.setObjectName("actionEditFiguresDialog")
        menu.setShortcut("Ctrl+E")
        menu.setText("Edit Figures")
        return menu

    def load(self):
        self.window = SubWindow(self._app.ui.workspace)

        self.menuEntry = QAction(self._app)
        self.menuEntry.setObjectName("actionEditFiguresDialog")
        self.menuEntry.setShortcut("Ctrl+F")
        self.menuEntry.setText("Edit Figures")
        self.menuEntry.triggered.connect(self.window.show)
        self.menu = vars(self._app.ui)["menuPlot"]
        self.menu.addAction(self.menuEntry)

        self.buildWidget()
        self.window.setWidget(self._widget)
        self._widget.setParent(self.window)

        self.window.hide()

    def unload(self):
        # Disconnect some slots
        self._app.figures().figureAdded.disconnect(self._figureListModel.doReset)
        self._app.figures().figureRemoved.disconnect(self._figureListModel.doReset)
        self.menuEntry.triggered.disconnect()

        self._widget.deleteLater()
        self.window.deleteLater()
        self.menu.removeAction(self.menuEntry)

    def reload(self):
        self.setModels()
        self._plotTab.reload()
        self._figureTab.reload()