There comes a time in every man's life where a single goocanvas.Canvas widget just won't cut it. Imagine you need two separate canvases for your interface, but you want them to scroll together with a single scroll bar. How would you solve this problem?

First, to enable a goocanvas.Canvas object to scroll is very easy (or so it would seem). Simply drop it into a gtk.ScrolledWindow widget, and you're done. As long as the boundary of your canvas exceeds the size, the scroll bars will work.

The Problem...

However, don't get too excited. A scrolledWindow widget that has a goocanvas.Canvas object as a child will not bubble up any scroll signals / events. So, if you have another canvas on the window, you will have no luck trying to synchronize up the scrollbars. Or if you want only part of the canvas to scroll, and part to remain fixed, this will not work.

The Solution...Place two canvas objects next to each other. Place a vertical and horizontal scroll bar where you want them to appear. Create a signal handler for the scroll events, and use the Canvas.scroll_to(x, y) method to manually scroll both canvases.

Example Code:Here are the signal handler functions for the 2 scroll bars to synchronize the scrolling of 2 goocanvas.Canvas objects:

A picture is worth a thousand words:Here are 2 similar screens using a goocanvas.Canvas object. Notice the horizontal scroll bar placement on them (at the bottom of the screen). The 2nd screen has an offset scroll bar, which will only scroll that half of the Canvas. Pretty cool!

Screen 1 - Using a single goocanvas.Canvas and a gtk.ScrolledWindow widget:

Popular entries

Siste Inlegg

I am proud to announce the immediate release of OpenShot 2.4.4, the absolute best version yet! This is going to be a long post, but here is a quick summary for those who are short on time. This releas...

I am very proud to announce the release of OpenShot 2.4.3, our latest and greatest version! A huge thanks to the community for contributing bug reports, enhancements, translations, and fixes!
Download...

Happy summer! Version 2.4.2, the latest and greatest OpenShot Video Editor is now available (after a long wait), and we have lots of great improvements to share! We have exciting new effects, tons of ...