Ejemplo n.º 1
0
    def _setup_color_schemes(self):
        chooser = GtkSource.StyleSchemeChooserWidget()
        sw = self.builder.get_object('sw_color_schemes')
        sw.add(chooser)

        sm = GtkSource.StyleSchemeManager()
        chooser.set_style_scheme(sm.get_scheme(self.config.ui_style_scheme))
        chooser.connect(
            'notify::style-scheme',
            lambda *a: self._sp('ui-style-scheme',
                                chooser.get_style_scheme().get_id()))
        self._chooser_color_scheme = chooser
Ejemplo n.º 2
0
    def __init__(self, transient_for, settings):
        super().__init__(transient_for=transient_for, modal=False)

        self.settings = settings
        self.set_default_size(340, 340)

        hints = Gdk.Geometry()
        hints.min_width = 340
        hints.min_height = 340
        self.set_geometry_hints(None, hints, Gdk.WindowHints.MIN_SIZE)

        self.set_border_width(5)
        self.set_deletable(False)
        self.set_title(_('Preferences'))

        self.toast = Granite.WidgetsToast(title=_("Toast"))

        indent_width = Gtk.SpinButton.new_with_range(1, 24, 1)
        indent_width.set_value(self.settings.get_int('indent-width'))
        indent_width.connect('value-changed', self.on_indent_width)

        self.sort_switch = Gtk.Switch(halign=Gtk.Align.START,
                                      valign=Gtk.Align.CENTER)
        self.sort_switch.set_state(self.settings.get_boolean('sort-desc'))
        self.sort_switch.connect("state-set", self.on_sort_desc)

        self.spellcheck_switch = Gtk.Switch(halign=Gtk.Align.START,
                                            valign=Gtk.Align.CENTER)
        self.spellcheck_switch.set_state(
            self.settings.get_boolean('spellcheck'))
        self.spellcheck_switch.connect("state-set", self.on_spellcheck)

        self.autosave_switch = Gtk.Switch(halign=Gtk.Align.START,
                                          valign=Gtk.Align.CENTER)
        self.autosave_switch.set_state(self.settings.get_boolean('autosave'))
        self.autosave_switch.connect("state-set", self.on_autosave)

        self.autoindent_switch = Gtk.Switch(halign=Gtk.Align.START,
                                            valign=Gtk.Align.CENTER)
        self.autoindent_switch.set_state(
            self.settings.get_boolean('autoindent'))
        self.autoindent_switch.connect("state-set", self.on_autoindent)

        self.spaces_tabs_switch = Gtk.Switch(halign=Gtk.Align.START,
                                             valign=Gtk.Align.CENTER)
        self.spaces_tabs_switch.set_state(
            self.settings.get_boolean('spaces-instead-of-tabs'))
        self.spaces_tabs_switch.connect("state-set", self.on_spaces_tabs)

        general_grid = Gtk.Grid(column_spacing=12, row_spacing=6)

        general_grid.attach(Granite.HeaderLabel(_("General")), 0, 0, 3, 1)
        general_grid.attach(
            Gtk.Label(_("Save files when changed:"), halign=Gtk.Align.END), 0,
            1, 1, 1)
        general_grid.attach(self.autosave_switch, 1, 1, 1, 1)
        general_grid.attach(
            Gtk.Label(_("Sort documents backwards:"), halign=Gtk.Align.END), 0,
            2, 1, 1)
        general_grid.attach(self.sort_switch, 1, 2, 1, 1)
        general_grid.attach(
            Gtk.Label(_("Spell checking:"), halign=Gtk.Align.END), 0, 3, 1, 1)
        general_grid.attach(self.spellcheck_switch, 1, 3, 1, 1)

        general_grid.attach(Granite.HeaderLabel(_("Tabs")), 0, 4, 3, 1)
        general_grid.attach(
            Gtk.Label(_("Automatic indentation:"), halign=Gtk.Align.END), 0, 5,
            1, 1)
        general_grid.attach(self.autoindent_switch, 1, 5, 1, 1)
        general_grid.attach(
            Gtk.Label(_("Insert spaces instead of tabs:"),
                      halign=Gtk.Align.END), 0, 6, 1, 1)
        general_grid.attach(self.spaces_tabs_switch, 1, 6, 1, 1)
        general_grid.attach(Gtk.Label(_("Tab width:"), halign=Gtk.Align.END),
                            0, 7, 1, 1)
        general_grid.attach(indent_width, 1, 7, 2, 1)

        # Interface grid
        interface_grid = Gtk.Grid(column_spacing=12, row_spacing=6)
        scrolled = Gtk.ScrolledWindow(hexpand=True, vexpand=True)

        self.dark_theme_switch = Gtk.Switch(halign=Gtk.Align.START,
                                            valign=Gtk.Align.CENTER)
        self.dark_theme_switch.set_state(
            self.settings.get_boolean('prefer-dark-theme'))
        self.dark_theme_switch.connect("state-set", self.on_dark_theme)

        style_chooser = GtkSource.StyleSchemeChooserWidget()
        style_chooser.connect('notify::style-scheme', self.on_scheme_changed)
        scrolled.add(style_chooser)

        scheme = GtkSource.StyleSchemeManager().get_scheme(
            self.settings.get_string('stylescheme'))
        if not scheme:
            scheme = GtkSource.StyleSchemeManager().get_scheme("classic")

        style_chooser.set_style_scheme(scheme)

        interface_grid.attach(Granite.HeaderLabel(_("Appearance")), 0, 0, 3, 1)
        interface_grid.attach(
            Gtk.Label(_("Prefer dark theme:"), halign=Gtk.Align.END), 0, 1, 2,
            1)
        interface_grid.attach(self.dark_theme_switch, 2, 1, 1, 1)
        interface_grid.attach(Granite.HeaderLabel(_("Styles")), 0, 2, 3, 1)
        interface_grid.attach(scrolled, 0, 3, 3, 1)

        # Export grid
        export_grid = Gtk.Grid(column_spacing=12, row_spacing=6)

        self.render_medium(export_grid)
        self.render_writeas(export_grid)

        # Main Stack
        main_stack = Gtk.Stack(margin=6, margin_bottom=18, margin_top=8)
        main_stack.add_titled(general_grid, "behavior", _("Behavior"))
        main_stack.add_titled(interface_grid, "interface", _("Interface"))
        main_stack.add_titled(export_grid, "export", _("Export"))

        main_stackswitcher = Gtk.StackSwitcher()
        main_stackswitcher.set_stack(main_stack)
        main_stackswitcher.set_halign(Gtk.Align.CENTER)

        main_grid = Gtk.Grid()
        main_grid.attach(main_stackswitcher, 0, 0, 1, 1)
        main_grid.attach(main_stack, 0, 1, 1, 1)

        self.overlay = Gtk.Overlay()
        self.overlay.add(main_grid)
        self.overlay.add_overlay(self.toast)
        self.get_content_area().add(self.overlay)

        close_button = Gtk.Button(label=_("Close"))
        close_button.connect('clicked', self.on_close_activated)
        self.add_action_widget(close_button, 0)
Ejemplo n.º 3
0
    def __init__(self, transient_for, settings):
        super().__init__(transient_for=transient_for, modal=False)

        self.settings = settings
        self.set_default_size(340, 300)

        self.set_border_width(5)
        self.set_deletable(False)
        self.set_title('Preferences')

        indent_width = Gtk.SpinButton.new_with_range(1, 24, 1)
        indent_width.set_value(self.settings.get_int('indent-width'))
        indent_width.connect('value-changed', self.on_indent_width)

        self.spellcheck_switch = Gtk.Switch(halign=Gtk.Align.START,
                                            valign=Gtk.Align.CENTER)
        self.spellcheck_switch.set_state(
            self.settings.get_boolean('spellcheck'))
        self.spellcheck_switch.connect("state-set", self.on_spellcheck)

        self.autosave_switch = Gtk.Switch(halign=Gtk.Align.START,
                                          valign=Gtk.Align.CENTER)
        self.autosave_switch.set_state(self.settings.get_boolean('autosave'))
        self.autosave_switch.connect("state-set", self.on_autosave)

        self.autoindent_switch = Gtk.Switch(halign=Gtk.Align.START,
                                            valign=Gtk.Align.CENTER)
        self.autoindent_switch.set_state(
            self.settings.get_boolean('autoindent'))
        self.autoindent_switch.connect("state-set", self.on_autoindent)

        self.spaces_tabs_switch = Gtk.Switch(halign=Gtk.Align.START,
                                             valign=Gtk.Align.CENTER)
        self.spaces_tabs_switch.set_state(
            self.settings.get_boolean('spaces-instead-of-tabs'))
        self.spaces_tabs_switch.connect("state-set", self.on_spaces_tabs)

        general_grid = Gtk.Grid(column_spacing=12, row_spacing=6)

        general_grid.attach(Granite.HeaderLabel("General"), 0, 0, 3, 1)
        general_grid.attach(
            Gtk.Label("Save files when changed:", halign=Gtk.Align.END), 0, 1,
            1, 1)
        general_grid.attach(self.autosave_switch, 1, 1, 1, 1)
        general_grid.attach(Gtk.Label("Spell checking:", halign=Gtk.Align.END),
                            0, 2, 1, 1)
        general_grid.attach(self.spellcheck_switch, 1, 2, 1, 1)

        general_grid.attach(Granite.HeaderLabel("Tabs"), 0, 3, 3, 1)
        general_grid.attach(
            Gtk.Label("Automatic indentation:", halign=Gtk.Align.END), 0, 4, 1,
            1)
        general_grid.attach(self.autoindent_switch, 1, 4, 1, 1)
        general_grid.attach(
            Gtk.Label("Insert spaces instead of tabs:", halign=Gtk.Align.END),
            0, 5, 1, 1)
        general_grid.attach(self.spaces_tabs_switch, 1, 5, 1, 1)
        general_grid.attach(Gtk.Label("Tab width:", halign=Gtk.Align.END), 0,
                            6, 1, 1)
        general_grid.attach(indent_width, 1, 6, 2, 1)

        interface_grid = Gtk.Grid(column_spacing=12, row_spacing=6)
        scrolled = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
        style_chooser = GtkSource.StyleSchemeChooserWidget()
        style_chooser.connect('notify::style-scheme', self.on_scheme_changed)
        scrolled.add(style_chooser)

        scheme = GtkSource.StyleSchemeManager().get_scheme(
            self.settings.get_string('stylescheme'))
        if not scheme:
            scheme = GtkSource.StyleSchemeManager().get_scheme("classic")

        style_chooser.set_style_scheme(scheme)

        interface_grid.attach(Granite.HeaderLabel("Styles"), 0, 0, 2, 1)
        interface_grid.attach(scrolled, 0, 2, 2, 1)

        main_stack = Gtk.Stack(margin=6, margin_bottom=18, margin_top=8)
        main_stack.add_titled(general_grid, "behavior", "Behavior")
        main_stack.add_titled(interface_grid, "interface", "Interface")

        main_stackswitcher = Gtk.StackSwitcher()
        main_stackswitcher.set_stack(main_stack)
        main_stackswitcher.set_halign(Gtk.Align.CENTER)

        main_grid = Gtk.Grid()
        main_grid.attach(main_stackswitcher, 0, 0, 1, 1)
        main_grid.attach(main_stack, 0, 1, 1, 1)

        self.get_content_area().add(main_grid)

        close_button = Gtk.Button(label="Close")
        close_button.connect('clicked', self.on_close_activated)
        self.add_action_widget(close_button, 0)