Re: [PyKDE] Any tools to generate sip files?

2003-03-14 Thread Vio
Frederick Polgardy Jr wrote:

It sounds wonderful in theory, but it's completely impractical in reality.  
It's fairly easy to convert basic language constructs (if/else, while, 
switch, function decls, class decls, etc.), but just about anything else is 
going to involve classes and functions in other libraries, which involves 
either A) too much knowlege on the part of the translator of how other 
libraries are implemented, or B) copious amounts of translation rules and 
supporting modules.

True, translating basic cpp constructs to python is pretty trivial (with 
appropriate scanner). But on your A and B points, at this moment I would 
have to say: not necessarily. You are only partially right, and some 
manual code massaging is to be expected (unfortunately). But at the end 
of the day, that's the task at hand, so you have to do what you have to 
do, no matter how painful, right?

Cheers,
Vio
___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde


Re: [PyKDE] Any tools to generate sip files?

2003-03-14 Thread Jim Bublitz
On 14-Mar-03 Frederick Polgardy Jr wrote:
> Well, whereas SIP looks at SIP files (a stone's throw from the
> C++ header file) and generates C++ bindings, I could imagine it
> wouldn't be *extremely* painful to write a utility like SIP to
> generate Boost code from the headers, or a slightly modified
> version thereof, instead. Not saying  I'm going to write it
> myself :), but the point was only that the limitation 
> doesn't lie with Boost itself.

Not having looked at Boost lately I'm not sure how difficult it
would be, but it's probably doable. I guess my point was that sip
already does this and Boost doesn't.
 
> The bigger issue re: Qt/KDE is that I have no idea how you'd
> handle the signal/slot mechanism without having preknowledge
> about it, like SIP does.

Again I'm not familiar enough with Boost to be certain, but it
seems that Boost sits "on top of" the C++ code while sip calls into
the C++ code - so, for example, Boost can handle templates more
easily than sip can. Signal/slot handling might be easier too since
at the C++ level Qt already knows how to do it - it might be just
another method call to Boost.

It seems to me the biggest difference though is that sip by design
handles a comprehensive set of bindings over a number of versions
very well, while Boost is designed more to add a Python feature to
your C++ code. sip excels at PyQt and PyKDE, but for a lot of
applications sip is overkill and Boost is probably more suitable.

Jim

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde


Re: [PyKDE] Any tools to generate sip files?

2003-03-14 Thread Frederick Polgardy Jr
It sounds wonderful in theory, but it's completely impractical in reality.  
It's fairly easy to convert basic language constructs (if/else, while, 
switch, function decls, class decls, etc.), but just about anything else is 
going to involve classes and functions in other libraries, which involves 
either A) too much knowlege on the part of the translator of how other 
libraries are implemented, or B) copious amounts of translation rules and 
supporting modules.

Fred

On Thursday 13 March 2003 07:24 pm, you wrote:
> Jim Bublitz wrote:
> >I took him to mean he wanted to translate (line for line) C++ into
> >python, for example:
> >
> >if (something)
> >{
> >   x = 1
> >   y = 2
> >}
> >
> >to
> >
> >if something:
> >x = 1
> >y = 2
>
> Exactly. Well, for the time being, writing such a scanner isn't "too"
> painful, at least with the tool I'm using right now (Plex1.1.4), only,
> of course, if somebody already handled this problem before me somehow, I
> would hate to re-invent the wheel once again :)

-- 
F R E D E R I C K   P O L G A R D Y   J R.
Bodacion Technologies
18-3 E Dundee Road - Suite 300 - Barrington, IL 60010
Phone: 847/842.9008 - Fax: 847/842-1731
Web: http://www.bodacion.com

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde


Re: [PyKDE] Any tools to generate sip files?

2003-03-14 Thread Frederick Polgardy Jr
Well, whereas SIP looks at SIP files (a stone's throw from the C++ header 
file) and generates C++ bindings, I could imagine it wouldn't be 
*extremely* painful to write a utility like SIP to generate Boost code from 
the headers, or a slightly modified version thereof, instead.  Not saying 
I'm going to write it myself :), but the point was only that the limitation 
doesn't lie with Boost itself.

The bigger issue re: Qt/KDE is that I have no idea how you'd handle the 
signal/slot mechanism without having preknowledge about it, like SIP does.

Fred

On Thursday 13 March 2003 10:00 pm, Jim Bublitz wrote:
> I've looked at it (and argued with David Abrams on comp.lang.python
> a little) but never tried it. Boost has some advantages over sip,
> especially if you only want to bind a few functions, have a lot of
> templates, or like writing C++. The drawbacks (in the context of
> of a large project like PyKDE anyway) is that it requires a lot of
> handwritten code, more knowledge of what the code actually does,
> looks difficult to automate, and would be difficult to maintain over
> a number of versions (right now PyQt supports everything from Qt1.42
> onward, and PyKDE supports KDE 2.1.1 onward, each with a single
> file set). Can't say as far as performance, but it seems like Boost
> should be pretty fast and perhaps a little smaller in binary size.

-- 
F R E D E R I C K   P O L G A R D Y   J R.
Bodacion Technologies
18-3 E Dundee Road - Suite 300 - Barrington, IL 60010
Phone: 847/842.9008 - Fax: 847/842-1731
Web: http://www.bodacion.com

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde


Re: [PyKDE] Any tools to generate sip files?

2003-03-13 Thread Vio
Jim Bublitz wrote:

On 14-Mar-03 Frederick Polgardy Jr wrote:
 

Well that's essentially what SIP is, although it's more than just
cpp->pyqt/kde, it's cpp->python in general.
   

I took him to mean he wanted to translate (line for line) C++ into
python, for example:
if (something)
{
  x = 1
  y = 2
}
to

if something:
   x = 1
   y = 2
Exactly. Well, for the time being, writing such a scanner isn't "too" 
painful, at least with the tool I'm using right now (Plex1.1.4), only, 
of course, if somebody already handled this problem before me somehow, I 
would hate to re-invent the wheel once again :)

Cheers,
Vio
___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde


Re: [PyKDE] Any tools to generate sip files?

2003-03-13 Thread Vio
Thanks for the Boost tip. Am looking into it as I write this.

Ok, perhaps I should have been more specific, more like: anyone aware of 
a tool for converting cpp 'source code' to python (or pyqt or pykde) 
'source code', the tool itself ideally written in python (though not 
necessarily, of course).
Sorry for being so python-biased :)

Vio



Frederick Polgardy Jr wrote:

Well that's essentially what SIP is, although it's more than just 
cpp->pyqt/kde, it's cpp->python in general.

Along the same lines, has anybody checked out Boost.Python by any chance?  
It's pretty awesome.  The folks at Boost are insane.

http://www.boost.org/libs/python/doc/index.html

Fred

On Thursday 13 March 2003 15:16, Vio wrote:
 

 On conversion tools topic, I am also writing a tool to convert more
broadly cpp -> pyqt/pykde (don't ask me why I need that :). Reading your
post, the thought occured that I may be reinventing the wheel right now.
Hence, anybody aware if such a cpp2py tool already exists?
Secondly, I'd also like to have a look at your 'h2sip' tool, if posible.

Cheers,
Vio
   

 



___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde


Re: [PyKDE] Any tools to generate sip files?

2003-03-13 Thread Jim Bublitz
On 14-Mar-03 Frederick Polgardy Jr wrote:
> Well that's essentially what SIP is, although it's more than just
> cpp->pyqt/kde, it's cpp->python in general.

I took him to mean he wanted to translate (line for line) C++ into
python, for example:

if (something)
{
   x = 1
   y = 2
}

to

if something:
x = 1
y = 2

which is not what sip does. Sip provides an interface to C++ libs
on the binary level - it has no idea what's in the cpp code, but
only knows what the call/return interface to the code is (hence sip
only needs to look at the h files, not the cpp files - mostly). The
bindings sip produces are in C++, not Python.
 
> Along the same lines, has anybody checked out Boost.Python by any
> chance?  It's pretty awesome.  The folks at Boost are insane.
 
> http://www.boost.org/libs/python/doc/index.html

I've looked at it (and argued with David Abrams on comp.lang.python
a little) but never tried it. Boost has some advantages over sip,
especially if you only want to bind a few functions, have a lot of
templates, or like writing C++. The drawbacks (in the context of
of a large project like PyKDE anyway) is that it requires a lot of
handwritten code, more knowledge of what the code actually does,
looks difficult to automate, and would be difficult to maintain over
a number of versions (right now PyQt supports everything from Qt1.42
onward, and PyKDE supports KDE 2.1.1 onward, each with a single
file set). Can't say as far as performance, but it seems like Boost
should be pretty fast and perhaps a little smaller in binary size.


Jim

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde


Re: [PyKDE] Any tools to generate sip files?

2003-03-13 Thread Frederick Polgardy Jr
Well that's essentially what SIP is, although it's more than just 
cpp->pyqt/kde, it's cpp->python in general.

Along the same lines, has anybody checked out Boost.Python by any chance?  
It's pretty awesome.  The folks at Boost are insane.

http://www.boost.org/libs/python/doc/index.html

Fred

On Thursday 13 March 2003 15:16, Vio wrote:
>   On conversion tools topic, I am also writing a tool to convert more
> broadly cpp -> pyqt/pykde (don't ask me why I need that :). Reading your
> post, the thought occured that I may be reinventing the wheel right now.
> Hence, anybody aware if such a cpp2py tool already exists?
>
> Secondly, I'd also like to have a look at your 'h2sip' tool, if posible.
>
> Cheers,
> Vio

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde


Re: [PyKDE] Any tools to generate sip files?

2003-03-13 Thread Jim Bublitz
On 13-Mar-03 Vio wrote:
> On conversion tools topic, I am also writing a tool to convert
> more broadly cpp -> pyqt/pykde (don't ask me why I need that :).
> Reading your post, the thought occured that I may be
> reinventing the wheel right now. Hence, anybody aware if such a
> cpp2py tool already exists?

I haven't ever looked for one - not aware of any.
 
> Secondly, I'd also like to have a look at your 'h2sip' tool, if
> posible.

Sure. I'll package up a tarball (and try to remember to put
switches around the KDE specific stuff) and write up a brief
README. I'll try to get to it this weekend.

It uses a handwritten predictive parser, and the tokenizer is
subclassed from the Python Tokenizer module. I've found it pretty
easy to extend/modify, but then again it's my code - YMMV. It might
be possible to extend it to cpp, but the stuff that handles
expressions and preprocessor stuff is really crappy at the moment
(don't need much of that for PyKDE h files fortunately). 

The way it stores data would be a nightmare for translating code
(you can't really look up a symbol in the symbol table very easily,
for example, unless you already know its scope, version, signature,
etc). However, that stuff is pretty well decoupled from the parser
and could be replaced without a lot of trouble. Without giving it a
lot of thought, I'd look at outputting some intermediate code (like
XML) and then working from that.

The tarball will probably run about 130K after endoding for email.
If you can't handle an attachment that size, let me know. Otherwise
I'll send you a copy in a few days.

If anyone else is curious, let me know. This isn't high quality
software at the moment.

Jim

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde


Re: [PyKDE] Any tools to generate sip files?

2003-03-13 Thread Vio
 On conversion tools topic, I am also writing a tool to convert more 
broadly cpp -> pyqt/pykde (don't ask me why I need that :). Reading your 
post, the thought occured that I may be reinventing the wheel right now. 
Hence, anybody aware if such a cpp2py tool already exists?

Secondly, I'd also like to have a look at your 'h2sip' tool, if posible.

Cheers,
Vio
Jim Bublitz wrote:

On 13-Mar-03 Hubbard, Dwight wrote:
 

I've been looking at trying to generate python bindings for the
libmyth
library which is part of the mythtv pvr project (
http://www.mythtv.org)
   

 
 

I was wondering if there where any tools to automate the
generation of the .sip files from the .h files instead of doing
it manually?
   

Almost.

I have a tool in development that does automatic h->sip conversion,
as well has generating the build scripts and writing some of the
docs. I'm using it to generate the next PyKDE version and it's
essentially complete enough to do that (ignoring the occasional bug
that still pops up now and then). I haven't tried it on anything
except PyKDE, so I'm sure there'll be problems with it, particularly
in generating the build stuff.
I took a quick look at the libmyth sources and only see one problem
- one of the h files has a "using" statement, which is one of the
few things I'm not planning on supporting. You'd have to add
explicit scoping manually to the variables covered by that
statement. I didn't see any place where you'd need to hand write
any C++ code for sip, but I only took a quick look. I also didn't
check to see what beyond the libmyth h files you'd need sip files
for. If libmyth references objects in other libs, you'd need to
bind those too or else hide the references somehow (Qt isn't a
problem however).
The other nice feature of this tool and sip is that they handle
versioning - you can build a new set of sip files from the previous
version's sip files and the new h files. It looks like this project
will be changing fairly rapidly at the moment.
If you have a strong urge to be a guinea pig for undocumented and
probably somewhat buggy incomplete software, I can send you a
tarball (it's all in Python). Basically all you should need to do is
create a project file (assuming it works). You'd also need Python
2.2.2, sip 3.5 and PyQt 3.5 (since libmyth is Qt based). This is
far from releaseable, but works pretty well. If it works, you'd
have sip files in about 20 seconds (all of PyKDE takes about 3 1/2
minutes). There's a strong chance this will be completely useless
to you.
Otherwise, I can take a look at it myself when I get some time.

Jim

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde
 



___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde


RE: [PyKDE] Any tools to generate sip files?

2003-03-13 Thread Jim Bublitz
I took a second very quick look at the libmyth sources, and there's
good news and bad news: the good news is the "using" statement is
for 'std' (always make me think of "sexually transmitted disease"),
so you won't have to do any explicit scoping. The bad new is that
you'll have to hand write mapped type code for all instances of
templates from std (but only if they're public or protected - you
can ignore all of the private stuff). It's not that hard to do
though, and instead of vector<> you'll get a Python list in the
bindings.

Jim

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde


RE: [PyKDE] Any tools to generate sip files?

2003-03-13 Thread Jim Bublitz
On 13-Mar-03 Hubbard, Dwight wrote:
> I've been looking at trying to generate python bindings for the
> libmyth
> library which is part of the mythtv pvr project (
> http://www.mythtv.org)
  
> I was wondering if there where any tools to automate the
> generation of the .sip files from the .h files instead of doing
> it manually?

Almost.

I have a tool in development that does automatic h->sip conversion,
as well has generating the build scripts and writing some of the
docs. I'm using it to generate the next PyKDE version and it's
essentially complete enough to do that (ignoring the occasional bug
that still pops up now and then). I haven't tried it on anything
except PyKDE, so I'm sure there'll be problems with it, particularly
in generating the build stuff.

I took a quick look at the libmyth sources and only see one problem
- one of the h files has a "using" statement, which is one of the
few things I'm not planning on supporting. You'd have to add
explicit scoping manually to the variables covered by that
statement. I didn't see any place where you'd need to hand write
any C++ code for sip, but I only took a quick look. I also didn't
check to see what beyond the libmyth h files you'd need sip files
for. If libmyth references objects in other libs, you'd need to
bind those too or else hide the references somehow (Qt isn't a
problem however).

The other nice feature of this tool and sip is that they handle
versioning - you can build a new set of sip files from the previous
version's sip files and the new h files. It looks like this project
will be changing fairly rapidly at the moment.

If you have a strong urge to be a guinea pig for undocumented and
probably somewhat buggy incomplete software, I can send you a
tarball (it's all in Python). Basically all you should need to do is
create a project file (assuming it works). You'd also need Python
2.2.2, sip 3.5 and PyQt 3.5 (since libmyth is Qt based). This is
far from releaseable, but works pretty well. If it works, you'd
have sip files in about 20 seconds (all of PyKDE takes about 3 1/2
minutes). There's a strong chance this will be completely useless
to you.

Otherwise, I can take a look at it myself when I get some time.

Jim

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde