rough POC with a hardcoded image file

This commit is contained in:
Matt Rose 2020-09-23 21:52:44 -04:00
parent a93609da8f
commit 501e6b3145
1 changed files with 14 additions and 3 deletions

View File

@ -6,7 +6,7 @@
import os import os
import signal import signal
import gi import gi
from gi.repository import GLib, GObject, Pango, Gtk, Gdk from gi.repository import GLib, GObject, Pango, Gtk, Gdk, GdkPixbuf
gi.require_version('Vte', '2.91') # vte-0.38 (gnome-3.14) gi.require_version('Vte', '2.91') # vte-0.38 (gnome-3.14)
from gi.repository import Vte from gi.repository import Vte
import subprocess import subprocess
@ -135,6 +135,7 @@ class Terminal(Gtk.VBox):
self.pending_on_vte_size_allocate = False self.pending_on_vte_size_allocate = False
self.vte = Vte.Terminal() self.vte = Vte.Terminal()
self.background_image = GdkPixbuf.Pixbuf.new_from_file("/Users/mattrose/test.jpg")
self.vte.set_allow_hyperlink(True) self.vte.set_allow_hyperlink(True)
self.vte._draw_data = None self.vte._draw_data = None
if not hasattr(self.vte, "set_opacity") or \ if not hasattr(self.vte, "set_opacity") or \
@ -146,7 +147,8 @@ class Terminal(Gtk.VBox):
self.vte.show() self.vte.show()
self.vte.set_clear_background(False)
self.vte.connect("draw",self.background_draw)
self.default_encoding = self.vte.get_encoding() self.default_encoding = self.vte.get_encoding()
self.update_url_matches() self.update_url_matches()
@ -1125,8 +1127,17 @@ class Terminal(Gtk.VBox):
widget.disconnect(connec) widget.disconnect(connec)
widget._draw_data = None widget._draw_data = None
def background_draw(self, widget, cr):
rect = self.vte.get_allocation()
xratio = float(rect.width) / float(self.background_image.get_width())
yratio = float(rect.height) / float(self.background_image.get_height())
cr.save()
cr.scale(xratio,yratio)
Gdk.cairo_set_source_pixbuf(cr, self.background_image, 0, 0)
cr.paint()
cr.restore()
def on_draw(self, widget, context): def on_draw(self, widget, context):
"""Handle an expose event while dragging"""
if not widget._draw_data: if not widget._draw_data:
return(False) return(False)