Skip to content

Commit

Permalink
cinnamon-dynamic-wallpaper@TobiZog: Cinnamon Dynamic Wallpaper v2.4 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiZog authored Feb 15, 2024
1 parent 4c9c83e commit 021e3c5
Show file tree
Hide file tree
Showing 18 changed files with 671 additions and 173 deletions.
11 changes: 9 additions & 2 deletions cinnamon-dynamic-wallpaper@TobiZog/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
time_bar_polylines.svg
*.glade~
*.glade#
*.txt
*.json
*.tar.gz
extracted_images/
selected/
__pycache__
time_bar.svg
__pycache__
time_bar_polylines.svg
6 changes: 6 additions & 0 deletions cinnamon-dynamic-wallpaper@TobiZog/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Version 2.4
- Adding Login window support
- Adding Russian translation (Thanks to blogdron)
- Adding Hungarian translation (Thanks to vajdao)
- Bugfix: Time period calculation on locations near the dateline, like Japan

# Version 2.3
- Adding Dutch translation
- Adding German translation
Expand Down
11 changes: 11 additions & 0 deletions cinnamon-dynamic-wallpaper@TobiZog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,14 @@ This extension switches the background image of your Cinnamon desktop multiple t
## Preferences Window
Because of the lack of configuration options in the standard Cinnamon configuration system for extensions offers this extension a custom preference window.
All configuration will be handled there. You can choose between included image sets, a HEIC file or a folder source and set the image to ten different daytime periods. Time periods will be estimated via network, custom coordinations or custom time periods. Some behaviour preferences (strech image, fill empty background with gradient color) are also here.
---
## Contribute
### Translation
You want to contribute a language which isn't supported yet? Here is how to do:

1. Fork the cinnamon-spices-extensions project: https://github.com/linuxmint/cinnamon-spices-extensions
2. Pull the repository
3. Open `cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/po/[email protected]` with a po-tool like poedit (https://poedit.net/).
4. Create a new translation in your language
5. Push the changes to your repository
6. Create a pull request
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @name Cinnamon-Dynamic-Wallpaper
* @alias TobiZog
* @since 2023-05-17
* @name Cinnamon-Dynamic-Wallpaper
* @alias TobiZog
* @since 2023-05-17
*
* @description Main application file
*/
Expand Down Expand Up @@ -77,7 +77,7 @@ CinnamonDynamicWallpaperExtension.prototype = {

// Hide the notification on system restart
this.settings.setValue("first_start", false)
this.settings.setValue("source_folder", DIRECTORY["path"] + "/images/included_image_sets/lakeside/")
this.settings.setValue("source_folder", DIRECTORY["path"] + "/res/images/included_image_sets/lakeside/")
}

// Start the main loop, checks in fixed time periods the
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"picture_aspect": {
"type": "generic",
"default": "scaled"
"default": "zoom"
},
"dynamic_background_color": {
"type": "generic",
Expand Down Expand Up @@ -130,5 +130,9 @@
"period_9_custom_start_time": {
"type": "generic",
"default": "21:00"
},
"login_image": {
"type": "generic",
"default": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
elif sys.argv[1] == "loop":
# Run the methods which updates the data
view_model = Main_View_Model()
view_model.set_login_image()
view_model.refresh_image()
view_model.set_background_gradient()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from gi.repository import Gio, Gdk

# Packages
import os, time, gi, locale
import os, time, locale, subprocess, getpass
from PIL import Image

# Local scripts
Expand Down Expand Up @@ -121,8 +121,6 @@ def string_to_time_converter(self, raw_str: str) -> time:
hour = raw_str[0:raw_str.find(":")]
minute = raw_str[raw_str.find(":") + 1:]

time(1, 2)

return time(hour=int(hour), minute=int(minute))


Expand Down Expand Up @@ -183,9 +181,20 @@ def refresh_image(self):
self.current_image_uri = self.cinnamon_prefs.source_folder + self.cinnamon_prefs.period_images[i]
break

# Set the background
# Update the background
self.background_settings['picture-uri'] = "file://" + self.current_image_uri

# Update the login_image
if self.cinnamon_prefs.login_image:
# Create the folder in /tmp
directory = '/usr/share/pixmaps/cinnamon_dynamic_wallpaper'

if not os.path.isdir(directory):
subprocess.run(['pkexec', 'install', '-o', getpass.getuser(), '-d', directory])

# Copy the current image to the temp folder for the login screen
os.system("cp " + self.current_image_uri + " " + directory + "/login_image.jpg")

# Set background stretching
self.background_settings['picture-options'] = self.cinnamon_prefs.picture_aspect

Expand Down Expand Up @@ -269,3 +278,53 @@ def set_background_gradient(self):
except:
self.background_settings['primary-color'] = "#000000"
self.background_settings['secondary-color'] = "#000000"


def set_login_image(self):
""" Writes a path to file in /tmp/cinnamon_dynamic_wallpaper to display the wallpaper on the login screen
"""
# New config file content
file_content = ""

# Location of the config file
file_location = self.WORKING_DIR + "/slick-greeter.conf"

if self.cinnamon_prefs.login_image:
self.refresh_image()

if os.path.isfile("/etc/lightdm/slick-greeter.conf"):
# File already exists, make a copy of the config
with open("/etc/lightdm/slick-greeter.conf", "r") as conf_file:
for line in conf_file.readlines():
if not line.startswith("background"):
file_content += line
elif line.endswith("cinnamon_dynamic_wallpaper/login_image.jpg"):
# Skip the configuration. It's already perfect!
return

else:
# File doesn't exists
file_content = "[Greeter]\n"

file_content += "background=/usr/share/pixmaps/cinnamon_dynamic_wallpaper/login_image.jpg"

# Create the file
with open(file_location, "w") as conf_file:
conf_file.write(file_content)
conf_file.close()

# Move it to /etc/lightdm
if os.path.isfile("/etc/lightdm/slick-greeter.conf"):
subprocess.call(['pkexec', 'mv', '/etc/lightdm/slick-greeter.conf', '/etc/lightdm/slick-greeter.conf.backup'])
subprocess.call(['pkexec', 'mv', file_location, '/etc/lightdm/'])
else:
subprocess.call(['pkexec', 'mv', file_location, '/etc/lightdm/'])

else:
self.reset_login_image()


def reset_login_image(self):
if os.path.isfile('/etc/lightdm/slick-greeter.conf.backup'):
subprocess.call(['pkexec', 'rm', '/etc/lightdm/slick-greeter.conf'])
subprocess.call(['pkexec', 'mv', '/etc/lightdm/slick-greeter.conf.backup', '/etc/lightdm/slick-greeter.conf'])
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self) -> None:
self.load_preferences()


def extract_json(self, parameter: str) -> str:
def extract_json(self, parameter: str) -> any:
""" Get a parameter from the json dictionary safely
Args:
Expand Down Expand Up @@ -52,13 +52,13 @@ def load_preferences(self):
self.extract_json('period_9_image')
]

self.period_source =self.extract_json('period_source')
self.location_refresh_intervals =self.extract_json('location_refresh_intervals')
self.network_location_provider =self.extract_json('network_location_provider')
self.latitude_auto =self.extract_json('latitude_auto')
self.longitude_auto =self.extract_json('longitude_auto')
self.latitude_custom =self.extract_json('latitude_custom')
self.longitude_custom =self.extract_json('longitude_custom')
self.period_source = self.extract_json('period_source')
self.location_refresh_intervals = self.extract_json('location_refresh_intervals')
self.network_location_provider = self.extract_json('network_location_provider')
self.latitude_auto = self.extract_json('latitude_auto')
self.longitude_auto = self.extract_json('longitude_auto')
self.latitude_custom = self.extract_json('latitude_custom')
self.longitude_custom = self.extract_json('longitude_custom')

self.period_custom_start_time = [
self.extract_json('period_0_custom_start_time'),
Expand All @@ -73,6 +73,8 @@ def load_preferences(self):
self.extract_json('period_9_custom_start_time')
]

self.login_image = self.extract_json('login_image')


def value_to_json(self, parameter: str, value: str):
""" Storing safely a value to the dictionary
Expand Down Expand Up @@ -127,6 +129,7 @@ def store_preferences(self):
self.value_to_json('period_7_custom_start_time', self.period_custom_start_time[7])
self.value_to_json('period_8_custom_start_time', self.period_custom_start_time[8])
self.value_to_json('period_9_custom_start_time', self.period_custom_start_time[9])
self.value_to_json('login_image', self.login_image)


# Write to file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from math import pi, sin, asin, acos, cos, floor, atan, tan
from datetime import datetime, timezone, time
from datetime import datetime, timezone, time, timedelta


class Suntimes:
Expand Down Expand Up @@ -55,7 +55,7 @@ def calc_sun_events(self):
civial_dusk_start = self.calc_sunrise_sunset_time(False)
night_start = self.calc_sunrise_sunset_time(False, 96)

light_period_duration = (sunset_start - morning_start) / 8
light_period_duration = timedelta(seconds=(sunset_start - morning_start).seconds / 8)

noon_start = morning_start + 3 * light_period_duration
afternoon_start = morning_start + 5 * light_period_duration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def __init__(self) -> None:
# Page 3: Behaviour
self.cb_picture_aspect: Gtk.ComboBox = self.builder.get_object("cb_picture_aspect")
self.sw_dynamic_background_color: Gtk.Switch = self.builder.get_object("sw_dynamic_background_color")
self.sw_login_image: Gtk.Switch = self.builder.get_object("sw_login_image")


def show(self):
Expand Down Expand Up @@ -178,6 +179,7 @@ def show(self):
self.add_items_to_combo_box(self.cb_picture_aspect, self.view_model.picture_aspects)
self.set_active_combobox_item(self.cb_picture_aspect, self.view_model.cinnamon_prefs.picture_aspect)
self.sw_dynamic_background_color.set_active(self.view_model.cinnamon_prefs.dynamic_background_color)
self.sw_login_image.set_active(self.view_model.cinnamon_prefs.login_image)


# Show the main window
Expand Down Expand Up @@ -693,6 +695,16 @@ def on_sw_dynamic_background_color_state_set(self, _: Gtk.Switch, state: bool):
"""
self.view_model.cinnamon_prefs.dynamic_background_color = state


def on_sw_login_image_state_set(self, _: Gtk.Switch, state: bool):
""" User switches login background image on or off
Args:
_ (Gtk.Switch): Used Switch
state (bool): Current state
"""
self.view_model.cinnamon_prefs.login_image = state


# About

Expand Down Expand Up @@ -747,6 +759,7 @@ def on_apply(self, *args):
# Use the new settings
self.view_model.refresh_image()
self.view_model.set_background_gradient()
self.view_model.set_login_image()


def on_destroy(self, *args):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"uuid": "cinnamon-dynamic-wallpaper@TobiZog",
"name": "Cinnamon Dynamic Wallpaper",
"description": "Cinnamon extension for dynamic desktop backgrounds based on time and location",
"version": "2.3",
"version": "2.4",
"multiversion": true,
"cinnamon-version": [
"5.4",
Expand Down
Loading

0 comments on commit 021e3c5

Please sign in to comment.