Phoenix icon indicating copy to clipboard operation
Phoenix copied to clipboard

wx.lib.editor.Editor gets stuck in a loop generating "drawing failure for widget" messages

Open ghost opened this issue 1 year ago • 7 comments

Operating system: Linux Mint 22 wxPython version & source: wxPython 4.2.2 gtk3 (phoenix) wxWidgets 3.2.6 from pypi Python version & source: 3.12.3 from distro

It also occurs with wxPython 4.2.1 gtk3 (phoenix) wxWidgets 3.2.2.1 + Python 3.10.12 + Linux Mint 21.3

Description of the problem:

In the wxPython demo, the Editor control never fully appears. Continuous warning messages are output to the command line.

As a side effect, entries in the demo's tree control for other recently used examples turn invisible on a grey background.

See this animated gif (click the play button, if necessary):

editor_demo_1-2024-10-29_11 20 49

Code Example (click to expand)

This is the example from the demo, modified to run stand-alone:

import wx
import wx.lib.editor as editor


class TestFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent)

        win = wx.Panel(self, -1)
        ed = editor.Editor(win, -1, style=wx.SUNKEN_BORDER)
        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(ed, 1, wx.ALL|wx.GROW, 1)
        win.SetSizer(box)
        win.SetAutoLayout(True)

        ed.SetText(["",
                    "This is a simple text editor, the class name is",
                    "Editor.  Type a few lines and try it out.",
                    "",
                    "It uses Windows-style key commands that can be overridden by subclassing.",
                    "Mouse select works. Here are the key commands:",
                    "",
                    "Cursor movement:     Arrow keys or mouse",
                    "Beginning of line:   Home",
                    "End of line:         End",
                    "Beginning of buffer: Control-Home",
                    "End of the buffer:   Control-End",
                    "Select text:         Hold down Shift while moving the cursor",
                    "Copy:                Control-Insert, Control-C",
                    "Cut:                 Shift-Delete,   Control-X",
                    "Paste:               Shift-Insert,   Control-V",
                    ""])


if __name__ == '__main__':
    app = wx.App()
    frame = TestFrame(None)
    frame.Show()
    app.MainLoop()

The first few error message on the command line:

(Editor_2.py:8883): Gtk-WARNING **: 13:25:30.814: drawing failure for widget 'wxPizza': invalid value for an input cairo_format_t

(Editor_2.py:8883): Gtk-WARNING **: 13:25:30.815: drawing failure for widget 'GtkScrolledWindow': invalid value for an input cairo_format_t

(Editor_2.py:8883): Gtk-WARNING **: 13:25:30.815: drawing failure for widget 'wxPizza': invalid value for an input cairo_format_t

(Editor_2.py:8883): Gtk-WARNING **: 13:25:30.815: drawing failure for widget 'wxPizza': invalid value for an input cairo_format_t

(Editor_2.py:8883): Gtk-WARNING **: 13:25:30.815: drawing failure for widget 'GtkBox': invalid value for an input cairo_format_t

(Editor_2.py:8883): Gtk-WARNING **: 13:25:30.815: drawing failure for widget 'GtkWindow': invalid value for an input cairo_format_t

(Editor_2.py:8883): Gtk-WARNING **: 13:25:30.824: drawing failure for widget 'wxPizza': invalid value for an input cairo_format_t

(Editor_2.py:8883): Gtk-WARNING **: 13:25:30.824: drawing failure for widget 'GtkScrolledWindow': invalid value for an input cairo_format_t

(Editor_2.py:8883): Gtk-WARNING **: 13:25:30.824: drawing failure for widget 'wxPizza': invalid value for an input cairo_format_t

(Editor_2.py:8883): Gtk-WARNING **: 13:25:30.824: drawing failure for widget 'wxPizza': invalid value for an input cairo_format_t

(Editor_2.py:8883): Gtk-WARNING **: 13:25:30.824: drawing failure for widget 'GtkBox': invalid value for an input cairo_format_t

ghost avatar Oct 29 '24 13:10 ghost

Further experiments with the Code Example indicate that the OnPaint() method is repeatedly being called.

If I drag the editor's vertical scrollbar to the bottom and the horizontal scrollbar to the right, then the messages stop being generated. However, the text is never displayed.

ghost avatar Oct 29 '24 18:10 ghost

Interestingly, I can't reproduce it, at least on Fedora 40.

swt2c avatar Nov 08 '24 23:11 swt2c

Is Fedora 40 using Wayland?

Edit: I have checked my other machines.

The bug occurs with:

  • wxPython 4.2.2 gtk3 (phoenix) wxWidgets 3.2.6 + Python 3.12.3 + Linux Mint 22
  • wxPython 4.2.1 gtk3 (phoenix) wxWidgets 3.2.2.1 + Python 3.10.12 + Linux Mint 21.3

But not with:

  • wxPython 4.2.2 osx-cocoa (phoenix) wxWidgets 3.2.6 + Python 3.12.6 + macOS Sequoia 15.1

ghost avatar Nov 09 '24 09:11 ghost

Is Fedora 40 using Wayland?

Yes, my test was with Wayland. Are you using Wayland also?

swt2c avatar Nov 11 '24 23:11 swt2c

Is Fedora 40 using Wayland?

Yes, my test was with Wayland. Are you using Wayland also?

No, I'm using X11 which is standard on Mint.

ghost avatar Nov 12 '24 07:11 ghost

If I add a call to self.Layout() in TestFrame.__init__(), the the program only outputs a small number of Gtk-WARNING messages (i.e. it doesn't get stuck in a loop). However, the Editor control is still not displayed.

In wx/lib/editor/editor.py the following method is defined:

    def DrawSimpleCursor(self, xp, yp, dc = None, old=False):
        if not dc:
            dc = wx.ClientDC(self)

        if old:
            xp = self.sco_x
            yp = self.sco_y

        szx = self.fw
        szy = self.fh
        x = xp * szx
        y = yp * szy
        dc.Blit(x,y, szx,szy, dc, x,y, wx.XOR)
        self.sco_x = xp
        self.sco_y = yp

If I comment out the call to dc.Blit() then the Gtk-WARNING messages are not output and the Editor control and its content are displayed as expected.

If I comment out the dc.Blit() call without adding the call to self.Layout() to TestFrame.__init__() then the Editor control does appear, but the text contents flicker rapidly until I click in the control.

ghost avatar Nov 12 '24 11:11 ghost

Indeed, I can reproduce this under X11.

swt2c avatar Nov 14 '24 04:11 swt2c