Daniel Burrows: CWidget tutoral 1: 'Hello, world!'
Late last year, I spent some time disentangling
aptitude's internal UI library and packaging it as a
separate library, which I named cwidget. This article
is the first in what will hopefully become a series describing the
basic concepts and APIs of cwidget. It applies to the versions of
cwidget currently available in Debian sid and lenny, 0.5.11-1 and
0.5.12-1. Autogenerated documentation of cwidget can be found
here (but beware that as of this writing it is
somewhat incomplete).
In this tutorial, I will walk through a simple program (hello.cc) that initializes cwidget, displays a simple message box, and then terminates the program when the user confirms the message. I assume a basic familiarity with C++.
The first thing to do is to include the portions of cwidget that our
program will use. Most importantly, we need the top levelcwidget routines. These are the global routines that initialize cwidget, shut it down, and control its main loop (among other things).
cwidget comes with a collection of stock#include <cwidget/toplevel.h>
dialog boxesfor things like displaying messages to the user. To access the routines that build these dialogs, we write:
All the symbols provided by the cwidget library are in the#include <cwidget/dialogs.h>
cwidget
namespace. Using the full library name means that there's a
reasonable chance that its names will not conflict with the names
provided by other libraries; however, it's a real pain to type
cwidget over and over. Since this is the only namespaced library we
are using in this program, it's handy to define cw as an alias for
cwidget:
Now we're ready to write the main routine. The first interaction of client code with the cwidget library is to initialize it. This will initialize the ncurses library and put the terminal into a mode suitable for a full-screen curses program.namespace cw = cwidget;
Next, we create a dialog box that will be displayed to the user. There are two things to note about this code:cw::toplevel::init();
- cwidget is Unicode-aware and the
ok()routine expects the message string to be a wide-character string. In this case, that means that we need to pass in a wide-character string (indicated by typing
in front of the string).L - The second argument tells cwidget what to do when the
ok
button is pressed. The expression
creates a slot using libsigc++. Briefly, a slot is a reference to a function or to a method of a class instance. When invoked, this particular slot will callsigc::ptr_fun(cw::toplevel::exitmain);cwidget::toplevel::exitmain(), which causes the main cwidget loop to exit. The slot is wrapped incwidget::util::arg, a utility function that handles passing slots as optional arguments.
Now that we have a widget, the next step is to arrange for it to appear on the terminal. In cwidget, control of the terminal is assigned to a singlecw::widgets::widget_ref dialog = cw::dialogs::ok(L"Hello, world!", cw::util::arg(sigc::ptr_fun(cw::toplevel::exitmain)));
top-levelwidget: whatever it displays is what gets displayed on the terminal, and all user input is passed directly to it. In a real program this widget will typically manage a collection of sub-widgets and assign each one a screen region, but for now let's just display the dialog box we created:
With everything initialized, we're ready to start the main loop.cw::toplevel::settoplevel(dialog);
mainloop() will keep the display up-to-date and dispatch incoming
events (for instance, keystrokes and mouse presses) until exitmain()
is invoked.
When the user presses Enter or clicks on the Ok button in the dialog,cw::toplevel::mainloop();
exitmain() will be invoked by the binding that we set up earlier.
Once this happens, we need to shut down cwidget in order to restore
the terminal to its original state. If you skip this step, the
terminal will be garbled and will not work properly when your program
exits.
And that's it! To compile the program, change to the directory containing hello.cc and run:cw::toplevel::shutdown();
Of course, you'll need to have the g++ and libcwidget-dev packages installed for this to work!$ g++ -o hello hello.cc $(pkg-config --cflags --libs cwidget)
Yesterday, my friend
We currently have fifteen cats in the house. Only three of them are ours.
When Sarah was contracting at Google, she started an informal, but
company-endorsed trap/neuter/release program, because the basement of
buildings 40-43 had a bit of a stray/feral cat infestation.
Since she left Google, she's continued doing trappings on an on and off
basis.
She got a call a couple of days ago about a litter of kittens behind one of
the other buildings, so she headed off last night with one of her crazy cat
lady friends, and they proceeded to catch one of the kittens. She brought
that home, and I went back with her, and the mother, which seems fairly
feral, had been caught in a trap. The rest of the kittens seemed to have
managed to secrete themselves away inside a generator behind the building.
This morning, with some help from various facilities types, she managed to
extract the other four kittens from the generator. So that put the mother
plus five kittens in the spare room (in a large cage).
At more or less the same time, Sarah got news of a litter of six kittens
that need rescuing from down Gilroy way (some woman in a trailer park didn't
seem to realise that boy cat + girl cat = kittens), so after grabbing the
other four kittens this morning, she headed off to Gilroy to grab them.
So the current plan is to get the mother cat of what we'll call the Google
litter desexed on Tuesday and then release her back where she came from. Her
five kittens are young enough (~8 weeks) that they can be socialised and
won't be feral. The six Gilroy kittens are from non-feral parents, and are
about 11 weeks old. All of the kittens are old enough to be desexed as well,
but Sarah can't get them into Palo Alto Animal Services for desexing for a
couple of weeks, so I suspect we're stuck with them in the interim, unless
Sarah can find foster homes for them. To cap it off, we're going to
Sacramento for the weekend, so we have to get one of our friends in the
complex to take care of them all.
The sad thing is the Gilroy Six seem to be in worse condition than the
Google Five. They've got pretty poor coats, and seem to have some diarrhoea.
Hopefully with a better diet they'll pick up. They're all very cute. The
first one of the Google Five that Sarah caught last night is particularly
cute. I expect Sarah will get some photos of them all up soon.
If anyone is in the Bay Area is interested in a kitten, we've got them by
the near-dozen.
I sometime wish I had access to an encyclopedia, written in wiki style so that it could be updated by anybody, that had an article about every SF story and novel ever written, and every fictional concept (like ansible, hyperspace etc) ever used in an SF story, and which crosslinked these in a useful manner.
Often, once I’ve had a worldbuilding idea, I want to go read some of the key stories that use the same or a similar idea, so that I could see what others have already done with the idea. Only it turns out there are no indexes that tell me “antigravity has been used in these ways in SF stories, and it is a central concept in these stories” etc.
Anybody know of something like this?

The usual suspects apply: too expensive for me especially without a guarantee of sponsorship, etc. Maybe next year!
It turns out that due to a weird collision of circumstances I am going to 
Netgear has jumped the bandwagon and released 


It's official, I am revoking my gpg key because after
There exist many bayasian/statistical spam filters, ranging from products such as spambayes, and spamassassin, to crm114. Each of them works in their own way. Having used and tested almost all of them I've noticed a common flaw.
The vast majority of spam-filters struggle to correctly classify "419 scam" mails, lottery fraud, and similar mails.
Why is that? In general, having read hundreds of these mails, I can see several things that are common in these kind of the mails: