Search code examples
python-2.7gtkwarningsmarkuppygobject

GTK: Error while adding some style to text


Recently, while doing some experiments and playing with GTK + Python2 (Glade not included) I discovered some interesting behaviour while adding some "style" to my text, which, in fact, is some standard markup that usually is accepted by GTK as a valid input, BUT if I try to add the "mnemonic" property to the text itself while using markup too, it will throw a GTK-WARNING saying that something went wrong (Markup wasn't applied) BUT it was applied indeed!

Some images to clarify my situation:


Mnemonic: False & Markup: True ----> OK

1.png


Mnemonic: True & Markup: False ----> OK

2.png


Mnemonic: True & Markup: True ----> GTK-WARNING (But everything's fine...)

3.png

4.png

Supposed "Problematic" line:

Label_1.set_markup_with_mnemonic('<span font_desc="Monospace 64" underline="none"> _Text </span>')

I firmly believe that this line shouldn't be a problem, because, as I've explained before, this just happens if I try to add "Mnemonics & Markup" properties at the same time, and nonetheless, it displays and works correctly.

Now, for the real question:

Is there any possible way to get rid of this useless GTK-WARNING directly from Python (Not needing to use shell features like redirecting to /dev/null, because I'm trying to make this app "shell-proof")

Or if there's a way to solve this issue?

Or either to workaround this?

Hints:

  • Maybe "_" means something in markup that works like a tag ("<i>")?
  • GTK Bug?
  • Glade suffers from this rare situation too!

Solution

  • Nevermind, it was some kind of weird error inside the markup string.

    Don't use <span font_desc=something...

    Instead use <span font=something...

    This way, GTK won't complain anymore. Maybe this proves that _ is used for something else in Pango's Markup code?