GTK error messages

90 views
Skip to first unread message

Michael Eager

unread,
Dec 28, 2020, 4:28:23 PM12/28/20
to wx-u...@googlegroups.com, wxpytho...@googlegroups.com
I'm running a wxPython program using a wx.ScrolledWindow. I'm getting a
lot of the following console messages:

(main.py:1170792): Gtk-CRITICAL **: 08:59:46.366:
gtk_box_gadget_distribute: assertion 'size >= 0' failed in GtkScrollbar

I'm guessing that there is something in the way that the ScrolledWindow
widget is initialized that is incorrect or incomplete.

Can anyone suggest how to debug this?

What's the best way to track back from a GTK error to the wxWidgets code
triggering the error?

wxWidgets Library Version 3.1.5, Compiled Dec 17, 2020 (using pip3).
Runtime version 3.22. Compile-time GTK 3.22.30.

--
Michael Eager

Scott Talbert

unread,
Dec 28, 2020, 9:39:07 PM12/28/20
to wx-u...@googlegroups.com, wxpytho...@googlegroups.com
Unfortunately, GTK is rather noisy with its warnings and this doesn't
*necessarily* indicate that there's a bug somewhere (although there could
be). Do you see any problems in your application?

You can make a GTK program abort on the first warning using a special
command line option, --g-fatal-warnings. With this you can get a stack
trace with gdb when the warning occurs. Doing it with Python is a little
tricky, but here's how you can do it:

$ gdb python3

...

(gdb) run <your program>.py --g-fatal-warnings

Then you should be able to get a stack trace, debug, etc. when one of
those warnings occurs.

Scott

gunter.ko...@gmail.com

unread,
Dec 28, 2020, 11:56:30 PM12/28/20
to wx-users
These error messages tend yo disappear or to change with gtk updates and sometimes it is impossible to avoid them.
In the current GTK they seem  no more to be named "critical',  but only " warning".

Marian Beermann

unread,
Dec 29, 2020, 9:30:59 AM12/29/20
to wx-u...@googlegroups.com, gunter.ko...@gmail.com
One can install a glib log writer (through g_log_set_writer_func via
ctypes) to discard or log GTK's noise somewhere else.

-Marian

Am 29.12.20 um 05:56 schrieb gunter.ko...@gmail.com:
> --
> Please read http://www.wxwidgets.org/support/mlhowto.htm
> <http://www.wxwidgets.org/support/mlhowto.htm> before posting.
>  
> To unsubscribe, send email to wx-users+u...@googlegroups.com
> or visit http://groups.google.com/group/wx-users
> <http://groups.google.com/group/wx-users>
> ---
> You received this message because you are subscribed to the Google
> Groups "wx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to wx-users+u...@googlegroups.com
> <mailto:wx-users+u...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/wx-users/8e206cab-e09f-403f-bb4b-630f9d3f3760n%40googlegroups.com
> <https://groups.google.com/d/msgid/wx-users/8e206cab-e09f-403f-bb4b-630f9d3f3760n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Michael Eager

unread,
Dec 29, 2020, 11:54:57 AM12/29/20
to wxpytho...@googlegroups.com, Scott Talbert, wx-u...@googlegroups.com
Thanks. I'll give that a try.

Would it help to build a local debug version of wxWidgets?


--
Michael Eager

Michael Eager

unread,
Dec 29, 2020, 12:00:37 PM12/29/20
to wx-u...@googlegroups.com, Marian Beermann, gunter.ko...@gmail.com
On 12/29/20 6:30 AM, Marian Beermann wrote:
> One can install a glib log writer (through g_log_set_writer_func via
> ctypes) to discard or log GTK's noise somewhere else.
>
> -Marian
>

Is there a way to do this from wxPython?

How is ctypes involved?


--
Michael Eager

Vadim Zeitlin

unread,
Dec 29, 2020, 12:03:12 PM12/29/20
to wx-u...@googlegroups.com, wxpytho...@googlegroups.com
On Tue, 29 Dec 2020 08:54:48 -0800 Michael Eager wrote:

ME> Would it help to build a local debug version of wxWidgets?

Yes, you definitely want to have debug symbols for wx and installing the
package with the debug symbols for GTK itself (typically provided by your
distribution) can often be helpful too.

Concerning the actual problem, I'm almost sure that it's harmless and just
due to the fact that the top level window itself is initially too small and
doesn't have enough space for all the children inside it. But it shouldn't
be difficult to confirm that this is indeed the case by looking at the
stack trace when the warning is given.

Good luck,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Michael Eager

unread,
Dec 29, 2020, 1:29:10 PM12/29/20
to wx-u...@googlegroups.com, Marian Beermann, gunter.ko...@gmail.com
Never mind. I was thinking of C ctypes.h. I found Python ctypes,
something I'd not used before.


--
Michael Eager

Michael Eager

unread,
Jan 4, 2021, 12:52:30 PM1/4/21
to wx-u...@googlegroups.com, Marian Beermann, gunter.ko...@gmail.com
On 12/28/20 1:28 PM, Michael Eager wrote:
> I'm running a wxPython program using a wx.ScrolledWindow. I'm getting a
> lot of the following console messages: ...

On 12/29/20 6:30 AM, Marian Beermann wrote:
> One can install a glib log writer (through g_log_set_writer_func via
> ctypes) to discard or log GTK's noise somewhere else.
>
> -Marian

I created a library which installs a glib_log_writer which filters out
the unwanted messages while allowing other messages to be logged
normally. This could be generalized to pass a list of messages from the
wxpython application to the filter instead of hard-coding the text.

---

In the wxpython application:

import ctypes

def SetGtkLogger(quiet):
mygtk = ctypes.cdll.LoadLibrary('./libfiltergtk.so')
mygtk.setgtklogger(quiet)

def main(argv):
SetGtkLogger(1)
...

---

$ cat filtergtk.c
#include <string.h>
#include <glib.h>
#include <stdio.h>

//#define DEBUG

void
print_fields (const GLogField *fields,
gsize n_fields)
{
#ifdef DEBUG
int i;
for (i = 0; i < n_fields; i++)
printf ("[%d]: ('%s':'%s')\n", i, fields[i].key,
fields[i].value);
#endif
}

static GLogWriterOutput
mylogwriter (GLogLevelFlags log_level,
const GLogField *fields,
gsize n_fields,
gpointer user_data)
{
print_fields (fields, n_fields);

if ((log_level == G_LOG_LEVEL_CRITICAL) &&
strstr (fields[4].value, "gtk_box_gadget_distribute"))
return G_LOG_WRITER_HANDLED;

return g_log_writer_default (log_level, fields, n_fields,
user_data);

}

void
setgtklogger (int quiet)
{
g_log_set_writer_func (mylogwriter, NULL, NULL);
if (!quiet)
g_message ("Installed local gtk message writer");
}

---

$ cat Makefile
# makefile for gtk message filter library
#
#

libfiltergtk.so: filtergtk.o
gcc -shared -o libfiltergtk.so -lglib-2.0 filtergtk.o

filtergtk.o: filtergtk.c
gcc -c -fPIC -I /usr/include/glib-2.0/ -I
/usr/lib64/glib-2.0/include/ filtergtk.c

clean:
rm -f filtergtk.o libfiltergtk.so


[Watch out for email replacing tabs with blanks in the makefile.]

--
Michael Eager

Gunter Königsmann

unread,
Jan 5, 2021, 3:20:37 AM1/5/21
to Michael Eager, wx-u...@googlegroups.com, Marian Beermann
If that would be a possible feature of wxLogger? The option to redirect gtk messages to a log panel, along with the wxWidgets one?
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

Vadim Zeitlin

unread,
Jan 5, 2021, 4:13:48 PM1/5/21
to wx-u...@googlegroups.com
On Tue, 05 Jan 2021 09:20:30 +0100 Gunter Königsmann wrote:

GK> If that would be a possible feature of wxLogger? The option to redirect
GK> gtk messages to a log panel, along with the wxWidgets one?

I'm not sure if it really makes sense for wxLog, which is about
(re)directing the messages generated by wx programs somewhere, not about
intercepting the messages from somewhere else. This functionality also
doesn't have any portable equivalent, AFAIK. So I think that the best we
could do would be to provide some GTK-specific function for such
redirection, but this doesn't have much advantage compared to just doing
the same thing in the application code.

Regards,

Michael Eager

unread,
Jan 7, 2021, 10:52:29 AM1/7/21
to wx-u...@googlegroups.com, wxpytho...@googlegroups.com
On 1/5/21 1:13 PM, Vadim Zeitlin wrote:
> On Tue, 05 Jan 2021 09:20:30 +0100 Gunter Königsmann wrote:
>
> GK> If that would be a possible feature of wxLogger? The option to redirect
> GK> gtk messages to a log panel, along with the wxWidgets one?
>
> I'm not sure if it really makes sense for wxLog, which is about
> (re)directing the messages generated by wx programs somewhere, not about
> intercepting the messages from somewhere else. This functionality also
> doesn't have any portable equivalent, AFAIK. So I think that the best we
> could do would be to provide some GTK-specific function for such
> redirection, but this doesn't have much advantage compared to just doing
> the same thing in the application code.


It may not make sense for wxLog, but if GTK generates spurious messages
with wx, putting some kind of GTK message manager in the wx library
seems like a good idea.

In a C/C++ program, it may be easy to just put the code in the
application. With wxPython, it's more awkward. If one takes my
approach, using a separate library, it needs to be built, distributed,
and installed along with the Python code. It would be better to be in
wx and wrapped by wxPython.

--
Michael Eager

Vadim Zeitlin

unread,
Jan 7, 2021, 11:54:18 AM1/7/21
to wx-u...@googlegroups.com, Michael Eager
On Thu, 7 Jan 2021 07:52:21 -0800 Michael Eager wrote:

ME> It may not make sense for wxLog, but if GTK generates spurious messages
ME> with wx, putting some kind of GTK message manager in the wx library
ME> seems like a good idea.
ME>
ME> In a C/C++ program, it may be easy to just put the code in the
ME> application. With wxPython, it's more awkward. If one takes my
ME> approach, using a separate library, it needs to be built, distributed,
ME> and installed along with the Python code. It would be better to be in
ME> wx and wrapped by wxPython.

This is indeed a good point and I'd be glad to add a GTK-specific function
(in wxApp, probably) or a class (if just a function isn't enough) for
wxPython and other wrappers if anybody feels motivated to make a PR adding it.
Reply all
Reply to author
Forward
0 new messages