Wonderful Things

I’m going to share some wonderful things with you now. I’ve saved them up, although my one reader has probably seen them all through my del.icio.us account.

I think Christopher Hitchens getting waterboarded is fairly noteworthy.

Zadie Smith writes about Kafka again. Funny story about this. I was reading the article, and the writer noted that Women are snares which lie in wait for men on all sides, in order to drag them into the merely finite is a “perfectly ordinary expression of misogyny, dispiriting in a mind that more often took the less-traveled path.” I was already annoyed with the article on a number of counts (it’s titled “F.Kafka, Everyman”) and I thought, I bet the author’s a woman. When I scrolled to the top and saw who it was, I thought, “well she makes some good points”. So, there.1

This article made the rounds on the aggregator blogs. There’s a passage that ends “She had scratched through her skull during the night—and all the way into her brain,” that made it like a story from Scary Stories to Tell in the Dark. Some people have called bullshit on it, but who cares?

This video will also scare the hell out of you. Look at the debate in the comments about whether it’s basically a snuff film.

Have you seen Quest for Fire? My god, it’s a French-Canadian movie about cavemen trying to get their fire back. It has authentic made-up cavemen dialogue in several languages and no subtitles. So awesome.

I like to corner people and tell them about the bonobos. This video will change your life. The thesis at the beginning of the video sounds ridiculous, but let it sink in a little before you reject it.

This video about a weird subculture in Japan will also change your life. There’s a tremendous surprise about halfway through. This video isn’t exactly eye-opening, but it brings you up to speed on something you might not have wanted to know about.

The second video here has become a local meme for Amy and I, along with the lines from this (an old thing that we just discovered). Huh??? What???

Technology Crisis I and II are just about the best free music you’ll ever get. It’s music written for an imaginary video game.

Anyway, I have a lot of this stuff. I estimate about 40% of my brain is made out of this crap.

---

  1. To get this, you have to understand that Zadie Smith and Kafka and the intersection of the two have been key influences throughout my 20s. [back]

Passion

Continuing with the theme of wholesome outdoor athletic activities, Amy and I went to see the Pittsburgh Passion playoff game on Saturday night. It was fun; there was a good crowd; the tickets were $5. The Passion have gone undefeated this season, and tonight we saw why. When we left at half-time (it was raining) it was something like 37-6 against Orlando (final 41-6).

My homework assignment for the DC folks (I guess for next year): go see a DC Divas game, and keep track of the next Passion vs. Divas game, so we can get together and I can be conflicted.

Critical Mass

Amy and I rode our bikes in Critical Mass for Pittsburgh, which I didn’t realize is a monthly thing. We didn’t know what to expect at all, but it turned out to be a very mellow and pleasant affair. Some of the regulars were making fun of a “competing” ride called Critical Manners1, where the pack doesn’t blow through red lights and even rides in a single file. We were also dismayed when we arrived at the meeting place that it didn’t seem like the mass was nearly large enough; it would be a sub-critical mass, a fizz-out. But when everyone got on their bikes and swarmed out it seemed like the pack magically grew to something like 150-200 bikes. Then everyone just sort of ghosted along at a leisurely pace with some quiet talking and not much yelling in a loop around the Oakland area. Since it was a Friday at 6PM, there weren’t even that many cars to inconvenience.

Of course, the 200~ person pack would take a long time to cross an intersection and stopping for the red lights would have broken it up, so that’s where the bad-boy behavior comes in. Even this was pretty civilized. At each intersection, if the light was red the front of the pack would wait, but then the whole pack would pass through. A couple bikes would park in front of the cross-street, just looking at the waiting cars and smiling. So we did see one guy in a white SUV try to muscle his way past the “guards”, but the cyclist just slid his bike under the SUV’s wheel and suddenly there were a couple cyclists talking to the driver.

Okay, so the cool part was when the pack climbed up Craig St. toward Bigelow, which is a kind of highway on a height that drops down like a rollercoaster into either Bloomfield (a residential neighborhood) or downtown. This is a main commuter avenue for getting across Pittsburgh’s East Side, and normally it would be iffy to ride with the cars there. This is where we had a line of cars backed up behind the pack, probably fairly annoyed for the 15 minutes that we held them up for. The point wasn’t to hold up the cars, even though I didn’t feel too bad about it. A lot of people make hellish 2+-hour commutes to and from Pittsburgh, just because they can’t imagine actually living in the city. Some of those people are the same drivers who act squirrelly around bikers, tailgating because they’re afraid to pass, or freaking out when you pause to turn in the left-turn lane.

Anyway, it turned out that it’s just really nice to own the road for awhile, and especially a privileged car commuter road like Bigelow. There’s a weird little sliver of a park (“Frank Curto Park”) that’s up on this inaccessible ridge by Bigelow that thousands of car commuters pass every day. Nobody goes to Frank Curto park, not even by car. Driving past you sometimes see a flock of geese turkeys2 and wonder how they got there. We rode past that (but we could have stopped) and then the entire pack bombed down through the long descent to downtown, with the sun starting to set and all of Pittsburgh below us. That was a nice experience, seeing how all the people dealt with the descent, because each person is focused on controlling his bike and enjoying the speed and wind. So it was a solitary meditative moment enabled by this group activity and effort. The whole time this is going on there was a rear guard which was probably putting on the brakes to keep the pack from getting too compressed and which was dealing with the annoyed motorists and an advance guard that had to open up the traffic when we got to the bottom of the hill, so there was also a sense that you were being given a gift of being able to enjoy this descent.

The pack rode around downtown a bit and ended up at Three Rivers state park where there’s a big fountain with a circular ring around it that some used as a velodrome. By that time the sun was really red. After that, everyone dispersed; it seemed like it was your job to find your own way home. I knew where the path was, just not how to get to its entrance from the park, so we had a short adventure with a densely wooded unofficial path before we figured out the proper way to get back home. Between the Critical Mass ride and the ride back we probably did 9-10 miles.

Anyways, so that’s the problem with the Critical Manners concept. Especially damning to me is the single-file line rule. The whole unpleasantness between cars and bikes is that cars get anxious when they can’t go 30 miles per hour, even when they’re just racing to the next red light and even when a bike is going 10+ miles per hour. The other lane’s taken and here’s this guy just toodling along on his bike in front of you, and oh! it’s just so frustrating. Making them wait is the quasi-political statement that says, we let you drive those things that poison our air and boil the planet, you don’t let us use this asphalt that we pay for.

---

  1. In the article about a San Francisco Critical Manners, there are 16 participants mentioned [back]
  2. Amy reminded me that it was turkeys, not geese. Turkeys is weird, geese not so much. Also, apparently the group word for turkeys is “rafter”? link [back]

A language game

Amy and I were sitting in an airport waiting for a flight. I said, “I should have been a pilot.” Amy asked me why. Really, it was just something to say; I was briefly imagining my alternate life in which I was an airline pilot. Instead of explaining the details of the fantasy (get to fly around the world, chicks dig on you, etc.) I said: “So I could fly far away from you.” See, it was funny to say because I didn’t mean it, and because this is so obviously a terrible thing to say to anyone, let alone your girlfriend. Oh, we had a good laugh.

Amy suggested that there could be an entire children’s book based on this premise:

  • I wish I were an astronaut… so that I could escape to another planet
  • I wish I were a deep sea diver… so that I could go to the bottom of the ocean and be alone
  • I wish I worked at night… so that I’d never see you
  • I wish I were an explorer in foreign lands… so that we’d lose contact
  • I wish I were a time traveler… so I could travel to before you were born… or after you died

Try this with your loved ones, the next time you’re feeling grumpy, or simply want to make an impression.

A gag for a Ben Stiller movie

Pale bearded guy wants girl. His woman-savvy friend advises him to ditch the beard and get a suntan. “She’ll look at you in a totally new light, man. She’ll be all, who’s this guy?” Guy takes his advice and lays in the sun. Music montage, natch. Then we see him shaving his beard off, with the lather. With great satisfaction he wipes off the last lather and dries his face. We see him step out the door into the light. His face is evenly bronzed… except for the entire lower half, pitifully white, minus a small tanned crescent above his chin!1

---

  1. I had a mild form of this. I thought it was razor burn until I realized with horror what had happened. [back]

Mos Def

Is it bad that I really like this lyric? You kind of have to hear it. From Close Edge:

I’m Mos Definite, not think so
Flood ya city with the black ink flow
And my crew ain’t scared to let them things go
So, stop with the nonsense, like he conscious
I’m just alright dawg, I’m doin’ great dawg
I don’t play games so I don’t playa hate y’all
Get it straight or get the fuck up out my face dawg
I’m like the second plane that made the tower’s face off
That shit that let you know it’s really not a game dawg1

Your grind and my grind ain’t the same dawg
2

I think this is appropriate. While I was in Hawaii I went to the Pearl Harbor memorial, where you stand on a platform above the sunken USS Arizona with its 900+ interred corpses. Before you go out to the platform you watch a video that details the sequence of events. The tone of the video is mournful, but it never goes so far as to condemn the Japanese for the attack, only reminding the viewer that they were an Axis power. Yamamoto is treated as a figure like Robert E. Lee, personally against the war but determined to make the best military showing. Then when the attack happens, you feel a chill: so many ships in so little time, and there’s video of the Arizona exploding. Basically, because this was an attack on a military base, it’s possible to experience this event first objectively as awesome (deinos3), then parochially (and humanely) as dastardly, tragic, sad, etc. Anyways, I figure Mos Def’s figure is precise here. I remember on September 11, someone told me that a plane had crashed into one of the Twin Towers, and I assumed that he was talking about some freakish accident. It was only when I heard about the second plane, and then the collapses, that I knew it really wasn’t a game.

---

  1. The heavy repetition (e.g., dawg, dawg, dawg, dawg, and -ow for six couplets at the beginning) works IMO. [back]
  2. The other stuff going on in the song is interesting too. He’s saying that he’s not a gangsta rapper but he’s not going to criticize those who are. I like the poetic conflation in hip-hop. His “grind” is and isn’t the same as drug-dealing. It’s like the different accounts of gangsta on Damn, It Feels Good to be a Gangsta, one of which describes the President of the United States as a gangsta. Then, the main idea of Mos Def’s song is that he’s “close to the edge”, not of flipping out and killing someone, but he’s paying attention to what’s happening on the margin of society. [back]
  3. It’s a cranky prescriptivist cliche to remind people that something that is awesome, like an “awesome god”, is something that is terrifying to behold.[back]

Apple Cocoa Cavil

I’m going to try to sound more like Andy Rooney1 up here on this blog. Also, how about I indicate when the boooring technical notes begin and end with technical and interesting.

This is one of my favorite xkcd comics. It really speaks to my experience. Usually I can pull away before I’ve finished registering for comments. Sometimes I’m halfway through a closely reasoned argument when I realize how perfectly pointless and non-personal-goal-advancing my actions are. Then, in the worst case scenario, there I am mixing it up with the other comment-warriors. Here’s me windmilling my way through a post about dolphin killing on Japanprobe. This used to be the url for a pitched brawl in which I interjected a few uninformed comments. Etcetera.

Anyway, I thought I’d write this post at a more meta level to dissuade myself from commenting elsewhere. So here goes (technical):

Have you ever noticed that Objective-C is really, really weird? Like, they just took all the C- and C++- style conventions and changed them? Me too. And on top of that it’s compiled and you do memory management and the engineers make APIs that have objects called NSCamelCasedFactoryMethodObjectFacilitator2. Okay, so then someone makes a script-y dynamic thing for managing the Objective-C stuff, good idea. And when designing this scripting interface they make the following language syntax design decisions:

Finally, the instruction separator is a dot, like in English sentences:
myString := ‘hello’.

The following example shows how to send a message to an object:
myString class

See, this is funny, because it’s completely different from every other programming language3. That is all.

Umm, but there is a somewhat interesting take-away. Both Apple and Microsoft have designed really sucky APIs (in terms of intuitability rather than functionality) , compared to which GTK is fairly sane (it gets a bit clunky when dealing with “GtkIter” operations). But the MacOS developers follow Apple’s improvements of this API, cooing over the increased simplicity afforded by the new NSMakesYourToastRegistry. It’s the same with new C#/ Windows API developments. So (this is actually the interesting part) the lesson is that when people work within a “closed” development system, they lose their sense about good and bad design!4

Here’s the idea. Closed development systems don’t get good feedback and don’t have good change mechanisms, so even very good engineers (probably Apple’s are some of the best) end up working in the dark a little. It gets all culty, because there’s an elect that makes the design decisions and a laity that passively learns the new scripture. And everyone’s straining so hard to understand what the design class hath laid down that they’re no longer perceiving the design objectively. And proprietary lock-in helps, because it leads to fatalism (“what can I do, switch to Windows?”). There are all these weird little island communities where the natives are effectively locked-in to a platform because they’ve already invested the energy to understand its weird design. This isn’t even necessarily a proprietary vs. opensource thing. There are strange over-designed opensource projects that aren’t particularly open because of this class division (and most opensource projects rely on only 1-3 main contributors, it seems). All I’m saying is that bad APIs / development languages happen when designers aren’t being influenced in the right way by the end-user developers, and I’m speculating that this has to do with particular attitudes and processes associated with proprietary code and also a kind of design elitism. I mean, doesn’t Objective-C code (as code) suck?

---

  1. I include this link because I think this already marginal reference will become incomprehensible in ten years.[back]
  2. Yeah, I’ve got their number all right.[back]
  3. Actually, these are pretty interesting design decisions. The := assignment syntax is wack, but probably necessary for named arguments or something. The dot on the end is okay, but you’re moving the OO-messaging operator into the generally useless semicolon position. By using the space for messaging, you’re now saying “subject verbs(args)” instead of “subject.verb object, args” (in Ruby you can omit the parens for a function). [back]
  4. So I sort of believe that. Mainly I’m bitter because I can’t get some code to work on MacOS.[back]

Example

An instance of obsessive behavior: trying out various WordPress themes, tweaking the CSS to look right, making sure the code highlighting is the same color as my gvim theme. Perhaps for hours. This by way of giving myself permission to stop.

Update

My life continues apace. At the moment, I’m looking for a job for the summer and onward1 , hopes fairly high. Going to Hawaii on Tuesday2.

Trends:

  • obsessive behavior
  • competence?
  • health?

An example of the first is the playing of this game. Probably I get in at least one game a day, usually more. A game will usually last an hour, but some games go much longer. Also, my computer is supposed to prevent me from typing/mousing for more than hour, and I will click to bypass its 3 minute break message for hours on end. You read me? Sometimes, say at periods like this when I’m trying to get on to the next thing, I “invest” my mind in the internet, just as during the semester I invested it in academic philosophy. That is, I try to catchup with the flow of information, trends, etc., at least in the domains I care about (mostly opensource software and some world affairs). What really happens is that my hands start hurting and I lose my attention span.

My sense of the second comes from a sudden improvement in my ability to “see” code. I made this portfolio site to show potential employers. It’s in PHP, which I don’t really know, but it’s logic, so I can hack out something like that with a little investigation of the syntax and standard libraries. I’ve also been writing a userspace driver for a usb device (the famous AgileLamp USB Lava Lamp!), which has been a really mysterious, frustrating process where I’ve ended up experimenting with several language bindings for the woefully under-documented libusb library. I ended up falling back to the original C library itself, and found that it’s no more or less understandable as logic than Ruby or Python (although as human-readable code C sucks). So it’s a sense of, if it’s code then it’s hackable. During the spring semester I got this way with writing philosophy papers, since these papers are all supposedly supposed to be publishable. I can take apart a topic and discuss it in a learned fashion for 15+ pages3. I’d like to get this way with electronics and maybe languages4.

By the last I only mean that I really enjoy riding around town on my bike. I have a route to school and can get to a couple interesting neighborhoods from my home. By health I do not mean not eating Jalapeno Cheetoses. Also, Amy and I found a very cheap pizza place that delivers, called Maximum Flavor. Their flavor truly cannot be surpassed. Attempts have been made, and all have failed, with tragic, often fatal, results. Pretty good pizza.

Anyways5, I’ll try to write here more, generally on more limited, technical topics, because “I’m just not that disclosive”6. Look at the timestamp on this post and you’ll get a sense of where I’m at, psychophysically. My wrists hurt and my eyes are burning/droopy.

---

  1. I will learn the formal rule for when to use onward vs. onwards. [back]
  2. Because I am wealthy and carefree. [back]
  3. Which points to how silly “philosophy” is as a discrete academic domain. So just say this: all knowledge-endeavor is in the domain of philosophy, but not all endeavors are sufficiently philosophically reflective. This means: there shouldn’t be any philosophy grads, but other disciplines should be required to be much deeper about what they’re doing, e.g., law. [back]
  4. I know my best years for this are behind me. sniff [back]
  5. I will learn the formal rule for when to use anyway vs. anyways. [back]
  6. As Joe is wont to say about himself [back]

Setup for Alexandria Development: III

The following code requires Alexandria trunk. For more information see Cathal’s article. You can get this file here or as a full gem source package through svn:

svn co http://alexandria.rubyforge.org/svn/alexandria/trunk/readinglist .
$:.unshift File.dirname(__FILE__)
 
=begin
 
This is a sample (but useable) app for maintaining a reading list that takes
its reading options directly from Alexandria. At the moment it allows you to
move books to the reading list, remove them, mark them as read, and reorder
them. It's commented so as to be a kind of tutorial. The reader is encouraged
to play with it and try to add functionality. 
 
This code demonstrates some of the most common operations in a Gtk app:
creating menus, hooking up a treeview and syncing it to data, and widget
packing. Of these, working with the TreeView will probably be the most
confusing. The basic concept behind treeviews is that a treeview is the
graphical widget that administers a "store" or short-term database (usually
either a ListStore or a TreeStore) which in turn is concerned with managing
either a list-like or tree-like structure of TreeIters. In the case of a
ListStore, a TreeIter represents a row that you see in the TreeView, and the
indices of the TreeIter (like iter[0], etc.) return the values for the columns
in that row. One thing to know about GTK Iter objects is that they like to get
"invalidated" whenever the managing View changes, so for example if you get the
iter for the user's selection of the third row of a TreeView and store it for
later, you'll find that the iter itself (as opposed to its TreePath, or
"absolute" location) is no longer available. Clear? It's definitely recommended
that you take a look at this tutorial:
 
http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-treeview
 
=end
 
module Readinglist
  require 'yaml'
  require 'alexandria'
  require 'gtk2'
 
  class ReadingListApp
    FILE_FORMAT = {:to_read => [], :have_read => []}
    READING_LIST_FILE = File.join(ENV["HOME"], ".reading_list.yml" )
 
    # I try to decompose methods as much as possible to show the procedural
    # skeleton of the program. I name the methods to read like sentences. 
 
    def initialize
      load_reading_list
      get_books
      setup_gui
      load_books_into_listview
    end
 
    # We use YAML as the "serialization" strategy. That is, we make sure a hash
    # is stored in a file in the user's home directory. We load it into memory,
    # manipulate it, and always make sure to sync it back to the file. This is
    # exactly how books are loaded in Alexandria. Alexandria even stores the
    # class instance to the file. 
 
    def load_reading_list
      unless File.exist?(READING_LIST_FILE)
        File.open(READING_LIST_FILE, 'w') do |file|
          file.write(FILE_FORMAT.to_yaml)
        end
      end
      database = YAML.load_file(File.join(ENV["HOME"], ".reading_list.yml" ))
      @reading_list = database[:to_read]
      @have_read = database[:have_read]
      puts @reading_list.inspect
    end
 
    # I have to make sure the listview and the data store are in sync, and I
    # want to make sure that when the program finishes the latest changes are
    # committed to file. This could get too expensive with enough books,
    # though. In Alexandria, some changes happen immediately (changes in book
    # attributes, covers) while others only occur on a clean program shutdown
    # (deleting, saving certain preferences).
 
    def save_to_yaml
      database = FILE_FORMAT
      database[:to_read] = @reading_list 
      database[:have_read] = @have_read 
      File.open(READING_LIST_FILE, 'w') do |file|
        file.write(database.to_yaml)
      end
    end
 
    # I initialize the Libraries simpleton (available through the above
    # require) and ask it to reload its list of libaries. Then the loadall class
    # method on Library gives me an array of arrays of books, which I then
    # flatten; that is, make into one long array. 
 
    def get_books
      libraries_simpleton = Alexandria::Libraries.instance
      libraries_simpleton.reload
      libraries = Alexandria::Library.loadall
      @books = libraries.flatten
    end
 
    # More declarative-style methods for erecting the GUI. This type of code
    # ends up being very mechanical to write, which is why people like to use
    # tools like Glade. In fact, keeping this gui layout code in the open is
    # probably a better idea for long-term maintenance. 
 
    def setup_gui
      setup_window
      setup_menus
      setup_current_reading_list
      setup_available_books_list 
      refresh_reading_list
      Alexandria::UI::Icons.init
      setup_callbacks
      @window.show_all # This needs to be called after widgets are packed. 
    end
 
    # For information on packing, see
    # http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-packing-intro . Here
    # @window, which can only contain one child widget, gets a VBox. I'll put
    # several widgets inside @vbox, including more "container" widgets (like
    # HBox), in which I put yet more widgets.
 
    def setup_window
      @window = Gtk::Window.new("Reading List")
      @window.set_width_request(800)
      @window.set_height_request(600)
      @window.add(@vbox = Gtk::VBox.new)
    end
 
    # For information on callbacks in Gtk see
    # http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk-signals . Ruby-gnome2
    # callbacks use the Ruby do/end block syntax. Since I don't like to define
    # the callback method inside the block, I use the method() function to turn
    # the method into a proc, and use the & syntax for passing in a "proc"
    # object to the block.
 
    def setup_callbacks
      @available_treeview.signal_connect("row-activated", &method(:on_row_activated))
      @window.signal_connect("delete-event", &method(:on_quit))      
    end
 
    # Pretty straight-forward, if wordy. The ImageMenuItems can use a
    # Gtk::Stock:: constant to save some work and get pretty icons. :expand =>
    # false is used to keep widgets from bulging out.
 
    def setup_menus
      @vbox.add(menubar = Gtk::MenuBar.new, :expand => false)
      menubar.append(file_menu = Gtk::MenuItem.new("_File"))
      menubar.append(edit_menu = Gtk::MenuItem.new("_Edit"))
      menubar.append(help_menu = Gtk::MenuItem.new("_Help"))
      file_menu.submenu = file_submenu = Gtk::Menu.new 
      edit_menu.submenu = edit_submenu = Gtk::Menu.new 
      help_menu.submenu = help_submenu = Gtk::Menu.new 
      file_submenu.add(Gtk::ImageMenuItem.new(Gtk::Stock::SAVE_AS))
      file_submenu.add(quit_item = Gtk::ImageMenuItem.new(Gtk::Stock::QUIT))
      quit_item.signal_connect("activate", &method(:on_quit))
      edit_submenu.add(Gtk::MenuItem.new("Mark selected _read"))
      help_submenu.add(about_submenu = Gtk::ImageMenuItem.new(Gtk::Stock::ABOUT))
    end
 
    # To setup the "current reading list" on top. The TreeView is connected
    # directly to the ListStore, but the TreeViewColumns and the CellRenderer*s
    # connected to them are responsible for telling the TreeView _how_ to
    # display the data within the ListStore. The argument :text => n is a
    # shorthand to tell the TreeViewColumn to associate with a position or
    # index in the TreeIter (row).
 
    def setup_current_reading_list
      @vbox.add(Gtk::Label.new("Books I am reading:"), :expand => false)
      @vbox.add(hbox = Gtk::HBox.new)
      hbox.add(scrolley1 = Gtk::ScrolledWindow.new)
      hbox.add(@button_vbox = Gtk::VButtonBox.new, :expand => false)
      setup_side_buttons
      scrolley1.add(@reading_treeview = Gtk::TreeView.new)
      @reading_treeview.model = @reading_store = Gtk::ListStore.new(Integer, String, String)
      renderer = Gtk::CellRendererText.new 
      reading_column1 = Gtk::TreeViewColumn.new("Order", renderer, :text => 0)
      @reading_treeview.append_column(reading_column1)
      reading_column2 = Gtk::TreeViewColumn.new("Title", renderer, :text => 1)
      @reading_treeview.append_column(reading_column2)
      reading_column3 = Gtk::TreeViewColumn.new("Author", renderer, :text => 2)
      @reading_treeview.append_column(reading_column3)
    end
 
    def setup_side_buttons
      @button_vbox.layout_style = Gtk::VButtonBox::START 
      @button_vbox.add(up_button = Gtk::Button.new(Gtk::Stock::GO_UP))
      @button_vbox.add(down_button = Gtk::Button.new(Gtk::Stock::GO_DOWN))
      @button_vbox.add(read_button = Gtk::Button.new("Read"))
      @button_vbox.add(remove_button = Gtk::Button.new(Gtk::Stock::REMOVE))
      up_button.signal_connect("clicked", &method(:on_click_up))
      down_button.signal_connect("clicked", &method(:on_click_down))
      remove_button.signal_connect("clicked", &method(:on_click_remove))
      read_button.signal_connect("clicked", &method(:on_click_read))
    end
 
    # Same as above, except with the added wrinkle that a TreeModelSort, using
    # a TreeModelFilter, is acting as a kind of proxy for the ListStore. This
    # is to support sorting of columns. This code is ripped off wholesale from
    # Alexandria.  
 
    def setup_available_books_list
      @vbox.add(Gtk::Label.new("Available books:"), :expand => false)
      @vbox.add(scrolley2 = Gtk::ScrolledWindow.new)
      scrolley2.add(@available_treeview = Gtk::TreeView.new)
 
      @list_store = Gtk::ListStore.new(Gdk::Pixbuf, String, String)
      @filter = Gtk::TreeModelFilter.new(@list_store)
      @available_treeview.model = @available_books_model = Gtk::TreeModelSort.new(@filter)
 
      setup_available_books_title_column
 
      renderer = Gtk::CellRendererText.new
      column2 = Gtk::TreeViewColumn.new("Author", renderer, :text => 2)
      column2.resizable = true
      column2.sort_column_id = 2
      @available_treeview.append_column(column2)
    end
 
    # This TreeViewColumn has two widgets, a CellRendererPixbuf for the book's
    # icon, and a regular CellRendererText for the book's Title. I have to tell
    # the CellRendererPixBuf how to display itself int the set_cell_data_func.
    # The convert_iter_to_child_iter is some kind of bookkeeping for the
    # TreeModelFilter.
 
    def setup_available_books_title_column
      column = Gtk::TreeViewColumn.new("Title")
 
      renderer = Gtk::CellRendererPixbuf.new 
      column.sizing = Gtk::TreeViewColumn::FIXED
      column.fixed_width = 200 
      column.widget = Gtk::Label.new("Title").show
      column.pack_start(renderer, expand = false)
      column.set_cell_data_func(renderer) do |column, cell, model, iter|
        iter = @available_treeview.model.convert_iter_to_child_iter(iter)
        iter = @filter.convert_iter_to_child_iter(iter)
        cell.pixbuf = iter[0]
      end
 
      renderer = Gtk::CellRendererText.new
      renderer.ellipsize = Pango::ELLIPSIZE_END if Pango.ellipsizable?
      column.pack_start(renderer, expand = true)
      column.add_attribute(renderer, :text, 1)
      column.sort_column_id = 1
      column.resizable = true
 
      @available_treeview.append_column(column)
    end
 
    # This supplies the actual data to @available_treeview. Icons.cover creates
    # a Gdk::PixBuf (image object) from cover files stored in the .alexandria
    # directory.
 
    def load_books_into_listview
      @books.each do |book|
        icon = Alexandria::UI::Icons.cover(book.library, book)
        icon = icon.scale(20,25) 
        iter= @list_store.append
        iter[0] = icon 
        iter[1] = book.title
        iter[2] = book.authors.join(" ")
      end
    end
 
    # Call this when you want to repopulate and reorder the reading_list. 
 
    def refresh_reading_list 
      @count = 0
      @reading_store.clear
      @reading_list.each do |item| 
        iter = @reading_store.append # Gets a new iter (row) to work with.
        iter[0] = @count += 1
        iter[1] = item[0]
        iter[2] = item[1]
      end
    end
 
    # @reading_treeview.selection.selected is the iter of the selected row. 
 
    def on_click_remove widget
      selection = @reading_treeview.selection.selected
      @reading_list.delete_at(selection[0].to_i - 1)
      save_to_yaml
      refresh_reading_list
    end
 
    def on_click_read widget
      selection = @reading_treeview.selection.selected
      @have_read << @reading_list.delete_at(selection[0].to_i - 1)
      save_to_yaml
      refresh_reading_list
    end
 
    # The idea is to swap the iters in the TreeView and mirror the swap in the
    # reading list. The iter's path is like its current map coordinates. Since
    # iters are always getting invalidated, it's a good plan to work with the
    # path. 
 
    def on_click_up widget
      selection = @reading_treeview.selection.selected
      position = selection[0].to_i - 1
      previous_path = selection.path
      previous_path.prev!
      previous = @reading_store.get_iter(previous_path)
      @reading_store.move_before(selection, previous)
      unless (position - 1) < 0
        @reading_list.insert(position - 1, @reading_list.delete_at(position))
        refresh_reading_list
      end
      @reading_treeview.selection.select_path(previous_path)
    end
 
    # on_click_up and on_click_down call for refactoring to reduce duplicated
    # code. Try it for yourself if you're interested.  
 
    def on_click_down widget
      selection = @reading_treeview.selection.selected
      position = selection[0].to_i - 1
      previous_path = selection.path
      after_path = selection.path 
      after_path.next!
      after = @reading_store.get_iter(after_path) 
      unless (position + 1) == @reading_list.length
        @reading_store.move_after(selection, after)
        @reading_list.insert(position + 1, @reading_list.delete_at(position))
        refresh_reading_list
        @reading_treeview.selection.select_path(after_path)
      end
    end
 
    # This is the callback for when a row in the lower available books listview
    # gets clicked.
 
    def on_row_activated widget, path, column
      iter = @available_treeview.model.get_iter(path)
      puts "#{iter[0]} #{iter[1]} #{iter[2]}"
      reading_list_item = []
      reading_iter = @reading_store.append 
      reading_iter[0] = @count += 1
      reading_iter[1] = iter[1]
      reading_list_item << iter[1]
      reading_iter[2] = iter[2]
      reading_list_item << iter[2]
      @reading_list << reading_list_item 
      save_to_yaml
    end
 
    # This method is called when the window is closed and when the quit menu
    # option is activated. Event is used for when the window connects to the
    # 'delete-event' signal and requires both parameters. Gtk.main_quit kills
    # the Gtk.main loop. 
 
    def on_quit widget, event = nil
      Gtk.main_quit
    end
  end
 
  def self.main
    ReadingListApp.new
    Gtk.main
  end
end
 
=begin
 
Some features that could be added: 
 
* connect up menu items 
* figure out how save to... works; does it export to one specific format or
  several?  
* Not a feature, but can the code be made cleaner, cleaner, more testable? 
* Something indescribably awesome...
 
A couple random tips: 
 
install ruby-debug gem to step through this code to see how it works
See http://cheat.errtheblog.com/s/rdebug/ for more information
 
install the utility_belt gem for colorized irb and add  
 
require 'rubygems'
require 'utility_belt'
 
to a file ~/.irbrc
 
=end
 
if __FILE__ == $0
  Readinglist.main
end