def __init__(self): self.change_cb = None self.parser = Parser() self.conf_file = os.path.join(Path.config_dir, "TrayIcon.xml") self.def_config = """ <preferences> <section name="notifications"> <i name="type" default="1" description="Type of notifications (0 for libnotify, 1 for higtooltip)" min='0' max='1' value="1"/> </section> </preferences> """ self.read_conf() log.debug("Notification type set to %d" % \ self.parser['notifications']['type'].value)
class Preferences(object): def __init__(self): self.change_cb = None self.parser = Parser() self.conf_file = os.path.join(Path.config_dir, "TrayIcon.xml") self.def_config = """ <preferences> <section name="notifications"> <i name="type" default="1" description="Type of notifications (0 for libnotify, 1 for higtooltip)" min='0' max='1' value="1"/> </section> </preferences> """ self.read_conf() log.debug("Notification type set to %d" % \ self.parser['notifications']['type'].value) def read_conf(self): good = False if os.path.exists(self.conf_file): try: log.debug("Parsing conf_file placed at %s" % self.conf_file) self.parser.parse_file(self.conf_file) good = True except: pass if not good: log.debug("Loading default values for TrayIcon") self.parser.parse_string(self.def_config) def save_conf(self): # Let's save our configuration to self.conf_file log.debug("Saving configuration to %s" % self.conf_file) self.parser.save_to_file(self.conf_file) def update(self): if self.change_cb is not None: self.change_cb(self.parser['notifications']['type'].value)