当前位置: 首页>>代码示例>>Python>>正文


Python GtkSource.Buffer方法代码示例

本文整理汇总了Python中gi.repository.GtkSource.Buffer方法的典型用法代码示例。如果您正苦于以下问题:Python GtkSource.Buffer方法的具体用法?Python GtkSource.Buffer怎么用?Python GtkSource.Buffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gi.repository.GtkSource的用法示例。


在下文中一共展示了GtkSource.Buffer方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: new_buffer

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import Buffer [as 别名]
def new_buffer(self):
        style_scheme_manager = GtkSource.StyleSchemeManager()
        b = GtkSource.Buffer()
        b.set_language(self.language_manager.get_language(self.language))
        b.set_highlight_syntax(True)

        user_editor_style = global_gui_config.get_config_value(self.editor_style, "classic")
        if user_editor_style.startswith("rafcon"):
            user_editor_style = "rafcon"
            dark_theme = global_gui_config.get_config_value('THEME_DARK_VARIANT', True)
            if dark_theme:
                user_editor_style = "rafcon-dark"
        scheme = style_scheme_manager.get_scheme(user_editor_style)
        if scheme:
            self.style_scheme = scheme
        else:
            logger.debug("The editor style '{}' is not supported. Using the default 'classic'".format(
                user_editor_style))
            self.style_scheme = style_scheme_manager.get_scheme('classic')
        b.set_style_scheme(self.style_scheme)
        return b 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:23,代码来源:editor.py

示例2: __init__

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import Buffer [as 别名]
def __init__(self, app, language=None):
        super(BaseEditor, self).__init__()
        self.buffer = GtkSource.Buffer()
        self.set_buffer(self.buffer)
        self._config = app.config

        # Disable blinking cursor
        settings = self.get_settings()
        settings.set_property('gtk-cursor-blink', False)
        self.set_auto_indent(True)
        self.set_highlight_current_line(True)

        if language is not None:
            lang_manager = GtkSource.LanguageManager()
            self.buffer.set_language(lang_manager.get_language(language))

        self._setup_style_scheme()
        self._setup_font()
        self._setup_tab_width()
        self._setup_line_numbers() 
开发者ID:andialbrecht,项目名称:runsqlrun,代码行数:22,代码来源:editor.py

示例3: __init__

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import Buffer [as 别名]
def __init__(self, parentWindow):
        self.parentWindow = parentWindow
        builder = get_ui("scriptpage.xml")
        self.ui = builder.get_object("scriptpage")
        builder.connect_signals(self)

        self.buffer = GtkSource.Buffer()
        self.buffer.connect("changed", self.on_modified)
        self.editor = GtkSource.View.new_with_buffer(self.buffer)
        scrolledWindow = builder.get_object("scrolledWindow")
        scrolledWindow.add(self.editor)

        # Editor font
        settings = Gio.Settings.new("org.gnome.desktop.interface")
        fontDesc = Pango.font_description_from_string(settings.get_string("monospace-font-name"))
        self.editor.modify_font(fontDesc)

        self.promptCheckbox = builder.get_object("promptCheckbox")
        self.showInTrayCheckbox = builder.get_object("showInTrayCheckbox")
        self.linkButton = builder.get_object("linkButton")
        label = self.linkButton.get_child()
        label.set_ellipsize(Pango.EllipsizeMode.MIDDLE)

        vbox = builder.get_object("settingsVbox")
        self.settingsWidget = SettingsWidget(parentWindow)
        vbox.pack_start(self.settingsWidget.ui, False, False, 0)

        # Configure script editor
        self.__m = GtkSource.LanguageManager()
        self.__sm = GtkSource.StyleSchemeManager()
        self.buffer.set_language(self.__m.get_language("python"))
        self.buffer.set_style_scheme(self.__sm.get_scheme("classic"))
        self.editor.set_auto_indent(True)
        self.editor.set_smart_home_end(True)
        self.editor.set_insert_spaces_instead_of_tabs(True)
        self.editor.set_tab_width(4)

        self.ui.show_all() 
开发者ID:autokey,项目名称:autokey,代码行数:40,代码来源:configwindow.py

示例4: ScrolledSourceView

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import Buffer [as 别名]
def ScrolledSourceView(text=None, syntax=None):
	'''If GTKSourceView was successfullly loaded, this generates a SourceView and
	initializes it. Otherwise ScrolledTextView will be used as a fallback.

	@param text: initial text to show in the view
	@param syntax: this will try to enable syntax highlighting for the given
	language. If None, no syntax highlighting will be enabled.
	@returns: a 2-tuple of a window and a view.
	'''
	if GtkSource:
		gsvbuf = GtkSource.Buffer()
		if syntax:
			gsvbuf.set_highlight_syntax(True)
			language_manager = GtkSource.LanguageManager()
			gsvbuf.set_language(language_manager.get_language(syntax))
		if text:
			gsvbuf.set_text(text)
		textview = GtkSource.View()
		textview.set_buffer(gsvbuf)
		textview.set_property("show-line-numbers", True)
		textview.set_property("auto-indent", True)
		font = Pango.FontDescription('Monospace')
		textview.modify_font(font)
		textview.set_property("smart-home-end", True)
		window = ScrolledWindow(textview)
		return (window, textview)
	else:
		return ScrolledTextView(text=text, monospace=True) 
开发者ID:zim-desktop-wiki,项目名称:zim-desktop-wiki,代码行数:30,代码来源:widgets.py

示例5: __init__

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import Buffer [as 别名]
def __init__(self, attrib, text):
		GtkSource.Buffer.__init__(self)
		self.set_highlight_matching_brackets(True)
		if attrib['lang']:
			self._set_language(attrib['lang'])

		self.object_attrib = attrib

		if text.endswith('\n'):
			text = text[:-1]
			# If we have trailing \n it looks like an extra empty line
			# in the buffer, so we default remove one
		self.set_text(text) 
开发者ID:zim-desktop-wiki,项目名称:zim-desktop-wiki,代码行数:15,代码来源:sourceview.py

示例6: _set_language

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import Buffer [as 别名]
def _set_language(self, lang):
		try:
			GtkSource.Buffer.set_language(self, lm.get_language(lang))
		except:
			logger.exception('Could not set language for sourceview: %s', lang) 
开发者ID:zim-desktop-wiki,项目名称:zim-desktop-wiki,代码行数:7,代码来源:sourceview.py

示例7: _set_buffer

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import Buffer [as 别名]
def _set_buffer(self, file_name):
        """Set the current content to the buffer of the file."""
        lang_manager = GtkSource.LanguageManager()
        language = lang_manager.guess_language(file_name, None)
        diff = self._git.get_diff(file_name)
        buff = GtkSource.Buffer()
        buff.set_highlight_syntax(True)
        buff.set_highlight_matching_brackets(True)
        buff.set_language(language)
        buff.props.text = diff
        self._source.set_buffer(buff)
        stat = self._git.get_stat(file_name)
        if stat:
            self._stats.set_text(stat)
            self._stats.show() 
开发者ID:bilelmoussaoui,项目名称:nautilus-git,代码行数:17,代码来源:compare.py

示例8: __init__

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import Buffer [as 别名]
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.language_manager = GtkSource.LanguageManager()
		self.textbuffer.set_language(self.language_manager.get_language('html'))
		self.textbuffer.set_highlight_syntax(True)

		self.textview.modify_font(Pango.FontDescription(self.config['text_font']))
		self.textview.set_property('highlight-current-line', self.config.get('text_source.highlight_line', True))
		self.textview.set_property('indent-width', self.config.get('text_source.tab_width', 4))
		self.textview.set_property('insert-spaces-instead-of-tabs', not self.config.get('text_source.hardtabs', False))
		self.textview.set_property('tab-width', self.config.get('text_source.tab_width', 4))
		wrap_mode = self.config.get('text_source.wrap_mode', 'NONE')
		if wrap_mode.startswith('GTK_WRAP_'):
			wrap_mode = wrap_mode[9:]
		if wrap_mode.upper() in ('CHAR', 'NONE', 'WORD', 'WORD_CHAR'):
			self.textview.set_property('wrap-mode', getattr(Gtk.WrapMode, wrap_mode.upper()))
		else:
			self.logger.warning("invalid GtkWrapMode: {0!r}".format(wrap_mode))

		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.HTMLCompletionProvider())
		source_completion.add_provider(completion_providers.JinjaEmailCompletionProvider()) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:47,代码来源:mail.py

示例9: __init__

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import Buffer [as 别名]
def __init__(self, application, file_path, directory):
		"""
		This class is used to set up the Gtk.SourceView instance to edit the file

		:param application: The main client application instance.
		:type application: :py:class:`Gtk.Application`
		:param str file_path: the path of the file to edit
		:param directory: the local or remote directory instance
		"""
		self.application = application
		# get editor tab objects
		self.file_location = directory.location
		self.file_path = file_path
		self.file_contents = None
		self.directory = directory

		config = self.application.config
		self.sourceview_editor = sftp_utilities.get_object('SFTPClient.notebook.page_editor.sourceview')
		self.save_button = sftp_utilities.get_object('SFTPClient.notebook.page_editor.toolbutton_save_html_file')
		self.template_button = sftp_utilities.get_object('SFTPClient.notebook.page_editor.toolbutton_template_wiki')
		self.template_button.connect('clicked', self.signal_template_help)
		self.statusbar = sftp_utilities.get_object('SFTPClient.notebook.page_editor.statusbar')

		# set up sourceview for editing
		self.sourceview_buffer = GtkSource.Buffer()
		self.sourceview_buffer.connect('changed', self.signal_buff_changed)
		self.sourceview_editor.set_buffer(self.sourceview_buffer)
		self.sourceview_editor.modify_font(Pango.FontDescription(config['text_font']))
		language_manager = GtkSource.LanguageManager()
		self.sourceview_buffer.set_language(language_manager.get_language('html'))
		self.sourceview_buffer.set_highlight_syntax(True)
		self.sourceview_editor.set_property('highlight-current-line', config.get('text_source.highlight_line', True))
		self.sourceview_editor.set_property('indent-width', config.get('text_source.tab_width', 4))
		self.sourceview_editor.set_property('insert-spaces-instead-of-tabs', not config.get('text_source.hardtabs', False))
		self.sourceview_editor.set_property('tab-width', config.get('text_source.tab_width', 4))

		scheme_manager = GtkSource.StyleSchemeManager()
		style_scheme_name = config.get('text_source.theme', 'cobalt')
		style_scheme = scheme_manager.get_scheme(style_scheme_name)
		if style_scheme:
			self.sourceview_buffer.set_style_scheme(style_scheme)
		else:
			logger.error("invalid GTK source theme: '{0}'".format(style_scheme_name))

		self.view_completion = self.sourceview_editor.get_completion()
		self.view_completion.set_property('accelerators', 0)
		self.view_completion.set_property('auto-complete-delay', 250)
		self.view_completion.set_property('show-icons', False)

		if not self.view_completion.get_providers():
			self.view_completion.add_provider(completion_providers.HTMLCompletionProvider())
			self.view_completion.add_provider(completion_providers.JinjaPageCompletionProvider())
			logger.info('successfully loaded HTML and Jinja completion providers') 
开发者ID:rsmusllp,项目名称:king-phisher-plugins,代码行数:55,代码来源:editor.py

示例10: __init__

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import Buffer [as 别名]
def __init__(self, main):
        super(ConsoleTextView,self).__init__(False, 1)

        self.main = main
        self.uicore = self.main.uicore

        #################################################################
        # Interactive Right Textview
        #################################################################

        self.buffer = GtkSource.Buffer()
        self.buffer.create_tag("green-background", background="green", foreground="black")
        self.view = GtkSource.View.new_with_buffer(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.NONE)
        self.view.connect("populate-popup", self._populate_menu)
        
        # setup view
        font_desc = Pango.FontDescription('monospace 9')
        if font_desc:
            self.view.modify_font(font_desc)

        self.buffer.set_highlight_syntax(False)
        language = self.main.lm.get_language('asm')
        self.buffer.set_language(language)

        self.mgr = GtkSource.StyleSchemeManager.get_default()

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

        #Always on bottom on change
        self.vajd = self.console_scrolled_window.get_vadjustment()
        self.vajd.connect('changed', lambda a, s=self.console_scrolled_window: self.rescroll(a,s))

        # Comand line entry
        self.exec_entry = Gtk.Entry()
        self.exec_entry.set_max_length(100)
        self.exec_entry.set_icon_from_stock(1, Gtk.STOCK_EXECUTE)
        self.exec_entry.set_icon_tooltip_text(1, 'Execute')
        self.exec_entry.set_text('Radare console: type ? for help')
        self.exec_entry.connect("activate", self.r2_exec)
        self.exec_entry.connect("icon-press", self.r2_exec)
        self.exec_entry.connect('focus-in-event', self._clean, 'in')
        self.exec_entry.connect('focus-out-event', self._clean, 'out')
        self.pack_end(self.exec_entry, False, True, 0) 
开发者ID:inguma,项目名称:bokken,代码行数:58,代码来源:console_textview.py


注:本文中的gi.repository.GtkSource.Buffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。