Monday, March 30, 2009

wxPerl: adding a GUI to the twitter script (part 1)

So far, I've only dabbled with Perl console applications. There is nothing wrong about them, and if you come from the Linux world you are probably quite familiar with running a program from the command line.
The standard Windows users however may not be as comfortable around CLI (Command Line interface) apps as they are around Graphical User Interface (GUI) programs.

I. Describing the need
  • The first need is to provide a simple GUI interface. I am tired of opening a shell, going to the script directory and typing something like:
    perl twit.pl -s "I am so lazy" -a
    every time I want to update my Twitter and Identica messages. I just want to type my text and click on a "Send" button.
  • Monitor the number of characters being typed so that it doesn't go over the 140-character limit.
  • Provide a standalone application that my mom would find easy to use.
  • I would also like to have the possibility of removing the last post for both Twitter and Identica, in case of a spelling mistake detected after sending the update for example.
II. Technical choices
From using Padre, wxPerl is already installed on my system in the form of the Wx module. I'll hence be using it (and it will help me understand the innards of Padre as a bonus).
Other options for GUI librairies would be Tk and Win32::GUI (the last one for Windows only obviously).

To build the standalone application, I have Perl2Exe in mind. However, I have not done much research on the subject yet. If you want to tell about your favorite choice in the comments section, I'll select from the list (or I might open a poll). Documention for the Wx module also mentions PAR and Perl2App.

II. Design the UI
Here's the list of needed elements:
  • Text box to enter up to 140 characters (2 lines of 70?)
  • 2 check boxes for twitter
  • 2 check boxes for identica
  • 1 "Send" button
  • 1 "Delete Last" button
  • 1 menu item to create/open login file
Let's try to lay it out in Paint first:

Drawing of the GUI
  • Errors will be displayed through message boxes.
  • In the Login menu, choices will be:
    - "Select Login File": window opens asking for file location. Default location used at start up.
    Parses selected file and displays error message if format not recognized.
    Stores login + password for whatever social website is recognized
    Back in the main form, Twitter and/or Identica boxes are greyed out if no login is found.
    No login/password encryption planned for the moment
    - "Edit Login File" : window first pops up asking for login file location.
    Allows the login file to be edited from the application.
  • The Twitter and Identi.ca boxes of the "Status" area will both be checked by default (if logins are provided)
  • Not sure how I'm going to implement the "Delete Last" functionality yet. There is a destroy_status() method in the Net::Twitter module. I'll have to read the doc.
Reviewing the design, I am wondering about the double Twitter and Identica checkboxes. Wouldn't one set be enough? Unless each set is updated in parallel: setting the top (resp. bottom) Twitter box would also set the bottom (resp. top) Twitter box. What's your take on this?

I'd like to use Test Driven Development for this little project but I have no experience in either TDD or writing tests for Perl applications.

For TDD, I know that you must first write a test, check that it fails, code so that the test succeeds then write the next test. Once some tests are written and pass, you can improve the program's code knowing that you have a test suite ready to check that all the features still work. That's about the extent of my knowledge on this subject but it sounds like fun :)

Concerning the tests themselves, I've read through Modern Perl Book's recent posts on testing but it hasn't sunk in with me yet. I guess I'll have to start by looking into this.

Larry Wall's quote of the day:
"The whole intent of Perl 5's module system was to encourage the growth of Perl culture rather than the Perl core."


2 comments :

  1. The articles posted in Modern Perl about testing are somewhat advanced.
    To get started with testing, I suggest you take a look at Test::Tutorial (http://search.cpan.org/~rgarcia/perl-5.10.0/lib/Test/Tutorial.pod).
    You can start writing your tests using Test::Simple and then move on to Test::More. From then you have a lot more options (Test::Exception, Test::Pod, Test::Warn ...) but most of the time you'll settle with the one of the first two.

    ReplyDelete
  2. I came across great Twitter scrips online. Check the link for the same.
    http://www.gotesting.info/demo/

    ReplyDelete