Post Reply 
Python: some practice, questions and #%§'
05-15-2021, 11:05 PM (This post was last modified: 05-16-2021 10:19 AM by Guenter Schink.)
Post: #3
RE: Python: some practice, questions and #%§'
(05-15-2021 01:04 AM)jkor Wrote:  I seem to have some success with the following snippet in PPL:

Code:

...

The snippet prints the y-coord of the mouse pointer for a two-point touch, or the key code for a clicked calculator key and can be exited by pressing 'On'. Both mouse() and keyboard() don't seem to accept any parameters.

As noted in one of your previous posts, I haven't had any luck making a Python script file work (using the More>Files>New Program feature of the Editor).

Thanks for your invaluable contributions to the knowledge base. Your posted have been very helpful in trying to figure things out.

Jim
Thanks for your comment, and the code snipped, that helped a lot. Now I have a routine for mouse, at least on the virtual Prime, that seems to work reliably and easy to use. Checking out on the real Prime will follow. For now I call it a day, although I should call it a night at 1 hour past midnight here.


Code:
from hpprime import *
# So far only tested on the Virtual.
# Left mouse button returns first tuple
# Right mouse button returns second tuple

# initiate Maus as 1 tuple of 2 tuples
# and wait for a mouse event
# Maus is the German word for mouse :-)
Maus=((),())
while Maus==((),()):
  Maus=mouse()

# clear terminal Window as it fits, guess that's what you were looking for
eval("PRINT")

#split Maus into two tuples Maus1 and Maus2
# in Python it's easy this way
(Maus1),(Maus2)=Maus

#let's see what we got
print("Maus1:",Maus1,"Maus2:",Maus2)

#before doing something with first tuple, 
#check  it's not empty
if Maus1>():
 (Maus1x,Maus1y)=Maus1
 print("Maus1x:",Maus1x,"Maus1y:",Maus1y)

#before doing something with second tuple, 
#check  it's not empty
if Maus2>():
  (Maus2x,Maus2y)=Maus2
  print("Maus2x:",Maus2x,"Maus2y:",Maus2y)
   
#end

EXPORT test7(a)
BEGIN
  PYTHON(name1, a);
END;

We'll continue to play with Python, no?
Günter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Python: some practice, questions and #%§' - Guenter Schink - 05-15-2021 11:05 PM



User(s) browsing this thread: 1 Guest(s)