def __init__(self, window, content, editor, text_view): self.text_view = text_view self.web_view = None self.web_view_pending_html = None builder = get_builder("Preview") preview = builder.get_object("preview") mode_button = builder.get_object("preview_mode_button") self.mode_revealer = builder.get_object("preview_mode_revealer") self.preview_converter = PreviewConverter() self.preview_renderer = PreviewRenderer( window, content, editor, text_view, preview, self.mode_revealer, mode_button) window.connect("style-updated", self.reload) self.text_changed_handler_id = None self.settings = Settings.new() self.web_scroll_handler_id = None self.text_scroll_handler_id = None self.loading = False self.shown = False
def __init__(self, window, content, editor, text_view): self.text_view = text_view self.web_view = None self.web_view_pending_html = None builder = get_builder("Preview") preview = builder.get_object("preview") mode_button = builder.get_object("preview_mode_button") self.mode_revealer = builder.get_object("preview_mode_revealer") self.preview_converter = PreviewConverter() self.preview_renderer = PreviewRenderer(window, content, editor, text_view, preview, self.mode_revealer, mode_button) window.connect("style-updated", self.reload) self.text_changed_handler_id = None self.settings = Settings.new() self.web_scroll_handler_id = None self.text_scroll_handler_id = None self.loading = False self.shown = False
def __init__(self, text_view): self.text_view = text_view self.text_view.connect("button-press-event", self.on_button_press_event) self.text_buffer = text_view.get_buffer() self.cursor_mark = self.text_buffer.create_mark( "click", self.text_buffer.get_iter_at_mark(self.text_buffer.get_insert())) self.latex_converter = latex_to_PNG.LatexToPNG() self.characters_per_line = Settings.new().get_int( "characters-per-line") self.popover = Gtk.Popover.new(self.text_view) self.popover.get_style_context().add_class("quick-preview-popup") self.popover.set_modal(True) self.preview_fns = { markup_regex.MATH: self.get_view_for_math, markup_regex.IMAGE: self.get_view_for_image, markup_regex.LINK: self.get_view_for_link, markup_regex.LINK_ALT: self.get_view_for_link, markup_regex.FOOTNOTE_ID: self.get_view_for_footnote, re.compile(r"(?P<text>\w+)"): self.get_view_for_lexikon }
class Theme: """ The Theme enum lists all supported themes using their "gtk-theme-name" value. The light variant is listed first, followed by the dark variant, if any. """ settings = Settings.new() def __init__(self, name, gtk_css_path, web_css_path, is_dark, inverse_name): self.name = name self.gtk_css_path = gtk_css_path self.web_css_path = web_css_path self.is_dark = is_dark self.inverse_name = inverse_name @classmethod def get_for_name(cls, name, default=None): current_theme = default or defaultThemes[0] for theme in defaultThemes: if name == theme.name: current_theme = theme return current_theme @classmethod def get_current(cls): theme_name = Gtk.Settings.get_default().get_property('gtk-theme-name') dark_mode = cls.settings.get_value('dark-mode').get_boolean() current_theme = cls.get_for_name(theme_name) # Technically, we could very easily allow the user to force the light ui on a dark theme. # However, as there is no inverse of "gtk-application-prefer-dark-theme", we shouldn't do that. if dark_mode and not current_theme.is_dark and current_theme.inverse_name: current_theme = cls.get_for_name(current_theme.inverse_name, current_theme.name) return current_theme
def __init__(self, *args, **kwargs): super().__init__(*args, application_id="de.wolfvollprecht.UberWriter", flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE, **kwargs) self.window = None self.settings = Settings.new()
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)
def __init__(self, text_view): self.text_view = text_view self.text_buffer = text_view.get_buffer() self.latex_converter = latex_to_PNG.LatexToPNG() cursor_mark = self.text_buffer.get_insert() cursor_iter = self.text_buffer.get_iter_at_mark(cursor_mark) self.click_mark = self.text_buffer.create_mark('click', cursor_iter) # Events for popup menu # self.TextView.connect_after('populate-popup', self.populate_popup) # self.TextView.connect_after('popup-menu', self.move_popup) self.text_view.connect('button-press-event', self.click_move_button) self.popover = None self.settings = Settings.new()
class Theme: """ The Theme enum lists all supported themes using their "gtk-theme-name" value. The light variant is listed first, followed by the dark variant, if any. """ previous = None settings = Settings.new() def __init__(self, name, web_css_path, is_dark, inverse_name): self.name = name self.web_css_path = web_css_path self.is_dark = is_dark self.inverse_name = inverse_name @classmethod def get_for_name(cls, name, default=None): current_theme = default or defaultThemes[0] for theme in defaultThemes: if name == theme.name: current_theme = theme return current_theme @classmethod def get_current_changed(cls): theme_name = Gtk.Settings.get_default().get_property('gtk-theme-name') dark_mode_auto = cls.settings.get_value('dark-mode-auto').get_boolean() dark_mode = cls.settings.get_value('dark-mode').get_boolean() current_theme = cls.get_for_name(theme_name) if not dark_mode_auto and dark_mode != current_theme.is_dark and current_theme.inverse_name: current_theme = cls.get_for_name(current_theme.inverse_name, current_theme.name) changed = current_theme != cls.previous cls.previous = current_theme return current_theme, changed @classmethod def get_current(cls): current_theme, _ = cls.get_current_changed() return current_theme def __eq__(self, other): return isinstance(other, self.__class__) and \ self.name == other.name and \ self.web_css_path == other.web_css_path and \ self.is_dark == other.is_dark and \ self.inverse_name == other.inverse_name
def __init__( self, main_window, content, editor, text_view, preview, mode_revealer, mode_button): self.main_window = main_window self.main_window.connect("delete-event", self.on_window_closed) self.content = content self.editor = editor self.text_view = text_view self.preview = preview self.mode_revealer = mode_revealer self.mode_button = mode_button self.mode_button.connect("clicked", self.show_mode_popover) self.settings = Settings.new() self.popover = None self.window = None self.headerbar = None self.mode = self.settings.get_enum("preview-mode") self.update_mode()
def __init__(self, main_window, content, editor, text_view, preview, mode_revealer, mode_button): self.main_window = main_window self.main_window.connect("delete-event", self.on_window_closed) self.content = content self.editor = editor self.text_view = text_view self.preview = preview self.mode_revealer = mode_revealer self.mode_button = mode_button self.mode_button.connect("clicked", self.show_mode_popover) self.settings = Settings.new() self.popover = None self.window = None self.headerbar = None self.mode = self.settings.get_enum("preview-mode") self.update_mode()
def __init__(self, stats_button, text_view): super().__init__() self.stats_button = stats_button self.stats_button.connect("clicked", self.on_stats_button_clicked) self.stats_button.connect("destroy", self.on_destroy) self.text_view = text_view self.text_view.get_buffer().connect("changed", self.on_text_changed) self.popover = None self.characters = 0 self.words = 0 self.sentences = 0 self.paragraphs = 0 self.read_time = (0, 0, 0) self.settings = Settings.new() self.stats_counter = StatsCounter() self.update_default_stat()
def __init__(self, stats_button, text_view): super().__init__() self.stats_button = stats_button self.stats_button.connect("clicked", self.on_stats_button_clicked) self.stats_button.connect("destroy", self.on_destroy) self.text_view = text_view self.text_view.get_buffer().connect("changed", self.on_text_changed) self.popover = None self.characters = 0 self.words = 0 self.sentences = 0 self.paragraphs = 0 self.read_time = (0, 0, 0) self.settings = Settings.new() self.stats_counter = StatsCounter(self.update_stats) self.update_default_stat()
def __init__(self, app): """Set up the main window""" Gtk.ApplicationWindow.__init__( self, application=Gio.Application.get_default(), title="Uberwriter") # Set UI self.builder = get_builder('Window') root = self.builder.get_object("FullscreenOverlay") root.connect('style-updated', self.apply_current_theme) self.add(root) self.set_default_size(900, 500) # Preferences self.settings = Settings.new() # Headerbars self.headerbar = headerbars.MainHeaderbar(app) self.set_titlebar(self.headerbar.hb_container) self.fs_headerbar = headerbars.FullscreenHeaderbar(self.builder, app) self.title_end = " – UberWriter" self.set_headerbar_title("New File" + self.title_end) self.timestamp_last_mouse_motion = 0 if self.settings.get_value("poll-motion"): 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 text editor self.text_view = TextView() self.text_view.props.halign = Gtk.Align.CENTER self.text_view.connect('focus-out-event', self.focus_out) self.text_view.get_buffer().connect('changed', self.on_text_changed) self.text_view.show() self.text_view.grab_focus() # Setup preview webview self.preview_webview = None self.scrolled_window = self.builder.get_object('editor_scrolledwindow') self.scrolled_window.get_style_context().add_class( 'uberwriter-scrolled-window') self.scrolled_window.add(self.text_view) self.editor_viewport = self.builder.get_object('editor_viewport') # Stats counter self.stats_counter_revealer = self.builder.get_object( 'stats_counter_revealer') self.stats_button = self.builder.get_object('stats_counter') self.stats_button.get_style_context().add_class('stats-counter') self.stats_handler = StatsHandler(self.stats_button, self.text_view) # Setup header/stats bar hide after 3 seconds self.top_bottom_bars_visible = True self.was_motion = True self.buffer_modified_for_status_bar = False # some people seems to have performance problems with the overlay. # Let them disable it self.overlay_id = None self.toggle_gradient_overlay( self.settings.get_value("gradient-overlay")) # Init file name with None self.set_filename() # Setting up spellcheck self.auto_correct = None self.toggle_spellcheck(self.settings.get_value("spellcheck")) 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 = Sidebar(self) self.sidebar_box.hide() ### # Search and replace initialization # Same interface as Sidebar ;) ### self.searchreplace = SearchAndReplace(self, self.text_view) # Window resize self.window_resize(self) self.connect("configure-event", self.window_resize) self.connect("delete-event", self.on_delete_called) # Set current theme self.apply_current_theme() self.get_style_context().add_class('uberwriter-window')
def __init__(self, app): """Set up the main window""" super().__init__(application=Gio.Application.get_default(), title="Uberwriter") self.get_style_context().add_class('uberwriter-window') # Set UI builder = get_builder('Window') root = builder.get_object("FullscreenOverlay") self.connect("delete-event", self.on_delete_called) self.add(root) self.set_default_size(1000, 600) # Preferences self.settings = Settings.new() # Headerbars self.headerbar = headerbars.MainHeaderbar(app) self.set_titlebar(self.headerbar.hb_container) self.fs_headerbar = headerbars.FullscreenHeaderbar(builder, app) self.title_end = " – UberWriter" self.set_headerbar_title("New File" + self.title_end) self.timestamp_last_mouse_motion = 0 if self.settings.get_value("poll-motion"): 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) self.scrolled_window = builder.get_object('editor_scrolledwindow') # Setup text editor self.text_view = TextView(self.settings.get_int("characters-per-line")) self.text_view.connect('focus-out-event', self.focus_out) self.text_view.get_buffer().connect('changed', self.on_text_changed) self.text_view.show() self.text_view.grab_focus() self.scrolled_window.add(self.text_view) # Setup stats counter self.stats_revealer = builder.get_object('editor_stats_revealer') self.stats_button = builder.get_object('editor_stats_button') self.stats_handler = StatsHandler(self.stats_button, self.text_view) # Setup preview content = builder.get_object('content') editor = builder.get_object('editor') self.preview_handler = PreviewHandler(self, content, editor, self.text_view) # Setup header/stats bar hide after 3 seconds self.top_bottom_bars_visible = True self.was_motion = True self.buffer_modified_for_status_bar = False # some people seems to have performance problems with the overlay. # Let them disable it self.overlay_id = None self.toggle_gradient_overlay(self.settings.get_value("gradient-overlay")) # Init file name with None self.set_filename() # Setting up spellcheck self.auto_correct = None self.toggle_spellcheck(self.settings.get_value("spellcheck")) self.did_change = False ### # Sidebar initialization test ### self.paned_window = builder.get_object("main_paned") self.sidebar_box = builder.get_object("sidebar_box") self.sidebar = Sidebar(self) self.sidebar_box.hide() ### # Search and replace initialization # Same interface as Sidebar ;) ### self.searchreplace = SearchAndReplace(self, self.text_view, builder)
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 if self.settings.get_value("poll-motion"): 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 text editor 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() # Setup preview webview self.preview_webview = None 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') # 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.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() # Markup and Shortcuts for the TextBuffer self.markup_buffer = MarkupBuffer( self, self.text_buffer, base_leftmargin) self.markup_buffer.markup_buffer() # Set current theme self.apply_current_theme() # 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 = InlinePreview( 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 self.toggle_spellcheck(self.settings.get_value("spellcheck")) 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 = Sidebar(self) self.sidebar_box.hide() ### # Search and replace initialization # Same interface as Sidebar ;) ### self.searchreplace = SearchAndReplace(self) # Window resize self.window_resize(self) self.connect("configure-event", self.window_resize) self.connect("delete-event", self.on_delete_called)
def __init__(self, app): """Set up the main window""" super().__init__(application=Gio.Application.get_default(), title="Uberwriter") self.get_style_context().add_class('uberwriter-window') # Set UI builder = Gtk.Builder() builder.add_from_resource("/de/wolfvollprecht/UberWriter/ui/Window.ui") root = builder.get_object("FullscreenOverlay") self.connect("delete-event", self.on_delete_called) self.add(root) self.set_default_size(1000, 600) # Preferences self.settings = Settings.new() # Headerbars self.headerbar = headerbars.MainHeaderbar(app) self.set_titlebar(self.headerbar.hb_container) self.fs_headerbar = headerbars.FullscreenHeaderbar(builder, app) self.title_end = " – UberWriter" self.set_headerbar_title("New File" + self.title_end) self.timestamp_last_mouse_motion = 0 if self.settings.get_value("poll-motion"): 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) self.scrolled_window = builder.get_object('editor_scrolledwindow') # Setup text editor self.text_view = TextView(self.settings.get_int("characters-per-line")) self.text_view.connect('focus-out-event', self.focus_out) self.text_view.get_buffer().connect('changed', self.on_text_changed) self.text_view.show() self.text_view.grab_focus() self.scrolled_window.add(self.text_view) # Setup stats counter self.stats_revealer = builder.get_object('editor_stats_revealer') self.stats_button = builder.get_object('editor_stats_button') self.stats_handler = StatsHandler(self.stats_button, self.text_view) # Setup preview content = builder.get_object('content') editor = builder.get_object('editor') self.preview_handler = PreviewHandler(self, content, editor, self.text_view) # Setup header/stats bar hide after 3 seconds self.top_bottom_bars_visible = True self.was_motion = True self.buffer_modified_for_status_bar = False # some people seems to have performance problems with the overlay. # Let them disable it self.overlay_id = None self.toggle_gradient_overlay( self.settings.get_value("gradient-overlay")) # Init file name with None self.set_filename() # Setting up spellcheck self.auto_correct = None self.toggle_spellcheck(self.settings.get_value("spellcheck")) self.did_change = False ### # Sidebar initialization test ### self.paned_window = builder.get_object("main_paned") self.sidebar_box = builder.get_object("sidebar_box") self.sidebar = Sidebar(self) self.sidebar_box.hide() ### # Search and replace initialization # Same interface as Sidebar ;) ### self.searchreplace = SearchAndReplace(self, self.text_view, builder)