else: value = False elif valtype == int: value = int(value) self.config[section][key] = value def write(self): #print "writing config %s" % self.config_file config = configparser.ConfigParser() for section in self.config: config.add_section(section) for key in self.config[section]: config.set(section, key, str(self.config[section][key])) configfile = open(self.config_file, 'w') config.write(configfile) configfile.close() def show(self): txt="\n" for section in self.config: txt += section+" :\n" for key in self.config[section]: txt += "\t%s = %s\n" % (key, self.config[section][key]) return txt if __name__ == "__main__": from test import TestKismon TestKismon.test_config(True)
def set_source(self, id): print("set source %s" % id) if id == "opencyclemap": self.osm.set_property("map-source", OsmGpsMap.MapSource_t.OPENCYCLEMAP) elif id == "custom": self.reinit_osm() else: id = "openstreetmap" self.osm.set_property("map-source", OsmGpsMap.MapSource_t.OPENSTREETMAP) self.config["source"] = id def on_changed(self, osm): self.save_zoom() class Marker: def __init__(self, key, lat, lon, color): self.key = key self.lat = lat self.lon = lon self.color = color if __name__ == "__main__": from test import TestKismon bla = TestKismon() bla.test_map() Gtk.main()
elif first_line.startswith('{'): # new json config self.logger.info('loading json config') with open(self.config_file, 'r') as f: loaded_config = json.load(f) for key in self.config: if key not in loaded_config: # doesn't exist before continue if type(self.config[key]) != type(loaded_config[key]): # type has changed continue if type(self.config[key]) == dict: self.config[key].update(loaded_config[key]) elif type(self.config[key]) == list: self.config[key] = loaded_config[key] else: self.logger.warning('unknown config format, using default') return def write(self): self.logger.info('writing json config') with open(self.config_file, 'w') as f: json.dump(self.config, f, indent=2) if __name__ == "__main__": from test import TestKismon TestKismon.test_config(True)
self.reinit_osm() self.set_source(id) def set_source(self, id): print("set source %s" % id) if id == "opencyclemap": self.osm.set_property("map-source", OsmGpsMap.MapSource_t.OPENCYCLEMAP) elif id == "custom": self.reinit_osm() else: id = "openstreetmap" self.osm.set_property("map-source", OsmGpsMap.MapSource_t.OPENSTREETMAP) self.config["source"] = id def on_changed(self, osm): self.save_zoom() class Marker: def __init__(self, key, lat, lon, color): self.key = key self.lat = lat self.lon = lon self.color = color if __name__ == "__main__": from test import TestKismon bla = TestKismon() bla.test_map() Gtk.main()