Esempio n. 1
0
    def __init__(self, document, document_view):
        self.document = document
        self.document_view = document_view
        self.main_window = ServiceLocator.get_main_window()
        self.font_manager = ServiceLocator.get_font_manager()
        self.font_manager.register_observer(self)

        self.view = view.DocumentAutocompleteView()
        self.mark_start = Gtk.TextMark.new('ac_session_start', True)
        self.mark_end = Gtk.TextMark.new('ac_session_end', False)
        self.matching_mark_start = Gtk.TextMark.new('ac_session_second_start', True)
        self.matching_mark_end = Gtk.TextMark.new('ac_session_second_end', False)

        self.provider = ServiceLocator.get_autocomplete_provider()

        self.blank_session = session_blank.SessionBlank(self, self.document)
        self.session = self.blank_session

        self.shortcuts_bar_height = 37
        self.cursor_offset = None

        char_width, line_height = self.font_manager.get_char_dimensions(self.document_view.source_view)
        self.view.scrolled_window.set_max_content_height(5 * line_height)
        self.view.scrolled_window.set_min_content_width(35 * char_width)

        self.focus_hide = False

        self.items = list()

        self.view.list.connect('row-activated', self.on_row_activated)
        self.view.list.connect('row-selected', self.on_row_selected)

        self.document.register_observer(self)
Esempio n. 2
0
    def __init__(self, document, document_view):
        self.document = document
        self.view = document_view
        self.settings = ServiceLocator.get_settings()
        self.font_manager = ServiceLocator.get_font_manager()

        self.indentation_update = None

        self.view.source_view.set_show_line_numbers(False)
        self.view.source_view.set_insert_spaces_instead_of_tabs(
            self.settings.get_value('preferences', 'spaces_instead_of_tabs'))
        self.view.source_view.set_tab_width(
            self.settings.get_value('preferences', 'tab_width'))
        self.view.source_view.set_highlight_current_line(
            self.settings.get_value('preferences', 'highlight_current_line'))
        self.document.content.source_buffer.set_highlight_matching_brackets(
            self.settings.get_value('preferences',
                                    'highlight_matching_brackets'))
        if self.settings.get_value('preferences', 'enable_line_wrapping'):
            self.view.source_view.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
        else:
            self.view.source_view.set_wrap_mode(Gtk.WrapMode.NONE)
        self.view.source_view.set_left_margin(
            self.font_manager.get_char_width() - 1)

        self.settings.connect('settings_changed', self.on_settings_changed)
        self.font_manager.connect('font_string_changed',
                                  self.on_font_string_changed)
Esempio n. 3
0
    def __init__(self, document):
        GtkSource.Buffer.__init__(self)

        self.document = document
        self.view = GtkSource.View.new_with_buffer(self)
        self.view.set_monospace(True)
        self.view.set_smart_home_end(True)
        self.view.set_auto_indent(True)
        self.settings = ServiceLocator.get_settings()
        self.source_language_manager = ServiceLocator.get_source_language_manager(
        )
        self.source_style_scheme_manager = ServiceLocator.get_source_style_scheme_manager(
        )
        self.font_manager = ServiceLocator.get_font_manager()
        self.font_manager.register_observer(self)

        self.mover_mark = self.create_mark('mover', self.get_start_iter(),
                                           True)

        # set source language for syntax highlighting
        self.source_language = self.source_language_manager.get_language(
            self.document.get_gsv_language_name())
        self.set_language(self.source_language)
        self.update_syntax_scheme()

        self.search_settings = GtkSource.SearchSettings()
        self.search_context = GtkSource.SearchContext.new(
            self, self.search_settings)
        self.search_context.set_highlight(True)

        self.insert_position = 0

        self.synctex_tag_count = 0
        self.synctex_highlight_tags = dict()

        self.indentation_update = None
        self.indentation_tags = dict()
        self.tab_width = self.settings.get_value('preferences', 'tab_width')
        self.settings.register_observer(self)

        self.placeholder_tag = self.create_tag('placeholder')
        self.placeholder_tag.set_property('background', '#fce94f')
        self.placeholder_tag.set_property('foreground', '#000')

        self.connect('mark-set', self.on_mark_set)
        self.connect('mark-deleted', self.on_mark_deleted)
        self.connect('insert-text', self.on_insert_text)
        self.connect('delete-range', self.on_delete_range)
        self.connect('end-user-action', self.on_end_user_action)
        self.connect('changed', self.on_buffer_changed)
        self.connect('modified-changed', self.on_modified_changed)

        self.document.add_change_code('buffer_ready')

        self.view.set_left_margin(
            self.font_manager.get_char_width(self.view) - 3)
Esempio n. 4
0
    def __init__(self, model):
        Gtk.VBox.__init__(self)
        self.get_style_context().add_class('autocomplete')

        self.main_window = ServiceLocator.get_main_window()
        self.model = model
        self.content = self.model.document.content

        self.set_halign(Gtk.Align.START)
        self.set_valign(Gtk.Align.START)

        self.shortcutsbar_height = 37
        self.x_position, self.y_position = (None, None)

        self.list = Gtk.ListBox()
        self.list.set_selection_mode(Gtk.SelectionMode.SINGLE)
        self.list.set_can_focus(False)
        self.items = list()
        self.selected_index = 0

        self.scrolled_window = Gtk.ScrolledWindow()
        self.scrolled_window.set_propagate_natural_height(True)
        self.scrolled_window.add(self.list)

        self.infobox = Gtk.Label('')
        self.infobox.set_xalign(0)
        self.infobox.set_ellipsize(Pango.EllipsizeMode.END)
        self.infobox.set_max_width_chars(30)
        self.infobox.get_style_context().add_class('infobox')

        self.pack_start(self.scrolled_window, True, True, 0)
        self.pack_start(self.infobox, False, False, 0)
        self.list.show_all()
        self.infobox.show_all()

        self.font_manager = ServiceLocator.get_font_manager()
        self.font_manager.connect('font_string_changed',
                                  self.on_font_string_changed)

        self.focus_hide = False

        self.line_height, self.char_width, self.full_height = (None, None,
                                                               None)
        self.update_sizes()

        self.model.document_view.scrolled_window.get_vadjustment().connect(
            'value-changed', self.on_adjustment_value_changed)
        self.model.document_view.scrolled_window.get_hadjustment().connect(
            'value-changed', self.on_adjustment_value_changed)
        self.model.document_view.source_view.connect('focus-out-event',
                                                     self.on_focus_out)
        self.model.document_view.source_view.connect('focus-in-event',
                                                     self.on_focus_in)
        self.list.connect('row-selected', self.on_row_selected)
Esempio n. 5
0
    def __init__(self, document, document_view):
        self.document = document
        self.document_view = document_view

        self.scbar_view = context_menu_view.ContextMenuView(document)
        stack = document_view.shortcutsbar_bottom.more_actions_popover.get_child(
        )
        stack.add_named(self.scbar_view, 'main')

        self.scbar_view.model_button_undo.connect('clicked', self.on_undo)
        self.scbar_view.model_button_redo.connect('clicked', self.on_redo)
        self.scbar_view.model_button_cut.connect('clicked', self.on_cut)
        self.scbar_view.model_button_copy.connect('clicked', self.on_copy)
        self.scbar_view.model_button_paste.connect('clicked', self.on_paste)
        self.scbar_view.model_button_delete.connect('clicked', self.on_delete)
        self.scbar_view.model_button_select_all.connect(
            'clicked', self.on_select_all)
        self.scbar_view.model_button_zoom_out.connect('button-press-event',
                                                      self.on_zoom_out)
        self.scbar_view.model_button_zoom_in.connect('button-press-event',
                                                     self.on_zoom_in)
        self.scbar_view.model_button_reset_zoom.connect(
            'button-press-event', self.on_reset_zoom)

        if self.document.is_latex_document():
            self.scbar_view.model_button_toggle_comment.connect(
                'clicked', self.on_toggle_comment)
            self.scbar_view.model_button_show_in_preview.connect(
                'clicked', self.on_show_in_preview)

        self.document_view.source_view.connect('populate-popup',
                                               self.on_populate_popup)
        self.document.content.connect('selection_might_have_changed',
                                      self.on_has_selection_changed)
        self.document.content.connect('can_undo_changed',
                                      self.on_can_undo_changed)
        self.document.content.connect('can_redo_changed',
                                      self.on_can_redo_changed)

        self.scbar_view.model_button_undo.set_sensitive(
            self.document.content.get_can_undo())
        self.scbar_view.model_button_redo.set_sensitive(
            self.document.content.get_can_redo())

        self.can_sync = False
        self.has_selection = False
        self.workspace = ServiceLocator.get_workspace()
        if self.document.is_latex_document():
            self.workspace.connect('update_sync_state',
                                   self.on_update_sync_state)

        self.font_manager = ServiceLocator.get_font_manager()
        self.font_manager.connect('font_string_changed',
                                  self.on_font_string_changed)
Esempio n. 6
0
 def get_indentation_tag(self, number_of_characters):
     try:
         tag = self.indentation_tags[number_of_characters]
     except KeyError:
         tag = self.source_buffer.create_tag('indentation-' +
                                             str(number_of_characters))
         font_manager = ServiceLocator.get_font_manager()
         tag.set_property(
             'indent',
             -1 * number_of_characters * font_manager.get_char_width(' '))
         self.indentation_tags[number_of_characters] = tag
     return tag
Esempio n. 7
0
    def __init__(self, document, document_view):
        self.document = document
        self.source_view = document_view.source_view
        self.adjustment = document_view.scrolled_window.get_vadjustment()

        self.widgets = list()
        self.total_size = 0
        self.lines = list()
        self.current_line = 0

        self.font_manager = ServiceLocator.get_font_manager()
        self.font_manager.connect('font_string_changed',
                                  self.on_font_string_changed)

        self.view = Gtk.DrawingArea()
        self.view.set_valign(Gtk.Align.FILL)
        self.view.set_halign(Gtk.Align.START)
        self.view.connect('draw', self.on_draw)
        self.view.show_all()

        def on_realize(widget):
            widget.get_window().set_pass_through(True)

        self.view.connect('realize', on_realize)
        self.style_context = self.view.get_style_context()
        self.color_manager = ServiceLocator.get_color_manager()
        self.bg_color = None
        self.fg_color = None
        self.cl_color = None
        self.border_color = None
        self.update_colors()
        self.source_view.get_style_context().connect('changed',
                                                     self.update_colors)

        document_view.overlay.add_overlay(self.view)
        document_view.overlay.set_overlay_pass_through(self.view, True)

        self.char_width, self.line_height = self.font_manager.get_char_dimensions(
        )

        self.source_view.connect('button-press-event', self.on_click)
        self.source_view.connect('enter-notify-event',
                                 self.on_pointer_movement)
        self.source_view.connect('leave-notify-event',
                                 self.on_pointer_movement)
        self.source_view.connect('motion-notify-event',
                                 self.on_pointer_movement)

        self.highlight_current_line = False
        settings = ServiceLocator.get_settings()
        self.set_line_highlighting(
            settings.get_value('preferences', 'highlight_current_line'))
        settings.connect('settings_changed', self.on_settings_changed)
Esempio n. 8
0
    def __init__(self, document, document_view):
        self.document = document
        self.document_view = document_view
        self.scbar_view = context_menu_view.ContextMenuView(document)
        stack = document_view.shortcuts_bar_bottom.more_actions_popover.get_child()
        stack.add_named(self.scbar_view, 'main')
        self.controller = context_menu_controller.ContextMenuController(self, self.scbar_view)
        self.presenter = context_menu_presenter.ContextMenuPresenter(self, self.scbar_view)

        self.font_manager = ServiceLocator.get_font_manager()
        self.font_manager.register_observer(self)

        document.register_observer(self)
Esempio n. 9
0
    def __init__(self, model, view):
        self.model = model
        self.view = view
        self.source_buffer = self.model.document.source_buffer
        self.source_gutter = self.model.document.view.source_view.get_gutter(
            Gtk.TextWindowType.LEFT)
        self.tag = self.source_buffer.create_tag('invisible_region',
                                                 invisible=1)

        self.lines_skip_query_data = dict()

        self.source_gutter.insert(self.view, 3)
        self.view.connect('query-data', self.query_data)
        self.model.register_observer(self)

        font_manager = ServiceLocator.get_font_manager()
        font_manager.register_observer(self)
        line_height = font_manager.get_line_height(self.source_buffer.view)
        self.view.set_size(line_height)
Esempio n. 10
0
    def get_screen_offsets_by_iter(self, text_iter):
        font_manager = ServiceLocator.get_font_manager()
        line_height = font_manager.get_line_height()
        iter_location = self.source_view.get_iter_location(text_iter)
        gutter = self.source_view.get_window(Gtk.TextWindowType.LEFT)

        if gutter != None:
            gutter_width = gutter.get_width()
        else:
            gutter_width = 0

        x_offset = -self.document.view.scrolled_window.get_hadjustment(
        ).get_value()
        y_offset = -self.document.view.scrolled_window.get_vadjustment(
        ).get_value()
        x_position = x_offset + iter_location.x - 2 + gutter_width
        y_position = y_offset + iter_location.y + line_height

        return x_position, y_position
Esempio n. 11
0
 def scroll_cursor_onscreen(self):
     text_iter = self.source_buffer.get_iter_at_mark(
         self.source_buffer.get_insert())
     visible_lines = self.get_number_of_visible_lines()
     iter_position = self.source_view.get_iter_location(text_iter).y
     end_yrange = self.source_view.get_line_yrange(
         self.source_buffer.get_end_iter())
     buffer_height = end_yrange.y + end_yrange.height
     font_manager = ServiceLocator.get_font_manager()
     line_height = font_manager.get_line_height()
     window_offset = self.source_view.get_visible_rect().y
     window_height = self.source_view.get_visible_rect().height
     gap = min(math.floor(max((visible_lines - 2), 0) / 2), 5)
     if iter_position < window_offset + gap * line_height:
         self.scroll_view(max(iter_position - gap * line_height, 0))
         return
     gap = min(math.floor(max((visible_lines - 2), 0) / 2), 8)
     if iter_position > (window_offset + window_height -
                         (gap + 1) * line_height):
         self.scroll_view(
             min(iter_position + gap * line_height - window_height,
                 buffer_height))
Esempio n. 12
0
    def __init__(self):
        Observable.__init__(self)

        self.font_manager = ServiceLocator.get_font_manager()

        self.displayname = ''
        self.filename = None
        self.save_date = None
        self.deleted_on_disk_dialog_shown_after_last_save = False
        self.last_activated = 0
        self.dark_mode = False
        self.is_root = False
        self.root_is_set = False

        self.symbols = dict()
        self.symbols['bibitems'] = set()
        self.symbols['labels'] = set()
        self.symbols['labels_with_offset'] = list()
        self.symbols['included_latex_files'] = set()
        self.symbols['bibliographies'] = set()
        self.symbols['packages'] = set()
        self.symbols['packages_detailed'] = dict()
        self.symbols['blocks'] = list()
Esempio n. 13
0
 def on_reset_zoom(self, widget=None, event=None):
     ServiceLocator.get_font_manager().reset_zoom()
Esempio n. 14
0
 def on_zoom_in(self, widget=None, event=None):
     ServiceLocator.get_font_manager().zoom_in()
Esempio n. 15
0
    def __init__(self, workspace):
        self.workspace = workspace
        main_window = ServiceLocator.get_main_window()
        settings = ServiceLocator.get_settings()

        self.new_latex_document_action = Gio.SimpleAction.new('new-latex-document', None)
        self.new_bibtex_document_action = Gio.SimpleAction.new('new-bibtex-document', None)
        self.open_document_dialog_action = Gio.SimpleAction.new('open-document-dialog', None)
        self.build_action = Gio.SimpleAction.new('build', None)
        self.save_and_build_action = Gio.SimpleAction.new('save-and-build', None)
        self.save_action = Gio.SimpleAction.new('save', None)
        self.save_as_action = Gio.SimpleAction.new('save-as', None)
        self.save_all_action = Gio.SimpleAction.new('save-all', None)
        self.save_session_action = Gio.SimpleAction.new('save-session', None)
        self.restore_session_action = Gio.SimpleAction.new('restore-session', GLib.VariantType('as'))
        self.find_action = Gio.SimpleAction.new('find', None)
        self.find_next_action = Gio.SimpleAction.new('find-next', None)
        self.find_prev_action = Gio.SimpleAction.new('find-prev', None)
        self.find_replace_action = Gio.SimpleAction.new('find-replace', None)
        self.close_all_action = Gio.SimpleAction.new('close-all-documents', None)
        self.close_document_action = Gio.SimpleAction.new('close-active-document', None)
        self.insert_before_after_action = Gio.SimpleAction.new('insert-before-after', GLib.VariantType('as'))
        self.insert_symbol_action = Gio.SimpleAction.new('insert-symbol', GLib.VariantType('as'))
        self.insert_before_document_end_action = Gio.SimpleAction.new('insert-before-document-end', GLib.VariantType('as'))
        self.document_wizard_action = Gio.SimpleAction.new('show-document-wizard', None)
        self.create_new_bibtex_entry_action = Gio.SimpleAction.new('create-new-bibtex-entry', None)
        self.show_previous_bibtex_entries_action = Gio.SimpleAction.new('show-previous-bibtex-entries', None)
        self.search_online_for_bibtex_entries_action = Gio.SimpleAction.new('search-online-for-bibtex-entries', None)
        self.include_bibtex_file_action = Gio.SimpleAction.new('include-bibtex-file', None)
        self.include_latex_file_action = Gio.SimpleAction.new('include-latex-file', None)
        self.add_remove_packages_dialog_action = Gio.SimpleAction.new('add-remove-packages-dialog', None)
        self.add_packages_action = Gio.SimpleAction.new('add-packages', GLib.VariantType('as'))
        self.comment_uncomment_action = Gio.SimpleAction.new('comment-uncomment', None)
        self.shortcuts_window_action = Gio.SimpleAction.new('show-shortcuts-window', None)
        self.show_preferences_action = Gio.SimpleAction.new('show-preferences-dialog', None)
        self.show_about_action = Gio.SimpleAction.new('show-about-dialog', None)
        self.quit_action = Gio.SimpleAction.new('quit', None)
        self.close_build_log_action = Gio.SimpleAction.new('close-build-log', None)
        sc_default = GLib.Variant.new_boolean(settings.get_value('preferences', 'inline_spellchecking'))
        self.toggle_spellchecking_action = Gio.SimpleAction.new_stateful('toggle-spellchecking', None, sc_default)
        self.set_spellchecking_language_action = Gio.SimpleAction.new('set-spellchecking-language', None)
        self.spellchecking_action = Gio.SimpleAction.new('spellchecking', None)
        dm_default = GLib.Variant.new_boolean(settings.get_value('preferences', 'prefer_dark_mode'))
        self.toggle_dark_mode_action = Gio.SimpleAction.new_stateful('toggle-dark-mode', None, dm_default)
        settings.gtksettings.get_default().set_property('gtk-application-prefer-dark-theme', dm_default)
        ip_default = GLib.Variant.new_boolean(settings.get_value('preferences', 'invert_pdf'))
        self.toggle_invert_pdf_action = Gio.SimpleAction.new_stateful('toggle-invert-pdf', None, ip_default)
        self.zoom_out_action = Gio.SimpleAction.new('zoom-out', None)
        self.zoom_in_action = Gio.SimpleAction.new('zoom-in', None)
        self.reset_zoom_action = Gio.SimpleAction.new('reset-zoom', None)

        main_window.add_action(self.new_latex_document_action)
        main_window.add_action(self.new_bibtex_document_action)
        main_window.add_action(self.open_document_dialog_action)
        main_window.add_action(self.build_action)
        main_window.add_action(self.save_and_build_action)
        main_window.add_action(self.save_action)
        main_window.add_action(self.save_as_action)
        main_window.add_action(self.save_all_action)
        main_window.add_action(self.save_session_action)
        main_window.add_action(self.restore_session_action)
        main_window.add_action(self.find_action)
        main_window.add_action(self.find_next_action)
        main_window.add_action(self.find_prev_action)
        main_window.add_action(self.find_replace_action)
        main_window.add_action(self.close_all_action)
        main_window.add_action(self.close_document_action)
        main_window.add_action(self.insert_before_after_action)
        main_window.add_action(self.insert_symbol_action)
        main_window.add_action(self.insert_before_document_end_action)
        main_window.add_action(self.document_wizard_action)
        main_window.add_action(self.create_new_bibtex_entry_action)
        main_window.add_action(self.show_previous_bibtex_entries_action)
        main_window.add_action(self.search_online_for_bibtex_entries_action)
        main_window.add_action(self.include_bibtex_file_action)
        main_window.add_action(self.include_latex_file_action)
        main_window.add_action(self.add_remove_packages_dialog_action)
        main_window.add_action(self.add_packages_action)
        main_window.add_action(self.comment_uncomment_action)
        main_window.add_action(self.shortcuts_window_action)
        main_window.add_action(self.show_preferences_action)
        main_window.add_action(self.show_about_action)
        main_window.add_action(self.quit_action)
        main_window.add_action(self.close_build_log_action)
        main_window.add_action(self.toggle_spellchecking_action)
        main_window.add_action(self.set_spellchecking_language_action)
        main_window.add_action(self.spellchecking_action)
        main_window.add_action(self.toggle_dark_mode_action)
        main_window.add_action(self.toggle_invert_pdf_action)
        main_window.add_action(self.zoom_out_action)
        main_window.add_action(self.zoom_in_action)
        main_window.add_action(self.reset_zoom_action)

        self.new_latex_document_action.connect('activate', self.on_new_latex_document_action_activated)
        self.new_bibtex_document_action.connect('activate', self.on_new_bibtex_document_action_activated)
        self.open_document_dialog_action.connect('activate', self.on_open_document_dialog_action_activated)
        self.build_action.connect('activate', self.on_build_action_activated)
        self.save_and_build_action.connect('activate', self.on_save_and_build_action_activated)
        self.save_action.connect('activate', self.on_save_button_click)
        self.save_as_action.connect('activate', self.on_save_as_clicked)
        self.save_all_action.connect('activate', self.on_save_all_clicked)
        self.save_session_action.connect('activate', self.on_save_session_clicked)
        self.restore_session_action.connect('activate', self.on_restore_session_clicked)
        self.find_action.connect('activate', self.on_menu_find_clicked)
        self.find_next_action.connect('activate', self.find_next)
        self.find_prev_action.connect('activate', self.find_prev)
        self.find_replace_action.connect('activate', self.on_menu_find_replace_clicked)
        self.close_all_action.connect('activate', self.on_close_all_clicked)
        self.close_document_action.connect('activate', self.on_close_document_clicked)
        self.insert_before_after_action.connect('activate', self.insert_before_after)
        self.insert_symbol_action.connect('activate', self.insert_symbol)
        self.insert_before_document_end_action.connect('activate', self.insert_before_document_end)
        self.document_wizard_action.connect('activate', self.start_wizard)
        self.include_bibtex_file_action.connect('activate', self.start_include_bibtex_file_dialog)
        self.include_latex_file_action.connect('activate', self.start_include_latex_file_dialog)
        self.add_remove_packages_dialog_action.connect('activate', self.start_add_remove_packages_dialog)
        self.add_packages_action.connect('activate', self.add_packages)
        self.comment_uncomment_action.connect('activate', self.comment_uncomment)
        self.create_new_bibtex_entry_action.connect('activate', self.start_create_new_bibtex_entry_dialog)
        self.show_previous_bibtex_entries_action.connect('activate', self.start_show_previous_bibtex_entries_dialog)
        self.search_online_for_bibtex_entries_action.connect('activate', self.start_search_online_for_bibtex_entries_dialog)
        self.shortcuts_window_action.connect('activate', self.show_shortcuts_window)
        self.show_preferences_action.connect('activate', self.show_preferences_dialog)
        self.show_about_action.connect('activate', self.show_about_dialog)
        self.close_build_log_action.connect('activate', self.close_build_log)
        self.toggle_spellchecking_action.connect('activate', self.on_spellchecking_toggle_toggled)
        self.set_spellchecking_language_action.connect('activate', self.start_spellchecking_language_dialog)
        self.spellchecking_action.connect('activate', self.start_spellchecking_dialog)
        self.toggle_dark_mode_action.connect('activate', self.on_dark_mode_toggle_toggled)
        self.toggle_invert_pdf_action.connect('activate', self.on_invert_pdf_toggle_toggled)
        self.zoom_out_action.connect('activate', self.on_zoom_out)
        self.zoom_in_action.connect('activate', self.on_zoom_in)
        self.reset_zoom_action.connect('activate', self.on_reset_zoom)

        self.font_manager = ServiceLocator.get_font_manager()
        self.update_zoom_actions()
        self.workspace.register_observer(self)
        self.font_manager.register_observer(self)
Esempio n. 16
0
 def on_zoom_out(self, widget=None, event=None):
     ServiceLocator.get_font_manager().zoom_out()
     return True
Esempio n. 17
0
 def get_number_of_visible_lines(self):
     font_manager = ServiceLocator.get_font_manager()
     line_height = font_manager.get_line_height()
     return math.floor(self.source_view.get_visible_rect().height /
                       line_height)
Esempio n. 18
0
    def __init__(self):
        Gtk.VBox.__init__(self)

        self.set_margin_start(18)
        self.set_margin_end(18)
        self.set_margin_top(18)
        self.set_margin_bottom(18)
        self.get_style_context().add_class('preferences-page')

        label = Gtk.Label()
        label.set_markup('<b>' + _('Font') + '</b>')
        label.set_xalign(0)
        label.set_margin_bottom(6)
        self.pack_start(label, False, False, 0)

        font_manager = ServiceLocator.get_font_manager()
        font_string = font_manager.get_system_font()
        self.option_use_system_font = Gtk.CheckButton(
            _('Use the system fixed width font (' + font_string + ')'))
        self.option_use_system_font.set_margin_bottom(18)
        self.pack_start(self.option_use_system_font, False, False, 0)

        self.font_chooser_revealer = Gtk.Revealer()
        vbox = Gtk.VBox()
        label = Gtk.Label()
        label.set_markup(_('Set Editor Font:'))
        label.set_xalign(0)
        label.set_margin_bottom(6)
        vbox.pack_start(label, False, False, 0)

        self.font_chooser_button = Gtk.FontButton()
        self.font_chooser_button.set_margin_bottom(18)
        hbox = Gtk.HBox()
        hbox.pack_start(self.font_chooser_button, False, False, 0)
        vbox.pack_start(hbox, False, False, 0)
        self.font_chooser_revealer.add(vbox)
        self.pack_start(self.font_chooser_revealer, False, False, 0)

        label = Gtk.Label()
        label.set_markup('<b>' + _('Colors') + '</b>')
        label.set_xalign(0)
        label.set_margin_bottom(6)
        self.pack_start(label, False, False, 0)

        self.option_dark_mode = Gtk.CheckButton(_('Dark Mode'))
        self.pack_start(self.option_dark_mode, False, False, 0)
        self.option_invert_preview = Gtk.CheckButton(
            _('Invert Colors in .pdf-Preview'))
        self.pack_start(self.option_invert_preview, False, False, 0)

        label = Gtk.Label()
        label.set_markup(_('Editor Color Scheme:'))
        label.set_xalign(0)
        label.set_margin_top(18)
        label.set_margin_bottom(6)
        self.pack_start(label, False, False, 0)

        self.style_switcher = Gtk.ComboBoxText()
        self.style_switcher_dark_mode = Gtk.ComboBoxText()

        self.style_switcher_stack = Gtk.Stack()
        self.style_switcher_stack.add_named(self.style_switcher, 'light')
        self.style_switcher_stack.add_named(self.style_switcher_dark_mode,
                                            'dark')
        box = Gtk.HBox()
        box.set_margin_bottom(18)
        box.pack_start(self.style_switcher_stack, False, False, 0)
        self.pack_start(box, False, False, 0)

        box = Gtk.HBox()
        box.set_margin_bottom(18)
        self.remove_scheme_button = Gtk.Button()
        self.remove_scheme_button.set_label('Remove active scheme')
        box.pack_end(self.remove_scheme_button, False, False, 0)
        self.add_scheme_button = Gtk.Button()
        self.add_scheme_button.set_label('Add from file...')
        box.pack_start(self.add_scheme_button, False, False, 0)
        self.pack_start(box, False, False, 0)

        label = Gtk.Label()
        label.set_markup('<b>' + _('Preview') + '</b>')
        label.set_xalign(0)
        label.set_margin_bottom(6)
        self.pack_start(label, False, False, 0)

        self.preview_wrapper = Gtk.VBox()
        self.preview_wrapper.get_style_context().add_class('preview')
        scrolled_window = Gtk.ScrolledWindow()
        scrolled_window.set_min_content_height(162)
        self.source_view = GtkSource.View()
        self.source_view.set_editable(False)
        self.source_view.set_cursor_visible(False)
        self.source_view.set_monospace(True)
        self.source_view.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
        self.source_view.set_show_line_numbers(False)
        self.source_view.set_highlight_current_line(False)
        scrolled_window.add(self.source_view)
        self.source_buffer = self.source_view.get_buffer()
        self.source_buffer.set_highlight_matching_brackets(False)
        self.source_buffer.set_text('''% Syntax highlighting preview
\\documentclass[letterpaper,11pt]{article}
\\usepackage{amsmath}
\\usepackage{amssymb}
\\begin{document}
\\section{Preview}
This is a \\textit{preview}, for $x, y \in \mathbb{R}: x \leq y$ or $x > y$.
\\end{document}''')
        self.source_buffer.place_cursor(self.source_buffer.get_start_iter())
        self.preview_wrapper.pack_start(scrolled_window, True, True, 0)
        self.pack_start(self.preview_wrapper, True, True, 0)