コード例 #1
0
ファイル: mainwindow.py プロジェクト: qeryq/SFECOMLA
class MainWindow(OWCanvasMainWindow):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.notification_overlay = NotificationOverlay(self.scheme_widget)
        self.notification_server = None

    def open_canvas_settings(self):
        # type: () -> None
        """Reimplemented."""
        dlg = OUserSettingsDialog(self, windowTitle=self.tr("Preferences"))
        dlg.show()
        status = dlg.exec_()
        if status == 0:
            self.user_preferences_changed_notify_all()

    def set_notification_server(self, notif_server):
        self.notification_server = notif_server

        # populate notification overlay with current notifications
        for notif in self.notification_server.getNotificationQueue():
            self.notification_overlay.addNotification(notif)

        notif_server.newNotification.connect(
            self.notification_overlay.addNotification)
        notif_server.nextNotification.connect(
            self.notification_overlay.nextWidget)

    def create_new_window(self):  # type: () -> CanvasMainWindow
        window = super().create_new_window()
        window.set_notification_server(self.notification_server)
        return window
コード例 #2
0
    def test_two_overlays(self):
        container2 = QWidget()
        overlay2 = NotificationOverlay(container2)

        self.server.newNotification.connect(overlay2.addNotification)
        self.server.nextNotification.connect(overlay2.nextWidget)

        mock = unittest.mock.MagicMock()
        self.notif.accepted.connect(mock)

        self.server.registerNotification(self.notif)

        self.container.show()
        container2.show()

        w1 = self.overlay.currentWidget()
        w2 = overlay2.currentWidget()

        self.assertTrue(w1.isVisible())
        self.assertTrue(w2.isVisible())

        button = w2.button(NotificationWidget.Ok)
        QTest.mouseClick(button, Qt.LeftButton)

        mock.assert_called_once_with()

        self.assertFalse(w1.isVisible())
        self.assertFalse(w2.isVisible())
コード例 #3
0
ファイル: mainwindow.py プロジェクト: szzyiit/orange3
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.notification_overlay = NotificationOverlay(self.scheme_widget)
     self.notification_server = None
     self.scheme_widget.setDropHandlers(
         [PluginDropHandler("orange.canvas.drophandler")]
     )
コード例 #4
0
    def setUp(self) -> None:
        self.container = QWidget()
        self.overlay = NotificationOverlay(self.container)
        self.server = NotificationServer()

        self.server.newNotification.connect(self.overlay.addNotification)
        self.server.nextNotification.connect(self.overlay.nextWidget)

        self.notif = Notification(
            title="Hello world!",
            text="Welcome to the testing grounds – this is where your resolve"
            "and stability will be tried and tested.",
            accept_button_label="Ok")
コード例 #5
0
ファイル: mainwindow.py プロジェクト: qeryq/SFECOMLA
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.notification_overlay = NotificationOverlay(self.scheme_widget)
     self.notification_server = None
コード例 #6
0
ファイル: mainwindow.py プロジェクト: lhenry15/tods-gui
class MainWindow(OWCanvasMainWindow):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.notification_overlay = NotificationOverlay(self.scheme_widget)
        self.notification_server = None

        # add build and run pipeline buttons
        # self._tods_run()

    def _tods_run(self):

        self.run_pipeline_action = QAction(
            self.tr("Run"),
            self,
            objectName="run-action",
            toolTip=self.tr("Run Pipeline"),
            triggered=self.run_pipeline,
        )

        self.build_pipeline_action = QAction(
            self.tr("Build"),
            self,
            objectName="build-action",
            toolTip=self.tr("Build Pipeline"),
            triggered=self.run_pipeline,
        )

        # self.zoom_in_action.setIcon(canvas_icons("arrow-right.svg"))
        # self.welcome_action.setIcon(canvas_icons("arrow-right.svg"))
        self.run_pipeline_action.setIcon(canvas_icons("arrow-right.svg"))
        self.build_pipeline_action.setIcon(canvas_icons("default-widget.svg"))

        dock_actions = [
            self.show_properties_action,
            self.canvas_align_to_grid_action,
            self.canvas_text_action,
            self.canvas_arrow_action,
            self.freeze_action,
            self.dock_help_action,
            # self.zoom_in_action,
            # self.welcome_action,
            self.build_pipeline_action,
            self.run_pipeline_action,
        ]

        # Tool bar in the collapsed dock state (has the same actions as
        # the tool bar in the CanvasToolDock
        actions_toolbar = QToolBar(orientation=Qt.Vertical)
        actions_toolbar.setFixedWidth(38)
        actions_toolbar.layout().setSpacing(0)

        actions_toolbar.setToolButtonStyle(Qt.ToolButtonIconOnly)

        for action in dock_actions:
            self.canvas_toolbar.addAction(action)
            button = self.canvas_toolbar.widgetForAction(action)
            button.setPopupMode(QToolButton.DelayedPopup)

            actions_toolbar.addAction(action)
            button = actions_toolbar.widgetForAction(action)
            button.setFixedSize(38, 30)
            button.setPopupMode(QToolButton.DelayedPopup)

    def run_pipeline(self):
        pass

    def build_pipeline(self):
        pass

    def open_canvas_settings(self):
        # type: () -> None
        """Reimplemented."""
        dlg = OUserSettingsDialog(self, windowTitle=self.tr("Preferences"))
        dlg.show()
        status = dlg.exec_()
        if status == 0:
            self.user_preferences_changed_notify_all()

    def set_notification_server(self, notif_server):
        self.notification_server = notif_server

        # populate notification overlay with current notifications
        for notif in self.notification_server.getNotificationQueue():
            self.notification_overlay.addNotification(notif)

        notif_server.newNotification.connect(
            self.notification_overlay.addNotification)
        notif_server.nextNotification.connect(
            self.notification_overlay.nextWidget)

    def create_new_window(self):  # type: () -> CanvasMainWindow
        window = super().create_new_window()
        window.set_notification_server(self.notification_server)
        return window
コード例 #7
0
class TestOverlay(QAppTestCase):
    def setUp(self) -> None:
        self.container = QWidget()
        self.overlay = NotificationOverlay(self.container)
        self.server = NotificationServer()

        self.server.newNotification.connect(self.overlay.addNotification)
        self.server.nextNotification.connect(self.overlay.nextWidget)

        self.notif = Notification(
            title="Hello world!",
            text="Welcome to the testing grounds – this is where your resolve"
            "and stability will be tried and tested.",
            accept_button_label="Ok")

    def tearDown(self) -> None:
        self.container = None
        self.overlay = None
        self.notif = None
        self.server = None

    def test_notification_widget(self):
        stdb = NotificationWidget.Ok | NotificationWidget.Close
        notifw = NotificationWidget(self.overlay,
                                    title="Titl",
                                    text="Tixt",
                                    standardButtons=stdb)

        QApplication.sendPostedEvents(notifw, QEvent.LayoutRequest)
        self.assertTrue(notifw.geometry().isValid())

        button_ok = notifw.button(NotificationWidget.Ok)
        button_close = notifw.button(NotificationWidget.Close)

        self.assertTrue(all([button_ok, button_close]))

        button = notifw.button(NotificationWidget.Ok)
        self.assertIsNot(button, None)
        self.assertEqual(notifw.buttonRole(button),
                         NotificationWidget.AcceptRole)

    def test_notification_dismiss(self):
        mock = unittest.mock.MagicMock()
        self.notif.clicked.connect(mock)
        self.server.registerNotification(self.notif)

        notifw = self.overlay.currentWidget()
        QTest.mouseClick(notifw.dismissButton, Qt.LeftButton)
        mock.assert_called_once_with(self.notif.DismissRole)

    def test_notification_accept(self):
        mock = unittest.mock.MagicMock()
        self.notif.clicked.connect(mock)
        self.server.registerNotification(self.notif)

        notifw = self.overlay.currentWidget()
        b = notifw._msgWidget.button(NotificationWidget.Ok)
        QTest.mouseClick(b, Qt.LeftButton)
        mock.assert_called_once_with(self.notif.AcceptRole)

    def test_two_overlays(self):
        container2 = QWidget()
        overlay2 = NotificationOverlay(container2)

        self.server.newNotification.connect(overlay2.addNotification)
        self.server.nextNotification.connect(overlay2.nextWidget)

        mock = unittest.mock.MagicMock()
        self.notif.accepted.connect(mock)

        self.server.registerNotification(self.notif)

        self.container.show()
        container2.show()

        w1 = self.overlay.currentWidget()
        w2 = overlay2.currentWidget()

        self.assertTrue(w1.isVisible())
        self.assertTrue(w2.isVisible())

        button = w2.button(NotificationWidget.Ok)
        QTest.mouseClick(button, Qt.LeftButton)

        mock.assert_called_once_with()

        self.assertFalse(w1.isVisible())
        self.assertFalse(w2.isVisible())

    def test_queued_notifications(self):
        notif2 = Notification(
            title="Hello universe!",
            text=
            "I'm another notif! I'm about to queue behind my older brother.")

        def handle_click(role):
            self.assertEqual(role, Notification.DismissRole)

        self.notif.clicked.connect(handle_click)

        self.server.registerNotification(self.notif)
        notif1 = self.overlay.currentWidget()
        button = notif1.dismissButton

        self.server.registerNotification(notif2)
        notif2 = self.overlay._widgets[1]

        self.container.show()

        self.assertTrue(notif1.isVisible())
        self.assertFalse(notif2.isVisible())

        QTest.mouseClick(button, Qt.LeftButton)

        self.assertFalse(notif1.isVisible())
        self.assertTrue(notif2.isVisible())