fix background image profile preferences ui

This commit is contained in:
Matt Rose 2020-11-19 11:24:33 -05:00
parent ebc266e554
commit 18ed95abe7
4 changed files with 93 additions and 109 deletions

View File

@ -360,11 +360,6 @@
<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>
@ -2885,6 +2880,60 @@
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkRadioButton" id="image_radiobutton">
<property name="label" translatable="yes">Background Image</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<property name="group">solid_radiobutton</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</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 File:</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> <child>
<object class="GtkBox" id="darken_background_vbox"> <object class="GtkBox" id="darken_background_vbox">
<property name="visible">True</property> <property name="visible">True</property>
@ -2895,7 +2944,7 @@
<object class="GtkLabel" id="darken_background_scale_label"> <object class="GtkLabel" id="darken_background_scale_label">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes">S_hade transparent background:</property> <property name="label" translatable="yes">S_hade background:</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="mnemonic_widget">darken_background_scale</property> <property name="mnemonic_widget">darken_background_scale</property>
<property name="xalign">0</property> <property name="xalign">0</property>
@ -2968,44 +3017,6 @@
</packing> </packing>
</child> </child>
</object> </object>
<packing>
<property name="expand">False</property>
<property name="fill">True</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> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
@ -3017,62 +3028,22 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<object class="GtkLabel"> <placeholder/>
<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>
<child> <child>
<object class="GtkLabel"> <placeholder/>
<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>
<child> <child>
<object class="GtkScale" id="background_image_shading_scale"> <placeholder/>
<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>
<child> <child>
<object class="GtkLabel"> <placeholder/>
<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> </child>
</object> </object>
<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">5</property> <property name="position">6</property>
</packing> </packing>
</child> </child>
</object> </object>
@ -4185,4 +4156,9 @@ Much of the behavior of Terminator is based on GNOME Terminal, and we are adding
<widget name="encoding_combobox"/> <widget name="encoding_combobox"/>
</widgets> </widgets>
</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>
</interface> </interface>

View File

@ -633,14 +633,14 @@ class PrefsEditor:
guiget('solid_radiobutton').set_active(True) guiget('solid_radiobutton').set_active(True)
elif self.config['background_type'] == 'transparent': elif self.config['background_type'] == 'transparent':
guiget('transparent_radiobutton').set_active(True) guiget('transparent_radiobutton').set_active(True)
elif self.config['background_type'] == 'image':
guiget('image_radiobutton').set_active(True)
self.update_background_tab() self.update_background_tab()
# 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 = guiget('background_image_file')
widget.set_filename(self.config['background_image']) 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
@ -945,10 +945,6 @@ class PrefsEditor:
self.config['background_image'] = widget.get_filename() self.config['background_image'] = widget.get_filename()
self.config.save() 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.
@ -1507,13 +1503,21 @@ class PrefsEditor:
backtype = None backtype = None
imagewidget = guiget('image_radiobutton') imagewidget = guiget('image_radiobutton')
transwidget = guiget('transparent_radiobutton') transwidget = guiget('transparent_radiobutton')
if transwidget.get_active() == True:
if imagewidget.get_active() == True:
backtype = 'image'
elif transwidget.get_active() == True:
backtype = 'transparent' backtype = 'transparent'
else: else:
backtype = 'solid' backtype = 'solid'
self.config['background_type'] = backtype self.config['background_type'] = backtype
self.config.save() self.config.save()
if backtype == 'image':
guiget('background_image_file').set_sensitive(True)
else:
guiget('background_image_file').set_sensitive(False)
if backtype in ('transparent', 'image'): if backtype in ('transparent', 'image'):
guiget('darken_background_scale').set_sensitive(True) guiget('darken_background_scale').set_sensitive(True)
else: else:

View File

@ -36,6 +36,7 @@ class Overpaint(Vte.Terminal):
def __init__(self): def __init__(self):
Vte.Terminal.__init__(self) Vte.Terminal.__init__(self)
self.config = Config() self.config = Config()
### inactive_color_offset is the opposite of alpha level
self.dim_p = float(self.config['inactive_color_offset']) self.dim_p = float(self.config['inactive_color_offset'])
self.dim_l = round(1.0 - self.dim_p,3) self.dim_l = round(1.0 - self.dim_p,3)
def dim(self,b): def dim(self,b):
@ -158,15 +159,16 @@ class Terminal(Gtk.VBox):
self.queue_draw() self.queue_draw()
self.background_image = None self.background_image = None
if self.config['background_image'] != '': if self.config['background_image'] != '':
self.vte.set_clear_background(False)
self.vte.connect("draw",self.background_draw)
try: try:
self.background_image = GdkPixbuf.Pixbuf.new_from_file(self.config['background_image']) self.background_image = GdkPixbuf.Pixbuf.new_from_file(self.config['background_image'])
except Exception: self.vte.set_clear_background(False)
pass self.vte.connect("draw",self.background_draw)
except Exception as e:
self.background_image = None
self.vte.set_clear_background(True)
err('error loading background image: %s' % e)
self.background_alpha = self.config['background_alpha'] self.background_alpha = self.config['background_darkness']
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 \
@ -746,7 +748,7 @@ class Terminal(Gtk.VBox):
self.bgcolor = Gdk.RGBA() self.bgcolor = Gdk.RGBA()
self.bgcolor.parse(self.config['background_color']) self.bgcolor.parse(self.config['background_color'])
if self.config['background_type'] == 'transparent': if self.config['background_type'] == 'transparent' or self.config['background_type'] == 'image':
self.bgcolor.alpha = self.config['background_darkness'] self.bgcolor.alpha = self.config['background_darkness']
else: else:
self.bgcolor.alpha = 1 self.bgcolor.alpha = 1
@ -1114,10 +1116,10 @@ class Terminal(Gtk.VBox):
widget._draw_data = None widget._draw_data = None
def background_draw(self, widget, cr): def background_draw(self, widget, cr):
if not self.background_image: if not self.config['background_type'] == 'image' or not self.background_image:
return(False) return(False)
over = self.bgcolor #if not self.background_image:
over.alpha = self.background_alpha # return(False)
rect = self.vte.get_allocation() rect = self.vte.get_allocation()
xratio = float(rect.width) / float(self.background_image.get_width()) xratio = float(rect.width) / float(self.background_image.get_width())
yratio = float(rect.height) / float(self.background_image.get_height()) yratio = float(rect.height) / float(self.background_image.get_height())
@ -1125,7 +1127,7 @@ class Terminal(Gtk.VBox):
cr.scale(xratio,yratio) cr.scale(xratio,yratio)
Gdk.cairo_set_source_pixbuf(cr, self.background_image, 0, 0) Gdk.cairo_set_source_pixbuf(cr, self.background_image, 0, 0)
cr.paint() cr.paint()
Gdk.cairo_set_source_rgba(cr,over) Gdk.cairo_set_source_rgba(cr,self.bgcolor)
cr.paint() cr.paint()
cr.restore() cr.restore()

View File

@ -439,7 +439,9 @@ class Terminator(Borg):
else: else:
bgcolor = Gdk.RGBA() bgcolor = Gdk.RGBA()
bgcolor = profiles[profile]['background_color'] bgcolor = profiles[profile]['background_color']
if profiles[profile]['background_type'] == 'transparent': if profiles[profile]['background_type'] == 'image':
backgound_image = profiles[profile]['background_image']
if profiles[profile]['background_type'] == 'transparent' or profiles[profile]['background_type'] == 'image':
bgalpha = profiles[profile]['background_darkness'] bgalpha = profiles[profile]['background_darkness']
else: else:
bgalpha = "1" bgalpha = "1"
@ -631,4 +633,4 @@ class Terminator(Borg):
return(layout) return(layout)
# vim: set expandtab ts=4 sw=4: # vim: set expandtab ts=4 sw=4: