-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_management.py
42 lines (35 loc) · 1.27 KB
/
config_management.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
import sys
import configparser
def load_config():
config = configparser.ConfigParser()
config.read('yaffle.ini')
if('Yaffle' not in config):
create_initial_config()
config.read('yaffle.ini')
if(config is None):
sys.exit(1)
else:
load_config()
else:
return config['Yaffle']
def create_initial_config():
config = configparser.ConfigParser()
config['Yaffle'] = {'YARR_URL': 'http://127.0.0.1:7070',
'selected_feed': '0'}
with open('yaffle.ini', 'w', encoding='utf-8') as configfile:
config.write(configfile)
def save_config(frame):
try:
config = configparser.ConfigParser()
config.read('yaffle.ini')
if frame.feed_tree is not None:
config['Yaffle']['selected_feed'] = str(frame.feed_tree.GetItemData(frame.feed_tree.GetSelection()))
width, height = frame.GetSize()
config['Yaffle']['dimensions'] = f"{width}x{height}"
x, y = frame.GetPosition()
config['Yaffle']['position'] = f"{x},{y}"
with open('yaffle.ini', 'w', encoding='utf-8') as configfile:
config.write(configfile)
except (configparser.Error, IOError) as e:
print(f"Failed to save state: {e}")
return