-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.py
More file actions
27 lines (22 loc) · 900 Bytes
/
config.py
File metadata and controls
27 lines (22 loc) · 900 Bytes
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
from PyQt5.QtCore import QObject, pyqtSignal
import configparser
class Config(QObject):
error_occurred = pyqtSignal(str)
def __init__(self):
super().__init__()
self.config = configparser.ConfigParser()
def read_config(self):
try:
self.config.read("config.ini", encoding="utf-8")
return self.config
except configparser.Error as e:
self.error_occurred.emit("Error reading config: {}".format(str(e)))
return None
def write_config(self, settings):
try:
for section, options in settings.items():
self.config[section] = options
with open("config.ini", "w", encoding="utf-8") as config_file:
self.config.write(config_file)
except configparser.Error as e:
self.error_occurred.emit("Error writing config: {}".format(str(e)))