Exemplo n.º 1
0
	def initialize(self, config, language):
		logging.info("Initialize the core")
		self.short_break_exercises = [] #language['exercises']['short_break_exercises']
		self.long_break_exercises = [] #language['exercises']['long_break_exercises']

		self.no_of_short_breaks_per_long_break = config['no_of_short_breaks_per_long_break']
		self.pre_break_warning_time = config['pre_break_warning_time']
		self.long_break_duration = config['long_break_duration']
		self.short_break_duration = config['short_break_duration']
		self.break_interval = config['break_interval']
		self.idle_time = config['idle_time']
		self.postpone_duration = config['postpone_duration']
		self.skip_break_window_classes = [x.lower() for x in config['active_window_class']['skip_break']]
		self.take_break_window_classes = [x.lower() for x in config['active_window_class']['take_break']]
		self.custom_exercises = config['custom_exercises']
		# Enable idle time pause only if xprintidle is available
		self.context['idle_pause_enabled'] = Utility.command_exist('xprintidle')

		exercises = language['exercises']
		for short_break_config in config['short_breaks']:
			exercise_name = short_break_config['name']
			name = None

			if exercise_name in self.custom_exercises:
				name = self.custom_exercises[exercise_name]
			else:
				name = exercises[exercise_name]

			break_time = short_break_config.get('time', self.short_break_duration)
			audible_alert = short_break_config.get('audible_alert', config['audible_alert'])
			image = short_break_config.get('image')

			# Validate time value
			if not isinstance(break_time, int) or break_time <= 0:
				logging.error('Invalid time in short break: ' + str(short_break_config))
				continue

			self.short_break_exercises.append([name, break_time, audible_alert, image])

		for long_break_config in config['long_breaks']:
			exercise_name = long_break_config['name']
			name = None

			if exercise_name in self.custom_exercises:
				name = self.custom_exercises[exercise_name]
			else:
				name = exercises[exercise_name]

			break_time = long_break_config.get('time', self.long_break_duration)
			audible_alert = long_break_config.get('audible_alert', config['audible_alert'])
			image = long_break_config.get('image')

			# Validate time value
			if not isinstance(break_time, int) or break_time <= 0:
				logging.error('Invalid time in long break: ' + str(long_break_config))
				continue

			self.long_break_exercises.append([name, break_time, audible_alert, image])
Exemplo n.º 2
0
def validate(plugin_config):
    command = None
    if Utility.DESKTOP_ENVIRONMENT == "gnome" and Utility.IS_WAYLAND:
        command = "dbus-send"
    else:
        command = "xprintidle"
    if not Utility.command_exist(command):
        return _("Please install the command-line tool '%s'") % command
    else:
        return None
Exemplo n.º 3
0
def __lock_screen_command():
    """
    Function tries to detect the screensaver command based on the current envinroment
    Possible results:
        Gnome, Unity, Budgie:		['gnome-screensaver-command', '--lock']
        Cinnamon:					['cinnamon-screensaver-command', '--lock']
        Pantheon, LXDE:				['light-locker-command', '--lock']
        Mate:						['mate-screensaver-command', '--lock']
        KDE:						['qdbus', 'org.freedesktop.ScreenSaver', '/ScreenSaver', 'Lock']
        XFCE:						['xflock4']
        Otherwise:					None
    """
    desktop_session = os.environ.get('DESKTOP_SESSION')
    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'):
            return ['xflock4']
        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'):
            return ['light-locker-command', '--lock']
        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'):
                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'):
                # Gnome 2
                return ['gnome-screensaver-command', '--lock']
    return None
Exemplo n.º 4
0
    def __init__(self, config, language, languages, able_to_lock_screen,
                 on_save_settings, glade_file):
        self.config = config
        self.on_save_settings = on_save_settings
        self.languages = []

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

        # Get the UI components
        self.window = builder.get_object('window_settings')
        self.spin_short_break_duration = builder.get_object(
            'spin_short_break_duration')
        self.spin_long_break_duration = builder.get_object(
            'spin_long_break_duration')
        self.spin_interval_between_two_breaks = builder.get_object(
            'spin_interval_between_two_breaks')
        self.spin_short_between_long = builder.get_object(
            'spin_short_between_long')
        self.spin_time_to_prepare = builder.get_object('spin_time_to_prepare')
        self.spin_idle_time_to_pause = builder.get_object(
            'spin_idle_time_to_pause')
        self.spin_postpone_duration = builder.get_object(
            'spin_postpone_duration')
        self.switch_show_time_in_tray = builder.get_object(
            'switch_show_time_in_tray')
        self.switch_strict_break = builder.get_object('switch_strict_break')
        self.switch_postpone = builder.get_object('switch_postpone')
        self.switch_audible_alert = builder.get_object('switch_audible_alert')
        self.cmb_language = builder.get_object('cmb_language')
        self.switch_screen_lock = builder.get_object('switch_screen_lock')
        self.spin_time_to_screen_lock = builder.get_object(
            'spin_time_to_screen_lock')

        # Translate the UI labels
        builder.get_object('lbl_short_break').set_label(
            language['ui_controls']['short_break_duration'])
        builder.get_object('lbl_long_break').set_label(
            language['ui_controls']['long_break_duration'])
        builder.get_object('lbl_interval_bettween_breaks').set_label(
            language['ui_controls']['interval_between_two_breaks'])
        builder.get_object('lbl_short_per_long').set_label(
            language['ui_controls']
            ['no_of_short_breaks_between_two_long_breaks'])
        builder.get_object('lbl_time_to_prepare').set_label(
            language['ui_controls']['time_to_prepare_for_break'])
        builder.get_object('lbl_idle_time_to_pause').set_label(
            language['ui_controls']['idle_time'])
        builder.get_object('lbl_postpone_duration').set_label(
            language['ui_controls']['postpone_duration'])
        builder.get_object('lbl_allow_postpone').set_label(
            language['ui_controls']['allow_postpone'])
        builder.get_object('lbl_show_time_in_tray').set_label(
            language['ui_controls']['show_time_in_tray'])
        builder.get_object('lbl_strict_break').set_label(
            language['ui_controls']['strict_break'])
        builder.get_object('lbl_audible_alert').set_label(
            language['ui_controls']['audible_alert'])
        builder.get_object('lbl_language').set_label(
            language['ui_controls']['language'])
        builder.get_object('lbl_enable_screen_lock').set_label(
            language['ui_controls']['enable_screen_lock'])
        builder.get_object('lbl_lock_screen_after').set_label(
            language['ui_controls']['time_to_screen_lock'])
        builder.get_object('btn_cancel').set_label(
            language['ui_controls']['cancel'])
        builder.get_object('btn_save').set_label(
            language['ui_controls']['save'])

        # Set the current values of input fields
        self.spin_short_break_duration.set_value(
            config['short_break_duration'])
        self.spin_long_break_duration.set_value(config['long_break_duration'])
        self.spin_interval_between_two_breaks.set_value(
            config['break_interval'])
        self.spin_short_between_long.set_value(
            config['no_of_short_breaks_per_long_break'])
        self.spin_time_to_prepare.set_value(config['pre_break_warning_time'])
        self.spin_idle_time_to_pause.set_value(config['idle_time'])
        self.spin_postpone_duration.set_value(config['postpone_duration'])
        self.switch_show_time_in_tray.set_active(config['show_time_in_tray'])
        self.switch_strict_break.set_active(config['strict_break'])
        self.switch_audible_alert.set_active(config['audible_alert'])
        self.spin_time_to_screen_lock.set_value(config['time_to_screen_lock'])

        # Enable idle_time_to_pause only if xprintidle is available
        self.spin_idle_time_to_pause.set_sensitive(
            Utility.command_exist('xprintidle'))

        # Enable optional audible alert only if pyaudio is available
        self.switch_audible_alert.set_sensitive(Utility.pyaudio is not None)
        self.switch_audible_alert.set_active(Utility.pyaudio is not None
                                             and config['audible_alert'])

        self.switch_screen_lock.set_sensitive(able_to_lock_screen)
        self.switch_screen_lock.set_active(able_to_lock_screen
                                           and config['enable_screen_lock'])
        self.switch_postpone.set_active(config['allow_postpone']
                                        and not config['strict_break'])

        # Update relative states
        # GtkSwitch state-set signal is available only from 3.14
        if Gtk.get_minor_version() >= 14:
            self.switch_strict_break.connect(
                'state-set', self.on_switch_strict_break_activate)
            self.switch_screen_lock.connect(
                'state-set', self.on_switch_screen_lock_activate)
            self.switch_postpone.connect('state-set',
                                         self.on_switch_postpone_activate)
            self.on_switch_strict_break_activate(
                self.switch_strict_break,
                self.switch_strict_break.get_active())
            self.on_switch_screen_lock_activate(
                self.switch_screen_lock, self.switch_screen_lock.get_active())
            self.on_switch_postpone_activate(self.switch_postpone,
                                             self.switch_postpone.get_active())

        # Initialize the language combobox
        language_list_store = Gtk.ListStore(GObject.TYPE_STRING)
        language_index = 2
        lang_code = config['language']

        # Add 'System Language' as the first option
        language_list_store.append(
            [language['ui_controls']['system_language']])
        language_list_store.append(['-'])
        self.languages.append('system')
        self.languages.append('system')  # Dummy record for row separator
        if 'system' == lang_code:
            self.cmb_language.set_active(0)

        for key in sorted(languages.keys()):
            language_list_store.append([languages[key]])
            self.languages.append(key)
            if key == lang_code:
                self.cmb_language.set_active(language_index)
            language_index += 1

        self.cmb_language.set_model(language_list_store)
        self.cmb_language.set_row_separator_func(
            lambda m, i: m.get_value(i, 0) == '-')
        cell = Gtk.CellRendererText()
        self.cmb_language.pack_start(cell, True)
        self.cmb_language.add_attribute(cell, 'text', 0)