Refactor modules and classes
This commit is contained in:
parent
9bcd0122ef
commit
5c554fffc1
|
@ -101,4 +101,7 @@ ENV/
|
|||
|
||||
safeeyes/config/locale/*/LC_MESSAGES/safeeyes.po~
|
||||
|
||||
node_modules/
|
||||
node_modules/
|
||||
|
||||
# PyCharm
|
||||
.idea
|
|
@ -29,16 +29,16 @@ from threading import Timer
|
|||
|
||||
import gi
|
||||
import psutil
|
||||
from safeeyes import Utility
|
||||
from safeeyes import utility
|
||||
from safeeyes.model import Config
|
||||
from safeeyes.SafeEyes import SafeEyes
|
||||
from safeeyes.SafeEyes import SAFE_EYES_VERSION
|
||||
from safeeyes.safeeyes import SafeEyes
|
||||
from safeeyes.safeeyes import SAFE_EYES_VERSION
|
||||
from safeeyes.rpc import RPCClient
|
||||
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
gettext.install('safeeyes', Utility.LOCALE_PATH)
|
||||
gettext.install('safeeyes', utility.LOCALE_PATH)
|
||||
|
||||
|
||||
def __running():
|
||||
|
@ -73,26 +73,26 @@ def __evaluate_arguments(args, safe_eyes):
|
|||
Evaluate the arguments and execute the operations.
|
||||
"""
|
||||
if args.about:
|
||||
Utility.execute_main_thread(safe_eyes.show_about)
|
||||
utility.execute_main_thread(safe_eyes.show_about)
|
||||
elif args.disable:
|
||||
Utility.execute_main_thread(safe_eyes.disable_safeeyes)
|
||||
utility.execute_main_thread(safe_eyes.disable_safeeyes)
|
||||
elif args.enable:
|
||||
Utility.execute_main_thread(safe_eyes.enable_safeeyes)
|
||||
utility.execute_main_thread(safe_eyes.enable_safeeyes)
|
||||
elif args.settings:
|
||||
Utility.execute_main_thread(safe_eyes.show_settings)
|
||||
utility.execute_main_thread(safe_eyes.show_settings)
|
||||
elif args.take_break:
|
||||
Utility.execute_main_thread(safe_eyes.take_break)
|
||||
utility.execute_main_thread(safe_eyes.take_break)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Start the Safe Eyes.
|
||||
"""
|
||||
system_locale = gettext.translation('safeeyes', localedir=Utility.LOCALE_PATH, languages=[Utility.system_locale(), 'en_US'], fallback=True)
|
||||
system_locale = gettext.translation('safeeyes', localedir=utility.LOCALE_PATH, languages=[utility.system_locale(), 'en_US'], fallback=True)
|
||||
system_locale.install()
|
||||
# locale.bindtextdomain is required for Glade files
|
||||
# gettext.bindtextdomain(gettext.textdomain(), Utility.LOCALE_PATH)
|
||||
locale.bindtextdomain('safeeyes', Utility.LOCALE_PATH)
|
||||
locale.bindtextdomain('safeeyes', utility.LOCALE_PATH)
|
||||
|
||||
parser = argparse.ArgumentParser(prog='safeeyes', description=_('description'))
|
||||
group = parser.add_mutually_exclusive_group()
|
||||
|
@ -108,7 +108,7 @@ def main():
|
|||
args = parser.parse_args()
|
||||
|
||||
# Initialize the logging
|
||||
Utility.intialize_logging(args.debug)
|
||||
utility.intialize_logging(args.debug)
|
||||
config = Config()
|
||||
|
||||
if __running():
|
||||
|
@ -143,9 +143,9 @@ def main():
|
|||
sys.exit(0)
|
||||
elif not args.quit:
|
||||
logging.info("Starting Safe Eyes")
|
||||
safeeyes = SafeEyes(system_locale, config)
|
||||
safeeyes.start()
|
||||
Timer(1.0, lambda: __evaluate_arguments(args, safeeyes)).start()
|
||||
safe_eyes = SafeEyes(system_locale, config)
|
||||
safe_eyes.start()
|
||||
Timer(1.0, lambda: __evaluate_arguments(args, safe_eyes)).start()
|
||||
Gtk.main()
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import logging
|
|||
import threading
|
||||
import time
|
||||
|
||||
from safeeyes import Utility
|
||||
from safeeyes import utility
|
||||
from safeeyes.model import Break
|
||||
from safeeyes.model import BreakType
|
||||
from safeeyes.model import BreakQueue
|
||||
|
@ -33,7 +33,7 @@ from safeeyes.model import EventHook
|
|||
from safeeyes.model import State
|
||||
|
||||
|
||||
class SafeEyesCore(object):
|
||||
class SafeEyesCore:
|
||||
"""
|
||||
Core of Safe Eyes runs the scheduler and notifies the breaks.
|
||||
"""
|
||||
|
@ -90,7 +90,7 @@ class SafeEyesCore(object):
|
|||
logging.info("Start Safe Eyes core")
|
||||
self.running = True
|
||||
self.scheduled_next_break_timestamp = int(next_break_time)
|
||||
Utility.start_thread(self.__scheduler_job)
|
||||
utility.start_thread(self.__scheduler_job)
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
|
@ -135,7 +135,7 @@ class SafeEyesCore(object):
|
|||
return
|
||||
if not self.context['state'] == State.WAITING:
|
||||
return
|
||||
Utility.start_thread(self.__take_break)
|
||||
utility.start_thread(self.__take_break)
|
||||
|
||||
def has_breaks(self):
|
||||
"""
|
||||
|
@ -163,7 +163,7 @@ class SafeEyesCore(object):
|
|||
time.sleep(1) # Wait for 1 sec to ensure the sceduler is dead
|
||||
self.running = True
|
||||
|
||||
Utility.execute_main_thread(self.__fire_start_break)
|
||||
utility.execute_main_thread(self.__fire_start_break)
|
||||
|
||||
def __scheduler_job(self):
|
||||
"""
|
||||
|
@ -198,7 +198,7 @@ class SafeEyesCore(object):
|
|||
self.scheduled_next_break_timestamp = -1
|
||||
|
||||
self.scheduled_next_break_time = current_time + datetime.timedelta(seconds=time_to_wait)
|
||||
Utility.execute_main_thread(self.__fire_on_update_next_break, self.scheduled_next_break_time)
|
||||
utility.execute_main_thread(self.__fire_on_update_next_break, self.scheduled_next_break_time)
|
||||
|
||||
# Wait for the pre break warning period
|
||||
logging.info("Waiting for %d minutes until next break", (time_to_wait / 60))
|
||||
|
@ -208,7 +208,7 @@ class SafeEyesCore(object):
|
|||
|
||||
if not self.running:
|
||||
return
|
||||
Utility.execute_main_thread(self.__fire_pre_break)
|
||||
utility.execute_main_thread(self.__fire_pre_break)
|
||||
|
||||
def __fire_on_update_next_break(self, next_break_time):
|
||||
"""
|
||||
|
@ -225,7 +225,7 @@ class SafeEyesCore(object):
|
|||
# Plugins wanted to ignore this break
|
||||
self.__start_next_break()
|
||||
return
|
||||
Utility.start_thread(self.__wait_until_prepare)
|
||||
utility.start_thread(self.__wait_until_prepare)
|
||||
|
||||
def __wait_until_prepare(self):
|
||||
logging.info("Wait for %d seconds before the break", self.pre_break_warning_time)
|
||||
|
@ -233,11 +233,11 @@ class SafeEyesCore(object):
|
|||
self.__wait_for(self.pre_break_warning_time)
|
||||
if not self.running:
|
||||
return
|
||||
Utility.execute_main_thread(self.__fire_start_break)
|
||||
utility.execute_main_thread(self.__fire_start_break)
|
||||
|
||||
def __postpone_break(self):
|
||||
self.__wait_for(self.postpone_duration)
|
||||
Utility.execute_main_thread(self.__fire_start_break)
|
||||
utility.execute_main_thread(self.__fire_start_break)
|
||||
|
||||
def __fire_start_break(self):
|
||||
# Show the break screen
|
||||
|
@ -252,10 +252,10 @@ class SafeEyesCore(object):
|
|||
self.scheduled_next_break_time = self.scheduled_next_break_time + datetime.timedelta(seconds=self.postpone_duration)
|
||||
self.__fire_on_update_next_break(self.scheduled_next_break_time)
|
||||
# Wait in user thread
|
||||
Utility.start_thread(self.__postpone_break)
|
||||
utility.start_thread(self.__postpone_break)
|
||||
else:
|
||||
self.start_break.fire(self.break_queue.get_break())
|
||||
Utility.start_thread(self.__start_break)
|
||||
utility.start_thread(self.__start_break)
|
||||
|
||||
def __start_break(self):
|
||||
"""
|
||||
|
@ -271,7 +271,7 @@ class SafeEyesCore(object):
|
|||
self.on_count_down.fire(countdown, seconds)
|
||||
time.sleep(1) # Sleep for 1 second
|
||||
countdown -= 1
|
||||
Utility.execute_main_thread(self.__fire_stop_break)
|
||||
utility.execute_main_thread(self.__fire_stop_break)
|
||||
|
||||
def __fire_stop_break(self):
|
||||
# Loop terminated because of timeout (not skipped) -> Close the break alert
|
||||
|
@ -297,4 +297,4 @@ class SafeEyesCore(object):
|
|||
|
||||
if self.running:
|
||||
# Schedule the break again
|
||||
Utility.start_thread(self.__scheduler_job)
|
||||
utility.start_thread(self.__scheduler_job)
|
|
@ -23,10 +23,10 @@ This module contains the entity classes used by Safe Eyes and its plugins.
|
|||
from distutils.version import LooseVersion
|
||||
from enum import Enum
|
||||
import logging
|
||||
from safeeyes import Utility
|
||||
from safeeyes import utility
|
||||
|
||||
|
||||
class Break(object):
|
||||
class Break:
|
||||
"""
|
||||
An entity class which represents a break.
|
||||
"""
|
||||
|
@ -76,7 +76,7 @@ class BreakType(Enum):
|
|||
LONG_BREAK = 2
|
||||
|
||||
|
||||
class BreakQueue(object):
|
||||
class BreakQueue:
|
||||
|
||||
def __init__(self, config, context):
|
||||
self.context = context
|
||||
|
@ -203,7 +203,7 @@ class State(Enum):
|
|||
QUIT = 5
|
||||
|
||||
|
||||
class EventHook(object):
|
||||
class EventHook:
|
||||
"""
|
||||
Hook to attach and detach listeners to system events.
|
||||
"""
|
||||
|
@ -229,21 +229,21 @@ class EventHook(object):
|
|||
return True
|
||||
|
||||
|
||||
class Config(object):
|
||||
class Config:
|
||||
"""
|
||||
The configuration of Safe Eyes.
|
||||
"""
|
||||
|
||||
def __init__(self, init=True):
|
||||
# Read the config files
|
||||
self.__user_config = Utility.load_json(Utility.CONFIG_FILE_PATH)
|
||||
self.__system_config = Utility.load_json(
|
||||
Utility.SYSTEM_CONFIG_FILE_PATH)
|
||||
self.__user_config = utility.load_json(utility.CONFIG_FILE_PATH)
|
||||
self.__system_config = utility.load_json(
|
||||
utility.SYSTEM_CONFIG_FILE_PATH)
|
||||
self.__force_upgrade = ['long_breaks', 'short_breaks']
|
||||
|
||||
if init:
|
||||
if self.__user_config is None:
|
||||
Utility.initialize_safeeyes()
|
||||
utility.initialize_safeeyes()
|
||||
self.__user_config = self.__system_config
|
||||
self.save()
|
||||
else:
|
||||
|
@ -261,9 +261,9 @@ class Config(object):
|
|||
self.__user_config, self.__system_config)
|
||||
self.__user_config = self.__system_config
|
||||
# Update the style sheet
|
||||
Utility.replace_style_sheet()
|
||||
utility.replace_style_sheet()
|
||||
|
||||
Utility.merge_plugins(self.__user_config)
|
||||
utility.merge_plugins(self.__user_config)
|
||||
self.save()
|
||||
|
||||
def __merge_dictionary(self, old_dict, new_dict):
|
||||
|
@ -291,7 +291,7 @@ class Config(object):
|
|||
"""
|
||||
Save the configuration to file.
|
||||
"""
|
||||
Utility.write_json(Utility.CONFIG_FILE_PATH, self.__user_config)
|
||||
utility.write_json(utility.CONFIG_FILE_PATH, self.__user_config)
|
||||
|
||||
def get(self, key, default_value=None):
|
||||
"""
|
||||
|
@ -315,7 +315,7 @@ class Config(object):
|
|||
return self.__user_config != config.__user_config
|
||||
|
||||
|
||||
class TrayAction(object):
|
||||
class TrayAction:
|
||||
"""
|
||||
Data object wrapping name, icon and action.
|
||||
"""
|
||||
|
@ -331,7 +331,7 @@ class TrayAction(object):
|
|||
if self.system_icon:
|
||||
return self.__icon
|
||||
else:
|
||||
image = Utility.load_and_scale_image(self.__icon, 16, 16)
|
||||
image = utility.load_and_scale_image(self.__icon, 16, 16)
|
||||
image.show()
|
||||
return image
|
||||
|
||||
|
@ -345,7 +345,7 @@ class TrayAction(object):
|
|||
|
||||
@classmethod
|
||||
def build(cls, name, icon_path, icon_id, action):
|
||||
image = Utility.load_and_scale_image(icon_path, 12, 12)
|
||||
image = utility.load_and_scale_image(icon_path, 12, 12)
|
||||
if image is None:
|
||||
return TrayAction(name, icon_id, action, True)
|
||||
else:
|
||||
|
|
|
@ -47,15 +47,15 @@ import logging
|
|||
import os
|
||||
import sys
|
||||
|
||||
from safeeyes import Utility
|
||||
from safeeyes import utility
|
||||
|
||||
sys.path.append(os.path.abspath(Utility.SYSTEM_PLUGINS_DIR))
|
||||
sys.path.append(os.path.abspath(Utility.USER_PLUGINS_DIR))
|
||||
sys.path.append(os.path.abspath(utility.SYSTEM_PLUGINS_DIR))
|
||||
sys.path.append(os.path.abspath(utility.USER_PLUGINS_DIR))
|
||||
|
||||
HORIZONTAL_LINE_LENGTH = 64
|
||||
|
||||
|
||||
class PluginManager(object):
|
||||
class PluginManager:
|
||||
"""
|
||||
Imports the Safe Eyes plugins and calls the methods defined in those plugins.
|
||||
"""
|
||||
|
@ -246,10 +246,10 @@ class PluginManager(object):
|
|||
|
||||
# Look for plugin.py
|
||||
plugin_dir = None
|
||||
if os.path.isfile(os.path.join(Utility.SYSTEM_PLUGINS_DIR, plugin['id'], 'plugin.py')):
|
||||
plugin_dir = Utility.SYSTEM_PLUGINS_DIR
|
||||
elif os.path.isfile(os.path.join(Utility.USER_PLUGINS_DIR, plugin['id'], 'plugin.py')):
|
||||
plugin_dir = Utility.USER_PLUGINS_DIR
|
||||
if os.path.isfile(os.path.join(utility.SYSTEM_PLUGINS_DIR, plugin['id'], 'plugin.py')):
|
||||
plugin_dir = utility.SYSTEM_PLUGINS_DIR
|
||||
elif os.path.isfile(os.path.join(utility.USER_PLUGINS_DIR, plugin['id'], 'plugin.py')):
|
||||
plugin_dir = utility.USER_PLUGINS_DIR
|
||||
else:
|
||||
logging.error('plugin.py not found for the plugin: %s', plugin['id'])
|
||||
return
|
||||
|
@ -259,7 +259,7 @@ class PluginManager(object):
|
|||
if not os.path.isfile(plugin_config_path):
|
||||
logging.error('config.json not found for the plugin: %s', plugin['id'])
|
||||
return
|
||||
plugin_config = Utility.load_json(plugin_config_path)
|
||||
plugin_config = utility.load_json(plugin_config_path)
|
||||
if plugin_config is None:
|
||||
return
|
||||
|
||||
|
@ -292,7 +292,7 @@ class PluginManager(object):
|
|||
else:
|
||||
# This is the first time to load the plugin
|
||||
# Check for dependencies
|
||||
if Utility.check_plugin_dependencies(plugin['id'], plugin_config, plugin_path):
|
||||
if utility.check_plugin_dependencies(plugin['id'], plugin_config, plugin_path):
|
||||
return
|
||||
|
||||
# Load the plugin module
|
|
@ -21,7 +21,7 @@ Audible Alert plugin plays a sound after each breaks to notify the user that the
|
|||
"""
|
||||
|
||||
import logging
|
||||
from safeeyes import Utility
|
||||
from safeeyes import utility
|
||||
|
||||
context = None
|
||||
pre_break_alert = False
|
||||
|
@ -37,10 +37,10 @@ def play_sound(resource_name):
|
|||
logging.info('Playing audible alert %s', resource_name)
|
||||
try:
|
||||
# Open the sound file
|
||||
path = Utility.get_resource_path(resource_name)
|
||||
path = utility.get_resource_path(resource_name)
|
||||
if path is None:
|
||||
return
|
||||
Utility.execute_command('aplay', ['-q', path])
|
||||
utility.execute_command('aplay', ['-q', path])
|
||||
|
||||
except BaseException:
|
||||
logging.error('Failed to play audible alert %s', resource_name)
|
||||
|
|
|
@ -24,7 +24,7 @@ import gi
|
|||
import logging
|
||||
import os
|
||||
|
||||
from safeeyes import Utility
|
||||
from safeeyes import utility
|
||||
from safeeyes.model import TrayAction
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
@ -54,23 +54,23 @@ def __lock_screen_command():
|
|||
current_desktop = os.environ.get('XDG_CURRENT_DESKTOP')
|
||||
if desktop_session is not None:
|
||||
desktop_session = desktop_session.lower()
|
||||
if ('xfce' in desktop_session or desktop_session.startswith('xubuntu') or (current_desktop is not None and 'xfce' in current_desktop)) and Utility.command_exist('xflock4'):
|
||||
if ('xfce' in desktop_session or desktop_session.startswith('xubuntu') or (current_desktop is not None and 'xfce' in current_desktop)) and utility.command_exist('xflock4'):
|
||||
return ['xflock4']
|
||||
elif desktop_session == 'cinnamon' and Utility.command_exist('cinnamon-screensaver-command'):
|
||||
elif desktop_session == 'cinnamon' and utility.command_exist('cinnamon-screensaver-command'):
|
||||
return ['cinnamon-screensaver-command', '--lock']
|
||||
elif (desktop_session == 'pantheon' or desktop_session.startswith('lubuntu')) and Utility.command_exist('light-locker-command'):
|
||||
elif (desktop_session == 'pantheon' or desktop_session.startswith('lubuntu')) and utility.command_exist('light-locker-command'):
|
||||
return ['light-locker-command', '--lock']
|
||||
elif desktop_session == 'mate' and Utility.command_exist('mate-screensaver-command'):
|
||||
elif desktop_session == 'mate' and utility.command_exist('mate-screensaver-command'):
|
||||
return ['mate-screensaver-command', '--lock']
|
||||
elif desktop_session == 'kde' or 'plasma' in desktop_session or desktop_session.startswith('kubuntu') or os.environ.get('KDE_FULL_SESSION') == 'true':
|
||||
return ['qdbus', 'org.freedesktop.ScreenSaver', '/ScreenSaver', 'Lock']
|
||||
elif desktop_session in ['gnome', 'unity', 'budgie-desktop'] or desktop_session.startswith('ubuntu'):
|
||||
if Utility.command_exist('gnome-screensaver-command'):
|
||||
if utility.command_exist('gnome-screensaver-command'):
|
||||
return ['gnome-screensaver-command', '--lock']
|
||||
# From Gnome 3.8 no gnome-screensaver-command
|
||||
return ['dbus-send', '--type=method_call', '--dest=org.gnome.ScreenSaver', '/org/gnome/ScreenSaver', 'org.gnome.ScreenSaver.Lock']
|
||||
elif os.environ.get('GNOME_DESKTOP_SESSION_ID'):
|
||||
if 'deprecated' not in os.environ.get('GNOME_DESKTOP_SESSION_ID') and Utility.command_exist('gnome-screensaver-command'):
|
||||
if 'deprecated' not in os.environ.get('GNOME_DESKTOP_SESSION_ID') and utility.command_exist('gnome-screensaver-command'):
|
||||
# Gnome 2
|
||||
return ['gnome-screensaver-command', '--lock']
|
||||
return None
|
||||
|
@ -125,7 +125,7 @@ def on_stop_break():
|
|||
Lock the screen after a long break if the user has not skipped within min_seconds.
|
||||
"""
|
||||
if user_locked_screen or (lock_screen and seconds_passed >= min_seconds):
|
||||
Utility.execute_command(lock_screen_command)
|
||||
utility.execute_command(lock_screen_command)
|
||||
|
||||
|
||||
def get_tray_action(break_obj):
|
||||
|
|
|
@ -16,16 +16,16 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from safeeyes import Utility
|
||||
from safeeyes import utility
|
||||
|
||||
|
||||
def validate(plugin_config):
|
||||
command = None
|
||||
if Utility.DESKTOP_ENVIRONMENT == "gnome" and Utility.IS_WAYLAND:
|
||||
if utility.DESKTOP_ENVIRONMENT == "gnome" and utility.IS_WAYLAND:
|
||||
command = "dbus-send"
|
||||
else:
|
||||
command = "xprintidle"
|
||||
if not Utility.command_exist(command):
|
||||
if not utility.command_exist(command):
|
||||
return _("Please install the command-line tool '%s'") % command
|
||||
else:
|
||||
return None
|
||||
|
|
|
@ -23,7 +23,7 @@ import threading
|
|||
import re
|
||||
import os
|
||||
|
||||
from safeeyes import Utility
|
||||
from safeeyes import utility
|
||||
from safeeyes.model import State
|
||||
|
||||
"""
|
||||
|
@ -176,7 +176,7 @@ def on_start():
|
|||
# If SmartPause is already started, do not start it again
|
||||
logging.debug('Start Smart Pause plugin')
|
||||
__set_active(True)
|
||||
Utility.start_thread(__start_idle_monitor)
|
||||
utility.start_thread(__start_idle_monitor)
|
||||
|
||||
|
||||
def on_stop():
|
||||
|
|
|
@ -23,7 +23,7 @@ gi.require_version('AppIndicator3', '0.1')
|
|||
from gi.repository import AppIndicator3 as appindicator
|
||||
from gi.repository import Gtk
|
||||
import logging
|
||||
from safeeyes import Utility
|
||||
from safeeyes import utility
|
||||
import threading
|
||||
import time
|
||||
|
||||
|
@ -37,7 +37,7 @@ tray_icon = None
|
|||
safeeyes_config = None
|
||||
|
||||
|
||||
class TrayIcon(object):
|
||||
class TrayIcon:
|
||||
"""
|
||||
Create and show the tray icon along with the tray menu.
|
||||
"""
|
||||
|
@ -193,7 +193,7 @@ class TrayIcon(object):
|
|||
self.indicator.set_icon("safeeyes_enabled")
|
||||
else:
|
||||
if self.wakeup_time:
|
||||
self.item_info.set_label(_('Disabled until %s') % Utility.format_time(self.wakeup_time))
|
||||
self.item_info.set_label(_('Disabled until %s') % utility.format_time(self.wakeup_time))
|
||||
else:
|
||||
self.item_info.set_label(_('Disabled until restart'))
|
||||
self.indicator.set_label('', '')
|
||||
|
@ -263,10 +263,10 @@ class TrayIcon(object):
|
|||
"""
|
||||
A private method to be called within this class to update the next break information using self.dateTime.
|
||||
"""
|
||||
formatted_time = Utility.format_time(self.date_time)
|
||||
formatted_time = utility.format_time(self.date_time)
|
||||
message = _('Next break at %s') % (formatted_time)
|
||||
# Update the menu item label
|
||||
Utility.execute_main_thread(self.item_info.set_label, message)
|
||||
utility.execute_main_thread(self.item_info.set_label, message)
|
||||
# Update the tray icon label
|
||||
if self.plugin_config.get('show_time_in_tray', False):
|
||||
self.indicator.set_label(formatted_time, '')
|
||||
|
@ -311,10 +311,10 @@ class TrayIcon(object):
|
|||
self.item_info.set_label(info)
|
||||
else:
|
||||
self.wakeup_time = datetime.datetime.now() + datetime.timedelta(minutes=time_to_wait)
|
||||
info = _('Disabled until %s') % Utility.format_time(self.wakeup_time)
|
||||
info = _('Disabled until %s') % utility.format_time(self.wakeup_time)
|
||||
self.on_disable(info)
|
||||
self.item_info.set_label(info)
|
||||
Utility.start_thread(self.__schedule_resume, time_minutes=time_to_wait)
|
||||
utility.start_thread(self.__schedule_resume, time_minutes=time_to_wait)
|
||||
|
||||
def lock_menu(self):
|
||||
"""
|
||||
|
@ -368,25 +368,25 @@ class TrayIcon(object):
|
|||
|
||||
with self.lock:
|
||||
if not self.active:
|
||||
Utility.execute_main_thread(self.item_enable.activate)
|
||||
utility.execute_main_thread(self.item_enable.activate)
|
||||
|
||||
def start_animation(self):
|
||||
if not self.active or not self.animate:
|
||||
return
|
||||
Utility.execute_main_thread(lambda: self.indicator.set_icon("safeeyes_disabled"))
|
||||
utility.execute_main_thread(lambda: self.indicator.set_icon("safeeyes_disabled"))
|
||||
time.sleep(0.5)
|
||||
Utility.execute_main_thread(lambda: self.indicator.set_icon("safeeyes_enabled"))
|
||||
utility.execute_main_thread(lambda: self.indicator.set_icon("safeeyes_enabled"))
|
||||
if self.animate and self.active:
|
||||
time.sleep(0.5)
|
||||
if self.animate and self.active:
|
||||
Utility.start_thread(self.start_animation)
|
||||
utility.start_thread(self.start_animation)
|
||||
|
||||
def stop_animation(self):
|
||||
self.animate = False
|
||||
if self.active:
|
||||
Utility.execute_main_thread(lambda: self.indicator.set_icon("safeeyes_enabled"))
|
||||
utility.execute_main_thread(lambda: self.indicator.set_icon("safeeyes_enabled"))
|
||||
else:
|
||||
Utility.execute_main_thread(lambda: self.indicator.set_icon("safeeyes_disabled"))
|
||||
utility.execute_main_thread(lambda: self.indicator.set_icon("safeeyes_disabled"))
|
||||
|
||||
def init(ctx, safeeyes_cfg, plugin_config):
|
||||
"""
|
||||
|
@ -429,7 +429,7 @@ def __unlock_menu():
|
|||
"""
|
||||
Unlock the menu
|
||||
"""
|
||||
Utility.execute_main_thread(tray_icon.unlock_menu)
|
||||
utility.execute_main_thread(tray_icon.unlock_menu)
|
||||
|
||||
|
||||
def on_start():
|
||||
|
|
|
@ -26,7 +26,7 @@ from xmlrpc.server import SimpleXMLRPCServer
|
|||
from xmlrpc.client import ServerProxy
|
||||
|
||||
|
||||
class RPCServer(object):
|
||||
class RPCServer:
|
||||
"""
|
||||
An aynchronous RPC server.
|
||||
"""
|
||||
|
@ -62,7 +62,7 @@ class RPCServer(object):
|
|||
self.__server.shutdown()
|
||||
|
||||
|
||||
class RPCClient(object):
|
||||
class RPCClient:
|
||||
"""
|
||||
An RPC client to communicate with the RPC server.
|
||||
"""
|
||||
|
|
|
@ -28,14 +28,14 @@ from threading import Timer
|
|||
import dbus
|
||||
import gi
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
from safeeyes import Utility
|
||||
from safeeyes.AboutDialog import AboutDialog
|
||||
from safeeyes.BreakScreen import BreakScreen
|
||||
from safeeyes import utility
|
||||
from safeeyes.ui.about_dialog import AboutDialog
|
||||
from safeeyes.ui.break_screen import BreakScreen
|
||||
from safeeyes.model import State
|
||||
from safeeyes.rpc import RPCServer
|
||||
from safeeyes.PluginManager import PluginManager
|
||||
from safeeyes.SafeEyesCore import SafeEyesCore
|
||||
from safeeyes.settings import SettingsDialog
|
||||
from safeeyes.plugin_manager import PluginManager
|
||||
from safeeyes.core import SafeEyesCore
|
||||
from safeeyes.ui.settings_dialog import SettingsDialog
|
||||
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
@ -43,7 +43,7 @@ from gi.repository import Gtk
|
|||
SAFE_EYES_VERSION = "2.0.9"
|
||||
|
||||
|
||||
class SafeEyes(object):
|
||||
class SafeEyes:
|
||||
"""
|
||||
This class represents a runnable Safe Eyes instance.
|
||||
"""
|
||||
|
@ -61,28 +61,28 @@ class SafeEyes(object):
|
|||
|
||||
# Initialize the Safe Eyes Context
|
||||
self.context['version'] = SAFE_EYES_VERSION
|
||||
self.context['desktop'] = Utility.desktop_environment()
|
||||
self.context['is_wayland'] = Utility.is_wayland()
|
||||
self.context['desktop'] = utility.desktop_environment()
|
||||
self.context['is_wayland'] = utility.is_wayland()
|
||||
self.context['locale'] = system_locale
|
||||
self.context['api'] = {}
|
||||
self.context['api']['show_settings'] = lambda: Utility.execute_main_thread(
|
||||
self.context['api']['show_settings'] = lambda: utility.execute_main_thread(
|
||||
self.show_settings)
|
||||
self.context['api']['show_about'] = lambda: Utility.execute_main_thread(
|
||||
self.context['api']['show_about'] = lambda: utility.execute_main_thread(
|
||||
self.show_about)
|
||||
self.context['api']['enable_safeeyes'] = lambda next_break_time=- \
|
||||
1: Utility.execute_main_thread(self.enable_safeeyes, next_break_time)
|
||||
self.context['api']['disable_safeeyes'] = lambda status: Utility.execute_main_thread(
|
||||
1: utility.execute_main_thread(self.enable_safeeyes, next_break_time)
|
||||
self.context['api']['disable_safeeyes'] = lambda status: utility.execute_main_thread(
|
||||
self.disable_safeeyes, status)
|
||||
self.context['api']['status'] = self.status
|
||||
self.context['api']['quit'] = lambda: Utility.execute_main_thread(
|
||||
self.context['api']['quit'] = lambda: utility.execute_main_thread(
|
||||
self.quit)
|
||||
if self.config.get('persist_state'):
|
||||
self.context['session'] = Utility.open_session()
|
||||
self.context['session'] = utility.open_session()
|
||||
else:
|
||||
self.context['session'] = {'plugin': {}}
|
||||
|
||||
self.break_screen = BreakScreen(
|
||||
self.context, self.on_skipped, self.on_postponed, Utility.STYLE_SHEET_PATH)
|
||||
self.context, self.on_skipped, self.on_postponed, utility.STYLE_SHEET_PATH)
|
||||
self.break_screen.initialize(self.config)
|
||||
self.plugins_manager = PluginManager(self.context, self.config)
|
||||
self.safe_eyes_core = SafeEyesCore(self.context)
|
||||
|
@ -93,7 +93,7 @@ class SafeEyes(object):
|
|||
self.safe_eyes_core.on_stop_break += self.stop_break
|
||||
self.safe_eyes_core.on_update_next_break += self.update_next_break
|
||||
self.safe_eyes_core.initialize(self.config)
|
||||
self.context['api']['take_break'] = lambda: Utility.execute_main_thread(
|
||||
self.context['api']['take_break'] = lambda: utility.execute_main_thread(
|
||||
self.safe_eyes_core.take_break)
|
||||
self.context['api']['has_breaks'] = self.safe_eyes_core.has_breaks
|
||||
self.context['api']['postpone'] = self.safe_eyes_core.postpone
|
||||
|
@ -282,9 +282,9 @@ class SafeEyes(object):
|
|||
"""
|
||||
self.plugins_manager.update_next_break(break_obj, break_time)
|
||||
self._status = _('Next break at %s') % (
|
||||
Utility.format_time(break_time))
|
||||
utility.format_time(break_time))
|
||||
if self.config.get('persist_state'):
|
||||
Utility.write_json(Utility.SESSION_FILE_PATH,
|
||||
utility.write_json(utility.SESSION_FILE_PATH,
|
||||
self.context['session'])
|
||||
|
||||
def stop_break(self):
|
||||
|
@ -312,10 +312,10 @@ class SafeEyes(object):
|
|||
Save the session object to the session file.
|
||||
"""
|
||||
if self.config.get('persist_state'):
|
||||
Utility.write_json(Utility.SESSION_FILE_PATH,
|
||||
utility.write_json(utility.SESSION_FILE_PATH,
|
||||
self.context['session'])
|
||||
else:
|
||||
Utility.delete(Utility.SESSION_FILE_PATH)
|
||||
utility.delete(utility.SESSION_FILE_PATH)
|
||||
|
||||
def __start_rpc_server(self):
|
||||
if self.rpc_server is None:
|
|
@ -22,19 +22,19 @@ This module creates the AboutDialog which shows the version and license.
|
|||
|
||||
import os
|
||||
|
||||
from safeeyes import Utility
|
||||
from safeeyes import utility
|
||||
|
||||
ABOUT_DIALOG_GLADE = os.path.join(Utility.BIN_DIRECTORY, "glade/about_dialog.glade")
|
||||
ABOUT_DIALOG_GLADE = os.path.join(utility.BIN_DIRECTORY, "glade/about_dialog.glade")
|
||||
|
||||
|
||||
class AboutDialog(object):
|
||||
class AboutDialog:
|
||||
"""
|
||||
AboutDialog reads the about_dialog.glade and build the user interface using that file.
|
||||
It shows the application name with version, a small description, license and the GitHub url.
|
||||
"""
|
||||
|
||||
def __init__(self, version):
|
||||
builder = Utility.create_gtk_builder(ABOUT_DIALOG_GLADE)
|
||||
builder = utility.create_gtk_builder(ABOUT_DIALOG_GLADE)
|
||||
builder.connect_signals(self)
|
||||
self.window = builder.get_object('window_about')
|
||||
builder.get_object('lbl_decription').set_label(_('description'))
|
|
@ -23,7 +23,7 @@ import threading
|
|||
import time
|
||||
|
||||
import gi
|
||||
from safeeyes import Utility
|
||||
from safeeyes import utility
|
||||
from Xlib.display import Display
|
||||
from Xlib.display import X
|
||||
|
||||
|
@ -32,10 +32,10 @@ from gi.repository import Gdk
|
|||
from gi.repository import GLib
|
||||
from gi.repository import Gtk
|
||||
|
||||
BREAK_SCREEN_GLADE = os.path.join(Utility.BIN_DIRECTORY, "glade/break_screen.glade")
|
||||
BREAK_SCREEN_GLADE = os.path.join(utility.BIN_DIRECTORY, "glade/break_screen.glade")
|
||||
|
||||
|
||||
class BreakScreen(object):
|
||||
class BreakScreen:
|
||||
"""
|
||||
The fullscreen window which prevents users from using the computer.
|
||||
This class reads the break_screen.glade and build the user interface.
|
||||
|
@ -149,7 +149,7 @@ class BreakScreen(object):
|
|||
Show an empty break screen on all screens.
|
||||
"""
|
||||
# Lock the keyboard
|
||||
Utility.start_thread(self.__lock_keyboard)
|
||||
utility.start_thread(self.__lock_keyboard)
|
||||
|
||||
screen = Gtk.Window().get_screen()
|
||||
no_of_monitors = screen.get_n_monitors()
|
|
@ -20,7 +20,7 @@ import math
|
|||
import os
|
||||
|
||||
import gi
|
||||
from safeeyes import Utility
|
||||
from safeeyes import utility
|
||||
from safeeyes.model import Config
|
||||
|
||||
gi.require_version('Gtk', '3.0')
|
||||
|
@ -28,18 +28,18 @@ from gi.repository import Gtk
|
|||
from gi.repository import GdkPixbuf
|
||||
|
||||
|
||||
SETTINGS_DIALOG_GLADE = os.path.join(Utility.BIN_DIRECTORY, "glade/settings_dialog.glade")
|
||||
SETTINGS_DIALOG_PLUGIN_GLADE = os.path.join(Utility.BIN_DIRECTORY, "glade/settings_plugin.glade")
|
||||
SETTINGS_DIALOG_BREAK_GLADE = os.path.join(Utility.BIN_DIRECTORY, "glade/settings_break.glade")
|
||||
SETTINGS_DIALOG_NEW_BREAK_GLADE = os.path.join(Utility.BIN_DIRECTORY, "glade/new_break.glade")
|
||||
SETTINGS_BREAK_ITEM_GLADE = os.path.join(Utility.BIN_DIRECTORY, "glade/item_break.glade")
|
||||
SETTINGS_PLUGIN_ITEM_GLADE = os.path.join(Utility.BIN_DIRECTORY, "glade/item_plugin.glade")
|
||||
SETTINGS_ITEM_INT_GLADE = os.path.join(Utility.BIN_DIRECTORY, "glade/item_int.glade")
|
||||
SETTINGS_ITEM_TEXT_GLADE = os.path.join(Utility.BIN_DIRECTORY, "glade/item_text.glade")
|
||||
SETTINGS_ITEM_BOOL_GLADE = os.path.join(Utility.BIN_DIRECTORY, "glade/item_bool.glade")
|
||||
SETTINGS_DIALOG_GLADE = os.path.join(utility.BIN_DIRECTORY, "glade/settings_dialog.glade")
|
||||
SETTINGS_DIALOG_PLUGIN_GLADE = os.path.join(utility.BIN_DIRECTORY, "glade/settings_plugin.glade")
|
||||
SETTINGS_DIALOG_BREAK_GLADE = os.path.join(utility.BIN_DIRECTORY, "glade/settings_break.glade")
|
||||
SETTINGS_DIALOG_NEW_BREAK_GLADE = os.path.join(utility.BIN_DIRECTORY, "glade/new_break.glade")
|
||||
SETTINGS_BREAK_ITEM_GLADE = os.path.join(utility.BIN_DIRECTORY, "glade/item_break.glade")
|
||||
SETTINGS_PLUGIN_ITEM_GLADE = os.path.join(utility.BIN_DIRECTORY, "glade/item_plugin.glade")
|
||||
SETTINGS_ITEM_INT_GLADE = os.path.join(utility.BIN_DIRECTORY, "glade/item_int.glade")
|
||||
SETTINGS_ITEM_TEXT_GLADE = os.path.join(utility.BIN_DIRECTORY, "glade/item_text.glade")
|
||||
SETTINGS_ITEM_BOOL_GLADE = os.path.join(utility.BIN_DIRECTORY, "glade/item_bool.glade")
|
||||
|
||||
|
||||
class SettingsDialog(object):
|
||||
class SettingsDialog:
|
||||
"""
|
||||
Create and initialize SettingsDialog instance.
|
||||
"""
|
||||
|
@ -54,7 +54,7 @@ class SettingsDialog(object):
|
|||
self.infobar_long_break_shown = False
|
||||
self.warn_bar_rpc_server_shown = False
|
||||
|
||||
builder = Utility.create_gtk_builder(SETTINGS_DIALOG_GLADE)
|
||||
builder = utility.create_gtk_builder(SETTINGS_DIALOG_GLADE)
|
||||
builder.connect_signals(self)
|
||||
|
||||
self.window = builder.get_object('window_settings')
|
||||
|
@ -101,7 +101,7 @@ class SettingsDialog(object):
|
|||
for long_break in config.get('long_breaks'):
|
||||
self.__create_break_item(long_break, False)
|
||||
|
||||
for plugin_config in Utility.load_plugins_config(config):
|
||||
for plugin_config in utility.load_plugins_config(config):
|
||||
self.box_plugins.pack_start(self.__create_plugin_item(plugin_config), False, False, 0)
|
||||
|
||||
self.spin_short_break_duration.set_value(config.get('short_break_duration'))
|
||||
|
@ -124,7 +124,7 @@ class SettingsDialog(object):
|
|||
parent_box = self.box_long_breaks
|
||||
if is_short:
|
||||
parent_box = self.box_short_breaks
|
||||
builder = Utility.create_gtk_builder(SETTINGS_BREAK_ITEM_GLADE)
|
||||
builder = utility.create_gtk_builder(SETTINGS_BREAK_ITEM_GLADE)
|
||||
box = builder.get_object('box')
|
||||
lbl_name = builder.get_object('lbl_name')
|
||||
lbl_name.set_label(_(break_config['name']))
|
||||
|
@ -157,7 +157,7 @@ class SettingsDialog(object):
|
|||
self.popover.hide()
|
||||
def __confirmation_dialog_response(widget, response_id):
|
||||
if response_id == Gtk.ResponseType.OK:
|
||||
Utility.reset_config()
|
||||
utility.reset_config()
|
||||
self.config = Config()
|
||||
# Remove breaks from the container
|
||||
self.box_short_breaks.foreach(lambda element: self.box_short_breaks.remove(element))
|
||||
|
@ -206,7 +206,7 @@ class SettingsDialog(object):
|
|||
"""
|
||||
Create an entry for plugin to be listed in the plugin tab.
|
||||
"""
|
||||
builder = Utility.create_gtk_builder(SETTINGS_PLUGIN_ITEM_GLADE)
|
||||
builder = utility.create_gtk_builder(SETTINGS_PLUGIN_ITEM_GLADE)
|
||||
lbl_plugin_name = builder.get_object('lbl_plugin_name')
|
||||
lbl_plugin_description = builder.get_object('lbl_plugin_description')
|
||||
switch_enable = builder.get_object('switch_enable')
|
||||
|
@ -336,7 +336,7 @@ class SettingsDialog(object):
|
|||
self.window.destroy()
|
||||
|
||||
|
||||
class PluginSettingsDialog(object):
|
||||
class PluginSettingsDialog:
|
||||
"""
|
||||
Builds a settings dialog based on the configuration of a plugin.
|
||||
"""
|
||||
|
@ -345,7 +345,7 @@ class PluginSettingsDialog(object):
|
|||
self.config = config
|
||||
self.property_controls = []
|
||||
|
||||
builder = Utility.create_gtk_builder(SETTINGS_DIALOG_PLUGIN_GLADE)
|
||||
builder = utility.create_gtk_builder(SETTINGS_DIALOG_PLUGIN_GLADE)
|
||||
builder.connect_signals(self)
|
||||
self.window = builder.get_object('dialog_settings_plugin')
|
||||
box_settings = builder.get_object('box_settings')
|
||||
|
@ -362,7 +362,7 @@ class PluginSettingsDialog(object):
|
|||
"""
|
||||
Load the UI control for int property.
|
||||
"""
|
||||
builder = Utility.create_gtk_builder(SETTINGS_ITEM_INT_GLADE)
|
||||
builder = utility.create_gtk_builder(SETTINGS_ITEM_INT_GLADE)
|
||||
builder.get_object('lbl_name').set_label(_(name))
|
||||
spin_value = builder.get_object('spin_value')
|
||||
spin_value.set_range(min_value, max_value)
|
||||
|
@ -376,7 +376,7 @@ class PluginSettingsDialog(object):
|
|||
"""
|
||||
Load the UI control for text property.
|
||||
"""
|
||||
builder = Utility.create_gtk_builder(SETTINGS_ITEM_TEXT_GLADE)
|
||||
builder = utility.create_gtk_builder(SETTINGS_ITEM_TEXT_GLADE)
|
||||
builder.get_object('lbl_name').set_label(_(name))
|
||||
txt_value = builder.get_object('txt_value')
|
||||
txt_value.set_text(settings[key])
|
||||
|
@ -389,7 +389,7 @@ class PluginSettingsDialog(object):
|
|||
"""
|
||||
Load the UI control for boolean property.
|
||||
"""
|
||||
builder = Utility.create_gtk_builder(SETTINGS_ITEM_BOOL_GLADE)
|
||||
builder = utility.create_gtk_builder(SETTINGS_ITEM_BOOL_GLADE)
|
||||
builder.get_object('lbl_name').set_label(_(name))
|
||||
switch_value = builder.get_object('switch_value')
|
||||
switch_value.set_active(settings[key])
|
||||
|
@ -413,7 +413,7 @@ class PluginSettingsDialog(object):
|
|||
self.window.show_all()
|
||||
|
||||
|
||||
class BreakSettingsDialog(object):
|
||||
class BreakSettingsDialog:
|
||||
"""
|
||||
Builds a settings dialog based on the configuration of a plugin.
|
||||
"""
|
||||
|
@ -427,7 +427,7 @@ class BreakSettingsDialog(object):
|
|||
self.on_add = on_add
|
||||
self.on_remove = on_remove
|
||||
|
||||
builder = Utility.create_gtk_builder(SETTINGS_DIALOG_BREAK_GLADE)
|
||||
builder = utility.create_gtk_builder(SETTINGS_DIALOG_BREAK_GLADE)
|
||||
builder.connect_signals(self)
|
||||
self.window = builder.get_object('dialog_settings_break')
|
||||
self.txt_break = builder.get_object('txt_break')
|
||||
|
@ -583,7 +583,7 @@ class BreakSettingsDialog(object):
|
|||
self.window.show_all()
|
||||
|
||||
|
||||
class NewBreakDialog(object):
|
||||
class NewBreakDialog:
|
||||
"""
|
||||
Builds a new break dialog.
|
||||
"""
|
||||
|
@ -592,7 +592,7 @@ class NewBreakDialog(object):
|
|||
self.parent_config = parent_config
|
||||
self.on_add = on_add
|
||||
|
||||
builder = Utility.create_gtk_builder(SETTINGS_DIALOG_NEW_BREAK_GLADE)
|
||||
builder = utility.create_gtk_builder(SETTINGS_DIALOG_NEW_BREAK_GLADE)
|
||||
builder.connect_signals(self)
|
||||
self.window = builder.get_object('dialog_new_break')
|
||||
self.txt_break = builder.get_object('txt_break')
|
Loading…
Reference in New Issue