示例#1
0
    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)
示例#2
0
 def take_break(self):
     """
     Calling this method stops the scheduler and show the next break screen
     """
     if self.break_queue.is_empty():
         return
     if not self.context['state'] == State.WAITING:
         return
     utility.start_thread(self.__take_break)
示例#3
0
def on_start():
    """
    Start a thread to continuously call xprintidle.
    """
    global active
    if not __is_active():
        # 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)
示例#4
0
 def __fire_pre_break(self):
     """
     Show the notification and start the break after the notification.
     """
     self.context['state'] = State.PRE_BREAK
     if not self.on_pre_break.fire(self.break_queue.get_break()):
         # Plugins wanted to ignore this break
         self.__start_next_break()
         return
     utility.start_thread(self.__wait_until_prepare)
示例#5
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)
示例#6
0
 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)
示例#7
0
文件: plugin.py 项目: Firiks/SafeEyes
def __swayidle_idle_time():
    global swayidle_running
    with swayidle_lock:
        if not swayidle_running:
            utility.start_thread(__start_swayidle_monitor)
            swayidle_running = True
        # Idle more recently than active, meaning idle time isn't stale.
        if swayidle_idle > swayidle_active:
            idle_time = int(
                datetime.datetime.now().timestamp()) - swayidle_idle
            return idle_time
    return 0
示例#8
0
 def __fire_start_break(self):
     # Show the break screen
     if not self.on_start_break.fire(self.break_queue.get_break()):
         # Plugins want to ignore this break
         self.__start_next_break()
         return
     if self.context['postponed']:
         # Plugins want to postpone this break
         self.context['postponed'] = False
         # Update the next break time
         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)
     else:
         self.start_break.fire(self.break_queue.get_break())
         utility.start_thread(self.__start_break)
示例#9
0
    def on_disable_clicked(self, *args):
        """
        Handle the menu actions of all the sub menus of 'Disable Safe Eyes'.
        This action disables the application if it is currently active.
        """
        # active = self.item_enable.get_active()
        if self.active and len(args) > 1:
            self.disable_ui()

            time_to_wait = args[1]
            if time_to_wait <= 0:
                info = _('Disabled until restart')
                self.on_disable(info)
                self.wakeup_time = None
                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)
                self.on_disable(info)
                self.item_info.set_label(info)
                utility.start_thread(self.__schedule_resume, time_minutes=time_to_wait)
示例#10
0
    def __show_break_screen(self, message, image_path, widget, tray_actions):
        """
        Show an empty break screen on all screens.
        """
        # Lock the keyboard
        utility.start_thread(self.__lock_keyboard)

        screen = Gtk.Window().get_screen()
        no_of_monitors = screen.get_n_monitors()
        logging.info("Show break screens in %d display(s)", no_of_monitors)

        for monitor in range(no_of_monitors):
            monitor_gemoetry = screen.get_monitor_geometry(monitor)
            x = monitor_gemoetry.x
            y = monitor_gemoetry.y

            builder = Gtk.Builder()
            builder.add_from_file(BREAK_SCREEN_GLADE)
            builder.connect_signals(self)

            window = builder.get_object("window_main")
            lbl_message = builder.get_object("lbl_message")
            lbl_count = builder.get_object("lbl_count")
            lbl_widget = builder.get_object("lbl_widget")
            img_break = builder.get_object("img_break")
            box_buttons = builder.get_object("box_buttons")
            toolbar = builder.get_object("toolbar")

            for tray_action in tray_actions:
                toolbar_button = None
                if tray_action.system_icon:
                    toolbar_button = Gtk.ToolButton.new_from_stock(
                        tray_action.get_icon())
                else:
                    toolbar_button = Gtk.ToolButton.new(
                        tray_action.get_icon(), tray_action.name)
                tray_action.add_toolbar_button(toolbar_button)
                toolbar_button.connect(
                    "clicked",
                    lambda button, action: self.__tray_action(button, action),
                    tray_action)
                toolbar_button.set_tooltip_text(_(tray_action.name))
                toolbar.add(toolbar_button)
                toolbar_button.show()

            # Add the buttons
            if self.enable_postpone:
                # Add postpone button
                btn_postpone = Gtk.Button(_('Postpone'))
                btn_postpone.get_style_context().add_class('btn_postpone')
                btn_postpone.connect('clicked', self.on_postpone_clicked)
                btn_postpone.set_visible(True)
                box_buttons.pack_start(btn_postpone, True, True, 0)

            if not self.strict_break:
                # Add the skip button
                btn_skip = Gtk.Button(_('Skip'))
                btn_skip.get_style_context().add_class('btn_skip')
                btn_skip.connect('clicked', self.on_skip_clicked)
                btn_skip.set_visible(True)
                box_buttons.pack_start(btn_skip, True, True, 0)

            # Set values
            if image_path:
                img_break.set_from_file(image_path)
            lbl_message.set_label(message)
            lbl_widget.set_markup(widget)

            self.windows.append(window)
            self.count_labels.append(lbl_count)

            # Set visual to apply css theme. It should be called before show method.
            window.set_visual(window.get_screen().get_rgba_visual())
            if self.context['desktop'] == 'kde':
                # Fix flickering screen in KDE by setting opacity to 1
                window.set_opacity(0.9)

            # In Unity, move the window before present
            window.move(x, y)
            window.resize(monitor_gemoetry.width, monitor_gemoetry.height)
            window.stick()
            window.set_keep_above(True)
            window.present()
            # In other desktop environments, move the window after present
            window.move(x, y)
            window.resize(monitor_gemoetry.width, monitor_gemoetry.height)
            logging.info("Moved break screen to Display[%d, %d]", x, y)
            window.fullscreen()