accelerator table returns?

Hi all,
I have an accelerator table that binds a lot of functions to as many
keystrokes. I now need to get the return value of any function called
by a keystroke in the table. For example, if every function bound in
the table returns true or false, I could loop until something returns
false:
ok=False
while not ok:
ok=#AcceleratorTable.CalledFunction #set to return value of whatever
func was #called by the most recent keystroke

Is such a thing possible?
The situation is that I have a battleship game. I have two players,
each a Player object. I will be switching from one to the other, and
so I need to wait until player1 calls a function that returns True; as
soon as that happens, I will switch over to player2 and wait until
player2 does something that returns True, then switch back to player1,
and so on. To do this, it seems like my best option is to have a
Player.takeTurn() function which just waits in a while loop, like the
example above, until the player does something. At that point, I will
switch to the other player and call the new player's takeTurn method,
then switch back the same way.
I hope this makes sense. I thought of looking through the wx source in
the site-packages folder but I could not find where the
AcceleratorTable is stored. TIA!

···

--
Have a great day,
Alex (msg sent from GMail website)
mehgcap@gmail.com; http://www.facebook.com/mehgcap

Well, one simple way to “return” something would be to use pubsub. But in your example, you could do it even easier by making the “ok” variable into an attribute:

self.ok = False
while not self.ok:
# do something

Then in the ok button’s event handler, you just set “self.ok” to True.

···

On Sun, Jun 6, 2010 at 3:43 PM, Alex Hall mehgcap@gmail.com wrote:

Hi all,

I have an accelerator table that binds a lot of functions to as many

keystrokes. I now need to get the return value of any function called

by a keystroke in the table. For example, if every function bound in

the table returns true or false, I could loop until something returns

false:

ok=False

while not ok:

ok=#AcceleratorTable.CalledFunction #set to return value of whatever

func was #called by the most recent keystroke

Is such a thing possible?

The situation is that I have a battleship game. I have two players,

each a Player object. I will be switching from one to the other, and

so I need to wait until player1 calls a function that returns True; as

soon as that happens, I will switch over to player2 and wait until

player2 does something that returns True, then switch back to player1,

and so on. To do this, it seems like my best option is to have a

Player.takeTurn() function which just waits in a while loop, like the

example above, until the player does something. At that point, I will

switch to the other player and call the new player’s takeTurn method,

then switch back the same way.

I hope this makes sense. I thought of looking through the wx source in

the site-packages folder but I could not find where the

AcceleratorTable is stored. TIA!

Mike Driscoll

Blog: http://blog.pythonlibrary.org

Hi all,
I have an accelerator table that binds a lot of functions to as many
keystrokes. I now need to get the return value of any function called
by a keystroke in the table. For example, if every function bound in
the table returns true or false, I could loop until something returns
false:
ok=False
while not ok:
ok=#AcceleratorTable.CalledFunction #set to return value of whatever
func was #called by the most recent keystroke

Is such a thing possible?
The situation is that I have a battleship game. I have two players,
each a Player object. I will be switching from one to the other, and
so I need to wait until player1 calls a function that returns True; as
soon as that happens, I will switch over to player2 and wait until
player2 does something that returns True, then switch back to player1,
and so on. To do this, it seems like my best option is to have a
Player.takeTurn() function which just waits in a while loop, like the
example above, until the player does something. At that point, I will
switch to the other player and call the new player's takeTurn method,
then switch back the same way.
I hope this makes sense. I thought of looking through the wx source in
the site-packages folder but I could not find where the
AcceleratorTable is stored. TIA!

--

Well, one simple way to "return" something would be to use pubsub. But in
your example, you could do it even easier by making the "ok" variable into
an attribute:

self.ok = False
while not self.ok:
    # do something

That should work; great idea!! Since everything is tied, in some way,
back to the Grid object, I can just set an attrib "turnOver" to false
until the player does something that ends their turn, then set it to
True. Meanwhile, the loop switching between the two players is
watching for this switch so that, when player1.grid.turnOver==True,
the active player is switched to player2... Anyway, thanks for the
suggestion; let us hope it is as easy to implement as I am thinking!

···

On 6/6/10, Mike Driscoll <mike@pythonlibrary.org> wrote:

On Sun, Jun 6, 2010 at 3:43 PM, Alex Hall <mehgcap@gmail.com> wrote:

--
-----------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

--
Have a great day,
Alex (msg sent from GMail website)
mehgcap@gmail.com; Redirecting...

Yes, except don't use an endless loop like that as it will block the main event loop and you won't be able to process any events. Instead you can use a timer or idle handler that watches for the flag to change and then does whatever is needed to switch the app to the other mode. If the flag doesn't change then the event handler just returns without doing anything and other events can be processed like normal.

Another approach to take that will have similar results to using the flag is to simply call some nextTurn() method whenever it is time to switch players. That method can then do whatever is needed at that point in time and you won't have to worry about watching/waiting for some flag to change state.

···

On 6/6/10 2:38 PM, Mike Driscoll wrote:

On Sun, Jun 6, 2010 at 3:43 PM, Alex Hall <mehgcap@gmail.com > <mailto:mehgcap@gmail.com>> wrote:

    Hi all,
    I have an accelerator table that binds a lot of functions to as many
    keystrokes. I now need to get the return value of any function called
    by a keystroke in the table. For example, if every function bound in
    the table returns true or false, I could loop until something returns
    false:
    ok=False
    while not ok:
      ok=#AcceleratorTable.CalledFunction #set to return value of whatever
    func was #called by the most recent keystroke

    Is such a thing possible?
    The situation is that I have a battleship game. I have two players,
    each a Player object. I will be switching from one to the other, and
    so I need to wait until player1 calls a function that returns True; as
    soon as that happens, I will switch over to player2 and wait until
    player2 does something that returns True, then switch back to player1,
    and so on. To do this, it seems like my best option is to have a
    Player.takeTurn() function which just waits in a while loop, like the
    example above, until the player does something. At that point, I will
    switch to the other player and call the new player's takeTurn method,
    then switch back the same way.
    I hope this makes sense. I thought of looking through the wx source in
    the site-packages folder but I could not find where the
    AcceleratorTable is stored. TIA!

    --

Well, one simple way to "return" something would be to use pubsub. But
in your example, you could do it even easier by making the "ok" variable
into an attribute:

self.ok = False
while not self.ok:
     # do something

Then in the ok button's event handler, you just set "self.ok" to True.

--
Robin Dunn
Software Craftsman

Thanks for the suggestions, everyone. Using wx.Yield() seems to have
done the trick, for now at least. If I run into a lot of problems then
I will try a separate thread and all that, but I am hoping that that
will not be necessary as I have not dealt with mixing a gui and
multiple threads... Of course it would be good knowledge to have, and
I will likely try it after I have a stable version up and running, but
for the moment Yield is handling things; I just call it wherever I am
idling and waiting for that flag to change.

···

On 6/7/10, Robin Dunn <robin@alldunn.com> wrote:

On 6/6/10 2:38 PM, Mike Driscoll wrote:

On Sun, Jun 6, 2010 at 3:43 PM, Alex Hall <mehgcap@gmail.com >> <mailto:mehgcap@gmail.com>> wrote:

    Hi all,
    I have an accelerator table that binds a lot of functions to as many
    keystrokes. I now need to get the return value of any function called
    by a keystroke in the table. For example, if every function bound in
    the table returns true or false, I could loop until something returns
    false:
    ok=False
    while not ok:
      ok=#AcceleratorTable.CalledFunction #set to return value of whatever
    func was #called by the most recent keystroke

    Is such a thing possible?
    The situation is that I have a battleship game. I have two players,
    each a Player object. I will be switching from one to the other, and
    so I need to wait until player1 calls a function that returns True; as
    soon as that happens, I will switch over to player2 and wait until
    player2 does something that returns True, then switch back to player1,
    and so on. To do this, it seems like my best option is to have a
    Player.takeTurn() function which just waits in a while loop, like the
    example above, until the player does something. At that point, I will
    switch to the other player and call the new player's takeTurn method,
    then switch back the same way.
    I hope this makes sense. I thought of looking through the wx source in
    the site-packages folder but I could not find where the
    AcceleratorTable is stored. TIA!

    --

Well, one simple way to "return" something would be to use pubsub. But
in your example, you could do it even easier by making the "ok" variable
into an attribute:

self.ok = False
while not self.ok:
     # do something

Then in the ok button's event handler, you just set "self.ok" to True.

Yes, except don't use an endless loop like that as it will block the
main event loop and you won't be able to process any events. Instead
you can use a timer or idle handler that watches for the flag to change
and then does whatever is needed to switch the app to the other mode.
If the flag doesn't change then the event handler just returns without
doing anything and other events can be processed like normal.

Another approach to take that will have similar results to using the
flag is to simply call some nextTurn() method whenever it is time to
switch players. That method can then do whatever is needed at that
point in time and you won't have to worry about watching/waiting for
some flag to change state.

--
Robin Dunn
Software Craftsman
http://wxPython.org

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

--
Have a great day,
Alex (msg sent from GMail website)
mehgcap@gmail.com; Redirecting...