Python: TEXTOUT_P, CHOOSE, INPUT here is how it works 22.jan addded a TextOut functio
|
12-20-2021, 10:17 PM
(This post was last modified: 01-24-2022 10:51 PM by Guenter Schink.)
Post: #1
|
|||
|
|||
Python: TEXTOUT_P, CHOOSE, INPUT here is how it works 22.jan addded a TextOut functio
edit 22.jan added a TxtOut function for easy interfacing with HOME post#4 /edit
edit 17.jan2022 Unfortunately it turned out that the STRING handling is a little bit more complicated than described in this post. I'll do a correction in post #3 /edit Python on the Prime is quite impressive by its speed. It's a pity it has a lot of bugs. Let's hope they will be addressed in future releases. While Python is really fast, it lacks some convenient functions like CHOOSE or (configurable) INPUT. But why not simply use what is available in HOME? The key is the function eval() of the module hpprime. Once the principle is understood we have almost full access to what the HOME environment provides. eval() simply passes a string to the interpreter in the HOME environment. Therefore we have to ensure to pass on a syntactically correct statement. All examples have < from hppdir import * > as a prerequisite. A simple example is the "WAIT" function of HOME. eval("WAIT") will wait until a key is pressed. But consider you wish to wait for an arbitrary duration you've stored in var "a". Code: 10 a=5 Why use TEXTOUT_P? The built-in function "textout" is rather limited as you neither can choose size nor background color. TEXTOUT_P provides you with all of that Code: eval('TEXTOUT_P("Günter",G0,50,120,1,#FF0000h,100,RGB(192,192,192))') So far these examples work in one direction. But for others we need something back from the HOME environment. CHOOSE Wouldn't it be nice to have that comfort in the Python environment too? This is how it works, e.g. Code: 1 eval(‘CHOOSE(N,"Our next HHC"," Nashville","Reno","San José" ') Again use of variables is available by string concatenation. INPUT Have a look at the syntax, and have fun making your own experiments. Variables management: Maybe you don't want to interfere with the common variables of the HOME environment. Then the AVars function comes in handy. Guess you wish to synchronize your variables in both environments you could do: Code: MyVar=eval('AVars(“MyVar”)') #to store what's in HOME into the Python variable. Some examples: edit: ref string handling refer to post #3 /edit Code: MyText=”some ranting” ; eval('AVars("MyText"):=’ + str(MyText)) This way these variables are created in both environments with identical contents. Well, the delimiters of lists in Python [] are different from those in HOME {}. But it doesn't affect the function (I think). There is one caveat with lists at least. HOME list seem to only accept max 2 dimensional lists. But anyway there are better ways in Python to store values (I/O). These methods presented have their value for the exchanges described. Comments, questions welcome Günter |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Python: TEXTOUT_P, CHOOSE, INPUT here is how it works 22.jan addded a TextOut functio - Guenter Schink - 12-20-2021 10:17 PM
RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works - tcab - 12-29-2021, 07:51 AM
RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works - Guenter Schink - 01-17-2022, 08:59 PM
RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works Correction 17.Jan 2022 - Guenter Schink - 01-23-2022, 11:16 PM
RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works Correction 17.Jan 2022 - jfelten - 01-24-2022, 06:34 PM
RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works Correction 17.Jan 2022 - Guenter Schink - 01-24-2022, 10:44 PM
RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works 22.jan addded a TextOut functio - jfelten - 01-25-2022, 02:46 AM
RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works 22.jan addded a TextOut functio - Guenter Schink - 01-25-2022, 09:44 PM
|
User(s) browsing this thread: 1 Guest(s)