How to use safeeyes - 10 common examples

To help you get started, we’ve selected a few safeeyes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github slgobinath / SafeEyes / safeeyes / __main__.py View on Github external
parser = argparse.ArgumentParser(prog='safeeyes', description=_('description'))
    group = parser.add_mutually_exclusive_group()
    group.add_argument('-a', '--about', help=_('show the about dialog'), action='store_true')
    group.add_argument('-d', '--disable', help=_('disable the currently running safeeyes instance'), action='store_true')
    group.add_argument('-e', '--enable', help=_('enable the currently running safeeyes instance'), action='store_true')
    group.add_argument('-q', '--quit', help=_('quit the running safeeyes instance and exit'), action='store_true')
    group.add_argument('-s', '--settings', help=_('show the settings dialog'), action='store_true')
    group.add_argument('-t', '--take-break', help=_('Take a break now').lower(), action='store_true')
    parser.add_argument('--debug', help=_('start safeeyes in debug mode'), action='store_true')
    parser.add_argument('--status', help=_('print the status of running safeeyes instance and exit'), action='store_true')
    parser.add_argument('--version', action='version', version='%(prog)s ' + SAFE_EYES_VERSION)
    args = parser.parse_args()

    # Initialize the logging
    Utility.intialize_logging(args.debug)
    config = Config()

    if __running():
        logging.info("Safe Eyes is already running")
        if not config.get("use_rpc_server", True):
            # RPC sever is disabled
            print(_('Safe Eyes is running without an RPC server. Turn it on to use command-line arguments.'))
            sys.exit(0)
            return
        rpc_client = RPCClient(config.get('rpc_port'))
        if args.about:
            rpc_client.show_about()
        elif args.disable:
            rpc_client.disable_safeeyes()
        elif args.enable:
            rpc_client.enable_safeeyes()
github slgobinath / SafeEyes / safeeyes / plugins / trayicon / plugin.py View on Github external
def __schedule_resume(self, time_minutes):
        """
        Schedule a local timer to enable Safe Eyes after the given timeout.
        """
        self.idle_condition.acquire()
        self.idle_condition.wait(time_minutes * 60)    # Convert to seconds
        self.idle_condition.release()

        with self.lock:
            if not self.active:
                Utility.execute_main_thread(self.item_enable.activate)
github slgobinath / SafeEyes / safeeyes / plugins / smartpause / plugin.py View on Github external
def __start_idle_monitor():
    """
    Continuously check the system idle time and pause/resume Safe Eyes based on it.
    """
    global smart_pause_activated
    global idle_start_time
    while __is_active():
        # Wait for waiting_time seconds
        idle_condition.acquire()
        idle_condition.wait(waiting_time)
        idle_condition.release()

        if __is_active():
            # Get the system idle time
            system_idle_time = __system_idle_time()
            if system_idle_time >= idle_time and context['state'] == State.WAITING:
                smart_pause_activated = True
                idle_start_time = datetime.datetime.now()
                logging.info('Pause Safe Eyes due to system idle')
                disable_safe_eyes(None)
            elif system_idle_time < idle_time and context['state'] == State.STOPPED:
                logging.info('Resume Safe Eyes due to user activity')
                smart_pause_activated = False
                idle_period = (datetime.datetime.now() - idle_start_time)
                idle_seconds = idle_period.total_seconds()
                context['idle_period'] = idle_seconds
                if interpret_idle_as_break and idle_seconds >= next_break_duration:
                    # User is idle for break duration and wants to consider it as a break
                    enable_safe_eyes()
                elif idle_seconds < break_interval:
                    # Credit back the idle time
                    next_break = next_break_time + idle_period
github slgobinath / SafeEyes / safeeyes / plugins / smartpause / plugin.py View on Github external
global idle_start_time
    while __is_active():
        # Wait for waiting_time seconds
        idle_condition.acquire()
        idle_condition.wait(waiting_time)
        idle_condition.release()

        if __is_active():
            # Get the system idle time
            system_idle_time = __system_idle_time()
            if system_idle_time >= idle_time and context['state'] == State.WAITING:
                smart_pause_activated = True
                idle_start_time = datetime.datetime.now()
                logging.info('Pause Safe Eyes due to system idle')
                disable_safe_eyes(None)
            elif system_idle_time < idle_time and context['state'] == State.STOPPED:
                logging.info('Resume Safe Eyes due to user activity')
                smart_pause_activated = False
                idle_period = (datetime.datetime.now() - idle_start_time)
                idle_seconds = idle_period.total_seconds()
                context['idle_period'] = idle_seconds
                if interpret_idle_as_break and idle_seconds >= next_break_duration:
                    # User is idle for break duration and wants to consider it as a break
                    enable_safe_eyes()
                elif idle_seconds < break_interval:
                    # Credit back the idle time
                    next_break = next_break_time + idle_period
                    enable_safe_eyes(next_break.timestamp())
                else:
                    # User is idle for more than the time between two breaks
                    enable_safe_eyes()
github slgobinath / SafeEyes / safeeyes / SafeEyes.py View on Github external
def quit(self):
        """
        Listen to the tray menu quit action and stop the core, notification and the app itself.
        """
        logging.info("Quit Safe Eyes")
        self.context['state'] = State.QUIT
        self.plugins_manager.stop()
        self.safe_eyes_core.stop()
        self.plugins_manager.exit()
        self.__stop_rpc_server()
        self.persist_session()
        Gtk.main_quit()
        # Exit all threads
        os._exit(0)
github slgobinath / SafeEyes / safeeyes / PluginManager.py View on Github external
Executes once the plugin.py is loaded as a module
 - disable()
    Executes if the plugin is disabled at the runtime by the user
 - on_exit()
    Executes before Safe Eyes exits
"""

import importlib
import inspect
import logging
import os
import sys

from safeeyes import Utility

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):
    """
    Imports the Safe Eyes plugins and calls the methods defined in those plugins.
    """

    def __init__(self, context, config):
        logging.info('Load all the plugins')
        self.__plugins = {}
        self.__plugins_on_init = []
        self.__plugins_on_start = []
        self.__plugins_on_stop = []
github slgobinath / SafeEyes / safeeyes / PluginManager.py View on Github external
- disable()
    Executes if the plugin is disabled at the runtime by the user
 - on_exit()
    Executes before Safe Eyes exits
"""

import importlib
import inspect
import logging
import os
import sys

from safeeyes import Utility

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):
    """
    Imports the Safe Eyes plugins and calls the methods defined in those plugins.
    """

    def __init__(self, context, config):
        logging.info('Load all the plugins')
        self.__plugins = {}
        self.__plugins_on_init = []
        self.__plugins_on_start = []
        self.__plugins_on_stop = []
        self.__plugins_on_exit = []
github slgobinath / SafeEyes / safeeyes / __main__.py View on Github external
parser = argparse.ArgumentParser(prog='safeeyes', description=_('description'))
    group = parser.add_mutually_exclusive_group()
    group.add_argument('-a', '--about', help=_('show the about dialog'), action='store_true')
    group.add_argument('-d', '--disable', help=_('disable the currently running safeeyes instance'), action='store_true')
    group.add_argument('-e', '--enable', help=_('enable the currently running safeeyes instance'), action='store_true')
    group.add_argument('-q', '--quit', help=_('quit the running safeeyes instance and exit'), action='store_true')
    group.add_argument('-s', '--settings', help=_('show the settings dialog'), action='store_true')
    group.add_argument('-t', '--take-break', help=_('Take a break now').lower(), action='store_true')
    parser.add_argument('--debug', help=_('start safeeyes in debug mode'), action='store_true')
    parser.add_argument('--status', help=_('print the status of running safeeyes instance and exit'), action='store_true')
    parser.add_argument('--version', action='version', version='%(prog)s ' + SAFE_EYES_VERSION)
    args = parser.parse_args()

    # Initialize the logging
    Utility.intialize_logging(args.debug)
    config = Config()

    if __running():
        logging.info("Safe Eyes is already running")
        if not config.get("use_rpc_server", True):
            # RPC sever is disabled
            print(_('Safe Eyes is running without an RPC server. Turn it on to use command-line arguments.'))
            sys.exit(0)
            return
        rpc_client = RPCClient(config.get('rpc_port'))
        if args.about:
            rpc_client.show_about()
        elif args.disable:
            rpc_client.disable_safeeyes()
        elif args.enable:
            rpc_client.enable_safeeyes()
        elif args.settings:
github slgobinath / SafeEyes / safeeyes / SafeEyesCore.py View on Github external
def __start_next_break(self):
        if not self.context['postponed']:
            self.break_queue.next()

        if self.running:
            # Schedule the break again
            Utility.start_thread(self.__scheduler_job)
github slgobinath / SafeEyes / safeeyes / SafeEyesCore.py View on Github external
def start(self, next_break_time=-1):
        """
        Start Safe Eyes is it is not running already.
        """
        if self.break_queue.is_empty():
            return
        with self.lock:
            if not self.running:
                logging.info("Start Safe Eyes core")
                self.running = True
                self.scheduled_next_break_timestamp = int(next_break_time)
                Utility.start_thread(self.__scheduler_job)