def __init__(self, source_view): self.checker = Gspell.Checker() self.spell_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer( source_view.get_buffer()) self.spell_buffer.set_spell_checker(self.checker) self.spell_view = Gspell.TextView.get_from_gtk_text_view(source_view) self.spell_view.set_enable_language_menu(False) self.spell_navigator = Gspell.NavigatorTextView.new(source_view)
def __init__(self, language): """Initialize a :class:`SpellChecker` instance.""" glanguage = Gspell.language_lookup(language) if glanguage is None: raise aeidon.Error('Language "{}" not supported'.format(language)) self.checker = Gspell.Checker(language=glanguage) self.language = language self.replacements = [] self.read_replacements()
def __init__(self): GtkSource.View.__init__(self) self.set_buffer(DraftSourceBuffer()) self._spell_checker = Gspell.Checker() buffer = self.get_buffer() gspell_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer(buffer) gspell_buffer.set_spell_checker(self._spell_checker) gspell_view = Gspell.TextView.get_from_gtk_text_view(self) gspell_view.set_inline_spell_checking(True) # TODO: Disabling this for now. These elements should not be created # for every SourceView. Make DraftEditor own them. # builder = Gtk.Builder() # builder.add_from_resource('/org/gnome/Draft/editor.ui') # self._link_editor = builder.get_object('link_editor') # self._url_entry = builder.get_object('url_entry') # self._title_entry = builder.get_object('title_entry') # self._img_editor = builder.get_object('img_editor') # self._img_url_entry = builder.get_object('img_url_entry') # self._img_title_entry = builder.get_object('img_title_entry') # self._browse_images_button = builder.get_object('browse_images_button') # self._hint_window = builder.get_object('hint_window') # self._link_editor.set_relative_to(self) # self._img_editor.set_relative_to(self) # screen = self._hint_window.get_screen() # visual = screen.get_rgba_visual() # if visual is not None and screen.is_composited(): # self._hint_window.set_visual(visual) # self._hint_window.set_app_paintable(True) self.connect('event', self._on_event) self.connect('key-press-event', self._on_key_press) self.connect('button-press-event', self._on_button_press) self.connect('focus-in-event', self._on_focus_in) self.connect('focus-out-event', self._on_focus_out) # self._link_editor.connect('closed', self._on_link_editor_closed) # self._img_editor.connect('closed', self._on_link_editor_closed) # self._browse_images_button.connect('clicked', self._on_browse_images) # self._hint_window.connect('draw', self._on_hint_window_draw) self.cached_char_height = 0 self.cached_char_width = 0 self.set_has_tooltip(True) # visual margins and offsets self.set_visible(True) self.set_pixels_above_lines(3) self.set_pixels_below_lines(3) self.set_pixels_inside_wrap(6) self.set_wrap_mode(Gtk.WrapMode.WORD) self.set_left_margin(DEFAULT_LEFT_MARGIN) self.set_right_margin(DEFAULT_RIGHT_MARGIN) self.set_top_margin(self._calculated_top_margin) self.set_bottom_margin(self._calculated_bottom_margin) # formatting specific options self.set_auto_indent(True) self.set_indent_on_tab(True) self.set_insert_spaces_instead_of_tabs(True) self.set_indent_width(2) self.set_smart_backspace(True) self.set_highlight_current_line(True) # Variables for scroll animation setup self._tick_id = 0 self._source = 0.0 self._target = 0.0 self._start_time = None self._end_time = None
def __init__(self, storage: Storage, settings: Settings): super().__init__() self.document = None self.storage = storage self.settings = settings self.buffer = GtkSource.Buffer() self.manager = GtkSource.LanguageManager() self.language = self.manager.get_language("markdown") self.buffer.set_language(self.language) self.buffer.create_tag('match', background="#66ff00") self.view = GtkSource.View() self.view.set_buffer(self.buffer) self.view.set_wrap_mode(Gtk.WrapMode.WORD) self.view.set_auto_indent(True) self.view.set_smart_home_end(True) self.view.set_insert_spaces_instead_of_tabs(True) self.view.set_tab_width(4) self.view.props.width_request = 920 self.view.set_halign(Gtk.Align.CENTER) self.view.set_pixels_above_lines(2) self.view.set_pixels_below_lines(2) self.view.set_pixels_inside_wrap(4) self.view.set_top_margin(8) self.view.set_left_margin(8) self.view.set_right_margin(8) self.view.set_bottom_margin(8) # self.view.set_monospace(True) self.view.get_style_context().add_class('norka-editor') self.view.connect('key-release-event', self.on_key_release_event) self.view.connect('move-cursor', self.on_view_move_cursor) # Connect markup handler self.markup_formatter = MarkupFormatter(self.buffer) self.get_style_context().add_class('norka-editor-view') self.connect('insert-bold', self.on_insert_bold) self.connect('insert-italic', self.on_insert_italic) self.connect('insert-code', self.on_insert_code) self.connect('insert-code-block', self.on_insert_code_block) self.connect('insert-h1', self.on_toggle_header1) self.connect('insert-h2', self.on_toggle_header2) self.connect('insert-h3', self.on_toggle_header3) self.connect('insert-list', self.on_toggle_list) self.connect('insert-ordered-list', self.on_toggle_ordered_list) self.connect('insert-quote', self.on_toggle_quote) self.connect('insert-link', self.on_insert_link) self.connect('insert-image', self.on_insert_image) self.scrolled = Gtk.ScrolledWindow(hexpand=True, vexpand=True) self.scrolled.get_style_context().add_class('scrolled-editor') self.scrolled.add(self.view) # SearchBar self.search_bar = SearchBar() self.search_revealer = Gtk.Revealer() self.search_revealer.add(self.search_bar) self.search_bar.connect('find-changed', self.do_next_match) self.search_bar.connect('find-next', self.do_next_match) self.search_bar.connect('find-prev', self.do_previous_match) self.search_bar.connect('stop-search', self.do_stop_search) content_grid = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) content_grid.pack_start(self.search_revealer, False, True, 0) content_grid.pack_start(self.scrolled, True, True, 0) content_grid.show_all() self.overlay = Gtk.Overlay() self.overlay.add(content_grid) self.stats_overlay = Granite.WidgetsOverlayBar.new(self.overlay) # Initialize stats calculations and connect `destroy` event self.stats_handler = StatsHandler(buffer=self.buffer) self.stats_overlay.connect('destroy', lambda x: self.stats_handler.on_destroy(self)) self.stats_handler.connect('update-document-stats', self.update_stats) self.stats = self.stats_handler.stats self.add(self.overlay) # SpellChecker self.font_desc = Pango.FontDescription() self.spellchecker = Gspell.Checker() self.spell_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer(self.view.get_buffer()) self.spell_buffer.set_spell_checker(self.spellchecker) spell_language = Gspell.Language.lookup(self.settings.get_string('spellcheck-language')) if spell_language: self.spellchecker.set_language(spell_language) self.spell_view = Gspell.TextView.get_from_gtk_text_view(self.view) self.spell_view.set_enable_language_menu(False) self.search_settings = GtkSource.SearchSettings(wrap_around=True) self.search_context = GtkSource.SearchContext(buffer=self.buffer, settings=self.search_settings) self.search_iter = None