From: Alex Hall on
Hi all, but mainly Tim Golden:
Tim, I am using your wonderful message loop for keyboard input, the
one on your site that you pointed me to a few months ago. It has been
working perfectly as long as I had only one dictionary of keys mapping
to one dictionary of functions, but now I want two of each. My program
has different modes, which may have varying keystrokes, and I also
have some global keystrokes which are the same across all modes, like
exiting or switching modes. I cannot figure out how to make the
message loop look in two dictionaries at onc. I tried using an if,
saying that if action_to_take was not set in the mode-specific
dictionary then look at the global dictionary, but it is like it is
never looking in the global dictionary at all. I get no syntax errors
or problems when running the program, so it has to be something in my
logic. Go to
http://www.gateway2somewhere.com/sw/main.pyw
to see what I mean; the problem code is near the very bottom of the
file. Thanks for any suggestions. Oh, please note that I indent one
space per indentation level.

--
Have a great day,
Alex (msg sent from GMail website)
mehgcap(a)gmail.com; http://www.facebook.com/mehgcap
From: Tim Golden on
On 23/03/2010 17:01, Alex Hall wrote:
> Hi all, but mainly Tim Golden:
> Tim, I am using your wonderful message loop for keyboard input, the
> one on your site that you pointed me to a few months ago. It has been
> working perfectly as long as I had only one dictionary of keys mapping
> to one dictionary of functions, but now I want two of each. My program
> has different modes, which may have varying keystrokes, and I also
> have some global keystrokes which are the same across all modes, like
> exiting or switching modes. I cannot figure out how to make the
> message loop look in two dictionaries at onc. I tried using an if,
> saying that if action_to_take was not set in the mode-specific
> dictionary then look at the global dictionary, but it is like it is
> never looking in the global dictionary at all. I get no syntax errors
> or problems when running the program, so it has to be something in my
> logic. Go to
> http://www.gateway2somewhere.com/sw/main.pyw


Happy to look, Alex, but that link's giving me a 404 at the moment

TJG
From: Alex Hall on
Sorry about that, it is fixed now.

On 3/23/10, Tim Golden <mail(a)timgolden.me.uk> wrote:
> On 23/03/2010 17:01, Alex Hall wrote:
>> Hi all, but mainly Tim Golden:
>> Tim, I am using your wonderful message loop for keyboard input, the
>> one on your site that you pointed me to a few months ago. It has been
>> working perfectly as long as I had only one dictionary of keys mapping
>> to one dictionary of functions, but now I want two of each. My program
>> has different modes, which may have varying keystrokes, and I also
>> have some global keystrokes which are the same across all modes, like
>> exiting or switching modes. I cannot figure out how to make the
>> message loop look in two dictionaries at onc. I tried using an if,
>> saying that if action_to_take was not set in the mode-specific
>> dictionary then look at the global dictionary, but it is like it is
>> never looking in the global dictionary at all. I get no syntax errors
>> or problems when running the program, so it has to be something in my
>> logic. Go to
>> http://www.gateway2somewhere.com/sw/main.pyw
>
>
> Happy to look, Alex, but that link's giving me a 404 at the moment
>
> TJG
> --
> http://mail.python.org/mailman/listinfo/python-list
>


--
Have a great day,
Alex (msg sent from GMail website)
mehgcap(a)gmail.com; http://www.facebook.com/mehgcap
From: MRAB on
Alex Hall wrote:
> Hi all, but mainly Tim Golden:
> Tim, I am using your wonderful message loop for keyboard input, the
> one on your site that you pointed me to a few months ago. It has been
> working perfectly as long as I had only one dictionary of keys mapping
> to one dictionary of functions, but now I want two of each. My program
> has different modes, which may have varying keystrokes, and I also
> have some global keystrokes which are the same across all modes, like
> exiting or switching modes. I cannot figure out how to make the
> message loop look in two dictionaries at onc. I tried using an if,
> saying that if action_to_take was not set in the mode-specific
> dictionary then look at the global dictionary, but it is like it is
> never looking in the global dictionary at all. I get no syntax errors
> or problems when running the program, so it has to be something in my
> logic. Go to
> http://www.gateway2somewhere.com/sw/main.pyw
> to see what I mean; the problem code is near the very bottom of the
> file. Thanks for any suggestions. Oh, please note that I indent one
> space per indentation level.
>
"msg.wParam" gives an int, but the keys of globalFuncs are 'g1', etc,
not ints.

Incidentally, you might want to change:

if(not action_to_take):

to:

if action_to_take is None:

in case any of the values happen to be 0 (if not now, then possibly at
some time in the future).
From: Alex Hall on
On 3/23/10, MRAB <python(a)mrabarnett.plus.com> wrote:
> Alex Hall wrote:
>> Hi all, but mainly Tim Golden:
>> Tim, I am using your wonderful message loop for keyboard input, the
>> one on your site that you pointed me to a few months ago. It has been
>> working perfectly as long as I had only one dictionary of keys mapping
>> to one dictionary of functions, but now I want two of each. My program
>> has different modes, which may have varying keystrokes, and I also
>> have some global keystrokes which are the same across all modes, like
>> exiting or switching modes. I cannot figure out how to make the
>> message loop look in two dictionaries at onc. I tried using an if,
>> saying that if action_to_take was not set in the mode-specific
>> dictionary then look at the global dictionary, but it is like it is
>> never looking in the global dictionary at all. I get no syntax errors
>> or problems when running the program, so it has to be something in my
>> logic. Go to
>> http://www.gateway2somewhere.com/sw/main.pyw
>> to see what I mean; the problem code is near the very bottom of the
>> file. Thanks for any suggestions. Oh, please note that I indent one
>> space per indentation level.
>>
> "msg.wParam" gives an int, but the keys of globalFuncs are 'g1', etc,
> not ints.
That did it. I originally used 1-4 like I did for the mode
dictionaries, not realizing that the ints were so important; I figured
they were just keys in the dictionary and that they could be anything,
it was just easier to use ints. Now, I have changed my globals to
20-23 and everything seems to be going well. Thanks!!
> Incidentally, you might want to change:
>
> if(not action_to_take):
>
> to:
>
> if action_to_take is None:
>
> in case any of the values happen to be 0 (if not now, then possibly at
> some time in the future).
Sorry, could you explain why you suggested this? I do not follow.
Because of the if statement "if action_to_take:", I figured it was
saying "if action_to_take was successfully set" or something else
having a boolean value. Guess not?
> --
> http://mail.python.org/mailman/listinfo/python-list
>


--
Have a great day,
Alex (msg sent from GMail website)
mehgcap(a)gmail.com; http://www.facebook.com/mehgcap
 |  Next  |  Last
Pages: 1 2
Prev: Python is cool!!
Next: Unicode blues in Python3