Merge pull request #217 from mattrose/background-image
Background image
This commit is contained in:
commit
e9eb89ef00
|
@ -251,6 +251,8 @@ DEFAULTS = {
|
||||||
'autoclean_groups' : True,
|
'autoclean_groups' : True,
|
||||||
'http_proxy' : '',
|
'http_proxy' : '',
|
||||||
'ignore_hosts' : ['localhost','127.0.0.0/8','*.local'],
|
'ignore_hosts' : ['localhost','127.0.0.0/8','*.local'],
|
||||||
|
'background_image' : '',
|
||||||
|
'background_alpha' : 0.0
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'layouts': {
|
'layouts': {
|
||||||
|
|
|
@ -360,6 +360,11 @@
|
||||||
<property name="step_increment">0.1</property>
|
<property name="step_increment">0.1</property>
|
||||||
<property name="page_increment">0.2</property>
|
<property name="page_increment">0.2</property>
|
||||||
</object>
|
</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">
|
<object class="GtkWindow" id="prefswin">
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="border_width">6</property>
|
<property name="border_width">6</property>
|
||||||
|
@ -1434,6 +1439,12 @@
|
||||||
<property name="top_attach">2</property>
|
<property name="top_attach">2</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">True</property>
|
<property name="expand">True</property>
|
||||||
|
@ -2860,7 +2871,7 @@
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">False</property>
|
<property name="fill">False</property>
|
||||||
<property name="padding">1</property>
|
<property name="padding">5</property>
|
||||||
<property name="position">0</property>
|
<property name="position">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
@ -2928,7 +2939,108 @@
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">True</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>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
|
|
@ -637,6 +637,10 @@ class PrefsEditor:
|
||||||
# Background shading
|
# Background shading
|
||||||
widget = guiget('background_darkness_scale')
|
widget = guiget('background_darkness_scale')
|
||||||
widget.set_value(float(self.config['background_darkness']))
|
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
|
## Scrolling tab
|
||||||
# Scrollbar position
|
# Scrollbar position
|
||||||
|
@ -931,6 +935,15 @@ class PrefsEditor:
|
||||||
self.config['scrollbar_position'] = value
|
self.config['scrollbar_position'] = value
|
||||||
self.config.save()
|
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):
|
def on_darken_background_scale_value_changed(self, widget):
|
||||||
"""Background darkness setting changed"""
|
"""Background darkness setting changed"""
|
||||||
value = widget.get_value() # This one is rounded according to the UI.
|
value = widget.get_value() # This one is rounded according to the UI.
|
||||||
|
|
|
@ -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
|
||||||
|
@ -136,6 +136,14 @@ 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 = 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.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 \
|
||||||
|
@ -147,7 +155,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()
|
||||||
|
|
||||||
|
@ -1126,8 +1135,23 @@ class Terminal(Gtk.VBox):
|
||||||
widget.disconnect(connec)
|
widget.disconnect(connec)
|
||||||
widget._draw_data = None
|
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):
|
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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue