Arios Jentu
Arios Jentu

Reputation: 45

WXPython Scrollable paint panel

Today I have one problem with making scrollable paint panel. I want to make vertical and horizontal boxsizers using this code:

#Панель рисования
DrawScroller = ScrolledWindow(PaintFrame, ID_ANY)
DrawScroller.SetScrollRate(5, 5)
DrawScroller.EnableScrolling(True, True)

DrawScroller.SetSize(Size(685, 600-51))
DrawScroller.Move(Point(115, 0))
DrawScroller.SetBackgroundColour(Colour(255, 255, 255))

ScrollBarV = BoxSizer(VERTICAL)
ScrollBarH = BoxSizer(HORIZONTAL)

DrawPanel = Panel(DrawScroller, ID_ANY)
DrawPanel.SetSize(Size(685*2, (600-51)*2))
DrawPanel.Move(Point(0, 0))
DrawPanel.SetBackgroundColour(Colour(255, 255, 255))

Paint = PaintZone(DrawPanel)
Paint.Clear()

x, y = DrawPanel.GetSize()
ScrollBarH.Add(DrawPanel, x, y)
ScrollBarV.Add(ScrollBarH)
DrawScroller.SetSizer(ScrollBarV)

Here PaintZone is same as PaintDC, but with some variables like figures and tools. When I run this code, and trying to draw, program will crush with this: "paint.sh: line 1: 20858 Segmentation fault (core dumped) python2 main.py"

When I comment block with creating scrollbars and setting sizer (3d and last in this code), code works great, and when draw, program doesn't crashs. I want scrollbars, because when drawing, DrawingPanel is changing size. How I can do this?

Upvotes: 1

Views: 91

Answers (1)

VZ.
VZ.

Reputation: 22688

Look at what you're doing: your DrawPanel is inside ScrollBarH, which is inside ScrollBarV, which is used as the sizer for, and hence is inside, DrawPanel. So you've managed to create a recursive hierarchy of windows and sizers -- no surprise it doesn't work.

Upvotes: 1

Related Questions