def get_settings_for_applet(self, path): if "max-instances" in self.applet_meta: self.multi_instance = int(self.applet_meta["max-instances"]) > 1 else: self.multi_instance = False if os.path.exists(path) and os.path.isdir(path): instances = os.listdir(path) if len(instances) != 0: for instance in instances: raw_data = open("%s/%s" % (path, instance)).read() try: js = json.loads( raw_data.decode('utf-8'), object_pairs_hook=collections.OrderedDict) except: raise Exception( "Failed to parse settings JSON data for %s %s" % (self.type, self.uuid)) instance_id = instance.split(".json")[0] self.applet_settings[instance_id] = js self.setting_factories[ instance_id] = XletSettingsWidgets.Factory( "%s/%s" % (path, instance), instance_id, self.multi_instance, self.uuid) return True else: raise Exception( "Could not find any active setting files for %s %s" % (self.type, self.uuid)) return False
def build_single(self): self.nb = None self.view = SectionBg() self.content_box = Gtk.VBox() self.view.add(self.content_box) self.content_box.set_border_width(5) for instance_key in self.applet_settings.keys(): for setting_key in self.applet_settings[instance_key].keys(): if setting_key == "__md5__" or self.applet_settings[ instance_key][setting_key]["type"] == "generic": continue self.setting_factories[instance_key].create( setting_key, self.applet_settings[instance_key][setting_key]["type"], self.uuid) widgets = self.setting_factories[instance_key].widgets for widget_key in widgets.keys(): if widgets[widget_key].get_indented(): indent = XletSettingsWidgets.IndentedHBox() indent.add_fill(widgets[widget_key]) self.content_box.pack_start(indent, False, False, 2) else: self.content_box.pack_start(widgets[widget_key], False, False, 2) if len(widgets[widget_key].dependents) > 0: widgets[widget_key].update_dependents() self.content.pack_start(self.view, True, True, 2) self.current_id = instance_key
def build_notebook(self): self.nb = Gtk.Notebook() i = 1 for instance_key in self.applet_settings.keys(): view = Gtk.ScrolledWindow() content_box = Gtk.VBox() view.add_with_viewport(content_box) content_box.set_border_width(5) for setting_key in self.applet_settings[instance_key].keys(): if setting_key == "__md5__" or self.applet_settings[ instance_key][setting_key]["type"] == "generic": continue self.setting_factories[instance_key].create( setting_key, self.applet_settings[instance_key][setting_key]["type"], self.uuid) widgets = self.setting_factories[instance_key].widgets for widget_key in widgets.keys(): if widgets[widget_key].get_indented(): indent = XletSettingsWidgets.IndentedHBox() indent.add_fill(widgets[widget_key]) content_box.pack_start(indent, False, False, 2) else: content_box.pack_start(widgets[widget_key], False, False, 2) if len(widgets[widget_key].dependents) > 0: widgets[widget_key].update_dependents() self.nb.append_page(view, Gtk.Label(_("Instance %s") % i)) view.key = instance_key i += 1 self.content.pack_start(self.nb, True, True, 2) self.nb.set_scrollable(True) self.nb.connect("switch-page", self.on_page_changed)