Add input format setting

Supports Pandoc's Markdown, Commonmark, GitHub Flavored Markdown,
MultiMarkdown and Plain Markdown.

Fixes #17
Fixes #122
ft.font-size^2
Gonçalo Silva 2019-04-15 02:35:24 +01:00
parent ce4a13278d
commit 9f41bfac8d
8 changed files with 352 additions and 262 deletions

View File

@ -20,19 +20,26 @@
</key>
<key name='spellcheck' type='b'>
<default>true</default>
<summary>Spellcheck</summary>
<summary>Check spelling while typing</summary>
<description>
Enable or disable spellchecking.
</description>
</key>
<key name='gradient-overlay' type='b'>
<default>false</default>
<summary>Show gradient overlay</summary>
<summary>Draw scroll gradient</summary>
<description>
Show a gradient overlay over the text at the top anf bottom of the window.
It can cause performance problems to some users.
</description>
</key>
<key name='input-format' type='s'>
<default>"markdown"</default>
<summary>Input format</summary>
<description>
Input format to use when previewing and exporting using Pandoc.
</description>
</key>
<key name='poll-motion' type='b'>
<default>true</default>
<summary>Allow Uberwriter to poll cursor motion</summary>

View File

@ -30,17 +30,7 @@
</item>
<item>
<attribute name="label" translatable="yes">Copy HTML</attribute>
<attribute name="action">app.HTML_copy</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">Open Tutorial</attribute>
<attribute name="action">app.open_examples</attribute>
</item>
<item>
<attribute name="action">app.help</attribute>
<attribute name="label" translatable="yes">Pandoc _Help</attribute>
<attribute name="action">app.copy_html</attribute>
</item>
</section>
<section>
@ -52,6 +42,10 @@
<attribute name="action">app.shortcuts</attribute>
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Open Tutorial</attribute>
<attribute name="action">app.open_tutorial</attribute>
</item>
<item>
<attribute name="action">app.about</attribute>
<attribute name="label" translatable="yes">_About UberWriter</attribute>

View File

@ -2,6 +2,11 @@
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkImage" id="help">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-info</property>
</object>
<object class="GtkWindow" id="PreferencesWindow">
<property name="can_focus">False</property>
<property name="modal">True</property>
@ -30,17 +35,17 @@
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin_left">30</property>
<property name="margin_right">30</property>
<property name="margin_top">30</property>
<property name="margin_bottom">30</property>
<property name="row_spacing">10</property>
<property name="column_spacing">10</property>
<property name="margin_left">16</property>
<property name="margin_right">16</property>
<property name="margin_top">16</property>
<property name="margin_bottom">16</property>
<property name="row_spacing">8</property>
<property name="column_spacing">8</property>
<child>
<object class="GtkLabel" id="Dark_mode_auto_label">
<object class="GtkLabel" id="dark_mode_auto_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Set dark mode automatically</property>
<property name="justify">right</property>
</object>
@ -50,10 +55,21 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="Dark_mode_label">
<object class="GtkSwitch" id="dark_mode_auto_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="dark_mode_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Force dark mode</property>
<property name="justify">right</property>
</object>
@ -63,10 +79,21 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="Spellcheck_label">
<object class="GtkSwitch" id="dark_mode_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="spellcheck_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Check spelling while typing</property>
<property name="justify">right</property>
</object>
@ -76,10 +103,21 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="Gradient_label">
<object class="GtkSwitch" id="spellcheck_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="gradient_overlay_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Draw scroll gradient</property>
<property name="justify">right</property>
</object>
@ -89,65 +127,74 @@
</packing>
</child>
<child>
<object class="GtkSwitch" id="Dark_mode_auto_switch">
<object class="GtkSwitch" id="gradient_overlay_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="action_name">app.dark_mode_auto</property>
<property name="halign">end</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="Dark_mode_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="action_name">app.dark_mode</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="Spellcheck_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="action_name">app.spellcheck</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="Gradient_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">start</property>
<property name="action_name">app.draw_gradient</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="left_attach">2</property>
<property name="top_attach">3</property>
</packing>
</child>
</object>
<packing>
<property name="tab_expand">True</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="Label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">page 1</property>
<child>
<object class="GtkLabel" id="format_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Input format</property>
<property name="justify">right</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkButton" id="input_format_help_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="image">help</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="input_format_combobox">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
<property name="active">0</property>
<property name="active_id">0</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="tab_fill">False</property>
</packing>
</child>
<child type="tab">
<placeholder/>
</child>
<child>
<placeholder/>
</child>

View File

@ -11,17 +11,14 @@
# with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.
import argparse
import webbrowser
from gettext import gettext as _
import gi
gi.require_version('Gtk', '3.0') # pylint: disable=wrong-import-position
from gi.repository import GLib, Gio, Gtk, Gdk, GdkPixbuf
from gi.repository import GLib, Gio, Gtk, GdkPixbuf
from uberwriter import window
from uberwriter.theme import Theme
from uberwriter.settings import Settings
from uberwriter.helpers import set_up_logging
from uberwriter.preferences_dialog import PreferencesDialog
@ -36,80 +33,12 @@ class Application(Gtk.Application):
**kwargs)
self.window = None
self.settings = Settings.new()
self.dark_mode_action = None
def do_startup(self, *args, **kwargs):
Gtk.Application.do_startup(self)
# Actions
action = Gio.SimpleAction.new("help", None)
action.connect("activate", self.on_help)
self.add_action(action)
action = Gio.SimpleAction.new("shortcuts", None)
action.connect("activate", self.on_shortcuts)
self.add_action(action)
action = Gio.SimpleAction.new("about", None)
action.connect("activate", self.on_about)
self.add_action(action)
action = Gio.SimpleAction.new("quit", None)
action.connect("activate", self.on_quit)
self.add_action(action)
dark_mode_auto = self.settings.get_value("dark-mode-auto")
action = Gio.SimpleAction.new_stateful("dark_mode_auto", None,
GLib.Variant.new_boolean(dark_mode_auto))
action.connect("change-state", self.on_dark_mode_auto)
self.add_action(action)
dark_mode = self.settings.get_value("dark-mode")
action = Gio.SimpleAction.new_stateful("dark_mode",
None,
GLib.Variant.new_boolean(dark_mode))
action.connect("change-state", self.on_dark_mode)
self.add_action(action)
action = Gio.SimpleAction.new_stateful("focus_mode", None,
GLib.Variant.new_boolean(False))
action.connect("change-state", self.on_focus_mode)
self.add_action(action)
action = Gio.SimpleAction.new_stateful("hemingway_mode", None,
GLib.Variant.new_boolean(False))
action.connect("change-state", self.on_hemingway_mode)
self.add_action(action)
action = Gio.SimpleAction.new_stateful("fullscreen", None,
GLib.Variant.new_boolean(False))
action.connect("change-state", self.on_fullscreen)
self.add_action(action)
action = Gio.SimpleAction.new_stateful("preview", None,
GLib.Variant.new_boolean(False))
action.connect("change-state", self.on_preview)
self.add_action(action)
action = Gio.SimpleAction.new("search", None)
action.connect("activate", self.on_search)
self.add_action(action)
spellcheck = self.settings.get_value("spellcheck")
action = Gio.SimpleAction.new_stateful("spellcheck", None,
GLib.Variant.new_boolean(spellcheck))
action.connect("change-state", self.on_spellcheck)
self.add_action(action)
gradient_overlay = self.settings.get_value("gradient-overlay")
action = Gio.SimpleAction.new_stateful("draw_gradient", None,
GLib.Variant.new_boolean(gradient_overlay))
action.connect("change-state", self.on_draw_gradient)
self.add_action(action)
# Menu Actions
self.settings.connect("changed", self.on_settings_changed)
action = Gio.SimpleAction.new("new", None)
action.connect("activate", self.on_new)
@ -123,14 +52,34 @@ class Application(Gtk.Application):
action.connect("activate", self.on_open_recent)
self.add_action(action)
action = Gio.SimpleAction.new("open_examples", None)
action.connect("activate", self.on_example)
self.add_action(action)
action = Gio.SimpleAction.new("save", None)
action.connect("activate", self.on_save)
self.add_action(action)
action = Gio.SimpleAction.new("search", None)
action.connect("activate", self.on_search)
self.add_action(action)
action = Gio.SimpleAction.new_stateful(
"focus_mode", None, GLib.Variant.new_boolean(False))
action.connect("change-state", self.on_focus_mode)
self.add_action(action)
action = Gio.SimpleAction.new_stateful(
"hemingway_mode", None, GLib.Variant.new_boolean(False))
action.connect("change-state", self.on_hemingway_mode)
self.add_action(action)
action = Gio.SimpleAction.new_stateful(
"preview", None, GLib.Variant.new_boolean(False))
action.connect("change-state", self.on_preview)
self.add_action(action)
action = Gio.SimpleAction.new_stateful(
"fullscreen", None, GLib.Variant.new_boolean(False))
action.connect("change-state", self.on_fullscreen)
self.add_action(action)
action = Gio.SimpleAction.new("save_as", None)
action.connect("activate", self.on_save_as)
self.add_action(action)
@ -139,14 +88,30 @@ class Application(Gtk.Application):
action.connect("activate", self.on_export)
self.add_action(action)
action = Gio.SimpleAction.new("HTML_copy", None)
action.connect("activate", self.on_html_copy)
action = Gio.SimpleAction.new("copy_html", None)
action.connect("activate", self.on_copy_html)
self.add_action(action)
action = Gio.SimpleAction.new("preferences", None)
action.connect("activate", self.on_preferences)
self.add_action(action)
action = Gio.SimpleAction.new("shortcuts", None)
action.connect("activate", self.on_shortcuts)
self.add_action(action)
action = Gio.SimpleAction.new("open_tutorial", None)
action.connect("activate", self.on_open_tutorial)
self.add_action(action)
action = Gio.SimpleAction.new("about", None)
action.connect("activate", self.on_about)
self.add_action(action)
action = Gio.SimpleAction.new("quit", None)
action.connect("activate", self.on_quit)
self.add_action(action)
# Shortcuts
# TODO: be aware that a couple of shortcuts are defined in _gtk_base.css
@ -184,8 +149,7 @@ class Application(Gtk.Application):
help=_("Show debug messages (-vv debugs uberwriter also)"))
parser.add_argument(
"-e", "--experimental-features", help=_("Use experimental features"),
action='store_true'
)
action='store_true')
(self.options, self.args) = parser.parse_known_args()
set_up_logging(self.options)
@ -193,82 +157,15 @@ class Application(Gtk.Application):
self.activate()
return 0
def on_about(self, _action, _param):
builder = get_builder('About')
about_dialog = builder.get_object("AboutDialog")
about_dialog.set_transient_for(self.window)
logo_file = get_media_path("de.wolfvollprecht.UberWriter.svg")
logo = GdkPixbuf.Pixbuf.new_from_file(logo_file)
about_dialog.set_logo(logo)
about_dialog.present()
def on_help(self, _action, _param):
"""open pandoc markdown web
"""
webbrowser.open("https://pandoc.org/MANUAL.html#pandocs-markdown")
def on_shortcuts(self, _action, _param):
builder = get_builder('Shortcuts')
builder.get_object("shortcuts").set_transient_for(self.window)
builder.get_object("shortcuts").show()
def on_dark_mode_auto(self, action, value, update_dark_mode_auto=True):
action.set_state(value)
self.settings.set_value("dark-mode-auto", GLib.Variant("b", value))
if update_dark_mode_auto:
self.on_dark_mode(self.lookup_action("dark_mode"),
GLib.Variant.new_boolean(not value.get_boolean()),
False)
def on_dark_mode(self, action, value, update_dark_mode_auto=True):
action.set_state(value)
self.settings.set_value("dark-mode", GLib.Variant("b", value))
if update_dark_mode_auto:
self.on_dark_mode_auto(self.lookup_action("dark_mode_auto"),
GLib.Variant.new_boolean(not value.get_boolean()),
False)
self.window.apply_current_theme()
def on_focus_mode(self, action, value):
action.set_state(value)
self.window.set_focus_mode(value)
def on_hemingway_mode(self, action, value):
action.set_state(value)
self.window.set_hemingway_mode(value)
def on_fullscreen(self, action, value):
action.set_state(value)
self.window.set_fullscreen(value)
def on_preview(self, action, value):
action.set_state(value)
self.window.toggle_preview(value)
def on_search(self, _action, _value):
self.window.open_search_and_replace()
def on_spellcheck(self, action, value):
action.set_state(value)
self.settings.set_value("spellcheck",
GLib.Variant("b", value))
self.window.toggle_spellcheck(value)
def on_draw_gradient(self, action, value):
action.set_state(value)
self.settings.set_value("gradient-overlay",
GLib.Variant("b", value))
if value:
self.window.overlay = self.window.scrolled_window.connect_after(
"draw", self.window.draw_gradient)
else:
self.window.scrolled_window.disconnect(self.window.overlay)
def on_settings_changed(self, settings, key):
if key == "dark-mode-auto" or key == "dark-mode":
self.window.apply_current_theme()
elif key == "spellcheck":
self.window.toggle_spellcheck(settings.get_value(key))
elif key == "gradient-overlay":
self.window.toggle_gradient_overlay(settings.get_value(key))
elif key == "input-format":
self.window.reload_preview()
def on_new(self, _action, _value):
self.window.new_document()
@ -279,26 +176,58 @@ class Application(Gtk.Application):
def on_open_recent(self, file):
self.window.load_file(file.get_current_uri())
def on_example(self, _action, _value):
self.window.open_uberwriter_markdown()
def on_save(self, _action, _value):
self.window.save_document()
def on_search(self, _action, _value):
self.window.open_search_and_replace()
def on_focus_mode(self, action, value):
action.set_state(value)
self.window.set_focus_mode(value)
def on_hemingway_mode(self, action, value):
action.set_state(value)
self.window.set_hemingway_mode(value)
def on_preview(self, action, value):
action.set_state(value)
self.window.toggle_preview(value)
def on_fullscreen(self, action, value):
action.set_state(value)
self.window.set_fullscreen(value)
def on_save_as(self, _action, _value):
self.window.save_document_as()
def on_export(self, _action, _value):
self.window.open_advanced_export()
def on_html_copy(self, _action, _value):
def on_copy_html(self, _action, _value):
self.window.copy_html_to_clipboard()
def on_preferences(self, _action, _value):
preferences_window = PreferencesDialog()
preferences_window.set_application(self)
preferences_window.set_transient_for(self.window)
preferences_window.show()
PreferencesDialog(self.settings).show(self.window)
def on_shortcuts(self, _action, _param):
builder = get_builder('Shortcuts')
builder.get_object("shortcuts").set_transient_for(self.window)
builder.get_object("shortcuts").show()
def on_open_tutorial(self, _action, _value):
self.window.open_uberwriter_markdown()
def on_about(self, _action, _param):
builder = get_builder('About')
about_dialog = builder.get_object("AboutDialog")
about_dialog.set_transient_for(self.window)
logo_file = get_media_path("de.wolfvollprecht.UberWriter.svg")
logo = GdkPixbuf.Pixbuf.new_from_file(logo_file)
about_dialog.set_logo(logo)
about_dialog.present()
def on_quit(self, _action, _param):
self.quit()

View File

@ -21,11 +21,12 @@ import logging
import os
import shutil
import gi
import pypandoc
from gi.overrides.Pango import Pango
from uberwriter.settings import Settings
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk # pylint: disable=E0611
@ -204,6 +205,7 @@ def get_char_width(widget):
widget.get_pango_context().get_metrics().get_approximate_char_width())
def pandoc_convert(text, fr="markdown", to="html5", args=[], outputfile=None):
def pandoc_convert(text, to="html5", args=[], outputfile=None):
fr = Settings.new().get_value('input-format').get_string() or "markdown"
args.extend(["--quiet"])
return pypandoc.convert_text(text, to, fr, extra_args=args, outputfile=outputfile)

View File

@ -18,23 +18,119 @@
"""this dialog adjusts values in gsettings
"""
import webbrowser
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk # pylint: disable=E0611
from gi.repository import Gtk, Pango, GLib # pylint: disable=E0611
import logging
logger = logging.getLogger('uberwriter')
from uberwriter.helpers import get_builder, show_uri, get_help_uri
from uberwriter.helpers import get_builder
class PreferencesDialog:
class PreferencesDialog(Gtk.Window):
__gtype_name__ = "PreferencesDialog"
def __new__(cls):
"""Special static method that's automatically called by Python when
constructing a new instance of this class.
Returns a fully instantiated PreferencesDialog object.
"""
builder = get_builder('Preferences')
new_object = builder.get_object("PreferencesWindow")
return new_object
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
self.builder = get_builder("Preferences")
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)
input_format_store = Gtk.ListStore(int, str)
input_format = self.settings.get_value("input-format").get_string()
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):
self.settings.set_value("dark-mode-auto", GLib.Variant.new_boolean(state))
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):
self.settings.set_value("dark-mode", GLib.Variant.new_boolean(state))
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):
self.settings.set_value("spellcheck", GLib.Variant.new_boolean(state))
return False
def on_gradient_overlay(self, _, state):
self.settings.set_value("gradient-overlay", GLib.Variant.new_boolean(state))
return False
def on_input_format(self, combobox):
fmt = self.formats[combobox.get_active()]
self.settings.set_value("input-format", GLib.Variant.new_string(fmt["format"]))
def on_input_format_help(self, _):
fmt = self.formats[self.input_format_combobox.get_active()]
webbrowser.open(fmt["help"])

View File

@ -27,7 +27,8 @@ class Settings(Gio.Settings):
"""
Gio.Settings.__init__(self)
def new():
@classmethod
def new(cls):
"""
Return a new Settings object
"""

View File

@ -132,9 +132,8 @@ class Window(Gtk.ApplicationWindow):
# some people seems to have performance problems with the overlay.
# Let them disable it
if self.settings.get_value("gradient-overlay"):
self.overlay = self.scrolled_window.connect_after("draw", self.draw_gradient)
self.overlay_id = None
self.toggle_gradient_overlay(self.settings.get_value("gradient-overlay"))
# Init file name with None
self.set_filename()
@ -186,8 +185,7 @@ class Window(Gtk.ApplicationWindow):
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
# Reload preview if it exists
if self.preview_webview:
self.show_preview()
self.reload_preview()
# Redraw contents of window
self.queue_draw()
@ -484,14 +482,14 @@ class Window(Gtk.ApplicationWindow):
"""
self.sidebar.toggle_sidebar()
def toggle_spellcheck(self, status):
def toggle_spellcheck(self, state):
"""Enable/disable the autospellchecking
Arguments:
status {gtk bool} -- Desired status of the spellchecking
"""
if status.get_boolean():
if state.get_boolean():
try:
self.spell_checker.enable()
except:
@ -525,6 +523,18 @@ class Window(Gtk.ApplicationWindow):
pass
return
def toggle_gradient_overlay(self, state):
"""Toggle the gradient overlay
Arguments:
state {gtk bool} -- Desired state of the gradient overlay (enabled/disabled)
"""
if state.get_boolean():
self.overlay_id = self.scrolled_window.connect_after("draw", self.draw_gradient)
elif self.overlay_id:
self.scrolled_window.disconnect(self.overlay_id)
def toggle_preview(self, state):
"""Toggle the preview mode
@ -572,7 +582,11 @@ class Window(Gtk.ApplicationWindow):
# but local files are opened in appropriate apps:
self.preview_webview.connect("decide-policy", self.on_click_link)
self.preview_webview.load_html(output.decode("utf-8"), 'file://localhost/')
self.preview_webview.load_html(output, 'file://localhost/')
def reload_preview(self):
if self.preview_webview:
self.show_preview()
def load_file(self, filename=None):
"""Open File from command line or open / open recent etc."""