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
评论列表
文章目录