2014-07-06 20:35:24 +00:00
|
|
|
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
|
|
|
|
### BEGIN LICENSE
|
2019-07-05 18:47:49 +00:00
|
|
|
# Copyright (C) 2019, Wolf Vollprecht <w.vollprecht@gmail.com>
|
2014-07-06 20:35:24 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU General Public License version 3, as published
|
|
|
|
# by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranties of
|
|
|
|
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
|
|
|
|
# PURPOSE. See the GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
### END LICENSE
|
|
|
|
|
|
|
|
### DO NOT EDIT THIS FILE ###
|
|
|
|
|
|
|
|
"""this dialog adjusts values in gsettings
|
|
|
|
"""
|
2019-04-15 01:35:24 +00:00
|
|
|
import webbrowser
|
|
|
|
|
2019-01-27 19:20:56 +00:00
|
|
|
import gi
|
2019-04-15 01:35:24 +00:00
|
|
|
|
2019-01-27 19:20:56 +00:00
|
|
|
gi.require_version('Gtk', '3.0')
|
2019-04-15 01:35:24 +00:00
|
|
|
from gi.repository import Gtk, Pango, GLib # pylint: disable=E0611
|
2014-07-06 20:35:24 +00:00
|
|
|
import logging
|
2019-04-01 16:00:17 +00:00
|
|
|
logger = logging.getLogger('uberwriter')
|
2014-07-06 20:35:24 +00:00
|
|
|
|
2019-04-15 01:35:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PreferencesDialog:
|
2014-07-06 20:35:24 +00:00
|
|
|
|
|
|
|
__gtype_name__ = "PreferencesDialog"
|
|
|
|
|
2019-04-15 01:35:24 +00:00
|
|
|
formats = [
|
|
|
|
{
|
|
|
|
"name": "Pandoc's Markdown",
|
|
|
|
"format": "markdown",
|
|
|
|
"help": "https://pandoc.org/MANUAL.html#pandocs-markdown"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "CommonMark",
|
|
|
|
"format": "commonmark",
|
|
|
|
"help": "https://commonmark.org"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "GitHub Flavored Markdown",
|
|
|
|
"format": "gfm",
|
|
|
|
"help": "https://help.github.com/en/categories/writing-on-github"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "MultiMarkdown",
|
|
|
|
"format": "markdown_mmd",
|
|
|
|
"help": "https://fletcherpenney.net/multimarkdown"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Plain Markdown",
|
|
|
|
"format": "markdown_strict",
|
|
|
|
"help": "https://daringfireball.net/projects/markdown"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
def __init__(self, settings):
|
|
|
|
self.settings = settings
|
2019-11-04 22:05:03 +00:00
|
|
|
self.builder = Gtk.Builder()
|
|
|
|
self.builder.add_from_resource(
|
|
|
|
"/de/wolfvollprecht/UberWriter/ui/Preferences.ui")
|
2019-04-15 01:35:24 +00:00
|
|
|
|
|
|
|
self.dark_mode_auto_switch = self.builder.get_object("dark_mode_auto_switch")
|
|
|
|
self.dark_mode_auto_switch.set_active(self.settings.get_value("dark-mode-auto"))
|
|
|
|
self.dark_mode_auto_switch.connect("state-set", self.on_dark_mode_auto)
|
|
|
|
|
|
|
|
self.dark_mode_switch = self.builder.get_object("dark_mode_switch")
|
|
|
|
self.dark_mode_switch.set_active(self.settings.get_value("dark-mode"))
|
|
|
|
self.dark_mode_switch.connect("state-set", self.on_dark_mode)
|
|
|
|
|
|
|
|
self.spellcheck_switch = self.builder.get_object("spellcheck_switch")
|
|
|
|
self.spellcheck_switch.set_active(self.settings.get_value("spellcheck"))
|
|
|
|
self.spellcheck_switch.connect("state-set", self.on_spellcheck)
|
|
|
|
|
|
|
|
self.gradient_overlay_switch = self.builder.get_object("gradient_overlay_switch")
|
|
|
|
self.gradient_overlay_switch.set_active(self.settings.get_value("gradient-overlay"))
|
|
|
|
self.gradient_overlay_switch.connect("state-set", self.on_gradient_overlay)
|
|
|
|
|
2019-04-27 03:56:26 +00:00
|
|
|
self.sync_scroll_switch = self.builder.get_object("sync_scroll_switch")
|
|
|
|
self.sync_scroll_switch.set_active(self.settings.get_value("sync-scroll"))
|
|
|
|
self.sync_scroll_switch.connect("state-set", self.on_sync_scroll)
|
|
|
|
|
2019-04-15 01:35:24 +00:00
|
|
|
input_format_store = Gtk.ListStore(int, str)
|
2019-04-27 03:13:48 +00:00
|
|
|
input_format = self.settings.get_string("input-format")
|
2019-04-15 01:35:24 +00:00
|
|
|
input_format_active = 0
|
|
|
|
for i, fmt in enumerate(self.formats):
|
|
|
|
input_format_store.append([i, fmt["name"]])
|
|
|
|
if fmt["format"] == input_format:
|
|
|
|
input_format_active = i
|
|
|
|
self.input_format_combobox = self.builder.get_object("input_format_combobox")
|
|
|
|
self.input_format_combobox.set_model(input_format_store)
|
|
|
|
input_format_renderer = Gtk.CellRendererText()
|
|
|
|
self.input_format_combobox.pack_start(input_format_renderer, True)
|
|
|
|
self.input_format_combobox.add_attribute(input_format_renderer, "text", 1)
|
|
|
|
self.input_format_combobox.set_active(input_format_active)
|
|
|
|
self.input_format_combobox.connect("changed", self.on_input_format)
|
|
|
|
|
|
|
|
self.input_format_help_button = self.builder.get_object("input_format_help_button")
|
|
|
|
self.input_format_help_button.connect('clicked', self.on_input_format_help)
|
|
|
|
|
|
|
|
def show(self, window):
|
|
|
|
preferences_window = self.builder.get_object("PreferencesWindow")
|
|
|
|
preferences_window.set_application(window.get_application())
|
|
|
|
preferences_window.set_transient_for(window)
|
|
|
|
preferences_window.show()
|
|
|
|
|
|
|
|
def on_dark_mode_auto(self, _, state):
|
2019-04-27 03:58:54 +00:00
|
|
|
self.settings.set_boolean("dark-mode-auto", state)
|
2019-04-15 01:35:24 +00:00
|
|
|
if state and self.dark_mode_switch.get_active():
|
|
|
|
self.dark_mode_switch.set_active(GLib.Variant.new_boolean(False))
|
|
|
|
return False
|
|
|
|
|
|
|
|
def on_dark_mode(self, _, state):
|
2019-04-27 03:58:54 +00:00
|
|
|
self.settings.set_boolean("dark-mode", state)
|
2019-04-15 01:35:24 +00:00
|
|
|
if state and self.dark_mode_auto_switch.get_active():
|
|
|
|
self.dark_mode_auto_switch.set_active(GLib.Variant.new_boolean(False))
|
|
|
|
return False
|
|
|
|
|
|
|
|
def on_spellcheck(self, _, state):
|
2019-04-27 03:58:54 +00:00
|
|
|
self.settings.set_boolean("spellcheck", state)
|
2019-04-15 01:35:24 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
def on_gradient_overlay(self, _, state):
|
2019-04-27 03:58:54 +00:00
|
|
|
self.settings.set_boolean("gradient-overlay", state)
|
2019-04-15 01:35:24 +00:00
|
|
|
return False
|
|
|
|
|
2019-04-27 03:56:26 +00:00
|
|
|
def on_sync_scroll(self, _, state):
|
2019-04-27 03:58:54 +00:00
|
|
|
self.settings.set_boolean("sync-scroll", state)
|
2019-04-27 03:56:26 +00:00
|
|
|
return False
|
|
|
|
|
2019-04-15 01:35:24 +00:00
|
|
|
def on_input_format(self, combobox):
|
|
|
|
fmt = self.formats[combobox.get_active()]
|
2019-04-27 03:58:54 +00:00
|
|
|
self.settings.set_string("input-format", fmt["format"])
|
2019-04-15 01:35:24 +00:00
|
|
|
|
|
|
|
def on_input_format_help(self, _):
|
|
|
|
fmt = self.formats[self.input_format_combobox.get_active()]
|
|
|
|
webbrowser.open(fmt["help"])
|
|
|
|
|