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)
def __init__(self, settings: Gio.Settings, **kwargs): super().__init__(**kwargs) self.set_default_icon(Pixbuf.new_from_resource_at_scale( '/com/github/tenderowl/norka/icons/com.github.tenderowl.norka.svg', 128, 128, True )) self.settings = settings self._configure_timeout_id = None self.preview = None self.apply_styling() self.current_size = (786, 520) self.resize(*self.settings.get_value('window-size')) self.connect('configure-event', self.on_configure_event) self.connect('destroy', self.on_window_delete_event) # Export clients self.medium_client = Medium() self.writeas_client = Writeas() self.uri_to_open = None # Make a header self.header = Header(self.settings) self.set_titlebar(self.header) self.header.show() # Init screens self.welcome_grid = Welcome() self.welcome_grid.connect('activated', self.on_welcome_activated) self.welcome_grid.connect('document-import', self.on_document_import) self.document_grid = DocumentGrid() self.document_grid.connect('document-create', self.on_document_create_activated) self.document_grid.connect('document-import', self.on_document_import) self.document_grid.view.connect('item-activated', self.on_document_item_activated) self.editor = Editor() self.screens = Gtk.Stack() self.screens.set_transition_duration(400) self.screens.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT) self.screens.add_named(self.welcome_grid, 'welcome-grid') self.screens.add_named(self.document_grid, 'document-grid') self.screens.add_named(self.editor, 'editor-grid') self.screens.show_all() self.toast = Granite.WidgetsToast() self.overlay = Gtk.Overlay() self.overlay.add_overlay(self.screens) self.overlay.add_overlay(self.toast) self.overlay.show_all() self.add(self.overlay) # Init actions self.init_actions() # If here's at least one document in storage # then show documents grid self.check_documents_count() # Pull the Settings self.toggle_spellcheck(self.settings.get_boolean('spellcheck')) self.autosave = self.settings.get_boolean('autosave') self.set_autoindent(self.settings.get_boolean('autoindent')) self.set_tabs_spaces(self.settings.get_boolean('spaces-instead-of-tabs')) self.set_indent_width(self.settings.get_int('indent-width')) self.set_style_scheme(self.settings.get_string('stylescheme')) self.editor.update_font(self.settings.get_string('font'))
def __init__(self, settings: Gio.Settings, storage: Storage, **kwargs): super().__init__(**kwargs) self.set_default_icon( Pixbuf.new_from_resource_at_scale( f'{RESOURCE_PREFIX}/icons/com.github.tenderowl.norka.svg', 128, 128, True)) self.settings = settings self.storage = storage self._configure_timeout_id = None self.preview = None self.extended_stats_dialog = None self.apply_styling() self.current_size = (786, 520) self.resize(*self.settings.get_value('window-size')) hints = Gdk.Geometry() hints.min_width = 554 hints.min_height = 435 self.set_geometry_hints(None, hints, Gdk.WindowHints.MIN_SIZE) self.connect('configure-event', self.on_configure_event) self.connect('destroy', self.on_window_delete_event) # Export clients self.medium_client = Medium() self.writeas_client = Writeas() self.uri_to_open = None # Make a header self.header = Header(self.settings) # self.set_titlebar(self.header) self.header.show() # Init screens self.welcome_grid = Welcome() # self.welcome_grid.connect('activated', self.on_welcome_activated) self.welcome_grid.connect('document-import', self.on_document_import) self.document_grid = DocumentGrid(self.settings, storage=self.storage) self.document_grid.connect('path-changed', self.on_path_changed) self.document_grid.connect('document-create', self.on_document_create_activated) self.document_grid.connect('document-import', self.on_document_import) self.document_grid.connect('rename-folder', self.on_folder_rename_activated) self.document_grid.view.connect('item-activated', self.on_document_item_activated) self.editor = Editor(self.storage, self.settings) self.editor.connect('update-document-stats', self.update_document_stats) self.screens = Gtk.Stack() self.screens.set_transition_duration(400) self.screens.set_transition_type( Gtk.StackTransitionType.SLIDE_LEFT_RIGHT) self.screens.add_named(self.welcome_grid, 'welcome-grid') self.screens.add_named(self.document_grid, 'document-grid') self.screens.add_named(self.editor, 'editor-grid') self.screens.show_all() self.toast = Granite.WidgetsToast() self.overlay = Gtk.Overlay() self.overlay.add_overlay(self.screens) self.overlay.add_overlay(self.toast) self.overlay.show_all() self.content_box.pack_start(self.header, False, False, 0) self.content_box.pack_end(self.overlay, True, True, 0) # Init actions self.init_actions() # If here's at least one document in storage # then show documents grid self.check_grid_items() # Pull the Settings self.toggle_spellcheck(self.settings.get_boolean('spellcheck')) self.autosave = self.settings.get_boolean('autosave') self.set_autoindent(self.settings.get_boolean('autoindent')) self.set_tabs_spaces( self.settings.get_boolean('spaces-instead-of-tabs')) self.set_indent_width(self.settings.get_int('indent-width')) self.set_style_scheme(self.settings.get_string('stylescheme')) self.editor.update_font(self.settings.get_string('font'))