-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_write.py
144 lines (122 loc) · 4.49 KB
/
read_write.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"""
Functions for reading/writing from/to configuration files
Author: Marco P. L. Ribeiro
Date: June 2019
MIT License
Copyright (c) 2019 Marco P. L. Ribeiro
"""
import os
import tkinter as tk
from configobj import ConfigObj
# Load activity linked to each block
def read_saved_plan(filename):
config = ConfigObj(filename)
block_linking = []
for row in range(24):
tempList=[]
for col in range(6):
tempList.append(config[str(row).zfill(2)][str(col)+'0'])
block_linking.append(tempList)
return block_linking
# Write the activity linked to each block
def write_saved_plan(filename,block_linking):
config = ConfigObj()
config.filename = './saved_plans/'+ filename + '.ini'
for row in range(24):
config[str(row).zfill(2)] = {}
for col in range(6):
config[str(row).zfill(2)][str(col)+'0'] = block_linking[row][col]
config.write()
# Function for shrinking the selected icon for use in the block
def shrinkImage(filepath, size):
import PIL
from PIL import Image
basewidth = size
img = Image.open(filepath)
wpercent = (basewidth / float(img.size[0]))
hsize = int((float(img.size[1]) * float(wpercent)))
img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS)
filename = os.path.basename(filepath)
img.save('./resized/'+filename)
return './resized/'+filename
# Read the settings file
def read_settings_file(settings_filename, tk_master):
config = ConfigObj(settings_filename)
main_text_colour=config['appearance']['main_text_colour']
select_window_text_colour=config['appearance']['select_window_text_colour']
background_colour=config['appearance']['background_colour']
foreground_colour=config['appearance']['foreground_colour']
unlinked_colour=config['appearance']['unlinked_colour']
SIZE_SETTING = int(config['appearance']['button_size'])
acts = {}
for act in config['activities']: # act = 'Sleep' etc.
act_image = tk.PhotoImage(master=tk_master, file=shrinkImage(config['activities'][act]['icon'],SIZE_SETTING))
acts[act] = dict({'icon':act_image, 'colour':config['activities'][act]['colour'], 'productive':config['activities'][act]['productive']})
acts['-1'] = dict({'icon':tk.PhotoImage(master=tk_master, width=SIZE_SETTING, height=SIZE_SETTING), 'colour':unlinked_colour, 'productive':'False'})
return ([main_text_colour, select_window_text_colour, background_colour, foreground_colour, unlinked_colour],
SIZE_SETTING, acts)
# Recreate the default settings file
def write_settings_file(settings_filename, tk_master):
config = ConfigObj()
config.filename = settings_filename
config['appearance'] = {}
config['appearance']['background_colour'] = '#3d3d3d'
config['appearance']['foreground_colour'] = '#3d3d3d'
config['appearance']['unlinked_colour'] = '#999999'
config['appearance']['main_text_colour'] = '#ffffff'
config['appearance']['select_window_text_colour'] = '#ffffff'
config['appearance']['button_size'] = 10
activities = {
'Sleep' : {
'icon' : "./icons/moon.png",
'colour' : "#000075",
'productive' : False
},
'Work' : {
'icon' : "./icons/work.png",
'colour' : "#808000",
'productive' : True
},
'Break' : {
'icon' : "./icons/clock.png",
'colour' : "#f032e6",
'productive' : False
},
'Planning' : {
'icon' : "./icons/calendar.png",
'colour' : "#800000",
'productive' : True
},
'Exercise' : {
'icon' : "./icons/run.png",
'colour' : "#f58231",
'productive' : False
},
'Read' : {
'icon' : "./icons/book.png",
'colour' : "#e6194b",
'productive' : False
},
'Eat' : {
'icon' : "./icons/cutlery.png",
'colour' : "#3cb44b",
'productive' : False
},
'Shower' : {
'icon' : "./icons/shower.png",
'colour' : "#4363d8",
'productive' : False
},
'Movie' : {
'icon' : "./icons/clapperboard.png",
'colour' : "#911eb4",
'productive' : False
},
'Hobby' : {
'icon' : "./icons/painter_palette.png",
'colour' : "#9a6324",
'productive' : False
}
}
config['activities'] = activities
config.write()