Documentation, cleanup
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import os, json
|
||||
|
||||
class Cinnamon_Pref_Handler:
|
||||
""" Class to work with the Cinnamon Extension preference format
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
# Location of the Cinnamon preference file since Cinnamon 5.4
|
||||
self.pref_location = os.path.expanduser("~") + \
|
||||
@@ -54,6 +56,7 @@ class Cinnamon_Pref_Handler:
|
||||
pref_data['period_9_custom_start_time']['value']
|
||||
]
|
||||
|
||||
|
||||
def store_preferences(self):
|
||||
""" Store the values of the Preference object to the JSON file
|
||||
"""
|
||||
|
||||
61
cinnamon-dynamic-wallpaper@TobiZog/5.4/scripts/dialogs.py
Normal file
61
cinnamon-dynamic-wallpaper@TobiZog/5.4/scripts/dialogs.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk
|
||||
|
||||
class Dialogs(Gtk.Window):
|
||||
""" All used Gtk dialogs
|
||||
|
||||
Args:
|
||||
Gtk (Gtk.Window): Window of Gtk application
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
|
||||
def source_folder_dialog(self) -> str:
|
||||
""" Display a FileChooser dialog where the user choose a folder
|
||||
|
||||
Returns:
|
||||
str: Absolute path to the selected folder
|
||||
"""
|
||||
dialog = Gtk.FileChooserDialog(
|
||||
title= "Please choose a folder with images",
|
||||
parent=self,
|
||||
action=Gtk.FileChooserAction.SELECT_FOLDER
|
||||
)
|
||||
|
||||
dialog.add_buttons(
|
||||
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, "Select", Gtk.ResponseType.OK
|
||||
)
|
||||
|
||||
dialog.set_default_size(800, 400)
|
||||
|
||||
response = dialog.run()
|
||||
|
||||
if response == Gtk.ResponseType.OK:
|
||||
location = dialog.get_filename()
|
||||
elif response == Gtk.ResponseType.CANCEL:
|
||||
location = ""
|
||||
|
||||
dialog.destroy()
|
||||
|
||||
return location
|
||||
|
||||
|
||||
def message_dialog(self, message: str):
|
||||
""" Displaying a Gtk Message dialog to the user
|
||||
|
||||
Args:
|
||||
message (str): Message which appear in the dialog
|
||||
"""
|
||||
dialog = Gtk.MessageDialog(
|
||||
transient_for=self,
|
||||
flags=0,
|
||||
message_type=Gtk.MessageType.INFO,
|
||||
buttons=Gtk.ButtonsType.OK,
|
||||
text=message
|
||||
)
|
||||
|
||||
dialog.run()
|
||||
dialog.destroy()
|
||||
@@ -1,32 +0,0 @@
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk
|
||||
|
||||
class FileChooser(Gtk.Window):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def on_btn_source_folder_clicked(self) -> str:
|
||||
dialog = Gtk.FileChooserDialog(
|
||||
title= "Please choose a folder with images",
|
||||
parent=self,
|
||||
action=Gtk.FileChooserAction.SELECT_FOLDER
|
||||
)
|
||||
|
||||
dialog.add_buttons(
|
||||
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, "Select", Gtk.ResponseType.OK
|
||||
)
|
||||
|
||||
dialog.set_default_size(800, 400)
|
||||
|
||||
response = dialog.run()
|
||||
|
||||
if response == Gtk.ResponseType.OK:
|
||||
location = dialog.get_filename()
|
||||
elif response == Gtk.ResponseType.CANCEL:
|
||||
location = ""
|
||||
|
||||
dialog.destroy()
|
||||
|
||||
return location
|
||||
@@ -1,15 +1,60 @@
|
||||
import os
|
||||
|
||||
class Images:
|
||||
""" Class for image operations
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def get_images_from_folder(self, URI: str) -> list:
|
||||
""" List all images in a folder
|
||||
|
||||
Args:
|
||||
URI (str): Absolute path of the folder
|
||||
|
||||
Returns:
|
||||
list: List of file names which are images
|
||||
"""
|
||||
items = []
|
||||
|
||||
for file in os.listdir(URI):
|
||||
if file.endswith("jpg") or file.endswith("jpeg") or file.endswith("png") or file.endswith("bmp"):
|
||||
if file.endswith(("jpg", "jpeg", "png", "bmp", "svg")):
|
||||
items.append(file)
|
||||
|
||||
items.sort()
|
||||
return items
|
||||
return items
|
||||
|
||||
|
||||
def extract_heic_file(self, file_uri: str) -> bool:
|
||||
""" Extract a heic file to an internal folder
|
||||
|
||||
Args:
|
||||
file_uri (str): Absolute path to the heic file
|
||||
|
||||
Returns:
|
||||
bool: Extraction was successful
|
||||
"""
|
||||
try:
|
||||
extract_folder = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir)) + \
|
||||
"/images/extracted_images/"
|
||||
|
||||
file_name: str = file_uri[file_uri.rfind("/") + 1:]
|
||||
file_name = file_name[:file_name.rfind(".")]
|
||||
|
||||
# Create the buffer folder if its not existing
|
||||
try:
|
||||
os.mkdir(extract_folder)
|
||||
except:
|
||||
pass
|
||||
|
||||
# Cleanup the folder
|
||||
for file in self.get_images_from_folder(extract_folder):
|
||||
os.remove(extract_folder + file)
|
||||
|
||||
# Extract the HEIC file
|
||||
os.system("heif-convert '" + file_uri + "' '" + extract_folder + file_name + ".jpg'")
|
||||
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import urllib.request, json
|
||||
|
||||
class Location():
|
||||
""" Class to handle location requests
|
||||
"""
|
||||
def __init__(self):
|
||||
self.GEO_URL = "https://get.geojs.io/v1/ip/geo.json"
|
||||
|
||||
def run(self) -> dict:
|
||||
def get_location(self) -> dict:
|
||||
""" Request the location via network
|
||||
|
||||
Returns:
|
||||
dict: latitude and longitude
|
||||
"""
|
||||
request = urllib.request.urlopen(self.GEO_URL)
|
||||
|
||||
data = json.load(request)
|
||||
|
||||
@@ -19,6 +19,12 @@ class Suntimes:
|
||||
|
||||
|
||||
def calc_suntimes(self, latitude: float, longitude: float) -> None:
|
||||
""" Start the calculation process
|
||||
|
||||
Args:
|
||||
latitude (float): Current latitude
|
||||
longitude (float): Current longitude
|
||||
"""
|
||||
self.latitude = latitude
|
||||
self.longitude = longitude
|
||||
self.calc_sun_events()
|
||||
@@ -43,6 +49,8 @@ class Suntimes:
|
||||
|
||||
|
||||
def calc_sun_events(self):
|
||||
""" Parent sun event calculater. Calls calc_sunrise_sunset_time() for every time period
|
||||
"""
|
||||
civial_dawn_start = self.calc_sunrise_sunset_time(True, 96)
|
||||
sunrise_start = self.calc_sunrise_sunset_time(True)
|
||||
morning_start = self.calc_sunrise_sunset_time(True, 89.167)
|
||||
@@ -71,8 +79,6 @@ class Suntimes:
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
||||
def calc_sunrise_sunset_time(self, is_sunrise: bool, zenith=90.833) -> datetime:
|
||||
""" Calculate all values to estimate the day periods
|
||||
"""
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import math
|
||||
|
||||
class Time_Bar_Chart:
|
||||
""" Class to handle the creation of the day time period bar
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
self.image_code = []
|
||||
|
||||
@@ -21,9 +23,10 @@ class Time_Bar_Chart:
|
||||
|
||||
|
||||
def create_bar_chart_with_polylines(self, save_location: str, image_width: int, image_height: int, times: list):
|
||||
""" Create a time bar chart
|
||||
""" Create a time bar chart WITH polylines
|
||||
|
||||
Args:
|
||||
save_location (str): Absolute path to store
|
||||
image_width (int): Width of the image in pixel
|
||||
image_height (int): Height of the image in pixel
|
||||
times (list): List of start times of the periods in minutes since midnight
|
||||
@@ -45,6 +48,14 @@ class Time_Bar_Chart:
|
||||
|
||||
|
||||
def create_bar_chart(self, save_location: str, image_width: int, image_height: int, times: list):
|
||||
""" Create a time bar chart WITHOUT polylines
|
||||
|
||||
Args:
|
||||
save_location (str): Absolute path to store
|
||||
image_width (int): Width of the image in pixel
|
||||
image_height (int): Height of the image in pixel
|
||||
times (list): List of start times of the periods in minutes since midnight
|
||||
"""
|
||||
self.create_bar(image_width, image_height, times)
|
||||
self.create_time_markers(image_width, image_height)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user