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)
Example #2
0
	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)
Example #3
0
    def __init__(self, image):
        Gtk.DrawingArea.__init__(self)
        self.connect('size-allocate', self.on_size_allocate)
        self.connect('draw', self.on_draw)

        areas = []
        self.color_button1 = 0.8, 0, 0, 1  # Just random mess,
        self.color_button1_border = 1, 0, 0, 1  # config overrides it anyway
        self.color_button2 = 0.8, 0.8, 0, 1
        self.color_button2_border = 1, 1, 0, 1
        self.color_hilight = 0, 1, 1, 1
        self.color_pressed = 1, 1, 1, 1
        self.color_text = 1, 1, 1, 1

        self.overlay = SVGWidget(image, False)
        self.tree = ET.fromstring(self.overlay.current_svg.encode("utf-8"))
        SVGWidget.find_areas(self.tree, None, areas, get_colors=True)

        self._hilight = ()
        self._pressed = ()
        self._button_images = {}
        self._help_areas = [
            self.get_limit("HELP_LEFT"),
            self.get_limit("HELP_RIGHT")
        ]
        self._help_lines = ([], [])

        # TODO: It would be cool to use user-set font here, but cairo doesn't
        # have glyph replacement and most of default fonts (Ubuntu, Cantarell,
        # similar shit) misses pretty-much everything but letters, notably ↲
        #
        # For that reason, DejaVu Sans is hardcoded for now. On systems
        # where DejaVu Sans is not available, Cairo will automatically fallback
        # to default font.
        self.font_face = "DejaVu Sans"
        # self.font_face = Gtk.Label(label="X").get_style().font_desc.get_family()
        log.debug("Using font %s", self.font_face)

        self.buttons = [Button(self.tree, area) for area in areas]
        background = SVGEditor.find_by_id(self.tree, "BACKGROUND")
        self.set_size_request(*SVGEditor.get_size(background))
        self.overlay.edit().keep("overlay").commit()
        self.overlay.hilight({})
Example #4
0
	def __init__(self, image):
		Gtk.DrawingArea.__init__(self)
		self.connect('size-allocate', self.on_size_allocate)
		self.connect('draw', self.on_draw)
		
		areas = []
		self.color_button1 = 0.8, 0, 0, 1			# Just random mess,
		self.color_button1_border = 1, 0, 0, 1		# config overrides it anyway
		self.color_button2 = 0.8, 0.8, 0, 1
		self.color_button2_border = 1, 1, 0, 1
		self.color_hilight = 0, 1, 1, 1
		self.color_pressed = 1, 1, 1, 1
		self.color_text = 1, 1, 1, 1
		
		self.overlay = SVGWidget(image, False)
		self.tree = ET.fromstring(self.overlay.current_svg.encode("utf-8"))
		SVGWidget.find_areas(self.tree, None, areas, get_colors=True)
		
		self._hilight = ()
		self._pressed = ()
		self._button_images = {}
		self._help_areas = [ self.get_limit("HELP_LEFT"), self.get_limit("HELP_RIGHT") ]
		self._help_lines = ( [], [] )
		
		# TODO: It would be cool to use user-set font here, but cairo doesn't
		# have glyph replacement and most of default fonts (Ubuntu, Cantarell,
		# similar shit) misses pretty-much everything but letters, notably ↲
		#
		# For that reason, DejaVu Sans is hardcoded for now. On systems
		# where DejaVu Sans is not available, Cairo will automatically fallback
		# to default font.
		self.font_face = "DejaVu Sans"
		# self.font_face = Gtk.Label(label="X").get_style().font_desc.get_family()
		log.debug("Using font %s", self.font_face)
		
		self.buttons = [ Button(self.tree, area) for area in areas ]
		background = SVGEditor.find_by_id(self.tree, "BACKGROUND")
		self.set_size_request(*SVGEditor.get_size(background))
		self.overlay.edit().keep("overlay").commit()
		self.overlay.hilight({})