GNOME Bugzilla – Bug 690921
Gtk.UIManager add_ui_from_string cannot handle 2 byte UTF symbols
Last modified: 2012-12-31 15:38:59 UTC
Trying to set following ui def: <ui><menubar name="MenuBar"><menu action="ToolsMenu"><placeholder name="P_ToolsMenu"><menu action="Analys-och-utforskning"><menuitem action="dbrowse"/><menuitem action="eventcmp"/></menu><menu action="Bearbetar-Släktträd"><menuitem action="dupfind"/><menuitem action="excity"/><menuitem action="patchnames"/><menuitem action="chname"/><menuitem action="editowner"/><menuitem action="mergecitations"/><menuitem action="reorder_ids"/><menuitem action="sortevents"/><menuitem action="evname"/><menuitem action="chtype"/></menu><menu action="Felsökning"><menuitem action="test_for_date_parser_and_displayer"/><menuitem action="dgenstats"/><menuitem action="testcasegenerator"/><menuitem action="populatesources"/><menuitem action="eval"/><menuitem action="leak"/></menu><menu action="Hjälpmedel"><menuitem action="not_related"/><menuitem action="mediaman"/><menuitem action="soundgen"/><menuitem action="relcalc"/><menuitem action="verify"/></menu><menu action="Reparera-Släktträd"><menuitem action="rebuild_refmap"/><menuitem action="check"/><menuitem action="rebuild"/><menuitem action="remove_unused"/><menuitem action="rebuild_genstats"/></menu></placeholder></menu></menubar></ui> Gives the error: self.tool_menu_ui_id = self.uistate.uimanager.add_ui_from_string(uidef)
+ Trace 231327
return Gtk.UIManager.add_ui_from_string(self, buffer, length)
return info.invoke(*args, **kwargs)
Translation: gi._glib.GError:Error on line 1 character 1182:The document ended unexpectedly within the closing tag for the element "menubar" The length of the string is 1181. 1182 points outside the string. The reason seems to be 2 byte UTF-8 symbols. overrides/GTK.py does: class UIManager(Gtk.UIManager): def add_ui_from_string(self, buffer): if not isinstance(buffer, _basestring): raise TypeError('buffer must be a string') length = len(buffer) return Gtk.UIManager.add_ui_from_string(self, buffer, length) which sets length to the number of characters in the buffer, while length should be the byte length I presume. Workaround: there is no need for UTF-8 symbols in the ui string, so keep actions ASCII only, and set in the Gtk.Action the label to the UTF-8 to be shown (http://developer.gnome.org/gtk3/stable/GtkAction.html#gtk-action-new)
I forgot to mention this is only with python 3. In python 2 this works. Also, some other UTF-8 strings do seem to work, so this might be more complicated than simply using a special UTF-8 symbol.
This was fixed recently, see bug 690329. *** This bug has been marked as a duplicate of bug 690329 ***