Follow up from previous post here.
At present, checking the bandwidth usage statistics for Reliance netconnect is clunky and laborious. In the previous post, I published a python script that I use to get the usage. To me, it seemed unnecessary to use a GUI for this. However, judging by the number of downloads, a lot of people have the need for this. And on windows, these people are not finding it as easy to install python and run the script from a terminal.
So responding to the demand, here is a GUI version. Remember to input the phone number with 0 (zero) as the first digit. The phone number and billing date are stored for subsequent uses. This was compiled and tested on windows XP.
For users with python and wxpython installed, you can download the script here and run it for the gui.
Any comments are welcome.
Credits:
Compiled with PyInstaller
Icons from here.
Showing posts with label python. Show all posts
Showing posts with label python. Show all posts
December 14, 2009
March 20, 2009
The command line tutor returns
I had stopped work on this long back, but found people still downloading it and discussing it once in a while. So here we go - a rewritten version can be got from its new home at google code. Any suggestions are welcome.
January 3, 2009
Emacs - a beginner's setup

It's almost 5 months since I started using emacs on a regular basis. After beginning to use it as a platform to learn lisp (with SLIME), now I use emacs for coding python and bash, writing manuscripts (with markdown), doing statistics with R (using ESS), file and directory management and sometimes even to play chess on FICS.
Emacs, in my opinion is something anyone should give a whirl. It is open source, free and easily installable on any operating system. It is an absolutely amazing piece of software - give it a shot and if after a couple of months you decide to give up, atleast you have got a taste of what it is about. Here I will attempt to list a few things that will ease the introduction to emacs.
Note: Many of these instructions may be specific for Gnu-emacs on Linux. They may vary if you are using another emacs variant or another platform.
1. Start off with a good looking emacs
An oft-repeated complaint is that emacs looks bad, bad enough to deter a newcomer sometimes. But then, it doesn't have to ...
Use the latest emacs snapshot that allows use of your preferred fonts with nice antialiasing. In Ubuntu this means
sudo aptitude install emacs-snapshot-gtk emacs-goodies-el
Now you can use any font you prefer by modifying the Xresources file as detailed here.
2. Disable the splash screen, scrollbar and toolbar. Add to your .emacs -
(setq inhibit-startup-message t)
(tool-bar-mode -1)
(scroll-bar-mode -1)
It may seem surprising to consider disabling the scrollbar and toolbar. Maybe a case can be made for having these on while you wean yourself from the mouse, but I believe that there are greater dividends to doing this early and getting used to mouseless editing. I have preferred leaving the menu-bar on although I dont use the menu items, just because it sometimes allows me to easily refer to the shortcuts available, but again, it is worth considering disabling this too.
3. Syntax highlighting
Install color themes. In ubuntu, this is done easily by installing emacs-goodies-el. Now, add this in your emacs to have 'font-lock' on for syntax highlighting.
(global-font-lock-mode t)
After M-x, typing color-theme- and hitting tab will shows the completions available. Try out the different color-themes to decide what you want to use. To enable it automatically, add a line like this -
(require 'color-theme)
(setq color-theme-is-global t)
(color-theme-scintilla)
4. Enable line numbers
If you feel lost without them,
(require 'linum)
(global-linum-mode)
5. If you like to 'see' a selected region, you have to enable transient-mark-mode -
(setq-default transient-mark-mode t)
6. And if you have trouble copy-pasting between other windows and emacs, this worked for me -
(setq x-select-enable-clipboard t)
With these basic things out of the way, you have a decent emacs set up to start with. There are multiple options for further customization, but I will leave them for you to experiment with. Packages to definitely try out are ido-mode, pabbrev, bookmarks and yasnippet.
Emacs, in my opinion is something anyone should give a whirl. It is open source, free and easily installable on any operating system. It is an absolutely amazing piece of software - give it a shot and if after a couple of months you decide to give up, atleast you have got a taste of what it is about. Here I will attempt to list a few things that will ease the introduction to emacs.
Note: Many of these instructions may be specific for Gnu-emacs on Linux. They may vary if you are using another emacs variant or another platform.
1. Start off with a good looking emacs
An oft-repeated complaint is that emacs looks bad, bad enough to deter a newcomer sometimes. But then, it doesn't have to ...
Use the latest emacs snapshot that allows use of your preferred fonts with nice antialiasing. In Ubuntu this means
sudo aptitude install emacs-snapshot-gtk emacs-goodies-el
Now you can use any font you prefer by modifying the Xresources file as detailed here.
2. Disable the splash screen, scrollbar and toolbar. Add to your .emacs -
(setq inhibit-startup-message t)
(tool-bar-mode -1)
(scroll-bar-mode -1)
It may seem surprising to consider disabling the scrollbar and toolbar. Maybe a case can be made for having these on while you wean yourself from the mouse, but I believe that there are greater dividends to doing this early and getting used to mouseless editing. I have preferred leaving the menu-bar on although I dont use the menu items, just because it sometimes allows me to easily refer to the shortcuts available, but again, it is worth considering disabling this too.
3. Syntax highlighting
Install color themes. In ubuntu, this is done easily by installing emacs-goodies-el. Now, add this in your emacs to have 'font-lock' on for syntax highlighting.
(global-font-lock-mode t)
After M-x, typing color-theme- and hitting tab will shows the completions available. Try out the different color-themes to decide what you want to use. To enable it automatically, add a line like this -
(require 'color-theme)
(setq color-theme-is-global t)
(color-theme-scintilla)
4. Enable line numbers
If you feel lost without them,
(require 'linum)
(global-linum-mode)
5. If you like to 'see' a selected region, you have to enable transient-mark-mode -
(setq-default transient-mark-mode t)
6. And if you have trouble copy-pasting between other windows and emacs, this worked for me -
(setq x-select-enable-clipboard t)
With these basic things out of the way, you have a decent emacs set up to start with. There are multiple options for further customization, but I will leave them for you to experiment with. Packages to definitely try out are ido-mode, pabbrev, bookmarks and yasnippet.
Loading image
Click anywhere to cancel
Image unavailable
October 4, 2008
Eepee - the electrophysiologist's tool
04 Oct 2008
Eepee is my attempt to make a tool for cardiologists to analyze ECG and Electrophysiology tracings.

The study of these tracings requires one to make various measurements and compare them. While this is available along with the acquisition software in the lab, review of these tracings for teaching or learning is usually done with printed / scanned tracings without an easy way to dynamically measure things. The usual approach is to use project a series of these tracings on powerpoint, while any measurements have to be made on a paper copy with hand-held calipers.
Eepee is an attempt to smoothly provide all this functionality with digital images. At its current state (version 0.9), the user can load any digital image, calibrate the x-axis with known measurement in the image and then use digital calipers to make measurements. Notes can also be made for any image. Notes and calibration are automatically stored for each image and are reloaded the next time.
It is still not past version 1.0 meaning that it is beta, but it is getting relatively complete and stable. It works on windows and linux and can be got here. I welcome any suggestions / comments.
Eepee is my attempt to make a tool for cardiologists to analyze ECG and Electrophysiology tracings.

The study of these tracings requires one to make various measurements and compare them. While this is available along with the acquisition software in the lab, review of these tracings for teaching or learning is usually done with printed / scanned tracings without an easy way to dynamically measure things. The usual approach is to use project a series of these tracings on powerpoint, while any measurements have to be made on a paper copy with hand-held calipers.
Eepee is an attempt to smoothly provide all this functionality with digital images. At its current state (version 0.9), the user can load any digital image, calibrate the x-axis with known measurement in the image and then use digital calipers to make measurements. Notes can also be made for any image. Notes and calibration are automatically stored for each image and are reloaded the next time.
It is still not past version 1.0 meaning that it is beta, but it is getting relatively complete and stable. It works on windows and linux and can be got here. I welcome any suggestions / comments.
April 6, 2007
An interactive Linux command line tutorial
Edit: A new version of cmd-tutor is now available. See here.
There has been a gradually increasing influx into the linux community in recent years. The release of Vista has encouraged a lot of people to take the plunge and switch to linux. And while it is not any more essential to use the command line to manage your linux desktop today, many newcomers are interested in knowing what it is all about.
A lot of excellent tutorials are available, like this for example, but there were some requests for an interactive tutorial. Those who have tried the online ruby tutorial will know what I am talking about.
So, I wrote this tutorial in python. Keeping in line with Unix philosophy, the mechanism for presenting the lessons is kept separate from the lessons itself. Therefore it is easy to extend it by adding more lessons later. Currently there are 5 lessons that I have written. These would serve as a gentle introduction to a newcomer.
You have to be running linux to use this. You can download cmd_tutor here. The instructions to install are in the package. Briefly, you have to extract the package somewhere, navigate to the src directory from the terminal and then type 'python install.py install' with superuser privileges. Once installed, you can type 'cmd_tutor' in the terminal to start the tutor.
Any comments and suggestions will be welcome.
There has been a gradually increasing influx into the linux community in recent years. The release of Vista has encouraged a lot of people to take the plunge and switch to linux. And while it is not any more essential to use the command line to manage your linux desktop today, many newcomers are interested in knowing what it is all about.
A lot of excellent tutorials are available, like this for example, but there were some requests for an interactive tutorial. Those who have tried the online ruby tutorial will know what I am talking about.
So, I wrote this tutorial in python. Keeping in line with Unix philosophy, the mechanism for presenting the lessons is kept separate from the lessons itself. Therefore it is easy to extend it by adding more lessons later. Currently there are 5 lessons that I have written. These would serve as a gentle introduction to a newcomer.
You have to be running linux to use this. You can download cmd_tutor here. The instructions to install are in the package. Briefly, you have to extract the package somewhere, navigate to the src directory from the terminal and then type 'python install.py install' with superuser privileges. Once installed, you can type 'cmd_tutor' in the terminal to start the tutor.
Any comments and suggestions will be welcome.
March 17, 2007
Tagging pdf documents with python
Tagging as a method of organizing and searching is commonly used for music files, pictures and favourite websites. For documents, the traditional method of searching has been based on indexing the content. All the modern desktop searches will index your pdf files. But using tags obviously has its advantages and people would go to great pains to manually add tags to each file as metadata or for organizing with itunes !
My personal itch is the need to search my collection of journal articles saved as pdf files. The problem with full text indexing of these files is that there is a long reference list at the end of these articles which misleads any attempt to search for a particular author, journal or title. I have struggled with this for some time and looked at applying tags to each file as a solution. The tags could be added as extended attributes in a linux file system like this or as metadata in a windows environment and used for searching. Even more useful might be applications that allow tagging and searching by tags. Tracker and leaftag come to mind for this purpose in Linux. The main hurdle, however, is that adding these tags manually is too tedious. So I experimented with ways to get the information for each pdf file from pubmed. The Biopython module provides a simple interface to the pubmed database from Python. So all one has to do is convert the pdf to text and then parse the text for some information that will allow correct identification at pubmed. The first step is relatively easy. Xpdf provides tools for pdf to text conversion, though I preferred to use beagle's data extraction tool since I already had beagle installed.
import commands
convertcommand = "beagle-extract-content \"" +pdffile +"\""
pdftext = commands.getoutput(convertcommand)
The second part is more difficult because there is no consistent formatting of contents between different publishers. The best way to do it turned out be using the doi. The doi or Digital Object Identifier is a unique name given to any digital object and is usually included in the publication. Parsing it was a matter of searching for 'DOI:' or 'doi:' in the text.
doi = pdftext.lower().split('doi:')[1].strip().split(' ')[0]
searchstring = doi +"[AID]"
The searchstring is constructed by adding the tag [AID] for Article Identifier. Searching in pubmed with this string with this string turns up the pubmed ID (pid) for the article. This allows retrieval of the formatted article information including title, authors, journal name, year of publication, volume and page numbers.
from Bio import PubMed
from Bio import Medline
rec_parser = Medline.RecordParser()
medline_dict = PubMed.Dictionary(parser = rec_parser)
pmid = PubMed.search_for(searchstring)[0]
record = medline_dict[pmid]
print "title is ", record.title
print "author is ", record.authors
print "source = ", record.source
Some journals, however, still do not provide the doi in the publication. So we need something to fall back on. I chose to use the article information which is usually published on the first page in a standard format like this - yr;volume:first page - last page (example 2007;41:272-275). There may sometimes be a space after the semicolon or the colon, so the search with regex looks like this.
import re
texttosearch = pdftext[:6000]
pattern = "[0-9]{4,};[ ]*[0-9]+:[ ]*[0-9]+"
m = re.search(pattern,texttosearch)
info = m.group(0)
yr = info.split(';')[0]
(vol,pg) = info.split(';')[1].split(':')
searchstring = vol +"[volume] AND "+ pg +"[page] AND "+ yr +"[pdat] + "+ "English[lang]"
For testing, I chose 10 journals comprising the prominent publications in medicine and cardiology and randomly picked an article each from Sep 2005 and Feb-Mar 2007. Correct information was obtained for all the 20 articles. Here is part of the output.
In conclusion, this seems a promising approach to automatically obtain information for each pdf file in my library. This information could be added to the file as extended attributes or used as tags for the file. Like Ruby, Python also has an xattr library and adding them automatically would be easy. The automatic retrieval will fail for some files, but the information could be added manually in such cases.
My personal itch is the need to search my collection of journal articles saved as pdf files. The problem with full text indexing of these files is that there is a long reference list at the end of these articles which misleads any attempt to search for a particular author, journal or title. I have struggled with this for some time and looked at applying tags to each file as a solution. The tags could be added as extended attributes in a linux file system like this or as metadata in a windows environment and used for searching. Even more useful might be applications that allow tagging and searching by tags. Tracker and leaftag come to mind for this purpose in Linux. The main hurdle, however, is that adding these tags manually is too tedious. So I experimented with ways to get the information for each pdf file from pubmed. The Biopython module provides a simple interface to the pubmed database from Python. So all one has to do is convert the pdf to text and then parse the text for some information that will allow correct identification at pubmed. The first step is relatively easy. Xpdf provides tools for pdf to text conversion, though I preferred to use beagle's data extraction tool since I already had beagle installed.
import commands
convertcommand = "beagle-extract-content \"" +pdffile +"\""
pdftext = commands.getoutput(convertcommand)
The second part is more difficult because there is no consistent formatting of contents between different publishers. The best way to do it turned out be using the doi. The doi or Digital Object Identifier is a unique name given to any digital object and is usually included in the publication. Parsing it was a matter of searching for 'DOI:' or 'doi:' in the text.
doi = pdftext.lower().split('doi:')[1].strip().split(' ')[0]
searchstring = doi +"[AID]"
The searchstring is constructed by adding the tag [AID] for Article Identifier. Searching in pubmed with this string with this string turns up the pubmed ID (pid) for the article. This allows retrieval of the formatted article information including title, authors, journal name, year of publication, volume and page numbers.
from Bio import PubMed
from Bio import Medline
rec_parser = Medline.RecordParser()
medline_dict = PubMed.Dictionary(parser = rec_parser)
pmid = PubMed.search_for(searchstring)[0]
record = medline_dict[pmid]
print "title is ", record.title
print "author is ", record.authors
print "source = ", record.source
Some journals, however, still do not provide the doi in the publication. So we need something to fall back on. I chose to use the article information which is usually published on the first page in a standard format like this - yr;volume:first page - last page (example 2007;41:272-275). There may sometimes be a space after the semicolon or the colon, so the search with regex looks like this.
import re
texttosearch = pdftext[:6000]
pattern = "[0-9]{4,};[ ]*[0-9]+:[ ]*[0-9]+"
m = re.search(pattern,texttosearch)
info = m.group(0)
yr = info.split(';')[0]
(vol,pg) = info.split(';')[1].split(':')
searchstring = vol +"[volume] AND "+ pg +"[page] AND "+ yr +"[pdat] + "+ "English[lang]"
For testing, I chose 10 journals comprising the prominent publications in medicine and cardiology and randomly picked an article each from Sep 2005 and Feb-Mar 2007. Correct information was obtained for all the 20 articles. Here is part of the output.

In conclusion, this seems a promising approach to automatically obtain information for each pdf file in my library. This information could be added to the file as extended attributes or used as tags for the file. Like Ruby, Python also has an xattr library and adding them automatically would be easy. The automatic retrieval will fail for some files, but the information could be added manually in such cases.
March 4, 2007
The User Interface of the future ?
Arguing whether the Command Line Interface (CLI) is superior to the Graphical User Interface (GUI) or vice versa strikes me as a futile exercise. It quickly becomes clear to anyone who has used both that the best way to interact with the computer is to use both methods. A CLI + GUI interface is vastly more powerful than a plain GUI interface. As you use both, you find more and more uses for the former, where it clearly surpasses the GUI. Why, you even start ordering your pizzas from the command line.
However, the difficulty many face in approaching the CLI initially is what Eric Raymond calls the 'mnemonic load'. Don Norman writes how the next major UI breakthrough should be in CLI. He anticipates the development of a more flexible command line language, with more resemblance to natural language and not requiring a strict adherence to an idiosyncratic syntax.
An alternative to an entire new language for the command line is to use a user-friendly intermediate layer which translates the user input into the syntax that the command line understands. This is analogous to the frequently used concept in Unix when a user friendly GUI actually uses command line tools, but provides a user friendly front end.
What you see below is a working prototype of such a program written in python. In its main loop, it collects user input and outputs a command to the terminal. When the input is a valid command line input, it is passed unchanged. But when it is not, it is 'translated' into a valid one. I call it the Genie. Here are a few examples of the genie in action.

The prompt includes a battery status monitor - I find it useful and it shows that the prompt is easily customizable. 'Normal' shell commands are interpreted directly - like 'ls -l | grep 2007-03' in the example. Navigation to usual places is easy just - 'go home' or 'go desk'. 'space' functions like an alias mapping to 'df -h / /home'. Note the genie says line which lets you know the command that is passed to the shell. So that a newcomer also learns shell syntax along the way.

When you want to install an application just 'install'. If the app is found in the apt-cache, installation is started. Otherwise you are allowed to choose from the matches in the apt-cache.

Any calculations are automatically recognized and passed on to bc. Finally, a listing of directory names is stored and searchable. So if you want to navigate to the python site-packages folder and didn't remember where it was, genie can help you.
Obviously, the possibilities are almost endless. The genie can be taught to understand new commands as you desire. It may be necessary to be able to carry genie around so that you have your custom genie on any computer you have to use. But finally, will the added ease of use facilitate introduction of the command line to new users or will the use of a simple interface like this preclude users from learning shell commands and thereby never being able to make full use of it ? Comments are welcome.
However, the difficulty many face in approaching the CLI initially is what Eric Raymond calls the 'mnemonic load'. Don Norman writes how the next major UI breakthrough should be in CLI. He anticipates the development of a more flexible command line language, with more resemblance to natural language and not requiring a strict adherence to an idiosyncratic syntax.
An alternative to an entire new language for the command line is to use a user-friendly intermediate layer which translates the user input into the syntax that the command line understands. This is analogous to the frequently used concept in Unix when a user friendly GUI actually uses command line tools, but provides a user friendly front end.
What you see below is a working prototype of such a program written in python. In its main loop, it collects user input and outputs a command to the terminal. When the input is a valid command line input, it is passed unchanged. But when it is not, it is 'translated' into a valid one. I call it the Genie. Here are a few examples of the genie in action.

The prompt includes a battery status monitor - I find it useful and it shows that the prompt is easily customizable. 'Normal' shell commands are interpreted directly - like 'ls -l | grep 2007-03' in the example. Navigation to usual places is easy just - 'go home' or 'go desk'. 'space' functions like an alias mapping to 'df -h / /home'. Note the genie says line which lets you know the command that is passed to the shell. So that a newcomer also learns shell syntax along the way.

When you want to install an application just 'install

Obviously, the possibilities are almost endless. The genie can be taught to understand new commands as you desire. It may be necessary to be able to carry genie around so that you have your custom genie on any computer you have to use. But finally, will the added ease of use facilitate introduction of the command line to new users or will the use of a simple interface like this preclude users from learning shell commands and thereby never being able to make full use of it ? Comments are welcome.
February 24, 2007
Hide and show panels with a keyboard shortcut in Ubuntu
I usually keep the default top and bottom panels in gnome, but especially on my laptop, place great value on the screen estate that I can get by hiding them. The usual way I do this is by using autohide and then setting the hidden size to 0 or 1. Mostly I dont need the panels because I can launch applications with Alt-F2 or with shortcuts. But when I need to access something from the panel, I have to mouse over the hidden panel to bring it up. The other minor irritation is that the panel may spring out when you dont really want it if your mouse wanders close to it.
In a recent post in the Ubuntu forums, it was suggested that it would be nice to set up a keyboard shortcut to show the panels when needed. Since it is easy to access the gconf-editor from the command line, it was easy to write a script to toggle the hide status of the panel. Here is a short how-to if someone is interested.
Copy this script and save it as "toggle.sh". A good location to keep it would be /home/<username>/.toggle.sh. Make the file executable :
chmod +x ~/.toggle.sh
#!/bin/bash
#find the current state of the panels
state=`gconftool-2 --get "/apps/panel/toplevels/top_panel_screen0/auto_hide"`
#if autohide on, turn it off
if [ $state = "true" ]; then
gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/auto_hide" --type bool "false"
gconftool-2 --set "/apps/panel/toplevels/bottom_panel_screen0/auto_hide" --type bool "false"
fi
#if autohide off, turn it on
if [ $state = "false" ]; then
gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/auto_hide" --type bool "true"
gconftool-2 --set "/apps/panel/toplevels/bottom_panel_screen0/auto_hide" --type bool "false"
fi
Open gconf-editor now, and in /apps/metacity/keybinding_commands, change the value of command_1 (or any other command which is unused) to /home/<username>/.toggle.sh.
Then go to /apps/metacity/global_keybindings and change the value of run_command_1 (if you mapped the script to command_1) to <Control>F12 or any other key combination you choose. Close gconf-editor and try it out ! I tested this with both metacity and beryl and it works perfectly.
In a recent post in the Ubuntu forums, it was suggested that it would be nice to set up a keyboard shortcut to show the panels when needed. Since it is easy to access the gconf-editor from the command line, it was easy to write a script to toggle the hide status of the panel. Here is a short how-to if someone is interested.
Copy this script and save it as "toggle.sh". A good location to keep it would be /home/<username>/.toggle.sh. Make the file executable :
chmod +x ~/.toggle.sh
#!/bin/bash
#find the current state of the panels
state=`gconftool-2 --get "/apps/panel/toplevels/top_panel_screen0/auto_hide"`
#if autohide on, turn it off
if [ $state = "true" ]; then
gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/auto_hide" --type bool "false"
gconftool-2 --set "/apps/panel/toplevels/bottom_panel_screen0/auto_hide" --type bool "false"
fi
#if autohide off, turn it on
if [ $state = "false" ]; then
gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/auto_hide" --type bool "true"
gconftool-2 --set "/apps/panel/toplevels/bottom_panel_screen0/auto_hide" --type bool "false"
fi
Open gconf-editor now, and in /apps/metacity/keybinding_commands, change the value of command_1 (or any other command which is unused) to /home/<username>/.toggle.sh.
Then go to /apps/metacity/global_keybindings and change the value of run_command_1 (if you mapped the script to command_1) to <Control>F12 or any other key combination you choose. Close gconf-editor and try it out ! I tested this with both metacity and beryl and it works perfectly.
Labels:
command line,
google reader,
linux,
medicine,
presentation,
pubmed,
python,
research,
RSS
Subscribe to:
Posts (Atom)
