tag:blogger.com,1999:blog-16938318648323873402024-03-13T16:50:26.745+01:00SPE IDE - Stani's Python EditorFree python IDE for Windows,Mac & Linux with UML,PyChecker,Debugger,GUI design,Blender & moreStanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.comBlogger26125tag:blogger.com,1999:blog-1693831864832387340.post-11312999566781515692010-02-17T21:11:00.007+01:002010-02-17T22:22:34.421+01:00Why I am going to talk at Pycon ...I started to develop <a href="http://pythonide.stani.be">SPE</a> when I was still using Windows back in 2002. By using Python and wxPython, I hoped SPE would run smoothly on all platforms. That was wishful thinking. Luckily the community stepped in: Linux users started sending me patches and Mac users collected money to buy me a Mac Mini. Many years ago I go I switched to Ubuntu and at that moment I've felt the joy not having chosen a technology which locks you up in one platform.<br /><br />Later I started developing <a href="http://photobatch.stani.be">Phatch</a> (Photo Batch Processor) and used my experience of SPE to polish if for Linux, Mac OS X and Windows. I took care of distributing it well on Linux by getting it in the major repositories (Debian, Ubuntu, Fedora, Arch, Suse, ...). Unfortunately I lacked the time for proper distribution on Mac OS X and Windows. I am happy to announce that is going to change. <br /><br />Together with <a href="http://nadiana.com/">Nadia Alramli</a> (other Phatch developer) we've dived deeper in the subject of developing and distributing cross-platform applications. Our conclusion is that is it takes more time to research than to implement the code. Therefore we are eager to share our knowledge during our talk at Pycon to save you from hair-pulling behaviour. We have learnt that Python solves 90% of the cross-platform problems for you, but that the remaining 10% could be tricky. In our <a href="http://us.pycon.org/2010/conference/schedule/event/38/">talk</a> we will point the finger on several painful issues and offer solutions, hoping that they will save you time and frustration.<br /><br />We prepared the <a href="http://us.pycon.org/2010/conference/schedule/event/38/">talk</a> by writing a paper (outline <a href="http://us.pycon.org/media/2010/talkdata/PyCon2010/038/outline.html">here</a>), which is far more extensive than the 30 min of talk will allow us. We designed the talk to give you a good overview and to get you started. I have send the paper for review to some people I highly respect. These were some reactions:<br /><br /><ul><li><span style="font-style:italic;">"Great document, I learned new things from it!"</span> Piotr Ożarowski (Debian Python Application Package Team)</li><br /><li><span style="font-style:italic;">"It's a pity I can not attend PyCon. Anyway, the subjects you are describing in the paper are seldom analyzed in such depth, and I believe the whole community will benefit from your presentation. Most interesting of all, correctly packaging and distributing an app on multiple platforms can be a deep nightmare and what you have on your paper is a beautiful example of how to avoid the most hair-pulling mistakes in doing it."</span> Andrea Gavana (wxPython)</li></ul><br />We will use wxPython as an example GUI toolkit, but the principles are valid for other toolkits as well. Our target audience are programmers who have already some experience on one platform but are wondering how things could be implemented on other platforms. Making your application cross-platform is the most efficient way to scale your user base.<br /><br />Rather than making any bullet point slides, we did our best to make the slides visually entertaining. So even if our voices would suddenly mute, you have at least something nice to look at. As the author of SPE I made sure that all code slides have a pretty syntax highlight. Combining Pygments with Inkscape rocks!<br /><br />I hope to see you at our <a href="http://us.pycon.org/2010/conference/schedule/event/38/">talk</a> at Friday 02:55pm @ Centennial II !Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com7tag:blogger.com,1999:blog-1693831864832387340.post-83448080957824275392009-05-20T18:32:00.014+02:002009-05-20T20:18:38.168+02:00sK1 vector graphics editor is now available for Ubuntu<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://sk1project.org/themes/YelloWhite/banners/banner1_1.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 205px; height: 225px;" src="http://sk1project.org/themes/YelloWhite/banners/banner1_1.png" border="0" alt="" /></a><br />At the last <a href="http://www.libregraphicsmeeting.org/2009/">Libre Graphics Meeting</a> I met <a href="http://river-valley.tv/sk1-v09-ready-for-prepress/">Igor Novikov</a>, who is the lead developer of <a href="http://sk1project.org/">sK1</a>. sK1 is a vector graphics editor, just like <a href="http://www.inkscape.org/">Inkscape</a> but with a different focus. While Inkscape is oriented to the SVG format and is ideal for web design, sK1 targets professional designers from the prepress world. So sK1 supports CMYK, multiple pages and separating colour plates. To quote <a href="http://en.wikipedia.org/wiki/SK1_(program)">wikipedia</a>:<blockquote>sK1 is an open-source illustration program for the Linux platform that can substitute professional proprietary software like CorelDRAW or Adobe Illustrator. Unique project features are CorelDRAW formats importers, tabbed multidocument interface, Cairo-based engine, color management etc.</blockquote><br />The multipage feature is very handy for designing booklets with vector graphics or presentations, which you could project with <a href="http://impressive.sourceforge.net/">impressive</a> (former keyjnote). Under the hood Inkscape and sK1 share Uniconvertor, for importing, exporting and converting vector graphics. Uniconvertor was developed by the sK1 team. (sK1 is a fork of the Skencil project.) Another difference from Inkscape, is that sK1 itself is developed mostly in python. So you could in a way it use as a python library.<br /><br />sK1 is being developed under Mandriva and it is hard to install on Ubuntu (especially for graphic designers). I noticed that Vladimir Osintsev was <a href="https://bugs.launchpad.net/ubuntu/+bug/151102">preparing</a> a package for Ubuntu. I contacted him and invited him to <a href="http://svn.debian.org/wsvn/python-apps/packages/sk1/#_packages_sk1_">work together</a> on it within the <a href="http://wiki.debian.org/Teams/PythonAppsPackagingTeam">Debian Python Package Team</a>. So hopefully sK1 will become available in Debian and Ubuntu (from Karmic).<br /><br />As some of you can't wait and like to use sK1 with the current Ubuntu releases, I decided to add sK1 for Jaunty and Intrepid to my PPA:<blockquote>deb http://ppa.launchpad.net/stani/ppa/ubuntu jaunty main</blockquote><br />To add the key of my PPA to your system, type the following in a terminal (replace jaunty with your ubuntu version):<blockquote>sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 7B0FB2CA</blockquote><br />You can read my PPA page <a href="https://launchpad.net/~stani/+archive/ppa">https://launchpad.net/~stani/+archive/ppa</a> for more information.<br /><br />Disclaimer: this is the development version of sK1 and the packages have not been tested by a critical mass. In case you have problems, you should report them on the <a href="http://sk1project.org/forum/index.php">sK1 forums</a>. The packaging is not perfect yet. For example there will be no entry in the start menu. This will be fixed in a next release. I've sent Igor from sK1 the necessary files to resolve this issue. So for now start sK1 by typing "sk1" in the run dialog (Alt+F2) or in a terminal.<br /><br />As a final remark: you need to remove your <span style="font-weight:bold;">~/.sk1</span> folder, otherwise sK1 might have troubles starting up.Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com7tag:blogger.com,1999:blog-1693831864832387340.post-44960303210138069592009-04-06T18:09:00.011+02:002009-04-06T21:37:33.907+02:00DWG support for BlenderI'm working on AR, a python library for <a href="http://www.blender.org/">Blender</a>, which might be interesting for ARchitects. It targets primarily Blender python scripters, not Blender end users. However non pythoneers might be interested in the library as well, as some side products are end user friendly.<br /><br />One of the features I have been working on is DWG support for Blender. It uses the DXF scripts of Blender under the hood, so it is limited to their abilities. Probably export will work better than import.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_KhIIKmJ4wWc/Sdorr856E0I/AAAAAAAAAHM/LS1L3BYRUqA/s1600-h/dwg_export_menu.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 310px;" src="http://2.bp.blogspot.com/_KhIIKmJ4wWc/Sdorr856E0I/AAAAAAAAAHM/LS1L3BYRUqA/s400/dwg_export_menu.png" alt="" id="BLOGGER_PHOTO_ID_5321613943775040322" border="0" /></a><br>The supported DWG versions are: 9, 10, 12, 13, 14, 2000, 2004 and 2007. (It can also export to the equivalent DXF formats.)<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_KhIIKmJ4wWc/SdosQ3X0wCI/AAAAAAAAAHU/RZy_oUw1f_4/s1600-h/dwg_export_version.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 310px;" src="http://4.bp.blogspot.com/_KhIIKmJ4wWc/SdosQ3X0wCI/AAAAAAAAAHU/RZy_oUw1f_4/s400/dwg_export_version.png" alt="" id="BLOGGER_PHOTO_ID_5321614577945067554" border="0" /></a><br>In case you want to use this plugin for Blender, you need to <a href="http://sd-2469.dedibox.fr/ar/pages/installation.html">install</a> my ar package first. It has been tested both on Linux and Windows. (Mac Os X might work as well.) Afterwards read the <a href="http://sd-2469.dedibox.fr/ar/tutorials/dwg.html">tutorial</a> for further instructions. You can use my DWG conversion python <a href="http://sd-2469.dedibox.fr/ar/modules/ar.lib.everydwg.html">module</a> also outside Blender.<br /><br />Are you an architect and coding with Python in Blender? I'd love to hear from you, not just because of this blog post. Just send me an email: spe.stani.be # gmail.comStanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com14tag:blogger.com,1999:blog-1693831864832387340.post-40232058502904392682009-03-31T18:21:00.001+02:002009-03-31T18:22:50.752+02:00Resumable IPython inside Blender TerminalWould it not be nice if <a href="http://ipython.scipy.org/">IPython</a> could run inside the <a href="http://www.blender.org/">Blender</a> terminal in such way that it will remember the namespace history in between sessions? Why IPython? It gives you auto completion, deep reloads, object introspection, input history, access to your operating system commands with python variables, auto indent, ... In case you are not convinced, read this <a href="http://ipython.scipy.org/doc/manual/html/interactive/tutorial.html">tutorial</a>, <a href="http://ipython.scipy.org/doc/manual/html/interactive/reference.html">reference</a> or watch these <a href="http://showmedo.com/videos/ipython">screencasts</a> on <a href="http://showmedo.com/">showmedo</a>.<br /><br />Most Linux distributions ship IPython in their repositories. For example installing on <a href="http://www.ubuntu.com/">Ubuntu</a> is as easy as:<blockquote><pre>$ sudo apt-get install ipython</pre></blockquote>Getting IPython on Windows or Mac is simple if you have <a href="http://pypi.python.org/pypi/setuptools">setuptools</a> installed:<blockquote><pre>$ easy_install IPython</pre></blockquote>Windows users should install <a href="http://ipython.scipy.org/dist/">pyreadline</a> as well for autocompletion. Check first in a terminal if IPython is correctly installed:<blockquote><pre>$ ipython<br />Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)<br />Type "copyright", "credits" or "license" for more information.<br /><br />IPython 0.8.4 -- An enhanced Interactive Python.<br />? -> Introduction and overview of IPython's features.<br />%quickref -> Quick reference.<br />help -> Python's own help system.<br />object? -> Details about 'object'. ?object also works, ?? prints more.<br /><br />In [1]:<br /></pre></blockquote>Save the following code as 'ipython_terminal.py' in your blender home script folder (~/.blender/scripts).<blockquote><pre>#!BPY<br /><br />"""<br />Name: 'IPython (Terminal) - Enhanced Interactive Python Shell in Terminal'<br />Blender: 248<br />Group: 'System'<br />Tooltip: 'Interactive Python Console in terminal'<br />"""<br /><br />__author__ = "Stani (SPE Python IDE)"<br />__url__ = ["pythonide.stani.be", "www.blender.org", "www.python.org"]<br />__bpydoc__ = """\<br />This only works if you started Blender from a terminal.<br />Otherwise Blender will freeze. The IPython console will<br />appear in the terminal. The namespace will be persistent<br />between console sessions within one Blender session.<br /><br />Press Ctrl-D to pause the IPython session and return to Blender.<br />"""<br /><br /># -*- coding: UTF-8 -*-<br /><br /># ar - ARchitecture library<br /># Copyright (C) 2009 www.stani.be<br />#<br /># This program is free software: you can redistribute it and/or modify<br /># it under the terms of the GNU General Public License as published by<br /># the Free Software Foundation, either version 3 of the License, or<br /># (at your option) any later version.<br />#<br /># This program is distributed in the hope that it will be useful,<br /># but WITHOUT ANY WARRANTY; without even the implied warranty of<br /># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br /># GNU General Public License for more details.<br />#<br /># You should have received a copy of the GNU General Public License<br /># along with this program. If not, see http://www.gnu.org/licenses/<br /><br />import sys<br /><br />from IPython.Shell import IPShell<br /><br />import bpy<br />import Blender<br /><br />try:<br /> shell = Blender.Registry.GetKey('ipython.terminal')['shell']<br /> shell.IP.exit_now = False # resume<br />except TypeError:<br /> sys_argv = sys.argv<br /> sys.argv = ['/usr/bin/ipython']<br /> shell = IPShell(user_ns={'Blender':Blender, 'bpy':bpy})<br /> sys.argv = sys_argv<br /> def pre_prompt_hook(ip, Blender=Blender, shell=shell):<br /> Blender.Redraw()<br /> Blender.Registry.SetKey('ipython.terminal', {'shell':shell})<br /> shell.IP.set_hook('pre_prompt_hook',pre_prompt_hook)<br /><br />shell.mainloop(banner=shell.IP.BANNER + shell.IP.banner2 +\<br /> '\nPress Ctrl-D to pause the IPython session and ' +\<br /> 'return to Blender.\n')<br /><br /></pre></blockquote>Make sure you start Blender from a terminal and not from the start menu, as IPython will run in the terminal. You can start the IPython terminal from the Script window in Blender. (Scripts > System > Ipython (Terminal) ) Just like in my previous blog post, each time a Python statement is entered, the Blender window is updated. So you can move a cube and see the result, if you type:<blockquote><pre>In [1]: cube = bpy.data.objects['Cube']<br /><br />In [2]: cube.LocX = -1</pre></blockquote>When you want to return to Blender, press Ctrl-D. If you restart later the IPython terminal, it will remember any commands you have typed or any variables you have declared (like cube in the example).<br /><br />IPython has a different prompt which makes it easy to go back to previous input statements or output values: <blockquote><pre>In [1]: a=1<br /><br />In [2]: print a<br />1<br /><br />In [3]: a<br />Out[3]: 1<br /><br />In [4]: exec _i2 # execute second command<br />1<br /><br />In [5]: exec In[2:4] # execute multiple previous commands<br />1<br /><br />In [6]: b=_3 # third ouput value<br /><br />In [7]: a==b<br />Out[7]: True</pre></blockquote>If you prefer a standard python prompt (>>>), just enter '%doctest_mode':<blockquote><pre>In [1]: %doctest_mode<br />*** Pasting of code with ">>>" or "..." has been enabled.<br />Exception reporting mode: Plain<br />Doctest mode is: ON<br /><br />>>><br /></pre></blockquote>For auto completion, press the TAB key: <blockquote><pre>In [1]: bpy.data.<br />bpy.data.__class__ bpy.data.curves<br />bpy.data.__delattr__ bpy.data.fonts<br />bpy.data.__dict__ bpy.data.groups<br />bpy.data.__doc__ bpy.data.images<br />bpy.data.__getattribute__ bpy.data.ipos<br />bpy.data.__hash__ bpy.data.lamps<br />bpy.data.__init__ bpy.data.lattices<br />bpy.data.__name__ bpy.data.materials<br />bpy.data.__new__ bpy.data.meshes<br />bpy.data.__reduce__ bpy.data.metaballs<br />bpy.data.__reduce_ex__ bpy.data.objects<br />bpy.data.__repr__ bpy.data.scenes<br />bpy.data.__setattr__ bpy.data.sounds<br />bpy.data.__str__ bpy.data.texts<br />bpy.data.actions bpy.data.textures<br />bpy.data.armatures bpy.data.worlds<br />bpy.data.cameras <br /><br />In [1]: bpy.data.m<br />bpy.data.materials bpy.data.meshes bpy.data.metaballs<br /><br />In [1]: from Blender import M<br />Material Mathutils Mesh Metaball Modifier </pre></blockquote>As shown in the last example auto completion works even for import statements.<br /><br />Altough the Blender window updates itself, the Blender user interface is still irresponsive when running an IPython session. In a future blog post I'll show how to run IPython inside the Blender window in such way that the user interface stays fully responsive.Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com2tag:blogger.com,1999:blog-1693831864832387340.post-49361609962001798342009-03-27T15:38:00.022+01:002009-03-27T16:38:58.843+01:00Free software python coin on national French televisionA while ago I blogged about my <a href="http://pythonide.blogspot.com/2008/10/how-to-make-money-with-free-software.html">winning coin design</a>. As an architect and artist I have switched some years ago to free software. A lot of so called experts would tell me that is impossible. They need Photoshop, Illustrator, Maya, ... on a fancy Macbook. However if I look to what they produce, I see no problem in making that with <a href="http://www.gimp.org">Gimp</a>, <a href="http://www.inkscape.org/">Inkscape</a>, <a href="http://www.blender.org">Blender</a>, ... even on an underpowered netbook. I did mainly this blogpost to proof not only that they are wrong, but also to showcase a design, which they even wouldn't be able to make with any proprietary software.<br /><br />The reactions were overwhelming both from the free software world and outside. The Dutch architecture site did a <a href="http://www.archined.nl/nieuws/5-euro-architectuur-herdenkingsmunt/">competition</a> for who could read all the names of the architects. I've been told the design featured in a popular Dutch comic <a href="http://www.foksuk.nl/">Fokke & Sukke</a>. (Anyone has a reference to this?) <a href="http://en.wikipedia.org/wiki/Rem_Koolhaas">Rem Koolhaas</a> was happy he was number one. Also typography sites showed a lot of interest. The Ministry of Finance promoted the coin on national Dutch television with this <a href="http://www.herdenkingsmunt.nl/domains/default/pages/content.aspx?content=14440000000131_2_10000000001651&contentcode=Architectuur_Vijfje_TV_Commercial&navid=14440000000043_14440000000082">clip</a>. (Unfortunately I was not involved in the production of the clip, otherwise it would have been 'Blendered'.) The more this kind of success stories pop up, the more people will be convinced to switch to free software.<br /><br />Last month a French television crew of <a href="http://info.france3.fr/avenue-europe">Avenue de l'Europe</a> (FR3) came to interview me about the coin. They are making a documentary about the 10 years existence of the euro. They chose my design as one of the most remarkable in the history of the euro. As the documentary is about the total history of the euro, I will probably get not more than one minute or maybe just some seconds. The emission is tomorrow 28/3 at 18h30 at FR3: <a href="http://info.france3.fr/avenue-europe">http://info.france3.fr/avenue-europe</a><br /><br />In the preparation emails for the interview, I felt they were more interested in the design than in free software. So in order to give some publicity, I wore an <a href="http://www.ubuntu.com">Ubuntu</a> T-shirt for the interview. As a location I chose the <a href="http://www.waag.org/project/fablab">Fablab</a> in Amsterdam. (They are still looking for people experienced with (graphical) free software or writing 3d printer drivers. If you want to help out, contact <a href="mailto:alex*waag.org">alex*waag.org</a>). I guess the television crew really have never heard about free software design, because one of them asked me if I went for holiday in South Africa recently when she saw my Ubuntu T-shirt.Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com3tag:blogger.com,1999:blog-1693831864832387340.post-55870427716592427392009-03-23T19:43:00.005+01:002009-03-23T20:08:33.283+01:00Standard Python Console inside BlenderBlender did not provide an interactive shell by default in the past. This changed a bit with the <a href="http://wiki.blender.org/index.php/Extensions:Py/Scripts/Manual/System/console">Interactive Python Console</a> of Campbell Barton (aka ideasman42), which is accessible from the script window (Scripts > System > Interactive Python Console). Unfortunately this console does not support copy&paste, word wrapping, prompts, ...<br /><br />I wrote a quick script in case you want to interact with Blender from a real Python console. Save it in your Blender home scripts folder (~/.Blender/scripts) as "terminal.py".<blockquote><pre>#!BPY<br /><br />"""<br />Name: 'Terminal - Interactive Python Console in terminal'<br />Blender: 248<br />Group: 'System'<br />Tooltip: 'Interactive Python Console in terminal'<br />"""<br /><br />__author__ = "Stani (SPE Python IDE)"<br />__url__ = ["pythonide.stani.be", "www.blender.org", "www.python.org"]<br />__bpydoc__ = """\<br />This only works if you started Blender from a terminal.<br />Otherwise Blender will freeze. The Python console will<br />appear in the terminal. The namespace will be persistent<br />between console sessions within one Blender session.<br /><br />Press Ctrl-D to quit.<br />"""<br /><br /># -*- coding: UTF-8 -*-<br /><br /># ar - ARchitecture library<br /># Copyright (C) 2009 www.stani.be<br />#<br /># This program is free software: you can redistribute it and/or modify<br /># it under the terms of the GNU General Public License as published by<br /># the Free Software Foundation, either version 3 of the License, or<br /># (at your option) any later version.<br />#<br /># This program is distributed in the hope that it will be useful,<br /># but WITHOUT ANY WARRANTY; without even the implied warranty of<br /># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br /># GNU General Public License for more details.<br /># <br /># You should have received a copy of the GNU General Public License<br /># along with this program. If not, see http://www.gnu.org/licenses/<br /><br />import code, sys<br />import Blender, bpy<br /><br />class InteractiveConsole(code.InteractiveConsole):<br /> def interact(self, banner=None):<br /> try:<br /> sys.ps1<br /> except AttributeError:<br /> sys.ps1 = ">>> "<br /> try:<br /> sys.ps2<br /> except AttributeError:<br /> sys.ps2 = "... "<br /> cprt = 'Type "help", "copyright", "credits" or "license"'+\<br /> ' for more information.'<br /> if banner is None:<br /> self.write("Python %s on %s\n%s\n(%s)\n" %<br /> (sys.version, sys.platform, cprt,<br /> self.__class__.__name__))<br /> else:<br /> self.write("%s\n" % str(banner))<br /> self.write('Press Ctrl-D to quit.\n')<br /> more = 0<br /> while 1:<br /> try:<br /> if more:<br /> prompt = sys.ps2<br /> else:<br /> prompt = sys.ps1<br /> try:<br /> line = self.raw_input(prompt)<br /> except EOFError:<br /> self.write("\n")<br /> break<br /> else:<br /> more = self.push(line)<br /> except KeyboardInterrupt:<br /> self.write("\nKeyboardInterrupt\n")<br /> self.resetbuffer()<br /> more = 0<br /> Blender.Redraw()<br /> Blender.Registry.SetKey('terminal.locals', self.locals)<br /><br />locals = Blender.Registry.GetKey('terminal.locals')<br />if not locals:<br /> locals = {'Blender':Blender, 'bpy':bpy}<br />console = InteractiveConsole(locals=locals)<br />console.interact()<br /></pre></blockquote>To use it, you need to start Blender from a terminal (with compiz turned off):<blockquote><pre>$ blender -w</pre></blockquote>This is very important, otherwise Blender will be blocked waiting for input at an invisible terminal. The terminal console can be started from the script window: Scripts > System > Terminal. The modules 'Blender' and 'bpy' are preloaded into the console, so you don't need to import them manually. Each time a Python statement is entered, the Blender window is updated. So you can move a cube and see the result, if you type:<blockquote><pre>>>> cube = bpy.data.objects['Cube']<br />>>> cube.LocX = -1</pre></blockquote>You can quit the interactive console by pressing Ctrl-D. You can restart the terminal as many times as you wish and automagically all your local variables will be kept (such as 'cube' in the example).<br /><br />The disadvantage is that the Blender window itself becomes unresponsive. For example you can not rotate the view during a Python console session. Also it would be much nicer to use IPython instead of the standard Python shell. However in a future blog post I'll have good news, if you want IPython integration inside Blender.Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com1tag:blogger.com,1999:blog-1693831864832387340.post-1696586398173637012009-03-08T13:19:00.014+01:002009-03-08T14:36:05.199+01:00Vector rendering with Blender in Ubuntu<a href="http://severnclaystudio.wordpress.com/bluebeard/">PantoGraph</a> is a prototype for a <a href="http://en.wikipedia.org/wiki/Vector_graphics">vector</a> rendering engine, developed in python by <a href="http://severnclaystudio.wordpress.com/about/">Severn Clay Studio</a>. This can be nice for architectural presentations. It is still beta, which means it gets quite slow for heavy drawings.<br /><br />It features two engines under the hood:<br /><ul><li><a href="http://cairographics.org/pycairo/">cairo</a> for svg, pdf and png output</li><li><a href="http://www.libming.org">ming</a> for animated flash output (.swf)</li></ul>Current features :<br /><ul><li>Hidden- line rendering</li><li>Solid colors (with- and without alpha) only</li><li>The ability to use simple closed, convex volumes to do a boolean “cut-away”</li><li>Control over lineweight and color for:</li><ul><li>Silhouette</li><li>Crease</li><li>Mesh</li><li>Hidden lines</li><li>Curves</li></ul><br /><li>A simple GUI that allows the saving of pens and pen settings</li></ul><br />It can be loaded as a python script from Blender. Don't bother with the installation instructions on the Pantograph homepage (like fiddling with your PYTHONPATH), as I wrote the following install script which takes care of everything (at least in Ubuntu Intrepid). Open a new text file with the name 'install_pantograph' and copy the following content inside:<br /><blockquote><pre>#!/bin/bash<br />#install most dependencies<br />sudo apt-get install -y python-ming python-cairo python-scipy<br />#install Polygon (python bindings)<br />wget http://download.dezentral.de/soft/Python/Polygon/Polygon-1.17.tar.gz<br />gzip -dc Polygon-1.17.tar.gz | tar xf -<br />rm Polygon-1.17.tar.gz<br />cd Polygon-1.17<br />python setup.py build<br />sudo python setup.py install<br />cd ..<br />rm -rf Polygon-1.17<br />#go to home blender dir<br />HOMEDIR=$HOME/.blender/scripts/<br />cd $HOMEDIR<br />#remove previous pantograph<br />rm pantograph*<br />rm progressImage.png<br />#install pantograph (progress image)<br />wget http://home.earthlink.net/~severnclay/pantograph_0.5.zip<br />unzip -o -j pantograph_0.5.zip progressImage.png -d ~/.blender/scripts<br />rm pantograph_0.5.zip<br />#install pantograph (bleeding edge)<br />wget http://home.earthlink.net/~severnclay/pantograph_bleedingEdge.zip<br />unzip -o -j pantograph_bleedingEdge.zip -d ~/.blender/scripts<br />rm pantograph_bleedingEdge.zip<br />#set homedir in config<br />cat pantographConfig.py | sed -e "s%/home/sclay/Work/Projects/pantograph/%$HOMEDIR%" > pantographConfig.py<br /></pre><br /></blockquote>Make the script executable, with right click (properties>permissions) in the file browser or from the terminal:<br /><blockquote><pre>$ chmod +x install_pantograph</pre></blockquote>And run the script in the terminal as you will need to give your password to install the dependencies.<br /><blockquote><pre>$ ./install_pantograph</pre></blockquote>After that you can access the pantograph renderer from the script window in Blender. First try it out with the default cube scene, before you let it crunch your heavy drawings.<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_KhIIKmJ4wWc/SbO_dTwSgFI/AAAAAAAAAHE/Fmv0i9ZGkgw/s1600-h/pantograph.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 283px;" src="http://1.bp.blogspot.com/_KhIIKmJ4wWc/SbO_dTwSgFI/AAAAAAAAAHE/Fmv0i9ZGkgw/s400/pantograph.png" alt="" id="BLOGGER_PHOTO_ID_5310798895839871058" border="0" /></a><br />If you want follow the progress of the render, you can better disable compiz and start Blender from a terminal, where the progress will be shown:<blockquote><pre>$ metacity --replace<br />$ blender -w</pre></blockquote>For feedback you can contact the developer at the <a href="http://blenderartists.org/forum/showthread.php?t=139517">blenderartists forum</a>.Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com0tag:blogger.com,1999:blog-1693831864832387340.post-29099264952628655372008-10-29T17:25:00.042+01:002008-11-21T16:27:14.216+01:00How to make money with free software...<span style="font-style:italic;">For a dutch text click <a href="http://www.zilverenvijfje.nl/beschrijving.asp">here</a>.</span><br /><br /><span style="font-weight:bold;">Introduction</span><br />The <a href="http://www.minfin.nl/">Dutch Ministry of Finance</a> organized an architecture competition for which a selected group of architectural offices (<a href="http://www.unstudio.com">unstudio</a>, <a href="http://www.noxarch.com">nox</a>, ...) and artists were invited, including myself. The goal of the competition was not to design a building, but the new 5 euro <a href="http://en.knm.nl/domains/knm/pages/article.asp?content=11720000000909_999_11650000000011&navid=11650000000014_11720000000067&cookie=init">commemorative coin</a> with the theme 'Netherlands and Architecture'. The winner will be rewarded with a nice price, but most of all with the honor: his design will be realized and will be a legal coin within the Netherlands.<br /><br />I approached the subject 'Netherlands and Architecture' from two points of view. On one hand I paid tribute to the rich Dutch architecture history and on the other hand to the contemporary quality of Dutch architecture. These form also the two sides of my coin. Traditionally the front of the coin needs to portray the queen, while the back side displays the value of the coin.<br /><br /><span style="font-weight:bold;">Front side</span><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_KhIIKmJ4wWc/SQiViteeCUI/AAAAAAAAAFU/tnhGeVNgfa8/s1600-h/Architectuur+5+2008+vz+v5.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 400px;" src="http://3.bp.blogspot.com/_KhIIKmJ4wWc/SQiViteeCUI/AAAAAAAAAFU/tnhGeVNgfa8/s400/Architectuur+5+2008+vz+v5.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5262620588137908546" /></a><br />When someone looks closely (click above on picture to enlarge) to my portrait of the <a href="http://en.wikipedia.org/wiki/Beatrix_of_the_Netherlands">queen</a>, it becomes clear that her portrait is constructed with names of important Dutch architects. On the outside the names are clearly readable, while they slowly get smaller to the center. Under a magnifying glass all names are readable, but not with only the human eye. It is fascinating to see how an old medium like a coin can be in this way a 'compact disc' of information.<br /><br />The tension between what is readable and what not, is also a metaphor how time shapes history. Some big names of the past, might be smaller names in the future and vice versa. To reflect this idea, I chose to order the architects not alphabetically or chronologically but in a new way: I used the internet as a seismograph and ordered the architects by the number of hits on the internet. <br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_KhIIKmJ4wWc/SQjzbyl9iEI/AAAAAAAAAG0/eo41gohKuPc/s1600-h/ordening_en.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 283px; height: 400px;" src="http://3.bp.blogspot.com/_KhIIKmJ4wWc/SQjzbyl9iEI/AAAAAAAAAG0/eo41gohKuPc/s400/ordening_en.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5262723823345436738" /></a><br /><br />Of course this order changes over time and as such this is another time stamp on the coin besides the number '2008'. Only the first 109 architects fitted on the coin, so that was immediately the selection. Apparently becoming famous goes exponentially:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_KhIIKmJ4wWc/SQic0BGSDYI/AAAAAAAAAFk/Qr6X99GapzY/s1600-h/architects_yahoo.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 267px;" src="http://1.bp.blogspot.com/_KhIIKmJ4wWc/SQic0BGSDYI/AAAAAAAAAFk/Qr6X99GapzY/s400/architects_yahoo.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5262628582044339586" /></a><br /><br />In order to achieve the image I developed my own single-line font system. I let the line width change within the same character in order to evoke an underlying picture:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_KhIIKmJ4wWc/SQilkQPxoTI/AAAAAAAAAFs/WVz3QIaNBwk/s1600-h/Koningin_niveaus5_32mm_big_dark40_light80_crop.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 306px;" src="http://1.bp.blogspot.com/_KhIIKmJ4wWc/SQilkQPxoTI/AAAAAAAAAFs/WVz3QIaNBwk/s400/Koningin_niveaus5_32mm_big_dark40_light80_crop.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5262638206837432626" /></a><br /><span style="font-weight:bold;">Back side</span><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_KhIIKmJ4wWc/SQiXPCrV5gI/AAAAAAAAAFc/Sv_XFUJSlds/s1600-h/Architectuur+5+2008+kz+v5.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 400px;" src="http://4.bp.blogspot.com/_KhIIKmJ4wWc/SQiXPCrV5gI/AAAAAAAAAFc/Sv_XFUJSlds/s400/Architectuur+5+2008+kz+v5.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5262622449254917634" /></a><br /><br />Nowadays Dutch architecture is famous for its strong conceptual approach. This translates itself in the fact that there are not only a lot of books about Dutch architects, but also by Dutch architects. <br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_KhIIKmJ4wWc/SQippnqTjaI/AAAAAAAAAGM/x94wHpSqVG8/s1600-h/all_books.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 126px; height: 400px;" src="http://4.bp.blogspot.com/_KhIIKmJ4wWc/SQippnqTjaI/AAAAAAAAAGM/x94wHpSqVG8/s400/all_books.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5262642697068580258" /></a><br />On the back side of the coin I treated the edge of the coin as a book shelve. The books rise as buildings towards the center. Through their careful placement they combine to outline the Netherlands, while birds’ silhouettes suggest the capitals of all the provinces. The following scheme reveals the process:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_KhIIKmJ4wWc/SQiokOuSYlI/AAAAAAAAAF8/fZhiKkbsgUQ/s1600-h/scheme_books.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 283px; height: 400px;" src="http://1.bp.blogspot.com/_KhIIKmJ4wWc/SQiokOuSYlI/AAAAAAAAAF8/fZhiKkbsgUQ/s400/scheme_books.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5262641504963420754" /></a><br /><br />One of the issues was how many books to take: many thin books or fewer thick books. With one very thick book you would only get a circle. To get the best approximation of the Netherlands you would need books of only one page, which is not optimal either. Therefore I needed to find the optimum between these two extremes which you can see in the scheme below. On the left you see the approximation of the Netherlands, in the middle you see the 'skyline' of the books and on the right you see the difference between the 'skyline' of the books and of the border line of the Netherlands:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_KhIIKmJ4wWc/SQi6hYOa1oI/AAAAAAAAAGk/lU4fTOcs0vI/s1600-h/schemes-pagina1.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 283px; height: 400px;" src="http://2.bp.blogspot.com/_KhIIKmJ4wWc/SQi6hYOa1oI/AAAAAAAAAGk/lU4fTOcs0vI/s400/schemes-pagina1.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5262661247183804034" /></a><br /><br />The following is the idea sketch for the birds. Each bird flies above the capital of each Dutch province. In the final coin these random birds are replaced with a bird which is typical for that province.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_KhIIKmJ4wWc/SQjuMeyzsWI/AAAAAAAAAGs/0oe8r6cy2hU/s1600-h/birds_for_gimp.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 342px; height: 400px;" src="http://3.bp.blogspot.com/_KhIIKmJ4wWc/SQjuMeyzsWI/AAAAAAAAAGs/0oe8r6cy2hU/s400/birds_for_gimp.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5262718062774432098" /></a><br /><br /><span style="font-weight:bold;">Technology</span><br />The whole design was done for 100% with free software. The biggest part consists of custom software in <a href="http://www.python.org">Python</a>, of course within the <a href="http://pythonide.stani.be">SPE editor</a>. For the visual power I used <a href="http://www.pythonware.com/products/pil/">PIL</a> and <a href="http://www.cairographics.org/pycairo/">pyCairo</a>. From time to time also <a href="http://www.gimp.org">Gimp</a>, <a href="http://www.inkscape.org">Inkscape</a> and <a href="http://photobatch.stani.be">Phatch</a> helped quite a bit. All the developing and processing was done on GNU/Linux machines which were running <a href="http://www.ubuntu.com">Ubuntu</a>/<a href="http://www.debian.org">Debian</a>. In the end I had to collaborate closely on location together with the technicians of the Royal Dutch Mint (coin factory). So all the last bits were done on my <a href="http://eeepc.asus.com">Asus Eee PC</a>. (I am still wondering why Asus doesn't offer Ubuntu on its netbooks.) The Eee laptop took a bit longer (30 seconds instead of 3 seconds to generate a whole coin), but did the job just fine. For looking up the number of hits on the internet, I rediscovered <a href="http://www.yahoo.com">Yahoo</a>, which provides a much better <a href="http://developer.yahoo.com">api</a> for automatic querying than its competitors. Of course the jury judged only the design and not the software used as others used Maya, Illustrator, ...<br /><br /><span style="font-weight:bold;">And the winner is...</span><br />I am proud to announce that I <a href="http://en.knm.nl/domains/knm/pages/article.asp?content=11720000000909_999_11650000000011&navid=11650000000014_11720000000067&cookie=init">won</a> the competition! So soon 350.000 Dutch people will use the fruits of free software. I would have loved to release the coin under the GPL, which could maybe solve the financial crisis. However for obvious reasons I was not allowed to do that. There will be also <a href="http://en.knm.nl/sanashop_v2/default/pages/Bulk_V2.asp?content=11720000000083_2_10000000002134&contentcode=Euromunten%20Nederland&navid=11650000000054_11650000000024">special editions</a> for collectors which can be bought world wide: a massive silver edition for € 30,95 and a massive gold edition for € 194,95. They will be probably sold out quickly as these are real collectors items. The coin is released in all Dutch post offices to the public the same day as the Intrepid Ibex: 30th October 2008.<br /><br />Here are some scans of the real coin:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_KhIIKmJ4wWc/SQittJk0XII/AAAAAAAAAGU/0D5SelE27cc/s1600-h/scan+herd+2400_queen.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 398px;" src="http://3.bp.blogspot.com/_KhIIKmJ4wWc/SQittJk0XII/AAAAAAAAAGU/0D5SelE27cc/s400/scan+herd+2400_queen.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5262647155758488706" /></a><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_KhIIKmJ4wWc/SQivbGC0R-I/AAAAAAAAAGc/fwQqTVHXfdY/s1600-h/scan+herd+2400_books.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 391px;" src="http://3.bp.blogspot.com/_KhIIKmJ4wWc/SQivbGC0R-I/AAAAAAAAAGc/fwQqTVHXfdY/s400/scan+herd+2400_books.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5262649044596180962" /></a><br /><br />The coin will be advertised 20 times on prime time on Dutch television with a nice <a href="http://www.herdenkingsmunt.nl/domains/default/pages/content.aspx?content=14440000000052_2_10000000001651&contentcode=main_jubileummunt">video clip</a> (will be available soon) and advertisements will run in several newspapers. Today was the official launch of the coin, with from left to right: myself, Secretary of State for Finance De Jager, the Chief government Architect Liesbeth van der Pol and Master of the Mint Maarten Brouwer...<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.minfin.nl/Actueel/Nieuwsberichten/2008/10/Rijksbouwmeester_slaat_eerste_Architectuur_Vijfje"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 267px;" src="http://www.minfin.nl/dsresource?objectid=minfinbeheer:60070&versionid=" border="0" alt="Liesbeth van der Pol toont het eerste Architectuur Vijfje (Bron foto: Githa van Eeuwen Fotografie)" /></a>Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com196tag:blogger.com,1999:blog-1693831864832387340.post-74716281186024701132008-06-11T14:05:00.008+02:002008-06-11T14:30:53.043+02:00Howto setup dual screen for Compiz in Ubuntu HardyIf you need to give presentations with your laptop and you are running Ubuntu Hardy, you might find that the gnome-display-properties (System>Preferences>Screen Resolution) do not work out of the box. So it is impossible to connect a beamer unless you clone. The same is true for a dual screen setup with Compiz.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_KhIIKmJ4wWc/SE_FaLj5VrI/AAAAAAAAADU/yY79Yub9PyE/s1600-h/Screenshot-Monitor+Resolution+Settings.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp2.blogger.com/_KhIIKmJ4wWc/SE_FaLj5VrI/AAAAAAAAADU/yY79Yub9PyE/s400/Screenshot-Monitor+Resolution+Settings.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5210600347461572274" /></a><br /><br />There is however a very easy trick to solve this. I have tested it with an Asus Eee PC 701 4G and with my Ati Radeon X600 desktop system. I am now enjoying running dual screen with all the 3d desktops enabled.<br /><br />The problem is that the default screen size configuration is too small, which does not allow you to place too screens next to each other. On the other hand Compiz can not handle texture sizes bigger than 2048x2048, which means for example two monitors of 1024x768. If you want to use bigger resolution, it is still possible, but you will need to turn off compiz and will loose the 3d effects.<br /><br />So to solve it, fire up a terminal:<br /><blockquote>$ sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.backup<br />$ sudo gedit /etc/X11/xorg.conf</blockquote><br /><br />Then find the "Screen" section and change it like this:<br /><blockquote><pre>Section "Screen"<br /> Identifier "Default Screen"<br /> Monitor "Configured Monitor"<br /> Device "Configured Video Device"<br /> SubSection "Display"<br /> Virtual 2048 2048 <br /> EndSubSection<br />EndSection</pre></blockquote><br /><br />To undo, you can just type:<br /><blockquote>$ sudo cp /etc/X11/xorg.conf.backup /etc/X11/xorg.conf</blockquote><br /><br />After doing this, you will be able to use gnome-display-properties with ease and run dual screen setups like this:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp0.blogger.com/_KhIIKmJ4wWc/SE_DRD5PC1I/AAAAAAAAADM/hCfBT741rFo/s1600-h/Screenshot_round.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp0.blogger.com/_KhIIKmJ4wWc/SE_DRD5PC1I/AAAAAAAAADM/hCfBT741rFo/s400/Screenshot_round.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5210597991761513298" /></a>Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com9tag:blogger.com,1999:blog-1693831864832387340.post-68883577143810958852008-03-31T13:45:00.011+02:002008-11-21T16:27:14.216+01:00How to write a wxPython video player with GstreamerwxPython ships by default with the wx.MediaCtrl for very basic playback of music or videos. As I would like to do more advanced video manipulation, I was curious if I could use Gstreamer directly in wxPython to create my own pipelines. It was surprisingly easy.<br />For those who don't know Gstreamer, I quote the website (http://www.gstreamer.org): <blockquote>GStreamer is a library that allows the construction of graphs of media-handling components, ranging from simple playback to complex audio (mixing) and video (non-linear editing) processing. Applications can take advantage of advances in codec and filter technology transparently.</blockquote><br /><br />There are python bindings for it, of which the documentation can be found on <a href="http://pygstdocs.berlios.de">http://pygstdocs.berlios.de</a><br />I would also suggest to read these introductions to gstreamer & python:<br /><ul><li><a href="http://www.cin.ufpe.br/~cinlug/wiki/index.php/Introducing_GStreamer">Introducing Gstreamer</a></li><li><a href="http://www.jonobacon.org/?p=750">Getting started with GStreamer with Python</a></li><li><a href="http://www.jonobacon.org/?p=851">Using Gnonlin with GStreamer and Python</a></li></ul><br />I translated the video player example 2.2 of the tutorial from pyGtk to wxPython:<br /><a href="http://pygstdocs.berlios.de/pygst-tutorial/playbin.html">http://pygstdocs.berlios.de/pygst-tutorial/playbin.html</a><br /><br />It should be straightforward to use this as a base for implementing your own pipelines. I work on Ubuntu, where I could install everything straight from the standard repositories.<br /><br />Here is the source code:<br /><blockquote><pre>#!/usr/bin/env python<br />#Example 2.2 http://pygstdocs.berlios.de/pygst-tutorial/playbin.html<br /><br />import sys, os<br />import wx<br />import pygst<br />pygst.require("0.10")<br />import gst<br /><br />import gobject<br />gobject.threads_init()<br /><br />class WX_Main(wx.App):<br /> <br /> def OnInit(self):<br /> window = wx.Frame(None)<br /> window.SetTitle("Video-Player")<br /> window.SetSize((500, 400))<br /> window.Bind(wx.EVT_CLOSE,self.destroy)<br /> vbox = wx.BoxSizer(wx.VERTICAL)<br /> hbox = wx.BoxSizer(wx.HORIZONTAL)<br /> self.entry = wx.TextCtrl(window)<br /> hbox.Add(self.entry, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4)<br /> self.button = wx.Button(window,label="Start")<br /> hbox.Add(self.button, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4)<br /> self.button.Bind(wx.EVT_BUTTON, self.start_stop)<br /> vbox.Add(hbox, 0, wx.EXPAND, 0)<br /> self.movie_window = wx.Panel(window)<br /> vbox.Add(self.movie_window,1,wx.ALL|wx.EXPAND,4)<br /> window.SetSizer(vbox)<br /> window.Layout()<br /> window.Show()<br /> self.SetTopWindow(window)<br /> <br /> self.player = gst.element_factory_make("playbin", "player")<br /> bus = self.player.get_bus()<br /> bus.add_signal_watch()<br /> bus.enable_sync_message_emission()<br /> bus.connect('message', self.on_message)<br /> bus.connect('sync-message::element', self.on_sync_message)<br /> <br /> return True<br /> <br /> def start_stop(self, event):<br /> if self.button.GetLabel() == "Start":<br /> filepath = self.entry.GetValue()<br /> if os.path.exists(filepath):<br /> self.button.SetLabel("Stop")<br /> self.player.set_property('uri',"file://" + filepath)<br /> self.player.set_state(gst.STATE_PLAYING)<br /> else:<br /> self.player.set_state(gst.STATE_NULL)<br /> self.button.SetLabel("Start")<br /> <br /> def on_message(self, bus, message):<br /> t = message.type<br /> if t == gst.MESSAGE_EOS:<br /> self.player.set_state(gst.STATE_NULL)<br /> self.button.SetLabel("Start")<br /> elif t == gst.MESSAGE_ERROR:<br /> self.player.set_state(gst.STATE_NULL)<br /> self.button.SetLabel("Start")<br /> <br /> def on_sync_message(self, bus, message):<br /> if message.structure is None:<br /> return<br /> message_name = message.structure.get_name()<br /> if message_name == 'prepare-xwindow-id':<br /> imagesink = message.src<br /> imagesink.set_property('force-aspect-ratio', True)<br /> imagesink.set_xwindow_id(self.movie_window.GetHandle())<br /> <br /> def destroy(self,event):<br /> #Stop the player pipeline to prevent a X Window System error<br /> self.player.set_state(gst.STATE_NULL)<br /> event.Skip()<br /> <br />app = WX_Main()<br />app.MainLoop()<br /></pre></blockquote>Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com6tag:blogger.com,1999:blog-1693831864832387340.post-33007335207916132392008-03-25T12:59:00.004+01:002008-03-25T13:07:08.441+01:00SPE packaged for Mac OS X<span dir="ltr"><a href="http://www.blogger.com/profile/02591842280854638602" onclick="" rel="nofollow">Krzysztof Olczyk</a> did a wonderful job by packaging SPE for Mac OS X. </span>You can download it here:<br /><a href="http://olczyk.krzysztof.googlepages.com/SPE.dmg">http://olczyk.krzysztof.googlepages.com/SPE.dmg</a><br /><br />He commented:<br /><blockquote>You can install now SPE in your Macintosh in a way you do with native applcation.<br />Simply mount the DMG and drag the SPE to Applications folder.<br /><br />Another advantage is, that now SPE will have its own icon in dock, like any application in Mac.<br /><br />Have fun.</blockquote><br />I will release soon SPE 0.8.4.e with some important bug fixes and I hope <span dir="ltr"><a href="http://www.blogger.com/profile/02591842280854638602" onclick="" rel="nofollow">Krzysztof Olczyk</a> will update the package for the Mac.<br /><br />Please test the package and let Krystof know how it works.<br /><br />Thanks Krystof!<br />Stani<br /></span>Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com24tag:blogger.com,1999:blog-1693831864832387340.post-90473812473596419142008-02-14T18:43:00.003+01:002008-03-31T13:49:10.681+02:00SPE 0.8.4.c Python IDE editor releasedAs SPE was being developed for more than a year in subversion, I thought it is time for a release again. This is a major bugfix release. It ships updated plugins and also some new features, especially if you use Linux or Blender, for which Witold did a great job. Thanks to the big help of MOTU pochu, this is added to Ubuntu Hardy. I would also like to thank in particular the webhost Zindep.com for their support and patience.<br /><br />New features:<br /><ul><li>new versions of WinPdb debugger, PyChecker, wxGlade & XRCed gui designer</li><li>clear output pane</li><li>support for wxPython 2.8</li><li>linux support for nautilus, gnome-terminal, konqueror, konsole, thunar</li><li>improved blender support up to 2.45 (by Witold)<br /></li></ul>Fixes:<br /><ul><li>sidebar sash more tolerant</li><li>show path in title (linux)</li><li>run with filename with spaces</li><li>nicer debug dialog box</li><li> kill process fix</li><li>notebook</li><li>insert signature</li><li>numpad keys (by isolationism)</li><li>find tab with nonexisting files</li><li>add environment to SPE.py (linux)</li><li>better warning for documentation for unsaved files</li><li>better handling of new empty files</li><li>many more...</li></ul>Installing on Debian(unstable) and Ubuntu Hardy:<br /><blockquote>sudo apt-get install spe</blockquote>Installing on all other platforms:<br /><ol><li>Download either the zip or tar ball from <a href="http://developer.berlios.de/project/showfiles.php?group_id=4161">here</a><br /></li><li>Unzip it where you want and do NOT rename the _spe folder</li><li>Start SPE from within the _spe folder with "python SPE.py"<br /></li></ol>Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com41tag:blogger.com,1999:blog-1693831864832387340.post-49807582539107043012008-02-06T19:15:00.001+01:002009-01-08T04:10:32.272+01:00Howto install sK1, a powerful alternative for Illustrator on UbuntuThis post is deprecated as <span class="highlight">sk1</span> now has an official ubuntu installer:<br /><a href="http://sk1project.org/modules.php?name=Products&product=sk1" target="_blank">http://sk1project.org/modules.php?na...ts&product=sk1</a><br /><br />So this is for archival purposes only:<br /><br />Igor, the icon king of <a href="http://photobatch.stani.be/">Phatch</a>, asked me if I could get sk1 to work on Ubuntu Gutsy. After playing around I found a way. Try this on your own risk.<br /><br />I never heard about sk1 and looked it up on the website:<br />http://sk1project.org/<br /><br /><blockquote>Why sk1project?<br /><br />We think that sK1 is a powerful illustration program for the Linux platform that can substitute professional proprietary software like CorelDRAW or Adobe Illustrator and we hope the program and its derivatives will be helpful for you.<br /><br />About sK1 vector graphics editor<br /><br />sK1 is an open source vector graphics editor similar to CorelDRAW, Adobe Illustrator, or Freehand.<br />First of all sK1 is oriented for PostScript processing.<br />The major sK1 features:<br /><br />* CMYK colorspace support<br />* CMYK support in Postscript<br />* Cairo-based engine<br />* Color managment<br />* Universal CDR importer (7-X3 versions)<br />* Modern Ttk based (former Tile widgets) user interface</blockquote>It looks quite impressive and in five steps you can have it up and running on your Ubuntu Gutsy. It is a KDE application.<br /><br /><span style="font-weight: bold;">1) Installing required modules</span><br />Type this at a terminal:<br /><blockquote>sudo apt-get install liblcms-utils python-liblcms python-imaging-tk kdebase-bin<br /></blockquote><span style="font-weight: bold;">2) Installing tcl/tk8.5</span><br />Download the tk8.5 and tcl8.5 packages of Gustavo A. Díaz for the amsn project:<br />http://download.tuxfamily.org/amsnskins/packages/ubuntu/tcl-tk/<br /><br />Open and install these files in this order with gdebi:<br /><a href="http://download.tuxfamily.org/amsnskins/packages/ubuntu/tcl-tk/tcl8.5_8.5.0-2_i386.deb">tcl8.5_8.5.0-2_i386.deb</a><br /><a href="http://download.tuxfamily.org/amsnskins/packages/ubuntu/tcl-tk/tk8.5_8.5.0-2_i386.deb">tk8.5_8.5.0-2_i386.deb</a><br /><br /><span style="font-weight: bold;">3) Installing sk1</span><br />Now download the latest version of sk1 from:<br />http://sk1project.org/modules.php?name=Products&product=sk1<br /><br />And convert it to a debian installer:<br /><blockquote>sudo alien sK1-0.9.0-rev324-0.mdv2008.i586.rpm</blockquote><span style="font-weight: bold;">4) Patching sk1</span><br />We need to patch this file:<br />sudo gedit /usr/lib/python2.5/site-packages/sk1/app/managers/colormanager.py<br /><br />Replace there on line 9:<br /><blockquote>from lcms import (...)</blockquote>into<br /><blockquote>from lcms.lcms import (...)</blockquote><span style="font-weight: bold;">5) Start sk1</span><br />Press Alt+F2 and type "sk1" at the terminal and sk1 is up and running! You can create a menu entry with alacarta or a desktop launcher with the command "sk1". I have not tested how well it works.<br /><br />This is a screenshot, turned into perspective with <a href="http://photobatch.stani.be/">Phatch</a>:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_KhIIKmJ4wWc/R6oAXFQJVNI/AAAAAAAAACU/gY2bNBohhU0/s1600-h/sk1_3d.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp1.blogger.com/_KhIIKmJ4wWc/R6oAXFQJVNI/AAAAAAAAACU/gY2bNBohhU0/s400/sk1_3d.png" alt="" id="BLOGGER_PHOTO_ID_5163940319280583890" border="0" /></a>Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com13tag:blogger.com,1999:blog-1693831864832387340.post-91959399334751419012008-01-16T17:24:00.001+01:002008-03-31T14:25:18.547+02:00Latest wxGlade, XRCed and Winpdb in subversionSo SPE is up to date again. The Winpdb debugger now features autocompletion. It is looking for a new <a href="http://www.winpdb.org/?p=33">name</a>, as most people associate win with Windows (while winpdb is being developed on ubuntu now). The new XRCed (gui designer for wxpython) looks really slick. This is a screenshot on ubuntu:<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_KhIIKmJ4wWc/R44xqU2gWyI/AAAAAAAAACM/686Jzc8uucU/s1600-h/xrced.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp1.blogger.com/_KhIIKmJ4wWc/R44xqU2gWyI/AAAAAAAAACM/686Jzc8uucU/s400/xrced.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5156113226607385378" /></a>Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com4tag:blogger.com,1999:blog-1693831864832387340.post-64713787953852652142007-11-01T17:24:00.001+01:002009-01-08T04:13:25.515+01:00How to change or recreate your Desktop folder on UbuntuThe default location of your Desktop folder is ~/Desktop. You might prefer another location. If you by accident deleted the Dekstop folder, it will be stuck in your Trash folder as you can't put it back. These two steps enable you to change or restore your desktop folder:<br /><blockquote>gedit ~/.config/user-dirs.dirs<br />killall nautilus</blockquote>In step 1 look for this entry: XDG_DESKTOP_DIR. Make it like this: XDG_DESKTOP_DIR="$HOME/Desktop"<br />Instead of step 2 you might also log off and log in again.<br /><br />This is only tested on Gutsy.Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com4tag:blogger.com,1999:blog-1693831864832387340.post-61085452358405724012007-10-31T21:50:00.000+01:002008-11-21T16:27:14.217+01:00How to install pymedia on Ubuntu (Gutsy)"<a href="http://www.pymedia.org">Pymedia</a> is a Python library for accessing and manipulating media files. It makes audio and video playback/creation a snap for even a newcomer to programming." There is a deb installer available for pymedia 1.3.5 but not for 1.3.7 So I decided to write this howto.<br /><br />First install all the dependencies:<br /><blockquote>sudo apt-get install python-dev libogg-dev libvorbis-dev liblame-dev libfaad2-dev libasound2-dev python-pygame<br /></blockquote>(Pygame is not really necessary, but recommended.)<br /><br />Extract a download of pymedia-*.tgz and open a terminal in the extracted folder, so we can build pymedia:<br /><blockquote>python setup.py build</blockquote><br />This should display:<br /><blockquote>Using UNIX configuration...<br /><br />OGG : found<br />VORBIS : found<br />FAAD : found<br />MP3LAME : found<br />VORBISENC : found<br />ALSA : found<br />Continue building pymedia ? [Y,n]:</blockquote><br />If everything is found press Y<br /><br />Finally install pymedia:<br /><blockquote>sudo python setup.py install</blockquote><br /><br />Test if pymedia installed correctly by typing this at the python shell:<br /><blockquote>import pymedia</blockquote><br /><br />You may now proceed to the <a href="http://www.pymedia.org/tut/">pymedia tutorials</a>.Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com6tag:blogger.com,1999:blog-1693831864832387340.post-78466407428971192512007-10-22T13:12:00.000+02:002007-11-01T20:19:30.099+01:00SPE 0.8.4.b works fine in Ubuntu GutsyThe latest version of SPE 0.8.4.b works very well in Ubuntu Gutsy. It is available through <a href="http://pythonide.blogspot.com/2007/02/how-to-download-latest-spe-from_26.html">subversion</a>. However the repository package is outdated, as it is still on 0.8.2.a What SPE needs to solve this issue is a Debian packager with love for python. This is the related bug on launchpad, from which I quote Scott:<br />"Ubuntu gets this package from Debian and it appears that it's been orphaned in Debian.<br />(...) it'd be hugely helpful if someone concerned about spe would adopt it in Debian. There is a Debian Python Applications Team with active DD support, so you need not be a DD to do this."<br />If you are not a packager it would be nice if you leave your comment on the launchpad bug. <br />https://bugs.launchpad.net/ubuntu/+source/spe/+bug/124896<br />So this gets more attention and will be fixed sooner as there is more demand. If someone steps up to package this for debian, I will release a new version of SPE.Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com26tag:blogger.com,1999:blog-1693831864832387340.post-21448788634683347262007-09-02T20:27:00.000+02:002007-09-02T20:35:56.780+02:00Winpdb 1.2.2, wxGlade0.6 & XRCed 0.1.8-5......all landed in subversion (rev255). wxGlade and XRCed are taken from their repositories, so they might be bleeding edge. Thanks to Diaa Sami some issues on Windows are fixed (eg running files with spaces). Check out the new SPE in the usual way:<blockquote><pre>svn checkout svn://svn.berlios.de/python/spe/trunk/_spe</pre></blockquote>Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com25tag:blogger.com,1999:blog-1693831864832387340.post-53745352454322070592007-06-08T17:59:00.001+02:002008-03-31T14:31:12.349+02:00Latest wxGlade in SPE subversionI've uploaded the latest wxGlade cvs into the subversion repository of SPE.Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com10tag:blogger.com,1999:blog-1693831864832387340.post-74452058761824286412007-03-14T19:43:00.000+01:002007-03-16T00:32:50.115+01:00Last WinPdb debugger 1.0.9 in SPE subversion<iframe src="http://digg.com/api/diggthis.php?u=http://www.digg.com/linux_unix/Release_of_WinPdb_1_0_9_the_best_python_debugger_and_uploaded_to_SPE_svn" style="padding: 4px 0pt 2px 4px; background: rgb(255, 255, 255) none repeat scroll 0% 50%; float: right; margin-left: 10px; margin-bottom: 5px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" frameborder="1" height="82" scrolling="no" width="55"></iframe>The last version of <a href="http://www.digitalpeers.com/pythondebugger/">WinPdb</a> debugger 1.0.9 has hit the SPE 0.8.4 subversion repository. What is now especially nice is that when you debug a python file from SPE, WinPdb remembers it when you have to relaunch the script. In case you don't know WinPdb:<br /><blockquote>Winpdb is a GPL python debugger, with support for smart breakpoints, multiple threads, namespace modification, embedded debugging, password encrypted communication and speed of up to 20 times that of pdb.</blockquote>What I like especially about WinPdb, is that it is perfect for gui debugging as it supports multiple threads, that you can change variables on the fly (with exec variable=new_value in the shell) and... the amazing speed for a debugger. It almost runs programs at normal speed. SPE gives you the option to start running a program normally and to let WinPdb break in from the moment you want to debug. WinPdb has been fixed for Ubuntu and Mac, so now it is the best open source python debugger for Linux, Mac and Windows.<br /><br />These are all the changes of 1.0.9:<br /><ul><li> Bug fix of bug 1654010 - window gets bigger on every session.</li><li> Bug fix of bug 1373074 - 2 Window menus on mac.</li><li> Bug fix of bug 1654011 - clipping long path names at the left.</li><li> Bug fix of bug 1654009 - List indices are sorted wrong.</li><li> Bug fix of bug 1610393 - Problems with wx-2.7.2-msw-unicode.</li><li> Bug fix of bug 1481097 - "# -*- coding: " problem.</li><li> + fixes for tons of unreported bugs.</li><li> Feature request 1654155 - More compact variable list on OS X.</li><li> Feature request 1446799 - Restarting.</li><li> Feature request 1364935 - remember command line file.</li></ul>In the latest release of SPE 0.8.3.c shipped with Winpdb 1.0.6 , so the changes of WinPdb might interest you as well:<br /><ul><li>Bug fix of bug 1358842 - Wrong terminal command in RHEL4.</li><li>Bug fix of bug 1559668 - not work with Ubuntu Dapper 6.06.</li><li>Bug fix of bug 1476311 - script launch fails with gnome-terminal.</li><li>Bug fix of bug 1492500 - Filtering should work anywhere.</li><li>Bug fix of bug 1445514 - Doesn't work with *.pyw scripts.</li><li>Bug fix of bug 1491470 - Slightly difficult to use a custom terminal in rpdb2.</li><li>Bug fix of bug 1546181 - Sort names alphabetically.</li><li>Bug fix of bug 1481097 - "# -*- coding: " problem.</li><li>Fixed exception handling on CPython 2.4.x and CPython 2.5.</li><li>Fixed some compatibility issues with wxPython 2.7.</li></ul>Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com7tag:blogger.com,1999:blog-1693831864832387340.post-66222789999467140422007-03-07T20:41:00.000+01:002007-03-14T19:18:36.493+01:00SPE: Call for testers!I've been working a lot on fixing SPE and upgrading it with the latest plugins. The winpdb debugger no longer fails and wxGlade crashes are history. Is that not great? Are you eager to try it out yourself? Please do! Get it from <a href="http://pythonide.blogspot.com/2007/02/how-to-download-latest-spe-from_26.html">subversion</a> and test it for any critical bug, so I can iron it out. I have been patching a lot for Ubuntu users, who will be very pleased with this release, and I'd like to thank Jurjen a lot for his work on Mac issues. This is a definitely a release everyone should upgrade to, wether you use windows, mac or linux!<br /><br />Here is an overview what has been done:<br /><br />The focus in this release is bugfixing, plugin upgrades and compatibility with wxPython 2.8, but it also still works on wxPython 2.6<br /><br />Upgrades:<br />- WinPdb to 1.0.8 (not fail in timely manner anymore)<br />- wxGlade to latest cvs (support for wxWindows2.8)<br /><br />New features:<br />- Save as copy<br />- Clear output pane<br /><br />Fixes<br />- output: escape html characters in tab & respect spaces<br />- preserve file permissions and avoid erasing file<br />- wxversion handling at startup<br />- font dialog<br />- recent files sorted by lowercase<br />- default buttons on all dialog<br />- mac: run terminal commands (jurjen)<br />- mac: pychecker<br />- ubuntu: switch to file<br />- some critical bug fixes which could have crashed SPE in the past<br />- much more ...<br /><br />PS. Winpdb does not work well on Mac & wxpython2.8 Nir is working on an update. So when it comes out it will be included with SPE.Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com21tag:blogger.com,1999:blog-1693831864832387340.post-45101752510818409982007-03-05T18:26:00.000+01:002007-11-01T20:17:42.362+01:00Pyxides brainstorm: generic 'fold explorer'I posted on the <a href="http://www2.blogger.com/img/gl.link.gif">pyxides mailing list</a> a prototype of a 'fold explorer'. A fold explorer is different from a class explorer as it shows the folding hierarchy of a document as a tree. <a href="http://groups.google.com/group/pyxides/tree/browse_frm/thread/d69dc30bc09bc654/0a47716fa15085af?rnum=1&_done=%2Fgroup%2Fpyxides%2Fbrowse_frm%2Fthread%2Fd69dc30bc09bc654%3F#doc_46b445313a53323d">Why?</a> The aim is to use the internal power of <a href="http://www.scintilla.org/">Scintilla</a> as much as possible. Scintilla supports 78 languages and a lot of them with folding. So the fold explorer enables any scintilla based editor to immediately support a whole range of languages. The fold explorer is also able to detect the start and end line of a node. If you right click any item in the tree, it will select the corresponding source. So later it should be possible with drag and drop items in a tree to reorganise your code. (Like in Leo, but without comments.) Now it uses 'picasso', a random style colorizer. For more information read the <a href="http://groups.google.com/group/pyxides/browse_frm/thread/8c00ae275f5f9cf">this thread</a> on the pyxides mailing list. (<a href="http://groups.google.com/group/pyxides/subscribe">Join</a> the mailing list!)<br /><br />Does anyone know how with python I could dynamically retrieve if a language support folding? That is the last missing piece.<br /><br />This screenshot shows how it parses its own python source:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp3.blogger.com/_KhIIKmJ4wWc/RexV53s-3HI/AAAAAAAAAA4/__SimNF7Adk/s1600-h/Screenshot-Fold%2BExplorer%2BDemo-1.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp3.blogger.com/_KhIIKmJ4wWc/RexV53s-3HI/AAAAAAAAAA4/__SimNF7Adk/s400/Screenshot-Fold%2BExplorer%2BDemo-1.png" alt="" id="BLOGGER_PHOTO_ID_5038496535814265970" border="0" /></a><br />Rob McMullen shows how it parses a C++ file:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_KhIIKmJ4wWc/RexWQns-3II/AAAAAAAAABA/8Tz69V0vZvc/s1600-h/cppfolded.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp2.blogger.com/_KhIIKmJ4wWc/RexWQns-3II/AAAAAAAAABA/8Tz69V0vZvc/s400/cppfolded.png" alt="" id="BLOGGER_PHOTO_ID_5038496926656289922" border="0" /></a><br />Here is the source code if you want to try it out for yourself. You need to have wxPython installed to run it. It is a nice demo if you want to play around with scintilla on python. I am open to any improvements, remarks or feedback.<br /><blockquote><pre>#!usr/bin/python <br /># -*- coding: utf8 -*- <br />#(c)www.stani.be, GPL licensed<br /><br />import sys, random<br />import wx<br />import wx.stc as stc<br /><br />DEFAULT_ENCODING= 'utf8'<br />STC_LANGUAGES = [x[8:] for x in dir(stc) if x.startswith('STC_LEX_')]<br />WHITE = 6777215<br />GRAY = 3388607<br /><br />def value2colour(c):<br /> return ('#%6s'%hex(c)[2:]).replace(' ','0').upper()<br /><br />def picasso():<br /> c = random.randint(0,GRAY)<br /> return value2colour(c), value2colour((c+GRAY)%WHITE)<br /><br />class Node:<br /> def __init__(self,level,start,end,text,parent=None,styles=[]):<br /> """Folding node as data for tree item."""<br /> self.parent = parent<br /> self.level = level<br /> self.start = start<br /> self.end = end<br /> self.text = text<br /> self.styles = styles #can be useful for icon detection<br /> self.children = []<br /> <br /><br />class Editor(stc.StyledTextCtrl):<br /> #---initialize<br /> def __init__(self,parent,language='UNKNOWN'):<br /> stc.StyledTextCtrl.__init__(self,parent,-1)<br /> self.setFoldMargin()<br /> self.encoding = DEFAULT_ENCODING<br /> <br /> def setFoldMargin(self):<br /> self.SetProperty("fold", "1")<br /> self.SetProperty("fold.html","1")<br /> #MARGINS<br /> self.SetMargins(0,0)<br /> #margin 1 for line numbers<br /> self.SetMarginType(1, stc.STC_MARGIN_NUMBER)<br /> self.SetMarginWidth(1, 50)<br /> #margin 2 for markers<br /> self.SetMarginType(2, stc.STC_MARGIN_SYMBOL)<br /> self.SetMarginMask(2, stc.STC_MASK_FOLDERS)<br /> self.SetMarginSensitive(2, True)<br /> self.SetMarginWidth(2, 12)<br /> # Plus for contracted folders, minus for expanded<br /> self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_MINUS, "white", "black")<br /> self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_PLUS, "white", "black")<br /> self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "white", "black")<br /> self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "white", "black")<br /> self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black")<br /> self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black")<br /> self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black")<br /> self.Bind(stc.EVT_STC_MARGINCLICK, self.onMarginClick)<br /> <br /> def onMarginClick(self, evt):<br /> # fold and unfold as needed<br /> if evt.GetMargin() == 2:<br /> if evt.GetShift() and evt.GetControl():<br /> self.FoldAll()<br /> else:<br /> lineClicked = self.LineFromPosition(evt.GetPosition())<br /> if self.GetFoldLevel(lineClicked)&stc.STC_FOLDLEVELHEADERFLAG:<br /> if evt.GetShift():<br /> self.SetFoldExpanded(lineClicked, True)<br /> self.Expand(lineClicked, True, True, 1)<br /> elif evt.GetControl():<br /> if self.GetFoldExpanded(lineClicked):<br /> self.SetFoldExpanded(lineClicked, False)<br /> self.Expand(lineClicked, False, True, 0)<br /> else:<br /> self.SetFoldExpanded(lineClicked, True)<br /> self.Expand(lineClicked, True, True, 100)<br /> else:<br /> self.ToggleFold(lineClicked)<br /> <br /> #---open<br /> def open(self,fileName, language, encoding=DEFAULT_ENCODING, line=0):<br /> self.setLanguage(language)<br /> self.setText(open(fileName).read(),encoding)<br /> wx.CallAfter(self.GotoLine,line)<br /> <br /> def setText(self,text,encoding=DEFAULT_ENCODING):<br /> self.encoding = encoding<br /> self.SetText(text.decode(encoding))<br /> self.Colourise(0, self.GetTextLength()) #make sure everything is lexed<br /> wx.CallAfter(self.explorer.update)<br /> <br /> def setLanguage(self,language):<br /> if language in STC_LANGUAGES:<br /> self.SetLexer(getattr(stc,'STC_LEX_%s'%language))<br /> for style in range(50):<br /> self.StyleSetSpec(style,"fore:%s,back:%s"%picasso())<br /> return True<br /> return False<br /> <br /> #---hierarchy<br /> def getHierarchy(self):<br /> #[(level,line,text,parent,[children]),]<br /> n = self.GetLineCount()+1<br /> prevNode = root = Node(level=0,start=0,end=n,text='root',parent=None)<br /> for line in range(n-1):<br /> foldBits = self.GetFoldLevel(line)<br /> if foldBits&stc.STC_FOLDLEVELHEADERFLAG:<br /> #folding point<br /> prevLevel = prevNode.level<br /> level = foldBits&stc.STC_FOLDLEVELNUMBERMASK<br /> text = self.GetLine(line)<br /> node = Node(level=level,start=line,end=n,text=text)<br /> if level == prevLevel:<br /> #say hello to new brother or sister<br /> node.parent = prevNode.parent<br /> node.parent.children.append(node)<br /> prevNode.end= line<br /> elif level>prevLevel:<br /> #give birth to child (only one level deep)<br /> node.parent = prevNode<br /> prevNode.children.append(node)<br /> else:<br /> #find your uncles and aunts (can be several levels up)<br /> while level < prevNode.level:<br /> prevNode.end = line<br /> prevNode = prevNode.parent<br /> node.parent = prevNode.parent<br /> node.parent.children.append(node)<br /> prevNode.end= line<br /> prevNode = node<br /> prevNode.end = line<br /> return root<br /> <br /> def selectNode(self,node):<br /> """If a tree item is right clicked select the corresponding code"""<br /> self.GotoLine(node.start)<br /> self.SetSelection(<br /> self.PositionFromLine(node.start),<br /> self.PositionFromLine(node.end),<br /> )<br /> <br />class TreeCtrl(wx.TreeCtrl):<br /> def __init__(self,*args,**keyw):<br /> keyw['style'] = wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS<br /> wx.TreeCtrl.__init__(self,*args,**keyw)<br /> self.root = self.AddRoot('foldExplorer root')<br /> self.hierarchy = None<br /> self.Bind(wx.EVT_RIGHT_UP, self.onRightUp)<br /> self.Bind(wx.EVT_TREE_KEY_DOWN, self.update)<br /> <br /> def update(self, event=None):<br /> """Update tree with the source code of the editor"""<br /> hierarchy = self.editor.getHierarchy()<br /> if hierarchy != self.hierarchy:<br /> self.hierarchy = hierarchy<br /> self.DeleteChildren(self.root)<br /> self.appendChildren(self.root,self.hierarchy)<br /> <br /> def appendChildren(self,wxParent,nodeParent):<br /> for nodeItem in nodeParent.children:<br /> wxItem = self.AppendItem(wxParent,nodeItem.text.strip())<br /> self.SetPyData(wxItem,nodeItem)<br /> self.appendChildren(wxItem,nodeItem)<br /> <br /> def onRightUp(self,event):<br /> """If a tree item is right clicked select the corresponding code"""<br /> pt = event.GetPosition();<br /> wxItem, flags = self.HitTest(pt)<br /> nodeItem = self.GetPyData(wxItem)<br /> self.editor.selectNode(nodeItem)<br /><br />class Frame(wx.Frame):<br /> def __init__(self,title,size=(800,600)):<br /> wx.Frame.__init__(self,None,-1,title,size=size)<br /> splitter = wx.SplitterWindow(self)<br /> self.explorer = TreeCtrl(splitter)<br /> self.editor = Editor(splitter)<br /> splitter.SplitVertically(<br /> self.explorer,<br /> self.editor,<br /> int(self.GetClientSize()[1]/3)<br /> )<br /> self.explorer.editor = self.editor<br /> self.editor.explorer = self.explorer<br /> self.Show()<br /> <br />if __name__ == '__main__':<br /> print 'This scintilla supports %d languages.'%len(STC_LANGUAGES)<br /> print ', '.join(STC_LANGUAGES)<br /> app = wx.PySimpleApp()<br /> frame = Frame("Fold Explorer Demo")<br /> <br /> fileName= sys.argv[-1] #choose file<br /> frame.editor.open(fileName,'PYTHON','utf8') #choose language in caps<br /> <br /> app.MainLoop()</pre></blockquote>Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com1tag:blogger.com,1999:blog-1693831864832387340.post-8843843796278534212007-03-04T19:55:00.000+01:002007-03-13T13:48:07.724+01:00How to switch between python2.4 and python2.5 on Ubuntu<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.ubuntu.com/"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 80px;" src="http://ubuntuforums.org/gallery/data/5/thumbs/ubuntu-powered.png" alt="" border="0" /></a>The default version of python on Edgy is python2.4 and on Feisty is python2.5 If you installed both versions of python and want to switch between them you have once to type this in a terminal:<br /><blockquote><pre>sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.4 10<br />sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.5 1</pre></blockquote>Afterwards you can choose at any time your standard python version by:<blockquote><pre>sudo update-alternatives --config python</pre></blockquote>Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com11tag:blogger.com,1999:blog-1693831864832387340.post-36255305621826585502007-02-28T17:06:00.001+01:002007-03-16T00:27:51.952+01:00SPE now works on wxPython2.8 and how to switch<iframe src="http://digg.com/api/diggthis.php?u=http://www.digg.com/programming/How_to_switch_to_wxPython_2_8_on_Ubuntu_Debian" style="padding: 4px 0pt 2px 4px; background: rgb(255, 255, 255) none repeat scroll 0% 50%; float: right; margin-left: 10px; margin-bottom: 5px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" frameborder="1" height="82" scrolling="no" width="55"></iframe>Today I switched on my laptop from wxPython2.6 to wxPython2.8 SPE seemed to work quite OK already, except: the bottom panel took too much place and was not draggable to a smaller size. After fixing this annoying bug, I am happily coding now with SPE on wxPython 2.8 For those who want to try out before I release, follow the subversion <a href="http://pythonide.blogspot.com/2007/02/how-to-download-latest-spe-from_26.html">instructions</a>. I tested the new SPE on Ubuntu (wxPython 2.6 & 2.8) and on Windows (wxPython 2.8). If anybody knows a good subversion client for the Mac, please comment.<br /><br />sudo wxPython 2.8 has major new features such as AUI (Advanced User Interface), anti-alias graphics (Graphicscontext) and a lot of new widgets (RichTextCtrl, CustomTreeCtrl, SearchCtrl a la Firefox, ...). This might be useful for SPE in the future, but at the moment SPE stays backwards compatible with wxPython 2.6.<br /><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.ubuntu.com/"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 80px;" src="http://ubuntuforums.org/gallery/data/5/thumbs/ubuntu-powered.png" alt="" border="0" /></a>On Feisty wxPython is already included in repositories, just type:<blockquote><pre>sudo apt-get install python-wxgtk2.8</pre></blockquote>On Edgy you need to use the wxPython coummunity repositories. Open /etc/apt/sources.list:<pre><blockquote>sudo gedit /etc/apt/sources.list</blockquote></pre>Add the following lines:<br /><pre><blockquote># wxPython APT repository at wxcommunity.com<br />deb http://wxpython.wxcommunity.com/apt/ubuntu/dapper /<br />deb-src http://wxpython.wxcommunity.com/apt/ubuntu/dapper /</blockquote></pre>Then copy and paste these lines in a terminal:<br /><pre><blockquote>sudo apt-get update<br />sudo apt-get dist-upgrade<br />sudo apt-get install python-wxgtk2.8 python-wxtools wx2.8-i18n</blockquote></pre>If you want to use XRC gui designer, you need python-xml:<pre><blockquote>sudo apt-get install python-xml</blockquote></pre>Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com8tag:blogger.com,1999:blog-1693831864832387340.post-62911822691397339912007-02-26T13:54:00.003+01:002008-08-07T02:17:57.135+02:00How to download the latest SPE from subversion<iframe src="http://digg.com/api/diggthis.php?u=http://www.digg.com/programming/How_to_download_the_latest_SPE_Stani_s_Python_Editor_from_subversion" style="padding: 4px 0pt 2px 4px; background: rgb(255, 255, 255) none repeat scroll 0% 50%; float: right; margin-left: 10px; margin-bottom: 5px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" frameborder="1" height="82" scrolling="no" width="55"></iframe>If you want to have the latest version of SPE, use <a href="http://en.wikipedia.org/wiki/Subversion_(software)">subversion</a> which is very easy. (Subversion is a way for multiple people around the world to work on the same program. It keeps the changes that they make to the source code of that program in sync with each other.) Do not forget first to uninstall your previous version of SPE! Windows users can uninstall SPE through 'Add/Remove programs' in the Control Panel (look for 'python-spe*', not for 'spe') and use a subversion client (<a href="http://tortoisesvn.net/downloads">tortoisesvn</a>, <a href="http://rapidsvn.tigris.org/">rapidsvn</a>) to get the latest SPE. Linux and mac users need just to copy and paste this in the terminal:<br /><span><blockquote><pre>svn checkout svn://svn.berlios.de/python/spe/trunk/_spe</pre></blockquote></span>This will create a '_spe' folder. (Do not rename it to 'spe' or another name!) From this folder you can run:<br /><span><blockquote><pre>python SPE.py</pre></blockquote></span>To browse the subversion repository online, surf to:<br /><blockquote><pre><a href="http://svn.berlios.de/wsvn/python/spe/trunk/_spe/">http://svn.berlios.de/wsvn/python/spe/trunk/_spe/</a></pre></blockquote><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.ubuntu.com/"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 80px;" src="https://wiki.ubuntu.com/WebsiteButtons?action=AttachFile&do=get&target=ubuntu_button_80x15_shaded.png" alt="" border="0" /></a>For ubuntu: to first remove SPE, type this in the terminal:<br /><span><blockquote><pre>sudo apt-get remove spe kiki wxglade</pre></blockquote></span>To install subversion (svn), type this in the terminal:<br /><span><blockquote><pre>sudo apt-get install subversion</pre></blockquote></span><br />Instructions for Tortoise SVN (thanks Richard):<blockquote><pre>1. Go to the location you want to download SPE to<br />2. Right click -> SVN Checkout<br />3. Paste svn://svn.berlios.de/python/spe/trunk/_spe into the url field<br />4. Click ok and it should work.<br /></pre></blockquote>Stanihttp://www.blogger.com/profile/16059756624190203689noreply@blogger.com