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


Python GtkSource.LanguageManager方法代码示例

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


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

示例1: __init__

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import LanguageManager [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

示例2: __init__

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import LanguageManager [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

示例3: __init__

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import LanguageManager [as 别名]
def __init__(self):
        GtkSource.View.__init__(self)

        self.set_hexpand(True)
        self.set_vexpand(True)

        # create buffer
        self.buf = self.get_buffer()

        # setup style and lang managers
        self.lm = GtkSource.LanguageManager()
        self.sm = GtkSource.StyleSchemeManager()

        self.lm.set_search_path([LANGDIR])
        self.sm.set_search_path([STYLEDIR])

        self.buf.set_style_scheme(self.sm.get_scheme('gcode'))
        self.buf.set_language(self.lm.get_language('gcode'))

        self.buf.set_max_undo_levels(20)

        self.set_show_line_numbers(True)
        self.set_show_line_marks(False)
        self.set_highlight_current_line(False)

        self.connect('key-press-event', self.on_key_press)

        # Set line highlight styles
        self.add_mark_category('error', '#ff7373')
        self.add_mark_category('motion', '#c5c5c5')
        self.add_mark_category('selected', '#96fef6')

        self.mark = None
        self.current_file = None
        self.error_line = None

        self.show() 
开发者ID:KurtJacobson,项目名称:hazzy,代码行数:39,代码来源:gcode_view.py

示例4: ScrolledSourceView

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import LanguageManager [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: _set_buffer

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import LanguageManager [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

示例6: __init__

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import LanguageManager [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

示例7: __init__

# 需要导入模块: from gi.repository import GtkSource [as 别名]
# 或者: from gi.repository.GtkSource import LanguageManager [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


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