Skip to content

Commit

Permalink
Experimental support for other DE
Browse files Browse the repository at this point in the history
such as Cinnamon, MATE and Pantheon. An incompatible DE should now trigger a warning message instead of crashing the app

A hidden menubar now exists for DE wanting it
  • Loading branch information
maoschanz committed Jul 9, 2019
1 parent 258a4b4 commit 11c7dcf
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 23 deletions.
10 changes: 4 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ def __init__(self, version):

def on_startup(self, *args):
self.build_app_actions()
builder = Gtk.Builder().new_from_resource(UI_PATH + 'menus.ui')
menubar_model = builder.get_object('menu-bar')
self.set_menubar(menubar_model)
if self.prefers_app_menu():
menu = self.build_app_menu()
menu = builder.get_object('app-menu')
self.set_app_menu(menu)

def on_activate(self, *args):
Expand Down Expand Up @@ -112,11 +115,6 @@ def get_valid_file(self, app, path):

############################################################################

def build_app_menu(self):
builder = Gtk.Builder().new_from_resource(UI_PATH + 'menus.ui')
menu = builder.get_object('app-menu')
return menu

def add_action_simple(self, action_name, callback, shortcuts):
action = Gio.SimpleAction.new(action_name, None)
action.connect('activate', callback)
Expand Down
138 changes: 137 additions & 1 deletion src/ui/menus.ui
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,142 @@
</section>
</menu>

<menu id="menu-bar">
<submenu>
<attribute name="label" translatable="yes">File</attribute>
<section>
<item>
<attribute name="action">app.new_window</attribute>
<attribute name="label" translatable="yes">New Window</attribute>
</item>
</section>
<section>
<item>
<attribute name="action">win.open</attribute>
<attribute name="label" translatable="yes">Open</attribute>
</item>
</section>
<section>
<item>
<attribute name="action">win.save</attribute>
<attribute name="label" translatable="yes">Save</attribute>
</item>
<item>
<attribute name="action">win.save_as</attribute>
<attribute name="label" translatable="yes">Save as…</attribute>
</item>
</section>
<section>
<item>
<attribute name="action">win.close</attribute>
<attribute name="label" translatable="yes">Close</attribute>
</item>
<item>
<attribute name="action">app.quit</attribute>
<attribute name="label" translatable="yes">Quit</attribute>
</item>
</section>
</submenu>
<submenu>
<attribute name="label" translatable="yes">Edit</attribute>
<section>
<item>
<attribute name="action">win.add</attribute>
<attribute name="label" translatable="yes">Add pictures</attribute>
</item>
<item>
<attribute name="action">win.add_folder</attribute>
<attribute name="label" translatable="yes">Add a folder</attribute>
</item>
</section>
<section>
<item>
<attribute name="action">win.set_as_wallpaper</attribute>
<attribute name="label" translatable="yes">Set as wallpaper</attribute>
</item>
<submenu id="adjustment-menu">
<attribute name="label" translatable="yes">Background adjustment</attribute>
<section>
<attribute name="label" translatable="yes">Background adjustment</attribute>
<!-- <item> -->
<!-- <attribute name="action">win.pic_options</attribute> -->
<!-- <attribute name="label" translatable="yes">None</attribute> -->
<!-- <attribute name="target">none</attribute> -->
<!-- </item> -->
<item>
<attribute name="action">win.pic_options</attribute>
<attribute name="label" translatable="yes">Mosaic</attribute>
<attribute name="target">wallpaper</attribute>
</item>
<item>
<attribute name="action">win.pic_options</attribute>
<attribute name="label" translatable="yes">Centered</attribute>
<attribute name="target">centered</attribute>
</item>
<item>
<attribute name="action">win.pic_options</attribute>
<attribute name="label" translatable="yes">Scaled</attribute>
<attribute name="target">scaled</attribute>
</item>
<item>
<attribute name="action">win.pic_options</attribute>
<attribute name="label" translatable="yes">Streched</attribute>
<attribute name="target">streched</attribute>
</item>
<item>
<attribute name="action">win.pic_options</attribute>
<attribute name="label" translatable="yes">Zoom</attribute>
<attribute name="target">zoom</attribute>
</item>
<item>
<attribute name="action">win.pic_options</attribute>
<attribute name="label" translatable="yes">Spanned</attribute>
<attribute name="target">spanned</attribute>
</item>
</section>
</submenu>
</section>
</submenu>
<submenu>
<attribute name="label" translatable="yes">View</attribute>
<section>
<attribute name="label" translatable="yes">Wallpaper type</attribute>
<item>
<attribute name="action">win.wallpaper-type</attribute>
<attribute name="label" translatable="yes">Slideshow</attribute>
<attribute name="target">slideshow</attribute>
</item>
<item>
<attribute name="action">win.wallpaper-type</attribute>
<attribute name="label" translatable="yes">Daylight</attribute>
<attribute name="target">daylight</attribute>
</item>
<item>
<attribute name="action">win.wallpaper-type</attribute>
<attribute name="label" translatable="yes">Custom</attribute>
<attribute name="target">custom</attribute>
</item>
</section>
</submenu>
<submenu>
<attribute name="label" translatable="yes">Help</attribute>
<section>
<item>
<attribute name="action">app.shortcuts</attribute>
<attribute name="label" translatable="yes">Keyboard Shortcuts</attribute>
</item>
<item>
<attribute name="action">app.help</attribute>
<attribute name="label" translatable="yes">User manual</attribute>
</item>
<item>
<attribute name="action">app.about</attribute>
<attribute name="label" translatable="yes">About</attribute>
</item>
</section>
</submenu>
</menu>

<menu id="window-menu">
<section>
<item>
Expand Down Expand Up @@ -56,7 +192,7 @@
</section>
</menu>

<menu id="adjustment-menu">
<menu id="eee">
<section>
<attribute name="label" translatable="yes">Background adjustment</attribute>
<!-- <item> -->
Expand Down
67 changes: 51 additions & 16 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def __init__(self, **kwargs):
self.gio_file = None
self._is_saved = True
self.check_24 = False
self.desktop_env = os.getenv('XDG_CURRENT_DESKTOP', 'GNOME')
self.set_show_menubar(False) # TODO show it with Cinnamon ??
# The issue with Cinnamon is with the start time popover

# Used in the "add pictures" file chooser dialog
self.preview_picture = Gtk.Image(margin_right=5)
Expand Down Expand Up @@ -194,26 +197,58 @@ def on_change_wallpaper_options(self, *args):
args[0].set_state(GLib.Variant.new_string(new_value))

def set_wallpaper_option(self, value):
gsettings = Gio.Settings.new('org.gnome.desktop.background')
wp_key = 'picture-options'
gsettings.set_string(wp_key, value)
gsettings, wp_path, wp_options = self.get_setting_keys()
if gsettings is None:
return self.unsupported_desktop()
gsettings.set_string(wp_options, value)

def get_wallpaper_option(self):
gsettings = Gio.Settings.new('org.gnome.desktop.background')
wp_key = 'picture-options'
return gsettings.get_string(wp_key)
gsettings, wp_path, wp_options = self.get_setting_keys()
if gsettings is None:
return self.unsupported_desktop()
return gsettings.get_string(wp_options)

def unsupported_desktop(self):
self.show_notification(_("This desktop environnement isn't supported."))
self.lookup_action('pic_options').set_enabled(False)
return ''

def get_setting_keys(self):
"""Return the setting keys required for the used environnement.
CAUTION: it can return None, which can crash the app if the value is
used anyway for a GSettings operation !"""
gsettings = None
wp_path = None
wp_options = None
if 'Budgie' in self.desktop_env:
pass # Doesn't support XML wallpapers XXX ???
elif 'GNOME' in self.desktop_env or 'Pantheon' in self.desktop_env:
gsettings = Gio.Settings.new('org.gnome.desktop.background')
wp_path = 'picture-uri'
wp_options = 'picture-options'
elif 'Cinnamon' in self.desktop_env:
gsettings = Gio.Settings.new('org.cinnamon.desktop.background')
wp_path = 'picture-uri'
wp_options = 'picture-options'
elif 'MATE' in self.desktop_env:
gsettings = Gio.Settings.new('org.mate.desktop.background')
wp_path = 'picture-filename'
wp_options = 'picture-options'
return gsettings, wp_path, wp_options

def action_set_as_wallpaper(self, *args):
desktop_env = os.getenv('XDG_CURRENT_DESKTOP', 'GNOME')
if 'GNOME' in desktop_env:
gsettings = Gio.Settings.new('org.gnome.desktop.background')
wp_key = 'picture-uri'
elif 'Pantheon' in desktop_env:
gsettings = Gio.Settings.new('org.gnome.desktop.background')
wp_key = 'picture-uri'
else:
self.show_notification(_("This desktop environnement isn't supported."))
gsettings.set_string(wp_key, self.gio_file.get_uri())
gsettings, wp_path, wp_options = self.get_setting_keys()
if gsettings is None:
return self.unsupported_desktop()
if 'GNOME' in self.desktop_env or 'Pantheon' in self.desktop_env:
value = self.gio_file.get_uri()
elif 'MATE' in self.desktop_env:
value = self.gio_file.get_path() # XXX à tester
elif 'Cinnamon' in self.desktop_env:
use_folder = Gio.Settings.new('org.cinnamon.desktop.background.slideshow')
use_folder.set_boolean('slideshow-enabled', False)
value = self.gio_file.get_uri()
gsettings.set_string(wp_path, value)

############################################################################
# Time management ##########################################################
Expand Down

0 comments on commit 11c7dcf

Please sign in to comment.