Author Archive
Desktop GUI Programming (Python (PyDev, pygtk) and Glade)
I recently decided to get back into desktop applications. Since about 2000 I’ve focused on developing for the web using Perl and PHP (mostly PHP). But sometimes it is nice to write a desktop app, instead of having to write a web app for everything. I’ve written some applications using the PHP CLI option, but that isn’t quite the same as a gui. My motivation was to write a GUI that controlled ffmpeg and would allow me to capture screen casts for tutorials I needed to make.
I started my adventure looking at a GUI frontend for PHP. And ran across PHP-GTK+. I installed it, and looked at some tutorials on it, but the more I looked, the more it looked like the community was inactive and stale. I also couldn’t find any way to package my application to share with others. They would need to install PHP, compile GTK+ (which wasn’t all that easy), reconfigure PHP and then run my application. Although most of the programs would be for my eyes only, it would be nice to have the option to share from time to time. So that was the end of the road for my PHP adventure.
I then decided to look at other languages for developing the application. I considered some of the options out there, Java, C, Ruby, Python, but decided to give Python a try. I’ve coded Java before, and I wasn’t a fan. Always seemed like overkill for everything I wanted to do. I’ve heard lots of good stuff about Python, and it is usually installed with most Linux installations, so this was my language of choice.
I then began looking for a good IDE for Python. Being a big fan of Eclipse, I ran across pydev for Ecplise. A simple install into the software manager in Eclipse, and I was off to the races. You will need to configure the location to your python binary, which for me (Ubuntu 9.10) was in /usr/bin/python2.6 Enabling this, gives you all the fancy code completion which I love so much. If you need to set it up, you need to visit (In Eclipse) Window -> Preferences -> Pydev -> Interpreter – Python -> New… and browse to your python binary. (If you do not have python available, you may need to install it first using apt-get or Synaptic Package Manager. Just search for python, and it should install everything you need to get started.) Here are some tutorials for getting started with Python:
I’ve used Glade once before, very briefly just to figure out what it was. It is a GUI drawer. Similar to the GUI drawer in Visual Basic, it allows you to layout your interface without using code. It creates XML files which can be imported by your application (and it has bindings for many languages) that create your interface. You just need to connect your code to the signals in the GUI, and you can make magic happen. You will need to install Glade via Synaptic Package Manager. The current version is the 3.6 series. Here are some great tutorials to get you started with Glade:
- GTK+ and Glade3 GUI Programming Tutorial
- Writing a GUI app with Python & Glade
- A Beginner’s Guide to Using pyGTK and Glade (older, but still useful)
So, my first dabble in GUI desktop programming in a decade, and my first taste of python. About 5 hours later I had written the application I wanted. It is an 84 line python script binding to one glade file for the interface. It allows me to select a window, and using a pre-set configuration, launch ffmpeg and record a screencast. Still a lot of work to do before it is ready to be shared, but it is a great start. Using pydev via Eclipse for the Python coding, and Glade for the interface design, you should be able to turn out some simple desktop apps in a matter of hours.
This is probably just the beginning of my python coding, so you may see more here on that in the future.
The Director! is Complete!
Announcement
At long last, The Director! is complete. This is the URL redirection php/apache script that I mentioned early last month. Had a few minor things to fix up, which I finally did last night, and now it is available to all.
It is a very rough looking piece of software, true to my views that admins shouldn’t care what the software looks like, provided it works correctly, and it looks pretty to the public. Since I suck at UI, AND The Director! has no public face, this is the perfect project for me!
So what does The Director! do?
The Director! is a URL shortening/redirection service similar to tinyurl and others that allow you to point one web address to another (presumably a short one to a longer one). Currently it does some simple stat tracking (if you want) on the URLs, and allows you to manage your redirects. More information and a download can be found here: http://www.cornempire.net/go/director (this shows The Director! in action as I have it installed on my site now).
Requirements and Cost
The Director! is a free download, available under an undetermined licence at this time. You are free to use it, just don’t take the code and sell it. If you make any modifications, feel free to share them back to us (submit an issue to the bug tracker and attach your code). We provide no support or guarantees/warranty for the code, if you choose to use it, you are on your own. Later, I’ll enumerate that into some sort of formal licence.
In order to make use of The Director! you will need:
- A webserver
- PHP running on the webserver
- A domain name of some sort
- A rewrite module for fancy redirects (instructions provided for apache and mod_rewrite)
You will need access to edit your webserver config, or .htaccess file if you are on shared hosting.
If you run into any issues, make a note below and I’ll do my best to help. But again, no formal guarantees or warranty come with the application.
Screenshots
Certainly nothing to be proud of…but here are some screenshots of The Director! in all of it’s ugly orange glory:




Credits
Other then me, many thanks to Pat for his help in writing The Director!. As well as credit to Mark James for the Silk Icons which I don’t think I’ve actually put to use yet, but when I redesign the GUI, I will.
CBC Play On Hockey Tournament
This past weekend, me and a few friends played in the National CBC Play On street hockey tournament. It is a 3-on-3 tournament with a goalie. We played in the Adult Beginner division, and we had a pretty good go of it. Ended up finishing in second place, losing the championship game after a tough string of games to get that far.
I played defence most of the time as did Stefan, while Pat and Matt played forward and Chris played goal.
In the round robin we finished in 3rd place, tops of the teams who suffered a defeat:
Game 1: Hawk’s Heroes vs Doom’s Crew: 2 – 1 win. (8 AM)
Game 2: Hawk’s Heroes vs Johnsons: 8 – 5 loss. (Noon)
Game 3: Hawk’s Heroes vs GFW Shockers: 14 – 6 win. (6:40 PM)
In game 3, we only had 3 players, so we had no substitution. Stefan played goal in Chris’ absence. We played an exhausted Shockers team and ended up doing quite well (I even scored 2 goals).
Sunday was a different story. Starting at around 11 (they were late starting the game..as usual), we had a rematch with sixth seeded Doom’s Crew. Another hard fought 2-1 victory.
This win saw us playing at 12:40 against the undefeated Dark Park Destroyers. This was our hardest game yet. The game was tied at ones after the first half. The second half of the game, we could hardly get the ball out of our end. We had no solid chances to score, and defencively we were scrambling to stay alive. Late in the second half, Matt took a nasty fall on his chest as he went hard to the net and got tangled up with the goalie. Chris played awesome in goal, and managed to get us to a shootout. Pat, Stefan and Matt were our three shooters, and Matt managed to score on our final shot, and Chris shut the door to preserve the win. So we punched our ticket to the championship game at 2:40.
By this time we were all starting to get pretty beat up, and very exhausted. We were facing the number one seeded team who had only played one other game that day. This game started on time, and we managed to make it out of the first half with a 2 – 1 lead, but that is when the wheels fell off. It started to rain, and the street got very slippery, especially where the buses stop, as that pavement was full of oil. Our earlier games caught up with us, and we didn’t have much run left in us. They racked up a few quick goals with some great passing and ended up 6 – 2. We got one back, at 6 – 3, but they finished off 7 – 3.
So we ended up in second place. It was a great weekend, and we did better then we all thought we would, especially since most of us only play once a month or so. Hopefully we will be able to play again next year, and win it all. Attached is the playoff bracket.
Did you play in one of these events across the country? If so, leave a post below.
Art, with ASCII, Asciio and ditaa
Art…with ASCII you say. Well yes I do. Anyone from back in the day will appreciate ASCII art. Better yet is the ability to create ASCII art and diagrams easily. Enter the players:
asciio is a tool that allows you to easily make ASCII diagrams.
ditaa is a tool that converts ASCII art diagrams into rendered images suitable for webpages or publications.
These tools allow you to make nice rendered images and ASCII diagrams. As some have put it, ASCII Visio.
I’ve created a tutorial an how to modify asciio to better create ditaa diagrams. You can view this tutorial here: http://wiki.cornempire.net/asciiart/start Soon, many of these changes will be integrated with the package available with Debian Sid (and by extension, any Debian based Linux distribution).
The ideas for the modifications came from here: http://strawp.net/archive/geeking-out-with-diagrams-in-ascii/ and those ideas lead to the more expansive tutorial linked above. Thanks to David Paleino at Debian who has packaged Ditaa and asciio and may integrate some of these changes into the packages in the future.
If you use, or have interest in ASCII diagrams, leave a comment below.
New Project: The Director!
Just a quick announcement that I’m working on a new programming project called The Director!. It is essentially a url redirection/shortening service written in PHP and utilizing the apache rewrite module to do the really cool stuff.
Those in the know realize that creating such a service is just a few lines of code in the vhost entry for apache, and then a few lines of code in a php script to do the redirection, but the goal here is to make it easy to use management interface with a bit of simple stat tracking.
Hoping to have version 0.1 out this weekend (depending on how my fence construction goes this weekend).
You can view more information here: http://wiki.cornempire.net/thedirector/start
Useful Database Commands
Here are some neat database commands I recently came across while I was trying to get statistics and status information on some mysql and postgres databases.
Postgres
This will give you a list of all of the databases in the server.*
select datname from pg_database;
* If you don’t know how to connect to postgres from the command line, don’t fear (well fear a little). What I had to do was su to the user that is a DB user, and then run /usr/local/pgsql/bin/psql This launched a command line client (without needing a password), that let me query the server. I can’t provide a better understanding then that, as this is the first time I’ve ever interacted with a postgres server.
This tells you how big a particular database is.
SELECT pg_size_pretty(pg_database_size('xythosdocs'));
The output is like this:
pg_size_pretty
----------------
2834 MB
(1 row)
Mysql
Get all database sizes:
SELECT table_schema "Data Base Name", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB", sum( data_free )/ 1024 / 1024 "Free Space in MB" FROM information_schema.TABLES GROUP BY table_schema;
Produces output like this on the command line:
+--------------------+----------------------+------------------+
| Data Base Name | Data Base Size in MB | Free Space in MB |
+--------------------+----------------------+------------------+
| blogadmin | 0.35750008 | 0.00098896 |
| blogs | 90.60342026 | 27.73141003 |
| information_schema | 0.00781250 | 0.00000000 |
| musicschedule | 0.00548172 | 0.00020599 |
| mysql | 0.54032421 | 0.00000000 |
| phpflash | 0.77745819 | 0.00000000 |
+--------------------+----------------------+------------------+
Get some status information on the sever. Run this from the command line:
mysqladmin -uroot -p status
Phpmyadmin also provides a lot of process status information if you have that installed.
Add Comments to Column – MySQL
So, you have a nice new database table, and you forgot (or couldn’t) add comments to the columns when you created it. I recently ran into this problem, and my usual internet searches didn’t turn up much. One would expect a statement similar to this:
ALTER COLUMN `columnname` ADD COMMENT 'a comment'
However, that statement doesn’t exist.
If you have gotten to my post, you probably realize that there is no easy way to add comments (unless you have a nice application that does it for you). The real statement is something along the lines of this:
ALTER TABLE `courses` CHANGE `courseid` `courseid` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'a new comment'
Which means you need to know the table definition, and restate it every time you want to change the comment. If you are doing this in bulk, that is a pain in the butt.
So, I wrote this little script that will take a create table definition, and turn it into Alter Table commands, that will add comments to each of your columns.
All you need to do is run ‘SHOW CREATE TABLE `tablename`’ on your database table, and insert that definition into my script here, and it will spit out a series of Alter Table calls with a space for a comment appended to the end.
The script is very basic at this point, and expects the formatting as shown in the example. The GUI I use, DbVisualizer, as well as the mysql command line client spit this out. So hopefully yours will to.
If you find this useful, or run into any problems with the script, please let me know.
Edit (April 15, 2010): Uploaded v0.2. Small mistake that was placing the column name in place of the table name. Sorry to anyone that was used it before and noticed it.
Migration
I’m in the process of migrating multiple blogs into a single installation of WordPressMU. Please stand by as I correct the problems here.
In the end, I promise to have a nice blog post on it.
Lemmings Plus Plus
In one of my many Linux Game RSS feeds, I ran across an announcement for L++. This is a multiplayer version of the old Lemmings game. Lemmings is a puzzle game where you have to guide your no-brain lemmings from the entrance, to the exit.
L++ has all of the original single player content, plus a lot of extra player created content. It has a built in level editor (which I found wasn’t super easy to use) and 8 player network multiplayer.
It is quite surprising how fun multiplayer lemmings could be. If you are a lemmings fan, and have a friend or two, I’d highly recommend giving this a try.
Update: I just went to the site, and they currently have taken the download off as they remove some of the copyrighted content that was in the game. You can read more here: http://lplusplus.co.cc/topic.php?topic=16. Oddly enough, I only downloaded the windows version as that was the machine I was on when I decided to try this. I guess I’ll have to wait with you to give it a try.
Openshot/IM Conflict Ubuntu 9.10
I recently installed the excellent OpenShot video editor for Ubuntu because I had to splice together some video from our curling league. We had two cameras shooting the action from the Semi-Final, and Final games.
OpenShot is a very easy to use program from making some basic movies and it handled the two different format videos pretty well.
However, after installing, I noticed that I could no longer use AMSN, my instant messenger of choice. When launching from the terminal, I would receive an error about GStreamer problems. This also affected Pidgin, and I’ve heard reports of problems with Empathy and others too. The problem lies in frei0r-plugins package, which messes up gstreamer for some programs, and is required by OpenShot. The easy solution to get it working is to remove frei0r-plugins, but of course, OpenShot won’t work anymore.
sudo apt-get purge frei0r-plugins
After searching the net a bit, I ran across a launchpad page that pointed the finger at libgavl. The problem is fixed in libgavl 1.1.1. Of course, 1.1.0 is the highest version you can get with Ubuntu 9.10.
So, to correct this once and for all, you can compile 1.1.1 yourself, or you can download the .deb for Ubuntu 10.04. So, go here: http://packages.ubuntu.com/lucid/libgavl1 and download the correct version for your architecture, and you should be good to do.
I got some warnings about an older, more supported version being available in the repositories, but you can safely ignore that.