Ikke's Blog

Dec 26
Blog moved

This blog is moved. You can find my new blog on http://eikke.com. Thanks for visiting!

Dec 14
Python strangeness

Could someone explain this?

Code:

list = (
    (0, 'foo'),
    (1, 'bar'),
    (2, 'baz'),
)

class Klass:
    def bat(self):
        print '-1'

for l in list:
    if not hasattr(Klass, l[1]):
        print '%s should print %d' % (l[1], l[0])
        def _f(self):
            print l[0]
        _f.__doc__ = 'Get %s' % l[1]
        setattr(Klass, l[1], _f)

k = Klass()
print
print 'Docstrings:'
print 'Foo:', k.foo.__doc__
print 'Bar:', k.bar.__doc__
print 'Baz:', k.baz.__doc__

print

print 'Executed:'
print 'bat:',
k.bat()
print 'foo:',
k.foo()
print 'bar:',
k.bar()
print 'baz:',
k.baz()

print

print 'Locations:'
print 'bat:', str(k.bat.im_func)
print 'foo:', str(k.foo.im_func)
print 'bar:', str(k.bar.im_func)
print 'baz:', str(k.baz.im_func)

Output:

foo should print 0
bar should print 1
baz should print 2

Docstrings:
Foo: Get foo
Bar: Get bar
Baz: Get baz

Executed:
bat: -1
foo: 2
bar: 2
baz: 2

Locations:
bat: <function bat at 0xb7c58e2c>
foo: <function _f at 0xb7c58df4>
bar: <function _f at 0xb7c58f0c>
baz: <function _f at 0xb7c58f44>
$ python -V
Python 2.4.4

Maybe I'm just missing something... Don't flame ;-)

Nov 9
More Clutter

This afternoon I wanted to implement some custom ClutterActor. I made a very basic actor which is basicly a simple rectangle, like ClutterRectangle, but allows you to define a color for every corner, which are blended by OpenGL.

Like this:
ClutterGlColorRect

I also added a simple animation sequence which changes all corner colors over time, so you get some visual effect, and added some motion effects (a simple rotation around 2 axes). The color changing effect is badly written now, should become a ClutterBehaviour, if possible.

Code is here, it could be a good starting point to learn how to write a custom actor using OpenGL (first time I ever wrote OpenGL code myself, it's not that hard, more experimenting later).

Performance and anti-aliasing is rather sluggish now, but I don't think it's related to my code as doing the same rotations on a single-color ClutterRectangle gives the same result.

Oh: yes, this code leaks at exit.

Enjoy :-)

Nov 8
Clutter reflections

Clutter reflections

See src/view-reflection.c in your local gallery git clone. Suboptimal code, no slideshow (only displays the first picture for a given tag), but well.

Maybe I should try to load images (using GdkPixbuf or something alike), use GEGL to do some transforms on them (more optimized than my hackish filters :-P), then use these transformed images on a Clutter texture...

I wonder how hard it would be to play a movie using clutter-gst and add reflections of it.

Nov 8
Clutter, advanced UI graphics made fun

Today I looked at Clutter, a nifty "rich UI" creation library using OpenGL and the like. After playing around with some of the samples, reading some API docs and writing one dumb simple text-rotating application (think Windows' text-message screensaver, you know), I wanted to make something more advanced (hum-hum).

I decided writing some photo slideshow application would be cool. We already have several of those, obviously, remember this is just a playground.
Having some sort of F-Spot (a great photo management application) integration would be nifty too, so I started with that: loading taglists and picture-paths for one tag. In the end it turned out writing that took more time than writing the simple view I created.

Next I wrote the Clutter driver code and some system to be able to easily switch view functions. I only implemented one so far, which just fades between images (in, out, next image in, out etc) and stores the GdkPixbuf's in a ringbuffer. Not optimal, no cleanup code yet, jadajadajada.

No screenshots as a static screenshot would not be very impressive (the current application neither but hey ;-)).

Anyway, it might be useful as a sample/basic Clutter application for some people. You can find the source code, clone URL and compilation instructions here. If you implement some nifty view, share it!

Enjoy.

:: Next Page >>

Categories

Who's Online?

  • Guest Users: 416

Misc

XML Feeds

What is RSS?