Pages

Resequencing Photos from more than one Camera

This is a python script which I have written to resequence photos taken from two cameras. The script makes use of the date and time of the photos to sequence the filenames.

import os, glob, time

fprefix = "Beijing"        # Name to prefix photos
folder  = "D:/Beijing2008" # Folder to look for photos
ext     = "jpg"            # Extension of photos
sno     = 1                # Serial number to start

print "Folder = ", folder
print '-' * 60
date_file_list = []
for file in glob.glob(folder + "/*." + ext):
  stats = os.stat(file)
  lastmod_date = time.localtime(stats[8])
  date_file_tuple = lastmod_date, file
  date_file_list.append(date_file_tuple)
  #print date_file_list  # test

date_file_list.sort()
#date_file_list.reverse()  # newest mod date now first

import string
print "%-40s %s" % ("filename:", "last modified:")
for file in date_file_list:
  folder, file_name = os.path.split(file[1])

  # Rename File
  ext = os.path.splitext(file_name)
  file_name = fprefix + ("%03d" % sno) + string.lower(ext[1])
  sno = sno + 1
  newfile = folder + "/" + file_name

  os.rename(file[1], newfile)

  # convert date tuple to MM/DD/YYYY HH:MM:SS format
  file_date = time.strftime("%m/%d/%y %H:%M:%S", file[0])
  print "%-40s %-20s %s" % (folder, file_name, file_date)

Autoexec with Windows Vista

In the days of Windows 98, commands which you wish to execute when the system starts up are placed in the autoexec.bat file. One of the useful things to do is to remove all temporary files in the temp folder. For example, we could issue these commands in the autoexec.bat file.
REM *** inside autoexec.bat ***
cd C:\temp
del *.tmp

Each time when the system reboots, those files with extension tmp will be removed in the temp folder of C: drive.

How to do this in Windows Vista? The autoexec.bat concept is not used in Vista. However, we can tell Vista to do this by specifying a Local Group Policy on the script to execute during Windows startup. We can do this by using the Local Group Policy Editor.

Open the Run... Dialog Box from the Windows Start menu. Key in "gpedit.msc" to start the Local Group Policy Editor.

image

When the Local Group Policy Editor appears, expand on the left pane, Local Computer PolicyComputer ConfigurationWindows SettingsScripts (Startup/Shutdown).

image

Double click on the right pane, Startup. Click on the Add button and specify the script you want Windows to execute during startup. In this case, I placed the delete commands in a script called cleartemp.bat.

image

Click OK and we are done! Exit the editor. Test out the script by restarting Windows Vista.

Vista and Command Prompt Here

Those of us who were using Windows XP and Microsoft PowerToys Command Prompt Here would miss this feature in Windows Vista. You will find that there is no equivalent of such a utility by Microsoft for Vista. This is so because of an obvious reason. Vista has already this feature built-in.

Open up Windows Explorer, hold the [Shift] key down, right-click on any folder on the details pane on the right, you will see "Open Command Window Here" menu item third in the pop-up menu. However, if you do this on the folder pane on the left of the Windows Explorer, this will not work. Disappointed?

Another way is to modify Vista's registry. Here is how this can be done. Navigate in your Registry to HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell and create a key called Open Command Prompt Here. Set the default string to whatever text you want to appear in the right-click menu. Create a new key within your newly created command prompt named "command," and set the default string to cmd.exe /k pushd %L. You may need to add %SystemRoot%\system32\ before the cmd.exe if the executable can't be found.

The changes should take place immediately. Right click a folder in both the right and left panes of your Windows Explorer and your new menu item should appear.

Python and .NET

I was asked to explore using Python with .NET. Here are three possibilities.

Configuration A – Plain IronPython
This is the most straightforward and plain vanilla installation.
Download IronPython-1.1.1-Bin.zip (975KB) from http://www.codeplex.com/IronPython.
Unzip the files into a folder, say C:\IronPython-1.1.1 and set the PATH. Voila!
Type ipy helloworld.py or ipyw helloworld.py

Configuration B – IronPython Studio
IronPython Studio is based on the Visual Studio 2008 Shell runtime (royalty free) and can be installed without requiring any version of Visual Studio. It provides the following templates for projects using IronPython.

Need to first install Visual Studio 2008 Shell (Isolated) (390MB) from http://www.microsoft.com/downloads/details.aspx?familyid=aca38719-f449-4937-9bac-45a9f8a73822&displaylang=en. Make sure you execute the vs_shell_isolated.enu.exe file in C:\VS 2008 Shell Redist\Isolated Mode. If you missed this step, the Iron Python Studio will not work.
Download IronPythonStudio.msi (1127KB) from http://www.codeplex.com/IronPythonStudio. Double click on the above msi file and the installation will start. IronPython is also included in the msi.

Configuration C – Visual Studio 2008 with IronPython
For those who already have VS2008 installed and are working in VS2008 for VB and C# projects, this would be the best configuration. Download Visual Studio 2008 SDK (98MB) from http://www.microsoft.com/downloads/details.aspx?familyid=30402623-93ca-479a-867c-04dc45164f5b&displaylang=en and install it on top of Visual Studio 2008. Run VS2008 under “Visual Studio 2008 SDK --> Tools --> Start Visual Studio 2008 Under Experimental Hive”. On top of VB, C#, C++ and all the project types in IronPython Studio, it also allows ASP.NET web applications and services to be developed using IronPython!



It is difficult to develop GUI Applications without IDE. Since I am a DOTNET guy, I go with Configuration C. Configuration B would be good for those of us who are not using VB and C#. Configuration A in my opinion is not productive, but nonetheless a very convenient way to pick up the basics of Python in .NET.

After some hours of experimentation, there are some serious bugs in IronPython. My colleague reported this problem, create a Button and define a button_click event for the button. However, when a new Label is created, the button_click function is overwritten. Any change made directly to the codes in the code view will most likely mess up the designer view. The Designer View can also be easily "corrupted" even with incorrect indentation.