|Ned Batchelder : Blog | Code | Text | Site|
» Home : Blog
I've been building a small GUI program with wxPython, and it's mostly a straightforward experience (if you're accustomed to the way GUIs tend to be built). wxGlade helps a lot with building the visible components of the UI. But I was going nuts trying to figure out why my Windows icons didn't look right. I went to the trouble of reading a technote (Icons in Win32) to decide which sizes and depths of icon I needed to provide to get a nice looking taskbar icon and alt-tab icon. But my taskbar icon always came out smeared, clearly having been scaled down from a 32×32 image.
I was ready to start reverse-engineering Windows' algorithm for picking the icon image, when I thankfully decided to look into the wxGlade-generated code first. Here's what it gave me for setting the icon in my main frame:
This clearly seems to be picking a single image from the icon, then setting it as the icon. That defeats the whole idea of a multi-image icon. No wonder Windows seems to be scaling a large image for the taskbar. The .ico bitmap loader probably just picks the highest quality image it finds.
Digging deeper into the wxWidgets docs, I found wxIconBundle and wxTopLevelWindow.SetIcons, and came up with this instead:
This works like a charm, giving me pixel-perfect icons for the taskbar and the alt-tab image. Bliss! I couldn't find much discussion of this issue, or use of these methods in existing code, and I don't know what it does on other platforms, but it works great on Windows.
Part of my continuing effort to help facilitate clear communication among engineers: Things to say when you're losing a technical argument:
I've been getting back into wxPython coding, and have been trying to find a clean example of the Model-View-Controller pattern, but haven't been having much luck. For example, I'd like to have menu commands where the main frame doesn't have to know to invoke a method on the current view. I'd rather that some generic event machinery found that the view could handle the event, and let it do just that.
For a more in-depth review of Inkscape's good and bad points, see Jakub "Jimmac" Steiner's review of Inkscape.
Mongoose is a Python library for handling uncaught exceptions cleanly, and providing some support for incident reporting along the way (motto: "Mongoose catches runaway Pythons"). It looks like one of those small tools for a specialized job that are such a treat in the Python world.
(Via a comment to Ian's good catch all exceptions post.)
First Raymond Chen wrote that exceptions are cleaner, more elegant, and harder to recognize:
So everyone agrees that exceptions (or any other comprehensive approach to error checking) is hard.
In response to Max, Ian Bicking writes about good catch all exceptions:
If you find yourself following URLs that have fragment identifiers (you know, the part after the "#" hash mark), and they take you to the right page, but not the right place on the page, then most likely the page you've landed on has images without width and height attributes. The browser loads the page, and finds the spot identified by the fragment id, but then the images load in, and move the page around underneath you.
The fix is to make sure all of the images on the page have width and height attributes. That way the page is laid out correctly even before the images are loaded, and the fragments will work properly.
As you may have already guessed, I updated my blog software to add width and height attributes to all my images. Using Python Imaging Library, it was a piece of cake. Links to particular blog entries on this site will now work much better.
So far, we've survived what is being termed "Blizzard '05". We got between two and three feet of snow, including drifting:
Compare it to my Snowcakes picture of two years ago.
The town of Brookline (like the city of Boston) has closed school for two days, which seems completely unwarranted. Better safe than sorry, I guess.
There are updates available for two free graphics packages I use on Windows: Picasa (a photo organizer), and The GIMP (the GNU Image Manipulation Program).
Picasa 2 is out, and it has a bunch of new features. Since being acquired by Google, it is free, so why not run it? And no, I don't know what Google plans to do with it. It has a Blogger button, but buying Picasa seems a long way for Google to go to get a little Blogger integration.
I finally implemented a categorization scheme for this blog. It was interesting going back over the last three years and trying to see patterns in the posts. In the end, I created 77 categories, some of which I couldn't have predicted. I didn't realize I'd made 12 posts about Lego, for example. And going through the movie posts, I almost made a separate category for The Matrix.
As of now, I haven't actually categorized everything. There are still lots of uncategorized posts, because it's hard to identify their buckets. (Also, I got tired of doing nothing but categorizing old posts). I didn't want to make one gigantic "Writing Software" category, but I don't know what to call some of the smaller buckets within it. For example, what do you call the topics about how to design classes and modules? Pattern topics would go into it, but it isn't just patterns.
I live in the Boston area, which means that January is cold. It was 8° (Fahrenheit) here yesterday. That's not that big a deal around here, but here's the thing: Somehow during the drive home in the evening, I managed to get my right index finger frostbitten. It was pale and numb, until I soaked it in some warm water and it returned to the same cold-pink as the others. Today: gloves.
I am not a graphic designer, but I have long admired what they do. One of the things I like about the hassle of rolling my own blogging software is the chance to do a little bit of design, both cosmetic and interactional. Khoi Vinh is a graphic designer, and shows his skill with his new improved design. This is a classic example of a grid design, where a page (or screen) is conceptually divided into a grid. The grid serves as a foundation for the content fitted into it, and ensures a consistency of geometry to the page. Interestingly, though the grid is intended as a constraint on the structure of the page, a hallmark of the technique is the flexibility of deciding how to place content within the grid. See Khoi's illustration of his grid for a demonstration.
Because I may need it someday: HTMLarea, a very impressive HTML editor that runs in IE and Mozilla Firefox. It was written by Mihai Bazon, who also makes some great menu software and other DHTML goodies at dynarch.com.
My wife Susan has an op-ed in today's Washington Post: Let Me Be Brave, about the Special Olympics and the death of Rosemary Kennedy (which I wrote about here last weekend). Of course, she says it all better than I could...
The first image from the Huygens probe on Titan shows the surface of the moon of Saturn:
Some remarkable factoids about the mission:
I don't know what this means from a business point of view. As an engineer, I scan down the list of patents and get the same glazed-eye look as anyone else. They all sound very similar, and all sound like either completely fundamental principles or trivial crap, like most patent titles do. Also of interest to me is that none of the three patents that I authored in the IBM portfolio are in the list:
Does this mean my patents are worthless? Or irrelevant? Or too valuable to disclaim? Maybe they just don't have much to do with the hotspots of open source. Who knows?
Bjarne Stroustrup has written a very interesting paper outlining some radical ideas for operator overloading: Generalizing Overloading for C++2000. He includes the notion of overloading no operator at all, so that "x y" can mean "x*y" the way physicists and mathematicians want it to mean.
Note: I got about halfway through this before realizing it was a joke...
AutismLink (Pennsylvania's Statewide Resource for Autism Spectrum Disorder) is selling Autism Awareness car magnets. There are other sources for these magnets, but AutismLink helps the cause more directly.
The UK's Guardian Unlimited has a section called The Digested Read, in which books are reviewed by way of condensing them into a single page in the style of the book itself. The whole thing is then snarkily summed up in a single sentence titled "The digested read ... digested". Judging by two samples from books I had actually read (Vernon God Little and Life of Pi), for some books they do a pretty good job nailing the tone and subject of the books. For others (Harry Potter and the Order of the Phoenix, for example), they seem to settle for mere parody.
I've heard of MAME, the arcade video game emulation software. I hadn't known that there's an entire cottage industry springing up to provide arcade-style enclosures for computers running MAME: SlikStik, DreamAuthentics, MAMEroom, and Dream Arcades, to name a few businesses. You can even get MAME-branded arcade tokens!
Matthew Baldwin collected a bunch of tricks of the trade from all sorts of professions (clown, butcher, nurse, photographer). He ended up getting more from all over, enough to start a whole blog about it: Tricks of the Trade. Some are edifying, some are horrifying (for example, mortician), all are fascinating.
Rosemary Kennedy, the disabled sister of JFK, and the inspiration for the Special Olympics, died yesterday.
This is a remarkable story, for both good and bad. On the bad side, a mildly retarded girl is lobotomized, leaving her profoundly disabled. She's hidden from view to prevent scandal to an ambitious and powerful family. On the good side, she inspires that family to create the Special Olympics, one of the best things to happen for disabled people in the last century.
I don't know how much Rosemary's story is unique for that era. There certainly were not the options and understanding that there are now. I'm saddened to think of her plight as an individual, but glad to benefit from the organization and attitudes that she helped, however indirectly, to create.
My 15-year-old autistic son drew this picture today:
He's drawn four characters (Piglet, Tigger, Pooh, and Eeyore), each in their characteristic color, and labelled in the same color. He's signed his name in red. I really like this picture, partly because Nat never draws pictures.
I was considering using this picture as a jumping off point for writing about one of the many philosophical quandries facing parents of disabled children: the disparity between his chronological age and developmental age, or the difficulty of choosing appropriate educational goals, or discerning the fine line between his personality and his disability.
But I'm not going to write about any of those things. Instead, I think I'll just enjoy the picture.
Steve Friedl has written a detailed and comprehensive guide to how to crack into relational-based systems: SQL Injection Attacks by Example. Also included (for those of us on the hook for building these systems) are tips for how to prevent injection attacks.
Last Sunday's investigation into musical navigation demonstrated to me once again just what an ad-hoc hodge-podge music notation is. It's developed over centuries, with odd symbols mixed together with abbreviations of Italian words, and so on. But even with its flaws, it's so well established that no one would propose changing it, right? Wrong.
The Music Notation Modernization Association is proposing exactly that. They have a set of detailed criteria that they used to evaluate over 500 different proposals, winnowing them down to a few dozen.
These notations have merit, but let's get serious here: there's no way music notation is going to change. There's just too much music already out there, with too many people already trained on the current system. If we can't manage to change English spelling, we aren't going to be able to change music notation.
On the same topic, it had to be out there, but I had never seen it: MusicXML.
Damien tells the story of his Formula Engine Rewrite:
It's a good story of how a major feature got built against the odds by one determined engineer.
Picture me standing at a lectern. A spray of microphones nearly obscures my face. Camera flashes strobe the room. I am near tears, but resolve to deliver my message:
Scoble has advice for job seekers:
I don't know whether this is true or not. I guess a blog couldn't hurt. Someday I'll need a job, and this will be a prime place to announce it. In fact, one of the things that got me to start this blog was the idea that I'd need a place someday from which to shout, "Help!" I'm glad at least one person thinks it will help.
I've long been surprised at the dearth of good tools for dealing with Windows icons. For example, considering how mainstream a format it is, I'm surprised to find that neither Photoshop nor Gimp can handle it. Perhaps it's because of .ico's inherent multiple image nature.
In particular, there haven't been any useful freeware icon editors that I've found. Well, now I've found one: @icon sushi It isn't exactly an icon editor, since it focuses on all aspects of icon other than the color of the pixels (in other words, all the things that are unique to icons). For painting pixels, use your favorite image editor, then use @icon sushi to pull the pictures together into an icon.
This is the 1000th post on this blog. Don't believe me? See for yourself.
I don't have anything wise to say to mark the occasion, no touching reflections on the 999 posts that have preceded it. In keeping with my aversion to marking special occasions, I'll allow myself the freedom to wax poetic about my blogging when I feel like it, rather than when the odometer happens to have a few zeros in it.
I've been blogging for close to three years, and I've enjoyed it, so I'll keep on doing it until it starts to suck. Knowing me, I'll probably keep doing it for a while even after it starts to suck. I've gotten some nice feedback from people, and that helps keep the momentum going.
Thanks for reading.
I was playing some piano music today, and saw that familiar notation "D.S. al Coda". Although it was familiar, I didn't actually know what it meant. I knew it had to do with going back and repeating some part of the music, but that detail of my piano education had withered long ago.
So I looked it up online, finding this great online music notation reference: Music Theory Online. Chapter 24 is Repeats, and told me what I needed to know. Acoustic Guitar also has a handy online lesson about notation. So: "D.S. al Coda" means go back to the percent-over-S sign, then play to the other plus-over-O sign, then play the coda (the end).
But when I looked at my sheet music with this new understanding, I saw some oddities: First, the percent-over-S sign was placed at the beginning of the piece, so why not use "D.C. al Coda", which means go back to the beginning, and so on? And when I looked at the end of the piece, it seemed clear it could have been written more compactly without changing the music: the same measures were in the coda as in the normal repeat that was skipped.
I guess music can be refactored just as code can. What I saw in the music were duplicate lines of code that could have been eliminated by rewriting the loops with different termination conditions! Fascinating.
BTW: Back in March, I asked about MIDI-to-notation converters. I really appreciate the shorthands of music notation after looking at the output of these programs. All the loops have been unrolled, all the trills, grace notes, and arpeggios have been literalized, and so on. A simple three-page song becomes a twelve-page mess of mind-numbing repetitive scribbles.
Happy New Year everyone!
I have to say this about New Year's Day though: I don't like special occasions, for two reasons:
For example, everyone's making resolutions today. Why today? Shouldn't we be introspective and purposeful the rest of the year? Why can't I make resolutions on February 5th or October 18th? Everyone tries to make their birthday special by doing just what they want to do. Why can't I do what I want to do every day?
And since we've just left the Christmas season, how about maintaining a little good will toward others the whole rest of the year? Hallmark shouldn't dictate our mood.
So my resolution for the new year: treat every day as special, regardless of the position of the Earth in its travels around the sun.