This is as days pass by, by Stuart Langridge

Hackergotchi

Would someone better with the Gimp than me like to do me a hackergotchi for Planet Gnome? I've been meaning to do it for ages and not got around to it. This snap at Flickr seems like a good candidate, but go wild if you can think of a better one (CC-derivs-licenced Flickr pics of me as a starting point :))

Editing a PDF (sorta) on Ubuntu

I have more than once had to fill in a paper form for people in America. Obviously, doing such things is a huge pain, because actual paper mail -- with stamps -- isn't just so last century, it's the century before that. You know, the one with robber barons and Lord Kelvin and workhouses. Put a stop to it. Email. Email, I tell you. It's gonna catch on, just you wait. Anyway, a fair few American corporations (and, wouldjabelieveit, the American government too) provide PDF versions of their forms so you can download them and print them out at your leisure. They're still designed to be printed and written on, though -- they're not officially PDF "forms" in the sense that the PDF reader can give you textboxes and an FDF file to fill them in, they're just PDF documents. Nonetheless, I find myself wanting to be able to open them up in OpenOffice.org and edit them. Now, you can't do that. (Well, you might be able to, but it's hard.) All I actually need to do is overtype them. So what I do is:
  1. Convert the PDF to an EPS file with pdftops: pdftops -eps AmericanGovernmentForm.pdf (the pdftops program is in the poppler-utils package)
  2. Create a new empty document in OpenOffice.org and drag the new .eps file onto it, which will embed it as an image
  3. Use Insert | Frame to draw a text frame on top of the new image (set it to have no border; set the background colour to anything other than No Fill and transparency to 100%)
  4. Overtype onto the form in the text frame
  5. Export as PDF to get a PDF version with your text in
  6. Email it to the government
No stamps. Their evil must be stopped.

Overriding a single field in the Django admin, using newforms-admin

Django has been gradually changing the way their automatically-created admin system works to use the newforms-admin code, which makes lots of cool new things possible. However, because newforms-admin is rather new (ha!), it's not brilliantly documented. One of the things I wanted to do today was to make one field use a custom field-editing widget that I'd created, rather than Django's default textbox, in the Django admin system. You do that like this. In newforms-admin, you specify admin options for a model by creating an extra ModelAdmin class for it:
class Vehicle(models.Model):
  colour = models.CharField()
  name = models.CharField()

class VehicleAdmin(admin.ModelAdmin):
  search_fields = ["name", "colour"]

admin.site.register(Vehicle, VehicleAdmin)
Imagine that we wanted to build a custom widget to allow people to choose a colour by clicking on a colour swatch. To do this, you need to actually create your custom widget. So, in a file custom_widgets.py, you create your widget. The easiest way to do this is to subclass one of the existing widgets (TextInput is a good one here, because that's a normal textbox, which is what gets used by default for CharFields) and then change its render method:
import django.newforms as forms
from string import Template
from django.utils.safestring import mark_safe

class ColourChooserWidget(forms.TextInput):
  def render(self, name, value, attrs=None):
    tpl = Template(u"""<h1>There would be a colour widget here, for value $colour</h1>""")
    return mark_safe(tpl.substitute(colour=value))
There are a few interesting wrinkles in there. First, overriding render() changes the HTML that your widget prints when asked to display itself by the admin system. (I haven't actually implemented the widget there; left as an exercise for the reader, that bit.) Second, you need to call mark_safe() on the HTML you return, otherwise the admin will escape it. Third, all input to mark_safe() must be Unicode, hence the u""" at the beginning of the string. The parameter value already is Unicode, but any strings you provide must also be explicitly Unicode strings; otherwise, mark_safe() fails silently -- the string will be escaped. Fourth, you don't have to use string.Template, but it's pretty convenient. Once you've created your custom widget, you have to hook it up to your model. In our example, we need to change VehicleAdmin:
from custom_widgets import ColourChooserWidget

...

class VehicleAdmin(admin.ModelAdmin):
  search_fields = ["name", "colour"]
  def formfield_for_dbfield(self, db_field, **kwargs):
    if db_field.name == 'colour':
      kwargs['widget'] = ColourChooserWidget
    return super(ArticleOptions,self).formfield_for_dbfield(db_field,**kwargs)
The formfield_for_dbfield() function gets called for each of the fields in your model; for the one we care about (colour in this example), override widget in the kwargs and then carry on with the rest of the function, and that hooks it up. That should be it; now, in the Django admin system, your colour field will use your ColourChooserWidget for editing.

Aaron Bockover's Gong-a-Thong Lightbulb Talk Extravaganza

The one, the only, Aaron Bockover points out how great LugRadio Live USA will be when it happens in just over two weeks. Modestly, though, he refrains from mentioning possibly the greatest part of it. Yes, this year, Aaron himself will be taking the prestigious role of orchestrating the Gong-a-Thong, a blizzard of incredibly short four-minute talks. Last year at LRL UK this went down really well -- it's a perfect opportunity for people who don't normally get the chance to speak to stand up and talk for a few minutes about what they've been doing. (Incidentally, if you're coming to LRL USA and you want to spend a few minutes wowing people with stuff, or mentioning your latest project, or ranting and waving your fists in the air about software patents or the bash shell or something, we want you to come and do it -- contact us and let us know. Those of you who were at LRL UK, or have seen pictures, will now be grinning at the thought. You see, it's called the Gong-a-Thong for a reason, and the reason is that the signal for the end of your talk is someone banging a big gong when time is up. And the person doing it, much like the guy at the beginning of the old Rank films, is all oiled up with a thong on. Jono's got a bit more history on how he and I thought up the gong-a-thong, and he's right about the sense of pride we felt last year. This year, Aaron has stepped forward to be the man with the beater and the shiny gold underwear. It's gonna rock like Alcatraz.

Bockonegger

LugRadio Live USA schedule now available

And now we have the schedule for LugRadio Live USA. Go and see and plan which talks you intend to watch!

LugRadio Live USA 2008 schedule

Internet Explorer 8 standards-compliant by default

Dean Hachamovitch on the IEBlog:
We’ve decided that IE8 will, by default, interpret web content in the most standards compliant way it can. This decision is a change from what we’ve posted previously.
This is really good news. The previous decision that IE8 would be IE7 unless you specifically told it to be IE8 was one that I was really quite unhappy with; it ignited discussion all over the web developer world. The reason that this is really good news isn't because IE8 will be IE8 by default (although that's exactly what was wanted): it's really good news because this is an example (the first example?) of Microsoft being prepared to break backwards compatibility in order to do it right. It's an example of trying to take people who are doing things wrong and help them to move into a world of doing it right, rather than bending over backwards to help those doing it wrong and punishing those doing it right. That's been Microsoft policy up to now, and I've always felt it to be penny-wise and pound-foolish; it keeps everyone working, but inhibits progress. This is a fundamental change in policy, based on the new Microsoft interoperability promise. And that's a brave move by Microsoft. The IE team are to be congratulated, because making IE8 default to being as standards-compliant as possible is going to make the web better; it'll be easier to build web sites and web applications that work across browsers, and those applications will be able to do more things. That's bad for lock-in, but it's good for the web as a whole, and that's important. Dean Hachamovitch again:
Shorter term, leading up not just to IE8’s release but broader IE8 adoption, this choice creates a clear call to action to site developers to make sure their web content works well in IE.
What we need to do that is beta releases of IE8 that can be installed alongside previous IE releases. Nobody who's an IE user wants to replace their system browser with a beta, because betas break -- that's the point of betas -- but we do all want to test with them. Allow IE8 to be installed in some form of "standalone" mode in an official, supported, way. The IE team have said in the past that the existing standalone mode is not supported, but if we could have a supported standalone mode then testing is much more likely to happen, and testing is what we need here. (Note: "create a whole new Windows installation in a virtual machine and test IE8 there" is not really what I'm talking about here.) Working with the WINE team to allow IE8 to run under Wine would be pretty helpful, too, especially given that this change in IE's direction is being driven by a promise of interoperability. This bodes well for IE passing the newly-released Acid 3 test, too. Hixie describes how the WebKit team are flying ahead on Acid3 support, just as they did with Acid 2; since Opera are pretty good at supporting recent standards, and the IE team are not only prepared to make serious standards-based decisions but have already committed to passing Acid 3, the Mozilla team might end up being last to pass, which would be a headline they don't want. In short: well done IE team. Now let's see IE8 kick some arse.

NetworkManager and phones and data plans

Dan Williams:
NetworkManager mobile broadband support...can most likely use your GSM mobile phone...if you add the appropriate stuff to the HAL .fdi file.
Blimey, that's excellent. What would be required to get .fdi files for loads of phones into HAL by default, so it Just Works out of the box? For a given mobile phone model, will the serial port always have the same settings, or does it depend on who your phone company is and so on as well? It'd be brilliant to have this all working with no configuration required. (PS. Dan, I couldn't use OpenID to log in to leave this as a comment on your site; it didn't recognise http://www.kryogenix.org/ as an OpenID for some reason.)

Better than Lego?

When I was a kid I played with Lego: specifically, Technic Lego, which is the one with the rods and cogs and whatnot. It occurred to me that it'd be pretty cool to have the Lego people be at LugRadio Live USA with a huge table covered in bits that people could go up and play with and use and look at. They can't make it, though (it's a long way from Scandinavia to San Francisco!). So, what are the cool kids using for building things now other than Lego itself? There was Fischer Technik when I was at school, but I've got no idea whether anyone still uses it; if this was LugRadio Live 1978 rather than 2008 then Meccano would have been good; what else is there? Nominate your favourite building stuff...

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.