Beispiel #1
0
    def closeEvent(self, event: QCloseEvent):
        '''
        Closeevent

        Parameters
        ----------
        event : QCloseEvent
        '''
        logger.debug('FloatingDockContainer closeEvent')
        self.d.set_state(DragState.inactive)
        if not self.is_closable():
            event.ignore()
            return

        # In Qt version after 5.9.2 there seems to be a bug that causes the
        # QWidget.event() function to not receive any NonClientArea mouse
        # events anymore after a close/show cycle. The bug is reported here:
        # https://bugreports.qt.io/browse/QTBUG-73295
        # The following code is a workaround for Qt versions > 5.9.2 that seems
        # to work
        # Starting from Qt version 5.12.2 this seems to work again. But
        # now the QEvent.NonClientAreaMouseButtonPress function returns always
        # Qt.RightButton even if the left button was pressed
        if (5, 9, 2) < QT_VERSION_TUPLE < (5, 12, 2):
            event.ignore()
            self.hide()
        else:
            super().closeEvent(event)
Beispiel #2
0
    def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
        if self.main.converting:
            sm = QtWidgets.QMessageBox()
            sm.setText("<h2>There is a conversion in process!</h2>")
            sm.addButton("Cancel Conversion", QtWidgets.QMessageBox.RejectRole)
            sm.addButton("Close GUI Only",
                         QtWidgets.QMessageBox.DestructiveRole)
            sm.addButton("Keep FastFlix Open",
                         QtWidgets.QMessageBox.AcceptRole)
            sm.exec_()
            if sm.clickedButton().text() == "Cancel Conversion":
                self.main.worker_queue.put(["cancel"])
                self.main.close()
            elif sm.clickedButton().text() == "Close GUI Only":
                self.main.close(no_cleanup=True)
                return super(Container, self).closeEvent(a0)
            else:
                a0.ignore()
                return

        for item in self.main.path.work.iterdir():
            if item.is_dir() and item.stem.startswith("temp_"):
                shutil.rmtree(item, ignore_errors=True)
            if item.name.lower().endswith((".jpg", ".jpeg", ".png", ".gif")):
                item.unlink()
        super(Container, self).closeEvent(a0)
Beispiel #3
0
 def closeEvent(self, event: QCloseEvent) -> None:
     """Called on closing window."""
     if self.should_close_document(self.tr("Quit")):
         gp.dump_prefs(self.pref)
         event.accept()
     else:
         event.ignore()
Beispiel #4
0
    def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
        if self.pb:
            try:
                self.pb.stop_signal.emit()
            except Exception:
                pass
        if self.main.converting:
            sm = QtWidgets.QMessageBox()
            sm.setText(f"<h2>{t('There is a conversion in process!')}</h2>")
            sm.addButton(t("Cancel Conversion"), QtWidgets.QMessageBox.RejectRole)
            sm.addButton(t("Close GUI Only"), QtWidgets.QMessageBox.DestructiveRole)
            sm.addButton(t("Keep FastFlix Open"), QtWidgets.QMessageBox.AcceptRole)
            sm.exec_()
            if sm.clickedButton().text() == "Cancel Conversion":
                self.app.fastflix.worker_queue.put(["cancel"])
                time.sleep(0.5)
                self.main.close()
            elif sm.clickedButton().text() == "Close GUI Only":
                self.main.close(no_cleanup=True)
                return super(Container, self).closeEvent(a0)
            else:
                a0.ignore()
                return

        for item in self.app.fastflix.config.work_path.iterdir():
            if item.is_dir() and item.stem.startswith("temp_"):
                shutil.rmtree(item, ignore_errors=True)
            if item.name.lower().endswith((".jpg", ".jpeg", ".png", ".gif")):
                item.unlink()
        if reusables.win_based:
            cleanup_windows_notification()
        self.main.close(from_container=True)
        super(Container, self).closeEvent(a0)
Beispiel #5
0
 def closeEvent(self, event: QCloseEvent) -> None:
     """Close event to avoid user close the window accidentally."""
     if self.check_file_changed():
         event.ignore()
         return
     if self.inputs_widget.inputs_play_shaft.isActive():
         self.inputs_widget.inputs_play_shaft.stop()
     self.save_settings()
     XStream.back()
     logger.info("Exit")
     event.accept()
Beispiel #6
0
    def contextMenuEvent(self, event: QtGui.QCloseEvent):

        menu = QtWidgets.QMenu(self)
        menu.setTitle("Link " + self.fitting_parameter.name + " to:")

        for fit_idx, f in enumerate(chisurf.fits):
            for fs in f:
                submenu = QtWidgets.QMenu(menu)
                submenu.setTitle(fs.name)

                # Sorted by "Aggregation"
                for a in fs.model.aggregated_parameters:
                    action_submenu = QtWidgets.QMenu(submenu)
                    action_submenu.setTitle(a.name)
                    ut = a.parameters
                    ut.sort(key=lambda x: x.name, reverse=False)
                    for p in ut:
                        if p is not self.fitting_parameter:
                            Action = action_submenu.addAction(p.name)
                            Action.triggered.connect(
                                self.make_linkcall(fit_idx, p.name))
                    submenu.addMenu(action_submenu)
                action_submenu = QtWidgets.QMenu(submenu)

                # Simply all parameters
                action_submenu.setTitle("All parameters")
                for p in fs.model.parameters_all:
                    if p is not self:
                        Action = action_submenu.addAction(p.name)
                        Action.triggered.connect(
                            self.make_linkcall(fit_idx, p.name))
                submenu.addMenu(action_submenu)

                menu.addMenu(submenu)
        menu.exec_(event.globalPos())
Beispiel #7
0
    def closeEvent(self, event: QtGui.QCloseEvent) -> None:
        """Detect close events and emit the ``closed`` signal."""

        super().closeEvent(event)
        if event.isAccepted():
            self.closed.emit()
        else:  # pragma: no cover
            pass
Beispiel #8
0
 def test_closeEvent(self):
     self.view.findChildren = mock.Mock()
     c1 = mock.Mock()
     c2 = mock.Mock()
     c3 = mock.Mock()
     self.view.findChildren.return_value = [c1, c2]
     self.view.closeEvent(QCloseEvent())
     c1.close.assert_called_once()
     c2.close.assert_called_once()
     c3.close.assert_not_called()
Beispiel #9
0
    def about_to_close(self, event: QCloseEvent) -> None:
        self.log.debug("About to close requested")

        if not self.model.is_set:
            self.model.on_close()
            self.log.debug("No project set; closing")
            event.accept()
            return

        name = self.model.path.name

        if not self.model.is_stale:
            self.model.on_close()
            self.log.debug(f"Project {name} has no changes; closing")
            event.accept()
            return

        response = showSaveDialog(
            parent=self._window,
            title="About to close",
            text=f"You have unsaved changes pending for project {name}.\n"
            "Do you want to save your changes?",
        )

        if response == QMessageBox.Save:
            self.model.save()
            self.model.on_close()
            self.log.debug(f"Project {name} saved; closing")
            event.accept()

        elif response == QMessageBox.Discard:
            self.model.on_close()
            self.log.debug(f"Project {name} not saved; closing")
            event.accept()

        elif response == QMessageBox.Cancel:
            self.log.debug(f"Project {name} not saved; not closing")
            event.ignore()

        else:
            raise RuntimeError(f"Unknown response {response}")
Beispiel #10
0
 def closeEvent(self, event: QtGui.QCloseEvent):
     if chisurf.settings.gui['confirm_close_program']:
         reply = chisurf.widgets.widgets.MyMessageBox.question(
             self, 'Message', "Are you sure to quit?",
             QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No)
         if reply == QtWidgets.QMessageBox.Yes:
             event.accept()
         else:
             event.ignore()
     else:
         event.accept()
Beispiel #11
0
    def test_that_closing_with_a_plot_will_close_the_window(self):
        self.gui.plot_window = mock.create_autospec(MultiPlotWindow)
        self.gui.closeEvent(QCloseEvent())

        self.assertEqual(self.gui.plot_window.closeEvent.call_count, 1)
Beispiel #12
0
    def test_that_closing_with_no_plot_will_not_throw(self):
        self.gui.plot_window = None

        assertRaisesNothing(self, self.gui.closeEvent, QCloseEvent())
Beispiel #13
0
 def closeEvent(self, event: QCloseEvent):
     if self.__cancel_check():
         event.accept()
     else:
         event.ignore()