Пример #1
0
    def display_value(self, key, w):
        """
		Sets value on UI element for single key. May be overridden
		by subclass to handle special values.
		"""
        if isinstance(w, Gtk.SpinButton):
            w.get_adjustment().set_value(ints(self.get_value(strip_v(key))))
        elif isinstance(w, Gtk.Entry):
            w.set_text(unicode(self.get_value(strip_v(key))))
        elif isinstance(w, Gtk.ComboBox):
            val = self.get_value(strip_v(key))
            m = w.get_model()
            for i in xrange(0, len(m)):
                if str(val) == str(m[i][0]).strip():
                    w.set_active(i)
                    break
            else:
                w.set_active(0)
        elif isinstance(w, Gtk.CheckButton):
            w.set_active(self.get_value(strip_v(key)))
        else:
            log.warning(
                "display_value: %s class cannot handle widget %s, key %s",
                self.__class__.__name__, w, key)
            if not w is None: w.set_sensitive(False)
Пример #2
0
	def display_value(self, key, w):
		"""
		Sets value on UI element for single key. May be overriden
		by subclass to handle special values.
		"""
		if isinstance(w, Gtk.SpinButton):
			w.get_adjustment().set_value(ints(self.get_value(strip_v(key))))
		elif isinstance(w, Gtk.Entry):
			w.set_text(unicode(self.get_value(strip_v(key))))
		elif isinstance(w, Gtk.ComboBox):
			val = self.get_value(strip_v(key))
			m = w.get_model()
			for i in xrange(0, len(m)):
				if str(val) == str(m[i][0]).strip():
					w.set_active(i)
					break
		elif isinstance(w, Gtk.CheckButton):
			w.set_active(self.get_value(strip_v(key)))
		else:
			log.warning("display_value: %s class cannot handle widget %s, key %s", self.__class__.__name__, w, key)
			if not w is None: w.set_sensitive(False)
Пример #3
0
	def cb_data_loaded(self, config):
		self.config = config
		try:
			if self.is_new:
				self.values = { x.lstrip("v") : "" for x in self.VALUES[self.mode] }
				if self.mode == "repo-edit":
					self.checks = {
						"vID" : self.check_repo_id,
						"vDirectory" : self.check_path
						}
					if self.id != None:
						try:
							v = [ x for x in self.config["Repositories"] if x["ID"] == self.id ][0]
							self.values = v
							self.is_new = False
						except IndexError:
							pass
				elif self.mode == "node-edit":
					self.set_value("Addresses", "dynamic")
					self.set_value("Compression", True)
					self.checks = {
						"vNodeID" : check_node_id,
						}
					if self.id != None:
						# Pre-fill node id, if provided
						self.set_value("NodeID", self.id)
			else:
				if self.mode == "repo-edit":
					self.values = [ x for x in self.config["Repositories"] if x["ID"] == self.id ][0]
					self.checks = {
						"vDirectory" : self.check_path
						}
				elif self.mode == "node-edit":
					self.values = [ x for x in self.config["Nodes"] if x["NodeID"] == self.id ][0]
				elif self.mode == "daemon-settings":
					self.values = self.config["Options"]
					self.checks = {}
				else:
					# Invalid mode. Shouldn't be possible
					self.close()
					return
		except KeyError:
			# ID not found in configuration. This is practicaly impossible,
			# so it's handled only by self-closing dialog.
			self.close()
			return
		# Iterate over all known configuration values and set UI elements using unholy method
		for key in self.VALUES[self.mode]:
			w = self.find_widget_by_id(key)
			self.widget_to_id[w] = key
			if not key is None:
				if isinstance(w, Gtk.SpinButton):
					w.get_adjustment().set_value(ints(self.get_value(key.lstrip("v"))))
				elif isinstance(w, Gtk.Entry):
					w.set_text(str(self.get_value(key.lstrip("v"))))
				elif isinstance(w, Gtk.ComboBox):
					val = self.get_value(key.lstrip("v"))
					m = w.get_model()
					for i in xrange(0, len(m)):
						if val == str(m[i][0]).strip():
							w.set_active(i)
							break
				elif isinstance(w, Gtk.CheckButton):
					w.set_active(self.get_value(key.lstrip("v")))
				elif key == "vNodes":
					# Very special case
					nids = [ n["NodeID"] for n in self.get_value("Nodes") ]
					for node in self.app.nodes.values():
						if node["id"] != self.app.daemon.get_my_id():
							b = Gtk.CheckButton(node.get_title(), False)
							b.set_tooltip_text(node["id"])
							self["vNodes"].pack_end(b, False, False, 0)
							b.set_active(node["id"] in nids)
					self["vNodes"].show_all()
				else:
					print w
		self.update_special_widgets()
		# Enable dialog
		self["editor"].set_sensitive(True)
		# Brag
		self.emit("loaded")
Пример #4
0
 def cb_data_loaded(self, config):
     self.config = config
     try:
         if self.is_new:
             self.values = {
                 x.lstrip("v"): ""
                 for x in self.VALUES[self.mode]
             }
             if self.mode == "repo-edit":
                 self.checks = {
                     "vID": self.check_repo_id,
                     "vDirectory": self.check_path
                 }
                 if self.id != None:
                     try:
                         v = [
                             x for x in self.config["Repositories"]
                             if x["ID"] == self.id
                         ][0]
                         self.values = v
                         self.is_new = False
                     except IndexError:
                         pass
             elif self.mode == "node-edit":
                 self.set_value("Addresses", "dynamic")
                 self.set_value("Compression", True)
                 self.checks = {
                     "vNodeID": check_node_id,
                 }
                 if self.id != None:
                     # Pre-fill node id, if provided
                     self.set_value("NodeID", self.id)
         else:
             if self.mode == "repo-edit":
                 self.values = [
                     x for x in self.config["Repositories"]
                     if x["ID"] == self.id
                 ][0]
                 self.checks = {"vDirectory": self.check_path}
             elif self.mode == "node-edit":
                 self.values = [
                     x for x in self.config["Nodes"]
                     if x["NodeID"] == self.id
                 ][0]
             elif self.mode == "daemon-settings":
                 self.values = self.config["Options"]
                 self.checks = {}
             else:
                 # Invalid mode. Shouldn't be possible
                 self.close()
                 return
     except KeyError:
         # ID not found in configuration. This is practicaly impossible,
         # so it's handled only by self-closing dialog.
         self.close()
         return
     # Iterate over all known configuration values and set UI elements using unholy method
     for key in self.VALUES[self.mode]:
         w = self.find_widget_by_id(key)
         self.widget_to_id[w] = key
         if not key is None:
             if isinstance(w, Gtk.SpinButton):
                 w.get_adjustment().set_value(
                     ints(self.get_value(key.lstrip("v"))))
             elif isinstance(w, Gtk.Entry):
                 w.set_text(str(self.get_value(key.lstrip("v"))))
             elif isinstance(w, Gtk.ComboBox):
                 val = self.get_value(key.lstrip("v"))
                 m = w.get_model()
                 for i in xrange(0, len(m)):
                     if val == str(m[i][0]).strip():
                         w.set_active(i)
                         break
             elif isinstance(w, Gtk.CheckButton):
                 w.set_active(self.get_value(key.lstrip("v")))
             elif key == "vNodes":
                 # Very special case
                 nids = [n["NodeID"] for n in self.get_value("Nodes")]
                 for node in self.app.nodes.values():
                     if node["id"] != self.app.daemon.get_my_id():
                         b = Gtk.CheckButton(node.get_title(), False)
                         b.set_tooltip_text(node["id"])
                         self["vNodes"].pack_end(b, False, False, 0)
                         b.set_active(node["id"] in nids)
                 self["vNodes"].show_all()
             else:
                 print w
     self.update_special_widgets()
     # Enable dialog
     self["editor"].set_sensitive(True)
     # Brag
     self.emit("loaded")