Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » STARTED: Python in bazaar
STARTED: Python in bazaar [message #31845] Wed, 30 March 2011 23:09 Go to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
hi guys,

i've just been playing around with python, and start to lovin it, at least in script area. when it comes to C API it's kinda BS. beeing still a novice in python i've been studying the C API a bit and accumulated some examples from the net.

so here we go. bazaar has got Python now, but is still not complete. it offers the basic development environment, release and debug version. a 'PyConsoleCtrl', which invokes python in a upp window, means the GUI/Main Thread does the job, and a 'PyShell' which opens a new thread window using Tk from python modules itself. it's a MT environment then. A PyTest shows how to generally use the C API when extending/embedding.

the syntax of native embedding is not very nice. i think of building a bridge PyObject <--> Value to make life easier. but since i'm new to it i'd love to have some help. so anyone with experience in python C API and UPP is welcome.

meanwhile, try what's there Smile

PS: the Python package contains a python27_d, whith the debug version of the lib, to spare you the work of compiling it. installation instructions are provided there too.
Re: STARTED: Python in bazaar [message #31846 is a reply to message #31845] Thu, 31 March 2011 06:28 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
I developed a Python module in my past life. It seems to be not that hard in simple cases, but if you want to dive deeper it is getting scary. I remember having a lot of troubles trying to simulate exception classes in the way I needed. Any way, I can try to help. My code is open source, though I'm not very proud of it.

Regards,
Novo
Re: STARTED: Python in bazaar [message #31849 is a reply to message #31846] Thu, 31 March 2011 09:44 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
sound good...

my goal would be to only offer a small single interface to python, not too extensive.. focus on exporting some part of the API of a Upp side class to be available in python and vice versa.

this implys the Value - PyObject translation for the most common types in python

Value: PyObject:

int = long int
in64 = long long integer (theoretically it's unlimited)
double = real
bool = BOOL
String = String
Time = DateTime
Time = Time
Date = Date

Vector<Value> = tuple (Vector<> basicly to distinguish from list)
Array<Value> = list
ArrayMap<Value, Value> = dict


and ofcorse the methods for modules/classes or static funcitons API

i'm still thinnking of how to best do the latter part.
since somehow with the self PyObject we'd need to access the class instance..(module instance is always the same, for static functions self == NULL anyway). i think it'd be best to have the upp class have a python PyObject* instance of the python class, and have the PyObject instance have another PyObject* as private member (kind of a contect variable) which represents the this pointer of a upp class. so both classes are runtime connected without the need to use maps.

could you provide your sourcecode to learn?

BTW: have you been able to use the Python package in bazaar?

[Updated on: Thu, 31 March 2011 09:45]

Report message to a moderator

Re: STARTED: Python in bazaar [message #31850 is a reply to message #31849] Thu, 31 March 2011 09:57 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
w.r.t. interfacing python with C++, see

http://www.boost.org/doc/libs/1_46_1/libs/python/doc/index.h tml

(boost is opensource, so I believe the boost library code could be used as reference...)
Re: STARTED: Python in bazaar [message #31851 is a reply to message #31849] Thu, 31 March 2011 09:58 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Thu, 31 March 2011 03:44

Vector<Value> = tuple (Vector<> basicly to distinguish from list)
Array<Value> = list
ArrayMap<Value, Value> = dict




Perhaps ValueArray and ValueMap might be a better option here?
Re: STARTED: Python in bazaar [message #31853 is a reply to message #31851] Thu, 31 March 2011 10:22 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
your' right Smile thanks...somehow dropped off my mind
Re: STARTED: Python in bazaar [message #31856 is a reply to message #31853] Thu, 31 March 2011 10:37 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
w.r.t BOOST:
wasnt there some descussion to include boost in upp?
but i remember it to be very bloated for that means..

but definitely, the part op python could be worth it..
at least, as a helper to achieve similar things for upp.

the licence is sth similar to BSD..

EDIT: can someone try to compile and use the PyConsoleCtrlTest in linux, optimal and debug? i have got no tux environment around now.. tried to compile it with TDMGCC both release and debug, both work..

[Updated on: Thu, 31 March 2011 11:26]

Report message to a moderator

Re: STARTED: Python in bazaar [message #31859 is a reply to message #31856] Thu, 31 March 2011 12:05 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Thu, 31 March 2011 04:37

w.r.t BOOST:
wasnt there some descussion to include boost in upp?
but i remember it to be very bloated for that means..



What do you mean by 'include'?

You want to use boost, use boost. It is very STLish, so it is not exactly "U++ way compatible", but it is C++ library and there should be nothing to prevent you using it...

Of course, it would be possible to create something like plugin/boost.
Re: STARTED: Python in bazaar [message #31860 is a reply to message #31856] Thu, 31 March 2011 12:06 Go to previous messageGo to next message
chickenk is currently offline  chickenk
Messages: 169
Registered: May 2007
Location: Grenoble, France
Experienced Member
PyConsoleCtrlTest works for me under Linux, in both Optimal and Debug modes, with 2 important remarks:

1. I tested with my own upp-waf build system and not theIDE directly since I was too lazy to open up theIDE... Razz I'll try it when I can though

2. On my system (let's say it's a Gentoo even though it's a bit more complicated), python 2.7 library is called libpython2.7.so and I had no debug library associated, so I made the following changes to Python.upp:
library(!DEBUG) python2.7;

library(DEBUG) python2.7;

Another question: is there a way to get the error message or stack trace when python fails? I get the -1 exit code when I write wrong code, but no more precised clue... Is it expected for now?



I also tested other packages, they look good and work nice. Here is another patch I made for PyShell:

Index: bazaar/PyShell/PyShell.h
===================================================================
--- bazaar/PyShell/PyShell.h	(revision 3320)
+++ bazaar/PyShell/PyShell.h	(working copy)
@@ -21,7 +21,7 @@
 		if(!t.IsOpen()) t.Run(THISBACK(Proc));
 	}
 	void Wait() { t.Wait(); }
-	bool IsRunning() const { return AtomicRead(a>0); }
+	bool IsRunning() const { return AtomicRead(a)>0; }
 
 	void Proc(); 


Not sure it's what you expect the function to be but at least it compiles.

Lionel
Re: STARTED: Python in bazaar [message #31861 is a reply to message #31856] Thu, 31 March 2011 12:06 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Thu, 31 March 2011 04:37


EDIT: can someone try to compile and use the PyConsoleCtrlTest in linux, optimal and debug? i have got no tux environment around now.. tried to compile it with TDMGCC both release and debug, both work..


I recommend VirtualBox. Recently I have releasing debian packages in i386 and amd64 variants, without rebooting or leaving windows Smile
Re: STARTED: Python in bazaar [message #31862 is a reply to message #31859] Thu, 31 March 2011 12:08 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
this is what i actually meant, sth like a plugin..

dont quite remember where it was in the forum, but the reason was that it is quite huge.. (70 mb download zip Smile

i think i'd go for python stuff on it as a frst helper only..
STL is indeed not so appealing here..
Re: STARTED: Python in bazaar [message #31863 is a reply to message #31862] Thu, 31 March 2011 12:10 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
thanks lionel, for the feedback, i'll check out some if the name python27 is only windows...

the change you made is a bugfix Smile thanks
Re: STARTED: Python in bazaar [message #31877 is a reply to message #31863] Mon, 04 April 2011 06:28 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
I posted my version of code to call Python from C++ and C++ from Python here.

Regards,
Novo
Re: STARTED: Python in bazaar [message #31878 is a reply to message #31877] Mon, 04 April 2011 09:35 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Factual: As this is unfinished packages, should not this be developed in 'sandbox' first?
Re: STARTED: Python in bazaar [message #31883 is a reply to message #31878] Mon, 04 April 2011 15:08 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
you're right..

will be movin things..
Re: STARTED: Python in bazaar [message #31887 is a reply to message #31878] Mon, 04 April 2011 19:07 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
mirek wrote on Mon, 04 April 2011 09:35

Factual: As this is unfinished packages, should not this be developed in 'sandbox' first?

Perhaps my question would be more appropriate in the "Newbie corner" but how in theIde do you pull something up that is in "bazaar" or "sandbox"?? A few times I just copied from bazaar into MyApps.

This apparently is for Python2.7. I have switched as many have to 3.x (except what is included and used in FWTools2.7).

PyConsole should work as well in Linux (Ubuntu) as well as Win, I just use what comes with Ubuntu as have not switched to 3.x there.
Will try it when I get an understanding of how it works.

Neil
Re: STARTED: Python in bazaar [message #31889 is a reply to message #31887] Mon, 04 April 2011 20:12 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
you will need to use the bazaar or sandbox assembly (which is like a group of packages).

when opening ide, double klick on MyApps (your own assembly, and you will see in the first line the assemblys that it depends on/draws things from. just add the path to the desired other assembly and there you go.
Re: STARTED: Python in bazaar [message #31890 is a reply to message #31889] Mon, 04 April 2011 21:11 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
I added to the line to include bazaar
"C:\MyApps;C:\upp\uppsrc;C:\upp\bazaar"

I still do not have the bazaar listing, just the original with Upp3321:
examples
MyApps
reference
tutorial
uppsrc

edit: Right click in that column -> New assembly
Package nests: C:\upp\bazaar;C:\upp\uppsrc
Assembly name: bazaar

This works.
Thanks kohait00

Neil

[Updated on: Mon, 04 April 2011 21:29]

Report message to a moderator

Re: STARTED: Python in bazaar [message #31891 is a reply to message #31890] Mon, 04 April 2011 21:35 Go to previous messageGo to next message
chickenk is currently offline  chickenk
Messages: 169
Registered: May 2007
Location: Grenoble, France
Experienced Member
The order is important. On the package selection window, right-click on the left-side part (list of assemblies) and select New assembly so that you isolate bazaar and MyApps as 2 different assemblies. Then you must enter:

"C:\upp\bazaar;C:\upp\uppsrc"

The line you entered for the MyApps assembly is interesting though, because it allows you to reference bazaar packages in your MyApps assembly packages. But to open the main packages of a folder, this one must be entered as the first folder of a given assembly.

You should then have at least the assemblies uppsrc, bazaar and MyApps (and probably others).

Lionel
Re: STARTED: Python in bazaar [message #31907 is a reply to message #31891] Tue, 05 April 2011 21:48 Go to previous messageGo to previous message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Lionel

My first try with "C:\MyApps;C:\upp\uppsrc;C:\upp\bazaar" was not correct. My second try and edit to the post worked, I just didn't mention that ";C:\upp\bazaar" was removed from MyApps.

Neil
Previous Topic: UppGL
Next Topic: Get MAC addresses for windows and linux
Goto Forum:
  


Current Time: Thu Apr 18 05:43:08 CEST 2024

Total time taken to generate the page: 0.03139 seconds