1919
2020import pkg_resources
2121
22- from AnyQt .QtGui import QFont , QColor , QPalette , QDesktopServices
22+ from AnyQt .QtGui import QFont , QColor , QPalette , QDesktopServices , QIcon
2323from AnyQt .QtWidgets import QMessageBox
2424from AnyQt .QtCore import (
2525 Qt , QDir , QUrl , QSettings , QThread , pyqtSignal , QT_VERSION
3939from Orange .canvas .registry import qt
4040from Orange .canvas .registry import WidgetRegistry , set_global_registry
4141from Orange .canvas .registry import cache
42+ from Orange .canvas .utils .overlay import NotificationWidget , NotificationOverlay
4243
4344log = logging .getLogger (__name__ )
4445
@@ -180,6 +181,57 @@ def make_sql_logger(level=logging.INFO):
180181 sql_log .addHandler (handler )
181182
182183
184+ def setup_notifications ():
185+ settings = config .settings ()
186+
187+ # If run for the fifth time, prompt short survey
188+ show_survey = settings ["startup/show-short-survey" ] and \
189+ settings ["startup/launch-count" ] >= 5
190+ if show_survey :
191+ surveyDialogButtons = NotificationWidget .Ok | NotificationWidget .Close
192+ surveyDialog = NotificationWidget (icon = QIcon ("Orange/widgets/icons/information.png" ),
193+ title = "Survey" ,
194+ text = "We want to understand our users better.\n "
195+ "Would you like to take a short survey?" ,
196+ standardButtons = surveyDialogButtons )
197+
198+ def handle_response (button ):
199+ if surveyDialog .buttonRole (button ) == NotificationWidget .AcceptRole :
200+ success = QDesktopServices .openUrl (
201+ QUrl ("https://orange.biolab.si/survey/short.html" ))
202+ settings ["startup/show-short-survey" ] = not success
203+ elif surveyDialog .buttonRole (button ) == NotificationWidget .RejectRole :
204+ settings ["startup/show-short-survey" ] = False
205+
206+ surveyDialog .clicked .connect (handle_response )
207+
208+ NotificationOverlay .registerNotification (surveyDialog )
209+
210+ # data collection permission
211+ if not settings ["error-reporting/permission-requested" ]:
212+ permDialogButtons = NotificationWidget .Ok | NotificationWidget .Close
213+ permDialog = NotificationWidget (icon = QIcon ("distribute/icon-48.png" ),
214+ title = "Anonymous Usage Statistics" ,
215+ text = "Do you wish to opt-in to sharing "
216+ "statistics about how you use Orange?\n "
217+ "All data is anonymized and used "
218+ "exclusively for understanding how users "
219+ "interact with Orange." ,
220+ standardButtons = permDialogButtons )
221+ btnOK = permDialog .button (NotificationWidget .AcceptRole )
222+ btnOK .setText ("Allow" )
223+
224+ def handle_response (button ):
225+ if permDialog .buttonRole (button ) != permDialog .DismissRole :
226+ settings ["error-reporting/permission-requested" ] = True
227+ if permDialog .buttonRole (button ) == permDialog .AcceptRole :
228+ settings ["error-reporting/send-statistics" ] = True
229+
230+ permDialog .clicked .connect (handle_response )
231+
232+ NotificationOverlay .registerNotification (permDialog )
233+
234+
183235def check_for_updates ():
184236 settings = QSettings ()
185237 check_updates = settings .value ('startup/check-updates' , True , type = bool )
@@ -244,8 +296,8 @@ def compare_versions(latest):
244296 thread .start ()
245297 return thread
246298
247- def send_usage_statistics ():
248299
300+ def send_usage_statistics ():
249301 class SendUsageStatistics (QThread ):
250302 def run (self ):
251303 try :
@@ -259,6 +311,7 @@ def run(self):
259311 thread .start ()
260312 return thread
261313
314+
262315def main (argv = None ):
263316 if argv is None :
264317 argv = sys .argv
@@ -531,6 +584,9 @@ def show_message(message):
531584 open_requests [- 1 ])
532585 canvas_window .load_scheme (open_requests [- 1 ].toLocalFile ())
533586
587+ # initialize notifications
588+ setup_notifications ()
589+
534590 # local references prevent destruction
535591 update_check = check_for_updates ()
536592 send_stat = send_usage_statistics ()
0 commit comments