/usr/lib/gedit/plugins/terminal.py

# -*- coding: utf8 -*-

# terminal.py - Embeded VTE terminal for gedit
# This file is part of gedit
#
# Copyright (C) 2005-2006 - Paolo Borelli
#
# gedit is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# gedit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with gedit; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA from gi.repository import GObject, GLib, Gio, Pango, Gdk, Gtk, Gedit, Vte
import os
import gettext
from gpdefs import * try:
gettext.bindtextdomain(GETTEXT_PACKAGE, GP_LOCALEDIR)
_ = lambda s: gettext.dgettext(GETTEXT_PACKAGE, s);
except:
_ = lambda s: s class GeditTerminal(Gtk.Box):
"""VTE terminal which follows gnome-terminal default profile options""" __gsignals__ = {
"populate-popup": (
GObject.SIGNAL_RUN_LAST,
None,
(GObject.TYPE_OBJECT,)
)
} defaults = {
'emulation' : 'xterm',
'visible_bell' : False,
} def __init__(self):
Gtk.Box.__init__(self) self.profile_settings = self.get_profile_settings()
self.profile_settings.connect("changed", self.on_profile_settings_changed)
self.system_settings = Gio.Settings.new("org.gnome.desktop.interface")
self.system_settings.connect("changed::monospace-font-name", self.font_changed) self._vte = Vte.Terminal()
self.reconfigure_vte()
self._vte.set_size(self._vte.get_column_count(), 5)
self._vte.set_size_request(200, 50)
self._vte.show()
self.pack_start(self._vte, True, True, 0) scrollbar = Gtk.Scrollbar.new(Gtk.Orientation.VERTICAL, self._vte.get_vadjustment())
scrollbar.show()
self.pack_start(scrollbar, False, False, 0) # we need to reconf colors if the style changes
#FIXME: why?
#self._vte.connect("style-update", lambda term, oldstyle: self.reconfigure_vte())
self._vte.connect("key-press-event", self.on_vte_key_press)
self._vte.connect("button-press-event", self.on_vte_button_press)
self._vte.connect("popup-menu", self.on_vte_popup_menu)
self._vte.connect("child-exited", self.on_child_exited) self._accel_base = '<gedit>/plugins/terminal'
self._accels = {
'copy-clipboard': [Gdk.KEY_C, Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK, self.copy_clipboard],
'paste-clipboard': [Gdk.KEY_V, Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK, self.paste_clipboard]
} for name in self._accels:
path = self._accel_base + '/' + name
accel = Gtk.AccelMap.lookup_entry(path) if not accel[0]:
Gtk.AccelMap.add_entry(path, self._accels[name][0], self._accels[name][1]) self._vte.fork_command_full(Vte.PtyFlags.DEFAULT, None, [Vte.get_user_shell()], None, GLib.SpawnFlags.SEARCH_PATH, None, None) def on_child_exited(self):
self._vte.fork_command_full(Vte.PtyFlags.DEFAULT, None, [Vte.get_user_shell()], None, GLib.SpawnFlags.SEARCH_PATH, None, None) def do_grab_focus(self):
self._vte.grab_focus() def get_profile_settings(self):
#FIXME return either the gnome-terminal settings or the gedit one
return Gio.Settings.new("org.gnome.gedit.plugins.terminal") def get_font(self):
if self.profile_settings.get_boolean("use-system-font"):
font = self.system_settings.get_string("monospace-font-name")
else:
font = self.profile_settings.get_string("font") return font def font_changed(self, settings=None, key=None):
font = self.get_font()
font_desc = Pango.font_description_from_string("") self._vte.set_font(font_desc) def reconfigure_vte(self):
# Fonts
self.font_changed() # colors
context = self._vte.get_style_context()
#fg = context.get_color(Gtk.StateFlags.NORMAL)
#bg = context.get_background_color(Gtk.StateFlags.NORMAL)
bg = Gdk.RGBA(0, 0, 0, 1)
fg = Gdk.RGBA(1, 1, 1, 1)
palette = [] if not self.profile_settings.get_boolean("use-theme-colors"):
fg_color = self.profile_settings.get_string("foreground-color")
if fg_color != "":
fg = Gdk.RGBA()
parsed = fg.parse(fg_color)
bg_color = self.profile_settings.get_string("background-color")
if bg_color != "":
bg = Gdk.RGBA()
parsed = bg.parse(bg_color)
str_colors = self.profile_settings.get_string("palette")
if str_colors != "":
for str_color in str_colors.split(':'):
try:
rgba = Gdk.RGBA()
rgba.parse(str_color)
palette.append(rgba)
except:
palette = []
break
if (len(palette) not in (0, 8, 16, 24)):
palette = [] self._vte.set_colors_rgba(fg, bg, palette) self._vte.set_cursor_blink_mode(self.profile_settings.get_enum("cursor-blink-mode"))
self._vte.set_cursor_shape(self.profile_settings.get_enum("cursor-shape"))
self._vte.set_audible_bell(not self.profile_settings.get_boolean("silent-bell"))
self._vte.set_allow_bold(self.profile_settings.get_boolean("allow-bold"))
self._vte.set_scroll_on_keystroke(self.profile_settings.get_boolean("scrollback-on-keystroke"))
self._vte.set_scroll_on_output(self.profile_settings.get_boolean("scrollback-on-output"))
self._vte.set_word_chars(self.profile_settings.get_string("word-chars"))
self._vte.set_emulation(self.defaults['emulation'])
self._vte.set_visible_bell(self.defaults['visible_bell']) if self.profile_settings.get_boolean("scrollback-unlimited"):
lines = -1
else:
lines = self.profile_settings.get_int("scrollback-lines")
self._vte.set_scrollback_lines(lines) def on_profile_settings_changed(self, settings, key):
self.reconfigure_vte() def on_vte_key_press(self, term, event):
modifiers = event.state & Gtk.accelerator_get_default_mod_mask()
if event.keyval in (Gdk.KEY_Tab, Gdk.KEY_KP_Tab, Gdk.KEY_ISO_Left_Tab):
if modifiers == Gdk.ModifierType.CONTROL_MASK:
self.get_toplevel().child_focus(Gtk.DirectionType.TAB_FORWARD)
return True
elif modifiers == Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK:
self.get_toplevel().child_focus(Gtk.DirectionType.TAB_BACKWARD)
return True for name in self._accels:
path = self._accel_base + '/' + name
entry = Gtk.AccelMap.lookup_entry(path) if entry and entry[0] and entry[1].accel_key == event.keyval and entry[1].accel_mods == modifiers:
self._accels[name][2]()
return True return False def on_vte_button_press(self, term, event):
if event.button == 3:
self._vte.grab_focus()
self.make_popup(event)
return True return False def on_vte_popup_menu(self, term):
self.make_popup() def create_popup_menu(self):
menu = Gtk.Menu() item = Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_COPY, None)
item.connect("activate", lambda menu_item: self.copy_clipboard())
item.set_accel_path(self._accel_base + '/copy-clipboard')
item.set_sensitive(self._vte.get_has_selection())
menu.append(item) item = Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_PASTE, None)
item.connect("activate", lambda menu_item: self.paste_clipboard())
item.set_accel_path(self._accel_base + '/paste-clipboard')
menu.append(item) self.emit("populate-popup", menu)
menu.show_all()
return menu def make_popup(self, event = None):
menu = self.create_popup_menu()
menu.attach_to_widget(self, None) if event is not None:
menu.popup(None, None, None, None, event.button, event.time)
else:
menu.popup(None, None,
lambda m: Gedit.utils_menu_position_under_widget(m, self),
None,
0, Gtk.get_current_event_time())
menu.select_first(False) def copy_clipboard(self):
self._vte.copy_clipboard()
self._vte.grab_focus() def paste_clipboard(self):
self._vte.paste_clipboard()
self._vte.grab_focus() def change_directory(self, path):
path = path.replace('\\', '\\\\').replace('"', '\\"')
self._vte.feed_child('cd "%s"\n' % path, -1)
self._vte.grab_focus() class TerminalPlugin(GObject.Object, Gedit.WindowActivatable):
__gtype_name__ = "TerminalPlugin" window = GObject.property(type=Gedit.Window) def __init__(self):
GObject.Object.__init__(self) def do_activate(self):
self._panel = GeditTerminal()
self._panel.connect("populate-popup", self.on_panel_populate_popup)
self._panel.show() image = Gtk.Image.new_from_icon_name("utilities-terminal", Gtk.IconSize.MENU) bottom = self.window.get_bottom_panel()
bottom.add_item(self._panel, "GeditTerminalPanel", _("Terminal"), image) def do_deactivate(self):
bottom = self.window.get_bottom_panel()
bottom.remove_item(self._panel) def do_update_state(self):
pass def get_active_document_directory(self):
doc = self.window.get_active_document()
if doc is None:
return None
location = doc.get_location()
if location is not None and Gedit.utils_location_has_file_scheme(location):
directory = location.get_parent()
return directory.get_path()
return None def on_panel_populate_popup(self, panel, menu):
menu.prepend(Gtk.SeparatorMenuItem())
path = self.get_active_document_directory()
item = Gtk.MenuItem.new_with_mnemonic(_("C_hange Directory"))
item.connect("activate", lambda menu_item: panel.change_directory(path))
item.set_sensitive(path is not None)
menu.prepend(item) # Let's conform to PEP8
# ex:ts=4:et:

gedit embeded terminal 设置字体 颜色的更多相关文章

  1. Latex中如何设置字体颜色(3种方式)

    Latex中如何设置字体颜色(三种方式)   1.直接使用定义好的颜色 \usepackage{color} \textcolor{red/blue/green/black/white/cyan/ma ...

  2. runtime查找 UIAlertAction 的key 及 UIActionSheet 设置字体颜色

    修改不了颜色了 结果发现kvo 的key 不对 哎 直接上代码 设置正确的属性找到对应的key  还以为iOS 11改变了方法 unsigned int count; Ivar *ivars =  c ...

  3. 如何在HTML中设置字体颜色,你知道这几种方式吗?

    color设置字体颜色 在color设置字体颜色之前,我们首先了解color在CSS中有几种取值方式,一共有4种方式,若有不全还请在评论区告知谢谢,4种方式如下: 十六进制.十进制. 英文单词.十六进 ...

  4. python设置图片背景和设置字体颜色大小

    # -*- coding: utf-8 -*- """ Created on Wed Dec 11 22:37:30 2019 @author: Dell "& ...

  5. C# 控制台程序(命令行程序)设置字体颜色,窗口宽高,光标行数

    控制台程序(命令行程序)设置窗口宽度高度,如下代码: Console.WriteLine(Console.WindowHeight); Console.WriteLine(Console.Buffer ...

  6. C# 控制台程序设置字体颜色

    这几天做了个程序,程序本身很简单.大体功能是输入查询条件,从数据库里取出结果计算并显示.但是用户的要求是使用控制台(console)来实现功能.由于功能简单,程序很快就做完了,在面向用户演示程序时,突 ...

  7. android 设置字体颜色、EditText自己主动输入转换成大写字母的多种方式

    在TextView上面设置某一个字的字体颜色为指定颜色时,能够通过java类SpannableString类和Html语言来实现. (一)SpannableString类方式 private void ...

  8. c++控制台 设置字体颜色

    一种方法是直接在程序上方栏杆点右键,然后属性处设置 优点是设置后一劳永逸,不需要像后面方法那样要自己把设置写入程序代码内 缺点是,一旦设置了就不能再改变了,程序从头到尾都是那种设置. 第二种方法是使用 ...

  9. android 在代码中设置字体颜色 问题

    项目中需要在代码中控制字体颜色 之前是直接引用资源文件  但是不行 tv.setTextColor(R.color.textColor_black); 无效果   后来在网上找了资料发现 要从reso ...

随机推荐

  1. navicat for mysql 数据库备份与还原

    一, 首先设置, 备份保存路径 工具 -> 选项 点开 其他 -> 日志文件保存路径 二. 开始备份 备份分两种, 一种是以sql保存, 一种是保存为备份 SQL保存 右键点击你要备份的数 ...

  2. laravel容器container 阅读记录

    今天抽时间又仔细看了一下laravel的container,记录一下. 所谓容器,听名字就知道,是一个仓库,装东西用的,所以,container所有的功能,都围绕一个主题:管理装. 类名称:Illum ...

  3. JSONModel(I)

    JSONModel使用简介 JSONModel 只需要将你的 model 类继承自 JSONModel ,而同时 model 中的属性名又恰巧可以和 JSON 数据中的 key 名字一样的话,那么非常 ...

  4. javascript时间处理

    1.将一般格式时间转换为时间戳: var systime = "2018年04月28日 16:01:09"; systime = systime.replace('年', &quo ...

  5. js-cookie的用法

    cookie的作用无需多言,自己封装一个cookie,不停地复制黏贴页颇为麻烦,在这里,有npm为我们封装好的插件js-cookie: https://www.npmjs.com/package/js ...

  6. Django之天天生鲜项目

    准备工作 1.配置settings.py内置文件 注意: AUTH_USER_MODEL配置参数要在第一次迁移数据库之前配置,否则可能django的认证系统工作不正常 2.创建应用 3.配置主路由 一 ...

  7. 使用solr进行配置文件

    我现在使用的是一个已经搭建好的solr环境下进行的测试: 第一步,需要配置solrhome中的一个配置文件schema.xml 配置内容如下,上面配置的是IK分词器,下面是配置完成的域. 因为我在这个 ...

  8. loj#3 -Copycat

    原题链接:https://loj.ac/problem/3 题目描述: --- Copycat 内存限制:256 MiB 时间限制:1000 ms 输入文件: copycat.in 输出文件: cop ...

  9. malloc/free 和 new/delete

    (本文参考于网上) 首先两者都可用于申请动态内存和释放内存。 对于非内部数据类型的对象而言,只用malloc/free无法满足动态对象的要求.对象在创建的同时要自动执行构造函数,对象在消亡之前要自动执 ...

  10. Linux学习进阶示意图

    Linux 基础 Linux 基础 Linux安装专题教程 Linux中文环境 Linux—从菜鸟到高手 鸟哥的Linux私房菜 基础学习篇(第二版) Ubuntu Linux入门到精通 Linux标 ...