This is

as days pass by, by Stuart Langridge

. Here I write about many things. In the past I wrote about other things but the past is past. I write code for people to play with, I write about my life on Twitter, and I write here.

On I wrote Simon Tatham's Portable Puzzle Collection Launcher, on the subject of Software, Howtos, and Linux.

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).
Tom Moitie

Damn you, I've now become completely addicted to "Slant". I think I deserve compensation :)

Ian

Thank you.

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

sil

Ian: thanks for the correction!

This website belongs to Stuart Langridge. Contact details are available. Don't eat yellow snow. Valid HTML5, at least in theory, except for the bits that aren't because I'm that futuristic that I'm ahead of the spec, oh yes. HTML5 help from Bruce Lawson, among others. Fonts from the superb FontSquirrel. End.