From 604229554acb02f1914a74b71b5e0e02e1641033 Mon Sep 17 00:00:00 2001 From: ruX Date: Sat, 8 Apr 2017 13:18:38 +0100 Subject: [PATCH 1/6] UI controll for lock screen --- safeeyes/SafeEyesCore.py | 1 + safeeyes/SettingsDialog.py | 5 ++ safeeyes/config/lang/en.json | 3 +- safeeyes/glade/settings_dialog.glade | 100 ++++++++++++++++++--------- 4 files changed, 74 insertions(+), 35 deletions(-) diff --git a/safeeyes/SafeEyesCore.py b/safeeyes/SafeEyesCore.py index 7a96b8c..0e2a189 100644 --- a/safeeyes/SafeEyesCore.py +++ b/safeeyes/SafeEyesCore.py @@ -65,6 +65,7 @@ class SafeEyesCore: self.skip_break_window_classes = [x.lower() for x in config['active_window_class']['skip_break']] self.take_break_window_classes = [x.lower() for x in config['active_window_class']['take_break']] self.custom_exercises = config['custom_exercises'] + self.time_to_screen_lock = config.get('time_to_screen_lock', -1) exercises = language['exercises'] for short_break_config in config['short_breaks']: diff --git a/safeeyes/SettingsDialog.py b/safeeyes/SettingsDialog.py index a68c9e1..dd66915 100644 --- a/safeeyes/SettingsDialog.py +++ b/safeeyes/SettingsDialog.py @@ -45,6 +45,7 @@ class SettingsDialog: self.switch_strict_break = builder.get_object('switch_strict_break') self.switch_audible_alert = builder.get_object('switch_audible_alert') self.cmb_language = builder.get_object('cmb_language') + self.spin_time_to_screen_lock = builder.get_object('spin_time_to_screen_lock') builder.get_object('lbl_short_break').set_label(language['ui_controls']['short_break_duration']) builder.get_object('lbl_long_break').set_label(language['ui_controls']['long_break_duration']) @@ -56,6 +57,7 @@ class SettingsDialog: builder.get_object('lbl_strict_break').set_label(language['ui_controls']['strict_break']) builder.get_object('lbl_audible_alert').set_label(language['ui_controls']['audible_alert']) builder.get_object('lbl_language').set_label(language['ui_controls']['language']) + builder.get_object('lbl_lock_screen_after').set_label(language['ui_controls']['time_to_screen_lock']) builder.get_object('btn_cancel').set_label(language['ui_controls']['cancel']) builder.get_object('btn_save').set_label(language['ui_controls']['save']) @@ -68,6 +70,7 @@ class SettingsDialog: self.spin_postpone_duration.set_value(config['postpone_duration']) self.switch_strict_break.set_active(config['strict_break']) self.switch_audible_alert.set_active(config['audible_alert']) + self.time_to_screen_lock = self.config.get('time_to_screen_lock', -1) # Initialize the language combobox language_list_store = Gtk.ListStore(GObject.TYPE_STRING) @@ -115,6 +118,8 @@ class SettingsDialog: self.config['strict_break'] = self.switch_strict_break.get_active() self.config['audible_alert'] = self.switch_audible_alert.get_active() self.config['language'] = self.languages[self.cmb_language.get_active()] + self.config['time_to_screen_lock'] = self.spin_time_to_screen_lock.get_value_as_int() + print(self.config['time_to_screen_lock']) self.on_save_settings(self.config) # Call the provided save method self.window.destroy() # Close the settings window diff --git a/safeeyes/config/lang/en.json b/safeeyes/config/lang/en.json index b7afdd2..daabab4 100644 --- a/safeeyes/config/lang/en.json +++ b/safeeyes/config/lang/en.json @@ -44,6 +44,7 @@ "strict_break": "Strict break (Hide skip button)", "system_language": "System Language", "time_to_prepare_for_break": "Time to prepare for break (in seconds)", - "until_restart": "Until restart" + "until_restart": "Until restart", + "time_to_screen_lock": "Lock screen if break is longer than (in seconds)" } } diff --git a/safeeyes/glade/settings_dialog.glade b/safeeyes/glade/settings_dialog.glade index 316c960..a3f3e34 100644 --- a/safeeyes/glade/settings_dialog.glade +++ b/safeeyes/glade/settings_dialog.glade @@ -46,24 +46,30 @@ 1 5 + + 1 + 15 + 1 + 5 + 1 60 1 5 + + 1 + 60 + 1 + 5 + 1 60 1 5 - - 1 - 15 - 1 - 5 - 400 False @@ -199,32 +205,6 @@ 7 - - - True - False - start - center - Audible alert at the end of break - - - 0 - 8 - - - - - True - False - start - center - Language - - - 0 - 9 - - True @@ -376,6 +356,19 @@ 8 + + + True + False + start + center + Audible alert at the end of break + + + 0 + 8 + + True @@ -387,10 +380,49 @@ - + + True + False + start + center + Language + + + 0 + 9 + - + + True + False + start + center + Lock screen if break is longer than (in seconds) + + + 0 + 10 + + + + + True + True + end + center + 1 + number + adjust_time_to_prepare + 1 + True + if-valid + 1 + + + 1 + 10 + From 76c26048e600e9591caab5aff95c3e97ccb00a53 Mon Sep 17 00:00:00 2001 From: ruX Date: Sat, 8 Apr 2017 14:01:48 +0100 Subject: [PATCH 2/6] Add checkbox for lockscreen feature and change state of spin accordingly --- safeeyes/SettingsDialog.py | 11 +++++++++-- safeeyes/config/lang/en.json | 3 ++- safeeyes/glade/settings_dialog.glade | 27 ++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/safeeyes/SettingsDialog.py b/safeeyes/SettingsDialog.py index dd66915..19fa0b3 100644 --- a/safeeyes/SettingsDialog.py +++ b/safeeyes/SettingsDialog.py @@ -45,6 +45,7 @@ class SettingsDialog: self.switch_strict_break = builder.get_object('switch_strict_break') self.switch_audible_alert = builder.get_object('switch_audible_alert') self.cmb_language = builder.get_object('cmb_language') + self.switch_screen_lock = builder.get_object('switch_screen_lock') self.spin_time_to_screen_lock = builder.get_object('spin_time_to_screen_lock') builder.get_object('lbl_short_break').set_label(language['ui_controls']['short_break_duration']) @@ -57,6 +58,7 @@ class SettingsDialog: builder.get_object('lbl_strict_break').set_label(language['ui_controls']['strict_break']) builder.get_object('lbl_audible_alert').set_label(language['ui_controls']['audible_alert']) builder.get_object('lbl_language').set_label(language['ui_controls']['language']) + builder.get_object('lbl_enable_screen_lock').set_label(language['ui_controls']['enable_screen_lock']) builder.get_object('lbl_lock_screen_after').set_label(language['ui_controls']['time_to_screen_lock']) builder.get_object('btn_cancel').set_label(language['ui_controls']['cancel']) builder.get_object('btn_save').set_label(language['ui_controls']['save']) @@ -70,7 +72,9 @@ class SettingsDialog: self.spin_postpone_duration.set_value(config['postpone_duration']) self.switch_strict_break.set_active(config['strict_break']) self.switch_audible_alert.set_active(config['audible_alert']) - self.time_to_screen_lock = self.config.get('time_to_screen_lock', -1) + self.switch_screen_lock.set_active(self.config.get('enable_screen_lock', True)) + self.spin_time_to_screen_lock.set_value(self.config.get('time_to_screen_lock', 20)) + self.on_switch_screen_lock_activate(self.switch_screen_lock, self.switch_screen_lock.get_active()) # Initialize the language combobox language_list_store = Gtk.ListStore(GObject.TYPE_STRING) @@ -104,6 +108,9 @@ class SettingsDialog: def show(self): self.window.show_all() + def on_switch_screen_lock_activate(self, switch, state): + self.spin_time_to_screen_lock.set_sensitive(self.switch_screen_lock.get_active()) + def on_window_delete(self, *args): self.window.destroy() @@ -119,7 +126,7 @@ class SettingsDialog: self.config['audible_alert'] = self.switch_audible_alert.get_active() self.config['language'] = self.languages[self.cmb_language.get_active()] self.config['time_to_screen_lock'] = self.spin_time_to_screen_lock.get_value_as_int() - print(self.config['time_to_screen_lock']) + self.config['enable_screen_lock'] = self.switch_screen_lock.get_active() self.on_save_settings(self.config) # Call the provided save method self.window.destroy() # Close the settings window diff --git a/safeeyes/config/lang/en.json b/safeeyes/config/lang/en.json index daabab4..4048ba1 100644 --- a/safeeyes/config/lang/en.json +++ b/safeeyes/config/lang/en.json @@ -45,6 +45,7 @@ "system_language": "System Language", "time_to_prepare_for_break": "Time to prepare for break (in seconds)", "until_restart": "Until restart", - "time_to_screen_lock": "Lock screen if break is longer than (in seconds)" + "time_to_screen_lock": "Lock screen if break is longer than (in seconds)", + "enable_screen_lock": "Enable screen lock for long breaks" } } diff --git a/safeeyes/glade/settings_dialog.glade b/safeeyes/glade/settings_dialog.glade index a3f3e34..6412290 100644 --- a/safeeyes/glade/settings_dialog.glade +++ b/safeeyes/glade/settings_dialog.glade @@ -402,7 +402,7 @@ 0 - 10 + 11 @@ -419,6 +419,31 @@ if-valid 1 + + 1 + 11 + + + + + True + False + start + center + Enable screen lock for long breaks + + + 0 + 10 + + + + + True + True + + + 1 10 From bf3d6848c824960d20db06b0ed98e83210b9eb3a Mon Sep 17 00:00:00 2001 From: ruX Date: Sat, 8 Apr 2017 14:30:44 +0100 Subject: [PATCH 3/6] Check current desktop environment type --- safeeyes/SettingsDialog.py | 3 ++- safeeyes/Utility.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/safeeyes/SettingsDialog.py b/safeeyes/SettingsDialog.py index 19fa0b3..7b1fd1f 100644 --- a/safeeyes/SettingsDialog.py +++ b/safeeyes/SettingsDialog.py @@ -72,7 +72,8 @@ class SettingsDialog: self.spin_postpone_duration.set_value(config['postpone_duration']) self.switch_strict_break.set_active(config['strict_break']) self.switch_audible_alert.set_active(config['audible_alert']) - self.switch_screen_lock.set_active(self.config.get('enable_screen_lock', True)) + self.switch_screen_lock.set_sensitive(Utility.is_desktop_lock_supported()) + self.switch_screen_lock.set_active(Utility.is_desktop_lock_supported() and self.config.get('enable_screen_lock', True)) self.spin_time_to_screen_lock.set_value(self.config.get('time_to_screen_lock', 20)) self.on_switch_screen_lock_activate(self.switch_screen_lock, self.switch_screen_lock.get_active()) diff --git a/safeeyes/Utility.py b/safeeyes/Utility.py index cabe621..4ad658c 100644 --- a/safeeyes/Utility.py +++ b/safeeyes/Utility.py @@ -240,3 +240,19 @@ def read_lang_files(): languages[lang_file_name.lower().replace('.json', '')] = lang['meta_info']['language_name'] return languages + +def desktop_envinroment(): + """ + Function tries to detect current envinroment + Possible results: unity, gnome or None if nothing detected + """ + if 'unity' == os.environ.get('XDG_CURRENT_DESKTOP', '').lower(): + return 'unity' + elif 'gnome' == os.environ.get('DESKTOP_SESSION', '').lower(): + return 'gnome' + + return None + +def is_desktop_lock_supported(): + return desktop_envinroment() in ['unity', 'gnome'] + From 6816cc60c423c7b295e30a5e24ddb7b85753d01a Mon Sep 17 00:00:00 2001 From: ruX Date: Sat, 8 Apr 2017 14:54:07 +0100 Subject: [PATCH 4/6] Lock screen is working --- safeeyes/SafeEyesCore.py | 7 ++++++- safeeyes/SettingsDialog.py | 2 +- safeeyes/Utility.py | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/safeeyes/SafeEyesCore.py b/safeeyes/SafeEyesCore.py index 0e2a189..6edf832 100644 --- a/safeeyes/SafeEyesCore.py +++ b/safeeyes/SafeEyesCore.py @@ -65,7 +65,8 @@ class SafeEyesCore: self.skip_break_window_classes = [x.lower() for x in config['active_window_class']['skip_break']] self.take_break_window_classes = [x.lower() for x in config['active_window_class']['take_break']] self.custom_exercises = config['custom_exercises'] - self.time_to_screen_lock = config.get('time_to_screen_lock', -1) + self.time_to_screen_lock = config.get('time_to_screen_lock', -1) + self.enable_screen_lock = config.get('enable_screen_lock', False) exercises = language['exercises'] for short_break_config in config['short_breaks']: @@ -292,6 +293,10 @@ class SafeEyesCore: audible_alert = self.short_break_exercises[self.short_break_message_index][2] image = self.short_break_exercises[self.short_break_message_index][3] + + if (Utility.is_desktop_lock_supported() and self.enable_screen_lock and self.time_to_screen_lock < seconds): + Utility.lock_desktop() + # Show the break screen self.start_break(message, image) diff --git a/safeeyes/SettingsDialog.py b/safeeyes/SettingsDialog.py index 7b1fd1f..2cd26b2 100644 --- a/safeeyes/SettingsDialog.py +++ b/safeeyes/SettingsDialog.py @@ -73,7 +73,7 @@ class SettingsDialog: self.switch_strict_break.set_active(config['strict_break']) self.switch_audible_alert.set_active(config['audible_alert']) self.switch_screen_lock.set_sensitive(Utility.is_desktop_lock_supported()) - self.switch_screen_lock.set_active(Utility.is_desktop_lock_supported() and self.config.get('enable_screen_lock', True)) + self.switch_screen_lock.set_active(Utility.is_desktop_lock_supported() and self.config.get('enable_screen_lock', False)) self.spin_time_to_screen_lock.set_value(self.config.get('time_to_screen_lock', 20)) self.on_switch_screen_lock_activate(self.switch_screen_lock, self.switch_screen_lock.get_active()) diff --git a/safeeyes/Utility.py b/safeeyes/Utility.py index 4ad658c..6b88766 100644 --- a/safeeyes/Utility.py +++ b/safeeyes/Utility.py @@ -256,3 +256,5 @@ def desktop_envinroment(): def is_desktop_lock_supported(): return desktop_envinroment() in ['unity', 'gnome'] +def lock_desktop(): + os.system("gnome-screensaver-command --lock") From b58c124bdf5057b228da6820acd6c398c3efecb1 Mon Sep 17 00:00:00 2001 From: ruX Date: Sat, 8 Apr 2017 14:59:41 +0100 Subject: [PATCH 5/6] Russian translation --- safeeyes/config/lang/ru.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/safeeyes/config/lang/ru.json b/safeeyes/config/lang/ru.json index e4b2a00..80711e5 100644 --- a/safeeyes/config/lang/ru.json +++ b/safeeyes/config/lang/ru.json @@ -44,6 +44,8 @@ "strict_break": "Обязательный перерыв (Скрыть кнопку 'Пропустить')", "system_language": "System Language", "time_to_prepare_for_break": "Время подготовки в перерыву (в секундах)", - "until_restart": "До перезагрузки" + "until_restart": "До перезагрузки", + "time_to_screen_lock": "Заблокировать экран если перерыв дольше(в секундах)", + "enable_screen_lock": "Включить блокировку экрана" } } From e960bb4dbf2bafb031fd9668c84135f1189f0cff Mon Sep 17 00:00:00 2001 From: ruX Date: Sat, 8 Apr 2017 15:41:16 +0100 Subject: [PATCH 6/6] Lock screen after specified amount of time --- safeeyes/SafeEyesCore.py | 7 +++++-- safeeyes/Utility.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/safeeyes/SafeEyesCore.py b/safeeyes/SafeEyesCore.py index 6edf832..0a01924 100644 --- a/safeeyes/SafeEyesCore.py +++ b/safeeyes/SafeEyesCore.py @@ -294,8 +294,9 @@ class SafeEyesCore: image = self.short_break_exercises[self.short_break_message_index][3] - if (Utility.is_desktop_lock_supported() and self.enable_screen_lock and self.time_to_screen_lock < seconds): - Utility.lock_desktop() + total_break_time = seconds + # Should we lock screen potentially? + consider_screen_lock = Utility.is_desktop_lock_supported() and self.enable_screen_lock # Show the break screen self.start_break(message, image) @@ -307,6 +308,8 @@ class SafeEyesCore: self.on_countdown(timeformat) time.sleep(1) # Sleep for 1 second seconds -= 1 + if consider_screen_lock and self.time_to_screen_lock == total_break_time - seconds: + Utility.lock_desktop() # Loop terminated because of timeout (not skipped) -> Close the break alert if not self.skipped and not self.postponed: diff --git a/safeeyes/Utility.py b/safeeyes/Utility.py index 6b88766..69f9b1f 100644 --- a/safeeyes/Utility.py +++ b/safeeyes/Utility.py @@ -257,4 +257,4 @@ def is_desktop_lock_supported(): return desktop_envinroment() in ['unity', 'gnome'] def lock_desktop(): - os.system("gnome-screensaver-command --lock") + subprocess.call(["gnome-screensaver-command","--lock",])