Search code examples
pythongtk3mousewheel

What are the gtk 3 python constants for the scroll events


I've been searching for the constants for python gtk 3 using PYGObjects. Specifically what are the enum constants for the scroll events. 'gi.repository.Gdk' object has no attribute 'SCROLL_UP'. The events are listed here and is not working from the pygi-convert.sh I have included sample code that pinpoints the issue. Thanks.

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk

def on_destroy (widget):
    Gtk.main_quit()
    return False

def scroll_notify_event(w, e):
    print e.direction
    if e.direction == Gdk.ScrollDirection.UP:
       print "You scrolled up"
    elif e.direction == Gdk.ScrollDirection.DOWN:
       print "You scrolled down"

def event(eventbox, event):
    print("Event: %s" % event)

def create ():
    window = Gtk.Window()
    window.connect("destroy", on_destroy)
    window.add_events( Gdk.EventMask.SCROLL_MASK )

    eventbox = Gtk.EventBox()
    eventbox.connect("event", event)
    window.connect('scroll-event', scroll_notify_event)
    window.add(eventbox)

    window.show_all()


if __name__ == '__main__':
    create()
    Gtk.main()

Solution

  • You're looking for Gdk.ScrollDirection.UP.

    The docs you linked are pygtk docs. pygtk is not gtk3. The relevant docs can be found here.