def _fill_button_images(self, buttons):
     e = self.edit()
     SVGEditor.update_parents(e)
     target = SVGEditor.get_element(e, "controller")
     target_x, target_y = SVGEditor.get_translation(target)
     for i in xrange(len(ControllerImage.BUTTONS_WITH_IMAGES)):
         b = nameof(ControllerImage.BUTTONS_WITH_IMAGES[i])
         try:
             elm = SVGEditor.get_element(e, "AREA_%s" % (b, ))
             if elm is None:
                 log.warning("Area for button %s not found", b)
                 continue
             x, y = SVGEditor.get_translation(elm)
             scale = 1.0
             if "scc-button-scale" in elm.attrib:
                 w, h = SVGEditor.get_size(elm)
                 scale = float(elm.attrib['scc-button-scale'])
                 tw, th = w * scale, h * scale
                 if scale < 1.0:
                     x += (w - tw) * 0.5
                     y += (h - th) * 0.5
                 else:
                     x -= (tw - w) * 0.25
                     y -= (th - h) * 0.25
             path = os.path.join(self.app.imagepath, "button-images",
                                 "%s.svg" % (buttons[i], ))
             img = SVGEditor.get_element(SVGEditor.load_from_file(path),
                                         "button")
             img.attrib["transform"] = "translate(%s, %s) scale(%s)" % (
                 x - target_x, y - target_y, scale)
             img.attrib["id"] = b
             SVGEditor.add_element(target, img)
         except Exception, err:
             log.warning("Failed to add image for button %s", b)
             log.exception(err)
	def _fill_button_images(self, buttons):
		e = self.edit()
		SVGEditor.update_parents(e)
		target = SVGEditor.get_element(e, "controller")
		target_x, target_y = SVGEditor.get_translation(target)
		for i in xrange(len(ControllerImage.BUTTONS_WITH_IMAGES)):
			b = nameof(ControllerImage.BUTTONS_WITH_IMAGES[i])
			try:
				elm = SVGEditor.get_element(e, "AREA_%s" % (b,))
				if elm is None:
					log.warning("Area for button %s not found", b)
					continue
				x, y = SVGEditor.get_translation(elm)
				scale = 1.0
				if "scc-button-scale" in elm.attrib:
					w, h = SVGEditor.get_size(elm)
					scale = float(elm.attrib['scc-button-scale'])
					tw, th = w * scale, h * scale
					if scale < 1.0:
						x += (w - tw) * 0.5
						y += (h - th) * 0.5
					else:
						x -= (tw - w) * 0.25
						y -= (th - h) * 0.25
				path = os.path.join(self.app.imagepath, "button-images",
					"%s.svg" % (buttons[i], ))
				img = SVGEditor.get_element(SVGEditor.load_from_file(path), "button")
				img.attrib["transform"] = "translate(%s, %s) scale(%s)" % (
					x - target_x, y - target_y, scale)
				img.attrib["id"] = b
				SVGEditor.add_element(target, img)
			except Exception, err:
				log.warning("Failed to add image for button %s", b)
				log.exception(err)
Exemple #3
0
	def get_limit(self, id):
		a = SVGEditor.find_by_id(self.tree, id)
		width, height = 0, 0
		if not hasattr(a, "parent"): a.parent = None
		x, y = SVGEditor.get_translation(a, absolute=True)
		if 'width' in a.attrib:  width = float(a.attrib['width'])
		if 'height' in a.attrib: height = float(a.attrib['height'])
		return x, y, width, height
Exemple #4
0
 def get_limit(self, id):
     a = SVGEditor.find_by_id(self.tree, id)
     width, height = 0, 0
     if not hasattr(a, "parent"): a.parent = None
     x, y = SVGEditor.get_translation(a, absolute=True)
     if 'width' in a.attrib: width = float(a.attrib['width'])
     if 'height' in a.attrib: height = float(a.attrib['height'])
     return x, y, width, height