Hi
I am sorry about this I have googled bitwise python a bit and tried a couple of things that I’m not happy with.
So I thought I’d just ask anyway.
I am trying to test the modifier key state against those in the user prefs (key_map_item)
so that when the appropriate mod key combo matches that of the the pref then that
function is called.
Any input would be gratefully accepted.
hopefully the code is self documented enough.
match = False
any= key_map_item.oskey and key_map_item.ctrl and key_map_item.shift and key_map_item.alt
#match the mod keys
oskey = key_map_item.oskey and event.oskey # "OSkey"
ctrl = key_map_item.ctrl and event.ctrl # "Ctrl"
shift = key_map_item.shift and event.shift #"Shift"
alt = key_map_item.alt and event.alt # "Alt"
if any and ( oskey or ctrl or shift or alt): match = True
and after that test for each sub-condition explicitly in an if-else construct.
It is often better (more pythonic) to write out each condition explicitly.
As for bitwise comparison, that shouln’t be necessary here, testing only for boolean truth values of python objects. Do I detect a background in C programming here?
it would take a bucket of if to equal a mask
like say
prefs_combo = 1100
key_combo = 1100
=True
or
prefs_combo = 0100
key_combo = 0100
= True
or
prefs_combo = 0101
key_combo = 0100
= False
and all the permutations can be handled in one test using a bit mask
I dont know the pythonese for the bit shiftting
good tip on the keyword. I am usually a lot more verbose
I tend to make long winded variables like
the_variable_that_counts_the_number_of_times_we_go_through_this_stupid_loop
and
test_to_see_if_the_water_is_fine
not really that bad but I do try and make it easy so when I go back a couple of years later I can get a bit of an idea whats going on
I hate writing documentation and I never read it unless ALL else fails anyway I developed this habit
yep C Perl PHP Java Javascript yada yada yada
Ive forgotten more than I know
small programer small town == big flexibilty