The examples are very usefull for learning pygtkglext, but I noticed they contain a small error in the code that checks wether a mouse button is pressed or not. Instead of if event.state == gtk.gdk.BUTTON1_MASK: one should use if event.state & gtk.gdk.BUTTON1_MASK: The affected examples van easily be found: tovrstra@myhost examples $ grep event.state * button.py: if event.state == gtk.gdk.VISIBILITY_FULLY_OBSCURED: coolwave.py: if event.state == gtk.gdk.BUTTON1_MASK: coolwave.py: elif event.state == gtk.gdk.BUTTON2_MASK: scribble.py: if event.state & gtk.gdk.BUTTON1_MASK: Shapes.py: if event.state == gtk.gdk.BUTTON1_MASK: Shapes.py: elif event.state == gtk.gdk.BUTTON2_MASK: teapot2.py: if event.state == gtk.gdk.BUTTON1_MASK: for some reason event.state & gtk.gdk.MOD2_MASK was also nonzero while I tried the examples. It first looked like the examples didn't work. Reproducible: Always Steps to Reproduce: 1. run for example teapots2.py 2. try to rotate the teapot by dragging on it. Actual Results: The teapot did not respond to the mouse. The two sliders in the window on the contrary do work. Expected Results: Make the teapot rotate while dragging it. Portage 2.0.49-r20 (default-x86-1.4, gcc-3.2.3, glibc-2.3.2-r3, 2.4.22-gentoo-r4) ================================================================= System uname: 2.4.22-gentoo-r4 i686 Pentium III (Coppermine) Gentoo Base System version 1.4.3.10 ACCEPT_KEYWORDS="x86" AUTOCLEAN="yes" CFLAGS="-O3 -march=pentium3 -fprefetch-loop-arrays -funroll-loops -pipe" CHOST="i686-pc-linux-gnu" COMPILER="gcc3" CONFIG_PROTECT="/etc /usr/X11R6/lib/X11/xkb /usr/kde/2/share/config /usr/kde/3/share/config /usr/share/config /usr/share/texmf/tex/generic/config/ /usr/share/texmf/tex/platex/config/ /var/qmail/control" CONFIG_PROTECT_MASK="/etc/gconf /etc/env.d" CXXFLAGS="-O3 -march=pentium3 -fprefetch-loop-arrays -funroll-loops -pipe" DISTDIR="/usr/portage/distfiles" FEATURES="autoaddcvs ccache sandbox" GENTOO_MIRRORS="http://ftp.belnet.be/mirrors/rsync.gentoo.org/gentoo/ http://gentoo.oregonstate.edu http://www.ibiblio.org/pub/Linux/distributions/gentoo" MAKEOPTS="-j2" PKGDIR="/usr/portage/packages" PORTAGE_TMPDIR="/var/tmp" PORTDIR="/usr/portage" PORTDIR_OVERLAY="/usr/local/portage" SYNC="rsync://rsync.gentoo.org/gentoo-portage" USE="X arts atlas avi berkdb bonobo cdr crypt cups curl dga directfb dnd doc dvd dvdr encode esd ethereal fbcon fltk foomaticdb fs gd gd-external gdbm gif ginac gnome gnomedb gpm gtk gtk2 gtkhtml icc ifc imap imlib java jpeg ldap libg++ libgda libwww mad mbox md5sum mikmod mmx motif mozilla mozsvg mpeg mpi mysql ncurses nls nvidia oav opengl pam parse-clocks pdflib perl png prelude python qhull readline sdl slang spell sse ssl svga tcltk tcpd tetex tiff truetype usb x86 xml2 xmms xv zlib"
would be able to make a patch for us with the changes?
I'm new in this, but I have to start somewhere ofcourse. You can expect a patch soon.
As I mentioned above, This is the first time I try to make patch. Here is what I did. I unpacked the source of pygtkglext in /usr/src/pygtkglext-1.0.0. There I made a copy of the /usr/src/pygtkglext-1.0.0/examples dir to examples.old. In the examples dir I made the changes and from /usr/src/pygtkglext-1.0.0/ I executed: diff -u examples.old examples > pygtkglext-1.0.0-gentoo.diff I made a new ebuild in my portage overlaydir (pygtkglext-1.0.0-r1.ebuild) and the diff file is put in the files directory. I added the following to pygtkglext-1.0.0.ebuild: *** begin pygtkglext-1.0.0.ebuild snipet *** src_unpack() { unpack ${A} cd ${S} epatch ${FILESDIR}/${P}-gentoo.diff } *** end pygtkglext-1.0.0.ebuild snipet *** when I do an emerge pygtkglext, everything goes fine and the patched examples can be found in /usr/share/doc/pygtkglext-1.0.0. (Hooray!) One thing was troubling me. Take a look at the first part of the pygtkglext-1.0.0-gentoo.diff file: *** begin pygtkglext-1.0.0-gentoo.diff snipet *** diff -u examples.old/coolwave.py examples/coolwave.py --- examples.old/coolwave.py 2004-01-18 11:35:37.000000000 +0100 +++ examples/coolwave.py 2004-01-18 11:54:32.000000000 +0100 @@ -246,10 +246,10 @@ pass def button_motion (self, width, height, event): - if event.state == gtk.gdk.BUTTON1_MASK: + if event.state & gtk.gdk.BUTTON1_MASK: self.__sphi += (event.x - self.__beginX)/4.0 self.__stheta += (self.__beginY - event.y)/4.0 - elif event.state == gtk.gdk.BUTTON2_MASK: + elif event.state & gtk.gdk.BUTTON2_MASK: self.__sdepth += (self.__beginY - event.y)/10.0 self.__beginX = event.x self.__beginY = event.y *** end pygtkglext-1.0.0-gentoo.diff snipet *** The second line still refers to the examples.old directory which in not present in a clean source. Does this matter? Should I do something about it? If yes, how?
Created attachment 24018 [details, diff] pygtkglext-1.0.0-gentoo.diff
i tried the original examples using event.state == ... and it seems to work fine, can others test to see if it works for them? example: mcvaio /usr/share/doc/pygtkglext-1.0.1/examples % fgrep event.state teapot2.py if event.state == gtk.gdk.BUTTON1_MASK: mcvaio /usr/share/doc/pygtkglext-1.0.1/examples % python teapot2.py
I suppose that your observation is perfectly normal. For some reason 'event.state & gtk.gdk.MOD2_MASK' is also non-zero when I run the examples on my machine. My point is that this is something a programmer should be aware of when writing software. If one wants to test wether a button is down, he should write 'event.state & gtk.gdk.BUTTON1_MASK'. This is because 'event.state == gtk.gdk.BUTTON1_MASK' means '(event.state & gtk.gdk.BUTTON1_MASK) and (event.state & (not gtk.gdk.BUTTON1_MASK) == 0)' This is also the reason why these kind of constants are called masks. They are meant to mask the part of the state one is not interested in. In this case we don't want to know wether the user presses ctrl, shift or some other modifier while button1 is pressed. I must admit I really don't know why that modifier2 is set in the state when I run these examples. I'd also like to mention that we are discussing a really futile detail here. I considder this bug as a way of learning how the bugzilla monster works and how to submit patches etc. On the other hand there is ofcourse the educational aspect. These examples are a good starting point for people who like to learn working with pygtkglext. From this point nice example codes that always works is a real must.
indeed. sorry this has taken so long. i consulted with the author of pygtkglext and he agrees with your findings and the changes will be incorporated into the next release of pygtkglext. meanwhile, this will be incorporated into pygtkglext-1.0.1.ebuild in gentoo until the next release from the authors. thank you for your bug report.