Skip to content

Commit

Permalink
Cinnamon Dynamic Wallpaper v.1.2 (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiZog authored Jul 13, 2023
1 parent c59a593 commit 6c2a0a6
Show file tree
Hide file tree
Showing 96 changed files with 187 additions and 87 deletions.
7 changes: 7 additions & 0 deletions cinnamon-dynamic-wallpaper@TobiZog/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Version 1.2
- Compatibility with Cinnamon 4.8 and higher
- Notification on first start
- Bugfix: No more restart needed after first enable
- Load at first start a predefined dynamic wallpaper
- More informations in the settings

# Version 1.1
- Compatibility with Cinnamon 5.4 and 5.8
- Two new image sets
Expand Down
19 changes: 3 additions & 16 deletions cinnamon-dynamic-wallpaper@TobiZog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Based on a location, this extension calculates the periods of a day and switches
- Offline sun angles estimation

### Tested Cinnamon versions
- 4.8 (Mint 20.1)
- 5.0 (Mint 20.2)
- 5.2 (Mint 20.3)
- 5.4 (Mint 21)
- 5.6 (Mint 21.1)
- 5.8 (Mint 21.2)
Expand Down Expand Up @@ -43,19 +46,3 @@ Based on a location, this extension calculates the periods of a day and switches

## Image Configurator
The Cinnamon Dynamic Wallpaper extension offers an integrated image configuration assistant. Here, you can choose an included image set or import a HEIC-file from your system. You have to choose the images for the time periods after the import.


## Included image sets
The image sets are from https://github.com/adi1090x/dynamic-wallpaper

| Aurora | Beach | Bitday |
| ------ | ----- | ------ |
| ![](files/cinnamon-dynamic-wallpaper@TobiZog/images/included_image_sets/aurora/5.jpg) | ![](files/cinnamon-dynamic-wallpaper@TobiZog/images/included_image_sets/beach/4.jpg) | ![](files/cinnamon-dynamic-wallpaper@TobiZog/images/included_image_sets/bitday/4.jpg) |

| Cliffs | Gradient | Lakeside |
| -------- | --------- | ------ |
| ![](files/cinnamon-dynamic-wallpaper@TobiZog/images/included_image_sets/cliffs/4.jpg) | ![](files/cinnamon-dynamic-wallpaper@TobiZog/images/included_image_sets/gradient/4.jpg) | ![](files/cinnamon-dynamic-wallpaper@TobiZog/images/included_image_sets/lakeside/4.jpg) |

| Mountains | Sahara |
| --------- | ------ |
| ![](files/cinnamon-dynamic-wallpaper@TobiZog/images/included_image_sets/mountains/4.jpg) | ![](files/cinnamon-dynamic-wallpaper@TobiZog/images/included_image_sets/sahara/4.jpg) |
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os
import windowHandler

if __name__ == "__main__":
wh = windowHandler.WindowHandler(os.path.expanduser("~") + "/.cinnamon/configs/cinnamon-dynamic-wallpaper@TobiZog/[email protected]")
wh.showMainWindow()
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,43 @@ CinnamonDynamicWallpaperExtension.prototype = {
this.bindSettings("etr_img_night_twilight", "img_night_twilight", this.setImageToTime)
this.bindSettings("etr_img_night", "img_night", this.setImageToTime)
this.bindSettings("tv_times", "tvTimes")

// Check for the first startup
if (this.settings.getValue("first_start")) {
// Welcome notification
this.showNotification("Welcome to Cinnamon Dynamic Wallpaper",
"Check the preferences to choose a dynamic wallpaper", true)

// Hide the notification on system restart
this.settings.setValue("first_start", false)

// Create the folder for the selected images
Util.spawnCommandLine("mkdir " + DIRECTORY.path + "/images/selected/")

// Link the default wallpaper to the folder
for (let i = 1; i <= 9; i++) {
Util.spawnCommandLine("ln -s " +
DIRECTORY.path + "/images/included_image_sets/lakeside/" + i + ".jpg " +
DIRECTORY.path + "/images/selected/" + i + ".jpg");
}
}


// Set image initial at desktop wallpaper
this.setImageToTime()

// Start the main loop, checks in fixed time periods the
this._loop()
},


/**
* Binding the settings objects
*
* @param {*} ui_name Name of preference in settings-schema.json
* @param {*} js_name Name of preference in JavaScript
* @param {*} func Function to call on change
*/
bindSettings: function (ui_name, js_name, func = this.on_settings_changed) {
this.settings.bindProperty(
Settings.BindingDirection.IN,
Expand All @@ -88,13 +118,13 @@ CinnamonDynamicWallpaperExtension.prototype = {
)
},


/**
* Displaying a desktop notification
*
* @param {string} title The Title in the notification
* @param {string} text The text in the notification
* @param {boolean} showOpenSettings Display the "Open settings" button in the notification, defaults to false
* @param {boolean} showOpenSettings Display the "Open settings" button in the notification,
* defaults to false
*/
showNotification: function (title, text, showOpenSettings = false) {
let source = new MessageTray.Source(this.uuid);
Expand Down Expand Up @@ -140,7 +170,9 @@ CinnamonDynamicWallpaperExtension.prototype = {
},



/**
* Estimate the right image based on time period of the day
*/
setImageToTime: function() {
let times = suntimes.calcTimePeriod(this.latitude, this.longitude)
let now = new Date()
Expand All @@ -159,7 +191,6 @@ CinnamonDynamicWallpaperExtension.prototype = {

for(let i = 0; i < timesArray.length; i++) {
if(timesArray[i][0] <= now && now <= timesArray[i][1] && i != lastDayTime) {
global.log(PATH + "/res/images/selected/" + imageSet[i])
this.changeWallpaper("file://" + PATH + "/images/selected/" + imageSet[i])

lastDayTime = i
Expand All @@ -184,7 +215,10 @@ CinnamonDynamicWallpaperExtension.prototype = {
"\nNight:\t\t\t\t" + convertToTimeString(timesArray[8][0]) + " - " + convertToTimeString(timesArray[8][1])
},


/**
* Get the location of the user
* Callback for changes in preferences
*/
updateLocation: function () {
if (this.autolocation) {
let loc = location.estimateLocation()
Expand All @@ -203,41 +237,60 @@ CinnamonDynamicWallpaperExtension.prototype = {
},


/**
* Main loop
*/
_loop: function () {
if (looping) {
this.setImageToTime()

if (lastLocationUpdate < new Date().getTime() - this.locationRefreshTime * 1000) {
this.updateLocation()
lastLocationUpdate = new Date()
}

// Refresh every 60 seconds
Mainloop.timeout_add_seconds(60, Lang.bind(this, this._loop));
}
},


/******************** UI Callbacks ********************/

/**
* Callback for settings-schema
* Opens the external heic-importer window
* Opens the external image configurator window
*/
openImageConfigurator: function() {
Util.spawnCommandLine("/usr/bin/env python3 " + DIRECTORY.path + "/image-configurator/image-configurator.py");
Util.spawnCommandLine("/usr/bin/env python3 " +
DIRECTORY.path + "/image-configurator/image-configurator.py");
},


/**
* Callback for settings-schema
* Opens the browser and navigate to the URL of the respository
* Opens the browser and navigates to the URL of the respository
*/
openRepoWebsite: function() {
Util.spawnCommandLine("xdg-open https://github.com/TobiZog/cinnamon-dynamic-wallpaper");
},


/**
* Main loop
* Callback for settings-schema
* Opens the browser and navigates to the URL of the Cinnamon Spices extension
*/
_loop: function() {
if(looping) {
this.setImageToTime()
openSpicesWebsite: function() {
Util.spawnCommandLine("xdg-open https://cinnamon-spices.linuxmint.com/extensions/view/97")
},

if (lastLocationUpdate < new Date().getTime() - this.locationRefreshTime * 1000) {
this.updateLocation()
lastLocationUpdate = new Date()
}

// Refresh every 60 seconds
Mainloop.timeout_add_seconds(60, Lang.bind(this, this._loop));
}

/**
* Callback for settings-schema
* Opens the browser and navigates to the GitHub issue page
*/
openIssueWebsite: function() {
Util.spawnCommandLine("xdg-open https://github.com/TobiZog/cinnamon-dynamic-wallpaper/issues/new")
}
}

Expand Down Expand Up @@ -266,13 +319,6 @@ function enable() {
Util.spawnCommandLine("apturl apt://libheif-examples");
}

// Display the welcome notification on activation
// extension.showNotification(
// APPNAME,
// "Welcome to " + APPNAME + "! Open the settings and configure the extensions.",
// true
// );

return extension;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from enum import Enum

class Source(Enum):
SELECTED = 0 # Load previous selected images
EXTRACT = 1 # Use a custom image set from a heic file
SET = 2 # Use an included image set
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@
<property name="window-position">center</property>
<property name="default-width">1024</property>
<property name="default-height">768</property>
<property name="icon">../icons/icon.png</property>
<property name="icon">../../icon.png</property>
<signal name="destroy" handler="onDestroy" swapped="no"/>
<child>
<object class="GtkStack" id="stack_main">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os
import windowHandler

if __name__ == "__main__":
wh = windowHandler.WindowHandler(os.path.expanduser("~") + "/.config/cinnamon/spices/cinnamon-dynamic-wallpaper@TobiZog/[email protected]")
wh.showMainWindow()
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import gi, os, glob, json, shutil, enum, threading, subprocess
import gi, os, glob, json, shutil, threading, subprocess
from data.enum import Source

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GdkPixbuf

PROJECT_DIR = os.path.dirname(os.path.dirname(__file__)) + "/"
UI_PATH = PROJECT_DIR + "image-configurator/" + "image-configurator.glade"
CONFIGURATOR_DIR = os.path.dirname(os.path.abspath(__file__))
PROJECT_DIR = os.path.dirname(CONFIGURATOR_DIR) + "/"
UI_PATH = CONFIGURATOR_DIR + "/" + "image-configurator.glade"

IMAGE_DIR = PROJECT_DIR + "images/"
IMAGE_EXTRACT_DIR = IMAGE_DIR + "extracted/"
IMAGE_SETS_DIR = IMAGE_DIR + "included_image_sets/"
IMAGE_SELECTED_DIR = IMAGE_DIR + "selected/"

class Source(enum.Enum):
SELECTED = 0 # Load previous selected images
EXTRACT = 1 # Use a custom image set from a heic file
SET = 2 # Use an included image set

class WindowHandler:
def __init__(self, pref_path: str) -> None:

class ImageConfigurator:
def __init__(self) -> None:
########### Class variables ###########
self.pref_path = pref_path

self.pref_vars = [
"etr_img_morning_twilight",
"etr_img_sunrise",
Expand Down Expand Up @@ -106,20 +106,6 @@ def __init__(self) -> None:

self.image_source = Source.SELECTED


# Check for Cinnamon version
# With version 5.6+, the folder of the configuration file was changed
version = subprocess.check_output(["cinnamon", "--version"])
version = version.decode()
version = version[version.find(" "):version.rfind("\n")].strip()

if version.startswith("5.4"):
self.pref_path = os.path.expanduser("~") + \
"/.cinnamon/configs/cinnamon-dynamic-wallpaper@TobiZog/[email protected]"
else:
self.pref_path = os.path.expanduser("~") + \
"/.config/cinnamon/spices/cinnamon-dynamic-wallpaper@TobiZog/[email protected]"

# Load preferences
self.loadFromSettings()

Expand All @@ -139,6 +125,7 @@ def showMainWindow(self):
def loadFromSettings(self):
""" Load preferences from the Cinnamon preference file
"""
#try:
# Load the settings
with open(self.pref_path, "r") as pref_file:
pref_data = json.load(pref_file)
Expand Down Expand Up @@ -173,6 +160,8 @@ def loadFromSettings(self):
self.cb_previews[i].set_active(j)
else:
self.image_source = Source.SET
#except:
# pass


def writeToSettings(self):
Expand Down Expand Up @@ -375,9 +364,4 @@ def onApply(self, *args):
def onDestroy(self, *args):
""" UI signal if the window is closed by the user
"""
Gtk.main_quit()


if __name__ == "__main__":
ic = ImageConfigurator()
ic.showMainWindow()
Gtk.main_quit()
Loading

0 comments on commit 6c2a0a6

Please sign in to comment.