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

Add background image to guake #1604

Merged
merged 12 commits into from
Sep 13, 2021
10 changes: 10 additions & 0 deletions guake/data/org.guake.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@
<summary>Window vertical alignment.</summary>
<description>Place Guake at: 0: top, 1: bottom</description>
</key>
<key name="background-image-file" type="s">
<default>''</default>
<summary>Background image filename.</summary>
<description>When setup, the selected background image will show on guake</description>
</key>
<key name="background-image-layout-mode" type="i">
<default>0</default>
<summary>Background image layout mode.</summary>
<description>To select which layout mode want to use for background image.</description>
</key>
<key name="use-scrollbar" type="b">
<default>true</default>
<summary>Sets the scrollbar visibility.</summary>
Expand Down
111 changes: 111 additions & 0 deletions guake/data/prefs.glade
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@
<!-- Generated with glade 3.22.1 -->
<interface domain="guake">
<requires lib="gtk+" version="3.18"/>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-clear</property>
</object>
<object class="GtkListStore" id="image_layout_mode_liststore">
<columns>
<!-- column-name label -->
<column type="gchararray"/>
<!-- column-name ImageLayoutMode -->
<column type="gint"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">Scale</col>
<col id="1">0</col>
</row>
<row>
<col id="0" translatable="yes">Tile</col>
<col id="1">1</col>
</row>
<row>
<col id="0" translatable="yes">Center</col>
<col id="1">2</col>
</row>
<row>
<col id="0" translatable="yes">Stretch</col>
<col id="1">3</col>
</row>
</data>
</object>
<object class="GtkAdjustment" id="max_tab_name_length_adj">
<property name="upper">1000</property>
<property name="step_increment">1</property>
Expand Down Expand Up @@ -1859,6 +1890,86 @@
<property name="top_attach">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="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkFileChooserButton" id="background_image_filechooser">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes"/>
<signal name="file-set" handler="on_background_image_file_chooser_file_changed" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">image1</property>
<signal name="clicked" handler="on_background_image_file_remove_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="background_image_layout_mode">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="model">image_layout_mode_liststore</property>
<property name="active">0</property>
<signal name="changed" handler="on_background_image_layout_mode_changed" swapped="no"/>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
</packing>
</child>
</object>
</child>
</object>
Expand Down
15 changes: 15 additions & 0 deletions guake/gsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Boston, MA 02110-1301 USA
"""
import logging
import os

import gi

Expand Down Expand Up @@ -63,6 +64,10 @@ def __init__(self, guake_inst):
settings.general.onChangedValue("window-horizontal-displacement", self.alignment_changed)
settings.style.onChangedValue("cursor-blink-mode", self.cursor_blink_mode_changed)
settings.style.onChangedValue("cursor-shape", self.cursor_shape_changed)
settings.general.onChangedValue("background-image-file", self.background_image_file_changed)
settings.general.onChangedValue(
"background-image-layout-mode", self.background_image_layout_mode_changed
)

settings.general.onChangedValue("use-scrollbar", self.scrollbar_toggled)
settings.general.onChangedValue("history-size", self.history_size_changed)
Expand Down Expand Up @@ -164,6 +169,16 @@ def cursor_shape_changed(self, settings, key, user_data):
for term in terminals:
term.set_property("cursor-shape", settings.get_int(key))

def background_image_file_changed(self, settings, key, user_data):
"""Called when the background image file settings has been changed"""
filename = settings.get_string(key)
if not filename or os.path.exists(filename):
self.guake.background_image_manager.load_from_file(settings.get_string(key))

def background_image_layout_mode_changed(self, settings, key, user_data):
"""Called when the background image layout mode settings has been changed"""
self.guake.background_image_manager.layout_mode = settings.get_int(key)

def scrollbar_toggled(self, settings, key, user_data):
"""If the gconf var use_scrollbar be changed, this method will
be called and will show/hide scrollbars of all terminals open.
Expand Down
16 changes: 16 additions & 0 deletions guake/guake_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
from guake.simplegladeapp import SimpleGladeApp
from guake.theme import patch_gtk_theme
from guake.theme import select_gtk_theme
from guake.utils import BackgroundImageManager
from guake.utils import FullscreenManager
from guake.utils import HidePrevention
from guake.utils import RectCalculator
Expand Down Expand Up @@ -167,6 +168,9 @@ def load_schema():
self.pending_restore_page_split = []
self._failed_restore_page_split = []

# BackgroundImageManager
self.background_image_manager = BackgroundImageManager(self.window)

# FullscreenManager
self.fullscreen_manager = FullscreenManager(self.settings, self.window, self)

Expand Down Expand Up @@ -812,6 +816,15 @@ def load_config(self, terminal_uuid=None):
self.settings.styleFont.triggerOnChangedValue(
self.settings.styleFont, "allow-bold", user_data=user_data
)
self.settings.general.triggerOnChangedValue(self.settings.general, "background-image-file")
self.settings.general.triggerOnChangedValue(
self.settings.general, "background-image-layout-mode"
)
self.settings.style.triggerOnChangedValue(self.settings.style, "cursor-shape")
self.settings.styleFont.triggerOnChangedValue(self.settings.styleFont, "style")
self.settings.styleFont.triggerOnChangedValue(self.settings.styleFont, "palette")
self.settings.styleFont.triggerOnChangedValue(self.settings.styleFont, "palette-name")
self.settings.styleFont.triggerOnChangedValue(self.settings.styleFont, "allow-bold")
self.settings.styleBackground.triggerOnChangedValue(
self.settings.styleBackground, "transparency", user_data=user_data
)
Expand Down Expand Up @@ -1433,3 +1446,6 @@ def restore_tabs(self, filename="session.json", suppress_notify=False):
notifier.showMessage(_("Guake Terminal"), _("Your tabs has been restored!"), filename)

log.info("Guake tabs restored from %s", session_file)

def load_background_image(self, filename):
self.background_image_manager.load_from_file(filename)
7 changes: 7 additions & 0 deletions guake/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ def new_page(self, directory=None, position=None):
# this is needed to initially set the last_terminal_focused,
# one could also call terminal.get_parent().on_terminal_focus()
self.terminal_attached(terminal)

if self.guake:
# Attack background image draw callback to root terminal box
root_terminal_box.connect_after("draw", self.guake.background_image_manager.draw)
return root_terminal_box, page_num, terminal

def terminal_spawn(self, directory=None):
Expand Down Expand Up @@ -530,6 +534,9 @@ def set_workspace(self, index: int):
# Restore pending page terminal split
notebook.guake.restore_pending_terminal_split()

# Restore config to workspace
notebook.guake.load_config()

def set_notebooks_tabbar_visible(self, v):
for nb in self.iter_notebooks():
nb.set_tabbar_visible(v)
Expand Down
23 changes: 23 additions & 0 deletions guake/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,20 @@ def on_font_style_font_set(self, fbtn):
"""Changes the value of font_style in dconf"""
self.settings.styleFont.set_string("style", fbtn.get_font_name())

def on_background_image_file_chooser_file_changed(self, fc):
self.settings.general.set_string(
"background-image-file", fc.get_filename() if fc.get_filename() else ""
)

def on_background_image_file_remove_clicked(self, btn):
filechooser = self.prefDlg.get_widget("background_image_filechooser")
filechooser.unselect_all()
self.on_background_image_file_chooser_file_changed(filechooser)

def on_background_image_layout_mode_changed(self, combo):
val = combo.get_active()
self.settings.general.set_int("background-image-layout-mode", val)

def on_transparency_value_changed(self, hscale):
"""Changes the value of background_transparency in dconf"""
value = hscale.get_value()
Expand Down Expand Up @@ -1139,6 +1153,15 @@ def load_configs(self):
value = self.settings.styleFont.get_boolean("bold-is-bright")
self.get_widget("bold_is_bright").set_active(value)

# background image file
filename = self.settings.general.get_string("background-image-file")
if os.path.exists(filename):
self.get_widget("background_image_filechooser").set_filename(filename)

# background image layout mode
value = self.settings.general.get_int("background-image-layout-mode")
self.get_widget("background_image_layout_mode").set_active(value)

# palette
self.fill_palette_names()
value = self.settings.styleFont.get_string("palette-name")
Expand Down
Loading