def generate_widget(self, item): """ Generates gtk widget for specified menutitem """ if isinstance(item, Separator) and item.label: widget = Gtk.Button.new_with_label(item.label) widget.set_relief(Gtk.ReliefStyle.NONE) widget.set_name("osd-menu-separator") return widget elif isinstance(item, Separator): widget = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL) widget.set_name("osd-menu-separator") return widget else: widget = Gtk.Button.new_with_label(item.label) widget.set_relief(Gtk.ReliefStyle.NONE) if hasattr(widget.get_children()[0], "set_xalign"): widget.get_children()[0].set_xalign(0) else: widget.get_children()[0].set_halign(Gtk.Align.START) if isinstance(item, Submenu): item.callback = self.show_submenu label1 = widget.get_children()[0] label2 = Gtk.Label(_(">>")) label2.set_property("margin-left", 30) box = Gtk.Box(Gtk.Orientation.HORIZONTAL) widget.remove(label1) box.pack_start(label1, True, True, 1) box.pack_start(label2, False, True, 1) widget.add(box) widget.set_name("osd-menu-item") elif item.id is None: widget.set_name("osd-menu-dummy") else: widget.set_name("osd-menu-item") if isinstance(item.icon, Gio.FileIcon): icon_file = item.icon.get_file().get_path() has_colors = True elif isinstance(item.icon, Gio.ThemedIcon): icon = Gtk.IconTheme.get_default().choose_icon( item.icon.get_names(), 64, 0) icon_file = icon.get_filename() if icon else None has_colors = True else: icon_file, has_colors = find_icon(item.icon, self.PREFER_BW_ICONS) if icon_file: icon = MenuIcon(icon_file, has_colors) label = widget.get_children()[0] for c in [] + widget.get_children(): widget.remove(c) box = Gtk.Box() box.pack_start(icon, False, True, 0) box.pack_start(label, True, True, 10) widget.add(box) return widget
def success(*a): log.error("Sucessfully locked input") config = self.controller.load_gui_config(os.path.join( get_share_path(), "images")) if config and config["gui"] and config["gui"]["buttons"]: buttons = config["gui"]["buttons"] try: for i in xrange(len(self._icons)): icon = self._icons[i] name = buttons[self.BUTTON_INDEXES[i]] filename, trash = find_icon("buttons/%s" % name) icon.set_filename(filename) icon.queue_draw() except IndexError: pass
def update_menu_icon(self): lblItemIconName = self.builder.get_object("lblItemIconName") if self.selected_icon is None: lblItemIconName.set_label(_("(no icon)")) self.menu_icon.set_visible(False) else: lblItemIconName.set_label(self.selected_icon) try: filename, trash = find_icon(self.selected_icon) self.menu_icon.set_filename(filename) self.menu_icon.set_visible(True) except Exception, e: log.error(e) log.error(traceback.format_exc()) self.menu_icon.set_visible(False)
def success(*a): log.error("Sucessfully locked input") config = self.controller.load_gui_config( os.path.join(get_share_path(), "images")) if config and config["gui"] and config["gui"]["buttons"]: buttons = config["gui"]["buttons"] try: for i in xrange(len(self._icons)): icon = self._icons[i] name = buttons[self.BUTTON_INDEXES[i]] filename, trash = find_icon("buttons/%s" % name) icon.set_filename(filename) icon.queue_draw() except IndexError: pass
def generate_widget(self, item): """ In QuickMenu, everything but submenus and simple menuitems is ignored. """ if self._button_index >= len(self.BUTTONS): return None if isinstance(item, (MenuItem, Submenu)): widget = Gtk.Button.new_with_label(item.label) widget.set_relief(Gtk.ReliefStyle.NONE) if hasattr(widget.get_children()[0], "set_xalign"): widget.get_children()[0].set_xalign(0) else: widget.get_children()[0].set_halign(Gtk.Align.START) if isinstance(item, Submenu): item.callback = self.show_submenu label1 = widget.get_children()[0] label2 = Gtk.Label(_(">>")) label2.set_property("margin-left", 30) box = Gtk.Box(Gtk.Orientation.HORIZONTAL) widget.remove(label1) box.pack_start(label1, True, True, 1) box.pack_start(label2, False, True, 1) widget.add(box) widget.set_name("osd-menu-item") elif item.id is None: # Ignored as well return None else: widget.set_name("osd-menu-item") item.button = self.BUTTONS[self._button_index] self._button_index += 1 icon_file, has_colors = find_icon("buttons/%s" % item.button, False) icon = MenuIcon(icon_file, has_colors) label = widget.get_children()[0] for c in [] + widget.get_children(): widget.remove(c) self._icons.append(icon) box = Gtk.Box() box.pack_start(icon, False, True, 0) box.pack_start(label, True, True, 10) widget.add(box) return widget return None
def generate_widget(self, item): if isinstance(item, Separator): # Ignored here return None elif item.id is None: # Dummies are ignored as well return None else: icon_file, has_colors = find_icon(item.icon, False) if icon_file: # Gridmenu hides label when icon is displayed widget = Gtk.Button() widget.set_relief(Gtk.ReliefStyle.NONE) widget.set_name("osd-menu-item-big-icon") if isinstance(item, Submenu): item.callback = self.show_submenu icon = MenuIcon(icon_file, has_colors) widget.add(icon) return widget else: return Menu.generate_widget(self, item)
def on_tvItems_cursor_changed(self, view): entName = self.builder.get_object("entName") lblLicense = self.builder.get_object("lblLicense") rvLicense = self.builder.get_object("rvLicense") icon = self.get_selected() if icon: entName.set_text(icon) full_path, trash = find_icon(icon) if full_path: path, name = os.path.split(full_path) license = IconChooser.find_license(path, name) if license and "(CC 0)" in license: # My own icons license = license.replace("(CC 0)", "").strip(" ,") else: license = None if license: m = RE_URL.match(license) if m: license = "%s<a href='%s'>%s</a>%s" % ( m.group(1), m.group(2), m.group(2), m.group(3)) lblLicense.set_markup(_("Free-use icon created by %s" % (license,))) rvLicense.set_reveal_child(bool(license))
def on_tvItems_cursor_changed(self, view): entName = self.builder.get_object("entName") lblLicense = self.builder.get_object("lblLicense") rvLicense = self.builder.get_object("rvLicense") icon = self.get_selected() if icon: entName.set_text(icon) full_path, trash = find_icon(icon) if full_path: path, name = os.path.split(full_path) license = IconChooser.find_license(path, name) if license and "(CC 0)" in license: # My own icons license = license.replace("(CC 0)", "").strip(" ,") else: license = None if license: m = RE_URL.match(license) if m: license = "%s<a href='%s'>%s</a>%s" % ( m.group(1), m.group(2), m.group(2), m.group(3)) lblLicense.set_markup( _("Free-use icon created by %s" % (license, ))) rvLicense.set_reveal_child(bool(license))
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 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