Skip to content

Commit

Permalink
Merge pull request #217 from mattrose/background-image
Browse files Browse the repository at this point in the history
Background image
  • Loading branch information
mattrose authored Sep 30, 2020
2 parents a84bed9 + 8db142d commit e9eb89e
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 6 deletions.
2 changes: 2 additions & 0 deletions terminatorlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@
'autoclean_groups' : True,
'http_proxy' : '',
'ignore_hosts' : ['localhost','127.0.0.0/8','*.local'],
'background_image' : '',
'background_alpha' : 0.0
},
},
'layouts': {
Expand Down
116 changes: 114 additions & 2 deletions terminatorlib/preferences.glade
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
15 changes: 14 additions & 1 deletion terminatorlib/prefseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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.
Expand Down
30 changes: 27 additions & 3 deletions terminatorlib/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -136,6 +136,14 @@ def __init__(self):
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 \
Expand All @@ -147,7 +155,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()

Expand Down Expand Up @@ -1126,8 +1135,23 @@ 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):
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)

Expand Down

0 comments on commit e9eb89e

Please sign in to comment.