Download Latest Version converter_0.234b_dev_beta.tar.gz (530.5 kB)
Email in envelope

Get an email when there's a new version of ALMA pyconv

Home / pyconv
Name Modified Size InfoDownloads / Week
Parent folder
readme.txt 2025-05-28 14.1 kB
converter_0.234b_dev_beta.tar.gz 2025-05-28 530.5 kB
converter_0.233d_beta.tar.gz 2025-05-28 505.2 kB
ALMA_pyconv_0.233b_beta.tar.gz 2019-01-16 468.5 kB
alma_pyconv_0.233a_beta.tar.gz 2019-01-12 467.0 kB
alma_pyconv_0.232_beta.tar.gz 2019-01-09 455.4 kB
alma_pyconv_0.231_beta.tar.gz 2017-03-11 451.0 kB
alma_pyconv_0.23_beta.tar.gz 2017-03-02 481.8 kB
Totals: 8 Items   3.4 MB 0
// ANSI CP 1250 , CR+LF


----------------------------------------
****************************************
README
****************************************
----------------------------------------

pyconv.php

recent version : 0.234b dev beta


****************************************
Short description
****************************************

Note : The very first completely functional version is the 0.233b beta ! 

This script :

- as a web script does a limited conversion on Python 2 source files (for example for run them by Skuplt) so that the source can be written in ALMA Python syntax, it comes with a complete web directory ('converter') and can be used by the page 'converter.php' in a server 
(but its main purpose is an online demonstration only !)

- as a console script does a limited conversion on Python 2 source files so that the source can be written in ALMA Python syntax
(but its main purpose is writing short Tkinter
scripts only !) 

- with or without switched-on identation and with a well built dictionary can be useful for very little projects as a preconverter for pindent.py, using ALMA Python syntax

for such purpose you may change this line :


- with or without switched on identation and with
a well built dictionary can be useful for very little
projects as a preconverter for pindent.py,
using ALMA Python syntax

for such purpose you may change this line :

$ujszoveg = converter($szoveg , "command_line" , true , $hiba , $tk) ;  

for no identation :

$ujszoveg = converter($szoveg , "command_line" , false , $hiba , $tk) ;

for 2 space identation :

$ujszoveg = converter($szoveg , "command_line" , 2 , $hiba , $tk) ;

etc.


For older funcional version it might be the proper syntax (please take a look into the description in the actual pyconv.php file !): 

$ujszoveg = converter($szoveg , "command_line" , true ) ;  

for no identation :

$ujszoveg = converter($szoveg , "command_line" , false ) ;

for 2 space identation :

$ujszoveg = converter($szoveg , "command_line" , 2 ) ;

etc.


Note : 
This script has its limits so this converter can not be used for general purpose as standalone converter.
Also, as my original aim was only convert short Tkinter scripts for my own projects, this script has an ad-hoc design with several independent loops for the text of the source code files, it is a hard limit for online usage.


Important !
This version and possibly all version come with only a poor built-in dictionary for aims of test and development.
It is the user's job to make a well maintained dictionary to herself.
You can find the dictionary in this script in the function converter() at the bottom of section 'variables'.  


-------------------------

A block does not need any indentation, but it can have free indentation style.
So the programmer have not worry about white spaces at all.

For example it is a valid ALMA Python code :

a_ = 0

while a_ < 100 :

c_ = ""

if a_ = round(a_/2)*2 :

print a_

for b_ in range(a_) :
c_ = c_ + "*"
endfor

print c_

endif

a_ = a_ + 1

endwhile


*****************************

Features

- free indentation style
- BASIC-like conditional statement with equals sighn
- built-in dictionary for case insensitive keywords


****************************************
How to use pyconv.php
****************************************

Firstly, you need a python script to convert. That script must apply the rules of ALMA Python syntax.
In this example that python script is named as 
'myscript.python'

Note for console mode :
The extension can be any valid extension, such as 'py' or 'pyt' or 'myextension', etc.
So the name of the script in this example also could be :
'myscript.py'
or
'myscript.pyt'
or
'myscript.myextension'
etc.

--------------   
console mode :
--------------

I. with no pindent.py
---------------------

From the version 0.233b beta or above it is doable. It is the default behavoir of pyconv.php for console mode. For identation there is more information above in the description.


in command line, when you give 'py' as new extension :

php pyconv.php myscript.python py

(Note : so you can type the above line in the console promt then hit the Return button.)


in command line, when you give no new extention :

php pyconv.php myscript.python

(Note : so you can type the above line in the console promt then hit the Return button.)


In the second case (when you do not give any new extension), the new extention shall be 'py' anyway.

You can give any valid new extention, not only 'py'.
For example :

php pyconv.php myscript.python piton

(Note : so you can type the above line in the console promt then hit the Return button.)


II. with pindent.py
-------------------

----------------------------------------------------------------
!! Important !! : This funcion was tested lastly about 7-8 years ago !!
At the recent development the pindent.py script (of course the version for Python 2) was not important. I will test it if the recent development and tests (without pindent.py) are already finished. The recent main goal of the development would be only a funcional PHP5 version of the pyconv.php script with limited purposeful basic funcionality and satisfaction. Trying to use pindent.py would be just optional and experimental.
----------------------------------------------------------------

It would be probably the much safer way of conversion though.

The whole conversion could be done in two steps.

1) first step 

Like it described above, in command line, when you give 'py' as new extension :

php pyconv.php myscript.python py

(Note : so you can type the above line in the console promt then hit the Return button.)

in command line, when you give no new extention :

php pyconv.php myscript.python

(Note : so you can type the above line in the console promt then hit the Return button.)


In the second case (when you do not give any new extension), the new extention shall be 'py' anyway.

For pindent.py you need the extention 'py' anyway !

---
Also important : it is better to apply pyconv.php 
with no identation

so the proper line in pyconv.php for this is as follows

$ujszoveg = converter($szoveg , "command_line" , false ) ;

OR

$ujszoveg = converter($szoveg , "command_line" , 0 ) ;
---

2) Second step

In this example you need a script which converted from 
'myscript.python' by pyconv.php, and has a new extention 'py'.
For example, let the new name be :
'myscript.py'

Note :
So in this example, 'myscript.py' is a Python script which made by a conversion from 'myscript.python'. The converter was pyconv.php

Now in the second conversion (= in the second second step), you have to use pindent.py in command line :

python pindent.py -r myscript.py


(Note : so you can type the above line in the console promt then hit the Return button.)

3) Final notes :

Of course you can write your own script to automate these steps. (I used FreeBASIC for that aim.)

This was my FreeBASIC script for pythconv.php (it was the  name of the very first version), you have to modifiy it if you want to use it for pyconv.php :

'-------------------

' UTF-8 , CR+LF

'program eper

dim shared as string parameters_
dim shared as byte n

parameters_ = "pythconv.php "
parameters_ = parameters_ + command$(1)
print "task : php " + parameters_
exec("php" , parameters_)

n = instr(command$(1) , ".")

if not n = 0 then
parameters_ = "pindent.py -r " + left(command$(1) , n - 1) + ".py"
else
parameters_ = "pindent.py -r " + command$(1) + ".py"
endif

print "task : python " + parameters_
exec("python" , parameters_)

print "eper converter is READY"

parameters_ = mid(parameters_ , 15 , len(parameters_) - 14)
exec("python" , parameters_)

print "eper is READY"

end

'-------------------

Note : Of course you should (would) need a Python 2 interpreter and a PHP interpreter installed in your machine for this FreeBASIC script. (pyconv.php developed for PHP 5) In Windows XP for both you also need proper path in the environment variable PATH/Path (sorry I do not know other Windows versions). 


-----------
web mode :
-----------

You have to upload/copy the whole folder 'converter' into your web/server directory.
This folder contents two stuffs from other authors :
EditArea (as online code editor) and Skulpt (as Python 2 interpreter). It comes with a test page (converter.php) which is used for the development. Both EditArea and Skulpt needs Javascript !

For start you can load the page converter.php in a web browser.

For example if you use XAMPP in Windows, the URL is :

http://localhost/converter/converter.php


Note :

In the script converter.php :

// it shall produce an indented code with 1 tab as indentation :

$text = converter($text , "web" , true) ;


// it shall produce an indented code with 2 spaces as indentation :

$text = converter($text , "web" , 2) ;


// it shall produce an indented code with 3 spaces as indentation :

$text = converter($text , "web" , 3) ;

etc.


****************************************
Syntax
****************************************

About this syntax
------------------

1. The syntax for pyconv.php called ALMA Python. It is a Python 2 syntax with some modifications.

2. The concept of the syntax for ALMA Python comes from the syntax for pindent.py. It has aimed to turn Python into a BASIC-like language, although it has some limits :

a) It is a restricted syntax for Python because of a BASIC-like feature.
b) Due the fact it comes from the pindent.py project it is fairly close to Euphoria and the alternate syntax for conditional statements in PHP. So it is not really a BASIC-like feature, but something similarly simple.   


ALMA Python syntax rules
------------------------

1.

There are seven kind of blocks which are closed by 
end (of block) statement :

if , while , for , try , with , def , class

a)

The end (of block) statement consists of two parts : the 'end' keyword and after it the block keyword :

end if , end while

etc.

b)

The end (of block) statement can be written in one word :

endif , endwhile , endfor

etc.

c)

The end (of block) statement is case insensitive.

So these are all legal end (of block) statement bellow :

EndIf , EndwHilE , endFOR

d)

A block does not need any indentation, but it can have free indentation style.

For example :

#---------------

a_ = 0 ; b_ = 5 ;
while a_ = 0 or a_ < 10 : 
if a_ = 4 or a_ = 6 or a_ = 8 or b_ =9 :# komment
print a_ ; print "alma" ;           
end  if
a_ = a_ + 1 
endwhile # komment



# Or for example :

		a_ = 0 ; b_ = 5 ;
		while a_ = 0 or a_ < 10 : 
	if a_ = 4 or a_ = 6 or a_ = 8 or b_ =9 :# komment
print a_ ; print "alma" ;           
	end  if
		a_ = a_ + 1 
		endwhile # komment

		
# Or for example :
 
a_ = 0 ; b_ = 5 ;
while a_ = 0 or a_ < 10 : 
	if a_ = 4 or a_ = 6 or a_ = 8 or b_ =9 :# komment
		print a_ ; print "alma" ;           
		end  if
	a_ = a_ + 1 
	endwhile # komment 

#---------------


2.

This version (and possibly all later versions) can not 
handle wrong multiline comments. Also, it has its hard
limit to handle multiline comments built in each other,
so please try to avoid such multiline comments.

This is still doable but please try to avoid this :

"""
Comment
 '''
 Comment
   '''
Comment
"""   

But a little fault like this may cause serious conversion trouble :

'"'
Wrong comment
'''
Codes here

'''
Comment
end if
'''

3.

It is possible to apply '=' instead of '==' in conditions.

For example :

while a_ = 0 or a_ < 10 : 

instead of

while a_ == 0 or a_ < 10 : 


Notes :

a)

This BASIC-like feature makes a restricted syntax.

In Python, a programmer can write something like this in his code :

if a_ = b_ == 0 :

In ALMA Python syntax it is impossible, because the converter shall produce this line from the above example :

if a_ == b_ == 0 :  

b)

It is possible to use the original Python syntax for 
'==' like in this example :

if a_ == 0 : 

4.

The whole syntax can be case insensitive, but it depends on the dictionary built in the script pyconv.php
The user has to create/develop her own dictionary for that.

Originally the script pyconv.php has a built-in dictionary for development or test purpose only. It comes with a few Python keywords, most of them come from a simplified Tkinter usage. Any keyword which is in this dictionary can be case insensitive in the script being converted.

a)

I recommend to use this web site to get Tkinter examples :

http://www.python-course.eu/python_tkinter.php


Note :
The names of the Events are case sensitive ! So - for example - the two lines bellow are wrong : 

widget.bind('<button-1>', hello)
widget.bind('<double-1>', quit)

b)

How to edit the dictionary :

#------// dictionary //------#

$dictionary = array
(
# Tkinter
"tkinter" => "Tkinter" ,
"tk" => "Tk" ,
"label" => "Label" ,
"message" => "Message" ,

etc.

For example, this is an entry of the dictionary :

"tkinter" => "Tkinter" ,

If you want to put a new entry into the dictionary, for example for the word 'HTMLParser', you can put a new line into the dictionary with this content :

"htmlparser" => "HTMLParser" ,

Note :
You can notice that the last entry line ends with no comma in the dictionary, because the whole thing is a comma separated list. The list only was written line by line because of readability and easy typing.

c)

A simple code example for Tkinter :

# -*- coding: utf-8 -*-
# UTF-8 , CR+LF

from tkinter import *

ablak_1 = tk()
ablak_1.geometry("200x100")

w = label(ablak_1, text="Hello, world!")
w.pack()

ablak_1.mainloop()
Source: readme.txt, updated 2025-05-28