Exemplo n.º 1
0
def show_alert(message, image_name):
	logging.info("Show the break screen")
	notification.close()
	plugins_data = plugins.pre_break(context)
	break_screen.show_message(message, Utility.get_resource_path(image_name), plugins_data)
	if config['strict_break'] and is_active:
		Utility.execute_main_thread(tray_icon.unlock_menu)
Exemplo n.º 2
0
def show_notification():
    """
	Receive the signal from core and pass it to the Notification.
	"""
    if config['strict_break']:
        Utility.execute_main_thread(tray_icon.lock_menu)
    plugins.pre_notification(context)
    notification.show(config['pre_break_warning_time'])
Exemplo n.º 3
0
    def __schedule_resume(self, time_minutes):
        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)
Exemplo n.º 4
0
 def __wait_until_prepare(self):
     logging.info("Wait for %d seconds before the break",
                  self.pre_break_warning_time)
     # Wait for the pre break warning period
     self.__wait_for(self.pre_break_warning_time)
     if not self.running:
         return
     Utility.execute_main_thread(self.__fire_start_break)
Exemplo n.º 5
0
    def __scheduler_job(self):
        """
		Scheduler task to execute during every interval
		"""
        if not self.__is_running():
            return

        time_to_wait = self.break_interval  # In minutes

        if self.context['postponed']:
            # Reduce the break count by 1 to show the same break again
            if self.break_count == 0:
                self.break_count = -1
            else:
                self.break_count = ((self.break_count - 1) %
                                    self.no_of_short_breaks_per_long_break)
            if self.__is_long_break():
                self.long_break_message_index = (
                    self.long_break_message_index - 1) % len(
                        self.long_break_exercises)
            else:
                self.short_break_message_index = (
                    self.short_break_message_index - 1) % len(
                        self.short_break_exercises)

            # Wait until the postpone time
            time_to_wait = self.postpone_duration
            self.context['postponed'] = False

        next_break_time = datetime.datetime.now() + datetime.timedelta(
            minutes=time_to_wait)
        self.update_next_break_info(next_break_time)

        self.break_count = ((self.break_count + 1) %
                            self.no_of_short_breaks_per_long_break)
        if self.__is_long_break():
            self.context['break_type'] = 'long'
        else:
            self.context['break_type'] = 'short'

        # Wait for the pre break warning period
        logging.info("Pre-break waiting for {} minutes".format(time_to_wait))
        self.notification_condition.acquire()
        self.notification_condition.wait(time_to_wait *
                                         60)  # Convert to seconds
        self.notification_condition.release()

        logging.info("Pre-break waiting is over")

        if not self.__is_running():
            return

        logging.info("Ready to show the break")

        self.is_before_break = False
        Utility.execute_main_thread(self.__check_active_window)
Exemplo n.º 6
0
    def __scheduler_job(self):
        """
        Scheduler task to execute during every interval
        """
        if not self.running:
            return

        self.context['state'] = State.WAITING
        time_to_wait = self.break_interval
        current_time = datetime.datetime.now()
        current_timestamp = current_time.timestamp()

        if self.context['postponed']:
            # Previous break was postponed
            logging.info('Prepare for postponed break')
            time_to_wait = self.postpone_duration
            self.context['postponed'] = False

        elif self.paused_time > -1 and self.__is_long_break():
            # Safe Eyes was paused earlier and next break is long
            paused_duration = int(current_timestamp - self.paused_time)
            self.paused_time = -1
            if paused_duration > self.breaks[self.next_break_index].time:
                logging.info(
                    'Skip next long break due to the pause longer than break duration'
                )
                # Skip the next long break
                self.__select_next_break()

        if current_timestamp < self.scheduled_next_break_timestamp:
            time_to_wait = round(self.scheduled_next_break_timestamp -
                                 current_timestamp)
            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)

        if self.__is_long_break():
            self.context['break_type'] = 'long'
        else:
            self.context['break_type'] = 'short'

        # Wait for the pre break warning period
        logging.info("Waiting for %d minutes until next break",
                     (time_to_wait / 60))
        self.__wait_for(time_to_wait)

        logging.info("Pre-break waiting is over")

        if not self.running:
            return

        self.context['new_cycle'] = self.next_break_index == 0
        Utility.execute_main_thread(self.__fire_pre_break)
Exemplo n.º 7
0
 def start_animation(self):
     if not self.active or not self.animate:
         return
     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"))
     if self.animate and self.active:
         time.sleep(0.5)
         if self.animate and self.active:
             Utility.start_thread(self.start_animation)
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
 def __set_next_break_info(self):
     formatted_time = Utility.format_time(self.dateTime)
     message = self.language['messages']['next_break_at'].format(
         formatted_time)
     # Update the tray icon label
     if self.config.get('show_time_in_tray', False):
         self.indicator.set_label(formatted_time, '')
     else:
         self.indicator.set_label('', '')
     # Update the menu item label
     Utility.execute_main_thread(self.item_info.set_label, message)
Exemplo n.º 10
0
	def __show_notification(self):
		# Show the notification
		self.show_notification()

		logging.info("Wait for {} seconds which is the time to prepare".format(self.pre_break_warning_time))
		# Wait for the pre break warning period
		self.notification_condition.acquire()
		self.notification_condition.wait(self.pre_break_warning_time)
		self.notification_condition.release()

		self.is_before_break = True
		Utility.execute_main_thread(self.__check_active_window)
Exemplo n.º 11
0
 def __set_next_break_info(self):
     """
     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)
     message = _('Next break at %s') % (formatted_time)
     # Update the menu item label
     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, '')
     else:
         self.indicator.set_label('', '')
Exemplo n.º 12
0
def __evaluate_arguments(args, safe_eyes):
    """
    Evaluate the arguments and execute the operations.
    """
    if args.about:
        Utility.execute_main_thread(safe_eyes.show_about)
    elif args.disable:
        Utility.execute_main_thread(safe_eyes.disable_safeeyes)
    elif args.enable:
        Utility.execute_main_thread(safe_eyes.enable_safeeyes)
    elif args.settings:
        Utility.execute_main_thread(safe_eyes.show_settings)
    elif args.take_break:
        Utility.execute_main_thread(safe_eyes.take_break)
Exemplo n.º 13
0
    def __start_break(self):
        """
        Start the break screen.
        """
        self.context['state'] = State.BREAK
        break_obj = self.breaks[self.next_break_index]
        countdown = break_obj.time
        total_break_time = countdown

        while countdown and self.running and not self.context[
                'skipped'] and not self.context['postponed']:
            seconds = total_break_time - countdown
            self.on_count_down.fire(countdown, seconds)
            time.sleep(1)  # Sleep for 1 second
            countdown -= 1
        Utility.execute_main_thread(self.__fire_stop_break)
Exemplo n.º 14
0
    def __scheduler_job(self):
        """
        Scheduler task to execute during every interval
        """
        if not self.running:
            return

        self.context['state'] = State.WAITING
        time_to_wait = self.break_interval

        if self.context['postponed']:
            # Wait until the postpone time
            time_to_wait = self.postpone_duration
            self.context['postponed'] = False

        current_time = datetime.datetime.now()
        current_timestamp = current_time.timestamp()
        if current_timestamp < self.scheduled_next_break_time:
            time_to_wait = round(self.scheduled_next_break_time -
                                 current_timestamp)
            self.scheduled_next_break_time = -1

        next_break_time = current_time + datetime.timedelta(
            seconds=time_to_wait)
        Utility.execute_main_thread(self.__fire_on_update_next_break,
                                    next_break_time)

        if self.__is_long_break():
            self.context['break_type'] = 'long'
        else:
            self.context['break_type'] = 'short'

        # Wait for the pre break warning period
        logging.info("Waiting for %d minutes until next break",
                     (time_to_wait / 60))
        self.__wait_for(time_to_wait)

        logging.info("Pre-break waiting is over")

        if not self.running:
            return

        self.context['new_cycle'] = self.next_break_index == 0
        Utility.execute_main_thread(self.__fire_pre_break)
Exemplo n.º 15
0
    def __take_break(self):
        """
        Show the next break screen
        """
        logging.info('Take a break due to external request')

        with self.lock:
            if not self.running:
                return

            logging.info("Stop the scheduler")

            # Stop the break thread
            self.waiting_condition.acquire()
            self.running = False
            self.waiting_condition.notify_all()
            self.waiting_condition.release()
            time.sleep(1)  # Wait for 1 sec to ensure the sceduler is dead
            self.running = True

        Utility.execute_main_thread(self.__fire_start_break)
Exemplo n.º 16
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()
Exemplo n.º 17
0
 def __postpone_break(self):
     self.__wait_for(self.postpone_duration)
     Utility.execute_main_thread(self.__fire_start_break)
Exemplo n.º 18
0
 def show_icon(self):
     Utility.execute_main_thread(self.indicator.set_status,
                                 appindicator.IndicatorStatus.ACTIVE)
Exemplo n.º 19
0
 def hide_icon(self):
     Utility.execute_main_thread(self.indicator.set_status,
                                 appindicator.IndicatorStatus.PASSIVE)
Exemplo n.º 20
0
def __unlock_menu():
    """
    Unlock the menu
    """
    Utility.execute_main_thread(tray_icon.unlock_menu)
Exemplo n.º 21
0
    def __set_next_break_info(self):
        formatted_time = Utility.format_time(self.dateTime)
        message = self.language['messages']['next_break_at'].format(
            formatted_time)

        Utility.execute_main_thread(self.item_info.set_label, message)
Exemplo n.º 22
0
    def hide_icon(self):
        """
		Hide the tray icon.
		"""
        Utility.execute_main_thread(self.indicator.set_status,
                                    appindicator.IndicatorStatus.PASSIVE)
Exemplo n.º 23
0
    def show_icon(self):
        """
		Show the tray icon.
		"""
        Utility.execute_main_thread(self.indicator.set_status,
                                    appindicator.IndicatorStatus.ACTIVE)
Exemplo n.º 24
0
 def stop_animation(self):
     self.animate = False
     if self.active:
         Utility.execute_main_thread(lambda: self.indicator.set_icon("safeeyes_enabled"))
     else:
         Utility.execute_main_thread(lambda: self.indicator.set_icon("safeeyes_disabled"))
Exemplo n.º 25
0
def show_notification():
	if config['strict_break']:
		Utility.execute_main_thread(tray_icon.lock_menu)
	plugins.pre_notification(context)
	notification.show(config['pre_break_warning_time'])
Exemplo n.º 26
0
    def quite(self):
        """
		Uninitialize the notification. Call this method when closing the application.
		"""
        logging.info('Uninitialize Safe Eyes notification')
        Utility.execute_main_thread(Notify.uninit)