def _clone_menu(self, xml, name, owner=None): """Menu duplicator Hopefully temporary hack for converting UIManager XML describing the main menubar into a rebindable popup menu. UIManager by itself doesn't let you do this, by design, but we need a bigger menu than the little things it allows you to build. """ ui_elt = ET.fromstring(xml) rootmenu_elt = ui_elt.find("menubar") rootmenu_elt.attrib["name"] = name xml = ET.tostring(ui_elt) xml = xml.decode("utf-8") self.app.ui_manager.add_ui_from_string(xml) tmp_menubar = self.app.ui_manager.get_widget('/' + name) popupmenu = Gtk.Menu() for item in tmp_menubar.get_children(): tmp_menubar.remove(item) popupmenu.append(item) if owner is not None: popupmenu.attach_to_widget(owner, None) popupmenu.set_title("MyPaint") popupmenu.connect("selection-done", self.popupmenu_done_cb) popupmenu.connect("deactivate", self.popupmenu_done_cb) popupmenu.connect("cancel", self.popupmenu_done_cb) self.popupmenu_last_active = None return popupmenu