예제 #1
0
def main():
    """
	Start the Safe Eyes.
	"""
    # Initialize the logging
    Utility.intialize_logging()

    logging.info("Starting Safe Eyes")

    # Import the dependencies
    Utility.import_dependencies()

    if not running():

        global break_screen
        global core
        global config
        global notification
        global tray_icon
        global language
        global context
        global plugins
        global system_lock_command

        config = Utility.read_config()

        context = {}
        language = Utility.load_language(config['language'])
        # Get the lock command only one time
        if config['lock_screen_command']:
            system_lock_command = config['lock_screen_command']
        else:
            system_lock_command = Utility.lock_screen_command()

        # Initialize the Safe Eyes Context
        context['version'] = SAFE_EYES_VERSION
        context['desktop'] = Utility.desktop_environment()

        tray_icon = TrayIcon(config, language, show_settings, show_about,
                             enable_safeeyes, disable_safeeyes, on_quit)
        break_screen = BreakScreen(context, on_skipped, on_postponed,
                                   break_screen_glade,
                                   Utility.style_sheet_path)
        break_screen.initialize(config, language)
        notification = Notification(context, language)
        plugins = Plugins(config)
        core = SafeEyesCore(context, show_notification, show_alert,
                            close_alert, break_screen.show_count_down,
                            tray_icon.next_break_time)
        core.initialize(config, language)
        plugins.start(context)  # Call the start method of all plugins
        core.start()

        handle_system_suspend()

        Gtk.main()
    else:
        logging.info('Another instance of safeeyes is already running')
        sys.exit(0)
예제 #2
0
    def __init__(self, system_locale, config):
        self.active = False
        self.break_screen = None
        self.safe_eyes_core = None
        self.config = config
        self.context = {}
        self.plugins_manager = None
        self.settings_dialog_active = False
        self.rpc_server = None
        self._status = ''

        # Initialize the Safe Eyes Context
        self.context['version'] = SAFE_EYES_VERSION
        self.context['desktop'] = Utility.desktop_environment()
        self.context['locale'] = system_locale
        self.context['api'] = {}
        self.context['api'][
            'show_settings'] = lambda: Utility.execute_main_thread(
                self.show_settings)
        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(
                self.disable_safeeyes, status)
        self.context['api']['status'] = self.status
        self.context['api']['quit'] = lambda: Utility.execute_main_thread(self.
                                                                          quit)
        if self.config.get('persist_state'):
            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.break_screen.initialize(self.config)
        self.plugins_manager = PluginManager(self.context, self.config)
        self.safe_eyes_core = SafeEyesCore(self.context)
        self.safe_eyes_core.on_pre_break += self.plugins_manager.pre_break
        self.safe_eyes_core.on_start_break += self.on_start_break
        self.safe_eyes_core.start_break += self.start_break
        self.safe_eyes_core.on_count_down += self.countdown
        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.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
        self.plugins_manager.init(self.context, self.config)
        atexit.register(self.persist_session)
        self.rpc_server = RPCServer(self.config.get('rpc_port'), self.context)
        self.rpc_server.start()