def _write(self):
        for group in self._groups:
            group.write(self._config)

        if self.mode != WindowMode.Embedded:
            for entry in self._changed_entries:
                self._initial_values[entry] = InitialValue(entry.value, entry.enabled)

            self._changed_entries.clear()
            self._widgets.apply.props.sensitive = False

        try:
            with open(self._config_path, 'w') as file:
                self._config.write(file)
        except OSError as e:
            helpers.show_message(e, Gtk.MessageType.ERROR)
Ejemplo n.º 2
0
 def _write(self):
     for section, keys in list(self._bindings.items()):
         if not self._config.has_section(section):
             self._config.add_section(section)
         for key, binding in list(keys.items()):
             if binding.option.enabled:
                 self._config.set(section, key, binding.option.value)
             else:
                 self._config.remove_option(section, key)
             self._initial_values[binding.option] = InitialValue(
                 binding.option.value,
                 binding.option.enabled)
     self._changed_values = set()
     self._apply_button.props.sensitive = False
     try:
         with open(self._config_path, 'w') as file:
             self._config.write(file)
     except OSError as e:
         helpers.show_message(e, Gtk.MessageType.ERROR)
    def _write(self):
        changed = self._changed_entries | self._new_entries
        for group in self._groups:
            group.write(self._config, changed.__contains__)

        if self.mode != WindowMode.Embedded:
            for entry in changed:
                self._initial_values[entry] = InitialValue(entry.value, entry.enabled)

        self._changed_entries.clear()
        self._new_entries.clear()
        self._removed_entries.clear()

        try:
            self._config.write()
        except OSError as e:
            helpers.show_message(e, Gtk.MessageType.ERROR)

        self._update_apply_button()
Ejemplo n.º 4
0
    def _write(self):
        changed = self._changed_entries | self._new_entries
        for group in self._groups:
            group.write(self._config, changed.__contains__)

        if self.mode != WindowMode.Embedded:
            for entry in changed:
                self._initial_values[entry] = InitialValue(
                    entry.value, entry.enabled)

        self._changed_entries.clear()
        self._new_entries.clear()
        self._removed_entries.clear()

        try:
            self._config.write()
        except OSError as e:
            helpers.show_message(e, Gtk.MessageType.ERROR)

        self._update_apply_button()
    def _read(self):
        self._config.clear()
        try:
            if not self._config.read(self._config_path) and \
               self.mode != WindowMode.Embedded:
                helpers.show_message(text=_('Failed to read configuration file: {path}')
                                     .format(path=self._config_path),
                                     message_type=Gtk.MessageType.ERROR)
        except (configparser.DuplicateSectionError,
                configparser.MissingSectionHeaderError):
            pass

        self._changed_entries = None

        for group in self._groups:
            group.read(self._config)

        self._initial_values = {entry: InitialValue(entry.value, entry.enabled)
                                for entry in self._initial_values.keys()}
        self._changed_entries = set()
        self._widgets.apply.props.sensitive = False
Ejemplo n.º 6
0
    def _init_window(self):
        self._bindings = {section: {key: self._new_binding(*args)
                                    for key, args in list(keys.items())}
                          for section, keys in list(OPTIONS_BINDINGS.items())}
        self._initial_values = {}
        self._changed_values = None

        self._config_path = helpers.get_config_path()
        self._allow_edit = self._has_access_to_write(self._config_path)
        self._no_access_infobar.props.visible = not self._allow_edit
        self._apply_button.props.visible = self._allow_edit
        if not self._allow_edit:
            helpers.show_message(
                text=_('No permissions to save configuration'),
                secondary_text=_(
                    'It seems that you don\'t have permissions to write to '
                    'file:\n{path}\n\nTry to run this program using "sudo" '
                    'or "pkexec"').format(path=self._config_path),
                message_type=Gtk.MessageType.WARNING)

        self._configure_special_entries()
        self._config = configparser.RawConfigParser()
        self._read()
Ejemplo n.º 7
0
    def _read(self):
        #self._config.clear()
        try:
            if not self._config.read(self._config_path):
                helpers.show_message(text=_('Failed to read configuration '
                                            'file: {path}')
                                     .format(path=self._config_path),
                                     message_type=Gtk.MessageType.ERROR)
        except (configparser.DuplicateSectionError,
                configparser.MissingSectionHeaderError):
            pass

        if not self._config.has_option(GREETER_SECTION, 'indicators'):
            try:
                value = self._config.get(GREETER_SECTION, 'show-indicators')
            except (configparser.NoOptionError, configparser.NoSectionError):
                pass
            else:
                if value:
                    self._config.set(GREETER_SECTION, 'indicators', value)
                self._config.remove_option(GREETER_SECTION, 'show-indicators')

        for section, keys in list(self._bindings.items()):
            for key, binding in list(keys.items()):
                with binding.option.handler_block(binding.changed_handler):
                    try:
                        binding.option.value = self._config.get(section, key)
                        binding.option.enabled = True
                    except (configparser.NoOptionError,
                            configparser.NoSectionError):
                        binding.option.value = binding.default
                        binding.option.enabled = False
                self._initial_values[binding.option] = InitialValue(
                    binding.option.value,
                    binding.option.enabled)
        self._changed_values = set()
        self._apply_button.props.sensitive = False
Ejemplo n.º 8
0
    def init_window(self):
        self._widgets = self.Widgets(builder=self.builder)

        if self.mode == WindowMode.Embedded:
            self.on_entry_removed = self.on_entry_removed_embedded
            self.on_entry_changed = self.on_entry_changed_embedded
            self._write = self._write_embedded

            self._widgets.buttons.hide()
            self._widgets.content.reorder_child(self._widgets.infobar, 0)
            self._widgets.content.connect('destroy', self.on_destroy, True)
            # Socket/Plug focus issues workaround
            self._widgets.multihead_label.connect('button-press-event',
                                                  self.on_multihead_click)
        elif self.mode == WindowMode.GtkHeader:
            for button in (self._widgets.apply, self._widgets.reload):
                self._widgets.buttons.remove(button)
                button.set_label('')
                button.set_always_show_image(True)
            self._widgets.buttons.hide()

            header = Gtk.HeaderBar()
            header.set_show_close_button(True)
            header.props.title = self.get_title()
            header.pack_start(self._widgets.reload)
            header.pack_start(self._widgets.apply)
            header.show_all()

            self.set_titlebar(header)

        self._config = Config.Config()

        self._entry_menu = None
        self._initial_values = {}
        self._entries = None

        self._changed_entries = None
        self._new_entries = None
        self._removed_entries = None

        self._groups = (SimpleGroup('greeter',
                                    WidgetsWrapper(self.builder, 'greeter'),
                                    self.GreeterGroupSetup),
                        MonitorsGroup(self.builder))

        for group in self._groups:
            group.entry_added.connect(self.on_entry_added)
            group.entry_removed.connect(self.on_entry_removed)

        self._allow_edit = self._config.is_writable()
        self._update_apply_button()

        if not self._allow_edit:
            self._set_message(
                _('You don\'t have permissions to change greeter configuration'
                  ), Gtk.MessageType.WARNING)
            if self.mode != WindowMode.Embedded:
                helpers.show_message(
                    text=_('No permissions to save configuration'),
                    secondary_text=_(
                        'It seems that you don\'t have permissions to write to '
                        'file:\n{path}\n\nTry to run this program using "sudo" '
                        'or "pkexec"').format(path=helpers.get_config_path()),
                    message_type=Gtk.MessageType.WARNING)

        self._read()
    def init_window(self):
        self._widgets = self.Widgets(builder=self.builder)
        self._multihead_dialog = None
        self._entry_menu = None
        self._initial_values = {}
        self._changed_entries = None
        self._entries = None
        self._groups = (
            SimpleGroup('greeter', self.builder, {
                # Appearance
                'theme-name': (OptionEntry.StringEntry, ''),
                'icon-theme-name': (OptionEntry.StringEntry, ''),
                'font-name': (OptionEntry.FontEntry, 'Sans 10'),
                'xft-antialias': (OptionEntry.BooleanEntry, 'false'),
                'xft-dpi': (OptionEntry.StringEntry, None),
                'xft-rgba': (OptionEntry.ChoiceEntry, None),
                'xft-hintstyle': (OptionEntry.ChoiceEntry, None),
                'background': (OptionEntry.BackgroundEntry, '#000000'),
                'user-background': (OptionEntry.BooleanEntry, 'true'),
                'hide-user-image': (OptionEntry.InvertedBooleanEntry, 'false'),
                'default-user-image': (IconEntry.IconEntry, '#avatar-default'),
                # Panel
                'clock-format': (OptionEntry.ClockFormatEntry, '%a, %H:%M'),
                'indicators': (IndicatorsEntry.IndicatorsEntry,
                               '~host;~spacer;~clock;~spacer;~language;~session;~a11y;~power'),
                # Position
                'position': (PositionEntry.PositionEntry, '50%,center'),
                # Misc
                'screensaver-timeout': (OptionEntry.AdjustmentEntry, '60'),
                'keyboard': (OptionEntry.StringPathEntry, ''),
                'reader': (OptionEntry.StringPathEntry, ''),
                'a11y-states': (OptionEntry.AccessibilityStatesEntry, ''),
                'allow-debugging': (OptionEntry.BooleanEntry, 'false'), }),
            MonitorsGroup(self.builder))

        for group in self._groups:
            group.entry_added.connect(self.on_entry_added)
            group.entry_removed.connect(self.on_entry_removed)

        self._config_path = helpers.get_config_path()
        self._allow_edit = self._has_access_to_write(self._config_path)
        self._widgets.apply.props.visible = self._allow_edit

        if not self._allow_edit:
            self._set_message(_('You don\'t have permissions to change greeter configuration'),
                              Gtk.MessageType.WARNING)
            if self.mode != WindowMode.Embedded:
                helpers.show_message(
                    text=_('No permissions to save configuration'),
                    secondary_text=_(
                        'It seems that you don\'t have permissions to write to '
                        'file:\n{path}\n\nTry to run this program using "sudo" '
                        'or "pkexec"').format(path=self._config_path),
                    message_type=Gtk.MessageType.WARNING)

        if self.mode == WindowMode.Embedded:
            self.on_entry_changed = self.on_entry_changed_embedded
            self._widgets.buttons.hide()
            self._widgets.content.reorder_child(self._widgets.infobar, 0)
            # Socket/Plug focus issues workaround
            self._widgets.multihead_label.connect('button-press-event', self.on_multihead_click)
        elif self.mode == WindowMode.GtkHeader:
            for button in (self._widgets.apply, self._widgets.reload):
                self._widgets.buttons.remove(button)
                button.set_label('')
                button.set_always_show_image(True)
            self._widgets.buttons.hide()

            header = Gtk.HeaderBar()
            header.set_show_close_button(True)
            header.props.title = self.get_title()
            header.pack_start(self._widgets.reload)
            header.pack_start(self._widgets.apply)
            header.show_all()

            self.set_titlebar(header)

        self._config = configparser.RawConfigParser(strict=False)
        self._read()
    def init_window(self):
        self._widgets = self.Widgets(builder=self.builder)

        if self.mode == WindowMode.Embedded:
            self.on_entry_removed = self.on_entry_removed_embedded
            self.on_entry_changed = self.on_entry_changed_embedded
            self._write = self._write_embedded

            self._widgets.buttons.hide()
            self._widgets.content.reorder_child(self._widgets.infobar, 0)
            self._widgets.content.connect('destroy', self.on_destroy, True)
            # Socket/Plug focus issues workaround
            self._widgets.multihead_label.connect('button-press-event', self.on_multihead_click)
        elif self.mode == WindowMode.GtkHeader:
            for button in (self._widgets.apply, self._widgets.reload):
                self._widgets.buttons.remove(button)
                button.set_label('')
                button.set_always_show_image(True)
            self._widgets.buttons.hide()

            header = Gtk.HeaderBar()
            header.set_show_close_button(True)
            header.props.title = self.get_title()
            header.pack_start(self._widgets.reload)
            header.pack_start(self._widgets.apply)
            header.show_all()

            self.set_titlebar(header)

        self._config = Config.Config()

        self._entry_menu = None
        self._initial_values = {}
        self._entries = None

        self._changed_entries = None
        self._new_entries = None
        self._removed_entries = None

        self._groups = (
            SimpleGroup('greeter', WidgetsWrapper(self.builder, 'greeter'), self.GreeterGroupSetup),
            MonitorsGroup(self.builder))

        for group in self._groups:
            group.entry_added.connect(self.on_entry_added)
            group.entry_removed.connect(self.on_entry_removed)

        self._allow_edit = self._config.is_writable()
        self._update_apply_button()

        if not self._allow_edit:
            self._set_message(_('You don\'t have permissions to change greeter configuration'),
                              Gtk.MessageType.WARNING)
            if self.mode != WindowMode.Embedded:
                helpers.show_message(
                    text=_('No permissions to save configuration'),
                    secondary_text=_(
                        'It seems that you don\'t have permissions to write to '
                        'file:\n{path}\n\nTry to run this program using "sudo" '
                        'or "pkexec"').format(path=helpers.get_config_path()),
                    message_type=Gtk.MessageType.WARNING)

        self._read()