← Back to team overview

zim-wiki team mailing list archive

Bug caused by difference between and and Ampersand

 

Hello,
 
I stumble upon wierd behaviour while I was editing somethig else the IDE changed all ampersands (&) to 'and's
 
and some things broke - not sure if all
 
the one problem I noticed was in zim\gui\pageview.py
 
in line 3428 in the 0.60 version from http://www.zim-wiki.org/downloads/zim-0.60.tar.gz
 
(the atachement is just copy of text to ensure correct transfer by e-mail)
t
 
 
elif (event.keyval in KEYVALS_LEFT_TAB
            and not (event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK)
        )  -----
 
elif (event.keyval in KEYVALS_LEFT_TAB
            and not (event.state and KEYSTATES and ~gtk.gdk.SHIFT_MASK)
        ) 
 
 
the code handles the shift tab combo
 
tab shifts content right
shift tab back but only in ampersand version
 
 
and all of them are always True
event.state
KEYSTATES
~gtk.gdk.SHIFT_MASK
 
 
I don't see meaning of this part, can somebody explain why this is here anyway?
event.state and KEYSTATES and ~gtk.gdk.SHIFT_MASK
 
 
__________________________________________________________________________________________
I am using "windows 8 64-bit", running from sources with python version 2.7.3
 
 
 
INFO: This is zim 0.60
DEBUG: Python version is sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0)
DEBUG: Platform is nt
DEBUG: Zim revision is:
  branch: pyzim-trunk
  revision: 672 jaap.karssenberg@xxxxxxxxx-20130430172720-n6jaw95wiyevdqln
  date: 2013-04-30 19:27:20 +0200
 
__________________________________________________________________________________________
debug info from modified function to print debug info
 
recorded view is for tab, shift + tab (with cursor placed before text)
 
 
    def do_key_press_event(self, event):
        # This method defines extra key bindings. It also triggers
        # end-of-word and end-of-line signals.
        #
        # Note that on maemo only TAB triggers this method, other keys
        # avoid it somehow
        #
        # Calls in read-only mode or selection mode are dispatched to two
        # methods below.

        handled = False
        buffer = self.get_buffer()
        print 'KEY %s (%i)' % (gtk.gdk.keyval_name(event.keyval), event.keyval)
        print 'STATE %s' % event.state

        print "event.state", event.state
        print "KEYSTATES", KEYSTATES
        print "~gtk.gdk.SHIFT_MASK", ~gtk.gdk.SHIFT_MASK
                #print "(event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK)", (event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK)
        print "(event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK)", (event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK)
                print "NOT event.state", not event.state
        print "NOT KEYSTATES", not KEYSTATES
        print "NOT ~gtk.gdk.SHIFT_MASK", not ~gtk.gdk.SHIFT_MASK
                print "NOT (event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK)",not (event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK)                 print "NOT with ANDs... KEYSTATES and ~gtk.gdk.SHIFT_MASK)",not (event.state and KEYSTATES and ~gtk.gdk.SHIFT_MASK)                 print'\n\n'
        if not self.get_editable():
 
 
KEY Tab (65289)
STATE <flags 0 of type GdkModifierType>
event.state <flags 0 of type GdkModifierType>
KEYSTATES <flags GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK of type GdkModifierType>
~gtk.gdk.SHIFT_MASK -2
(event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK) 0
NOT event.state True
NOT KEYSTATES False
NOT ~gtk.gdk.SHIFT_MASK False
NOT (event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK) True
NOT with ANDs... KEYSTATES and ~gtk.gdk.SHIFT_MASK) True



KEY Shift_L (65505)
STATE <flags GDK_SHIFT_MASK of type GdkModifierType>
event.state <flags GDK_SHIFT_MASK of type GdkModifierType>
KEYSTATES <flags GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK of type GdkModifierType>
~gtk.gdk.SHIFT_MASK -2
(event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK) 0
NOT event.state False
NOT KEYSTATES False
NOT ~gtk.gdk.SHIFT_MASK False
NOT (event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK) True
NOT with ANDs... KEYSTATES and ~gtk.gdk.SHIFT_MASK) False



KEY ISO_Left_Tab (65056)
STATE <flags GDK_SHIFT_MASK of type GdkModifierType>
event.state <flags GDK_SHIFT_MASK of type GdkModifierType>
KEYSTATES <flags GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK of type GdkModifierType>
~gtk.gdk.SHIFT_MASK -2
(event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK) 0
NOT event.state False
NOT KEYSTATES False
NOT ~gtk.gdk.SHIFT_MASK False
NOT (event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK) True
NOT with ANDs... KEYSTATES and ~gtk.gdk.SHIFT_MASK) False


Hello,

I stumble upon wierd behaviour while I was editing somethig else the IDE changed all ampersands (&) to 'and's

and some things broke - not sure if all

the one problem I noticed was in zim\gui\pageview.py

in line 3428 in the 0.60 version from http://www.zim-wiki.org/downloads/zim-0.60.tar.gz

elif (event.keyval in KEYVALS_LEFT_TAB
            and not (event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK)
        ) 

-----

elif (event.keyval in KEYVALS_LEFT_TAB
            and not (event.state and KEYSTATES and ~gtk.gdk.SHIFT_MASK)
        ) 

the code handles the shift tab combo

tab shifts content right

shift tab back but only in ampersand version

and all of them are always True

event.state

KEYSTATES

~gtk.gdk.SHIFT_MASK

I don't see meaning of this part, can somebody explain why this is here anyway?

event.state and KEYSTATES and ~gtk.gdk.SHIFT_MASK

__________________________________________________________________________________________

I am using "windows 8 64-bit", running from sources with python version 2.7.3

INFO: This is zim 0.60
DEBUG: Python version is sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0)
DEBUG: Platform is nt
DEBUG: Zim revision is:
  branch: pyzim-trunk
  revision: 672 jaap.karssenberg@xxxxxxxxx-20130430172720-n6jaw95wiyevdqln
  date: 2013-04-30 19:27:20 +0200

__________________________________________________________________________________________

debug info from modified function to print debug info

recorded view is for tab, shift + tab (with cursor placed before text)

    def do_key_press_event(self, event):
        # This method defines extra key bindings. It also triggers
        # end-of-word and end-of-line signals.
        #
        # Note that on maemo only TAB triggers this method, other keys
        # avoid it somehow
        #
        # Calls in read-only mode or selection mode are dispatched to two
        # methods below.

        handled = False
        buffer = self.get_buffer()
        print 'KEY %s (%i)' % (gtk.gdk.keyval_name(event.keyval), event.keyval)
        print 'STATE %s' % event.state

        print "event.state", event.state
        print "KEYSTATES", KEYSTATES
        print "~gtk.gdk.SHIFT_MASK", ~gtk.gdk.SHIFT_MASK
       
        #print "(event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK)", (event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK)
        print "(event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK)", (event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK)
       
        print "NOT event.state", not event.state
        print "NOT KEYSTATES", not KEYSTATES
        print "NOT ~gtk.gdk.SHIFT_MASK", not ~gtk.gdk.SHIFT_MASK
       
        print "NOT (event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK)",not (event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK)
       
        print "NOT with ANDs... KEYSTATES and ~gtk.gdk.SHIFT_MASK)",not (event.state and KEYSTATES and ~gtk.gdk.SHIFT_MASK)
       
        print'\n\n'
        if not self.get_editable():

KEY Tab (65289)
STATE <flags 0 of type GdkModifierType>
event.state <flags 0 of type GdkModifierType>
KEYSTATES <flags GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK of type GdkModifierType>
~gtk.gdk.SHIFT_MASK -2
(event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK) 0
NOT event.state True
NOT KEYSTATES False
NOT ~gtk.gdk.SHIFT_MASK False
NOT (event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK) True
NOT with ANDs... KEYSTATES and ~gtk.gdk.SHIFT_MASK) True



KEY Shift_L (65505)
STATE <flags GDK_SHIFT_MASK of type GdkModifierType>
event.state <flags GDK_SHIFT_MASK of type GdkModifierType>
KEYSTATES <flags GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK of type GdkModifierType>
~gtk.gdk.SHIFT_MASK -2
(event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK) 0
NOT event.state False
NOT KEYSTATES False
NOT ~gtk.gdk.SHIFT_MASK False
NOT (event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK) True
NOT with ANDs... KEYSTATES and ~gtk.gdk.SHIFT_MASK) False



KEY ISO_Left_Tab (65056)
STATE <flags GDK_SHIFT_MASK of type GdkModifierType>
event.state <flags GDK_SHIFT_MASK of type GdkModifierType>
KEYSTATES <flags GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK of type GdkModifierType>
~gtk.gdk.SHIFT_MASK -2
(event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK) 0
NOT event.state False
NOT KEYSTATES False
NOT ~gtk.gdk.SHIFT_MASK False
NOT (event.state & KEYSTATES & ~gtk.gdk.SHIFT_MASK) True
NOT with ANDs... KEYSTATES and ~gtk.gdk.SHIFT_MASK) False

Follow ups