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

Adds support for background changing based on light/dark #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions automathemely/autoth_tools/envspecific.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def get_installed_themes(desk_env):

if desk_env == 'gnome':
types['shell'] = True
types['background'] = True

elif desk_env == 'kde':
types['lookandfeel'] = True
Expand Down Expand Up @@ -157,6 +158,19 @@ def get_installed_themes(desk_env):

themes['shell'] = [(t,) for t in sort_remove_dupes(t_list)]

if types['background']:
from gi.repository import Gio
gsettings = Gio.Settings.new("org.gnome.desktop.background")

current_background = ""
try:
# this stores file path in the format of file:///home/xxx/xxx.jpg
current_background = gsettings["picture-uri"]
except KeyError:
pass

themes['background'] = current_background

return themes


Expand Down Expand Up @@ -352,3 +366,12 @@ def set_theme(desk_env, t_type, theme):
from gi.repository import Gio
cinnamon_settings = Gio.Settings.new('org.cinnamon.theme')
cinnamon_settings['name'] = theme

elif t_type == 'background':
from gi.repository import Gio
gnome_gsettings = Gio.Settings.new("org.gnome.desktop.background")
# Perform some sane checking
if theme:
if not theme.startswith("file://"):
theme = "file://{}".format(theme)
gnome_gsettings["picture-uri"] = theme
36 changes: 36 additions & 0 deletions automathemely/autoth_tools/settsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ def setup_all(self):
step_increment=1, page_increment=5, page_size=0), 1, 0)

elif isinstance(obj, Gtk.Entry):
if val is None and keys[-1] == "background":
# try to load current background from system settings
if self.system_themes and "background" in self.system_themes:
val = self.system_themes["background"]

obj.set_text(try_or_default_type(val, str))

elif isinstance(obj, Gtk.Switch):
Expand Down Expand Up @@ -405,6 +410,37 @@ def on_remove_scripts_row(self, button, *args):
add_button = self.builder.get_object('rowadd_button')
add_button.set_sensitive(True)

def on_bg_choose_file(self, button, *args):
button_id = Gtk.Buildable.get_name(button)
sub_entry = split_id_delimiter(button_id)[1]
open_dialog = Gtk.FileChooserDialog("Pick a background", None,
Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT))
# extract current text in textbox
entry = self.builder.get_object(sub_entry)
cur_filename = entry.get_text()
# set it as the default chosen file in dialog
open_dialog.set_file(Gio.File.new_for_path(cur_filename))

open_dialog.set_local_only(True)
open_dialog.set_modal(True)
open_dialog.connect("response", self.open_response_cb, sub_entry)
open_dialog.show()

def open_response_cb(self, dialog, response_id, data):
entry = self.builder.get_object(data)

# chosen file
if response_id == Gtk.ResponseType.ACCEPT:
entry.set_text(dialog.get_filename())

# clears it
elif response_id == Gtk.ResponseType.CANCEL:
entry.set_text("")

dialog.destroy()

def on_add_scripts_row(self, button, *args):
active_listbox_page = self.builder.get_object('scripts_notebook').get_current_page()

Expand Down
156 changes: 156 additions & 0 deletions automathemely/lib/manager_gui.glade
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,84 @@
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">8</property>
<property name="margin_bottom">8</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="column_spacing">12</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="label" translatable="yes">Background</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">8</property>
<property name="margin_bottom">8</property>
<property name="spacing">12</property>
<child>
<object class="GtkEntry" id="*themes.gnome.light.background">
<property name="visible">True</property>
<property name="can_focus">True</property>
<signal name="changed" handler="on_any_change" 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" id="bgchoose_button~*themes.gnome.light.background">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">end</property>
<signal name="clicked" handler="on_bg_choose_file" swapped="no"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-file</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child type="tab">
Expand Down Expand Up @@ -615,6 +693,84 @@
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">8</property>
<property name="margin_bottom">8</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="column_spacing">12</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="label" translatable="yes">Background</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">8</property>
<property name="margin_bottom">8</property>
<property name="spacing">12</property>
<child>
<object class="GtkEntry" id="*themes.gnome.dark.background">
<property name="visible">True</property>
<property name="can_focus">True</property>
<signal name="changed" handler="on_any_change" 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" id="bgchoose_button~*themes.gnome.dark.background">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">end</property>
<signal name="clicked" handler="on_bg_choose_file" swapped="no"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-file</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="position">1</property>
Expand Down