Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix background image profile preferences ui #296

Merged
merged 1 commit into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 65 additions & 89 deletions terminatorlib/preferences.glade
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,6 @@
<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 @@ -2885,6 +2880,60 @@
<property name="position">1</property>
</packing>
</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>
<object class="GtkBox" id="darken_background_vbox">
<property name="visible">True</property>
Expand All @@ -2895,7 +2944,7 @@
<object class="GtkLabel" id="darken_background_scale_label">
<property name="visible">True</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="mnemonic_widget">darken_background_scale</property>
<property name="xalign">0</property>
Expand Down Expand Up @@ -2968,44 +3017,6 @@
</packing>
</child>
</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>
<property name="expand">False</property>
<property name="fill">True</property>
Expand All @@ -3017,62 +3028,22 @@
<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>
<placeholder/>
</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>
<placeholder/>
</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>
<placeholder/>
</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>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
<property name="position">6</property>
</packing>
</child>
</object>
Expand Down Expand Up @@ -4185,4 +4156,9 @@ Much of the behavior of Terminator is based on GNOME Terminal, and we are adding
<widget name="encoding_combobox"/>
</widgets>
</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>
18 changes: 11 additions & 7 deletions terminatorlib/prefseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,14 +633,14 @@ def on_palette_click(event, data, widget=widget):
guiget('solid_radiobutton').set_active(True)
elif self.config['background_type'] == 'transparent':
guiget('transparent_radiobutton').set_active(True)
elif self.config['background_type'] == 'image':
guiget('image_radiobutton').set_active(True)
self.update_background_tab()
# 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
Expand Down Expand Up @@ -945,10 +945,6 @@ def on_background_image_file_set(self,widget):
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 Expand Up @@ -1507,13 +1503,21 @@ def update_background_tab(self):
backtype = None
imagewidget = guiget('image_radiobutton')
transwidget = guiget('transparent_radiobutton')
if transwidget.get_active() == True:

if imagewidget.get_active() == True:
backtype = 'image'
elif transwidget.get_active() == True:
backtype = 'transparent'
else:
backtype = 'solid'
self.config['background_type'] = backtype
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'):
guiget('darken_background_scale').set_sensitive(True)
else:
Expand Down
26 changes: 14 additions & 12 deletions terminatorlib/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Overpaint(Vte.Terminal):
def __init__(self):
Vte.Terminal.__init__(self)
self.config = Config()
### inactive_color_offset is the opposite of alpha level
self.dim_p = float(self.config['inactive_color_offset'])
self.dim_l = round(1.0 - self.dim_p,3)
def dim(self,b):
Expand Down Expand Up @@ -158,15 +159,16 @@ def __init__(self):
self.queue_draw()
self.background_image = None
if self.config['background_image'] != '':
self.vte.set_clear_background(False)
self.vte.connect("draw",self.background_draw)

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_clear_background(False)
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_darkness']
self.vte.set_allow_hyperlink(True)
self.vte._draw_data = None
if not hasattr(self.vte, "set_opacity") or \
Expand Down Expand Up @@ -746,7 +748,7 @@ def reconfigure(self, _widget=None):
self.bgcolor = Gdk.RGBA()
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']
else:
self.bgcolor.alpha = 1
Expand Down Expand Up @@ -1114,18 +1116,18 @@ 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:
if not self.config['background_type'] == 'image' or not self.background_image:
return(False)
over = self.bgcolor
over.alpha = self.background_alpha
#if not self.background_image:
# return(False)
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)
Gdk.cairo_set_source_rgba(cr,self.bgcolor)
cr.paint()
cr.restore()

Expand Down
6 changes: 4 additions & 2 deletions terminatorlib/terminator.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ def reconfigure(self):
else:
bgcolor = Gdk.RGBA()
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']
else:
bgalpha = "1"
Expand Down Expand Up @@ -631,4 +633,4 @@ def describe_layout(self):

return(layout)

# vim: set expandtab ts=4 sw=4:
# vim: set expandtab ts=4 sw=4: