Archive for March, 2005

Fsck PHP

Thursday, March 31st, 2005

How did I ever get lured into using PHP for my web development? Who planted this seed in my head? I am going to blame j$.

After spending several months only programming in Perl I have today started work again on some web tools that I develop. These tools are all written in PHP using Smarty and MySql. With the taste of Perl fresh in my mouth, I curse you PHP!

Why if I want to push a value onto an array do I need to use array_push instead of them just making a push function that is smart enough to deal with different data types? Actually, where are my strict data types to begin with? Why doesn’t it warn me when I am implicity treating a string like an array?

I think that I have come to the conclusion that PHP is a toy. It might be a nice toy but I am no longer going to give it more than that. I guess that leaves me with, well, I don’t know to be honest.

There are so many things that you are just doing all the time to generate websites that there are no facilities for included in PHP. Smarty templates feel like a hack to me. They are a huge step in the right direction, but I just don’t like them that much.

To be honest most of my complaints may very will be caused by how I use PHP, not by PHP itself. That is totally possible. The problem is that after programming in PHP for several years I can’t see a fundamental change in my habits occuring. Maybe it is time to move on. Maybe Ruby on Rails. Maybe do everything in Java on the backend. Maybe start using Cold Fusion. Maybe I should just switch to one of the .Net languages. Or just write everything as extensions to Apache in C.(For some reason I doubt the last three of those will happen.)

Then there is the weight of existing code binding me down. That means that all work will have to be bitwise. One new tool at a time I will slowly tip the scales to whatever new architecture I decide I like. Or maybe I should continue suffering, and focus on solving real problems like the fact I have to use 19 different sets of credentials in my office.

Just having one of those days where I realize some of the tools I am using don’t quite fit anymore. I am not sure where this train of thought will take me, if anywhere. I guess that makes this just another rant on just another blog.

Perl-Gtk2 Tutorial Part 4: And you thought HTML formatting was bad

Wednesday, March 30th, 2005

In the last section of the tutorial it became obvious that you could only put one object into a window. Well, that is not terribly useful. Unless you are happy with programs that only have an exit button, in which case thanks for visiting you have all the tools you need for an exit button.

For the rest of us, hoping to some day do something useful with our Perl GUIs, we are barely getting started. (I had no idea how much this tutorial was going to cut into my drinking time…) The biggest problem with creating a GUI using the tools we have available at this point is that we can only fit one damn object into our window. If only there was an object we could put in the window that could contain other objects.

Containers
Enter Gtk2::Container. Well really, enter Gtk2::HBox, Gtk2::VBox, and Gtk2::Table. There are tons of other classes that implement the Gtk2::Container object that are also useful, but using these three you can do nearly any formatting you want. There might be easier ways to do it, but we will talk about the easy ways later. First, we have to understand the hard way.

Generally, an HBox is an object that allows you to create a line of objects horizontally across the window. A VBox is an object that allows you to create a line of objects vertically down the screen. A Table is a grid that allows you to put objects pretty much wherever you want.

So far the examples have been staying pretty simple. Well, unfortunately, that is about to change. I will try my best to keep things simple, so bare with me. In the end you will either have a window that is formatted all wrong and be cursing the day you chose to use Gtk2, or you will have a beutiful professional looking app that makes you proud. Or you will somehow end up with both and be just a little more compassionate when cursing the names of the people who design bad user interfaces for your favorite programs.

My first word of advice on window layout with Perl-Gtk2 is to get out a piece of paper and sketch out what you want your window to look like. You have to be way too precise in layout to just wing this stuff. There are really a lot of decisions to make here. Do you want your program to have a tabbed interface? Will all of your info fit in one window, or will you need to be able to scroll? Do you have to have total control over size and layout, or are you okay with the API doing autosizing of windows and widgets?

This portion of the tutorial is only going to be really helpful if you want to do a non-tabbed interface, no scrolling, and are okay with GTK2 autosizing everything. There will be more on window formatting in future tutorials including scolled windows and tabbed windows.

Gtk2::VBox
Important Member Functions:new, pack_start_defaults($object), pack_end_defaults($object), reorder_child($object, $int)
Important Signals:None really.
Descriptions:A VBox is a container that allows you to pack objects vertically down your window.
Code:
#!/usr/bin/perl

use strict;
use warnings;

use Gtk2 '-init';

my $vbox = Gtk2::VBox->new;
my $checkbox = Gtk2::CheckButton->new_with_label("Added First (juggle)");
my $checkbox2 = Gtk2::CheckButton->new_with_label("Added Second");
my $checkbox3 = Gtk2::CheckButton->new_with_label("Added Last");

$vbox->pack_start_defaults($checkbox);
$vbox->pack_start_defaults($checkbox2);
$vbox->pack_start_defaults($checkbox3);

# When checkbox is toggled on make it last, when off make it first
$checkbox->signal_connect (toggled => sub {
   #If the button is toggled on, make it last
   if ($checkbox->get_active) {
      $vbox->reorder_child($checkbox,3);
      # If the button is toggled off, make it first
   } else {
   $vbox->reorder_child($checkbox,0);
   }
});

# Set up window
my $window = Gtk2::Window->new;
$window->set_title ('VBox example');
$window->signal_connect (delete_event => sub {Gtk2->main_quit});

# Add vbox to window
$window->add($vbox);
$window->show_all;
Gtk2->main;

Gtk2::HBox
Important Member Functions:new, pack_start($object), pack_end($object)
Important Signals:None really.
Descriptions:An Hbox is a container that allows you to pack objects horizontally across your window.
Code:
#!/usr/bin/perl

use strict;
use warnings;

use Gtk2 '-init';

my $hbox = Gtk2::HBox->new;
my $checkbox = Gtk2::CheckButton->new_with_label("Added First (juggle)");
my $checkbox2 = Gtk2::CheckButton->new_with_label("Added Second");
my $checkbox3 = Gtk2::CheckButton->new_with_label("Added Last");

$hbox->pack_start_defaults($checkbox);
$hbox->pack_start_defaults($checkbox2);
$hbox->pack_start_defaults($checkbox3);

# When checkbox is toggled on make it last, when off make it first
$checkbox->signal_connect (toggled => sub {
   #If the button is toggled on, make it last
   if ($checkbox->get_active) {
     $hbox->reorder_child($checkbox,3);
   # If the button is toggled off, make it first
   } else {
     $hbox->reorder_child($checkbox,0);
   }
});

# Set up window
my $window = Gtk2::Window->new;
$window->set_title ('HBox example');
$window->signal_connect (delete_event => sub {Gtk2->main_quit});

# Add vbox to window
$window->add($hbox);
$window->show_all;
Gtk2->main;

Gtk2::Table
Important Member Functions:new($rows,$cols), attach_defaults($object, $left, $right, $top, $bottom), remove($object)
Important Signals:None really.
Descriptions:The Table container allows you to create an arbitrarily sized grid, and then attach objects to any part of that grid. This is a really useful container, but it can be hard to get the layout to look exactly as you want.
Code:
#!/usr/bin/perl

use strict;
use warnings;

use Gtk2 '-init';

#Create a table with 10 rows, and 4 cols
my $table = Gtk2::Table->new(9,3);
# Make every row the same height, ever col the same width
$table->set_homogeneous(1);

my $checkbox = Gtk2::CheckButton->new_with_label("Added First (juggle)");
my $checkbox2 = Gtk2::CheckButton->new_with_label("Added Second");
my $checkbox3 = Gtk2::CheckButton->new_with_label("Added Last");

# First checkbox goes top left. Remember it is ($object, $left, $right, $top, $bottom)
$table->attach_defaults($checkbox, 0, 1, 0, 1);
# Second checkbox we will have room to stretch
$table->attach_defaults($checkbox2, 0, 3, 3, 5);
# Last checkboc will skip some space to be on the bottom right
$table->attach_defaults($checkbox3, 2, 3, 8, 9);
# When checkbox is toggled on make it left justified, when off make it right
$checkbox->signal_connect (toggled => sub {
   #If the button is toggled on, make it last
   if ($checkbox->get_active) {
      $table->remove($checkbox);
      $table->attach_defaults($checkbox, 2, 3, 0, 1);
   # If the button is toggled off, make it first
   } else {
      $table->remove($checkbox);
      $table->attach_defaults($checkbox, 0, 1, 0, 1);
   }
});

# Set up window
my $window = Gtk2::Window->new;
$window->set_title ('Table example');
$window->signal_connect (delete_event => sub {Gtk2->main_quit});

# Add vbox to window
$window->add($table);
$window->show_all;
Gtk2->main;

Nesting Containers like little Russian Dolls
The code above shows three common contains and how to use them to add a bunch of objects to one window. We are starting to get close to being able to create a usable UI. Although the table container is nice for organizing layout both vertically and horizontally, there are times that you are going to want to stack a bunch of Hbox on top of each other inside of one Vbox. Nesting these two containers allows the creation of very usable content in windows.

#!/usr/bin/perl

use strict;
use warnings;

use Gtk2 '-init';

# There will be one VBox that contains three HBoxex. The top most
# HBox will also have a VBox nested inside of it.
my $outer_vbox = Gtk2::VBox->new;
my $top_hbox = Gtk2::HBox->new;
my $top_hbox_inner_vbox = Gtk2::VBox->new;
my $main_hbox = Gtk2::HBox->new;
my $bottom_hbox = Gtk2::HBox->new;

# Add a couple of objects to top_hbox
$top_hbox->pack_start_defaults(Gtk2::Label->new("Top HBox First"));
$top_hbox->pack_start_defaults(Gtk2::Label->new("Top Hbox Second"));

# Add a couple of objects to the top_hbox_inner_vbox
$top_hbox_inner_vbox->pack_start_defaults(Gtk2::Label->new("Top Inner First"));
$top_hbox_inner_vbox->pack_start_defaults(Gtk2::Label->new("Top Inner Second"));
$top_hbox_inner_vbox->pack_start_defaults(Gtk2::Label->new("Top Inner Third"));

# Add the top_hbox_inner_vbox to the top_hbox
$top_hbox->pack_start_defaults($top_hbox_inner_vbox);

# Add the top_hbox to the outer_vbox
$outer_vbox->pack_start_defaults($top_hbox);

# Add a couple of objects to the main_hbox
$main_hbox->pack_start_defaults(Gtk2::CheckButton->new_with_label("Main Check 1"));
$main_hbox->pack_start_defaults(Gtk2::CheckButton->new_with_label("Main Check 2"));
$main_hbox->pack_start_defaults(Gtk2::CheckButton->new_with_label("Main Check 3"));

# Add the main_hbox to the outer_vbox
$outer_vbox->pack_start_defaults($main_hbox);

# Add something to the bottom_hbox
$bottom_hbox->pack_start_defaults(Gtk2::Label->new("Bottom Hbox First"));
$bottom_hbox->pack_start_defaults(Gtk2::Label->new("Main is this cluttered and ugly"));

# Add the bottom_hbox to the outer_vbox
$outer_vbox->pack_start_defaults($bottom_hbox);

# Set up window
my $window = Gtk2::Window->new;
$window->set_title ('Nesting example');
$window->signal_connect (delete_event => sub {Gtk2->main_quit});

# Add vbox to window
$window->add($outer_vbox);
$window->show_all;
Gtk2->main;

Man. Both the code and the resulting window is messy. Maybe there is a better way. Right now I don’t know for sure, but hopefully as this tutorial progresses we can figure out some better ways to do page layout. Next up is talking about windows, scrolled windows, and notebooks.

1969 Ford Mustang Mach 1 351W

Tuesday, March 29th, 2005

Just to be clear to everyone, I am NOT selling this car. It is a car that belongs to a relative who is holding onto it until I have the garage space to keep her myself. If all goes well, he will pass the car onto me and I will be able to pass it onto my son (or son-in-law as the case may be) when I am old. If all goes well, it will absolutely never be put on the market, because muscle cars, like fine silver, should never leave the family.

This past weekend an offer was extended to me that puts me in the best difficult position I have ever been in. A relative offered me a 1969 Ford Mustang Mach 1 for an unimaginably attractive price. This leaves me scrambling to figure out if I can make it work.

The car is mechanically very sound. A lot of professional love and care have went into it over the years. The person who has the car is unable to drive it very often because they have bad hips and can’t work on the car. A muscle car you can’t work on is basically a muscle that doesn’t run. It needs some brake work, but they are planning on having that done before I would get the car.

The car exterior is in very good shape. I don’t know how good because I have never looked too closely at it. From a distance it looks great. It is a dark metalic blue with all of the Mach 1 graphics on it mostly in black. It is a Fastback. Having never looked to closely, I am pretty sure it’s exterior is in better shape than the exterior of my current car.

The car interior is a bit of another story. It needs work. I don’t remember it being too bad, but it definately needs work. New seats front and back. Probably new carpeting throughout. Probably a bunch of other work as well.

After doing some research it looks like the cost of replacement parts for the car are along two seperate tiers. There is the cost of original OEM parts, which is very high. Then there is the cost of modern high performace parts from Edlebrock, Holly, MSD, and Ford Racing. These parts are actually really fairly priced. No more expensive than parts for my Cougar that is for sure.

So, to make this happen I need to scroung up the money/time to get the car from Cleveland to Colorado. There is a lot of research that has to be done on this front. First I would have to sell my Cougar. This should not be too hard to do because I don’t owe all that much money on it. That will get rid of my $300 a month car payment.

Next I need to get new insurance. It looks like removing my Cougar and putting the Mustang onto my current insurance as a daily driver would be about another $20 a month. Not bad. I need to do more research and see if I need to go through a more specialty provider.

Someplace to store it. I want a garage space at my apartment complex, but it looks like there are none available at the moment. That will add another $80-100 a month.

Transporting the car from Cleveland to Boulder looks like it will cost less than $1000 (as little as $700) if I go uncovered and $1500 if covered. That is cheaper than me going to Cleveland and driving it back.

So, that looks like $1000 up front which isn’t bad plus an additional $120 a month fixed. Since I won’t have a payment on it that will mean a new change of ~$200 a month less fixed payments. That should almost be enough to keep her running.

I really have to find a way to make this happen. I just do. I want a muscle car and my wife is in on it. That alone might never happen again.

Perl-Gtk2 Tutorial Part 3: So many widgets to chose from

Monday, March 28th, 2005

In Part 1 and Part 2 of this tutorial I introduced some of the basics of how to get started with Perl-Gtk2. Now that you can throw up a basic window and understand signals and callbacks, we need to go over some of the objects that you can pick from to fill your window and listen for signals from.

If you look at the Perl-Gtk2 documentation you will quickly realize that there are nearly countless objects to chose from. How do you know which one to use? How do you use them? How do you decode those crazy pages in the documentation?

This post is going to cover some of the simple building block objects that I think are most useful. If anyone else wrote this page they would have an entirely different set of favorites I am sure. Some things I am not going to cover here:

  • Windows, Containers, and other formatting stuff is still to come
  • ItemFactories are cool, but too complicated for this page
  • SimpleList and SimpleMenu are my true favorite widgets, but those will come later and in much more detail
  • Everything else. There are countless widgets to chose from so don’t think that this list will have the best one for whatever you are doing.

This page will be formatted simply to try and get you the info that you need in order to use these objects soon. These lists will probably be incomplete and definately be irresponsible. The lists won’t have where these objects fall in the Hierarchy, so you will have no idea what they will inherit from thier parent objects. They will gloss over vitally important info and cause you trouble in the long run. You should really be referring to the Documentation. The code below will only be described in detail if it departs significantly from Example 1 or Example 2.

Gtk2::Button
Important Member Functions: new_with_label($string)
Important Signals: clicked, activate, enter, leave
Description: Ahh, the button. Where would software be without buttons. The command line, that’s where. You will use buttons for everything. You wanna save a file, click this button. You wanna kill a program, click that button. You want to launch an ICBM, click the button. This example is not great because the button fills the whole window. When you add other stuff to the window this will no longer a problem, so wait for the discussion of containers.
Code:
#!/usr/bin/perl

use strict;
use warnings;

use Gtk2 '-init';

my $button = Gtk2::Button->new_with_label("Kill Me.");
$button->signal_connect (clicked => sub {Gtk2->main_quit});

# When your mouse enters button area, change label
$button->signal_connect (enter => sub {$button->set_label("Mmm. Mouse")});

# When you mouse leaves button area, change label back
$button->signal_connect (leave => sub {$button->set_label("Kill Me.")});

# Set up window
my $window = Gtk2::Window->new;
$window->set_title ('Button example');
$window->signal_connect (delete_event => sub {Gtk2->main_quit});

# Add button to window
$window->add($button);

$window->show_all;

Gtk2->main;

Gtk2::CheckButton
Important Member Functions: new_with_label($string), get_mode, set_active($bool)
Important Signals: toggled
Description:This is the checkbutton that we have been talking about since day 2. It actually is a lot like a button that remembers whether it has been clicked or not. A very similar objects is the Gtk2::ToggleButton, which is functionally the same except it is drawn as a full button that stays down once clicked.
Code:
#!/usr/bin/perl

use strict;
use warnings;

use Gtk2 '-init';

my $checkbox = Gtk2::CheckButton->new_with_label("Check me out.");

# This is a complex enough sub that good form would dictact that it be
# a real sub, not an anonymous sub. We will cover using real subs
# in an upcoming part of the tutorial.
$checkbox->signal_connect (toggled => sub {

   #If the button is toggled on, change the text to something good
   if ($checkbox->get_active) {
      $checkbox->set_label("I'm checked.");

   # If the button is toggled off, change to something boring
   } else {
      $checkbox->set_label("I'm umchecked.");
   }

});

# Set up window
my $window = Gtk2::Window->new;
$window->set_title ('Button example');
$window->signal_connect (delete_event => sub {Gtk2->main_quit});

# Add button to window
$window->add($checkbox);

$window->show_all;

Gtk2->main;

Gtk2::Label
Important Member Functions: new($string), set_text($new_string)
Important Signals: None really.
Description:This Object is just used to display a string of text on the screen. Generally there will not be a lot of interaction with it from the user, but you might need to change the text after the program has started running.
Code:
#!/usr/bin/perl

use strict;
use warnings;

use Gtk2 '-init';

my $label = Gtk2::Label->new("Just a plain label.");
$label->set_text("The text changed before you noticed.");

# Set up window
my $window = Gtk2::Window->new;
$window->set_title ('Label example');
$window->signal_connect (delete_event => sub {Gtk2->main_quit});

# Add button to window
$window->add($label);

$window->show_all;

Gtk2->main;

Gtk2::Entry
Important Member Functions: new, set_text($new_string), get_text
Important Signals: changed
Description:At this point I bet you are thinking that the true or false nature of buttons and such are pretty restricting. Enter the Entry. Sweet, sweet text entry. Now we can write a program that allows you to enter your favorite four letter word.
Code:
#!/usr/bin/perl

use strict;
use warnings;

use Gtk2 '-init';

# Set up a text entry
my $entry = Gtk2::Entry->new;
$entry->set_text("Type Exit to Exit!");

# Set up a callback so that if the text is changed to be
# equal to Exit the window closes.
$entry->signal_connect( changed => sub {
   if ($entry->get_text eq "Exit") {
      Gtk2->main_quit;
   }
});

# Set up window
my $window = Gtk2::Window->new;
$window->set_title ('Entry example');
$window->signal_connect (delete_event => sub {Gtk2->main_quit});

# Add button to window
$window->add($entry);
$window->show_all;
Gtk2->main;

Okay, this is only the absolute tip of the iceberg as far as objects in this API go. I have picked four or five of the most basic objects that are used for user interaction. I have not covered some of the most useful in my opinion, but we will get there. Keeping it simple for now.

In all of these examples you may have noticed that you can only add one item to a window right now. Well, that is not too useful. The next tutorial will start to address this issue of how to add a bunch of objects to one window to make something useful. Or at least something pretty. Okay I can’t really promise either of those things. Maybe we should just try and make something entertaining.

Bash Scripting

Monday, March 28th, 2005

Advanced Bash-Scripting Guide I almost bookmarked this page to read later when I realized that that was a really stupid way to tie that knowledge to one computer…

Stupid laptops…

Sunday, March 20th, 2005

So, I have been reading up a bit lately on how cool Solaris 10 is, and how everyone in the world should run it. I am not buying all of that hype, but I will admit that JDE is pretty and containers appear to be really, really cool.

The problem is that I only have a laptop to install it on. So, I take a swing at getting it installed on my Dell C400 only to learn that it has the crappiest video card ever. It uses the onboard Intel i830 graphics controller. This doesn’t use it’s own ram, but steals system ram instead. What a load of crap. On top of this, the dell bios is flakey and only allows it to steal 1mb of system ram.

So, I am left trying to get X to run with more than 256 colors at a decent resolution, and having no luck. I will post more if I can figure it out today. I will only screw around with it for a couple of more hours, then I am going to try Redhat 9 and see if I have better luck with that.

Perl-Gtk2 Tutorial Part 2: Signals, Callbacks, and Doing Stuff

Wednesday, March 16th, 2005

In my post on using perl-gtk2 yesterday I showed the basics of how to write a perl program that generates a window using Perl-Gtk2. The window didn’t really do much. Just sat there and was pretty. In order to do stuff, you have to start worrying about signals and callbacks.

Perl-Gtk2 is an event driven API so once the window is up and being displayed the program just waits there for something to happen. These things that are happening can either be in the backend, or they could be the user interacting with the GUI.

Every time something happens to an object in the GUI, it emits a signal. (This might not be 100% true, but is close enough for our purposes.) If you backend changes the state of a checkbox, the checkbox yells out “toggled”. If the user clicks on a button, the button hollars “clicked”. These are signals.

So we have all of these objects making a huge racket. What do we do now? We have to tell the program what to do when it recieves each of these signals. So, in our example, for our checkbox we say that when you are toggled call the function to close the window. Here is what that would look like:

(Example 2)

#!/usr/bin/perl -w

use Gtk2 '-init';

my $window = Gtk2::Window->new;
$window->set_title ('SimpleList examples');
$window->signal_connect (delete_event => sub {Gtk2->main_quit; TRUE});

my $checkbox = new Gtk2::CheckButton("Kill Me!");
my $checkbox_callback_id = $checkbox->signal_connect( toggled =>
           sub { Gtk2->main_quit; 1 });

$window->add($checkbox);
$window->show_all;

Gtk2->main;

Most of this code is the same as from Example 1 in Part 1. Here is a breakdown of what is happening in each new line, and lines that will make more sense now.

$window->signal_connect (delete_event => sub {Gtk2->main_quit; TRUE});
This line was in example 1 as well, but it should start to make more sense now. This code is saying that if $window emits the delete_event signal then have Gtk2->main exit the event driven loop. How do you get the main window to emit that signal? The easiest way is to click the “X” button on the window decorations or to chose close from your window manager if it provides that.

my $checkbox = new Gtk2::CheckButton("Kill Me!");
In order to show how signals work, I have to add something to interact with. An upcoming part of the tutorial will go into details on the different objects that you can include in your GUI, so don’t worry about the details too much yet.

my $checkbox_callback_id = $checkbox->signal_connect( toggled =>
           sub { Gtk2->main_quit; TRUE });

Here is the heart of the lesson. I have this checkbox on the screen that is labled “Kill Me”. This code is what makes it live up to that label. The code associates a callback to the anonymous sub when the button emits the “toggled” callback. When the button yells that someone toggled it, it executes this sub. (Which does the same thing as clicking the close button at the top of the window.)

$window->add($checkbox);
This line adds the checkbox to the window so that it is displayed. More details will be provided on window layout in an upcoming part of the tutorial.

So, by adding a couple of more lines of code to our example we now have a window that does something. Not a lot, but more than what our window could do after the first part of the tutorial. Signals and Callbacks are the hardest thing to deal with in GUI programming other than getting the GUI layout to look like you want.

If Signals and Callbacks still do not make a lot of sense, we will revisit them in more detail once we have a better grasp on how to use perl-Gtk2. That section will cover what parameters are passed to your callback function, how to disable and re-enable a callback, and how to disassociate a callback entirely from a signal.

In the next section of the tutorial, I will give you a tour of some common Widgets that you can add to your windows to make your windows do neat things other than just destroying itself.

Perl-Gtk2 Tutorial Part 1: Windows, Windows Everywhere

Tuesday, March 15th, 2005

I have been writing a lot of simple administrative scripts for the computer systems my company sells lately. Up until now these scripts have been aimed at our field reps, not our customers. That is about to change, and I certainly don’t want to present my customers with a gnarly text based interface. End users mean that I am going to need to start writing some GUI interfaces.

I have blogged and posted about my initial attempts at creating this interface. Now that I am getting close to being done with this first GUI I thought that I could give back some of what I have learned.

The first lesson that I learned is that there is not a terrible amount of information out there on using Gtk or Gtk2 in Perl. Heck, a lot of the time the documentation for perl is along the lines of “Look at the C API documentation and figure it out.” Cool if you are a C programmer, but that does not seem to be a fair assumption to make. Here is my attempt to fix that. If this goes well I am thinking I might be able to give it back to Perlmonks to thank everyone who has been so helpful with this.

In the beginning there was only the window:
(Example 1)
#!/usr/bin/perl -w
use strict;
use Gtk2 '-init';

my $window = Gtk2::Window->new;
$window->set_title ('My First Window!');
$window->signal_connect (delete_event => sub {Gtk2->main_quit; 1});
$window->show_all;

Gtk2->main;

Wow. It only takes 7 lines of perl to generate a window that is totally useless. Man is it tempting to create a program that does popup advertising in my programs now. Line by line, here is what is happening.

#!/usr/bin/perl -w
use strict;

This one is pretty self explanatory. Every one of your scripts starts similar to this, right?

use Gtk2 '-init';
This pulls in the Perl-Gtk2 module (you have it installed right?) and initializes Gtk+ and Glib. According to the Gtk2-Perl docs pretty much every script that uses Gtk2 should use -init.

my $window = Gtk2::Window->new;
Now we are getting to the good stuff. This is what actually creates a new window. Before we display this window though, lets set some of it’s attributes so that it looks and behaves as we expect a window to look and behave.

$window->set_title ('My First Window!');
What good is a window without a title telling the user where this window came from. This is a great example of how you set the properties of Gtk2 objects. Get used to the $object->function($args) format because you are going to be using it a lot.

$window->signal_connect (delete_event => sub {Gtk2->main_quit; 1});
Okay, now we are getting a little deeper into Gtk2. Gtk2 is an event driven library. So, once we create these objects and display them, the program sits in Gtk2->main, and waits for the user to do something. Each time the user does something, a signal is emitted. These signals are what tell us that a user clicked on a checkbox, or typed something into an editible field, or clicked the close button. This line of code, and the idea between signals and callbacks will explained in the next portion of this tutorial.

$window->show_all;
Cool. We have everything we need for a basic window, so lets show it off to the world.

Gtk2->main;
At this point, the program enters Gtk2->main and waits for the user to interact with it in some way. In our case, since the only functionality we have added to the window is a way to close it, the only thing that it cares about is someone clicking the Close button in the window decoration (or title bar if you like).

Thats it. We have 7 lines of code that create a window, tells the window how to destroy itself, and then displays that window. In the next section I will cover basic Signals and Callbacks because those are what allow us to do actual things when the user interacts with our window.

The (International) Noise Conspiracy

Monday, March 14th, 2005

How can you go wrong with a name like this?

The (International) Noise Conspiracy has the same lead singer as the band Refused, and seems to have taken the creativity of Refused to entirely new and unexpected heights.

I saw Refused long, long ago in Chicago right after they released “Songs to Fuel the Flames of Discontent”. To be honest I was not terribly impressed. I never really liked that album all that much. It is certainly not bad, but it is certainly not spectactular. When Refused released The Shape of Punk to come I was floored.

First, it takes some guts to name an album “The Shape Of Punk To Come”. Then, to pull it off as a truely groundbreaking album that is immensly creative and accessible at the same time. Not to mention having dancing beats.

So, when I started listening to The (International) Noise Conspiracy album “The First Conspiracy” I was not real sure what to expect. Even expecting something unique I was not in any way prepared for this band. Half punk with similar vocal tracks to the later Refused albums. Half… Well… Half rockabilly. Or maybe half gospel. Who knows that the other half is but it rocks.

The way “T.I.M.E.B.O.M.B.” overlays screaming desperate vocals with some old school keyboards and surf rock guitars is brilliant. “The Blast” is more upbeat, the type of music you can dance with your girl to, with sweet in-tune female backups over throaty lead vocals.

The whole time I am listening to these songs I am thinking “Man, I need to have some Lucky Strikes rolled up in my sleaves and to be riding an old shovel head.” This is not a rockabilly band in the sense that I think of High Fi and the Road Burners or the Reverand Horton Heat, but it certainly has a lot of that spirit in it. This is as close to good old fashioned rock and roll as a punk band can get without turning into an old fashioned rock and roll band.

CELs and a dead car

Monday, March 14th, 2005

This past week my cars CEL light came on while driving home from work. Since I didn’t have any time to look at what was going on, I just parked the car and drove my wifes until I had a chance.

Saturday morning I got up with the best intentions of working on my car. I hop in it to drive it to the auto parts store to read my engine diagnostic codes. Turn the key, the starter spins the engine, but it won’t start. It doesn’t sound like anything is firing at all actually.

Shit. Well, in my simplistic view in order to get fire in an engine you need air, fuel, spark, and compression. Grab Stephanies car and head to the auto parts store. Get a new air filter and fuel filter and borrow one of thier engine code scanners. I don’t really think it is the air or fuel filter, but it couldn’t hurt to change them and it is a very cheap thing to try.

Swap out the air filter, no improvement but man was my old one nasty looking. Swap out my fuel filter, no improvement but I am a little high from spending an extended period of time under my car with gas fumes. Scan my engine codes and discover I am getting a CEL light for “P0430 - Catalyst inefficency”. Looking on line this could be caused by a bad catalytic converter directly, or it could be being caused indirectly by a bad O2 sensor or bad MAF sensor. None of those things should cause my car to not start though.

At this point I let my engine flood and I can smell gas from it. So, I am most likely getting air and fuel. Next up is spark. My car has a distributorless ignition system and is the first car I have ever worked on without a distributor. I test my ignition coil and see that the primary windings are reading 1.5 ohms instead of between 0.3 and 1.0 which is what my Chiltons tells me it should be. This is a really easy thing to change on my car so I head to the autoparts store and buy a new coil. Take it home and test it and it comes back with the same readings as my old one. Pop it on the engine and it still won’t start. Put the old one back on and pop the new one in it’s box to return.

At this point JT shows up so I make him run me to the autoparts store this time. If my ignition coil is good, the next thing to try would be my spark plugs and wires. To be honest, my car was long, long past due for new plugs and wires. So, out with the old and in with the new. With JT and I both working on the car at the same time we are able to replace all the plugs and wires in less than an hour.

Hop in and turn the key. The car sputters to life. Rejoice! It is running like shit though. As I let it run for a minute my check engine light comes on and begins flashing. Fsck. That indicates that the engine is misfiring on my car. Well at least the car is running. That is a huge step in the right direction. I shut the car off and start heading upstairs to see what the folks on the cougar forum have to say about this.

As I walk into my apartment it hits me. My fuel filter. I changed my fuel filter and this is the first time I have started the car since. There is going to be air in the fuel line initially. I go back out start the car and let it run for a minute. The engine quickly smoothes out and is running quietly. No CEL. No nothing. Perfect.

So after $100 dollars and an afternoon of work my car is back in the world of the living. New spark plugs, spark plug wires, air filter, and fuel filter. She is actually running much, much better than before this incident. I guess she got to a point where she just wasn’t going to run anymore without a tuneup.