U++ framework
Do not panic. Ask here before giving up.

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: 1431
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: 14290
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: 14290
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: 14290
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: 171
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: 14290
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: 1431
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: 14290
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: 171
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 next 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
Re: STARTED: Python in bazaar [message #31958 is a reply to message #31907] Mon, 11 April 2011 14:56 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
so now there is even a boost python example in bazaar (BoostPyTest). it also contains how to setup boost for the ide.


still need to figure out how it properly works with boost python and exposure/extending/embedding. but so far there is a compileable environment to test things on..
enjoy.
any help / hints are pretty welcome, since even though there is some amount of information on boost python, there are few quality code examples, like the proper syntaxes of the macros and class_<> definitions..etc.

[Updated on: Mon, 11 April 2011 14:57]

Report message to a moderator

Re: STARTED: Python in bazaar [message #31971 is a reply to message #31958] Tue, 12 April 2011 23:57 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
proper exit() handling is supported now, after digging the python source code it's quite simple.

i'm still struggeling for an idea how to properly expose Value to object (boost.python).

anyone's got some experience in boost python and firm in Upp to provide a hint?

problem is, that both, Value and object are actually ref count containers for data.. and, both, upp (c++) side can own the data, and the Python interpreter / GC can own data (through Py_Object, wrapped by boost object). now how to properly manage that? i obviously cant expose the Value itself to object as data. i need to expose the Value's data as object's data..taking ref count in account.

or maybe not expose it at all but provide converter functions for both sides..that'd so far be the most clean way. but this would make any exposure of Upp api calls with Value as argument or return type impossible and would need to have some wrapper functions doing the conversion before and after python invokation.

ideas really welcome..
Python in bazaar growing [message #32415 is a reply to message #31971] Tue, 17 May 2011 09:33 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
hi people

python package and export of upp is growing and doing well so far. it's still very alpha but it's working great thanks to boost.python facilities.

want to encourage to take a look on it and give some feedback. see bazaar/BoostPyTest, and Py/install.txt.

index.php?t=getfile&id=3247&private=0
  • Attachment: boostpy.GIF
    (Size: 23.50KB, Downloaded 845 times)
Re: Python in bazaar growing [message #32416 is a reply to message #32415] Tue, 17 May 2011 10:47 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Looks good.

I couldn't find the Py/install.txt.
I have Python 3.2 r32:88445 installed.

When trying to run from theIDE I get this error massage.
c:\myapps\boostpytest\world.h(4) : fatal error C1083: Cannot open include file: 'Py/Py.h': No such fi
	le or directory
c:\myapps\boostpytest\BoostPyTest.h(4) : fatal error C1083: Cannot open include file: 'PyConsoleCtrl/
	PyConsoleCtrl.h': No such file or directory


When using some Python code when it is compiled is it ahead of time compiled or is it wrapped in the .exe and still runtime compiled?

Neil

[Updated on: Tue, 17 May 2011 13:25]

Report message to a moderator

Re: Python in bazaar growing [message #32418 is a reply to message #32416] Tue, 17 May 2011 11:18 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
no it's all runtime.. it does not precompile anything (well maybe internally in python environment, but this does not affect the upp runtime. what you see is really the content of a DocEdit which is passed to python as is..

using / importing other .py files laying next to the app .exe would be cache-compiled, you will find a .pyc file named after your py file after usage..

i will add an usage example for that too.
Re: Python in bazaar growing [message #32420 is a reply to message #32418] Tue, 17 May 2011 12:00 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Maybe py2exe could be tied in.

The license is open MIT and only when modified py2exe code is distributed does the GPL kick in.
http://stackoverflow.com/questions/599066/py2exe-page-says-i t-is-licensed-under-gpl-can-i-still-use-it-in-a-python-proje ct
and
http://www.py2exe.org/LICENSE.txt

Even then
Quote:

- your code is never converted to machine code - it's still an interpreted language.


But maybe that wouldn't fit with Upp's cross platform concept because that is for the Win OS.

I manually ported a considerable amount of my Python and Java code to C++ (except the GUI stuff) so it would be AOT compiled (and harder to decompile) but there would be cases especially for proof of concept where running the Python code in a Upp app would save a lot of time.

[Updated on: Tue, 17 May 2011 12:38]

Report message to a moderator

Re: Python in bazaar growing [message #32422 is a reply to message #32420] Tue, 17 May 2011 13:35 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
Quote:


running the Python code in a Upp app would save a lot of time


well thats exactly the point of embedding python. in this case, in an upp application.

to have a scripting support at hand when needed is a huge advantage, especially when debugging. and also, when defining gui layout, this could be worth using.

i actually see py2exe in a different use case, where one only has got a py script, and wants to be independant from py installation.

but the currently addressed use case deals with interoperability of U++ and python, where precompilation does not make sense. that for the case where the user wants to have the possibility to run some sort of own task inside the prepared environment, let's say an automated test for a device..
Re: Python in bazaar growing [message #32426 is a reply to message #32422] Tue, 17 May 2011 14:32 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
have just included a py script invokation and upp acces froom a py script example
Re: Python in bazaar growing [message #32427 is a reply to message #32416] Tue, 17 May 2011 14:36 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
nlneilson wrote on Tue, 17 May 2011 10:47

Looks good.

I couldn't find the Py/install.txt.
I have Python 3.2 r32:88445 installed.

When trying to run from theIDE I get this error massage.
c:\myapps\boostpytest\world.h(4) : fatal error C1083: Cannot open include file: 'Py/Py.h': No such fi
	le or directory
c:\myapps\boostpytest\BoostPyTest.h(4) : fatal error C1083: Cannot open include file: 'PyConsoleCtrl/
	PyConsoleCtrl.h': No such file or directory




obviously there is something wrong with your upp installation. bazaar/Py/install.txt has to be there. please double check your installation. can you build any other bazaar application?
the instructions in install.txt should yield a working Py environment
Re: Python in bazaar growing [message #32439 is a reply to message #32427] Tue, 17 May 2011 21:27 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
kohait00 wrote on Tue, 17 May 2011 14:36

obviously there is something wrong with your upp installation.


Yes there was a problem and it relates to my post in this thread on April 4
Quote:

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.


I updated several times since then and had moved the Py stuff from bazaar into MyApps.

I just now updated to Upp 3427 and Py/install.txt is in bazaar.
Re: Python in bazaar growing [message #32447 is a reply to message #32439] Wed, 18 May 2011 11:44 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
have you succeeded to run it?
Re: Python in bazaar growing [message #32448 is a reply to message #32447] Wed, 18 May 2011 12:10 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Not yet.

I have Python 3.2 and your app uses 2.7

I just updated to Ubuntu 11.04 that runs dual boot with Win.
The default is Python 2.7 on that OS, will try it there later.

[Updated on: Wed, 18 May 2011 12:16]

Report message to a moderator

Re: Python in bazaar growing [message #32513 is a reply to message #32448] Mon, 23 May 2011 13:38 Go to previous message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
could anyone commit this please?

CtrlCore.h
@@ -1157,6 +1157,7 @@ public:
 
 	Ctrl&   IgnoreMouse(bool b = true)                   { ignoremouse = b; return *this; }
 	Ctrl&   NoIgnoreMouse()                              { return IgnoreMouse(false); }
+	bool    IsIgnoreMouse() const                        { return ignoremouse; }
 	bool    HasMouse() const;
 	bool    HasMouseDeep() const;
 	bool    HasMouseInFrame(const Rect& r) const;
Previous Topic: UppGL
Next Topic: Get MAC addresses for windows and linux
Goto Forum:
  


Current Time: Tue Apr 28 03:23:54 GMT+2 2026

Total time taken to generate the page: 0.01584 seconds