Merge pull request #217 from mattrose/background-image

Background image
This commit is contained in:
Matt Rose 2020-09-30 10:23:50 -04:00 committed by GitHub
commit e9eb89ef00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 157 additions and 6 deletions

View File

@ -251,6 +251,8 @@ DEFAULTS = {
'autoclean_groups' : True,
'http_proxy' : '',
'ignore_hosts' : ['localhost','127.0.0.0/8','*.local'],
'background_image' : '',
'background_alpha' : 0.0
},
},
'layouts': {

View File

@ -360,6 +360,11 @@
<property name="step_increment">0.1</property>
<property name="page_increment">0.2</property>
</object>
<object class="GtkAdjustment" id="background_image_shading_adjustment">
<property name="upper">1</property>
<property name="step_increment">0.1</property>
<property name="page_increment">0.01</property>
</object>
<object class="GtkWindow" id="prefswin">
<property name="can_focus">False</property>
<property name="border_width">6</property>
@ -1434,6 +1439,12 @@
<property name="top_attach">2</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
@ -2860,7 +2871,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">1</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
@ -2928,7 +2939,108 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Background Image:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFileChooserButton" id="background_image_file">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">Choose file</property>
<signal name="file-set" handler="on_background_image_file_set" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Shade Background Image:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Transparent </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkScale" id="background_image_shading_scale">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">background_image_shading_adjustment</property>
<property name="round_digits">1</property>
<signal name="value-changed" handler="on_background_image_shading_scale_value_changed" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Opaque</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
</object>

View File

@ -637,7 +637,11 @@ class PrefsEditor:
# 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 @@ class PrefsEditor:
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.

View File

@ -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
@ -136,6 +136,14 @@ class Terminal(Gtk.VBox):
self.pending_on_vte_size_allocate = False
self.vte = Vte.Terminal()
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 \
@ -147,7 +155,8 @@ class Terminal(Gtk.VBox):
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()
@ -1126,8 +1135,23 @@ class Terminal(Gtk.VBox):
widget.disconnect(connec)
widget._draw_data = None
def background_draw(self, widget, cr):
if not self.background_image:
return(False)
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())
cr.save()
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):
"""Handle an expose event while dragging"""
if not widget._draw_data:
return(False)