Home arrow GIS Data & Resources arrow Scripts and Code arrow Python arrow Python! GUI project directory builder!
Python! GUI project directory builder! PDF Print E-mail

Written by Kevin Bell,

In Salt Lake City's Transportation Division, GIS requests come from many different people, and the projects can be revived years later. In order to organize these projects I made a simple python application that builds up a project directory to hold all of the data. I have a folder, say C:\gis, that contains a folder for every person in my office that may have GIS needs. If I'm asked to make a new map or crunch some numbers, I click my app's icon and a wxGUI prompts me for a project name, the requestee, and it also gives me a couple check boxes to open a basemap and/or the new project directory that organizes the information.

If Bill requests a wattage summary for 1300 E street lights, I click my project builder app, and I type in wattageSummary_1300E, choose "Bill" from the drop down list, and upon clicking the button "BUILD THE PROJECT" a directory is built C:\gis\Bill\wattageSummary_1300E, with a new basemap in the directory named wattageSummary_1300E.mxd... Also, subdirectories are built for FinalData, TempData, and OriginalData. See the screenshots. Organizing your project data makes it much easier to track down your past work!

This sample doesn't do anything with the ESRI geoprocessor, but is utilizing the wxPython GUI library which is useful for cross platform GUI development. see www.wxpython.org to download this. After downloading this, you can start the demo which gives code samples for just about every type of GUI widget you'd ever want... There's everything from data grid controls to drop down lists to sliders to process/event managers.

Happy GUI development!

The project builder GUI

resulting File structure

#GUIprojectBuilder.py
#DATE: 11-29-2006
#AUTHOR: Kevin Bell
#Purpose: build a gis project directory...


import wx, sys, os, shutil, normalDate

class myTestApp(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Create Project Directory", size=(300,250))
        panel = wx.Panel(self, -1)
  
        myProjectLabel = wx.StaticText(panel, -1, "Project Name: ", pos=(10,10))
        self.tc = wx.TextCtrl(panel, -1, "Enter a project name here", size=(175,-1), pos=(90,10))
  
        path = ("F:\\gis") # <---- you'll get the folders in this directory...
        l=os.listdir(path)
        myChoices = [x for x in l if os.path.isdir(os.path.join(path, x))]
  
        myChoiceLabel = wx.StaticText(panel, -1, "Who's it for? ", pos=(10,50))
        self.myChoice = wx.Choice(panel, -1, pos=(90,50), choices=myChoices)
        self.Bind(wx.EVT_CHOICE, self.OnChoose, self.myChoice)
  
        self.requestee = None
 
        self.myChk= wx.CheckBox(panel, -1, "Open the directory?", pos=(90,90), size=wx.DefaultSize, name="chkOpenDir")
        self.myChk.SetValue(True)
  
        self.myChk2= wx.CheckBox(panel, -1, "Open the MXD?", pos=(90,130), size=wx.DefaultSize, name="chkOpenMap")
        self.myChk2.SetValue(True)
  
        self.button =  wx.Button(panel, -1, "BUILD THE PROJECT", pos=(90, 160))
        self.Bind(wx.EVT_BUTTON, self.OnClick, self.button)
  
  

    def OnChoose(self, event):
        self.requestee = event.GetString()
 
    def OnClick(self, event):
        #self.button.SetLabel("clicked")
        requestee = self.requestee
        projectName = self.tc.GetValue()
        today = normalDate.ND()
        prjnamedate = str(today) + "_" + projectName
  
        os.makedirs("F:\\gis" + "\\" + requestee + "\\" + prjnamedate)
        os.makedirs("F:\\gis" + "\\" + requestee + "\\" + prjnamedate + "\\Temp")
        os.makedirs("F:\\gis" + "\\" + requestee + "\\" + prjnamedate + "\\FinalData")
        os.makedirs("F:\\gis" + "\\" + requestee + "\\" + prjnamedate + "\\OriginalData")
  
        #----copy a basemap as a new map named date_projectName
        newMxd = "F:\\gis" + "\\" + requestee + "\\" + prjnamedate + "\\" + prjnamedate + ".mxd"
        shutil.copyfile ("F:\\gis\\000.mxd", newMxd)
        #----open the new map
        if self.myChk2.GetValue() == True:
        os.startfile("F:\\gis" + "\\" + requestee + "\\" + prjnamedate + "\\" + prjnamedate + ".mxd")
        if self.myChk.GetValue() == True:
        os.startfile("F:\\gis" + "\\" + requestee + "\\" + prjnamedate)
  
  #close app here
  wx.Exit()

if __name__ == '__main__':
     app = wx.PySimpleApp()
     frame = myTestApp()
     frame.Center(direction=wx.BOTH)
     frame.Show()
     app.MainLoop()
 


Users' Comments  
 

Display 3 of 3 comments

1. Wed, 09-17-2008 at 11:32 AM

Thanks Kevin! This looks like an excellent way to manage short burn projects! I am always looking for easier ways to avoid making a 'pile' in my drive spaces.

2. Mon, 09-29-2008 at 10:21 AM

Very useful for clean data organization -- I especially like the auto-generated data folders. Thanks!

3. Tue, 03-03-2009 at 11:31 PM

while running the code of " Python! GUI project directory builder! " i returned an error - python new.py 
Traceback (most recent call last): 
File "new.py", line 1, in ? 
import wx, sys, os, shutil, normalDate 
ImportError: No module named normalDate 
-what shuld i do....please reply

Display 3 of 3 comments

Add your comment

17, Sep. 2008
Last Updated ( 17, Sep. 2008 )
 
< Prev   Next >

AGRC Contacts | UGIC Contacts

feed image feed image

Utah GIS Portal © 2009 AGRC

Optimized for