วิธีเปิดใช้งานความโปร่งใสใน vte.Terminal

ฉันกำลังสร้างเทอร์มินัลอย่างง่ายใน python โดยใช้ vte.Terminal ฉันต้องการให้พื้นหลังเทอร์มินัลมีความโปร่งใสในระดับหนึ่ง แต่ set_opacity ไม่ทำงาน แต่มันทำงานในเทอร์มิเนเตอร์และเทอร์มินัลอื่น ๆ

window.set_opacity ทำให้ทั้งหน้าต่างโปร่งใส แต่ฉันไม่ต้องการให้ค้างคาวหัวเรื่องโปร่งใส นี่คือรหัส

#!/usr/bin/env python

import vte
import gtk
import pango
import os
import signal

window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect('destroy', lambda w: gtk.main_quit())
# initial window size
window.resize(640, 480)

terminal = vte.Terminal()
terminal.connect("child-exited", lambda w: gtk.main_quit())

# here you can set backscroll buffer
terminal.set_scrollback_lines(5000)
# encoding for console
terminal.set_encoding("UTF-8")
terminal.set_cursor_blinks(False)

# here you can set background image
#terminal.set_background_image_file("some/background/picture/here")

# transparency
terminal.set_opacity (45000)
# font for terminal
font = pango.FontDescription()
font.set_family("Ubuntu Mono")
# font size
font.set_size(11 * pango.SCALE)
font.set_weight(pango.WEIGHT_NORMAL)
font.set_stretch(pango.STRETCH_NORMAL)

terminal.set_font_full(font, True)

child_pid = terminal.fork_command()

scroll = gtk.ScrolledWindow()
scroll.set_policy(0,1)
scroll.add_with_viewport(terminal)

window.add(scroll)
window.show_all()

# This must be here! before gtk.main()
# here you can set columns count (first param)
terminal.set_size(500,0)

try:
    gtk.main()
except KeyboardInterrupt:
    pass

person voldyman    schedule 27.07.2012    source แหล่งที่มา
comment
คุณเคยได้รับคำตอบนี้หรือไม่? ฉันมีปัญหาเดียวกัน   -  person weberc2    schedule 02.05.2015


คำตอบ (1)


ตัวอย่างต่อไปนี้สามารถแก้ไขปัญหานี้ได้

colormap = window.get_screen().get_rgba_colormap()
if colormap == None:
    colormap = window.get_screen().get_rgb_colormap()
gtk.widget_set_default_colormap(colormap)

หน้าตาหน้าต่างเป็นแบบนี้

แม้ว่าฉันจะลงเอยด้วยการใช้ Vala สำหรับโปรแกรมและมีฟังก์ชันง่ายๆ ชื่อ set_visual.

หวังว่านี่จะช่วยได้

person voldyman    schedule 03.05.2015
comment
ฉันกำลังเล่นกับสิ่งนี้อยู่... ฉันสามารถทำให้เทอร์มินัลโปร่งใสได้ แต่ทันทีที่ฉันใส่ ScrolledWindow ไว้ระหว่างหน้าต่างหลักและวิดเจ็ตเทอร์มินัล มันจะทึบแสงอีกครั้ง แม้ว่าฉันจะเรียก ScrolledWindow.set_opacity(0) . ฉันยังใช้วาลา - person weberc2; 08.05.2015