def compare_versions(latest): version = pkg_resources.parse_version skipped = settings.value('startup/latest-skipped-version', "", type=str) if version(latest) <= version(current) or \ latest == skipped: return questionButtons = NotificationWidget.Ok | NotificationWidget.Close question = NotificationWidget( icon=QIcon(gui.resource_filename('icons/Dlg_down3.png')), title='Orange Update Available', text='Current version: <b>{}</b><br>' 'Latest version: <b>{}</b>'.format(current, latest), textFormat=Qt.RichText, standardButtons=questionButtons, acceptLabel="Download", rejectLabel="Skip this Version") def handle_click(b): if question.buttonRole(b) == question.RejectRole: settings.setValue('startup/latest-skipped-version', latest) if question.buttonRole(b) == question.AcceptRole: QDesktopServices.openUrl( QUrl("https://orange.biolab.si/download/")) question.clicked.connect(handle_click) NotificationOverlay.registerNotification(question)
def test_notification_message(self): self.notif.setText("Hello world! It's so nice here") QApplication.sendPostedEvents(self.notif, QEvent.LayoutRequest) self.assertTrue(self.notif.geometry().isValid()) button_ok = self.notif.button(NotificationWidget.Ok) button_close = self.notif.button(NotificationWidget.Close) self.assertTrue(all([button_ok, button_close])) self.assertIs(self.notif.button(NotificationWidget.Ok), button_ok) self.assertIs(self.notif.button(NotificationWidget.Close), button_close) button = self.notif.button(NotificationWidget.Ok) self.assertIsNot(button, None) self.assertTrue(self.notif.buttonRole(button), NotificationWidget.AcceptRole) mock = unittest.mock.MagicMock() self.notif.accepted.connect(mock) NotificationOverlay.registerNotification(self.notif) cloned = NotificationOverlay.overlayInstances[0].currentWidget() self.assertTrue(cloned.isVisible()) button = cloned._msgwidget.button(NotificationWidget.Ok) QTest.mouseClick(button, Qt.LeftButton) self.assertFalse(cloned.isVisible()) mock.assert_called_once()
def test_queued_notifications(self): surveyDialogButtons = NotificationWidget.Ok | NotificationWidget.Close surveyDialog = NotificationWidget( title="Survey", text="We want to understand our users better.\n" "Would you like to take a short survey?", standardButtons=surveyDialogButtons) def handle_survey_response(b): self.assertEqual(self.notif.buttonRole(b), NotificationWidget.DismissRole) self.notif.clicked.connect(handle_survey_response) NotificationOverlay.registerNotification(self.notif) notif1 = NotificationOverlay.overlayInstances[0]._widgets[0] button = notif1._dismiss_button NotificationOverlay.registerNotification(surveyDialog) notif2 = NotificationOverlay.overlayInstances[0]._widgets[1] self.assertTrue(notif1.isVisible()) self.assertFalse(notif2.isVisible()) QTest.mouseClick(button, Qt.LeftButton) self.assertFalse(notif1.isVisible()) self.assertTrue(notif2.isVisible())
def setup_notifications(): settings = QSettings() # If run for the fifth time, prompt short survey show_survey = settings.value("startup/show-short-survey", True, type=bool) and \ settings.value("startup/launch-count", 0, type=int) >= 5 if show_survey: surveyDialogButtons = NotificationWidget.Ok | NotificationWidget.Close surveyDialog = NotificationWidget( icon=QIcon(gui.resource_filename("icons/information.png")), title="Survey", text="We want to understand our users better.\n" "Would you like to take a short survey?", standardButtons=surveyDialogButtons) def handle_survey_response(button): if surveyDialog.buttonRole( button) == NotificationWidget.AcceptRole: success = QDesktopServices.openUrl( QUrl("https://orange.biolab.si/survey/short.html")) settings.setValue("startup/show-short-survey", not success) elif surveyDialog.buttonRole( button) == NotificationWidget.RejectRole: settings.setValue("startup/show-short-survey", False) surveyDialog.clicked.connect(handle_survey_response) NotificationOverlay.registerNotification(surveyDialog) # data collection permission if not settings.value( "error-reporting/permission-requested", False, type=bool): permDialogButtons = NotificationWidget.Ok | NotificationWidget.Close permDialog = NotificationWidget( icon=QIcon(gui.resource_filename("../../distribute/icon-48.png")), title="Anonymous Usage Statistics", text="Do you wish to opt-in to sharing " "statistics about how you use Orange?\n" "All data is anonymized and used " "exclusively for understanding how users " "interact with Orange.", standardButtons=permDialogButtons) btnOK = permDialog.button(NotificationWidget.AcceptRole) btnOK.setText("Allow") def handle_permission_response(button): if permDialog.buttonRole(button) != permDialog.DismissRole: settings.setValue("error-reporting/permission-requested", True) if permDialog.buttonRole(button) == permDialog.AcceptRole: UsageStatistics.set_enabled(True) settings.setValue("error-reporting/send-statistics", True) permDialog.clicked.connect(handle_permission_response) NotificationOverlay.registerNotification(permDialog)
def test_notification_dismiss(self): mock = unittest.mock.MagicMock() self.notif.clicked.connect(mock) NotificationOverlay.registerNotification(self.notif) QTest.mouseClick(self.notif._dismiss_button, Qt.LeftButton) mock.assert_called_once_with(self.notif._dismiss_button)