[pygtk] Writting a widget with native scrolling support

6 views
Skip to first unread message

Laszlo Nagy

unread,
Oct 20, 2008, 3:20:19 PM10/20/08
to py...@daa.com.au
I want to write an owner-drawn widget (using Cairo) with native
scrolling capabilities. Let's say this widget has a get_hadjustment()
and a get_vadjustment() method. Scrolling inside the widget is already
implemented. E.g. the widget draws different things on its surface,
depending on the values of its adjustments.

I would like to add this widget to a ScrolledWindow. Here is what I do:

# Create an owner drawn widget with native scrolling capabilites.
w = MyTable()

# Create a ScrolledWindow
# This will share the adjustments between the scrollbars
# and the w widget.
sw = gtk.ScrolledWindow(
hadjustment=w.get_hadjusment(),
vadjustment=w.get_vadjusment()
)
# Add scrollable child widget to scrolled window.
sw.add(w)


When starting my program, I get this message:

main.py:44: GtkWarning: gtk_scrolled_window_add(): cannot add non
scrollable widget use gtk_scrolled_window_add_with_viewport() instead
sw.add(w)

I wonder why it thinks that this is a non-scrollable widget? Should I
define some special slots for gtk to think this widget is scrollable?
I'm sorry but I could not find documentation about this. Of course you
do not need to explain everything, just please point me to the right
place in the pygtk docs, or just give some hints how to do it.

Thank you,

Laszlo

_______________________________________________
pygtk mailing list py...@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Gustavo J. A. M. Carneiro

unread,
Oct 21, 2008, 11:07:08 AM10/21/08
to Laszlo Nagy, py...@daa.com.au
http://www.daa.com.au/pipermail/pygtk/2006-January/011668.html

--
Gustavo J. A. M. Carneiro
<g...@inescporto.pt> <gus...@users.sourceforge.net>
"The universe is always one step beyond logic" -- Frank Herbert

Laszlo Nagy

unread,
Oct 23, 2008, 9:42:52 AM10/23/08
to Gustavo J. A. M. Carneiro, py...@daa.com.au
Gustavo J. A. M. Carneiro wrote:
> http://www.daa.com.au/pipermail/pygtk/2006-January/011668.html
>
Yes, this was the only related post that I could find on the internet.
But I could not use it for anything because it does not tell how to do
it. It says:

"For custom widgets, check the method gtk.Widget.set_set_scroll_adjustments_signal(signal_name)"


But this method only has a signal_name parameter. I do not see how I
could use it for specifying my adjustments and making my widget support
scrolling natively?

(Also that was written in 2006, probably it is outdated.)

Thanks,

Gustavo J. A. M. Carneiro

unread,
Oct 23, 2008, 11:55:25 AM10/23/08
to Laszlo Nagy, py...@daa.com.au
On Thu, 2008-10-23 at 15:42 +0200, Laszlo Nagy wrote:
> Gustavo J. A. M. Carneiro wrote:
> > http://www.daa.com.au/pipermail/pygtk/2006-January/011668.html
> >
> Yes, this was the only related post that I could find on the internet.
> But I could not use it for anything because it does not tell how to do
> it. It says:
>
> "For custom widgets, check the method gtk.Widget.set_set_scroll_adjustments_signal(signal_name)"
>
>
> But this method only has a signal_name parameter. I do not see how I
> could use it for specifying my adjustments and making my widget support
> scrolling natively?
>
> (Also that was written in 2006, probably it is outdated.)

It is not outdated. See
http://library.gnome.org/devel/gtk/2.14/GtkWidget.html

GtkWidgetClass
typedef struct {
/* The object class structure needs to be the first
* element in the widget class structure in order for
* the class mechanism to work correctly. This allows a
* GtkWidgetClass pointer to be cast to a GtkObjectClass
* pointer.
*/
GtkObjectClass parent_class;


guint activate_signal;

guint set_scroll_adjustments_signal;
} GtkWidgetClass;

activate_signal The signal to emit when a widget of this class
is activated, gtk_widget_activate() handles the emission.
Implementation of this signal is optional.

set_scroll_adjustment_signal This signal is emitted when a
widget of this class is added to a scrolling aware parent,
gtk_widget_set_scroll_adjustments() handles the emission.
Implementation of this signal is optional.


gtk.Widget.set_set_scroll_adjustments_signal is PyGtk's equivalent to
Gtk+/C setting the field set_scroll_adjustments_signal of the
GtkWidgetClass of your widget. Basically you have to define a signal
"my-signal" in your widget that accepts two gtk.Adjustment objects as
parameters, then do
MyClass.set_set_scroll_adjustments_signal("my-signal"). Of course you
still need to implement the scrolling by monitoring the adjustments and
updating the widget's view accordingly, but after that you can add your
widget to a scrolled window.


>
> Thanks,
>
> Laszlo
>
>
--

Gustavo J. A. M. Carneiro

<g...@inescporto.pt> <gus...@users.sourceforge.net>
"The universe is always one step beyond logic" -- Frank Herbert

_______________________________________________

Reply all
Reply to author
Forward
0 new messages