Simon Tatham’s Portable Puzzle Collection Launcher

Simon Tatham has written a collection of little puzzles, which are very useful little things to play with when you’ve got five minutes to spare. However, installing the Debian package (sgt-puzzles) doesn’t add the little games to your Gnome menu. I could just add a submenu and loads of .desktop files, one for each app, but I couldn’t be bothered with that. So, a tiny PyGtk program to launch them. This will only work on Debian/Ubuntu because it looks for the dpkg .list file to build the list of packages!

/usr/local/bin/sgt-index:

#!/usr/bin/python
import gtk, sys, os

try:
  fp = open("/var/lib/dpkg/info/sgt-puzzles.list")
except:
  print "sgt-puzzles not installed!"
  sys.exit()

games = [
  os.path.split(x.strip())[1]
  for x in fp if x.startswith('/usr/games/')
]
games.sort()

def startgame(event, gamename):
  os.system("/usr/games/"+gamename+" &")
  gtk.main_quit()

win = gtk.Window()
hbox = gtk.HBox()
vbox1 = gtk.VBox()
vbox2 = gtk.VBox()
win.add(hbox)
hbox.add(vbox1)
hbox.add(vbox2)
count = 0
for g in games:
  count += 1
  b = gtk.Button(g)
  b.connect("clicked", startgame, g)
  if count % 2 == 1:
    vbox1.add(b)
  else:
    vbox2.add(b)

win.connect("destroy", gtk.main_quit)
win.show_all()

gtk.main()

Then just add an item to the menu (right-click the Applications and say Edit Menus).

3 Responses to “Simon Tatham’s Portable Puzzle Collection Launcher”

  1. Damn you, I’ve now become completely addicted to “Slant”. I think I deserve compensation :)

    Tom Moitie
  2. Thank you.

    “Obviously” /usr/local/bin/sgt-index needs to be made executable for this to work.

    Ian
  3. Ian: thanks for the correction!

    sil

Leave a Reply

OpenID is a decentralised authentication system. If you use LiveJournal or Vox you already have an OpenID; just use the URL of your homepage there. See also how to get yourself an OpenID.