def dark_mode_toggled(self, widget, data=None):
        # Save state for saving settings later
        self.dark_mode = widget.get_active()
        if self.dark_mode:
            # Dark Mode is on
            css = open(helpers.get_media_path('style_dark.css'), 'rb')
            css_data = css.read()
            css.close()
            self.style_provider.load_from_data(css_data)
            self.background_image = helpers.get_media_path('bg_dark.png')
            self.MarkupBuffer.dark_mode(True)

        else: 
            # Dark mode off
            css = open(helpers.get_media_path('style.css'), 'rb')
            css_data = css.read()
            css.close()
            self.style_provider.load_from_data(css_data)
            self.background_image = helpers.get_media_path('bg_light.png')
            self.MarkupBuffer.dark_mode(False)

        surface = cairo.ImageSurface.create_from_png(self.background_image)
        self.background_pattern = cairo.SurfacePattern(surface)
        self.background_pattern.set_extend(cairo.EXTEND_REPEAT)

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), self.style_provider,     
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
        )
        # Redraw contents of window (self)
        self.queue_draw()
Beispiel #2
0
    def dark_mode_toggled(self, widget, data=None):
        if widget.get_active():
            # Dark Mode is on
            # Hack for f*****g unico-shit
            if Gtk.get_minor_version() == 4:
                css = open(helpers.get_media_path('style_dark_old.css'), 'rb')
            else:
                css = open(helpers.get_media_path('style_dark.css'), 'rb')
            css_data = css.read()
            css.close()
            self.style_provider.load_from_data(css_data)
            self.background_image = helpers.get_media_path('bg_dark.png')
            self.MarkupBuffer.dark_mode(True)

        else: 
            # Dark mode off
            css = open(helpers.get_media_path('style.css'), 'rb')
            css_data = css.read()
            css.close()

            self.style_provider.load_from_data(css_data)
            self.background_image = helpers.get_media_path('bg_light.png')
            self.MarkupBuffer.dark_mode(False)

        surface = cairo.ImageSurface.create_from_png(self.background_image)
        self.background_pattern = cairo.SurfacePattern(surface)
        self.background_pattern.set_extend(cairo.EXTEND_REPEAT)

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), self.style_provider,     
            Gtk.STYLE_PROVIDER_PRIORITY_USER
        )
        (w, h) = self.get_size()
        self.resize(w+1, h+1)
    def dark_mode_toggled(self, widget, data=None):
        if widget.get_active():
            # Dark Mode is on
            # Hack for f*****g unico-shit
            if Gtk.get_minor_version() == 4:
                css = open(helpers.get_media_path('style_dark_old.css'), 'rb')
            else:
                css = open(helpers.get_media_path('style_dark.css'), 'rb')
            css_data = css.read()
            css.close()
            self.style_provider.load_from_data(css_data)
            self.background_image = helpers.get_media_path('bg_dark.png')
            self.MarkupBuffer.dark_mode(True)

        else: 
            # Dark mode off
            css = open(helpers.get_media_path('style.css'), 'rb')
            css_data = css.read()
            css.close()

            self.style_provider.load_from_data(css_data)
            self.background_image = helpers.get_media_path('bg_light.png')
            self.MarkupBuffer.dark_mode(False)

        surface = cairo.ImageSurface.create_from_png(self.background_image)
        self.background_pattern = cairo.SurfacePattern(surface)
        self.background_pattern.set_extend(cairo.EXTEND_REPEAT)

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), self.style_provider,     
            Gtk.STYLE_PROVIDER_PRIORITY_USER
        )
        (w, h) = self.get_size()
        self.resize(w+1, h+1)
Beispiel #4
0
    def dark_mode_toggled(self, widget, data=None):
        # Save state for saving settings later
        self.dark_mode = widget.get_active()
        if self.dark_mode:
            # Dark Mode is on
            css = open(helpers.get_media_path('style_dark.css'), 'rb')
            css_data = css.read()
            css.close()
            self.style_provider.load_from_data(css_data)
            self.background_image = helpers.get_media_path('bg_dark.png')
            self.MarkupBuffer.dark_mode(True)

        else:
            # Dark mode off
            css = open(helpers.get_media_path('style.css'), 'rb')
            css_data = css.read()
            css.close()
            self.style_provider.load_from_data(css_data)
            self.background_image = helpers.get_media_path('bg_light.png')
            self.MarkupBuffer.dark_mode(False)

        surface = cairo.ImageSurface.create_from_png(self.background_image)
        self.background_pattern = cairo.SurfacePattern(surface)
        self.background_pattern.set_extend(cairo.EXTEND_REPEAT)

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), self.style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
        # Redraw contents of window (self)
        self.queue_draw()
 def get_frequency_dict(self, language):
     self.frequency_dict = {}
     pp_pickled = get_media_path("frequency_dict_" + self.language + ".pickle")
     if pp_pickled and os.path.isfile(pp_pickled):
         f = open(pp_pickled, 'rb')
         self.frequency_dict = pickle.load(f)
         f.close()
     else:
         pp = get_media_path('wordlists/en_us_wordlist.xml')
         frequencies = ET.parse(pp)
         root = frequencies.getroot()
         for child in root:
             self.frequency_dict[child.text] = int(child.attrib['f'])
         f = open('pickled_dict', 'wb+')
         pickle.dump(self.frequency_dict, f)
         f.close()
Beispiel #6
0
    def toggle_preview(self, widget, data=None):
        if widget.get_active():

            # Toggle buttons

            # self.preview_button.set_active(True)
            # self.preview_mnu_button.set_active(True)
            # Insert a tag with ID to scroll to
            # self.TextBuffer.insert_at_cursor('<span id="scroll_mark"></span>')
            # TODO
            # Find a way to find the next header, scroll to the next header.

            args = ['pandoc',
                    '--from=markdown',
                    '-smart',
                    '-thtml',
                    '--mathjax',
                    '--lua-filter=' + helpers.get_media_path('task-list.lua'),
                    '-c', helpers.get_media_file('uberwriter.css')]
            print(args)

            p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

            text = bytes(self.get_text(), "utf-8")
            output = p.communicate(text)[0]

            # Load in Webview and scroll to #ID
            self.webview = WebKit.WebView()
            self.webview_settings = self.webview.get_settings()
            self.webview_settings.set_allow_universal_access_from_file_urls(True)
            self.webview.load_html(output.decode("utf-8"), 'file://localhost/')

            # Delete the cursor-scroll mark again
            # cursor_iter = self.TextBuffer.get_iter_at_mark(self.TextBuffer.get_insert())
            # begin_del = cursor_iter.copy()
            # begin_del.backward_chars(30)
            # self.TextBuffer.delete(begin_del, cursor_iter)

            self.ScrolledWindow.remove(self.TextEditor)
            self.ScrolledWindow.add(self.webview)
            self.webview.show()

            # This saying that all links will be opened in default browser, \
            # but local files are opened in appropriate apps:
            self.webview.connect("decide-policy", self.on_click_link)
        else:
            self.ScrolledWindow.remove(self.webview)
            self.webview.destroy()
            self.ScrolledWindow.add(self.TextEditor)
            self.TextEditor.show()
            
            # self.preview_button.set_active(False)
            # self.preview_mnu_button.set_active(False)

        self.queue_draw()
        return True
Beispiel #7
0
    def toggle_preview(self, widget, data=None):
        if widget.get_active():
            # Insert a tag with ID to scroll to
            self.TextBuffer.insert_at_cursor('<span id="scroll_mark"></span>')

            args = [
                'pandoc', '--from=markdown', '--smart', '-thtml', '--mathjax',
                '-c',
                helpers.get_media_file('uberwriter.css')
            ]

            p = subprocess.Popen(args,
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE)

            text = bytes(self.get_text(), "utf-8")
            output = p.communicate(text)[0]

            # Load in Webview and scroll to #ID
            self.webview = WebKit.WebView()
            self.webview.load_html_string(output.decode("utf-8"),
                                          'file://localhost/' + '#scroll_mark')

            # Delete the cursor-scroll mark again
            cursor_iter = self.TextBuffer.get_iter_at_mark(
                self.TextBuffer.get_insert())
            begin_del = cursor_iter.copy()
            begin_del.backward_chars(30)
            self.TextBuffer.delete(begin_del, cursor_iter)

            self.ScrolledWindow.remove(self.TextEditor)
            self.ScrolledWindow.add(self.webview)
            self.webview.show()

            # Making the background white

            white_background = helpers.get_media_path('white.png')
            surface = cairo.ImageSurface.create_from_png(white_background)
            self.background_pattern = cairo.SurfacePattern(surface)
            self.background_pattern.set_extend(cairo.EXTEND_REPEAT)
            # This saying that all links will be opened in default browser, but local files are opened in appropriate apps:

            self.webview.connect("navigation-requested", self.on_click_link)
        else:
            self.ScrolledWindow.remove(self.webview)
            self.webview.destroy()
            self.ScrolledWindow.add(self.TextEditor)
            self.TextEditor.show()
            surface = cairo.ImageSurface.create_from_png(self.background_image)
            self.background_pattern = cairo.SurfacePattern(surface)
            self.background_pattern.set_extend(cairo.EXTEND_REPEAT)
        self.queue_draw()
Beispiel #8
0
    def toggle_preview(self, widget, data=None):
        if widget.get_active():
            # Insert a tag with ID to scroll to
            # self.TextBuffer.insert_at_cursor('<span id="scroll_mark"></span>')
            # TODO
            # Find a way to find the next header, scroll to the next header.

            args = ['pandoc',
                    '--from=markdown',
                    '--smart',
                    '-thtml',
                    '--mathjax',
                    '-c', helpers.get_media_file('uberwriter.css')]

            p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

            text = bytes(self.get_text(), "utf-8")
            output = p.communicate(text)[0]

            # Load in Webview and scroll to #ID
            self.webview = WebKit.WebView()
            self.webview.load_html_string(output.decode("utf-8"), 'file://localhost/')

            # Delete the cursor-scroll mark again
            # cursor_iter = self.TextBuffer.get_iter_at_mark(self.TextBuffer.get_insert())
            # begin_del = cursor_iter.copy()
            # begin_del.backward_chars(30)
            # self.TextBuffer.delete(begin_del, cursor_iter)

            self.ScrolledWindow.remove(self.TextEditor)
            self.ScrolledWindow.add(self.webview)
            self.webview.show()

            # Making the background white

            white_background = helpers.get_media_path('white.png')
            surface = cairo.ImageSurface.create_from_png(white_background)
            self.background_pattern = cairo.SurfacePattern(surface)
            self.background_pattern.set_extend(cairo.EXTEND_REPEAT)
            # This saying that all links will be opened in default browser, but local files are opened in appropriate apps:
            self.webview.connect("navigation-requested", self.on_click_link)
        else:
            self.ScrolledWindow.remove(self.webview)
            self.webview.destroy()
            self.ScrolledWindow.add(self.TextEditor)
            self.TextEditor.show()
            surface = cairo.ImageSurface.create_from_png(self.background_image)
            self.background_pattern = cairo.SurfacePattern(surface)
            self.background_pattern.set_extend(cairo.EXTEND_REPEAT)
        self.queue_draw()
    def set_language(self, language):
        print("Language changed to: %s" % language)

        # handle 2 char cases e.g. "en"
        if(len(language) == 2):
            if "en":
                language = "en_US"

        if self.language == language:
            return

        else:
            self.language = language
            print("Language changing")
            config_file = get_media_path("pressagio_config.ini")
            pres_config = configparser.ConfigParser()
            pres_config.read(config_file)
            pres_config.set("Database", "database", get_media_path("corpora/" + self.language + ".sqlite"))
            self.context_tracker = pressagio.context_tracker.ContextTracker(
                pres_config, self.predictor_registry, self.callback)
            self.prsgio = self.predictor_registry[0]

            self.enchant_dict = enchant.Dict(self.language)
    def __init__(self, textview, textbuffer):
        self.TextView = textview
        self.buffer = textbuffer
        self.suggestion = ""
        self.bubble = self.bubble_label = None
        self.buffer.connect_after('insert-text', self.text_insert)
        self.TextView.connect('key-press-event', self.key_pressed)

        self.language = "en_US"
        self.frequency_dict = {}
        self.get_frequency_dict(self.language)
        self.enchant_dict = enchant.Dict(self.language)
        
        self.use_pressagio = False
        config_file = get_media_path("pressagio_config.ini")
        pres_config = configparser.ConfigParser()
        pres_config.read(config_file)
        pres_config.set("Database", "database", get_media_path("corpora/" + self.language + ".sqlite"))
        self.callback = PressagioCallback("")

        self.predictor_registry = pressagio.predictor.PredictorRegistry(pres_config)
        self.context_tracker = pressagio.context_tracker.ContextTracker(
            pres_config, self.predictor_registry, self.callback)
        self.prsgio = self.predictor_registry[0]
Beispiel #11
0
    def init(self):
        """Init main application"""

        # set theme variant (dark/light)
        dark = self.settings.get_value("dark-mode")
        Gtk.Settings.get_default().set_property(
            "gtk-application-prefer-dark-theme", dark)

        # set css for current theme
        self.style_provider = Gtk.CssProvider()

        themes = {
            "Arc": "arc_style.css",
            "Arc-Dark": "arc_style.css",
            "Arc-Darker": "arc_style.css",
        }

        theme = Gtk.Settings.get_default().get_property("gtk-theme-name")
        self.style_provider.load_from_path(
            helpers.get_media_path(themes.get(theme, "adwaita_style.css")))

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), self.style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
    def finish_initializing(self, builder):  # pylint: disable=E1002
        """Set up the main window"""
        super(UberwriterWindow, self).finish_initializing(builder)

        self.AboutDialog = AboutUberwriterDialog
        self.UberwriterAdvancedExportDialog = UberwriterAdvancedExportDialog
        self.builder = builder

        self.connect('save-file', self.save_document)
        self.connect('save-file-as', self.save_document_as)
        self.connect('new-file', self.new_document)
        self.connect('open-file', self.open_document)
        self.connect('toggle-fullscreen', self.menu_activate_fullscreen)
        self.connect('toggle-focusmode', self.menu_activate_focusmode)
        self.connect('toggle-preview', self.menu_activate_preview)
        self.connect('toggle-spellcheck', self.toggle_spellcheck)
        self.connect('close-window', self.on_mnu_close_activate)
        self.connect('toggle-search', self.open_search_and_replace)
        self.scroll_adjusted = False

        # Code for other initialization actions should be added here.

        # Texlive checker
        self.texlive_installed = False

        self.set_name('UberwriterWindow')

        self.use_headerbar = True
        if self.use_headerbar == True:
            self.hb_revealer = Gtk.Revealer(name='titlebar_revealer')
            self.hb = Gtk.HeaderBar()
            self.hb_revealer.add(self.hb)
            self.hb_revealer.props.transition_duration = 1000
            self.hb_revealer.props.transition_type = Gtk.RevealerTransitionType.CROSSFADE
            self.hb.props.show_close_button = True
            self.hb.get_style_context().add_class("titlebar")
            self.set_titlebar(self.hb_revealer)
            self.hb_revealer.show()
            self.hb_revealer.set_reveal_child(True)
            self.hb.show()

            bbtn = Gtk.MenuButton()
            btn_settings = Gtk.MenuButton()
            btn_settings.props.image = Gtk.Image.new_from_icon_name('emblem-system-symbolic', Gtk.IconSize.BUTTON)
            self.builder.get_object("menu4").detach()
            btn_settings.set_popup(self.builder.get_object("menu4"))

            self.builder.get_object("menu1").detach()
            bbtn.set_popup(self.builder.get_object("menu1"))
            self.hb.pack_start(bbtn)
            self.hb.pack_end(btn_settings)
            self.hb.show_all()
            self.testbits = Gdk.WindowState.MAXIMIZED
            self.connect('draw', self.override_headerbar_background)

        self.title_end = "  –  UberWriter"
        self.set_headerbar_title("New File" + self.title_end)

        self.focusmode = False

        self.word_count = builder.get_object('word_count')
        self.char_count = builder.get_object('char_count')
        self.menubar = builder.get_object('menubar1')
        self.menubar.hide()

        # Wire up buttons
        self.fullscreen_button = builder.get_object('fullscreen_toggle')
        self.focusmode_button = builder.get_object('focus_toggle')
        self.preview_button = builder.get_object('preview_toggle')

        self.fullscreen_button.set_name('fullscreen_toggle')
        self.focusmode_button.set_name('focus_toggle')
        self.preview_button.set_name('preview_toggle')

        # Setup status bar hide after 3 seconds

        self.status_bar = builder.get_object('status_bar_box')
        self.statusbar_revealer = builder.get_object('status_bar_revealer')
        self.status_bar.get_style_context().add_class('status_bar_box')
        self.status_bar_visible = True
        self.was_motion = True
        self.buffer_modified_for_status_bar = False
        self.connect("motion-notify-event", self.on_motion_notify)
        GObject.timeout_add(3000, self.poll_for_motion)

        self.accel_group = Gtk.AccelGroup()
        self.add_accel_group(self.accel_group)

        # Setup light background
        self.TextEditor = TextEditor()
        self.TextEditor.set_name('UberwriterEditor')
        self.get_style_context().add_class('uberwriter_window')

        base_leftmargin = 40
        # self.TextEditor.set_left_margin(base_leftmargin)
        self.TextEditor.set_left_margin(40)
        self.TextEditor.props.width_request = 600
        self.TextEditor.props.halign = Gtk.Align.CENTER
        self.TextEditor.set_vadjustment(builder.get_object('vadjustment1'))
        self.TextEditor.set_wrap_mode(Gtk.WrapMode.WORD)
        self.TextEditor.connect('focus-out-event', self.focus_out)
        self.TextEditor.get_style_context().connect('changed', self.style_changed)

        # self.TextEditor.install_style_property_parser

        self.TextEditor.show()
        self.TextEditor.grab_focus()

        self.ScrolledWindow = builder.get_object('editor_scrolledwindow')
        self.EditorAlignment = builder.get_object('editor_alignment')
        self.EditorAlignment.add(self.TextEditor)
        self.alignment_padding = 40
        self.EditorViewport = builder.get_object('editor_viewport')
        self.EditorViewport.connect_after("draw", self.draw_gradient)

        self.smooth_scroll_starttime = 0
        self.smooth_scroll_endtime = 0
        self.smooth_scroll_acttarget = 0
        self.smooth_scroll_data = {
            'target_pos': -1,
            'source_pos': -1, 
            'duration': 0
        }
        self.smooth_scroll_tickid = -1

        self.PreviewPane = builder.get_object('preview_scrolledwindow')

        self.TextEditor.set_margin_top(38)
        self.TextEditor.set_margin_bottom(16)

        self.TextEditor.set_pixels_above_lines(4)
        self.TextEditor.set_pixels_below_lines(4)
        self.TextEditor.set_pixels_inside_wrap(8)

        tab_array = Pango.TabArray.new(1, True)
        tab_array.set_tab(0, Pango.TabAlign.LEFT, 20)
        self.TextEditor.set_tabs(tab_array)

        self.TextBuffer = self.TextEditor.get_buffer()
        self.TextBuffer.set_text('')

        # Init Window height for top/bottom padding
        self.window_height = self.get_size()[1]

        self.text_change_event = self.TextBuffer.connect('changed', self.text_changed)

        # Init file name with None
        self.filename = None

        self.generate_recent_files_menu(self.builder.get_object('recent'))

        self.style_provider = Gtk.CssProvider()
        self.style_provider.load_from_path(helpers.get_media_path('style.css'))

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), self.style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
        )

        # Markup and Shortcuts for the TextBuffer
        self.MarkupBuffer = MarkupBuffer(self, self.TextBuffer, base_leftmargin)
        self.MarkupBuffer.markup_buffer()

        # Scrolling -> Dark or not?
        self.textchange = False
        self.scroll_count = 0
        self.timestamp_last_mouse_motion = 0
        self.TextBuffer.connect_after('mark-set', self.mark_set)

        # Drag and drop

        # self.TextEditor.drag_dest_unset()
        # self.TextEditor.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY)
        self.target_list = Gtk.TargetList.new([])
        self.target_list.add_uri_targets(1)
        self.target_list.add_text_targets(2)

        self.TextEditor.drag_dest_set_target_list(self.target_list)
        self.TextEditor.connect_after('drag-data-received', self.on_drag_data_received)
        def on_drop(widget, *args):
            print("drop")
        self.TextEditor.connect('drag-drop', on_drop)


        self.TextBuffer.connect('paste-done', self.paste_done)
        # self.connect('key-press-event', self.alt_mod)

        # Events for Typewriter mode

        # Setting up inline preview
        self.InlinePreview = UberwriterInlinePreview(self.TextEditor, self.TextBuffer)

        # Vertical scrolling
        self.vadjustment = self.ScrolledWindow.get_vadjustment()
        self.vadjustment.connect('value-changed', self.scrolled)


        self.spellcheck_button = builder.get_object("disable_spellcheck")
        # Setting up spellcheck
        self.auto_correct = None
        try:
            self.SpellChecker = SpellChecker(self.TextEditor,
                locale.getdefaultlocale()[0], collapse=False)
            if self.auto_correct:
                self.auto_correct.set_language(self.SpellChecker.language)
                self.SpellChecker.connect_language_change(self.auto_correct.set_language)

            self.spellcheck = True
        except:
            self.SpellChecker = None
            self.spellcheck = False
            builder.get_object("disable_spellcheck").set_active(False)

        if self.spellcheck:
            self.SpellChecker.append_filter('[#*]+', SpellChecker.FILTER_WORD)

        self.did_change = False

        ###
        #   Sidebar initialization test
        ###
        self.paned_window = builder.get_object("main_pained")
        self.sidebar_box = builder.get_object("sidebar_box")
        self.sidebar = UberwriterSidebar(self)
        self.sidebar_box.hide()

        ###
        #   Search and replace initialization
        #   Same interface as Sidebar ;)
        ###
        self.searchreplace = UberwriterSearchAndReplace(self)


        # Window resize
        self.window_resize(self)
        self.connect("configure-event", self.window_resize)
        self.connect("delete-event", self.on_delete_called)

        self.gtk_settings = Gtk.Settings.get_default()
        self.load_settings(builder)

        self.plugins = [BibTex(self)]
    def finish_initializing(self, builder):  # pylint: disable=E1002
        """Set up the main window"""

        super(UberwriterWindow, self).finish_initializing(builder)

        # preferences
        self.settings = Settings.new()
        self.builder = builder

        self.connect('save-file', self.save_document)
        self.connect('save-file-as', self.save_document_as)
        self.connect('new-file', self.new_document)
        self.connect('open-file', self.open_document)
        self.connect('close-window', self.on_mnu_close_activate)
        self.scroll_adjusted = False

        # Code for other initialization actions should be added here.

        # Texlive checker
        self.texlive_installed = False

        self.set_name('UberwriterWindow')

        # Headerbars
        self.hb_container = Gtk.Frame(name='titlebar_container')
        self.hb_container.set_shadow_type(Gtk.ShadowType.NONE)
        self.hb_revealer = Gtk.Revealer(name='titlebar_revealer')
        self.hb = Gtk.HeaderBar()
        self.hb_revealer.add(self.hb)
        self.hb_revealer.props.transition_duration = 1000
        self.hb_revealer.props.transition_type = Gtk.RevealerTransitionType.CROSSFADE
        self.hb.props.show_close_button = True
        self.hb.get_style_context().add_class("titlebar")
        self.hb_container.add(self.hb_revealer)
        self.hb_container.show()
        self.set_titlebar(self.hb_container)
        self.hb_revealer.show()
        self.hb_revealer.set_reveal_child(True)
        self.hb.show()

        btn_new = Gtk.Button().new_with_label(_("New"))
        btn_open = Gtk.Button().new_with_label(_("Open"))
        btn_recent = Gtk.MenuButton().new()
        btn_recent.set_image(
            Gtk.Image.new_from_icon_name("go-down-symbolic",
                                         Gtk.IconSize.BUTTON))
        btn_recent.set_tooltip_text(_("Open Recent"))
        btn_recent.set_popup(self.generate_recent_files_menu())
        btn_save = Gtk.Button().new_with_label(_("Save"))
        btn_search = Gtk.Button().new_from_icon_name("system-search-symbolic",
                                                     Gtk.IconSize.BUTTON)
        btn_search.set_tooltip_text(_("Search and replace"))
        btn_menu = Gtk.MenuButton().new()
        btn_menu.set_tooltip_text(_("Menu"))
        btn_menu.set_image(
            Gtk.Image.new_from_icon_name("open-menu-symbolic",
                                         Gtk.IconSize.BUTTON))

        btn_new.set_action_name("app.new")
        btn_open.set_action_name("app.open")
        btn_recent.set_action_name("app.open_recent")
        btn_save.set_action_name("app.save")
        btn_search.set_action_name("app.search")

        btn_menu.set_use_popover(True)
        self.builder_window_menu = get_builder('Menu')
        self.model = self.builder_window_menu.get_object("Menu")
        btn_menu.set_menu_model(self.model)

        self.hb.pack_start(btn_new)
        self.hb.pack_start(btn_open)
        self.hb.pack_start(btn_recent)
        self.hb.pack_end(btn_menu)
        self.hb.pack_end(btn_search)
        self.hb.pack_end(btn_save)
        self.hb.show_all()

        # same for fullscreen headerbar
        # TODO: Refactorice: this is duplicated code!

        self.fullscr_events = self.builder.get_object("FullscreenEventbox")
        self.fullscr_hb_revealer = self.builder.get_object(
            "FullscreenHbPlaceholder")
        self.fullscr_hb = self.builder.get_object("FullscreenHeaderbar")
        self.fullscr_hb.get_style_context().add_class("titlebar")
        self.fullscr_hb_revealer.show()
        self.fullscr_hb_revealer.set_reveal_child(False)
        self.fullscr_hb.show()
        self.fullscr_events.hide()

        fs_btn_new = Gtk.Button().new_with_label(_("New"))
        fs_btn_open = Gtk.Button().new_with_label(_("Open"))
        self.fs_btn_recent = Gtk.MenuButton().new()
        self.fs_btn_recent.set_tooltip_text(_("Open Recent"))
        self.fs_btn_recent.set_image(
            Gtk.Image.new_from_icon_name("go-down-symbolic",
                                         Gtk.IconSize.BUTTON))
        self.fs_btn_recent.set_tooltip_text(_("Open Recent"))
        self.fs_btn_recent.set_popup(self.generate_recent_files_menu())
        fs_btn_save = Gtk.Button().new_with_label(_("Save"))
        fs_btn_search = Gtk.Button().new_from_icon_name(
            "system-search-symbolic", Gtk.IconSize.BUTTON)
        fs_btn_search.set_tooltip_text(_("Search and replace"))
        self.fs_btn_menu = Gtk.MenuButton().new()
        self.fs_btn_menu.set_tooltip_text(_("Menu"))
        self.fs_btn_menu.set_image(
            Gtk.Image.new_from_icon_name("open-menu-symbolic",
                                         Gtk.IconSize.BUTTON))
        fs_btn_exit = Gtk.Button().new_from_icon_name("view-restore-symbolic",
                                                      Gtk.IconSize.BUTTON)
        fs_btn_exit.set_tooltip_text(_("Exit Fullscreen"))

        fs_btn_new.set_action_name("app.new")
        fs_btn_open.set_action_name("app.open")
        self.fs_btn_recent.set_action_name("app.open_recent")
        fs_btn_save.set_action_name("app.save")
        fs_btn_search.set_action_name("app.search")
        fs_btn_exit.set_action_name("app.fullscreen")

        self.fs_btn_menu.set_use_popover(True)
        self.builder_window_menu = get_builder('Menu')
        self.model = self.builder_window_menu.get_object("Menu")
        self.fs_btn_menu.set_menu_model(self.model)

        self.fullscr_hb.pack_start(fs_btn_new)
        self.fullscr_hb.pack_start(fs_btn_open)
        self.fullscr_hb.pack_start(self.fs_btn_recent)
        self.fullscr_hb.pack_end(fs_btn_exit)
        self.fullscr_hb.pack_end(self.fs_btn_menu)
        self.fullscr_hb.pack_end(fs_btn_search)
        self.fullscr_hb.pack_end(fs_btn_save)
        self.fullscr_hb.show_all()
        # this is a little tricky
        # we show hb when the cursor enters an area of 1 px at the top of the window
        # as the hb is shown the height of the eventbox grows to accomodate it
        self.fullscr_events.connect('enter_notify_event', self.show_fs_hb)
        self.fullscr_events.connect('leave_notify_event', self.hide_fs_hb)
        self.fs_btn_menu.get_popover().connect('closed', self.hide_fs_hb)

        self.title_end = "  –  UberWriter"
        self.set_headerbar_title("New File" + self.title_end)

        self.focusmode = False

        self.word_count = builder.get_object('word_count')
        self.char_count = builder.get_object('char_count')

        # Setup status bar hide after 3 seconds

        self.status_bar = builder.get_object('status_bar_box')
        self.statusbar_revealer = builder.get_object('status_bar_revealer')
        self.status_bar.get_style_context().add_class('status_bar_box')
        self.status_bar_visible = True
        self.was_motion = True
        self.buffer_modified_for_status_bar = False
        self.connect("motion-notify-event", self.on_motion_notify)
        GObject.timeout_add(3000, self.poll_for_motion)

        self.accel_group = Gtk.AccelGroup()
        self.add_accel_group(self.accel_group)

        # Setup light background
        self.TextEditor = TextEditor()
        self.TextEditor.set_name('UberwriterEditor')
        self.get_style_context().add_class('uberwriter_window')

        base_leftmargin = 100
        self.TextEditor.set_left_margin(base_leftmargin)
        self.TextEditor.set_left_margin(40)
        self.TextEditor.set_top_margin(80)
        self.TextEditor.props.width_request = 600
        self.TextEditor.props.halign = Gtk.Align.CENTER
        self.TextEditor.set_vadjustment(builder.get_object('vadjustment1'))
        self.TextEditor.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
        self.TextEditor.connect('focus-out-event', self.focus_out)
        self.TextEditor.get_style_context().connect('changed',
                                                    self.style_changed)

        # self.TextEditor.install_style_property_parser

        self.TextEditor.show()
        self.TextEditor.grab_focus()

        self.EditorAlignment = builder.get_object('editor_alignment')
        self.ScrolledWindow = builder.get_object('editor_scrolledwindow')
        self.ScrolledWindow.props.width_request = 600
        self.ScrolledWindow.add(self.TextEditor)
        self.alignment_padding = 40
        self.EditorViewport = builder.get_object('editor_viewport')
        self.ScrolledWindow.connect_after("draw", self.draw_gradient)

        self.smooth_scroll_starttime = 0
        self.smooth_scroll_endtime = 0
        self.smooth_scroll_acttarget = 0
        self.smooth_scroll_data = {
            'target_pos': -1,
            'source_pos': -1,
            'duration': 0
        }
        self.smooth_scroll_tickid = -1

        self.PreviewPane = builder.get_object('preview_scrolledwindow')

        self.TextEditor.set_top_margin(80)
        self.TextEditor.set_bottom_margin(16)

        self.TextEditor.set_pixels_above_lines(4)
        self.TextEditor.set_pixels_below_lines(4)
        self.TextEditor.set_pixels_inside_wrap(8)

        tab_array = Pango.TabArray.new(1, True)
        tab_array.set_tab(0, Pango.TabAlign.LEFT, 20)
        self.TextEditor.set_tabs(tab_array)

        self.TextBuffer = self.TextEditor.get_buffer()
        self.TextBuffer.set_text('')

        # Init Window height for top/bottom padding
        self.window_height = self.get_size()[1]

        self.text_change_event = self.TextBuffer.connect(
            'changed', self.text_changed)

        # Init file name with None
        self.set_filename()

        self.style_provider = Gtk.CssProvider()
        self.style_provider.load_from_path(helpers.get_media_path('style.css'))

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), self.style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

        # Markup and Shortcuts for the TextBuffer
        self.MarkupBuffer = MarkupBuffer(self, self.TextBuffer,
                                         base_leftmargin)
        self.MarkupBuffer.markup_buffer()

        # Setup dark mode if so
        if self.settings.get_value("dark-mode"):
            self.dark_mode_toggled(True)

        # Scrolling -> Dark or not?
        self.textchange = False
        self.scroll_count = 0
        self.timestamp_last_mouse_motion = 0
        self.TextBuffer.connect_after('mark-set', self.mark_set)

        # Drag and drop

        # self.TextEditor.drag_dest_unset()
        # self.TextEditor.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY)
        self.target_list = Gtk.TargetList.new([])
        self.target_list.add_uri_targets(1)
        self.target_list.add_text_targets(2)

        self.TextEditor.drag_dest_set_target_list(self.target_list)
        self.TextEditor.connect_after('drag-data-received',
                                      self.on_drag_data_received)

        def on_drop(widget, *args):
            print("drop")

        self.TextEditor.connect('drag-drop', on_drop)

        self.TextBuffer.connect('paste-done', self.paste_done)
        # self.connect('key-press-event', self.alt_mod)

        # Events for Typewriter mode

        # Setting up inline preview
        self.InlinePreview = UberwriterInlinePreview(self.TextEditor,
                                                     self.TextBuffer)

        # Vertical scrolling
        self.vadjustment = self.ScrolledWindow.get_vadjustment()
        self.vadjustment.connect('value-changed', self.scrolled)

        # Setting up spellcheck
        self.auto_correct = None
        try:
            self.SpellChecker = SpellChecker(self.TextEditor,
                                             locale.getdefaultlocale()[0],
                                             collapse=False)
            if self.auto_correct:
                self.auto_correct.set_language(self.SpellChecker.language)
                self.SpellChecker.connect_language_change(
                    self.auto_correct.set_language)

            self.spellcheck = True
        except:
            self.SpellChecker = None
            self.spellcheck = False

        if self.spellcheck:
            self.SpellChecker.append_filter('[#*]+', SpellChecker.FILTER_WORD)

        self.did_change = False

        ###
        #   Sidebar initialization test
        ###
        self.paned_window = builder.get_object("main_pained")
        self.sidebar_box = builder.get_object("sidebar_box")
        self.sidebar = UberwriterSidebar(self)
        self.sidebar_box.hide()

        ###
        #   Search and replace initialization
        #   Same interface as Sidebar ;)
        ###
        self.searchreplace = UberwriterSearchAndReplace(self)

        # Window resize
        self.window_resize(self)
        self.connect("configure-event", self.window_resize)
        self.connect("delete-event", self.on_delete_called)
    def toggle_preview(self, state):

        if state.get_boolean():

            # Insert a tag with ID to scroll to
            # self.TextBuffer.insert_at_cursor('<span id="scroll_mark"></span>')
            # TODO
            # Find a way to find the next header, scroll to the next header.
            # TODO: provide a local version of mathjax

            # We need to convert relative routes to absolute ones
            # For that first we need to know if the file is saved:
            if self.filename:
                base_path = os.path.dirname(self.filename)
            else:
                base_path = ''
            os.environ['PANDOC_PREFIX'] = base_path + '/'

            # Set the styles according the color theme
            if self.settings.get_value("dark-mode"):
                stylesheet = helpers.get_media_path('uberwriter_dark.css')
            else:
                stylesheet = helpers.get_media_path('uberwriter.css')

            args = [
                'pandoc', '-s', '--from=markdown', '--to=html5', '--mathjax',
                '--css=' + stylesheet, '--lua-filter=' +
                helpers.get_script_path('relative_to_absolute.lua'),
                '--lua-filter=' + helpers.get_script_path('task-list.lua')
            ]

            p = subprocess.Popen(args,
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE)

            text = bytes(self.get_text(), "utf-8")
            output = p.communicate(text)[0]

            # Load in Webview and scroll to #ID
            self.webview = WebKit.WebView()
            self.webview_settings = self.webview.get_settings()
            self.webview_settings.set_allow_universal_access_from_file_urls(
                True)
            self.webview.load_html(output.decode("utf-8"), 'file://localhost/')

            # Delete the cursor-scroll mark again
            # cursor_iter = self.TextBuffer.get_iter_at_mark(self.TextBuffer.get_insert())
            # begin_del = cursor_iter.copy()
            # begin_del.backward_chars(30)
            # self.TextBuffer.delete(begin_del, cursor_iter)

            self.ScrolledWindow.remove(self.TextEditor)
            self.ScrolledWindow.add(self.webview)
            self.webview.show()

            # This saying that all links will be opened in default browser, \
            # but local files are opened in appropriate apps:
            self.webview.connect("decide-policy", self.on_click_link)
        else:
            self.ScrolledWindow.remove(self.webview)
            self.webview.destroy()
            self.ScrolledWindow.add(self.TextEditor)
            self.TextEditor.show()

        self.queue_draw()
        return True
Beispiel #15
0
    def finish_initializing(self, builder):  # pylint: disable=E1002
        """Set up the main window"""
        super(UberwriterWindow, self).finish_initializing(builder)

        self.AboutDialog = AboutUberwriterDialog
        self.UberwriterAdvancedExportDialog = UberwriterAdvancedExportDialog

        # Code for other initialization actions should be added here.

        # Texlive checker

        self.texlive_installed = False

        # Draw background
        self.background_image = helpers.get_media_path('bg_light.png')
        self.connect('draw', self.draw_bg)

        self.set_name('UberwriterWindow')

        self.title_end = "  –  UberWriter"
        self.set_title("New File" + self.title_end)

        # Drag and drop
        self.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY)

        self.target_list = Gtk.TargetList.new([])
        self.target_list.add_uri_targets(1)
        self.target_list.add_text_targets(2)

        self.drag_dest_set_target_list(self.target_list)

        self.focusmode = False

        self.word_count = builder.get_object('word_count')
        self.char_count = builder.get_object('char_count')
        self.menubar = builder.get_object('menubar1')

        # Wire up buttons
        self.fullscreen_button = builder.get_object('fullscreen_toggle')
        self.focusmode_button = builder.get_object('focus_toggle')
        self.preview_button = builder.get_object('preview_toggle')

        self.fullscreen_button.set_name('fullscreen_toggle')
        self.focusmode_button.set_name('focus_toggle')
        self.preview_button.set_name('preview_toggle')

        # Setup status bar hide after 3 seconds

        self.status_bar = builder.get_object('status_bar_box')
        self.status_bar.set_name('status_bar_box')
        self.status_bar_visible = True
        self.was_motion = True
        self.buffer_modified_for_status_bar = False
        self.connect("motion-notify-event", self.on_motion_notify)
        GObject.timeout_add(3000, self.poll_for_motion)

        self.accel_group = Gtk.AccelGroup()
        self.add_accel_group(self.accel_group)

        # Setup light background

        surface = cairo.ImageSurface.create_from_png(self.background_image)
        self.background_pattern = cairo.SurfacePattern(surface)
        self.background_pattern.set_extend(cairo.EXTEND_REPEAT)

        self.TextEditor = TextEditor()

        base_leftmargin = 100
        self.TextEditor.set_left_margin(base_leftmargin)
        self.TextEditor.set_left_margin(40)

        self.TextEditor.set_wrap_mode(Gtk.WrapMode.WORD)

        self.TextEditor.show()

        self.ScrolledWindow = builder.get_object('editor_scrolledwindow')
        self.ScrolledWindow.add(self.TextEditor)

        self.PreviewPane = builder.get_object('preview_scrolledwindow')

        pangoFont = Pango.FontDescription("Ubuntu Mono 15px")

        self.TextEditor.modify_font(pangoFont)

        self.TextEditor.set_margin_top(38)
        self.TextEditor.set_margin_bottom(16)

        self.TextEditor.set_pixels_above_lines(4)
        self.TextEditor.set_pixels_below_lines(4)
        self.TextEditor.set_pixels_inside_wrap(8)

        tab_array = Pango.TabArray.new(1, True)
        tab_array.set_tab(0, Pango.TabAlign.LEFT, 20)
        self.TextEditor.set_tabs(tab_array)

        self.TextBuffer = self.TextEditor.get_buffer()
        self.TextBuffer.set_text('')

        # Init Window height for top/bottom padding

        self.window_height = self.get_size()[1]

        self.text_change_event = self.TextBuffer.connect(
            'changed', self.text_changed)

        self.TextEditor.connect('move-cursor', self.cursor_moved)

        # Init file name with None
        self.filename = None

        self.generate_recent_files_menu(self.builder.get_object('recent'))

        self.style_provider = Gtk.CssProvider()

        css = open(helpers.get_media_path('style.css'), 'rb')
        css_data = css.read()
        css.close()

        self.style_provider.load_from_data(css_data)

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), self.style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

        # Still needed.
        self.fflines = 0

        # Markup and Shortcuts for the TextBuffer
        self.MarkupBuffer = MarkupBuffer(self, self.TextBuffer,
                                         base_leftmargin)
        self.MarkupBuffer.markup_buffer()
        self.FormatShortcuts = FormatShortcuts(self.TextBuffer,
                                               self.TextEditor)

        # Scrolling -> Dark or not?
        self.textchange = False
        self.scroll_count = 0

        self.TextBuffer.connect('mark-set', self.mark_set)

        self.TextEditor.drag_dest_unset()

        # Events to preserve margin. (To be deleted.)
        self.TextEditor.connect('delete-from-cursor', self.delete_from_cursor)
        self.TextEditor.connect('backspace', self.backspace)

        self.TextBuffer.connect('paste-done', self.paste_done)
        # self.connect('key-press-event', self.alt_mod)

        # Events for Typewriter mode
        self.TextBuffer.connect_after('mark-set', self.after_mark_set)
        self.TextBuffer.connect_after('changed', self.after_modify_text)
        self.TextEditor.connect_after('move-cursor', self.after_cursor_moved)
        self.TextEditor.connect_after('insert-at-cursor',
                                      self.after_insert_at_cursor)

        # Setting up inline preview
        self.InlinePreview = UberwriterInlinePreview(self.TextEditor,
                                                     self.TextBuffer)

        # Vertical scrolling
        self.vadjustment = self.TextEditor.get_vadjustment()
        self.vadjustment.connect('value-changed', self.scrolled)

        # Setting up spellcheck
        try:
            self.SpellChecker = SpellChecker(self.TextEditor,
                                             locale.getdefaultlocale()[0],
                                             collapse=False)
            self.spellcheck = True
        except:
            self.SpellChecker = None
            self.spellcheck = False
            builder.get_object("disable_spellcheck").set_active(False)

        if self.spellcheck:
            self.SpellChecker.append_filter('[#*]+', SpellChecker.FILTER_WORD)

        self.did_change = False

        # Window resize
        self.connect("configure-event", self.window_resize)
        self.connect("delete-event", self.on_delete_called)
        self.load_settings(builder)
    def finish_initializing(self, builder): # pylint: disable=E1002
        """Set up the main window"""
        super(UberwriterWindow, self).finish_initializing(builder)

        self.AboutDialog = AboutUberwriterDialog
        self.UberwriterAdvancedExportDialog = UberwriterAdvancedExportDialog

        # Code for other initialization actions should be added here.
        
        # Texlive checker

        self.texlive_installed = False

        # Draw background
        self.background_image = helpers.get_media_path('bg_light.png')
        self.connect('draw', self.draw_bg)

        self.set_name('UberwriterWindow')

        self.title_end = "  –  UberWriter"
        self.set_title("New File" + self.title_end)

        # Drag and drop
        self.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY)
        
        self.target_list = Gtk.TargetList.new([])
        self.target_list.add_uri_targets(1)
        self.target_list.add_text_targets(2)

        self.drag_dest_set_target_list(self.target_list)

        self.focusmode = False

        self.word_count = builder.get_object('word_count')
        self.char_count = builder.get_object('char_count')
        self.menubar = builder.get_object('menubar1')
        
        # Wire up buttons
        self.fullscreen_button = builder.get_object('fullscreen_toggle')
        self.focusmode_button = builder.get_object('focus_toggle')
        self.preview_button = builder.get_object('preview_toggle')

        self.fullscreen_button.set_name('fullscreen_toggle')
        self.focusmode_button.set_name('focus_toggle')
        self.preview_button.set_name('preview_toggle')
        
        # Setup status bar hide after 3 seconds

        self.status_bar = builder.get_object('status_bar_box')
        self.status_bar.set_name('status_bar_box')
        self.status_bar_visible = True
        self.was_motion = True
        self.buffer_modified_for_status_bar = False
        self.connect("motion-notify-event", self.on_motion_notify)
        GObject.timeout_add(3000, self.poll_for_motion)

        self.accel_group = Gtk.AccelGroup()
        self.add_accel_group(self.accel_group)

        # Setup light background

        surface = cairo.ImageSurface.create_from_png(self.background_image)
        self.background_pattern = cairo.SurfacePattern(surface)
        self.background_pattern.set_extend(cairo.EXTEND_REPEAT)

        self.TextEditor = TextEditor()

        base_leftmargin = 100
        self.TextEditor.set_left_margin(base_leftmargin)
        self.TextEditor.set_left_margin(40)

        self.TextEditor.set_wrap_mode(Gtk.WrapMode.WORD)

        self.TextEditor.show()

        self.ScrolledWindow = builder.get_object('editor_scrolledwindow')
        self.ScrolledWindow.add(self.TextEditor)
        
        self.PreviewPane = builder.get_object('preview_scrolledwindow')

        pangoFont = Pango.FontDescription("Ubuntu Mono 15px")

        self.TextEditor.modify_font(pangoFont)

        self.TextEditor.set_margin_top(38)
        self.TextEditor.set_margin_bottom(16)

        self.TextEditor.set_pixels_above_lines(4)
        self.TextEditor.set_pixels_below_lines(4)
        self.TextEditor.set_pixels_inside_wrap(8)

        tab_array = Pango.TabArray.new(1, True)
        tab_array.set_tab(0, Pango.TabAlign.LEFT, 20)
        self.TextEditor.set_tabs(tab_array)


        self.TextBuffer = self.TextEditor.get_buffer()
        self.TextBuffer.set_text('')

        # Init Window height for top/bottom padding

        self.window_height = self.get_size()[1]

        self.text_change_event = self.TextBuffer.connect('changed', self.text_changed)
        
        self.TextEditor.connect('move-cursor', self.cursor_moved)

        # Init file name with None
        self.filename = None

        self.generate_recent_files_menu(self.builder.get_object('recent'))

        self.style_provider = Gtk.CssProvider()

        css = open(helpers.get_media_path('style.css'), 'rb')
        css_data = css.read()
        css.close()

        self.style_provider.load_from_data(css_data)

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), self.style_provider,     
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
        )
 
        # Still needed.
        self.fflines = 0

        # Markup and Shortcuts for the TextBuffer
        self.MarkupBuffer = MarkupBuffer(self, self.TextBuffer, base_leftmargin)
        self.MarkupBuffer.markup_buffer()
        self.FormatShortcuts = FormatShortcuts(self.TextBuffer, self.TextEditor)

        # Scrolling -> Dark or not?
        self.textchange = False
        self.scroll_count = 0

        self.TextBuffer.connect('mark-set', self.mark_set)
        
        self.TextEditor.drag_dest_unset()

        # Events to preserve margin. (To be deleted.)
        self.TextEditor.connect('delete-from-cursor', self.delete_from_cursor)
        self.TextEditor.connect('backspace', self.backspace)

        self.TextBuffer.connect('paste-done', self.paste_done)
        # self.connect('key-press-event', self.alt_mod)

        # Events for Typewriter mode
        self.TextBuffer.connect_after('mark-set', self.after_mark_set)
        self.TextBuffer.connect_after('changed', self.after_modify_text)
        self.TextEditor.connect_after('move-cursor', self.after_cursor_moved)
        self.TextEditor.connect_after('insert-at-cursor', self.after_insert_at_cursor)

        # Setting up inline preview
        self.InlinePreview = UberwriterInlinePreview(self.TextEditor, self.TextBuffer)

        # Vertical scrolling
        self.vadjustment = self.TextEditor.get_vadjustment()
        self.vadjustment.connect('value-changed', self.scrolled)

        # Setting up spellcheck
        try:
            self.SpellChecker = SpellChecker(self.TextEditor, locale.getdefaultlocale()[0], collapse=False)
            self.spellcheck = True
        except:
            self.SpellChecker = None
            self.spellcheck = False
            builder.get_object("disable_spellcheck").set_active(False)

        if self.spellcheck:
            self.SpellChecker.append_filter('[#*]+', SpellChecker.FILTER_WORD)

        self.did_change = False

        # Window resize
        self.connect("configure-event", self.window_resize)
        self.connect("delete-event", self.on_delete_called)
        self.load_settings(builder)
    def finish_initializing(self, builder):  # pylint: disable=E1002
        """Set up the main window"""
        super(UberwriterWindow, self).finish_initializing(builder)

        self.AboutDialog = AboutUberwriterDialog
        self.UberwriterAdvancedExportDialog = UberwriterAdvancedExportDialog
        self.builder = builder

        self.connect('save-file', self.save_document)
        self.connect('save-file-as', self.save_document_as)
        self.connect('new-file', self.new_document)
        self.connect('open-file', self.open_document)
        self.connect('toggle-fullscreen', self.menu_activate_fullscreen)
        self.connect('toggle-focusmode', self.menu_activate_focusmode)
        self.connect('toggle-preview', self.menu_activate_preview)
        self.connect('toggle-spellcheck', self.toggle_spellcheck)
        self.connect('close-window', self.on_mnu_close_activate)
        self.connect('toggle-search', self.open_search_and_replace)
        self.scroll_adjusted = False

        # Code for other initialization actions should be added here.

        # Texlive checker
        self.texlive_installed = False

        self.set_name('UberwriterWindow')

        self.use_headerbar = True
        if self.use_headerbar == True:
            self.hb_revealer = Gtk.Revealer(name='titlebar_revealer')
            self.hb = Gtk.HeaderBar()
            self.hb_revealer.add(self.hb)
            self.hb_revealer.props.transition_duration = 1000
            self.hb_revealer.props.transition_type = Gtk.RevealerTransitionType.CROSSFADE
            self.hb.props.show_close_button = True
            self.hb.get_style_context().add_class("titlebar")
            self.set_titlebar(self.hb_revealer)
            self.hb_revealer.show()
            self.hb_revealer.set_reveal_child(True)
            self.hb.show()

            bbtn = Gtk.MenuButton()
            btn_settings = Gtk.MenuButton()
            btn_settings.props.image = Gtk.Image.new_from_icon_name(
                'emblem-system-symbolic', Gtk.IconSize.BUTTON)
            self.builder.get_object("menu4").detach()
            btn_settings.set_popup(self.builder.get_object("menu4"))

            self.builder.get_object("menu1").detach()
            bbtn.set_popup(self.builder.get_object("menu1"))
            self.hb.pack_start(bbtn)
            self.hb.pack_end(btn_settings)
            self.hb.show_all()
            self.testbits = Gdk.WindowState.MAXIMIZED
            self.connect('draw', self.override_headerbar_background)

        self.title_end = "  –  UberWriter"
        self.set_headerbar_title("New File" + self.title_end)

        self.focusmode = False

        self.word_count = builder.get_object('word_count')
        self.char_count = builder.get_object('char_count')
        self.menubar = builder.get_object('menubar1')
        self.menubar.hide()

        # Wire up buttons
        self.fullscreen_button = builder.get_object('fullscreen_toggle')
        self.focusmode_button = builder.get_object('focus_toggle')
        self.preview_button = builder.get_object('preview_toggle')

        self.fullscreen_button.set_name('fullscreen_toggle')
        self.focusmode_button.set_name('focus_toggle')
        self.preview_button.set_name('preview_toggle')

        # Setup status bar hide after 3 seconds

        self.status_bar = builder.get_object('status_bar_box')
        self.statusbar_revealer = builder.get_object('status_bar_revealer')
        self.status_bar.get_style_context().add_class('status_bar_box')
        self.status_bar_visible = True
        self.was_motion = True
        self.buffer_modified_for_status_bar = False
        self.connect("motion-notify-event", self.on_motion_notify)
        GObject.timeout_add(3000, self.poll_for_motion)

        self.accel_group = Gtk.AccelGroup()
        self.add_accel_group(self.accel_group)

        # Setup light background
        self.TextEditor = TextEditor()
        self.TextEditor.set_name('UberwriterEditor')
        self.get_style_context().add_class('uberwriter_window')

        base_leftmargin = 40
        # self.TextEditor.set_left_margin(base_leftmargin)
        self.TextEditor.set_left_margin(40)
        self.TextEditor.props.width_request = 600
        self.TextEditor.props.halign = Gtk.Align.CENTER
        self.TextEditor.set_vadjustment(builder.get_object('vadjustment1'))
        self.TextEditor.set_wrap_mode(Gtk.WrapMode.WORD)
        self.TextEditor.connect('focus-out-event', self.focus_out)
        self.TextEditor.get_style_context().connect('changed',
                                                    self.style_changed)

        # self.TextEditor.install_style_property_parser

        self.TextEditor.show()
        self.TextEditor.grab_focus()

        self.ScrolledWindow = builder.get_object('editor_scrolledwindow')
        self.EditorAlignment = builder.get_object('editor_alignment')
        self.EditorAlignment.add(self.TextEditor)
        self.alignment_padding = 40
        self.EditorViewport = builder.get_object('editor_viewport')
        self.EditorViewport.connect_after("draw", self.draw_gradient)

        self.smooth_scroll_starttime = 0
        self.smooth_scroll_endtime = 0
        self.smooth_scroll_acttarget = 0
        self.smooth_scroll_data = {
            'target_pos': -1,
            'source_pos': -1,
            'duration': 0
        }
        self.smooth_scroll_tickid = -1

        self.PreviewPane = builder.get_object('preview_scrolledwindow')

        self.TextEditor.set_margin_top(38)
        self.TextEditor.set_margin_bottom(16)

        self.TextEditor.set_pixels_above_lines(4)
        self.TextEditor.set_pixels_below_lines(4)
        self.TextEditor.set_pixels_inside_wrap(8)

        tab_array = Pango.TabArray.new(1, True)
        tab_array.set_tab(0, Pango.TabAlign.LEFT, 20)
        self.TextEditor.set_tabs(tab_array)

        self.TextBuffer = self.TextEditor.get_buffer()
        self.TextBuffer.set_text('')

        # Init Window height for top/bottom padding
        self.window_height = self.get_size()[1]

        self.text_change_event = self.TextBuffer.connect(
            'changed', self.text_changed)

        # Init file name with None
        self.filename = None

        self.generate_recent_files_menu(self.builder.get_object('recent'))

        self.style_provider = Gtk.CssProvider()
        self.style_provider.load_from_path(helpers.get_media_path('style.css'))

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), self.style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

        # Markup and Shortcuts for the TextBuffer
        self.MarkupBuffer = MarkupBuffer(self, self.TextBuffer,
                                         base_leftmargin)
        self.MarkupBuffer.markup_buffer()

        # Scrolling -> Dark or not?
        self.textchange = False
        self.scroll_count = 0
        self.timestamp_last_mouse_motion = 0
        self.TextBuffer.connect_after('mark-set', self.mark_set)

        # Drag and drop

        # self.TextEditor.drag_dest_unset()
        # self.TextEditor.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY)
        self.target_list = Gtk.TargetList.new([])
        self.target_list.add_uri_targets(1)
        self.target_list.add_text_targets(2)

        self.TextEditor.drag_dest_set_target_list(self.target_list)
        self.TextEditor.connect_after('drag-data-received',
                                      self.on_drag_data_received)

        def on_drop(widget, *args):
            print("drop")

        self.TextEditor.connect('drag-drop', on_drop)

        self.TextBuffer.connect('paste-done', self.paste_done)
        # self.connect('key-press-event', self.alt_mod)

        # Events for Typewriter mode

        # Setting up inline preview
        self.InlinePreview = UberwriterInlinePreview(self.TextEditor,
                                                     self.TextBuffer)

        # Vertical scrolling
        self.vadjustment = self.ScrolledWindow.get_vadjustment()
        self.vadjustment.connect('value-changed', self.scrolled)

        self.spellcheck_button = builder.get_object("disable_spellcheck")
        # Setting up spellcheck
        self.auto_correct = None
        try:
            self.SpellChecker = SpellChecker(self.TextEditor,
                                             locale.getdefaultlocale()[0],
                                             collapse=False)
            if self.auto_correct:
                self.auto_correct.set_language(self.SpellChecker.language)
                self.SpellChecker.connect_language_change(
                    self.auto_correct.set_language)

            self.spellcheck = True
        except:
            self.SpellChecker = None
            self.spellcheck = False
            builder.get_object("disable_spellcheck").set_active(False)

        if self.spellcheck:
            self.SpellChecker.append_filter('[#*]+', SpellChecker.FILTER_WORD)

        self.did_change = False

        ###
        #   Sidebar initialization test
        ###
        self.paned_window = builder.get_object("main_pained")
        self.sidebar_box = builder.get_object("sidebar_box")
        self.sidebar = UberwriterSidebar(self)
        self.sidebar_box.hide()

        ###
        #   Search and replace initialization
        #   Same interface as Sidebar ;)
        ###
        self.searchreplace = UberwriterSearchAndReplace(self)

        # Window resize
        self.window_resize(self)
        self.connect("configure-event", self.window_resize)
        self.connect("delete-event", self.on_delete_called)

        self.gtk_settings = Gtk.Settings.get_default()
        self.load_settings(builder)

        self.plugins = [BibTex(self)]
    def __init__(self, app):
        """Set up the main window"""

        Gtk.ApplicationWindow.__init__(
            self,
            application=Gio.Application.get_default(),
            title="Uberwriter")

        self.builder = get_builder('UberwriterWindow')
        self.add(self.builder.get_object("FullscreenOverlay"))

        self.set_default_size(850, 500)

        # preferences
        self.settings = Settings.new()

        self.set_name('UberwriterWindow')

        # Headerbars
        self.headerbar = headerbars.MainHeaderbar(app)
        self.set_titlebar(self.headerbar.hb_container)
        self.fs_headerbar = headerbars.FsHeaderbar(self.builder, app)

        self.title_end = "  –  UberWriter"
        self.set_headerbar_title("New File" + self.title_end)

        self.focusmode = False

        self.word_count = self.builder.get_object('word_count')
        self.char_count = self.builder.get_object('char_count')

        # Setup status bar hide after 3 seconds

        self.status_bar = self.builder.get_object('status_bar_box')
        self.statusbar_revealer = self.builder.get_object(
            'status_bar_revealer')
        self.status_bar.get_style_context().add_class('status_bar_box')
        self.status_bar_visible = True
        self.was_motion = True
        self.buffer_modified_for_status_bar = False
        self.connect("motion-notify-event", self.on_motion_notify)
        GObject.timeout_add(3000, self.poll_for_motion)

        self.accel_group = Gtk.AccelGroup()
        self.add_accel_group(self.accel_group)

        # Setup light background
        self.text_editor = TextEditor()
        self.text_editor.set_name('UberwriterEditor')
        self.get_style_context().add_class('uberwriter_window')

        base_leftmargin = 100
        self.text_editor.set_left_margin(base_leftmargin)
        self.text_editor.set_left_margin(40)
        self.text_editor.set_top_margin(80)
        self.text_editor.props.width_request = 600
        self.text_editor.props.halign = Gtk.Align.CENTER
        self.text_editor.set_vadjustment(
            self.builder.get_object('vadjustment1'))
        self.text_editor.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
        self.text_editor.connect('focus-out-event', self.focus_out)
        self.text_editor.get_style_context().connect('changed',
                                                     self.style_changed)

        self.text_editor.set_top_margin(80)
        self.text_editor.set_bottom_margin(16)

        self.text_editor.set_pixels_above_lines(4)
        self.text_editor.set_pixels_below_lines(4)
        self.text_editor.set_pixels_inside_wrap(8)

        tab_array = Pango.TabArray.new(1, True)
        tab_array.set_tab(0, Pango.TabAlign.LEFT, 20)
        self.text_editor.set_tabs(tab_array)

        self.text_editor.show()
        self.text_editor.grab_focus()

        self.editor_alignment = self.builder.get_object('editor_alignment')
        self.scrolled_window = self.builder.get_object('editor_scrolledwindow')
        self.scrolled_window.props.width_request = 600
        self.scrolled_window.add(self.text_editor)
        self.alignment_padding = 40
        self.editor_viewport = self.builder.get_object('editor_viewport')
        self.scrolled_window.connect_after("draw", self.draw_gradient)

        self.smooth_scroll_starttime = 0
        self.smooth_scroll_endtime = 0
        self.smooth_scroll_acttarget = 0
        self.smooth_scroll_data = {
            'target_pos': -1,
            'source_pos': -1,
            'duration': 0
        }
        self.smooth_scroll_tickid = -1

        self.text_buffer = self.text_editor.get_buffer()
        self.text_buffer.set_text('')

        # Init Window height for top/bottom padding
        self.window_height = self.get_size()[1]

        self.text_change_event = self.text_buffer.connect(
            'changed', self.text_changed)

        # Init file name with None
        self.set_filename()

        self.style_provider = Gtk.CssProvider()
        self.style_provider.load_from_path(helpers.get_media_path('style.css'))

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), self.style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

        # Markup and Shortcuts for the TextBuffer
        self.markup_buffer = MarkupBuffer(self, self.text_buffer,
                                          base_leftmargin)
        self.markup_buffer.markup_buffer()

        # Setup dark mode if so
        self.toggle_dark_mode(self.settings.get_value("dark-mode"))

        # Scrolling -> Dark or not?
        self.textchange = False
        self.scroll_count = 0
        self.timestamp_last_mouse_motion = 0
        self.text_buffer.connect_after('mark-set', self.mark_set)

        # Drag and drop

        # self.TextEditor.drag_dest_unset()
        # self.TextEditor.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY)
        self.target_list = Gtk.TargetList.new([])
        self.target_list.add_uri_targets(1)
        self.target_list.add_text_targets(2)

        self.text_editor.drag_dest_set_target_list(self.target_list)
        self.text_editor.connect_after('drag-data-received',
                                       self.on_drag_data_received)

        def on_drop(_widget, *_args):
            print("drop")

        self.text_editor.connect('drag-drop', on_drop)

        self.text_buffer.connect('paste-done', self.paste_done)
        # self.connect('key-press-event', self.alt_mod)

        # Events for Typewriter mode

        # Setting up inline preview
        self.inline_preview = UberwriterInlinePreview(self.text_editor,
                                                      self.text_buffer)

        # Vertical scrolling
        self.vadjustment = self.scrolled_window.get_vadjustment()
        self.vadjustment.connect('value-changed', self.scrolled)

        # Setting up spellcheck
        self.auto_correct = None
        try:
            self.spell_checker = SpellChecker(self.text_editor,
                                              locale.getdefaultlocale()[0],
                                              collapse=False)
            if self.auto_correct:
                self.auto_correct.set_language(self.spell_checker.language)
                self.spell_checker.connect_language_change(  #pylint: disable=no-member
                    self.auto_correct.set_language)

            self.spellcheck = True
        except:
            self.spell_checker = None
            self.spellcheck = False

        if self.spellcheck:
            self.spell_checker.append_filter('[#*]+', SpellChecker.FILTER_WORD)

        self.did_change = False

        ###
        #   Sidebar initialization test
        ###
        self.paned_window = self.builder.get_object("main_pained")
        self.sidebar_box = self.builder.get_object("sidebar_box")
        self.sidebar = UberwriterSidebar(self)
        self.sidebar_box.hide()

        ###
        #   Search and replace initialization
        #   Same interface as Sidebar ;)
        ###
        self.searchreplace = UberwriterSearchAndReplace(self)

        # Window resize
        self.window_resize(self)
        self.connect("configure-event", self.window_resize)
        self.connect("delete-event", self.on_delete_called)