Feature: Python Console

15 views
Skip to first unread message

jon...@gmail.com

unread,
Apr 25, 2009, 4:01:19 AM4/25/09
to HeeksCAD - Developers Mailing List
Any thoughts on an integrated python console? Perhaps for
creating objects and such. I'd really like to be able to type in

for i in range(10):
for j in range(10):
circle(i*10,j*10,5)


Object creation seems pretty strait forward. Even boolean
operations. But what about modifying existing geometry?

dan falck

unread,
Apr 25, 2009, 10:02:00 AM4/25/09
to HeeksCAD - Developers Mailing List
I'm all for that one. Automating the design and CAM stages would be
spectacular.

Dan Falck

Dan Heeks

unread,
Apr 25, 2009, 12:29:01 PM4/25/09
to HeeksCAD - Developers Mailing List
It would be nice, I guess, so long as it's optional.
Maybe the "Make Python script" button in HeeksCNC would write to this,
instead of it's "Program" window ( which is simply a text control for
python script ).
Currently HeeksCNC doesn't have python integrated, either, it just
writes a file and then executes python giving it the file name.

jon...@gmail.com

unread,
Apr 26, 2009, 2:42:05 PM4/26/09
to HeeksCAD - Developers Mailing List
Yes it would definitely be optional. Now i'm just wondering how to do
it. Freecad has a python console so it can't be impossible.

jon...@gmail.com

unread,
Apr 27, 2009, 4:29:46 PM4/27/09
to HeeksCAD - Developers Mailing List
I did some work on this. The closest thing I could find to code
for a python console/terminal emulator for wxwidgets, is the code for
PyShell in wxpython. At first I figured, how great, since I have to
interface with python anyways, I can just do it earlier and instatiate
the wxpython module from c++ and be done. Good news is that seems like
it works. Bad news is that I can't get it to compile.
The trick is that HeeksCAD and wxPython need to use the same dll's
of wxWidgets. Compiling wxWidgets is something everyone is familiar
with, but wxPython is a pain. There are all these improperly
documented scripts. Most of which don't work right anyways. Like if I
change a compilation option. Clean doesn't work and instead I have to
delete the entire tree and restart. If you use debug libraries from
wxWidgets, it tries to spit out debug python code which can only be
run by a debug version of python.
After this and that, I got something built. But I can't run it,
presumably because of a runtime conflict. I'm guessing I need to
rebuild python itself with vs9 or it just isn't going to work.
All of these problems should not exist under linux as everything
tends to use the same libraries anyways. But I have no idea how anyone
would ever manage to build this under windows. Maybe one of those ugly
scripts that takes 10 hours to download everything under the sun and
compile it for you?

jon...@gmail.com

unread,
Apr 27, 2009, 9:58:44 PM4/27/09
to HeeksCAD - Developers Mailing List

I finally got the console running. The build process is still out
of control. I figure that should be forked to a new topic on how to
manage dependencies under windows. Now I want to expose heekscad to
python. I figure a wrapper around HeeksInterface is the way to go. I
don't know much about writing python wrappers, so any help/advice
would be welcome.

Dan Heeks

unread,
Apr 28, 2009, 4:09:39 AM4/28/09
to HeeksCAD - Developers Mailing List
I have written simple Python wrappers in the libarea project, but I am
no expert on it. I just cast my CArea objects to integers so I don't
have to worry about Python classes.

jon...@gmail.com

unread,
Apr 28, 2009, 11:35:43 PM4/28/09
to HeeksCAD - Developers Mailing List
On Apr 26, 11:42 am, jon...@gmail.com wrote:
> Yes it would definitely be optional.

I finally got it making lines and circles in heekscad. After messing
with different ways of doing it. It ended up just being a plugin. I
need to refactor the code to get the stuff for the window out of
heekscad itself. Maybe there should be another project. HeeksPython?
It will still have the requirement of special care with the
dependencies, but at least HeeksCAD itself won't be broken while
people fix there deps.

Try to limit the drool
http://prymfg.com/screenshots/screen.jpg

jon...@gmail.com

unread,
Apr 29, 2009, 11:19:24 PM4/29/09
to HeeksCAD - Developers Mailing List
I posted the code at code.google.com/p/heekspython As previously
mentioned, building is not for the faint of heart.

Dan Heeks

unread,
Apr 30, 2009, 9:42:15 AM4/30/09
to HeeksCAD - Developers Mailing List
I have built this now. This is a most excellent concept. A plugin for
HeeksCAD makes it optional and keeps the messy code away from the
HeeksCAD project.
I have changed the project files, so that HeeksPython has Debug,
Release, Unicode Debug and Unicode Release configurations, like
HeeksCAD.
I have only been able to get the Unicode configurations to run,
though.

I get a console window, but unfortunately it is gray and I can't type
into it.
I wonder what is wrong?

Dan Heeks

unread,
Apr 30, 2009, 12:30:58 PM4/30/09
to HeeksCAD - Developers Mailing List
jonpry,

The problem was "The wx.App object must be created first!"

I have it working now. by adding
app = wx.App()\n\
in the python_code2 string

see my blog entry
http://heekscnc.blogspot.com/2009/04/heekspython.html

Thank you very much.

Dan.

jon...@gmail.com

unread,
Apr 30, 2009, 7:44:18 PM4/30/09
to HeeksCAD - Developers Mailing List
Thats great that you got it working. I wasn't sure that anyone ever
would. It is weird that you get that error. My guess is that wxPython
is using a different wxWidgets dll than heekscad. According to the
docs that shouldn't work, but I guess you got it to. You can confirm
this by starting the debugger and looking at the output. It lists each
dll as it is loaded. wxbase* and such should only happen once.

jon...@gmail.com

unread,
May 3, 2009, 3:24:28 AM5/3/09
to HeeksCAD - Developers Mailing List
Nice job on the blog! When i checked out the latest version of
heekspython, i couldn't get it to work. Crashes all over the place. I
really need to work on this dependency repository thing. Anyways, on a
philosophical note. I don't like this #undef _DEBUG stuff. For various
reasons, it isn't possible to build a debug wxpython without using a
debug python. And you can't build a release wxpython with a debug
wxwidgets. I think debug everything is really useful and there should
be a reasonable way for developers to take advantage.

I've made some changes to the codebase and am tempted to check it all
in. Erasing the #undef _DEBUG, but I wanted to see what other people
thought first.

Here's a little outline of how i got it to build what i think is the
right way. I'll get this on the wiki soon.

Download python source to your hard disk. I got version 2.6.2?

Open the visual studio solution file in pythondir\PCBuild and let it
do its conversion.

Select configuration debug and hit build. This will run for a while,
and then will complain about ~7 build failures, don't worry about
these.
Select configuration release and hit build as well.

Download wxpython sources to your hard disk and unpack
This one is tricky because if you mess anything up, you'll have to
delete the entire tree, unpack and start over

rename the file in wxpythondir\include\wx\msw\setup0.h to setup.h

edit this file and change the following lines

wxUSE_GRAPHICS_CONTEXT 1
wxUSE_GLCANVAS 1
wxUSE_POSTSCRIPT 1
wxUSE_DATEPICKCTRL_GENERIC 1

open up your visual studio command prompt and cd to

wxpythondir\build\msw

then type

nmake -f makefile.vc SHARED=1 MONOLITHIC=0 USE_OPENGL=1 USE_GDIPLUS=1
UNICODE=1 BUILD=debug

this will run for a while and hopefully not say anything bad

then cd to wxpythondir\contrib\build\stc

nmake -f makefile.vc SHARED=1 MONOLITHIC=0 USE_OPENGL=1 USE_GDIPLUS=1
UNICODE=1 BUILD=debug


then cd to wxpythondir\contrib\build\gizmos and issue a

nmake -f makefile.vc SHARED=1 MONOLITHIC=0 USE_OPENGL=1 USE_GDIPLUS=1
UNICODE=1 BUILD=debug



then cd to
wxdir\wxpython

and type

pythondir\PCBuild\python_d.exe setup.py build_ext --inplace
MONOLITHIC=0 --debug


then all should be well. the original visual studio project at least
describes what relative directories you need to use for linking and
including. The dll's must get copied to the heekscad directory.
Heekscad then needs to be changed to link against the wxwidgets libs
produced through this process. It is important to note that wxpython
source includes the wxwidgets source and this process builds them
both. You can't use different build of wxwidgets in different parts of
the program.

Perttu Ahola

unread,
May 3, 2009, 4:59:26 AM5/3/09
to heeksca...@googlegroups.com
I have tried to build this now on Linux.

Here is the makefile I made:
http://sooda.dy.fi/paste/?r6b&plainpaste

It is mostly copied from HeeksCNC and libactp.

You also need to change
#define HEEKSCNC_EXPORT
to
#define HEEKSPYTHON_EXPORT
in src/Interface.h

It builds, but when i add it to HeeksCAD and restart HeeksCAD, i get a message
window labeled "HeeksCAD Error" saying "***** Error importing the wxPython
API! *****".

This is printed on the terminal:
------------------
[pera@humppa HeeksCAD]$ ./HeeksCAD
Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/__init__.py",
line 45, in <module>
from wx._core import *
File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/_core.py",
line 4, in <module>
import _core_
ImportError: /usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/_core_.so:
undefined symbol: PyObject_GenericGetAttr
[pera@humppa HeeksCAD]$
------------------

Jon Pry

unread,
May 3, 2009, 8:51:22 PM5/3/09
to heeksca...@googlegroups.com
That looks pretty good. I'll see if I can find anything as soon as I get back to a linux box. Its been suggested that adding something like

-Xlinker -export-dynamic

to the linker command might do it

Perttu Ahola

unread,
May 4, 2009, 5:31:06 AM5/4/09
to heeksca...@googlegroups.com
I have tried -Xlinker -export-dynamic. Seems to do nothing.

Dan Heeks

unread,
May 5, 2009, 3:25:57 AM5/5/09
to HeeksCAD - Developers Mailing List
I made a Linux build too and I got the same problem "undefined symbol:
PyObject_GenericGetAttr"
I did a search and found this http://bugs.python.org/issue4434
It suggests "-Xlinker -export-dynamic", but that did nothing for me.

It also suggests ( in the second message ) linking against the static
library libpython.a, but I can't find this file on my computer.

Jon Pry

unread,
May 7, 2009, 12:35:12 PM5/7/09
to heeksca...@googlegroups.com
are you linking with -lpython?  this sounds promising to me. i use something like this in a linux project once.

dlopen("libpython2.5.so", RTLD_LAZY |
RTLD_GLOBAL);

linking heekscad itself with python may be the easiest thing to do. the linux dynamic loader is finicky about stuff(aka i don't know how to use it)

Perttu Ahola

unread,
May 7, 2009, 1:41:13 PM5/7/09
to heeksca...@googlegroups.com
I got heekspython to work by adding `python-config --libs` to heekscad's
makefile's linker line, and by using this makefile for heekspython:
http://sooda.dy.fi/paste/?oPF&plainpaste

Somebody add me (cele...@gmail.com) to the heekspython project?

----- Original Message -----
From: Jon Pry <jon...@gmail.com>
To: heeksca...@googlegroups.com
Sent: Thursday 07 May 2009 19:35:12
Subject: Re: Feature: Python Console

Perttu Ahola

unread,
May 7, 2009, 2:01:28 PM5/7/09
to heeksca...@googlegroups.com
Actually, I only got it to show the python interpreter window in HeeksCAD. You
have to change the two instances of heekspython.so in the makefile to
HeeksPython.so, and also add it to the python module search path (for
example, export PYTHONPATH="whatever/HeeksPython" before running HeeksCAD)
for importing it.

Dan Heeks

unread,
May 7, 2009, 2:04:49 PM5/7/09
to heeksca...@googlegroups.com
you are a member of heekspython project


Reply all
Reply to author
Forward
0 new messages