0

The wxWidgets project uses GTK in Linux, and my wxPython-based application with basic components makes a lot of warnings and errors for which I as a python coder/end user have not much to do about it.

The errors distract my standard streams and aren't fatal to my program. The usual ones in my case are:

(python2.6:9886): Gtk-WARNING **: gtk_widget_size_allocate(): attempt to allocate widget with width -4 and height 13
(python2.6:9886): Gtk-CRITICAL **: gtk_widget_is_ancestor: assertion `ancestor != NULL' failed

Is it so bad a practice to suppress this kind of third-party errors from my part? And how is this done?

1
  • what version of wxPython do you use?
    – Igor
    Commented Mar 10, 2023 at 13:25

3 Answers 3

1

It's not coming from wxPython -- it's from GTK itself. You can fix the first one by ensuring positive values (or -1 for "any") are used for the size values when creating Controls.

I'm not too sure on the second one - can you pinpoint what widget/event triggers it? I was having one error about printing and that was due to not having CUPS set up properly.

2
  • The second error spams twice every time I switch tabs in wx.Notebook. But there are other cases as well. I appreciate your knowledge of GTK workings but I'm not sure whether I want to go on pleasing the GTK gods instead of focusing on the python
    – mike3996
    Commented Aug 9, 2010 at 7:23
  • Well the fact you're creating a control with a width of -4 shows that you're doing something wrong ;). Ah...notebooks - are you sure that your notebook's children have their parents set correctly? You can't supress them - for example, opening Nautilus from the command line often shows GTK warnings - but they're not generated from the program, per say. Commented Aug 9, 2010 at 12:25
0

Just redirect stderr somewhere else.

import sys
sys.stderr = open("some path")

Or you could redirect to a class with a Write method that does nothing.

2
  • It doesn't do the job. I tried redirecting before wx.App and I tried redirecting in my wx.Frame's __init__ to no avail.
    – mike3996
    Commented Aug 6, 2010 at 22:10
  • Hmmm...must be getting redirected in the C++ portion of wx, not the Python portion. Try dropping a line to the official wxPython mailing list. They'll have ideas. Commented Aug 9, 2010 at 16:29
0

using PySide6... had similar warning from Gtk when using QFileDialog static methods. (QFileDialog.getSaveFilename, etc)

when I built the object without using static method, the warning disappeared. (eg obj = QFileDialog(), obj.setFileMode(QFileDialog.FileMode.ExistingFile) ... )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.