Python

Select a Python code block in Geany with Lua

Veröffentlicht in Kategorie Coding, Computer, Lua, Python am 4. April 2014 von Chris – Ersten Kommentar schreiben

Here’s a nifty little Lua script for the Geanylua plug-in for the Geany text editor: install it into your ~/.config/geany/plugins/geanylua folder and add the name of the script to ~/.config/geany/plugins/geanylua/hotkeys.cfg to allow binding it to a keyboard shortcut (I use Ctrl-Alt-b, see the Geanylua documentation for more information on assigning keys to scripts).

When the script is activated, it will select the block corresponding to the current code folding level of the line the cursor is on in the active document. E.g. if you place the cursor in the body of a Python function on a line that is on the same indentation level as the first line of the body of the function, it will select the whole function. Also, if the cursor is on the opening line of a block, e.g. a line starting with class, def, if, etc., the script will select the block started by this line.

Note: this strategy does not work well in conjunction with functions preceded by a decorator, since the selection will not include the decorator line. For this reason, the selection is inverted, i.e. it starts at the end of the block and ends at the beginning. This means you can hold down shift and move the cursor backwards, and the selection will extend from the beginning of the block backwards, instead of the end of the selection being shortened as it would be for a normal selection.

Here’s the code of the Lua script as a Gist:

The script makes use of some Scintilla messages, which are only accessible in Geanylua via the geany.scintilla() function. The available messages are documented here.

Get the gist of it

Veröffentlicht in Kategorie Coding, Computer, Python am 11. Februar 2014 von Chris – Ersten Kommentar schreiben

Some months ago I finally caught up with modern development practices and switched to Git for new software projects. I even now use my GitHub and Bitbucket accounts more often, e.g. for collaboration projects, though I host my own projects on my own server with the help of Trac and gitosis.

One thing I do like about GitHub though, are Gists. Like many good ideas this one makes one wonder, why nobody came up with it before. Basically Gists are code snippets you publish on the web (like in a pastebin) but they are under version control and each Gist is its own mini git repository. They let you share programming ideas and nifty little tools with the rest of the world with ease and others can easily take them and comment, expand or correct them. The revision control makes it clear, what developed from where and who did what. Finally, your Gist page on GitHub serves as a central place, where you can browse, search and present all these digital scrap notes.

It is also very easy to include Gists in your blog, which is what I’m starting with this post.

Weiter lesen »

Audiosignalverabeitung mit Python

Veröffentlicht in Kategorie Coding, Computer, Musik, Python, Verschiedenes am 28. Februar 2011 von Chris – Ersten Kommentar schreiben

Wie man an einzelnen Beiträgen in diesem Blog sehen kann, beschäftige ich mich seit einiger Zeit verstärkt mit Soundsynthese und Audioprocessing. Als bekennender Fan von Python habe ich mich mal nach Tools für die mathematische Analyse und Verarbeitung von Audiosignalen in Python umgesehen und möchte hier mal meine Recherche-Ergebnisse vorstellen.

Weiter lesen »

Impromptu first beta

Veröffentlicht in Kategorie Ankündigungen, Coding, Computer, Python am 21. Januar 2011 von Chris – Ersten Kommentar schreiben

I was recently researching into GUI libraries for PyGame when I found pyglet, which is an alternative to PyGame for 2D/3D graphics programming with Pyython. It has no dependencies other than a standard Python installation and OpenGL, the API is well-structured and the documentation clean and extensive.

So I wrote a little demo application, which displays a pseudo-HTML file in a window and scrolls it up- or downwards with speed controllable by simple keyboard commands. Sort of like a teleprompter. You can use different fonts, colors and sizes through the subset of HTML4 supported by pyglet.

I thought this made be useful for others, for example when recording a podcast, webcast or an audiobook or when doing a presentation, so I baked a Python distribution package and put it on the Python Package Index.

So here’s to you: Impromptu 0.1b

Impromptu running in window mode under Ubuntu Linux

Impromptu running in window mode under Ubuntu Linux

Share & Enjoy!

Python BarCamp Köln am Samstag, 17.4.2010

Veröffentlicht in Kategorie Ankündigungen, Events, Python am 14. April 2010 von Chris – 2 Kommentare

Am diesem Samstag organisiert unsere lokale Python User Group den ersten Python BarCamp in Köln. Da dies eine sogenannte Unkonferenz sein soll, bei der die Teilnehmer das Programm größtenteils selbst organisieren, wäre es schön, wenn einfach jeder, der Lust hat teilzunehmen, vorbeikommen könnte. Leider müssen wir aber aufgrund der Beschränkungen der Räumlichkeiten die Teilnehmerzahl auf 30 begrenzen. Es sind aber noch einige Plätze frei! Deshalb habe ich gerade folgende Nachricht an verschiedene deutsche Python-Mailinglisten und Gruppierungen geschickt:
Weiter lesen »

How to create a new ticket in Trac from a script

Veröffentlicht in Kategorie Coding, Python am 26. Februar 2010 von Chris – Ersten Kommentar schreiben

This is just a note to myself and to spare someone, who faces the same task, going through the Trac sources to find out how to do this:

from trac.env import open_environment
from trac.ticket.model import Ticket

# A list of email addresses or trac user names
NOTIFICATION_LIST = ['randomhacker', 'boss']

ticket = Ticket(open_environment('/path/to/trac/env'))
ticket.populate(dict(
    component = u'My component',
    type = u'task',
    status = u'new',
    summary = u'Make the world a better place',
    reporter = u'me',
    # Set owner to default for given component
    owner = None,
    # You can use Trac wiki syntax here
    description = u"Don't ask '''me''' how to do it...",
    cc = ",".join(NOTIFICATION_LIST))
)
ticket_id = ticket.insert()

That’s all!

Update 2010-03-01: Naturally, after I figured this all out by myself by looking through the Trac source, I found this similar explanation on the trac wiki.

TurboGears 1.1 final(ly) released into the wild!

Veröffentlicht in Kategorie Coding, Python, TurboGears am 5. Oktober 2009 von Chris – 1 Kommentar

(A note to German readers: Artikel über Open Source, Programmieren und Software im Allgemeinen werde ich auf Englisch schreiben, da dies in meinem Kopf irgendwie so verdrahtet ist. Darüber kann ich gar nicht auf Deutsch schreiben ;) )

After releasing the 1.1rc1 release candidate two weeks ago, which seemed to have no major issues, and fixing a few remaining stumbling blocks, I am now proud and relieved to say, that TurboGears 1.1 final is finally out the door!

Weiter lesen »