Tuesday, October 29, 2013

kdev-python update: version 1.5.2 released

I'm happy to announce the availability of a second stabilization update for the 1.5 series of kdev-python, the Python language support plugin for the KDevelop development environment. See the 1.5 announcement for more information.
kdev-python version 1.5.2
http://download.kde.org/stable/kdevelop/kdev-python/1.5.2/src/kdev-python-v1.5.2.tar.xz.mirrorlist
SHA256:84ae7015623a3848b1c1ce8e8f958c32778e9ba0afafa3ea3b3dd70687e1fe40

The kdev-python 1.5 series is compatible with KDevelop 4.5 (kdevplatform 1.5) and is suitable for working with Python 2.x source code.
If you're only interested in using (as opposed to packaging or developing) kdev-python, you should consider installing kdev-python from your distribution's package manager instead of downloading the source code.
kdev-python running in KDevelop master
Changes in this release (relative to 1.5.1):
  • Fix a bug which led to the PEP8 checker running on non-python files in some cases
  • Properly support unicode docstrings (thanks to Alexandr Zamaraev)
  • Fix a crash in code completion which happened in some rare cases
  • Fix a crash which could happen when a list comprehension was used as the default value for a function parameter
This is a small update containing only the above 4 bug fixes; all users are urged to switch to the new version as soon as it becomes available in their distribution.

There will be a larger update containing various cool new features in a few weeks, so stay tuned!

Monday, October 28, 2013

kte-collaborative 0.2: First stable release of the collaborative text editing project

I'm pleased to announce the first stable release of kte-collaborative, which provides collaborative text editing in kate through kde-telepathy, and an update to the libqinfinity library.
libqinfinity version 0.5.2:
http://download.kde.org/stable/libqinfinity/0.5.2/src/libqinfinity-v0.5.2.tar.xz.mirrorlist
SHA256: 739f99afb7fd464e4b541e2980e07911c8f30924f9871f14294dc3148137825a

kte-collaborative version 0.2.0 (aka 0.2):
http://download.kde.org/stable/kte-collaborative/0.2.0/src/kte-collaborative-v0.2.0.tar.xz.mirrorlist 
SHA256: 06c8cfb16b93a8fe3c5e2267ba3f71110526966267f73fed20a902c3f7982a55

kte-collaborative 0.2 depends on kde-telepathy 0.7 beta or later, and works with libinfinity 0.5.x.
kte-collaborative 0.2, with dolphin listing some files from gobby.0x539.de and editing a file in kate.
There have not been many noteworthy user-visible changes since the last beta release, so please to refer to the 0.2 beta announcement for more information. As always, please report any bugs you find to bugs.kde.org!

Wednesday, October 23, 2013

Advanced code completion filtering in kate / KDevelop

I have implemented two new ways to filter the code completion popup in kate: filtering the list using an abbreviation, and filtering the list using text not occuring at the word's beginning. This can probably best be demonstrated by lots of pictures:

You can match completion items by their abbreviation. This works for both camel case and underscore notation.

You can also match entries by words they merely contain but do not start with. This matching is only allowed at word borders (capitals or underscores). This feature makes it far easier to find that damn class which has an unexpected name prefix, or the m_foo variable you thought was called foo.

The abbreviation expansion engine also allows you to type parts of the words from the abbreviation, making your search more specific in a convenient way.
This feature is not specific to kdev-python, it works in all kate-based apps. It is available in kate's master branch, and will be available in KDE SC >= 4.12.

If you have more suggestions or cases which are not handled well, I'm happy to discuss this further. Have fun hacking!

P.S. If anyone can come up with an efficient algorithm for doing what is depicted in the last image, I'd be interested. The current one is quite slow for some corner cases.

Sunday, October 6, 2013

Extracting text from Photoshop (PSD) images

I just needed to grab text from some Photoshop images and put it into a LaTeX document. But, how do I get that text on Linux? GIMP can't do it, nor can any other program I tried (they all rasterize the text). Fortunately the text is just saved in plain in the .psd file, so it's relatively easy to get it out of there. However it's in utf-16, so with just grep it's quite painful. Here's a little Python script which finds and decodes text from psd images (inline version below). You use it by passing it the .psd file, and the beginning of the text you want to find, and it'll give you the rest.
python psdtextextract.py myimage.psd "This is"
will result in "This is a text layer." if that's the text your layer indeed contains. To find a sample of the text you can use any image viewer such as gwenview. Quite stupid, I know, but it works ;)

Inline source code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from codecs import encode, decode

def get_next_occurence(text, buf, start):
    text = encode(text, "utf-16")[2:] # cut BOM
    index = buf.find(text, start)
    if index == -1:
        return b"", -1
    end = buf.find(b'\x00\x00', index)
    if end == -1:
        return b"", -1
    chunk = b'\x00' + buf[index:end + 2]
    return chunk.replace(b'\x5C', b''), end

def get_all_occurences(text, buf):
    start = 0
    items = []
    while start != -1:
        try:
            found, start = get_next_occurence(text, buf, start)
            items.append(decode(found, "utf-16be").replace('\r', '\n'))
        except UnicodeDecodeError as e:
            continue
            print(" - undecodable match skipped:", e)

    return items

if __name__ == '__main__':
    import sys
    if len(sys.argv) > 4 or len(sys.argv) < 3:
        print("Usage: psdtextextract.py file.psd pattern [display-all-matches]")
    with open(sys.argv[1], 'rb') as f:
        items = get_all_occurences(sys.argv[2], f.read())
        if "display-all-matches" not in sys.argv:
            print(items[0])
        else:
            for item in items:
                print(item)