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 |
|||
12-29-2021, 07:51 AM
Post: #2
|
|||
|
|||
RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works
Thank you Guenter for these continued, amazing discoveries about Python on the Prime!
|
|||
01-17-2022, 08:59 PM
Post: #3
|
|||
|
|||
RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works
Passing strings as such from the Python environment to the HOME environment is straightforward:
Prerequisite: from hppprime import * Example: Code: 00 from hppprime import * but consider this where I try to pass the string as a variable Code: 00 from hppprime import * This doesn't work! Why? The reason is that the content of the variable text isn't enclosed in quotes (or double quotes). Thus it is interpreted as a variable name by the HOME environment ==> Syntax Error Solution: enclose the variable name text with double quotes. here is how it works: Code: 00 from hppprime import * The spaces between the quotes and double quote are here only to show the two different kinds of quotes. Practically you'd omit them as they actually add blanks to the string. In order to make life easier it is suitable to define a function for this Code: 00 from hppprime import * This function is specifically useful for the <TEXTOUT_P> function in the HOME environment as this function is much more powerful than the <textout> function in the Python environment. The next release of my Mandelbrot Explorer will demonstrate some use of it. I hope: a) This is understandable b) of use for someone Günter |
|||
01-23-2022, 11:16 PM
Post: #4
|
|||
|
|||
RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works Correction 17.Jan 2022
I've just published a new Version of my Mandelbrot Explorer.
included is a handy routine for use of HOME TEXTOUT_P. Here is the code snipped Code:
Günter |
|||
01-24-2022, 06:34 PM
Post: #5
|
|||
|
|||
RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works Correction 17.Jan 2022
Supposedly, one of the recent firmware versions allows you to also change the formatting of the text (bold, italic, alignment, monospace, etc.), although I haven't been able to get that to work at all. Would you be able to take a look at that and explain how it works?
|
|||
01-24-2022, 10:44 PM
Post: #6
|
|||
|
|||
RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works Correction 17.Jan 2022
(01-24-2022 06:34 PM)jfelten Wrote: Supposedly, one of the recent firmware versions allows you to also change the formatting of the text (bold, italic, alignment, monospace, etc.), although I haven't been able to get that to work at all. Would you be able to take a look at that and explain how it works? I had a look at it and quite frankly I couldn't decipher how that was supposed to work. Here is how it is described. Quote:A new form of TEXTOUT: If someone could decipher it, with working examples I'd be happy. And could give it a try Günter |
|||
01-25-2022, 02:46 AM
Post: #7
|
|||
|
|||
RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works 22.jan addded a TextOut functio
Wait a minute... apparently this feature was removed in firmware version 2.1.14603. From what I recall, it was introduced in version 2.1.14596, which is supposedly a beta release. So, this is most likely an unfinished beta feature and, while useful, should probably not concern us just quite yet.
|
|||
01-25-2022, 09:44 PM
Post: #8
|
|||
|
|||
RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works 22.jan addded a TextOut functio
(01-25-2022 02:46 AM)jfelten Wrote: Wait a minute... apparently this feature was removed in firmware version 2.1.14603. From what I recall, it was introduced in version 2.1.14596, which is supposedly a beta release. So, this is most likely an unfinished beta feature and, while useful, should probably not concern us just quite yet. I have no idea where to look for these "enhanced features" |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)