2013-01-22 20 views
3

我正在用Python + Gtk3編寫一個使用Vte的應用程序。
我無法改變所有的顏色。
爲什麼set_color_foreground和它的同伴set_color_XXX在Vte(Python-Gtk3)中不起作用?

例如,對於前景色,我想這個代碼,但文字顏色沒有變化:

class Shell(Gtk.Box): 
    def __init__(self,on_close_button_cb,path = ""): 
     super(Shell,self).__init__(orientation=Gtk.Orientation.VERTICAL) 

     v = Vte.Terminal() 
     v.set_color_foreground(Gdk.Color(65535,0,0)) 
     v.set_size(80,80) 
     v.show_all() 

     if path == "": 
      path = os.environ['HOME'] 

     self.vpid = v.fork_command_full(Vte.PtyFlags.DEFAULT, path, ["/bin/bash"], [], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None,) 
     self.pack_start(v,True,True,0) 

     self.set_visible(True) 
+0

我有同樣的問題,但在C. – Rrjrjtlokrthjji

回答

2

更改Vte.Terminal()控件的顏色有 之後進行終端小部件已經實現。否則,顏色變化 用set_colors(),set_color_foreground()等方法完成 不考慮在內。

下面的工作示例提出了兩種這樣做的方法。 該示例使用調色板和set_colors(),但如果您想要使用set_color_foreground()或 其他set_color _ *()方法,則會使用相同的 。就個人而言,我更喜歡選項1:

import gi 
gi.require_version('Gtk', '3.0') 

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

palette_components = [ 
    (0, 0x0707, 0x3636, 0x4242), # background 
    (0, 0xdcdc, 0x3232, 0x2f2f), 
    (0, 0x8585, 0x9999, 0x0000), 
    (0, 0xb5b5, 0x8989, 0x0000), 
    (0, 0x2626, 0x8b8b, 0xd2d2), 
    (0, 0xd3d3, 0x3636, 0x8282), 
    (0, 0x2a2a, 0xa1a1, 0x9898), 
    (0, 0xeeee, 0xe8e8, 0xd5d5), # foreground 
    (0, 0x0000, 0x2b2b, 0x3636), 
    (0, 0xcbcb, 0x4b4b, 0x1616), 
    (0, 0x5858, 0x6e6e, 0x7575), 
    (0, 0x6565, 0x7b7b, 0x8383), 
    (0, 0x8383, 0x9494, 0x9696), 
    (0, 0x6c6c, 0x7171, 0xc4c4), 
    (0, 0x9393, 0xa1a1, 0xa1a1), 
    (0, 0xfdfd, 0xf6f6, 0xe3e3) 
    ] 

palette = [] 
for components in palette_components: 
    color = Gdk.Color(components[1], components[2], components[3]) 
    palette.append(color) 


def terminal_realize_cb(terminal): 
    terminal.set_colors(None, None, palette) 


if __name__ == '__main__': 
    window = Gtk.Window() 
    window.connect('delete-event', Gtk.main_quit) 

    terminal = Vte.Terminal() 

    # Option 1: connect to the terminal widget's realize event 
    # and call it's set_colors() method there 
    terminal.connect('realize', terminal_realize_cb) 

    terminal.fork_command_full(Vte.PtyFlags.DEFAULT, 
           None, 
           ['/bin/bash'], 
           [], 
           GLib.SpawnFlags.DO_NOT_REAP_CHILD, 
           None, 
           None) 

    window.add(terminal) 
    window.show_all() 

    # Option 2: call the terminal's set_colors() method 
    # after the window has been shown (which indirectly 
    # realizes the terminal widget) 
    #terminal.set_colors(None, None, palette) 

    Gtk.main() 
相關問題