OnPaint Windows Problems...

Hello NG,

    always regarding the porting of C++ code to Python, I am having problems
in a OnPaint function. Essentially, I need to draw some horizontal lines.
These "lines" are stored in self._items, together with other windows (that
I don't care of, I need only the lines). These lines have some properties
like GetLineY(), GetSpacing() and so on, but that's not relevant. The coordinates
with which I call DrawLine() are correct.
This is my OnPaint() call:

    def OnPaint(self, event):

        """Handle the EVT_PAINT event in the FoldPanelItem. """

        # draw all the items that are lines

        dc = wx.PaintDC(self)
        vertical = self.IsVertical()

        for i in range(0, len(self._items)):
            item = self._items[i]

            if item.GetType() == "SEPARATOR":
                pen = wx.Pen(item.GetLineColour(), 1, wx.SOLID)
                dc.SetPen(pen)
                a = item.GetLeftSpacing()
                b = item.GetLineY() + item.GetSpacing()
                c = item.GetLineLength()
                d = a + c

                if vertical:
                    dc.DrawLine(a, b, d, b)
                else:
                    dc.DrawLine(b, a, b, d)

        event.Skip()

The problem is that, when I resize the window, the lines are redrawn but
they appear corrupted (discontinuous), with some blank space in a single
line, like in this small representation:

_______________ ___ __ ________ ___ _

The effect disappears if I minimize and then maximize my main frame.

Does anyone have some suggestions/pointers?

Thank you a lot.

Andrea.

andrea_gavana@tin.it wrote:

Hello NG,

    always regarding the porting of C++ code to Python, I am having problems
in a OnPaint function. Essentially, I need to draw some horizontal lines.
These "lines" are stored in self._items, together with other windows (that
I don't care of, I need only the lines). These lines have some properties
like GetLineY(), GetSpacing() and so on, but that's not relevant. The coordinates
with which I call DrawLine() are correct. This is my OnPaint() call:

    def OnPaint(self, event):

        """Handle the EVT_PAINT event in the FoldPanelItem. """
                # draw all the items that are lines

        dc = wx.PaintDC(self)
        vertical = self.IsVertical()

        for i in range(0, len(self._items)):
            item = self._items[i]

Why don't you do it this way:

          for item in self._items:

                        if item.GetType() == "SEPARATOR":
                pen = wx.Pen(item.GetLineColour(), 1, wx.SOLID)
                dc.SetPen(pen)
                a = item.GetLeftSpacing()
                b = item.GetLineY() + item.GetSpacing()
                c = item.GetLineLength()
                d = a + c
                                if vertical:
                    dc.DrawLine(a, b, d, b)
                else:
                    dc.DrawLine(b, a, b, d)

        event.Skip()

The problem is that, when I resize the window, the lines are redrawn but
they appear corrupted (discontinuous), with some blank space in a single
line, like in this small representation:

_______________ ___ __ ________ ___ _

The effect disappears if I minimize and then maximize my main frame.

When the window is resized only the portions that are "uncovered" by the resize are redrawn by default, the rest of the window is clipped. If you give the window the wx.FULL_REPAINT_ON_RESIZE style then the whole window will be refreshed when the resize happens. Be careful about flicker in this case though. Double buffering will help get rid of that.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!