0

我做了一个程序,在一个窗口中显示四个终端,但是字体太大了。这是我的代码:

#!/usr/bin/python shells.py

from gi.repository import Gtk, Vte, Gdk
from gi.repository import GLib
import os

class MainWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="shells")
        self.resize(1000, 1000)

        table = Gtk.Table(2, 2, True)
        self.add(table)

        palette = [Gdk.color_parse('red')] * 16
        terminal1 = Vte.Terminal()
        terminal2 = Vte.Terminal()
        terminal3 = Vte.Terminal()
        terminal4 = Vte.Terminal()

        scrolledwindow1 = Gtk.ScrolledWindow()
        scrolledwindow1.add(terminal1)

        scrolledwindow2 = Gtk.ScrolledWindow()
        scrolledwindow2.add(terminal2)

        scrolledwindow3 = Gtk.ScrolledWindow()
        scrolledwindow3.add(terminal3)

        scrolledwindow4 = Gtk.ScrolledWindow()
        scrolledwindow4.add(terminal4)

        terminal1.fork_command_full(Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin  /sh"], 
                                   [], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)
        terminal2.fork_command_full(Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin/sh"],
                                   [], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)
        terminal3.fork_command_full(Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin/sh"],
                                   [], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)
        terminal4.fork_command_full(Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin/sh"],
                                   [], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)

        terminal1.set_colors(Gdk.color_parse('red'), Gdk.color_parse('black'), palette)
        terminal2.set_colors(Gdk.color_parse('green'), Gdk.color_parse('black'), palette)
        terminal3.set_colors(Gdk.color_parse('yellow'), Gdk.color_parse('black'), palette)
        terminal4.set_colors(Gdk.color_parse('blue'), Gdk.color_parse('black'), palette)

        table.attach(scrolledwindow1, 0, 1, 0, 1)
        table.attach(scrolledwindow2, 1, 2, 0, 1)
        table.attach(scrolledwindow3, 0, 1, 1, 2)
        table.attach(scrolledwindow4, 1, 2, 1, 2)

win = MainWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

根据我使用的文档Vte set_font

import pango
font = pango.FontDescription()
terminal1.set_font(font)

我收到以下错误:

AttributeError: type object 'Context' has no attribute '__info__'

该示例来自堆栈溢出问题: 如何在 vte.Terminal 中启用透明度

然后我根据这个Vte 'decrease-font-size' 信号使用:

terminal1.connect('decrease-font-size', function, data)
def function():
    print "press crtl -to decrease font-size"

这个没有任何反应。其余的也不起作用。我还注意到,我不能真正改变一个终端的大小,使用:

terminal1.set_size(30, 29)

似乎什么都改变不了。

对于这些示例,为了简单起见,我只使用了终端 1。还有一件奇怪的事情是,当我执行“清除”命令时,它似乎重新排列并且字体变大了。我为奇怪的英语道歉。这不是我的母语,但我会尽力而为。在编程方面,我只有 python 和相关库或模块的经验。我正在使用 Linux Debian 版本作为操作系统。

问候

4

1 回答 1

0

连接到as的realize信号,然后才创建,然后在终端上并由它返回:Vte.TerminalPango.FontDescription()get_font()set_size()Pango.FontDescription()

#!/usr/bin/env python3


import os

from gi.repository import GLib
from gi.repository import Pango
from gi.repository import Gdk
from gi.repository import Gtk
from gi.repository import Vte


class MainWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="shells")
        self.resize(1000, 1000)

        table = Gtk.Table(2, 2, True)
        self.add(table)

        palette = [Gdk.color_parse('red')] * 16
        terminal1 = Vte.Terminal()
        terminal1.connect('realize', self.on_realize_terminal)
        terminal2 = Vte.Terminal()
        terminal2.connect('realize', self.on_realize_terminal)
        terminal3 = Vte.Terminal()
        terminal3.connect('realize', self.on_realize_terminal)
        terminal4 = Vte.Terminal()
        terminal4.connect('realize', self.on_realize_terminal)

        scrolledwindow1 = Gtk.ScrolledWindow()
        scrolledwindow1.add(terminal1)

        scrolledwindow2 = Gtk.ScrolledWindow()
        scrolledwindow2.add(terminal2)

        scrolledwindow3 = Gtk.ScrolledWindow()
        scrolledwindow3.add(terminal3)

        scrolledwindow4 = Gtk.ScrolledWindow()
        scrolledwindow4.add(terminal4)

        terminal1.fork_command_full(Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin/sh"], 
                                   [], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)
        terminal2.fork_command_full(Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin/sh"],
                                   [], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)
        terminal3.fork_command_full(Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin/sh"],
                                   [], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)
        terminal4.fork_command_full(Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin/sh"],
                                   [], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)

        terminal1.set_colors(Gdk.color_parse('red'), Gdk.color_parse('black'), palette)
        terminal2.set_colors(Gdk.color_parse('green'), Gdk.color_parse('black'), palette)
        terminal3.set_colors(Gdk.color_parse('yellow'), Gdk.color_parse('black'), palette)
        terminal4.set_colors(Gdk.color_parse('blue'), Gdk.color_parse('black'), palette)

        table.attach(scrolledwindow1, 0, 1, 0, 1)
        table.attach(scrolledwindow2, 1, 2, 0, 1)
        table.attach(scrolledwindow3, 0, 1, 1, 2)
        table.attach(scrolledwindow4, 1, 2, 1, 2)

    def on_realize_terminal(self, terminal):
        font = terminal.get_font()
        font.set_size(16 * Pango.SCALE)


if __name__ == '__main__':
    win = MainWindow()
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()
    Gtk.main()
于 2013-06-12T19:43:30.183 回答