From 501e6b314506fde4b65025d2980df5ec03ba0eae Mon Sep 17 00:00:00 2001 From: Matt Rose Date: Wed, 23 Sep 2020 21:52:44 -0400 Subject: [PATCH 1/4] rough POC with a hardcoded image file --- terminatorlib/terminal.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 30639ba1..95bbf473 100644 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -6,7 +6,7 @@ import os import signal 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) from gi.repository import Vte import subprocess @@ -135,6 +135,7 @@ def __init__(self): self.pending_on_vte_size_allocate = False self.vte = Vte.Terminal() + self.background_image = GdkPixbuf.Pixbuf.new_from_file("/Users/mattrose/test.jpg") self.vte.set_allow_hyperlink(True) self.vte._draw_data = None if not hasattr(self.vte, "set_opacity") or \ @@ -146,7 +147,8 @@ def __init__(self): self.vte.show() - + self.vte.set_clear_background(False) + self.vte.connect("draw",self.background_draw) self.default_encoding = self.vte.get_encoding() self.update_url_matches() @@ -1125,8 +1127,17 @@ def on_drag_motion(self, widget, drag_context, x, y, _time, _data): widget.disconnect(connec) 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): - """Handle an expose event while dragging""" if not widget._draw_data: return(False) From 415b7653dc61b3962e12886cbfd3255412d72da2 Mon Sep 17 00:00:00 2001 From: Matt Rose Date: Thu, 24 Sep 2020 16:24:54 -0400 Subject: [PATCH 2/4] added config values for background_image and background_alpha --- terminatorlib/config.py | 2 ++ terminatorlib/terminal.py | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/terminatorlib/config.py b/terminatorlib/config.py index 4abc564b..1d62254c 100644 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -250,6 +250,8 @@ 'autoclean_groups' : True, 'http_proxy' : '', 'ignore_hosts' : ['localhost','127.0.0.0/8','*.local'], + 'background_image' : '', + 'background_alpha' : 0.0 }, }, 'layouts': { diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 95bbf473..c02dc27f 100644 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -135,7 +135,14 @@ def __init__(self): self.pending_on_vte_size_allocate = False self.vte = Vte.Terminal() - self.background_image = GdkPixbuf.Pixbuf.new_from_file("/Users/mattrose/test.jpg") + self.background_image = None + if self.config['background_image'] != '': + try: + self.background_image = GdkPixbuf.Pixbuf.new_from_file(self.config['background_image']) + except Exception: + pass + + self.background_alpha = self.config['background_alpha'] self.vte.set_allow_hyperlink(True) self.vte._draw_data = None if not hasattr(self.vte, "set_opacity") or \ @@ -1128,6 +1135,11 @@ def on_drag_motion(self, widget, drag_context, x, y, _time, _data): widget._draw_data = None def background_draw(self, widget, cr): + if not self.background_image: + return(False) + print("bgcolor obj: %s" % self.bgcolor.alpha) + over = self.bgcolor + over.alpha = self.background_alpha 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()) @@ -1135,6 +1147,8 @@ def background_draw(self, widget, cr): cr.scale(xratio,yratio) Gdk.cairo_set_source_pixbuf(cr, self.background_image, 0, 0) cr.paint() + Gdk.cairo_set_source_rgba(cr,over) + cr.paint() cr.restore() def on_draw(self, widget, context): From 6db631f7d5d99a2bd977ca82af67ebc891572995 Mon Sep 17 00:00:00 2001 From: Matt Rose Date: Thu, 24 Sep 2020 16:41:14 -0400 Subject: [PATCH 3/4] remove print debug --- terminatorlib/terminal.py | 1 - 1 file changed, 1 deletion(-) diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index c02dc27f..df3bf29c 100644 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -1137,7 +1137,6 @@ def on_drag_motion(self, widget, drag_context, x, y, _time, _data): def background_draw(self, widget, cr): if not self.background_image: return(False) - print("bgcolor obj: %s" % self.bgcolor.alpha) over = self.bgcolor over.alpha = self.background_alpha rect = self.vte.get_allocation() From 8db142d92b51d816a4d0e288f25be67992a6a0a4 Mon Sep 17 00:00:00 2001 From: Matt Rose Date: Wed, 30 Sep 2020 10:20:02 -0400 Subject: [PATCH 4/4] add GUI controls for background image --- terminatorlib/preferences.glade | 116 +++++++++++++++++++++++++++++++- terminatorlib/prefseditor.py | 15 ++++- 2 files changed, 128 insertions(+), 3 deletions(-) diff --git a/terminatorlib/preferences.glade b/terminatorlib/preferences.glade index 968fe9cb..3b1063c7 100644 --- a/terminatorlib/preferences.glade +++ b/terminatorlib/preferences.glade @@ -360,6 +360,11 @@ 0.1 0.2 + + 1 + 0.1 + 0.01 + False 6 @@ -1434,6 +1439,12 @@ 2 + + + + + + True @@ -2860,7 +2871,7 @@ False False - 1 + 5 0 @@ -2928,7 +2939,108 @@ False True - 2 + 3 + + + + + True + False + + + True + False + Background Image: + + + False + True + 5 + 0 + + + + + True + False + Choose file + + + + False + True + end + 1 + + + + + False + True + 4 + + + + + True + False + + + True + False + Shade Background Image: + + + False + True + 5 + 0 + + + + + True + False + Transparent + + + False + True + 1 + + + + + True + True + background_image_shading_adjustment + 1 + + + + True + True + 2 + + + + + True + False + Opaque + + + False + True + end + 3 + + + + + False + True + 5 diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index a198fc5c..f483924d 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -637,7 +637,11 @@ def on_palette_click(event, data, widget=widget): # Background shading widget = guiget('background_darkness_scale') widget.set_value(float(self.config['background_darkness'])) - + widget = guiget('background_image_file') + widget.set_filename(self.config['background_image']) + widget = guiget('background_image_shading_scale') + widget.set_value(float(self.config['background_alpha'])) + ## Scrolling tab # Scrollbar position widget = guiget('scrollbar_position_combobox') @@ -931,6 +935,15 @@ def on_scrollbar_position_combobox_changed(self, widget): self.config['scrollbar_position'] = value self.config.save() + def on_background_image_file_set(self,widget): + print(widget.get_filename()) + self.config['background_image'] = widget.get_filename() + self.config.save() + + def on_background_image_shading_scale_value_changed(self,widget): + self.config['background_alpha'] = widget.get_value() + self.config.save() + def on_darken_background_scale_value_changed(self, widget): """Background darkness setting changed""" value = widget.get_value() # This one is rounded according to the UI.