Skip to content

Commit

Permalink
added settings window, wallpaper selection mode setting
Browse files Browse the repository at this point in the history
  • Loading branch information
GabMus committed Jan 24, 2018
1 parent 2f278be commit 2e97404
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 33 deletions.
102 changes: 70 additions & 32 deletions data/ui/ui.glade
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,6 @@ Author: Gabriele Musco
<!-- interface-name HydraPaper -->
<!-- interface-description Wallpaper manager with multimonitor support for GNOME -->
<!-- interface-authors Gabriele Musco -->
<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="halign">start</property>
<property name="label" translatable="yes">label</property>
</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="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
<object class="GtkFileFilter" id="filefilterFolders">
<mime-types>
<mime-type>inode/directory</mime-type>
Expand Down Expand Up @@ -251,6 +219,76 @@ Author: Gabriele Musco
<placeholder/>
</child>
</object>
<object class="GtkWindow" id="settingsWindow">
<property name="can_focus">False</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property>
<property name="skip_pager_hint">True</property>
<property name="transient_for">window</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<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">12</property>
<property name="margin_bottom">12</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Select wallpapers with a double click</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="wallpaperSelectionModeToggle">
<property name="visible">True</property>
<property name="can_focus">True</property>
<signal name="state-set" handler="on_wallpaperSelectionModeToggle_state_set" 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">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title">Settings</property>
<property name="show_close_button">True</property>
</object>
</child>
</object>
<object class="GtkPopover" id="wallpapersFoldersPopover">
<property name="height_request">250</property>
<property name="can_focus">False</property>
Expand Down
43 changes: 42 additions & 1 deletion hydrapaper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ def __init__(self, **kwargs):
self.monitors_flowbox = self.builder.get_object('monitorsFlowbox')
self.wallpapers_flowbox = self.builder.get_object('wallpapersFlowbox')

self.wallpaper_selection_mode_toggle = self.builder.get_object('wallpaperSelectionModeToggle')

self.wallpaper_selection_mode_toggle.set_active(
not self.configuration['selection_mode'] == 'single'
)

self.wallpapers_flowbox.set_activate_on_single_click(
self.configuration['selection_mode'] == 'single'
)

# This is a list of Monitor objects
self.monitors = MonitorParser.build_monitors_from_dict()
self.wallpapers_list = []
Expand All @@ -100,14 +110,24 @@ def get_config_file(self):
'wallpapers_paths': [
'{0}/Pictures'.format(HOME),
'/usr/share/backgrounds/gnome/'
]
],
'selection_mode': 'single'
}
self.save_config_file(n_config)
return n_config
else:
with open(self.CONFIG_FILE_PATH, 'r') as fd:
config = json.loads(fd.read())
fd.close()
if not 'wallpapers_paths' in config.keys():
config['wallpapers_paths'] = [
'{0}/Pictures'.format(HOME),
'/usr/share/backgrounds/gnome/'
]
self.save_config_file(n_config)
if not 'selection_mode' in config.keys():
config['selection_mode'] = 'single'
self.save_config_file(config)
return config

def remove_wallpaper_folder(self, btn):
Expand Down Expand Up @@ -239,14 +259,25 @@ def do_activate(self):

appMenu = Gio.Menu()
appMenu.append("About", "app.about")
appMenu.append("Settings", "app.settings")
appMenu.append("Quit", "app.quit")

about_action = Gio.SimpleAction.new("about", None)
about_action.connect("activate", self.on_about_activate)
self.builder.get_object("aboutdialog").connect(
"delete-event", lambda *_:
self.builder.get_object("aboutdialog").hide() or True
)
self.add_action(about_action)

settings_action = Gio.SimpleAction.new("settings", None)
settings_action.connect("activate", self.on_settings_activate)
self.builder.get_object("settingsWindow").connect(
"delete-event", lambda *_:
self.builder.get_object("settingsWindow").hide() or True
)
self.add_action(settings_action)

quit_action = Gio.SimpleAction.new("quit", None)
quit_action.connect("activate", self.on_quit_activate)
self.add_action(quit_action)
Expand Down Expand Up @@ -285,6 +316,9 @@ def do_command_line(self, args):
def on_about_activate(self, *args):
self.builder.get_object("aboutdialog").show()

def on_settings_activate(self, *args):
self.builder.get_object("settingsWindow").show()

def on_quit_activate(self, *args):
self.quit()

Expand Down Expand Up @@ -360,6 +394,13 @@ def on_newWallpapersFolderFileChooserButton_file_set(self, filechooser_btn):
self.fill_wallpapers_folders_popover_listbox()
self.refresh_wallpapers_flowbox()

def on_wallpaperSelectionModeToggle_state_set(self, switch, doubleclick_activate):
if doubleclick_activate:
self.configuration['selection_mode'] = 'double'
else:
self.configuration['selection_mode'] = 'single'
self.wallpapers_flowbox.set_activate_on_single_click(not doubleclick_activate)
self.save_config_file(self.configuration)

# Handler functions END

Expand Down

0 comments on commit 2e97404

Please sign in to comment.