Archive for the ‘Geek’ Category

(on Technorati , Del.icio.us)

python treeview toggle

Had this post sitting around. Seems finished. May be helpful to someone. /me waves Wand of Publish +1

I was confused when I was playing around with this basic concept: adding a toggle widget to the treeview in pygtk. The reason for this is an inconsistency in the api model – or at least how I perceived it. With a regular toggle button, you create the widget and can manipulate it once it is drawn. The checkmark is toggled and the “toggled” signal is emitted. I only connect a signal handler to the toggled signal after. However, following this same logic, I created a list with a column of toggle widgets and tried clicking them… but nothing happened. The problem here was the toggled value was linked to the list’s data, and the data wasn’t actually changing. Even though the toggle signal was being emitted, the checkmark wasn’t being toggled because the data wasn’t changing, so I thought there was a problem with my code and the signal wasn’t being emitted. But actually, it would make more sense if it was a “clicked” signal that was being emitted, not the “toggled” signal.

Example source code:

#!/usr/bin/env python
 
# example basictreeviewtoggle.py
 
import pygtk
pygtk.require('2.0')
import gtk
import gobject
 
class BasicTreeViewToggleExample:
 
    # close the window and quit
    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        return False
 
    def column_toggled(self, cell, path, model):
        # get toggled iter, and value at column 0
        iter = model.get_iter((int(path),))
        val = model.get_value(iter, 0)
 
        # toggle the value
        val = not val
 
        # set new value
        model.set(iter, 0, val)
 
 
    def __init__(self):
        # create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Basic TreeView Toggle Example")
        self.window.set_size_request(200, 200)
        self.window.connect("delete_event", self.delete_event)
 
        # create a ListStore with two columns to use as the model
        self.model = gtk.ListStore(gobject.TYPE_BOOLEAN, str)
 
        # create some list items
        for item in range(5):
            self.model.append([False, 'item %i' % item])
 
        # create the TreeView using the model
        self.view = gtk.TreeView(self.model)
 
        # create a CellRendererText to render the data
        self.cellrenderer_text = gtk.CellRendererText()
        self.cellrenderer_toggle = gtk.CellRendererToggle()
        self.cellrenderer_toggle.connect('toggled', self.column_toggled, self.model)
 
        # create the TreeViewColumns to display the data
        self.tvcolumntext = gtk.TreeViewColumn('TreeViewColumn 1')
        self.tvcolumntoggle = gtk.TreeViewColumn('tog', self.cellrenderer_toggle, active=0)
 
        # add the TreeViewColumns to the TreeView
        self.view.append_column(self.tvcolumntoggle)
        self.view.append_column(self.tvcolumntext)
 
 
 
 
        # add the cell to the tvcolumn and allow it to expand
        self.tvcolumntoggle.pack_start(self.cellrenderer_toggle, False)
        self.tvcolumntext.pack_start(self.cellrenderer_text, True)
 
 
        # set the cell "text" attribute to column 0 - retrieve text
        # from that column in treestore
        self.tvcolumntext.add_attribute(self.cellrenderer_text, 'text', 1)
 
 
 
        # make it searchable
        self.view.set_search_column(1)
 
        # Allow sorting on the column
        self.tvcolumntext.set_sort_column_id(1)
 
        # Allow drag and drop reordering of rows
        self.view.set_reorderable(True)
 
        self.sw = gtk.ScrolledWindow()
        self.sw.add(self.view)
        self.window.add(self.sw)
 
        self.window.show_all()
 
def main():
    gtk.main()
 
if __name__ == "__main__":
    tvexample = BasicTreeViewToggleExample()
    main()

Creating a DVD Slideshow in Linux

For my brother’s wedding, about a week ago, my sister wanted to do a slideshow for them. She’s done this before and she’s known for spending lots of time making very nice, emotional slideshows with carefully chosen pictures and music. Previously, she would count in her head while manually switch the slides with a traditional projector. (We have a lot of great family photos that are only on slides.) Anyway, she figured she’d use computers this time around and my assistance was “enlisted.” I kept thinking, “If only I had a Mac, I’m sure this would be easy….” But it turns out there’s a reasonable command-line program available on Linux that is just a little cumbersome (mostly because it’s command-line tool for something that really needs to be visual) – but works quite well: dvd-slideshow. I’m going to go over what I did, mention some quirks and how to work around them.

First, install dvd-slideshow (a set of command-line tools).

sudo aptitude install dvd-slideshow

You may want to get the latest version from the webpage and manually install that.

Update: While writing this, I have since discovered “slcreator” which looks like it would fill in the glaringly absent graphical component of dvd-slideshow. Though it hasn’t been updated for quite a long time…. it’s definitely worth investigating before going through the manual process yourself.

Step 1: Organize your digitized photos within a directory

Since my sister was the creative force behind this, she needed to see the photos as she was deciding on the order. Nautilus thumbnails were good enough, so I simply showed her how to rename files and made suggestions for organizing them by name (like naming a photo “12a.jpg” if you want the photo to be in between “12.jpg” and “13.jpg”). This worked in Nautilus, but in the next step, the ordering would be changed to 12a.jpg, 12.jpg, 13.jpg – which is probably a bug in dir2slideshow. (You could work around this by always using a single letter after the number.)

Step 2: Generate input file from images directory and customize

dir2slideshow -o output_directory -t seconds_per_picture -c crossfade_seconds images_directory

This will output a text file in the output_directory that contains all the images in the images_directory with specified transition and duration times. The order of the pictures should be how it is listed by name in your file browser, minus the bug I mentioned earlier. You can manually edit this file and then pass it to dvd-slideshow.

Multiple Directories:
My sister had arranged photos in multiple directories, each consisting of a theme (childhood, Halloween, travel, etc) and a specific song to go with it. So I just generated multiple input files with appropriate names, worked on individual sections, and eventually copied them all into a master input file keeping the desired order.

Adding Music and Silence:
Another bug I encountered was getting music to fade out at the correct time. In the input file, the format for adding music is this: audiofile:track:effect1:effect1_params:effect2:effect2_params . So I had my_sad_song.mp3:1:fadein:0:fadeout:5 saying I wanted it to spend 5 seconds fading out. Additionally, I wanted about 10 seconds of silence at the very end. Your are supposedly able to specify silence:duration_in_seconds but at the end of the slideshow, it wasn’t forcing the song to fade out in time to include that amount of silence – it seemed to be ignoring it at the end if there was no more photos. I got around this by creating a small file of silence, silence.wav, and using that instead of the built-in silence option.

Nice looking fonts
Another quirk I encountered was terrible looking fonts with the built-in title:duration:thought_provoking_title. I didn’t want to spend too long looking at the cause of this, so I just created some title images in the Gimp.

Step 3: Generate the Slideshow

dvd-slideshow -mp2 -nomenu -o tmp/working -f tmp/ALL.txt

The mp2 option is required to avoid an error message and has worked on all DVD players I’ve heard of, so far. The nomenu option is for creating a DVD with no menu – I just wanted it to start playing the slideshow when the disc is inserted into the player. The o option specifies the output directory and the f option specifies the input file created earlier. Once this finishes (it might take a while) you should have a DVD .vob (MPEG2) file and an xml file in the output directory.

Debugging:
I like to see how the final product will look, so I chose not to use the L (low quality) option for debugging. Instead, I created a smaller input file with specifically what I wanted to test. When I was happy with the test, I copied the changes into my master input file.

Step 4: Create the DVD Filesystem

dvd-menu -f tmp/working/ALL.xml -nomenu -mp2 -o tmp/working-dvd

This will output a folder dvd_fs in the output folder (tmp/working-dvd) containing VIDEO_TS and AUDIO_TS directories with the required files for a proper DVD.

Adding Content:
This is where you optionally add more files to the DVD. For me, I added two folders, Music containing the music used in the slideshow and Photos containing the photos used in the slideshow. A good idea would also be to add the source file and commands used to create the DVD and then you are distributing the source. ;)

Step 5: Make an ISO to burn

mkisofs -dvd-video -udf -o ~/Desktop/slideshow.iso tmp/working-dvd/dvd_fs

This creates an ISO called slideshow.iso on the desktop.

Step 6: Burn the ISO

There’s many ways to burn an ISO, but just use Nautilus: right click on the icon on your desktop and select Write to Disc…. That’s it! Test it out in your DVD player.

References

Lots more info about specific commands and useful examples can be found at the dvd-slideshow’s documentation page.

Playing Video from your Linux PC on your Wii

Maybe you’ve watched youtube videos on your Wii using the Internet Channel or the promo videos on the Nintendo Channel and you thought it would be cool to watch other videos from your (Linux) PC. I know I did. But I wasn’t sure if it would be possible in a reasonable quality. Since then, I’ve decided the quality was unacceptable for me… But I’ll try to quickly document what I did for others.

You basically have two options: Put a decompressed copy of your video on your SD card and watch it in the Photo Channel OR watch it streaming from your PC over your network via the Internet Channel (like youtube).

1. Playing it directly off your SD card

Instructions for how to convert the video to play in the Photo Channel can be found here:
http://icculus.org/~dolson/wii-video-conversion.html
HOWEVER, 3/4 of an hour of decent quality video will cost 1+ gigabytes, due to the format. The quality will be maintained, but unless you have a 2GB card and/or small videos, this may not be feasible. I couldn’t get my 45min (350MB originally, I think) file to fit on my 1GB SD card in the appropriate format, so I gave up on this method. I was more interested in browsing multiple files on my PC, anyways.

On to the other option….

2. Stream it from your computer

For this method, you need a few more things:

  • A home PC accessible from the network via your Wii
  • Videos you want to play need to be converted to Flash video (FLV). To do this, you will need ffmpeg.
  • sudo aptitude install ffmpeg
  • Web server running on your home PC. I’m using Apache on an Ubuntu PC.
  • sudo aptitude install apache2 apache2-utils

Most of what follows can be configured, but I’m going to try and follow what’s default in Ubuntu (if I can remember correctly).

To keep things clean, I enabled user directories. To do this, you must enable the userdir mod in apache:

sudo a2enmod userdir

What are user directories?

This is a directory (usually called “public_html”) that every user can use to publish things (like webpages) on the webserver from their home directory. For me, my home directory is /home/steve/ so my user directory is /home/steve/public_html/ . It is optional, so I have to create it if it doesn’t already exist.

mkdir ~/public_html/

When accessing these user directories via a web browser (Internet Channel), you must enter your Home PC’s IP address, followed by a tilde (~) and your username.

"http://your.pc's.ip.address/~username/"

So accessing my public_html directory is done as follows: http://192.168.0.99/~steve/ . (Note that 192.168.0.99 is a private IP address and unless your computer is set up on your local network with the same IP AND your username is “steve”, this won’t work for you. ;-) )

Test it, and make sure you’ve installed Apache and set up user directories correctly.

Flash Video Player

Now you need a compatible flash player to embed into your webpage. Wii’s Internet Channel is based on Opera, and includes Flash version…. 7?! Doh! Newer FLV players won’t work! Also, Full-screen mode isn’t possible so you want the video to be as large as possible, or to be easily zoomed in and centred – yup, it’s a pain. The best player I found for this was FLV Player, but feel free to look around for more. ;) Now put your player of choice (I chose player_flv_maxi.swf) in public_html somewhere so that it can be included in your webpage.

Example Preparing Video

An example command for converting your video to FLV using ffmpeg:

ffmpeg -i input_video.avi -ar 22050 -b 1280 -s 320x240 output.flv

Example Webpage

An example of an html page containing a video:

< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 
	<title>Wii Video Test</title>
 
	<style type="text/css">
		body { background-color: #000; padding: 0 20px; color:#000; font: 13px/18px Arial, sans-serif; }
		a { color: #360; }
		h3 { padding-top: 20px; }
	</style>
 
</head>
<body>
 
    <object type="application/x-shockwave-flash" data="player_flv_maxi.swf" width="624" height="352">
        <param name="movie" value="player_flv.swf_maxi" />
        <param name="allowFullScreen" value="true" />
        <param name="FlashVars" value="flv=my_converted_video.flv&amp;autoload=1" />
    </object>
 
</body>
</html>

Note: both player_flv_maxi.swf and my_converted_video.flv must be in the same directory as this html page. For testing purposes, call this index.html and put it in your public_html directory.

That’s it, I think. Again, I wasn’t really satisfied with the compression of FLVs and the frame rate of bigger videos, so I ended up not using either of these two methods. I suppose a media PC, Apple TV, or PS3 or something would be better suited – none of which I have. :)

Related

AttrDict Python Module

I’ve been doing quite a bit of Python hacking in my recent free time. A couple days ago, I had the desire for a dictionary that I could access key values just like object attribute names. For example, in the dictionary d={'key':'value'}, I wanted to be able to use d.key to return 'value'. I thought this would be a common desire and probably already exists (and might even be built-in somehow), so I went on to #python and asked the folk there. Nobody knew of anything. So I set off to write my own. I called it AttrDict.

Yesterday, I found something similar already exists. It’s called ObDict. Similar? Very! :P But different enough that I continued mine… and have a somewhat complete python module of my own. So far it’s been a nice opportunity to learn more about Python objects and use the unittest module for unit testing.

It’s not 100% coverage of the dict interface, but it’s pretty close and I think it’s usable enough that I can slap a quick release together and work on other stuff. Bugs/patches/testing/suggestions welcome.

Update:

Wooops, forgot to write a bit more about it. Here’s the docstring from the module:

Simple extension of the built-in dictionary so that dictionary keys are mirrored
as object attributes. This is for convenience. You can do things like this:

d = dict() #standard dict, for comparison
a = AttrDict() #

d['ok'] = ‘this is ok’
d.ok -> AttributeError raised
d.ok = ‘test’ -> AttributeError raised

You cannot assign attributes to standard Python dicts.

a['ok'] = ‘this is ok’
a.ok -> ‘this is ok’ #attribute is automatically created
a.ok = ‘changed’
a['ok'] -> ‘changed’ #and the dict value is automatically updated
a.ok2 = ‘new value’ #adding new attribute, ok2
a['ok2'] -> ‘new value’ #dict key is automatically created

This introduces a limitation on the dictionary keys such
that they must be strings and provide valid Python syntax for accessing.

For example:

{’123′:’valid’} #is a valid dictionary

but

mydict.123 #is not valid Python syntax.

Attempting to create a key that cannot be accessed through an attribute name
will raise an AttributeError Exception.

This module has not been built for optmization. Some of the method
documentation has been taken from Python’s dict documentation. For more info
on a particular method, refer to that. I’ve tried to mirror the effects of
the standard dict as closely as possible.

Recent Geekiness

Hmmm… I’ve been pretty quiet on the blog front. Better write something. Show some sign of life. Well, officially 2 weeks of not being gainfully employed and I’ve been making pretty good use of the time, I think! (I know, you’d expect more blog posts from someone who has more time – I’m weird). Even though I haven’t been blogging much, I *have* kept fairly active in Twitter, so if you follow that, it’s kind of like my mini-blog.

So what have I been doing? Naturally, most of my time has been spent on the computer. I finished a tool (written in Python) that I had started in the last week of employment – both for personal satisfaction and for the benefit of a (ex) colleague. I think it will be useful, and that makes me happy. :)

Warning: the following is quite long and geeky. Feel free to skip to the end.

Distributions and Open Source 3D

I’ve done a lot of poking around with my computer, fixing lots of problems (and creating a few others). The most serious of these problems was my wireless connection, which appeared to die somewhat suddenly. I ended up trying multiple other Linux distributions over the course of resolving it. OpenSUSE had a nice polish to it, but I found the interface kind of cluttered. They seem to use their YaST back-end for everything configuration-related. Fedora 9 was really well organized and pretty, I was generally very impressed. But the best thing about Fedora 9? 3D acceleration worked when I booted it up! Even on the live CD! Not only that, but because of Fedora’s “Free” motto, this was the open source (ATI Radeon) driver! WHAT?! I couldn’t even get the proprietary (Catalyst) driver to work on Ubuntu!

Obviously, I had to do some more research. I found out that Fedora runs a lot of software that hasn’t been released as “stable” quite yet. Well guess what I’m running on my Ubuntu now? That same software. I’ve noticed my computer crash a few times when I leave certain other experimental software running for a while, but other than that, it’s stable enough for me to keep and enjoy the perks of 3D every now and then. But I certainly can’t advise it unless you’re willing to suffer the consequences – of which, there could definitely be. (I can’t use the closed source drivers, they somehow break my computer.) You could make a bootable thumb drive to test it out first. I did. Start here.

Performance, Games, and Screencasting

I guess I should talk about that. I read someone say the performance of the open source driver (radeon) is about 40% of the closed source driver (fglrx). 3D effects on the desktop work pretty good, but I can’t play FPSs (First Person Shooters) like Sauerbraten – an open source Quake-like game. In fact, I can barely play “Extreme Tux Racer.” Kinda sad. :( But I can play Neverball and CriticalMass! :) Oh, and I can kind of play Frets on Fire, an open source Guitar Hero clone (has a pretty funny tutorial). So the open source drivers aren’t as feature complete or as high performance as the closed source ones, but since AMD/ATI have become more open, releasing documentation and helping out the community, the open source drivers have been quickly closing the gap. This is very exciting for me. :)

Anyway, enough of that.. I spent a lot of time playing around with 3d and getting my wireless to work again. And the primary solution to my wireless problem? Turning the wireless router upside down. It still cuts out every now and then, but it’s mostly solid now (although maybe a bit slower, due to some buggy drivers). yay. No Internet makes Steven cry. (I really wish I could run a cable to my room….)

I resolved connection problems with my printer (yet again). Oh, and I also set up mic recording and tested making screencasts. I want to use Istanbul, but it seems to have more problems and fewer options than gtk-recordMyDesktop. I was considering making screencasts, as video tutorials for introducing people to GNOME or other simple things. I’ve written down a few ideas, but I’m not sure where that will go. I would like to do it as a kind of mini series with a bit of polish, but I’d have to look into the somewhat shady world of Linux video editing.

Packaging

For some reason (perhaps I’m a bit of a masochist) I decided to learn about Debian packaging (creating those lovely .deb files that us Ubuntu users find so handy). My pain was further enhanced by choosing to package a library (Clutter), rather than a normal application. I found the documentation available to be overly verbose and not particularly plentiful – I suppose I wanted something concise and never found it. When I had finally produced two packages (the lib binary and the accompanying dev package) I could install on my system, I didn’t bother because a few other libs depended on the library I was updating, and I was tired of packaging. And I didn’t really want to create an even more unstable system. ^.^ But even though I didn’t use my packages (which I’m sure were far from “Debian” standards) I found the whole thing quite educational and I’m glad I went through it. I have a new respect for package maintainers and perhaps I can now package my own software (if I get around to writing something worth packaging). :)

The non (less?) Geeky

Aside from all that geeky stuff, I’ve been spending a bit of time with friends and family, and doing lots of rollerblading. Played RockBand at Jeremy’s birthday on 360. Sung til everyone’s ears bled. Drums are fun. That game is seriously fun. It just came out for Wii, but I think I will wait for the next Guitar Hero which promises even more and should be out in Fall. More is better, right? I like more. Oh and I still have to push out that blog post about my roadtrip….

Upgrading

Ubuntu Hardy Heron is out! [ Features | Download ]

If I disappear for a while, something probably didn’t go smoothly. I almost expect a problem with my wireless drivers… :/

*click*

Update: As I anticipated, my desktop had (and is still having) some troubles with the wireless. I’m currently able to connect to the Internet… but barely. I have an RaLink 2500 PCI card. For the previous version of Ubuntu (Gutsy) I was using the CVS version of this driver, because the one included in Gutsy was broken. This driver is being combined with a few other drivers and being rewritten as a unified driver, the rt2x00 driver. The good news is that this unified driver have been included in the kernel and they’re actively developed. The bad news is that (for me) they barely function. I tried using the windows driver through ndiswrapper, but that didn’t seem to work. I tried compiling the old CVS drivers again, and they don’t seem to work any more. So I’m back to the included driver in Hardy that limps along….

On the laptop side of things, everything went peachy… until I decided to try the binary NVIDIA drivers again (to play with 3D things). That was utter fail, and I remembered why I disabled them. But then.. my sound stopped working….? huh?

Temptation to do a fresh install rising.

Update 2: I’m not going to hold my breath on my desktop’s connection, but it seems to be doing better. Also, I solved the sound problem on my laptop. And I set up my tablet. Whoo!