summaryrefslogtreecommitdiff
path: root/src/manage_saves.py
blob: 2730a5de16cd2ac4de8845cd47f432f4376abb55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from rich import print
import json
import os

class Theme:
    def __init__(self, colors, comp_colors, wallpaper, name):
        self.colors = colors
        self.comp_colors = comp_colors
        self.wallpaper = wallpaper
        self.name = name
    def toDict(self):
        return {
                "name"       : self.name,
                "colors"     : self.colors,
                "comp_colors": self.comp_colors,
                "wallpaper"  : self.wallpaper,
                }


def getAllThemes(theme_dir):
    themes = []
    themes_in_dir = [file for file in os.listdir(theme_dir) if os.path.isfile(os.path.join(theme_dir, file)) and file.endswith('.theme')]

    for file in themes_in_dir:
        theme_location = theme_dir + file
        themes.append(load_theme(theme_location))
    return themes


def save_theme(hex_colors, hex_compliments, wallpaper_location, save_location, theme_name):
    """
    Save a theme to the disk at a specified location as a json object.
    """ 
    
    theme = Theme(hex_colors, hex_compliments, wallpaper_location, theme_name)

    with open(save_location, 'w') as file:
        json.dump(theme.toDict(), file)
    print('[bold green]color palette saved successfully')


def load_theme(save_location):
    """
    Load a theme from disk at a specified location
    """
    with open(save_location, 'r') as file:
        data = json.loads(file.read()) 
    return data