Пример #1
0
    def __init__(self, *args, **kwargs):
        self.label = Gtk.Label(label='Edit')
        """The :py:class:`Gtk.Label` representing this tabs name."""
        super(MailSenderEditTab, self).__init__(*args, **kwargs)
        self.textview = self.gobjects['view_html_file']
        """The :py:class:`Gtk.TextView` object of the editor."""
        self.textbuffer = GtkSource.Buffer()
        """The :py:class:`Gtk.TextBuffer` used by the :py:attr:textview` attribute."""
        self.textview.set_buffer(self.textbuffer)
        self.textview.modify_font(
            Pango.FontDescription(self.config['text_font']))
        self.language_manager = GtkSource.LanguageManager()
        self.textbuffer.set_language(
            self.language_manager.get_language('html'))
        self.textbuffer.set_highlight_syntax(True)
        self.toolbutton_save_html_file = self.gobjects[
            'toolbutton_save_html_file']
        self.textview.connect('populate-popup',
                              self.signal_textview_populate_popup)

        scheme_manager = GtkSource.StyleSchemeManager()
        style_scheme_name = self.config['text_source_theme']
        style_scheme = scheme_manager.get_scheme(style_scheme_name)
        if style_scheme:
            self.textbuffer.set_style_scheme(style_scheme)
        else:
            self.logger.error(
                "invalid GTK source theme: '{0}'".format(style_scheme_name))
        self.file_monitor = None
Пример #2
0
    def do_create_configure_widget(self):
        box = Gtk.Box()
        language_manager = GtkSource.LanguageManager()
        self.undecided = []
        for id in language_manager.get_language_ids():
            if id not in whitelist and id not in blacklist:
                self.undecided.append(id)

        self.whitelist_widget = ListWidget(whitelist, 'Always wrap',
                                           'whitelist.json')
        self.blacklist_widget = ListWidget(blacklist, 'Never wrap',
                                           'blacklist.json')
        self.undecided_widget = ListWidget(self.undecided)

        self.button_add_whitelist = Gtk.Button('<')
        self.button_remove_whitelist = Gtk.Button('>')
        self.button_add_blacklist = Gtk.Button('>')
        self.button_remove_blacklist = Gtk.Button('<')

        self.button_add_whitelist.connect('clicked', self.whitelist_add)
        self.button_remove_whitelist.connect('clicked', self.whitelist_remove)
        self.button_add_blacklist.connect('clicked', self.blacklist_add)
        self.button_remove_blacklist.connect('clicked', self.blacklist_remove)

        box.add(self.whitelist_widget)
        box.add(self.button_add_whitelist)
        box.add(self.button_remove_whitelist)
        box.add(self.undecided_widget)
        box.add(self.button_remove_blacklist)
        box.add(self.button_add_blacklist)
        box.add(self.blacklist_widget)

        box.set_size_request(500, 700)
        return box
Пример #3
0
    def __init__(self):
        Gtk.Plug.__init__(self)
        Gtk.Plug.construct(self, wid)

        lang_manager = GtkSource.LanguageManager()
        lang = lang_manager.guess_language(path)
        style_manager = GtkSource.StyleSchemeManager.get_default()
        style = style_manager.get_scheme("classic")

        f = open(path, "r", encoding=ENCODING, errors="replace")
        txt = f.read()
        f.close()

        self.srcbuf = GtkSource.Buffer()
        self.srcbuf.set_style_scheme(style)
        self.srcbuf.set_language(lang)
        self.srcbuf.set_text(txt)

        scroll = Gtk.ScrolledWindow()
        view = GtkSource.View.new_with_buffer(self.srcbuf)

        view.set_show_line_numbers(True)
        view.set_highlight_current_line(True)
        view.get_space_drawer().set_enable_matrix(True)
        view.set_editable(False)
        view.set_tab_width(8)
        #view.override_font(Pango.FontDescription('mono 12'))
        view.set_name("sourceview")

        cssprovider = Gtk.CssProvider()
        cssprovider.load_from_path(
            os.path.dirname(sys.argv[0]) + "/gtksourceview.css")
        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), cssprovider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
        scroll.add(view)

        hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        self.lbl_search = Gtk.Label()
        button = Gtk.Button.new_with_label("Set text")
        button.connect("pressed", self.search_dialog)
        self.btn_case = Gtk.ToggleButton.new_with_label("Case sensitive")
        self.btn_case.connect("pressed", self.search_case)
        self.btn_regex = Gtk.ToggleButton.new_with_label("RegEx")
        self.btn_regex.connect("pressed", self.search_regex)
        hbox.pack_start(self.btn_case, False, True, 2)
        hbox.pack_start(self.btn_regex, False, True, 2)
        hbox.pack_start(button, False, True, 2)
        hbox.pack_end(self.lbl_search, True, True, 1)
        hbox.set_border_width(5)

        win = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        win.pack_start(scroll, True, True, 1)
        win.pack_end(hbox, False, True, 1)

        self.sopts = GtkSource.SearchSettings()
        self.scontext = GtkSource.SearchContext(buffer=self.srcbuf,
                                                settings=self.sopts)

        self.add(win)
Пример #4
0
    def set_language(self, key):
        manager = GtkSource.LanguageManager()
        language = manager.get_language(key)

        self.start_undoable()
        self.get_buffer().set_language(language)
        self.stop_undoable()
Пример #5
0
    def __init__(self, db):

        self.builder = Gtk.Builder()
        GObject.type_register(GtkSource.View)
        self.builder.add_from_file(UI_FILE)
        self.builder.connect_signals(self)
        self.db = db

        language_manager = GtkSource.LanguageManager()
        self.source_view = self.builder.get_object('gtksourceview1')
        self.source_buffer = GtkSource.Buffer()
        self.source_view.set_buffer(self.source_buffer)
        self.source_buffer.set_language(language_manager.get_language('sql'))
        completion = self.source_view.get_completion()
        keyword_provider = GtkSource.CompletionWords.new('Keywords')
        keyword_provider.register(self.source_buffer)
        completion.add_provider(keyword_provider)

        self.window = self.builder.get_object('window1')
        self.window.show_all()

        self.populate_sql_commands()

        cursor = self.db.cursor()
        cursor.execute("SELECT command FROM sql.history WHERE current = True")
        command = cursor.fetchone()[0]
        self.source_buffer.set_text(command)
        cursor.close()
Пример #6
0
    def __init__(self, pathname):
        Observable.__init__(self)

        self.pathname = pathname
        self.kernelname = None
        self.cells = []
        self.active_cell = None
        self.busy_cells = set()
        self.modified_cells = set()
        self.kernel_state = None
        self.result_factory = ServiceLocator.get_result_factory()

        self.save_state = 'saved'
        try: self.last_saved = datetime.datetime.fromtimestamp(os.path.getmtime(pathname))
        except FileNotFoundError:
            self.last_saved = datetime.datetime.fromtimestamp(0)
        
        # set source language for syntax highlighting
        self.source_language_manager = GtkSource.LanguageManager()
        self.source_language_manager.set_search_path((os.path.dirname(__file__) + '/../resources/gtksourceview/language-specs',))
        self.source_language_code = self.source_language_manager.get_language('sage')
        self.source_language_markdown = self.source_language_manager.get_language('markdown')
        
        self.source_style_scheme_manager = GtkSource.StyleSchemeManager()
        self.source_style_scheme_manager.set_search_path((os.path.dirname(__file__) + '/../resources/gtksourceview/styles',))
        self.source_style_scheme = self.source_style_scheme_manager.get_scheme('sage')

        self.cursor_position = {'cell': None, 'cell_position': None, 'cell_size': None, 'position': None}

        self.list_item = list_item_model.NotebookListItem(self)
        self.view = notebook_viewgtk.NotebookView()
        self.presenter = notebook_presenter.NotebookPresenter(self, self.view)
        self.controller = notebook_controller.NotebookController(self, self.view)
        self.evaluator = notebook_evaluator.NotebookEvaluator(self)
        self.headerbar_controls = headerbar_controls.HeaderbarControls(self)
Пример #7
0
    def openfile(path):
        for of in app.openfiles:
            if of[0] != None:
                if path in of[0]:
                    return
        with open(path, "r") as loadedfile:
            buffer = GtkSource.Buffer()
            buffer.set_text(loadedfile.read())
            buffer.set_modified(False)
            # syntax highlighting
            lman = GtkSource.LanguageManager()
            lan = lman.guess_language(path)
            swindow = Handler.create_tab(path, buffer)
            if lan:
                buffer.set_highlight_syntax(True)
                buffer.set_language(lan)
                if lan.get_name() == 'Python':
                    swindow.get_children()[0].connect(
                        "show-completion", Handler.onShowCompletion,
                        swindow.get_children()[0])
            else:
                buffer.set_highlight_syntax(False)
            buffer.set_highlight_matching_brackets(True)

            app.openfiles.append([path, buffer, swindow])
Пример #8
0
    def __init__(self):
        super().__init__()

        self.document = None

        self.buffer = GtkSource.Buffer()
        self.manager = GtkSource.LanguageManager()
        self.buffer.set_language(self.manager.get_language("markdown"))

        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.set_pixels_above_lines(4)
        self.view.set_pixels_below_lines(4)
        self.view.set_left_margin(8)
        self.view.set_right_margin(8)
        self.view.get_style_context().add_class('norka-editor')

        self.view.connect('key-release-event', self.on_key_release_event)

        self.font_desc = Pango.FontDescription()
        self.spellchecker = GtkSpell.Checker()

        self.add(self.view)
Пример #9
0
    def __init__(self, config):

        GtkSource.View.__init__(self)

        self.actualizador = False
        self.control = False
        self.archivo = False
        self.lenguaje = False
        self.tab = "    "

        self.set_show_line_numbers(config['numeracion'])

        self.lenguaje_manager = GtkSource.LanguageManager()

        self.lenguajes = {}
        for id in self.lenguaje_manager.get_language_ids():
            lang = self.lenguaje_manager.get_language(id)
            self.lenguajes[id] = lang.get_mime_types()

        self.set_insert_spaces_instead_of_tabs(True)
        self.set_tab_width(4)
        self.set_auto_indent(True)

        font = "%s %s" % (config['fuente'], config['tamanio'])
        self.modify_font(Pango.FontDescription(font))

        self.show_all()

        self.connect("key-press-event", self.__key_press_event)
Пример #10
0
	def __init__(self, *args, **kwargs):
		self.label = Gtk.Label(label='Edit')
		"""The :py:class:`Gtk.Label` representing this tabs name."""
		super(MailSenderEditTab, self).__init__(*args, **kwargs)
		self.textview = self.gobjects['view_html_file']
		"""The :py:class:`Gtk.TextView` object of the editor."""
		self.textbuffer = GtkSource.Buffer()
		"""The :py:class:`Gtk.TextBuffer` used by the :py:attr:textview` attribute."""
		self.textview.set_buffer(self.textbuffer)
		self.textview.modify_font(Pango.FontDescription(self.config['text_font']))
		self.language_manager = GtkSource.LanguageManager()
		self.textbuffer.set_language(self.language_manager.get_language('html'))
		self.textbuffer.set_highlight_syntax(True)
		self.toolbutton_save_html_file = self.gobjects['toolbutton_save_html_file']
		self.textview.connect('populate-popup', self.signal_textview_populate_popup)
		self.textview.connect('key-press-event', self.signal_textview_key_pressed)

		scheme_manager = GtkSource.StyleSchemeManager()
		style_scheme_name = self.config['text_source_theme']
		style_scheme = scheme_manager.get_scheme(style_scheme_name)
		if style_scheme:
			self.textbuffer.set_style_scheme(style_scheme)
		else:
			self.logger.error("invalid GTK source theme: '{0}'".format(style_scheme_name))
		self.file_monitor = None

		source_completion = self.textview.get_completion()
		source_completion.set_property('accelerators', 0)
		source_completion.set_property('auto-complete-delay', 250)
		source_completion.set_property('show-icons', False)
		source_completion.add_provider(completion_providers.HTMLComletionProvider())
		source_completion.add_provider(completion_providers.JinjaEmailCompletionProvider())
Пример #11
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.view.set_left_margin(6)
        self.settings = ServiceLocator.get_settings()

        resources_path = ServiceLocator.get_resources_path()

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

        # set source language for syntax highlighting
        self.source_language_manager = GtkSource.LanguageManager()
        self.source_language_manager.set_search_path(
            (os.path.join(resources_path, 'gtksourceview',
                          'language-specs'), ))
        self.source_language = self.source_language_manager.get_language(
            self.document.get_gsv_language_name())
        self.set_language(self.source_language)

        self.source_style_scheme_manager = GtkSource.StyleSchemeManager()
        self.source_style_scheme_manager.set_search_path(
            (os.path.join(resources_path, 'gtksourceview', 'styles'), ))
        self.source_style_scheme_light = self.source_style_scheme_manager.get_scheme(
            'setzer')
        self.source_style_scheme_dark = self.source_style_scheme_manager.get_scheme(
            'setzer-dark')

        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.view.connect('key-press-event', self.on_keypress)

        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.document.add_change_code('buffer_ready')
Пример #12
0
 def __init__(self):
     GtkSource.Buffer.__init__(self)
     self.language = None
     self.language_setted = False
     self.languages = [_('Plain text')]
     self.language_manager = GtkSource.LanguageManager()
     self.languages.extend(self.language_manager.get_language_ids())
Пример #13
0
    def __init__(self, worksheet):
        super(Editor, self).__init__()
        self.buffer = GtkSource.Buffer()
        self.worksheet = worksheet
        self._parsed = None

        sm = GtkSource.StyleSchemeManager()
        sm.append_search_path(paths.theme_dir)
        self.buffer.set_style_scheme(sm.get_scheme('monokai-extended'))

        lang_manager = GtkSource.LanguageManager()
        self.buffer.set_language(lang_manager.get_language('sql'))
        self.set_buffer(self.buffer)
        # TODO: Move to configuration
        font_desc = Pango.FontDescription.from_string('Ubuntu Mono 16')
        self.modify_font(font_desc)

        self.set_show_line_numbers(True)
        self.set_highlight_current_line(True)
        # attrs = GtkSource.MarkAttributes()
        # attrs.set_icon_name('document-new-symbolic')
        # self.set_mark_attributes('statement', attrs, 10)
        # self.set_show_line_marks(True)

        renderer = StatementGutter(self.buffer)
        gutter = self.get_gutter(Gtk.TextWindowType.LEFT)
        gutter.insert(renderer, 1)

        # Completions
        self._setup_completions()

        self.buffer.connect('changed', self.on_buffer_changed)
Пример #14
0
 def load_and_show_themes(self):
     # Set theme.
     self.themeManager = GtkSource.StyleSchemeManager()
     # Map from theme id to StyleScheme.
     self.themes = {
         tid: self.themeManager.get_scheme(tid)
         for tid in self.themeManager.get_scheme_ids()
     }
     # Holds the currently selected theme info.
     self.theme = None
     celltheme = Gtk.CellRendererText()
     self.comboTheme.pack_start(celltheme, True)
     self.comboTheme.add_attribute(celltheme, 'text', 0)
     self.bufferOutput = GtkSource.Buffer()
     self.langManager = GtkSource.LanguageManager()
     self.bufferLang = self.langManager.get_language('python3')
     self.bufferOutput.set_language(self.bufferLang)
     self.bufferOutput.set_highlight_syntax(True)
     self.bufferOutput.set_highlight_matching_brackets(True)
     if not self.set_theme_config():
         # Use first preferred theme if available.
         themeprefs = ('oblivion', 'tomorrownighteighties', 'twilight',
                       'kate')
         for themeid in themeprefs:
             theme = self.themes.get(themeid, None)
             if theme:
                 self.set_theme(theme)
                 break
     self.build_theme_list()
Пример #15
0
    def __init__(self, config):

        GtkSource.View.__init__(self)

        self.actualizador = False
        self.control = False
        self.archivo = False
        self.lenguaje = False
        self.tab = "    "

        self.lenguaje_manager = GtkSource.LanguageManager()

        self.set_show_line_numbers(config['numeracion'])
        self.set_insert_spaces_instead_of_tabs(True)
        self.set_tab_width(4)
        self.set_show_right_margin(True)
        self.set_auto_indent(True)
        self.set_smart_home_end(True)
        self.set_highlight_current_line(True)

        font = "%s %s" % (config['fuente'], config['tamanio'])
        self.modify_font(Pango.FontDescription(font))

        self.show_all()
        self.connect("key-press-event", self.__key_press_event)
Пример #16
0
    def add_text_view(self):
        scrolledWindow = self.add_scrolled_window()
        self.set_child_packing(self.frame, True, True, 0, gtk.PackType.START)

        buf = gtksource.Buffer()
        lang_manager = gtksource.LanguageManager()
        buf.set_highlight_matching_brackets(True)
        if self.node is not None and self.node.is_code():
            codelanguage = self.node.get_code_language()
            if codelanguage in lang_manager.get_language_ids():
                language = lang_manager.get_language(codelanguage)
            else:
                language = lang_manager.get_language("python")
            buf.set_language(language)
            buf.set_highlight_syntax(True)
        textview = gtksource.View.new_with_buffer(buf)
        textview.set_auto_indent(True)
        textview.set_insert_spaces_instead_of_tabs(True)
        textview.set_tab_width(2)
        if self.node is not None and self.node.is_code():
            textview.set_show_line_numbers(True)
            font_desc = pango.FontDescription("monospace")
            if font_desc:
                textview.modify_font(font_desc)

        textview.set_pixels_above_lines(2)
        textview.set_pixels_below_lines(2)
        textview.set_wrap_mode(gtk.WrapMode.WORD)
        textview.connect("focus-in-event", self.entry_focus_in)

        scrolledWindow.add(textview)
        textview.show()
        return textview
Пример #17
0
    def create_source_view(self):
        font_desc = Pango.FontDescription('monospace 11')

        if GtkSource:
            lang_mgr = GtkSource.LanguageManager()
            lang = lang_mgr.get_language('python')

            buffer = GtkSource.Buffer()
            buffer.set_language(lang)
            buffer.set_highlight_syntax(True)

            view = GtkSource.View()
            view.set_buffer(buffer)
            view.set_show_line_numbers(True)

            scrolled_window = self.create_scrolled_window()
            scrolled_window.add(view)

        else:
            scrolled_window, buffer = self.create_text_view()
            view = scrolled_window.get_child()

        view.modify_font(font_desc)
        view.set_wrap_mode(Gtk.WrapMode.NONE)
        return scrolled_window, buffer
Пример #18
0
    def render_prop(self, prop, value, callback, callback_data, sdfg):
        widget = None
        if prop.dtype == bool and value is not None:
            widget = Gtk.Switch()
            widget.set_active(value)
            widget.connect("state-set", callback, callback_data)
        elif isinstance(prop, dace.properties.CodeProperty):
            buf = GtkSource.Buffer()
            value = prop.to_string(value)
            widget = GtkSource.View.new_with_buffer(buf)
            lang_manager = GtkSource.LanguageManager()
            language = lang_manager.get_language("python")
            buf.set_language(language)
            buf.set_text(value)
            buf.set_highlight_syntax(True)
            buf.connect("changed", callback, callback_data)
        elif prop.enum is not None:
            widget = Gtk.ComboBoxText()

            if isinstance(prop, dace.properties.DataProperty):
                enum = prop.enum(sdfg)
            else:
                enum = prop.enum

            for i, option in enumerate(enum):
                widget.append_text(prop.to_string(option))
                if option == value:
                    widget.set_active(i)
            widget.connect("changed", callback, callback_data)
        else:
            widget = Gtk.Entry()
            widget.set_text(prop.to_string(value))
            widget.connect("changed", callback, callback_data)
        return widget
Пример #19
0
    def __init__(self, *a, **kw):
        GtkSource.View.__init__(self, *a, **kw)
        self.filename = None
        self.mark = None
        self.offset = 0
        self.program_length = 0
        self.idle_line_reset = True
        self.buf = self.get_buffer()
        self.buf.set_max_undo_levels(20)
        self.buf.connect('changed', self.update_iter)
        self.lm = GtkSource.LanguageManager()
        self.sm = GtkSource.StyleSchemeManager()
        if 'EMC2_HOME' in os.environ:
            path = os.path.join(os.environ['EMC2_HOME'],
                                'share/gtksourceview-2.0/language-specs/')
            self.lm.set_search_path(self.lm.get_search_path() + [path])

        self.buf.set_language(self.lm.get_language('.ngc'))
        self.set_show_line_numbers(True)
        self.set_show_line_marks(True)
        self.set_highlight_current_line(True)

        self.add_mark_category('error', '#ff7373')
        self.add_mark_category('motion', '#c5c5c5')
        self.add_mark_category('selected', '#96fef6')

        #TODO: how to set property background? but seems to work ok regardless.
        self.found_text_tag = Gtk.TextTag()

        self.connect('button-release-event', self.button_pressed)
Пример #20
0
    def _create_buffer(self, file_path=None):

        # 支持的语言
        # ada awk boo c c-sharp changelog chdr cpp css d def desktop diff
        # docbook dot dpatch dtd eiffel erlang forth fortran gap gettext-translation
        # gtk-doc gtkrc haddock haskell haskell-literate html idl ini java js latex
        # libtool lua m4 makefile msil nemerle objc objective-caml ocl octave pascal
        # perl php pkgconfig python r rpmspec ruby scheme sh sql tcl texinfo vala vbnet
        # verilog vhdl xml xslt yacc

        manager = GtkSource.LanguageManager()

        src_buffer = GtkSource.Buffer()

        # TODO:以后如果有算法,需要根据内容来判断文件的类型。
        if file_path is not None:
            language = manager.guess_language(file_path, None)  # 设定语法的类型
            src_buffer.set_language(language)
            src_buffer.set_highlight_syntax(True)  # 语法高亮

        #src_buffer.connect("changed", self.on_src_bufer_changed)
        # 可以利用 styleSchemeManager.get_scheme_ids() 得到所有的id
        # ['cobalt', 'kate', 'oblivion', 'solarized-dark', 'solarized-light', 'tango', 'classic']
        styleSchemeManager = GtkSource.StyleSchemeManager.get_default()
        styleScheme = styleSchemeManager.get_scheme("cobalt")
        if styleScheme is not None:
            self.styleScheme = styleScheme  # 不能丢弃
            src_buffer.set_style_scheme(self.styleScheme)

        return src_buffer
Пример #21
0
	def __init__(self,ebeveyn, title = "Talimat Editör"):
		Gtk.Window.__init__(self)
		self.ebeveyn = ebeveyn
		self.degistimi = False
		self.acilan_dosya = ""
		self.kaydirma = Gtk.ScrolledWindow()
		self.kaydirma.set_hexpand(True)
		self.kaydirma.set_vexpand(True)
		self.editor = GtkSource.View()
		self.editor.set_show_line_numbers(1)
		self.editor.set_indent_on_tab(1)
		self.editor.set_tab_width(4)
		self.editor.set_show_line_marks(1)
		self.kaydirma.add(self.editor)
		self.pack_start(self.kaydirma, expand = True, fill = True, padding = 5)
		self.textbuff = GtkSource.Buffer()
		self.textbuff.connect("changed",self.yazi_degisti)
		self.editor.set_buffer(self.textbuff)
		self.lm = GtkSource.LanguageManager()
		self.textbuff.set_language(self.lm.get_language('ini'))

		self.keywords = """
				GtkSourceView
				Completion
			"""
		self.set_auto_completation()
Пример #22
0
    def __init__(self, app):
        Gtk.Window.__init__(self, title="Source.View Example", application=app)
        self.set_border_width(10)
        self.set_default_size(450, 450)
        scrolled_window = Gtk.ScrolledWindow()
        scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC,
                                   Gtk.PolicyType.AUTOMATIC)
        sourceview = GtkSource.View.new()
        buf = sourceview.get_buffer()
        scrolled_window.add(sourceview)
        sourcefile = GtkSource.File()
        sourcefile.set_location(Gio.File.new_for_path(python_file))
        lang_manager = GtkSource.LanguageManager()
        buf.set_language(lang_manager.get_language("python3"))

        print("Using Scheme:", buf.get_style_scheme().get_id())
        prev_scheme = buf.get_style_scheme().get_id()

        ssm = GtkSource.StyleSchemeManager.new()
        # print(ssm.get_search_path())
        for path in ssm.get_search_path():
            print(path)
        print(ssm.get_scheme_ids())
        scheme = ssm.get_scheme(ssm.get_scheme_ids()[5])
        if not scheme:
            scheme = ssm.get_scheme(prev_scheme)
        buf.set_style_scheme(scheme)
        print("Now using Scheme:", buf.get_style_scheme().get_id())

        loader = GtkSource.FileLoader.new(buf, sourcefile)
        loader.load_async(0, None, None, None, None, None)
        wrap_mode = Gtk.WrapMode(2)
        # https://lazka.github.io/pgi-docs/#Gtk-3.0/enums.html#Gtk.WrapMode
        sourceview.set_wrap_mode(wrap_mode)
        self.add(scrolled_window)
Пример #23
0
 def __init__(self):
     super().__init__(application_id='mlv.knrf.pastebinReader')
     GLib.set_application_name('Pastebin Reader')
     GLib.set_prgname('mlv.knrf.pastebinReader')
     self.backend  = App_Backend()
     self.cat_name = "javascript"
     self.lang_mang = GtkSource.LanguageManager()
Пример #24
0
    def make_source(self):
        scheme = GtkSource.StyleSchemeManager()
        scheme.set_search_path()

        language = GtkSource.LanguageManager()

        buffer = GtkSource.Buffer()
        buffer.set_language(language.get_language('php'))
        buffer.set_style_scheme(scheme.get_scheme('tango'))
        buffer.set_highlight_syntax(True)

        font = Pango.FontDescription()
        font.set_family(
            'Droid Sans Mono, DejaVu Sans Mono, Ubuntu Mono, Monospace')
        font.set_absolute_size(11 * Pango.SCALE)

        self.source = GtkSource.View.new_with_buffer(buffer)
        self.source.override_font(font)
        self.source.set_show_line_numbers(True)
        self.source.set_insert_spaces_instead_of_tabs(False)
        self.source.set_auto_indent(True)
        self.source.set_tab_width(4)
        self.source.set_indent_width(4)
        self.source.set_smart_home_end(True)
        self.source.set_highlight_current_line(True)
Пример #25
0
    def __init__(self, app):
        Gtk.Window.__init__(self, title="Source.View Example", application=app)
        self.set_border_width(10)
        self.set_default_size(450, 450)

        bb = Gtk.ButtonBox()
        bb.set_orientation(Gtk.Orientation.HORIZONTAL)
        bb.set_spacing(2)

        swb = GtkSource.StyleSchemeChooserButton.new()

        bb.add(swb)
        bb.set_child_secondary(swb, True)
        box = Gtk.Box()
        box.set_orientation(Gtk.Orientation.VERTICAL)
        box.set_spacing(5)
        box.pack_start(bb, False, False, 0)

        scrolled_window = Gtk.ScrolledWindow()
        scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC,
                                   Gtk.PolicyType.AUTOMATIC)
        box.pack_start(scrolled_window, True, True, 0)

        sourceview = GtkSource.View.new()
        buf = sourceview.get_buffer()
        lm = GtkSource.LanguageManager()
        buf.set_language(lm.get_language("python3"))
        scrolled_window.add(sourceview)
        sourcefile = GtkSource.File()
        sourcefile.set_location(Gio.File.new_for_path(python_file))
        loader = GtkSource.FileLoader.new(buf, sourcefile)
        loader.load_async(0, None, None, None, None, None)
        wrap_mode = Gtk.WrapMode(2)
        sourceview.set_wrap_mode(wrap_mode)
        self.add(box)
Пример #26
0
 def __init__(self, main_app):
     """Create the source view window and init its properties"""
     self.main = main_app
     self.model = main_app.model
     self.clipboard = Gtk.Clipboard()
     control_viewport = self.main.builder.get_object('control_view')
     manager = GtkSource.LanguageManager()
     lang_python = manager.get_language('python')
     self.buffer = GtkSource.Buffer(language=lang_python)
     self.buffer.props.highlight_syntax = True
     self.control_view = GtkSource.View(buffer=self.buffer)
     self.buffer.place_cursor(self.buffer.get_start_iter())
     self.control_view.connect('button-press-event',
                               self.on_control_view_clicked)
     self.buffer.connect('changed', self.on_buffer_changed)
     self.buffer.connect('notify::can-undo',
                         lambda o, p: self.main.update_undo_redo_menuitem())
     self.buffer.connect('notify::can-redo',
                         lambda o, p: self.main.update_undo_redo_menuitem())
     self.tag_error = self.buffer.create_tag("error", background="red")
     debug_textview = self.main.builder.get_object('trace_textview')
     self.debug_buffer = LogBuffer(sys.stdout)
     sys.stdout = self.debug_buffer
     debug_textview.set_buffer(self.debug_buffer)
     self.control_view.show()
     #hide trace window by default
     #self.main.builder.get_object('hboxdebug').hide()
     control_viewport.add(self.control_view)
Пример #27
0
    def init_buffer(self):
        self.source_buffer = GtkSource.Buffer()

        resources_path = ServiceLocator.get_resources_path()

        # set source language for syntax highlighting
        self.source_language_manager = GtkSource.LanguageManager()
        self.source_language_manager.set_search_path(
            (os.path.join(resources_path, 'gtksourceview',
                          'language-specs'), ))
        self.source_language = self.source_language_manager.get_language(
            self.get_gsv_language_name())
        self.source_buffer.set_language(self.source_language)

        self.source_style_scheme_manager = GtkSource.StyleSchemeManager()
        self.source_style_scheme_manager.set_search_path(
            (os.path.join(resources_path, 'gtksourceview', 'styles'), ))
        self.source_style_scheme_light = self.source_style_scheme_manager.get_scheme(
            'setzer')
        self.source_style_scheme_dark = self.source_style_scheme_manager.get_scheme(
            'setzer-dark')

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

        self.source_buffer.connect('changed', self.on_buffer_changed)
        self.source_buffer.connect('insert-text', self.on_insert_text)

        self.add_change_code('buffer_ready')
Пример #28
0
    def __init__(self, core, textviews):
        super(ReprTextView, self).__init__(False, 1)

        #################################################################
        # Right Textview
        #################################################################

        self.uicore = core
        self.textviews = textviews

        # Use GtkSourceView to add eye candy :P
        # create buffer
        lm = GtkSource.LanguageManager()
        # Add ui dir to language paths
        paths = lm.get_search_path()
        paths.append(os.path.dirname(__file__) + os.sep + 'data' + os.sep)
        lm.set_search_path(paths)
        self.buffer = GtkSource.Buffer()
        self.buffer.create_tag("green-background",
                               background="green",
                               foreground="black")
        self.buffer.set_data('languages-manager', lm)
        self.view = GtkSource.View(self.buffer)

        # FIXME options must be user selectable (statusbar)
        self.view.set_editable(False)
        self.view.set_highlight_current_line(True)
        # posible values: Gtk.WrapMode.NONE, Gtk.WrapMode.CHAR, Gtk.WrapMode.WORD...
        self.view.set_wrap_mode(Gtk.WrapMode.WORD)

        # setup view
        font_desc = Pango.FontDescription('monospace 9')
        if font_desc:
            self.view.modify_font(font_desc)

        self.buffer.set_highlight_syntax(False)
        manager = self.buffer.get_data('languages-manager')
        language = manager.get_language('asm')
        self.buffer.set_language(language)

        self.mgr = GtkSource.StyleSchemeManager.get_default()

        # Scrolled Window
        self.repr_scrolled_window = Gtk.ScrolledWindow()
        self.repr_scrolled_window.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
        self.repr_scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC,
                                             Gtk.PolicyType.AUTOMATIC)
        self.repr_scrolled_window.show()
        # Add Textview to Scrolled Window
        self.repr_scrolled_window.add(self.view)
        self.pack_start(self.repr_scrolled_window, expand=True, fill=True)

        # Create the search widget
        Searchable.__init__(self, self.view, small=True)

        # Used for code navidation on _search function
        self.match_start = None
        self.match_end = None
        self.search_string = ''
Пример #29
0
    def __init__(self, main_window, codes):
        """
        This method is the constructor.
        """
        Gtk.Dialog.__init__(
            self, "Code Window", main_window,
            Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL,
            (Gtk.STOCK_OK, Gtk.ResponseType.OK))

        self.codes = codes
        self.main_window = main_window
        self.set_default_size(800, 600)
        box = self.get_content_area()
        vbox = Gtk.VBox()
        box.pack_start(vbox, True, True, 0)

        toolbar = Gtk.Toolbar()
        toolbar.set_style(Gtk.ToolbarStyle.BOTH)
        toolbar.set_hexpand(False)
        toolbar.set_property("expand", False)
        vbox.pack_start(toolbar, False, False, 0)

        button = Gtk.ToolButton.new_from_stock(Gtk.STOCK_SAVE_AS)
        button.set_expand(False)
        button.set_label(_("Save Source"))
        button.set_is_important(True)
        button.connect("clicked", self.__save_button_clicked, None)
        toolbar.add(button)

        button = Gtk.ToolButton.new_from_stock(Gtk.STOCK_EXECUTE)
        button.set_expand(False)
        button.set_label(_("Run this code"))
        button.set_is_important(True)
        button.connect("clicked", self.__run_button_clicked, None)
        toolbar.add(button)

        self.notebook = Gtk.Notebook()
        vbox.pack_start(self.notebook, True, True, 0)

        self.buffers = {}

        for key in self.codes:
            code = self.codes[key]
            lang_manager = GtkSource.LanguageManager()
            textbuffer = GtkSource.Buffer.new_with_language(
                lang_manager.get_language('c'))
            textview = GtkSource.View.new_with_buffer(textbuffer)
            textview.set_show_line_numbers(True)
            textview.set_left_margin(10)
            textview.set_right_margin(10)
            textview.get_buffer().set_text(code)
            self.buffers[key] = textview.get_buffer()

            sw = Gtk.ScrolledWindow()
            sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
            sw.add(textview)
            textview.show()
            self.notebook.append_page(sw, Gtk.Label(key))
        self.show_all()
Пример #30
0
    def __init__(self):
        super().__init__()

        self.document = None

        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.set_pixels_above_lines(4)
        # self.view.set_pixels_below_lines(4)
        self.view.set_left_margin(8)
        self.view.set_right_margin(8)
        self.view.get_style_context().add_class('norka-editor')

        self.view.connect('key-release-event', self.on_key_release_event)

        self.scrolled = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
        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)

        self.stats_handler = StatsHandler(overlay_bar=self.stats_overlay, buffer=self.buffer)
        self.stats_handler.update_default_stat()

        self.add(self.overlay)

        self.font_desc = Pango.FontDescription()
        self.spellchecker = GtkSpell.Checker()

        self.search_settings = GtkSource.SearchSettings(wrap_around=True)
        self.search_context = GtkSource.SearchContext(buffer=self.buffer, settings=self.search_settings)
        self.search_iter = None