def place(self, gen, root): e = SVGEditor.add_element(root, "rect", style = "opacity:1;fill-opacity:0.0;stroke-width:2.0;", fill="#000000", stroke="#06a400", id = "box_%s" % (self.name,), width = self.width, height = self.height, x = self.x, y = self.y, ) y = self.y + self.PADDING for line in self.lines: h = gen.line_height x = self.x + self.PADDING for icon in line.icons: image = find_image(icon) if image: SVGEditor.add_element(root, "image", x = x, y = y, style = "filter:url(#filterInvert)", width = h, height = h, href = image) x += h + self.SPACING x = self.x + self.PADDING + self.icount * (h + self.SPACING) y += h txt = SVGEditor.add_element(root, "text", x = x, y = y, style = gen.label_template.attrib['style'] ) SVGEditor.set_text(txt, line.text) y += self.SPACING
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)
def place(self, gen, root): e = SVGEditor.add_element( root, "rect", style="opacity:1;fill-opacity:0.1;stroke-width:2.0;", fill="#00FF00", stroke="#06a400", id="box_%s" % (self.name, ), width=self.width, height=self.height, x=self.x, y=self.y, ) y = self.y + self.PADDING for line in self.lines: h = gen.line_height x = self.x + self.PADDING for icon in line.icons: image = find_image(icon) if image: # Fix: here stuff goes from weird to awfull, as rsvg # (library that gnome uses to render SVGs) can't render # linked images. Embeding is used instead. image = 'data:image/svg+xml;base64,%s' % (base64.b64encode( file(image, "rb").read())) # Another problem: rsvg will NOT draw image unless href # tag uses namespace. No idea why is that, but I spent # 3 hours finding this, so I'm willing to murder. SVGEditor.add_element(root, "image", x=x, y=y, style="filter:url(#filterInvert)", width=h, height=h, **{"xlink:href": image}) x += h + self.SPACING x = self.x + self.PADDING + self.icount * (h + self.SPACING) y += h txt = SVGEditor.add_element( root, "text", x=x, y=y, style=gen.label_template.attrib['style']) max_line_width = self.max_width - gen.line_height - self.PADDING while line.text and line.get_size(gen)[0] > max_line_width: line.text = line.text[:-1] SVGEditor.set_text(txt, line.text) y += self.SPACING
def place(self, gen, root): e = SVGEditor.add_element(root, "rect", style = "opacity:1;fill-opacity:0.1;stroke-width:2.0;", fill="#00FF00", stroke="#06a400", id = "box_%s" % (self.name,), width = self.width, height = self.height, x = self.x, y = self.y, ) y = self.y + self.PADDING for line in self.lines: h = gen.line_height x = self.x + self.PADDING for icon in line.icons: image = find_image(icon) if image: # Fix: here stuff goes from weird to awfull, as rsvg # (library that gnome uses to render SVGs) can't render # linked images. Embeding is used instead. image = 'data:image/svg+xml;base64,%s' % ( base64.b64encode(file(image, "rb").read()) ) # Another problem: rsvg will NOT draw image unless href # tag uses namespace. No idea why is that, but I spent # 3 hours finding this, so I'm willing to murder. SVGEditor.add_element(root, "image", x = x, y = y, style = "filter:url(#filterInvert)", width = h, height = h, **{"xlink:href" : image} ) x += h + self.SPACING x = self.x + self.PADDING + self.icount * (h + self.SPACING) y += h txt = SVGEditor.add_element(root, "text", x = x, y = y, style = gen.label_template.attrib['style'] ) max_line_width = self.max_width - gen.line_height - self.PADDING while line.text and line.get_size(gen)[0] > max_line_width: line.text = line.text[:-1] SVGEditor.set_text(txt, line.text) y += self.SPACING
def place_marker(self, gen, root): x1, y1 = self.x, self.y x2, y2 = x1 + self.width, y1 + self.height if self.align & (Align.LEFT | Align.RIGHT) == 0: edges = [[x2, y2], [x1, y2]] elif self.align & Align.BOTTOM == Align.BOTTOM: if self.align & Align.LEFT != 0: edges = [[x2, y2], [x1, y1]] elif self.align & Align.RIGHT != 0: edges = [[x2, y1], [x1, y2]] elif self.align & Align.TOP == Align.TOP: if self.align & Align.LEFT != 0: edges = [[x2, y1], [x2, y2]] elif self.align & Align.RIGHT != 0: edges = [[x1, y1], [x1, y2]] else: if self.align & Align.LEFT != 0: edges = [[x2, y1], [x2, y2]] elif self.align & Align.RIGHT != 0: edges = [[x1, y1], [x2, y2]] targets = SVGEditor.get_element(root, "markers_%s" % (self.name, )) if targets is None: return i = 0 for target in targets: tx, ty = float(target.attrib["cx"]), float(target.attrib["cy"]) try: edges[i] += [tx, ty] i += 1 except IndexError: break edges = [i for i in edges if len(i) == 4] for x1, y1, x2, y2 in edges: e = SVGEditor.add_element( root, "line", style="opacity:1;stroke:#06a400;stroke-width:0.5;", # id = "box_%s_line0" % (self.name,), x1=x1, y1=y1, x2=x2, y2=y2)
def place_marker(self, gen, root): x1, y1 = self.x, self.y x2, y2 = x1 + self.width, y1 + self.height if self.align & (Align.LEFT | Align.RIGHT) == 0: edges = [ [ x2, y2 ], [ x1, y2 ] ] elif self.align & Align.BOTTOM == Align.BOTTOM: if self.align & Align.LEFT != 0: edges = [ [ x2, y2 ], [ x1, y1 ] ] elif self.align & Align.RIGHT != 0: edges = [ [ x2, y1 ], [ x1, y2 ] ] elif self.align & Align.TOP == Align.TOP: if self.align & Align.LEFT != 0: edges = [ [ x2, y1 ], [ x2, y2 ] ] elif self.align & Align.RIGHT != 0: edges = [ [ x1, y1 ], [ x1, y2 ] ] else: if self.align & Align.LEFT != 0: edges = [ [ x2, y1 ], [ x2, y2 ] ] elif self.align & Align.RIGHT != 0: edges = [ [ x1, y1 ], [ x2, y2 ] ] targets = SVGEditor.get_element(root, "markers_%s" % (self.name,)) if targets is None: return i = 0 for target in targets: tx, ty = float(target.attrib["cx"]), float(target.attrib["cy"]) try: edges[i] += [ tx, ty ] i += 1 except IndexError: break edges = [ i for i in edges if len(i) == 4] for x1, y1, x2, y2 in edges: e = SVGEditor.add_element(root, "line", style = "opacity:1;stroke:#06a400;stroke-width:0.5;", # id = "box_%s_line0" % (self.name,), x1 = x1, y1 = y1, x2 = x2, y2 = y2 )