Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
139 user(s) are online (120 user(s) are browsing Forums)

Members: 1
Guests: 138

rjd324, more...

Support us!

Headlines

 
  Register To Post  

(1) 2 »
Python
Just can't stay away
Just can't stay away


See User information
Hi i, uploaded
http://users.online.be/AD/P_Docstring.gc
a gui written in Gui4Cli to view the classes, functions, docstrings or combinations thereof of a Python module, view the entire module or open the classic __doc__ result (less interesting than the combination, possibilities above.

The gui opens on the Python:lib drawer and aloows easy selection of module to query.

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@all

Hi, i uploaded also
http://users.online.be/AD/UsingAmiPython.htm

My newbee search report on using Python on the Amiga.
I intend to complete it with later experience, and any comment
will be gladly taken up.

The original text is
http://users.online.be/AD/UsingAmiPython.txt
written in "restuctuted text" markup
It was transformed to html using rst2html.py from the docutils page.

Go to top
Re: Python
Quite a regular
Quite a regular


See User information
@JosDuchIt

Great! Thank you!

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@Joeled
Thanks for your appreciation

@ all
Has anybody found how to make use of the packages in lib?
Even only having acces to help("module") or help("packagedrawer") ?
Except for the drawers defined in sys.path such help is not available

Here are my results:

I used the following AppendPath.py to add drawerd eg (lib/xml) to the path.
This seems to do its job

put it in python:scripts
use it interactively as follows:
Python:scripts> python
Python:scripts> import AppendPath

AppendPath.py
-------------------
import sys
print sys.path
import asl
drawer, file = asl.FileRequest('Select a Python lib drawer', 'Python:lib', '', '')
print drawer
sys.path.append(drawer)
print sys.path
-----------

Remark: you have to open the lib subdrawer (eg the xml drawer), selecting a file is unnecessary

However even after that help(xml) help(saxutils) gives me a NameError: xxx is not defined


What does work however is copying the xml drawer in the sites-packages drawer.

It still leaves me unsatisfied.

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@all

I still am not able to change PYTHONPATH environmental variable (or should i use PYTHONHOME ??)
I did try to save a modified path (obtained with sys.path) modified as above above to env:PYTHONPATH using
PPath = open("envarc:PYTHONPATH","w")
pickle.dump(sys.path,PPpath)

It does not help and leaving python and then entering python again (from the same shell or an other has python mixzed up and freezed.

At least i found that os.chdir permits to test successive modules located in any directory, without having to leave the python session in order to change the current directory


I did put the folowing 'module' in Python:lib/Hello/ drawer

Hello.py
---------
""" a test for learning how to locate & use modulesn libraries """
def hell():
print "hello"
---------
>>> os.chdir("Python:lib/Hello/")
>>> import Hello
>>> hell()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'hell' is not defined
>>> Hello.hell()
hello
>>> help(Hello)


Help on module Hello:

NAME
Hello

FILE
python:lib/hello.py

FUNCTIONS
hell()

Usefull (hm) Links on Python environmental variables

http://www.wellho.net/resources/ex.php4?item=y115/penv.py "Python environment variables - Python example"
http://docs.python.org/library/os.html "15.1. os ? Miscellaneous operating system interfaces ? Python v2.7 documentation"
http://code.activestate.com/recipes/1 ... et-environment-variables/ "How to Set Environment Variables « Python recipes « ActiveState Code"
http://tingzhou.wordpress.com/2008/04 ... ment-variables-in-python/ "Set environment variables in python « Ting?s research page?>Moved to http://tzhou.blogspot.com/"
http://docs.python.org/using/cmdline.html#using-on-envvars "1. Command line and environment ? Python v2.7 documentation"

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@JosDuchIt
A strange thread on Python!
...a gui written in Gui4Cli...
Oh yeh! That's not even listed on the OS4 Depot. I can't find it.?

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@Snuffy
The link is
http://users.online.be/AD/P_Docstring.gc
Download also from
http://users.online.be/AD/ also the OS4 compatible Gui4Cli interpreter.and "gui." (still 68k) its launcher
You will find both in OWB_.gc that should work out of the box. Save P_Docstring.gc next to the OWB_.gc file. You might care to have a look at it,.

AmigaPython has till now only the asl module as 'gui' (requesters)
As explained in http://users.online.be/AD/UsingAmiPython.htm you can use the GUi4Cli gui creation facilities to launch python scripts & make them interact through files, environmental variables.

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@Snuffy
Some more reflections on the integration of Gui4Cli and Python (and their comparison)



Python is said to be well fitted to the development of large applications.
In fact some essential features permitting this are present in Gui4Cli too.
One of these is the concept of namespaces.
For Python see http://bytebaker.com/2008/07/30/python-namespaces/
For Gui4Cli see http://users.online.be/AD/Gui4Cli_.guide

- The equivalent for an "import" in Gui4Cli is a "Guiload", so you can build libraries of subroutines, or hust reuse subroutines from another running application.
- variables & subroutines of a specific loaded subroutine (which can or cannot return values, can be addressed directly
- the latter is also possible through arexx commands. In fact you might in this way run some python script that is launched from within a Gui4Cli's gui (eg attached to some button)

What is lacking in Gui4Cli is the concept of functions, classes

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@JosDuchIt

....you can use the GUi4Cli gui creation facilities to launch python scripts & make them interact through files, environmental variables.
Really? I just make sure the 'tooltype' is Python and drop them in 'RamDisk' and click them; for example: Calendar.py I find "ANN" is my best friend interface for Python & scripting.
Do you have any info on running a "Curses" terminal? It's all their in the Python:Libs/Curses.

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@Snuffy

can you give some explicit examples how you start or use curses?
I don't find the info helpfull enough for a newbee like me.
It does not seem to have a gui, right ?
Calendar seems to be only a printing appplicartion (no gui) right?
What is ANN ?

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@all
1. Regular expressions
-----------------------------------
I uploaded http://users.online.be/AD/P_RegexPhone.gc
It demonstrates the use of python regex module re.py.
Clicking in a list of phone numbers will transform it to a standard format.
The right listview shows the python script that is generated and modified on the fly before execution

Inspiration from
http://www.regular-expressions.info/reference.html "Regular Expressions Reference - Basic Syntax"
http://www.pythonregex.com/ "Python Regex Tool"
http://www.regular-expressions.info/repeat.html "Regex tutorial * and + "
http://diveintopython.org/regular_exp ... ons/street_addresses.html "7.2. Case Study: Street Addresses"
http://diveintopython.org/regular_expressions/verbose.html "7.5. Verbose Regular Expressions"

Regular expressions and pattern matching is lacking in Gui4Cli as an independent functionality, so this was a motivation for me to get to grips with python.

2. Environmental variable PYTHONSTART
-----------------------------------------------------------
This variable will tell python to run the corresponding script first (as if all commands were typed from the shell).

To the contrary of PYTHONPATH setting this variable works OK.
You can set it from CLI
as
> setenv PYTHONSTARTUP 'myscriptpath.py'
and then
>python will start with executing this first
This is quite usefull for rapid testing or repetitive use & developing of some script from shell.

3. Gui's for Python
--------------------------
Is anybody aware of a python GUI package or module that works under OS4? TkInter is in the 2.5.1 distribution but i can't get it to work. I don't know what to expect either: Do you have to set up a loop to see which gadget has been hit or used, or can you add code directly to the gadget (or event as they are called in Gui4Cli) ??

4. rst 2 html gui
---------------------
I uploaded http://users.online.be/AD/P_2htm.gc permitting to transform restructured text files to html
It needs rst2html.py

5. Save and load python datastructures
-----------------------------------------------------
Saving and loading datastructures (a feature Hollywood has too) is one of the ways to make different pythonscripts to interact in "real time" (using ram: or env:) or slower using HD.

http://users.online.be/AD/P_dump.gc demonstrates this

6. Launching applications or scripts from a Gui
---------------------------------------------------------------
The following quick methods are available to speed up launching of your favorite or recently most used applications or scripts

- Use Workbench putting them together in a directory with icons an launching tooltype
- If in the same directory maybe launchable with a diorectory manager
- Have those icons on Amidock or similar
- Have a gui using an event based gui system (say Gui4Cli)
- using buttons or icons
- using a directory listview (if most are in teh same directory
- using a 'dictionary' with 'keys' (names) and application paths, the names being visible in a listview
Uploaded http://users.online.be/AD/P_Launch.gc demonstrating these 3 methods for the other uploaded Python-Gui4Cli gui's

It is to be noted that Gui4Cli has three ways of launching an external script, CLI command or application
- Synchronous; CLI "MyexternalcommandPath'
- asynchronous; RUN "MyexternalapplicationPath"
- asynchronous too but with a notification of the applications closing : LAUNCH "MyAppPath" using xONRETURN to continue the command sequence needed after that.
(of course you can also use Workbench's arexx port from Gui4Cli to launch an application)
(Appart form that it has its own way of launching & opening Gui4Cli scripts)



Python has the os.startfile() function I have still to test its possibilities

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@JosDuchIt


can you give some explicit examples how you start or use curses?
Try:
import curses
But, there's no module!

It does not seem to have a gui, right ?
It's a windowed terminal.

Calendar seems to be only a printing appplicartion (no gui) right?
It's a calendar program. I don't know about a 'printing appplication' ?

What is ANN ?
It's kind of a programmer's text editor called 'Annotate': http://www.onyxsoft.se/annotate.html
I use it a lot for Python and SDLBasic scripts.

Is anybody aware of a python GUI package or module that works under OS4? TkInter is in the 2.5.1 distribution but i can't get it to work.
Because there's no 'module' -- the DLL of python. Python requires modules to to run stuff and there ain't that many. Sorry, but 'Gui4Cli' just doesn't work for me as a Python gui. An AmiCygnix interface/gui would be nice. That's why I mentioned "Curses". Did you know that there's a "PyGTK"? AmiCygnix already uses GTK-2.0. One only has to compile "PyGObj" to AmiCygnix to get PyGTK you would think. ?

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@Snuffy
@Snuffy
Annotate:
I looked at it some time, does it have Python support ?
I am using Cygnus Ed and am sticking to it because of its excellent arexx port .( I have my own Gui4Cli support written in Gui4Cli ) How do both compare in your opinion?
Curses:
I understand it can't be used under AOS4

Calendar:
With a 'printing application " i just mean "no gui", only printing to the shell, no buttons to select the kind of calendar you want to see in some listview and maintain it there, no save button to have a requester appear to save it for use in another program or document: the traditional 'shell printing utility' wher you need intensive typing skills and a very good memory.

Templates:
The above makes me aware that i still did not discover if you can easily get the template of some script, function. Most traditional AOS shell commands generate such template. There is a venerable Gui4Cli written "autogui" script that generates a gui on the fly for such commands.
A non-automatic Gui4Cli gui as described for calendar.py is easy to write. There is no need here for thight interaction between python modules.

Gui generation
I am no gui package specialist, unable even to give advice on the comparative merits of MUI & Reaction. I can give expert opinion on the abilities of Gui4Cli and its usefullnes and motivational value for a newbee trying to do something with the acquired python knowledge that goes beyond CL interface.

For tight integration of a complex python application you probably need more than Gui4Cli: some of the packages http://wiki.python.org/moin/GuiProgramming with a good Guibuilder.
This is not a python newbee concern though.
Starting from your hint i looked at the GTK & PyGTK & Cairo & Autoglade line a
http://library.gnome.org/devel/gtk-tutorial/stable/
http://sourceforge.net/projects/autoglade/
This is hardly newbee stuff, where getting to easily know & use the installed libraries (the PYTHONPATH problem still not solved) is the first hurdle, have an idea of what else exists, installing what looks usefull getting to know & using an external package the second

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@all

Wheras the python help system was able to list the keywords, it did not give info for a chosen keyword in my setup (as it came with OS4.1 i guess)

help> and
gave the answer:
---
Sorry, topic and keyword documentation is not available because the Python
HTML documentation files could not be found. If you have installed them,
please set the environment variable PYTHONDOCS to indicate their location.

On the Microsoft Windows operating system, the files can be built by
running "hh -decompile . PythonNN.chm" in the C:\PythonNN\Doc> directory.
---
This pointed me to the URL where you can download the "standard 2.5.1 documentation" archive : http://www.python.org/ftp/python/doc/2.5.1/
I did download this doc form
http://www.python.org/ftp/python/doc/2.5.1/html-2.5.1.zip
unzipped it in the python: drawer and from shell did
> setenv PYTHONDOCS "PYTHON:Python-Docs-2.5.1"
and
> copy env:PYTHONDOCS envarc:


The help system (pydoc it seems) is a lot more usefull now.
Information not contained in the docstrings of functions & modules. is now avalable It also gives info now on individual keywords, modules and topics.
The module list is far larger than the one you can query before (probably limited to the ones in the PYTHONPATH non existing and not cahangeable environmental variable. (becoming very frustrated at this one)
eg
help> icon

I also found that in order to get help information directly form the python interactive shell you should use '"'s
>>> help("keywords")
>>> help("and") # a keyword
>>> help("topics")
>>> help("float") # a documented topic
>>> help("integer") # mentioned in the topics list but not documented
>>> help("modules") # all modules in python:lib , ???
>>> help("icon") a module listed
>> help(icon) will not work : icon undefined.

At least this is a big step forward in handling the existing doc for newbee.me

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@all
I just did notice that the version of Python i have now is no longer 2.5.1 as mentioend in
sys:documentation/python/AmigaPython.txt but a bugfix version 2.5.5 which also came with a new documentation

http://www.python.org/ftp/python/doc/2.5/html-2.5.zip

I installed it in PYTHON:Python-Docs-2.5
and adapted the PYTHONDOCS environmental variable to this location

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@all

I did get from Vegaseat on Daniweb the following working snippet, allowing to save help information to file:
-----
# simplified version of sending help() output to a file

import sys

# save present stdout
out = sys.stdout

fname = "ram:help_print7.txt"
# set stdout to file handle
sys.stdout = open(fname, "w")

# run your help code
# its console output goes to the file now
help("print")

sys.stdout.close()

# reset stdout
sys.stdout = out
-------

I'll use that in P_Docstring.gc to generate list of modules and have access to the standard documentation from a mouseclick in the left listview.

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@JosDuchIt #14

...Sorry, topic and keyword documentation is not available because the Python HTML documentation files could not be found.
I'm not following all your info. ???
If you were writing a script and wanted help with a 'directive' quickly, try this: Import the module of your directive; for example, let's use 'exit' in the module 'Sys' :

Amiga Python 53.29
Python 2.5.5 ...
>>> import sys
>>> help(sys.exit)

exit(...)
exit([status])

Exit the interpreter by raising SystemExit(status).
If the status is omitted or None, it defaults to zero (i.e., success).
If the status is numeric, it will be used as the system exit status.
If it is another kind of object, it will be printed and the system
exit status will be one (i.e., failure).
------------
The formula:
>>> help(module.directive) works most of the time.

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@Snuffy
When you do
>>> help()
you are informed about the fact that you can get help on "modules" "keywords" and "topics"

If you did not install the html documentation as pointed at with the given URL you wil not for example have an usefull answer for
>>>help("and")
"and" being a keyword not a module or a function
help("modules") give you a list of the standard modules you can query
You do get access also this way to usefull help on the built-in functions or
statements
eg
>>> help("print")

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@Snuffy
@Snuffy

" if you were writing a script and wanted help with a 'directive' quickly, try this: Import the module of your directive; for example, let's use 'exit' in the module 'Sys' : ..."

What i am trying to achieve is easy acces to what is available.
If you know allready that you need to import sys that's a step further.

I want to see what is available as info on the functionality of sys and export it to a file, note this info in some user list (things i learned, things i used in) etc That's what P_docstring.gc is heading at.
I want to browse quickly through topics keywords, standard modules
help("modules") saved to a file and visible in a listview.
The pluspoint is, that i have right now a motivation to use python scripts even if they are embedded in a Gui4Cli frame.

A trick i discovered to interface to a simple python script, mypython.py which does something with some file and has some line,

myfile = open("env:myoutput","w")

without the need to add an asl query or arguments passing is this:
i replace it with
myfile = open(@myoutput, "w")
I then load the script in a Listview of my Docstring.gc gui
I replace it there with the Gui4Cli Command
LVRep @myoutput '"$myoutput"' CS
where $myoutput is the value of the variable myoutput
Then save the modified mypython.py and launch from within the gui.
Not brilliant and fast but perfect for me right now

Go to top
Re: Python
Just can't stay away
Just can't stay away


See User information
@all



I uploaded a new version of DocString.gc You can find it here:
http://users.online.be/AD/P_Docstring_.gc

It generates the 3 help lists "modules" "keywords" and "topics", as well as the list of builtin functions.
Using a cycler the left LV will show these lists.
Double clicking gives you the help info
xCYCLER 540 0 60 17 target target
GadHelp "modules in python/lib or builtIn functions"
CSTR Lib Lib
CSTR Mod Mod
CSTR Key Key
CSTR Topc Topc
CSTR B_In B_In

The first one 'Lib' (default on opening) opens a directory LV on the Python:Lib drawer.
Most of the top buttons work only in this mode and give you info on the first highlighted module.

I'll have them disappear when you select an other target.

The gui has to be improved now and the code cleaned up.

The idea is also to get as much as possible done in python scripts.(those scripts appear as Textfiles in the Docstring source and are copied where the Textfile points to ( mostly in env:
as env:.mypythonscript.py

The "." is important in Gui4Cl because that identifies the file as an environmental variable.
You can have a (help) requester showing its content like this

Ezreq $.mypythonscript.py ok var

Suggestions or questions are wellcome.

Go to top

  Register To Post
(1) 2 »

 




Currently Active Users Viewing This Thread: 4 ( 0 members and 4 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project