Python: TEXTOUT_P, CHOOSE, INPUT here is how it works 22.jan addded a TextOut functio - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works 22.jan addded a TextOut functio (/thread-17833.html) |
Python: TEXTOUT_P, CHOOSE, INPUT here is how it works 22.jan addded a TextOut functio - Guenter Schink - 12-20-2021 10:17 PM 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 RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works - tcab - 12-29-2021 07:51 AM Thank you Guenter for these continued, amazing discoveries about Python on the Prime! RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works - Guenter Schink - 01-17-2022 08:59 PM 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 RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works Correction 17.Jan 2022 - Guenter Schink - 01-23-2022 11:16 PM 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 RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works Correction 17.Jan 2022 - jfelten - 01-24-2022 06:34 PM 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? RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works Correction 17.Jan 2022 - Guenter Schink - 01-24-2022 10:44 PM (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 RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works 22.jan addded a TextOut functio - jfelten - 01-25-2022 02:46 AM 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. 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 (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" |