Post Reply 
Python oddities
05-05-2021, 07:41 PM
Post: #1
Python oddities
reported to calcbeta

Beta 04/28 and earlier recent Betas
G2 and Virtual, not tested on G1

1. Reboot
2. Drawing not correct


1. Run a Python script from Home, change to any APP, and the G2 reboots.
From Tim's document "PPL-Changes + python.odt" I copied this snipped:

Code:
#PYTHON name
import sys
print(str(1+2)+sys.argv[0])
#end
Export ppl(a)
Begin
   PYTHON(name, a);
End;

The Python program runs o.k. from Home screen by entering ppl(5), but when I later push <APP> <Python> or any other App, the Prime kindly reports "Your HP Prime had a problem and will reboot in 3 seconds." Which it does. Short interrupt only, yet annoying. Every time I make some edits to a script I switch the Prime off and on again in order not to loose anything.

___________________________________________________________________________

2. Drawing functions in Python. Preface: I'm working my way to Python and your implementation of it as a newcomer. Maybe I overlook the obvious.

I've set up this short program to test some drawing functions. As you can see, I have used two options for setting the cartesian parameters. Either with "eval" of "hpprime" or with Python's "set_cartesian" (which is now deactivated) both work fine with "line_c" and "textout_c" but not with "fillrect_c" or "rect_c" that is the latter two don't do anything. The non-cartesian commands are there for comparison. These are the commands I have tested, can't say anything of the other ones.


Code:
#PYTHON name
from hpprime import *
eval("Xmin=-15.9")
eval("Xmax=15.9")
eval("Ymin=-11.9")
eval("Ymax=11.9")
#set_cartesian(-16,16,-11,11)
fillrect_c(0,0,0,30,30,0,0)
fillrect(0,0,0,320,240,0,0)
line_c(0, -15.9, 0, 15.9, 0, 0x00FF00)
line_c(0, 0, -10, 0, 10, 0xFF0000)
fillrect(0,110,80,100,80,0x00FFFF,0xFFFFFF)
textout(0,0,0,"PIXEL",0xffffff)
textout_c(0,-3,0,"CARTESIAN",0)
eval("wait()")
#end
Export zeich(a)
Begin
     PYTHON(name, a);
End;
3. I'm using the HOME environment because only there (true?) I can have various independent Python scripts. The <Symb> <Num> combination isn't really handy. But perhaps I haven't seen the obvious.

I ran all these tests again after I rest the Prime including formatting the "disk", no change.

Yet I think it's a great improvement and keeps me busy to explore new things, thank you very much for these achievements.

Günter
Find all posts by this user
Quote this message in a reply
05-05-2021, 08:56 PM
Post: #2
RE: Python oddities
(05-05-2021 07:41 PM)Guenter Schink Wrote:  reported to calcbeta

Beta 04/28 and earlier recent Betas
G2 and Virtual, not tested on G1

1. Reboot
2. Drawing not correct


1. Run a Python script from Home, change to any APP, and the G2 reboots.
From Tim's document "PPL-Changes + python.odt" I copied this snipped:

Code:
#PYTHON name
import sys
print(str(1+2)+sys.argv[0])
#end
Export ppl(a)
Begin
   PYTHON(name, a);
End;

The Python program runs o.k. from Home screen by entering ppl(5), but when I later push <APP> <Python> or any other App, the Prime kindly reports "Your HP Prime had a problem and will reboot in 3 seconds." Which it does. Short interrupt only, yet annoying. Every time I make some edits to a script I switch the Prime off and on again in order not to loose anything.

___________________________________________________________________________

2. Drawing functions in Python. Preface: I'm working my way to Python and your implementation of it as a newcomer. Maybe I overlook the obvious.

I've set up this short program to test some drawing functions. As you can see, I have used two options for setting the cartesian parameters. Either with "eval" of "hpprime" or with Python's "set_cartesian" (which is now deactivated) both work fine with "line_c" and "textout_c" but not with "fillrect_c" or "rect_c" that is the latter two don't do anything. The non-cartesian commands are there for comparison. These are the commands I have tested, can't say anything of the other ones.


Code:
#PYTHON name
from hpprime import *
eval("Xmin=-15.9")
eval("Xmax=15.9")
eval("Ymin=-11.9")
eval("Ymax=11.9")
#set_cartesian(-16,16,-11,11)
fillrect_c(0,0,0,30,30,0,0)
fillrect(0,0,0,320,240,0,0)
line_c(0, -15.9, 0, 15.9, 0, 0x00FF00)
line_c(0, 0, -10, 0, 10, 0xFF0000)
fillrect(0,110,80,100,80,0x00FFFF,0xFFFFFF)
textout(0,0,0,"PIXEL",0xffffff)
textout_c(0,-3,0,"CARTESIAN",0)
eval("wait()")
#end
Export zeich(a)
Begin
     PYTHON(name, a);
End;
3. I'm using the HOME environment because only there (true?) I can have various independent Python scripts. The <Symb> <Num> combination isn't really handy. But perhaps I haven't seen the obvious.

I ran all these tests again after I rest the Prime including formatting the "disk", no change.

Yet I think it's a great improvement and keeps me busy to explore new things, thank you very much for these achievements.

Günter

Where is PPL-Changes + python.odt?

When I try to export the program name (hat), I get an error at

Export hat()

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
05-05-2021, 10:24 PM
Post: #3
RE: Python oddities
(05-05-2021 08:56 PM)toml_12953 Wrote:  Where is PPL-Changes + python.odt?

When I try to export the program name (hat), I get an error at

Export hat()

It was in Tim's announcement

https://www.hpcalc.org/prime/beta/betanotes.zip

I think the syntax is not really obvious, could you post your code? Perhaps I can help. There are two distinct structures in the mentioned document, either one works, but don't mix them.

BTW, I took the freedom to tailor your Pyhat a bit. There is no improvement, I just played a little bit with Python things.
Code:
#PYTHON EXPORT name(c)
from hpprime import *
from math import *
mache=pixon
t0 = eval("ticks()") # Save the current clock count for timing program
fg=0xa0a0a0
# Clear screen
bg=0
fillrect(0,0,0,320,240,bg,bg)
# Start program proper
p=160; q=120
xp=144; xr=1.5*3.1415927
yp=56; yr=1; zp=64
xf=xr/xp; yf=yp/yr; zf=xr/zp
for zi in range(-q,q+1):
  if zi>=-zp and zi<=zp:
    zt=zi*xp/zp; zz=zi
    xl=int(.5+sqrt(xp*xp-zt*zt))
    # Draw one cross-section of figure
    for xi in range(-xl,xl+1):
      xt=sqrt(xi*xi+zt*zt)*xf; xx=xi
      yy=(sin(xt)+.4*sin(3*xt))*yf
      x1=xx+zz+p
      y1=yy-zz+q
      mache(0,x1,230-y1,fg)
#      eval("wait(0.001)")
      if y1!=0:
        line(0,x1,230-y1+1,x1,230,bg) # Erase points below current point
#    eval("wait(0.001)")
t = eval("ticks()")-t0
# Wait for key and print elapsed time
eval("wait()")
t = t/1000
print(t," seconds")
#end
Export pyhat(a)
Begin
  name(a);
End;

This has to be copied into an PPL program to work. Then it can be called by "pyhat(0)", any number instead of "0" will do.

Günter
Find all posts by this user
Quote this message in a reply
05-06-2021, 12:28 AM (This post was last modified: 05-06-2021 12:53 AM by toml_12953.)
Post: #4
RE: Python oddities
(05-05-2021 10:24 PM)Guenter Schink Wrote:  
(05-05-2021 08:56 PM)toml_12953 Wrote:  Where is PPL-Changes + python.odt?

When I try to export the program name (hat), I get an error at

Export hat()

It was in Tim's announcement

https://www.hpcalc.org/prime/beta/betanotes.zip

I think the syntax is not really obvious, could you post your code? Perhaps I can help. There are two distinct structures in the mentioned document, either one works, but don't mix them.

BTW, I took the freedom to tailor your Pyhat a bit. There is no improvement, I just played a little bit with Python things.

This has to be copied into an PPL program to work. Then it can be called by "pyhat(0)", any number instead of "0" will do.

Günter

OK, I got it to work now. Thanks!
I did change the line to

fg=exec("rgb(0,255,0)")

since that keeps the figure green and doesn't exact a time penalty by being enclosed in the loop.

What's the purpose of "mache"?

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: