Cross-Platform GUI Programming

Over the last week or so, I’ve been working on a test program for Project X. The requirements pretty much dictated a GUI solution, but while I work primarily under Linux, the other developer on it works primarily in Windows, and we use both C++ and Lisp for this project. Any programmer who’s tried to write GUI programs for more than one platform knows that while all GUIs look pretty much the same, and do almost exactly the same things, the programming interfaces are completely different.

That’s rather ridiculous, when you think about it. If you develop a program for one OS, even in a mostly-portable language like C++, you have to all but rewrite the interface code to get it to run under a different OS — just to get the same general look! Microsoft and Apple have a vested interest in making it difficult for people to port programs to other platforms, so it makes some sense that they wouldn’t go out of their way to simplify it. But open-source people don’t, and they’ve come up with a solution: a package called wxWidgets.

Not only does wxWidgets bridge the GUI interface gap in a way that’s portable, it does so in a way that’s accessible from nearly any programming language! The Lisp interface for wxWidgets (wxcl) wouldn’t compile cleanly for me under Linux, but I suspect that will be fairly easy for me to fix when I need it. The C++ interface worked with no problem, and in maybe ten hours of work (with no prior experience with it) I’ve managed to build all the GUI code for the test program, for both Linux and Windows. 🙂

“But wait, there’s more!” The wxWindows solution also covers other areas of cross-platform pain: a standard graphics format (XPM), file and stream handling, multiple (human) language programs, multithreading, database access classes, Internet and TCP/IP classes, multimedia classes, embedded web browsers, and more — all source-code portable between different OSes. And it’s cleaner than MFC or any other Windows programming framework I’ve used — and I’ve used a lot of them, and even written a couple of my own. It’s… elegant. That’s the only word I can use to describe it.

This is the way programming is supposed to be.

Between this kind of thing, the rise of web-based programs, and the recently-mentioned Unity feature of the upcoming VMware Workstation, the OS is becoming less and less relevant. And that’s a good thing… for everyone except Apple and Microsoft, at least. 🙂

11 Comments

  1. The only problem is that wxWidgets is pretty ugly, though there’s worse. (Tcl/Tk under *nix is pretty ugly, though with “tiles” that’s going to be finally improved in the next version, and the “Tk” toolkit, available in other scripting languages and the Scheme dialect of Lisp besides Tcl is pretty elegant, though nobody accused Tcl itself of being elegant. (I kind of like it though, and its very embeddable in other languages.))

  2. I’m not sure where you heard that, because wxWidgets uses the native “widgets” (windows, controls, dialogs, etcetera) for each platform. It’s hard to tell the difference between a wxWidgets application and one written in the pure API for the platform in question, other than at the source code level. If you’re careful to use them, there are even ways to arrange the buttons differently according to the preferred button order for each platform.

  3. I didn’t “hear” that, I saw it, under Linux at least… Of course, it does resemble gtk+ version two which isn’t too bad looking. I suspect the application may have misused it or something.

  4. Under Linux, wxWidgets can target GTK+, MGL, or X11. I’d never heard of MGL before, but it’s easily possible that you saw a version compiled for some system that you weren’t used to.

    (And GTK+, at least, does have native widgets. :-p ).

  5. BTW, the new version of Tcl/Tk, 8.5, has finally been released, with the more flexible and reportedly less ugly look and feel. I’ll have to give it a try.

    Hopefully the other scripting languages will pick up on the latest Tk as well soon enough. The ones that implement it modularly, such as Python, will do it very soon, though of course the modular implementation has the drawback of needing Tcl/Tk on one’s system. (It’s a very small run-time though, a heck of a lot smaller than the typical Windows run-time, or even smaller than Ruby/Perl/Python etc. Of course, the Tcl language and libraries are much smaller… If only Tcl was more elegant, but I sort of like some of its warts. I actually think the concept of the language keyword as a “tool command”, complete with something that looks like option flags ah-lah POSIX command line arguments, is pretty cool. 🙂 )

  6. If you give it a try, let me know what you think of it. I doubt it will be much better than wxWidgets for my purposes, but I like to keep up on various technologies.

  7. It looks like it addresses both longstanding performance (though that’s remediable as its highly extendable and embeddable in C) and look and feel issues. I’ll have to let you know if there’s any letdowns. If you want to have some idea of what it’s like and what it does, the Tcl’er’s wiki is a very nice source. (IIRC http://wiki.tcl.tk)

  8. Sorry, plenty of more interesting stuff to do for the foreseeable future. 🙂

  9. I don’t know about that, Tcl/Tk is a classic toolkit to use as a front end to non-graphical applications, which I think is your application. (Of course, it’s become a lot more practical as a GUI environment for stand-alone applications.)

Comments are closed.