Python! Easy GUI... PDF Print E-mail

Written by Kevin Bell,

There are a lot of options for GUI development with python, but a lot of them require more code than some would like, so enter easyGUI!  In the code below, the GUI part is ONLY the first line in the lauchEnter function. The GUI assigns a string to the variable "caseN". How easy is that?!!  At the end of the script, I use a message box as well, which again is a one liner.

We have scanned traffic accident reports on the network, and looking through the files in windows explorer is a pain, so this code prompts you for a case number, and upon recieving it, it parses off the file extension since our reports can be .tiff or .pdf, then goes and opens the file if we have it, otherwise it tells you that we don't have that case. I put the script on the desktop, so it's a single click, enter casenumber, and get the file.

http://easygui.sourceforge.net/

 

from easygui import *
import sys
import os

def lauchEnter():
    caseN =enterbox("Enter an Accident Case Number.", "Get Accident Report", default = "SL", strip=True)
    print caseN
    path = r"X:\Accidents\CaseNumberImages"
    
    if os.path.isfile(path + "\\" + caseN + "-1.pdf"):
        print caseN + " is a pdf file"
        os.startfile(path + "\\" + caseN + "-1.pdf")
        sys.exit(0)
        
    elif os.path.isfile(path + "\\" + caseN + "-1.tif"):
        print caseN + " is a tiff file"
        os.startfile(path + "\\" + caseN + "-1.tif")
        sys.exit(0)
        
    else:
        print "didn't stick"
        msgbox("We don't have that file", title="FAILURE TO LOCATE FILE", ok_button="QUIT")
        sys.exit(0)


lauchEnter()

Users' Comments  
 

No comment posted

Add your comment

07, Jan. 2009
Last Updated ( 07, Jan. 2009 )
 
< Prev   Next >

AGRC Contacts | UGIC Contacts

feed image feed image

Utah GIS Portal © 2009 AGRC

Optimized for