Archive for the ‘Software’ Category

How to sleep in a Windows .bat script

Friday, December 18th, 2015

There is no sleep command for the Microsoft command line. Here is one way to add a fixed delay to a batch file script:

Use the ping command to ping an invalid address and set the timeout for the number of milliseconds you want to delay. So for example, the following command would delay for 5 seconds before proceeding:

     @ping -n 1 -w 5000 > nul

Suppressing the default namespace in ElementTree

Monday, July 7th, 2014

xmlThis solution removes the default namespace from the input XML and makes typing ElementTree Xpath expressions a lot easier.  The trick is to remove the xmlns=”…” attribute from the input XML before parsing it.  Most other workarounds suggest traversing the tree of elements after parsing, and modifying the tag entries.


import ElementTree as ET

# Parse the contents of the XML file
tree = ET.parse(xmlFile)

# Get the root element
root = tree.getroot()

# Use fully qualified tag names in path expressions
extentX = root.find(".//{http://some/namespace}Coverage/{http://some/namespace}Extent/x")


import ElementTree as ET
import re # regular expression module

# Read the contents of the XML file into xmlstring
with open(xmlFile) as f:
    xmlstring =

# Remove the default namespace definition (xmlns="http://some/namespace")
xmlstring = re.sub('\\sxmlns="[^"]+"', '', xmlstring, count=1)

# Parse the XML string
root = ET.fromstring(xmlstring)

# Use much simpler path expressions
extentX = root.find(".//Coverage/Extent/x")

Thanks to this post on the always useful StackOverflow for suggesting the solution.

Vega Prime Viewer Hot Keys

Thursday, September 26th, 2013

bostonThumbnailI happened upon a list of the hot key functions for the Presagis Vega Prime standard viewer, which is used in the Lynx Prime Active Preview and is supported in the API by the vpApp class. Since I can never remember where to find them, I’m putting the list here.

vpApp responds to the following keyboard input:

        Esc : quit the application
          ~ : enable / disable the first stats page
          s : cycle forward through the stats for all channels
          S : cycle backward through the stats for all channels
  Backspace : reset the state vector for all observers
      Enter : capture the state vector for all observers
          c : put all observers at the center of the scene
          f : enable / disable fog for all channels
          l : enable / disable lighting for all channels
          p : print the absolute position for all observers
          t : enable / disable texture for all channels
          T : enable / disable transparency for all channels
          w : enable / disable wireframe for all channels
          a : enable / disable shaders for all channels
          x : enable / disable the position strategy for all observers
        Tab : enable / disable scene graph overlay drawing
     NumPad : pan position of the scene graph overlay
          q : scale the scene graph overlay up
          Q : scale the scene graph overlay down
         F8 : capture video stream
         F9 : capture still-image

Setting up Cygwin

Wednesday, September 19th, 2012

CygwinThis is my procedure for installing Cygwin on a Windows desktop. There are many ways to configure the Cygwin environment. This seems to work for me:

  1. Go to
  2. Download the Cygwin installer/updater to your desktop
    1. Choose setup_x86.exe (32-bit installation), or
    2. Choose setup_x86-64.exe (64-bit installation)
  3. Run it

Use the following settings to answer the setup questions:

Root dir:  c:\cygwin  (for 32-bit; or c:\cygwin64 for the 64-bit install)
Install for:  All users
Default file type:  DOS
Package dir:  c:\cygwin_install (recommended; can be deleted later)

Be sure to install the following packages:

Section  Package
------- -------
Net     inetutils
Net     ncftp
Net     openssh
Net     ping
Python  python
Python  python-imaging
Python  python-tkinter
Shells  chere
Shells  mintty
Shells  tcsh
Shells  xterm (for resize)
Utils   ncurses (for tset)
Web     wget

Set the HOME environment variable in Windows (Computer->Properties->Advanced->Environment Variables) (put your username instead of username):

Win XP:
HOME  c:\Documents and Settings\username
Win Vista/7/8:
HOME  c:\Users\username

Optional environment variables:

$OSG_HOME (OpenSceneGraph)

Set the PATH environment variable. Cygwin will inherit the Windows PATH, but you need to add the directories containing the Cygwin executables. This is a very minimal .cshrc file. You will probably want to add a more sophisticated one. I have a small set of “dot” files that I copy into a user’s HOME directory when setting up Cygwin. To create the minimal .cshrc file, type the following lines at a shell prompt, ending with the <Ctrl-D> (Cygwin EOF) character:

/usr/bin/cat > $HOME/.cshrc
set path=(/usr/local/bin /usr/bin /bin $path)
setenv CYGWIN nodosfilewarning

Run the following commands (put your username instead of username):

Win XP:
/usr/bin/mkdir /home
cd /home
/usr/bin/ln -s /cygdrive/c/Documents\ and\ Settings/username/My\ Documents username
Win Vista/7:
/usr/bin/mkdir /home
cd /home
/usr/bin/ln -s /cygdrive/c/Users/username username


mintty shortcut:

C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico /bin/tcsh

Create ~/.Xdefaults containing the following:

rxvt.scrollBar_right: True
rxvt.visualBell: True
rxvt.cursorColor: red
rxvt.saveLines: 5000
rxvt.geometry: 80x40
rxvt.font: courier
rxvt.foreground: black
rxvt.background: white
xterm.scrollBar_right: True
xterm.visualBell: True
xterm.cursorColor: red
xterm.saveLines: 5000
xterm.geometry: 80x40
xterm.font: Consolas
xterm.foreground: black
xterm.background: white

Put mintty in the Windows Explorer folder right-mouse menu:

Run the following command to create a Windows Explorer context menu entry:

/usr/bin/chere -if -t mintty -s tcsh -e "Cygwin Terminal Here" -o "-i /Cygwin-Terminal.ico"

If you get an error like this:

Error (5): Access is denied.
/usr/bin/chere Error: Hive not writable
/usr/bin/chere: Aborting.

it is a UAC (permissions) problem.  Launch the shell as Administrator and try it again.

Modify /etc/csh.login as follows, to let the shell run by chere start in the proper directory:
Replace the last line:



if ( ! ${?CHERE_INVOKING} ) then

CMake Debug and Release Builds (in Eclipse)

Tuesday, May 1st, 2012

While coding recently in C++ on a project that uses CMake, I needed to build my code with Debug settings in Eclipse.  It’s Eclipse, so there are probably many ways to do it.  I followed this approach.

I ran into one small problem.  I was modifying a project that I had already been working with.  So when I tried running the cmake commands to generate the Release and Debug makefiles

mkdir Release Debug
cmake -E chdir Debug/ cmake -G "Unix Makefiles" ../ -DCMAKE_BUILD_TYPE:STRING=Debug
cmake -E chdir Release/ cmake -G "Unix Makefiles" ../ -DCMAKE_BUILD_TYPE:STRING=Release

nothing was written to the Release or Debug folder.  To fix this, I had to first delete the CMakeCache.txt file from my project folder.

rm CMakeCache.txt

APOD Wallpaper: Fascinating!

Thursday, April 5th, 2012

If Mr. Spock had a big flat panel screen instead of being forced to look into a slot in a cereal box, he would have used APOD Wallpaper for his desktop background.  The Astronomy Picture of the Day website features a daily different collection of photons collected from the far reaches of the universe.  The awe-inspiring images from the depths of space are occasionally interspersed with space-related pictures of objects closer to home.  And each one comes with an explanation that adds to the wonderment.

You could visit the APOD website each day.  Or better,  Windows users can run the APOD Wallpaper app and receive a different breathtaking image on your desktop background each morning.  The app puts a little icon of the planet Jupiter in your Systray.  Right mousing on Jupiter pops up a menu that will bring up the APOD Wallpaper settings, show you the astronomer’s explanation of the day’s image, or take you to the APOD website.

The app is easy to install.  It comes in a Zip file.  Just unzip it into a convenient location (such as c:\Program Files\APOD), and run it.  In the Settings you can tell it to automatically run when Windows starts.  There are a couple of other Windows apps that do nearly the same thing.  Linux and Mac users have several choices, too.

Simple Popup Requester in Python

Wednesday, March 14th, 2012

Sometimes I think I should change the name of this blog to Mind Like a Sieve, subtitle Straining to Remember.

I’ve built some miscellaneous one-off GUIs with various Python toolkits like Tkinter and wxPython, but this time I wanted just a simple confirmation popup.  In this case it was to pause so I could attach a debugger.

The comment on this page of the tkinterbook had exactly what I needed.  Also, there is a page showing examples of all the different simple popups you can make using this approach.  One benefit of using this approach is that Tkinter is bundled with Python, so there are no additional packages to install.

Here’s the simplest code snippet:

import Tkinter, tkMessageBox
Tkinter.Tk().withdraw() # suppress blank Tk root window in Windows
tkMessageBox.showinfo("Debugging", "Attach debugger, then click OK")

You can, of course, get much fancier with some of the popup versions, and you can capture the return value from the user interaction.