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 generate_widget(self, item): if item.id is None: # Labels and separators, radial menu can't show these return None e = self.editor.clone_element("menuitem_template") SVGEditor.set_text(e, item.label) e.attrib['id'] = "menuitem_" + item.id return e
def generate_widget(self, item): if isinstance(item, (Separator, Submenu)) or item.id is None: # Labels and separators, radial menu can't show these return None e = self.editor.clone_element("menuitem_template") SVGEditor.set_text(e, item.label) e.attrib['id'] = "menuitem_" + item.id return e
def pack_items(self, trash, items): index = 0 pb = self.b.get_pixbuf() image_width = pb.get_width() item_width = 360.0 / len(self.items) a1, a2 = (-90.0 - item_width * 0.5) * PI / 180.0, ( -90.0 + item_width * 0.5) * PI / 180.0 for i in items: # Set size of each arc if SVGWidget.get_element(i.widget, "arc") is not None: l = SVGWidget.get_element(i.widget, "arc") radius = float( l.attrib["radius"] ) # TODO: Find how to get value of 'sodipodi:rx' l.attrib["d"] = l.attrib["d-template"] % ( radius * cos(a1) + image_width / 2, radius * sin(a1) + image_width / 2, radius * cos(a2) + image_width / 2, radius * sin(a2) + image_width / 2, ) # Rotate arc to correct position i.a = (360.0 / float(len(self.items))) * float(index) i.widget.attrib['transform'] = "%s rotate(%s, %s, %s)" % ( i.widget.attrib['transform'], i.a, image_width / 2, image_width / 2) # Rotate text in arc to other direction to keep it horisontal if SVGWidget.get_element(i.widget, "menuitem_text") is not None: l = SVGWidget.get_element(i.widget, "menuitem_text") l.attrib['id'] = "text_" + i.id l.attrib['transform'] = "%s rotate(%s)" % ( l.attrib['transform'], -i.a) # Place up to 3 lines of item label label = i.label.split("\n") first_line = 0 if len(label) == 1: self.editor.remove_element( SVGWidget.get_element(i.widget, "line0")) self.editor.remove_element( SVGWidget.get_element(i.widget, "line2")) first_line = 1 elif len(label) == 2: self.editor.remove_element( SVGWidget.get_element(i.widget, "line0")) first_line = 1 for line in xrange(0, len(label)): l = SVGWidget.get_element(i.widget, "line%s" % (first_line + line, )) if l is None: break SVGEditor.set_text(l, label[line]) # Continue with next menu item i.index = index index += 1 self.editor.remove_element("menuitem_template") self.editor.commit() del self.editor
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 pack_items(self, trash, items): index = 0 pb = self.b.get_pixbuf() image_width = pb.get_width() item_width = 360.0 / len(self.items) a1, a2 = (-90.0 - item_width * 0.5) * PI / 180.0, (-90.0 + item_width * 0.5) * PI / 180.0 for i in items: # Set size of each arc if SVGWidget.get_element(i.widget, "arc") is not None: l = SVGWidget.get_element(i.widget, "arc") radius = float(l.attrib["radius"]) # TODO: Find how to get value of 'sodipodi:rx' l.attrib["d"] = l.attrib["d-template"] % ( radius * cos(a1) + image_width / 2, radius * sin(a1) + image_width / 2, radius * cos(a2) + image_width / 2, radius * sin(a2) + image_width / 2, ) # Rotate arc to correct position i.a = (360.0 / float(len(self.items))) * float(index) i.widget.attrib['transform'] = "%s rotate(%s, %s, %s)" % ( i.widget.attrib['transform'], i.a, image_width / 2, image_width / 2) # Rotate text in arc to other direction to keep it horisontal if SVGWidget.get_element(i.widget, "menuitem_text") is not None: l = SVGWidget.get_element(i.widget, "menuitem_text") l.attrib['id'] = "text_" + i.id l.attrib['transform'] = "%s rotate(%s)" % (l.attrib['transform'], -i.a) # Place up to 3 lines of item label label = i.label.split("\n") first_line = 0 if len(label) == 1: self.editor.remove_element(SVGWidget.get_element(i.widget, "line0")) self.editor.remove_element(SVGWidget.get_element(i.widget, "line2")) first_line = 1 elif len(label) == 2: self.editor.remove_element(SVGWidget.get_element(i.widget, "line0")) first_line = 1 for line in xrange(0, len(label)): l = SVGWidget.get_element(i.widget, "line%s" % (first_line + line,)) if l is None: break SVGEditor.set_text(l, label[line]) # Continue with next menu item i.index = index index += 1 self.editor.remove_element("menuitem_template") self.editor.commit() del self.editor
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 pack_items(self, trash, items): if self._size > 0 and self._size < 100: self.scale = self._size / 100.0 root = SVGEditor.get_element(self.editor, "root") SVGEditor.scale(root, self.scale) pb = self.b.get_pixbuf() # Image width is not scaled as everything bellow operates # in 'root' object coordinate space image_width = pb.get_width() index = 0 item_offset = 360.0 / len(self.items) a1 = (-90.0 - item_offset * 0.5) * PI / 180.0 a2 = (-90.0 + item_offset * 0.5) * PI / 180.0 for i in self.items_with_icon: i.icon_widget.get_parent().remove_child(i.icon_widget) self.items_with_icon = [] for i in items: # Set size of each arc if SVGEditor.get_element(i.widget, "arc") is not None: l = SVGEditor.get_element(i.widget, "arc") radius = float( l.attrib["radius"] ) # TODO: Find how to get value of 'sodipodi:rx' l.attrib["d"] = l.attrib["d-template"] % ( radius * cos(a1) + image_width / 2, radius * sin(a1) + image_width / 2, radius * cos(a2) + image_width / 2, radius * sin(a2) + image_width / 2, ) # Rotate arc to correct position i.a = (360.0 / float(len(self.items))) * float(index) SVGEditor.rotate(i.widget, i.a, image_width * 0.5, image_width * 0.5) # Check if there is any icon icon_file, has_colors = find_icon(i.icon, False) if hasattr( i, "icon") else (None, False) if icon_file: # Icon - hide all text and place MenuIcon widget on top of image self.editor.remove_element( SVGEditor.get_element(i.widget, "menuitem_text")) self.editor.remove_element( SVGEditor.get_element(i.widget, "line0")) self.editor.remove_element( SVGEditor.get_element(i.widget, "line2")) i.icon_widget = MenuIcon(icon_file, has_colors) i.icon_widget.set_name("osd-radial-menu-icon") i.icon_widget.set_size_request(self.ICON_SIZE * self.scale, self.ICON_SIZE * self.scale) self.b.get_parent().put(i.icon_widget, 200, 200) self.items_with_icon.append(i) else: # No icon - rotate text in arc to other direction to keep it horisontal if SVGEditor.get_element(i.widget, "menuitem_text") is not None: l = SVGEditor.get_element(i.widget, "menuitem_text") l.attrib['id'] = "text_" + i.id l.attrib['transform'] = "%s rotate(%s)" % ( l.attrib['transform'], -i.a) # Place up to 3 lines of item label label = i.label.split("\n") first_line = 0 if len(label) == 1: self.editor.remove_element( SVGEditor.get_element(i.widget, "line0")) self.editor.remove_element( SVGEditor.get_element(i.widget, "line2")) first_line = 1 elif len(label) == 2: self.editor.remove_element( SVGEditor.get_element(i.widget, "line0")) first_line = 1 for line in xrange(0, len(label)): l = SVGEditor.get_element(i.widget, "line%s" % (first_line + line, )) if l is None: break SVGEditor.set_text(l, label[line]) # Continue with next menu item i.index = index index += 1 self.editor.remove_element("menuitem_template") self.editor.commit() del self.editor
def generate_widget(self, item): e = self.editor.clone_element("menuitem_template") SVGEditor.set_text(e, item.label) e.attrib['id'] = "menuitem_" + item.id return e
def pack_items(self, trash, items): if self._size > 0 and self._size < 100: self.scale = self._size / 100.0 root = SVGEditor.get_element(self.editor, "root") SVGEditor.scale(root, self.scale) pb = self.b.get_pixbuf() # Image width is not scaled as everything bellow operates # in 'root' object coordinate space image_width = pb.get_width() index = 0 item_offset = 360.0 / len(self.items) a1 = (-90.0 - item_offset * 0.5) * PI / 180.0 a2 = (-90.0 + item_offset * 0.5) * PI / 180.0 for i in self.items_with_icon: i.icon_widget.get_parent().remove_child(i.icon_widget) self.items_with_icon = [] for i in items: # Set size of each arc if SVGEditor.get_element(i.widget, "arc") is not None: l = SVGEditor.get_element(i.widget, "arc") radius = float(l.attrib["radius"]) # TODO: Find how to get value of 'sodipodi:rx' l.attrib["d"] = l.attrib["d-template"] % ( radius * cos(a1) + image_width / 2, radius * sin(a1) + image_width / 2, radius * cos(a2) + image_width / 2, radius * sin(a2) + image_width / 2, ) # Rotate arc to correct position i.a = (360.0 / float(len(self.items))) * float(index) SVGEditor.rotate(i.widget, i.a, image_width * 0.5, image_width * 0.5) # Check if there is any icon icon_file, has_colors = find_icon(i.icon, False) if hasattr(i, "icon") else (None, False) if icon_file: # Icon - hide all text and place MenuIcon widget on top of image self.editor.remove_element(SVGEditor.get_element(i.widget, "menuitem_text")) self.editor.remove_element(SVGEditor.get_element(i.widget, "line0")) self.editor.remove_element(SVGEditor.get_element(i.widget, "line2")) i.icon_widget = MenuIcon(icon_file, has_colors) i.icon_widget.set_name("osd-radial-menu-icon") i.icon_widget.set_size_request(self.ICON_SIZE * self.scale, self.ICON_SIZE * self.scale) self.b.get_parent().put(i.icon_widget, 200, 200) self.items_with_icon.append(i) else: # No icon - rotate text in arc to other direction to keep it horisontal if SVGEditor.get_element(i.widget, "menuitem_text") is not None: l = SVGEditor.get_element(i.widget, "menuitem_text") l.attrib['id'] = "text_" + i.id l.attrib['transform'] = "%s rotate(%s)" % (l.attrib['transform'], -i.a) # Place up to 3 lines of item label label = i.label.split("\n") first_line = 0 if len(label) == 1: self.editor.remove_element(SVGEditor.get_element(i.widget, "line0")) self.editor.remove_element(SVGEditor.get_element(i.widget, "line2")) first_line = 1 elif len(label) == 2: self.editor.remove_element(SVGEditor.get_element(i.widget, "line0")) first_line = 1 for line in xrange(0, len(label)): l = SVGEditor.get_element(i.widget, "line%s" % (first_line + line,)) if l is None: break SVGEditor.set_text(l, label[line]) # Continue with next menu item i.index = index index += 1 self.editor.remove_element("menuitem_template") self.editor.commit() del self.editor