/
INITIATE_FieldViewerFull.py
169 lines (117 loc) · 5.51 KB
/
INITIATE_FieldViewerFull.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import sys
if '.' not in sys.path:
sys.path.append('.')
from TK_GUI.FieldImageViewer_20130618 import FieldImages
from Tkinter import *
from TK_GUI import managers
import string, shutil
from pysqlite2 import dbapi2 as sql
from PIL import Image, ImageTk
from Tkinter import Frame, Canvas, SUNKEN, LEFT,RIGHT, Label
import os, tkSimpleDialog, tkFileDialog, tkMessageBox
def selectMetaGeoTables(cursor):
sql = 'SELECT f_table_name FROM geometry_columns'
cursor.execute(sql)
results = cursor.fetchall()
dic= {}
for result in results:
dic[result[0].title()] = result[0]
# dic[result[0]]= result[0].replace('CCWD_','').title()
return dic
class SelectMenu(object):
def __init__(self, dic,execute, title, mode=SINGLE):
self.masterselect = Tk()
self.exe = execute
self.dic = dic
master = self.masterselect
master.wm_attributes("-topmost", 1)
master.title(title)
master.maxsize(500,500)
master.geometry('+100+100')
master.iconbitmap(root.logoPath)
frame2 = Frame(master, height=6, bd=7, relief=SUNKEN)
frame2.pack(fill=X, padx= 2, pady=2)
frame5 = Frame(frame2, bd=7)
frame5.pack()
scrollbar = Scrollbar(frame5)
scrollbar.pack(side=RIGHT, fill= Y)
self.listbox = Listbox(frame5,height = 20, width= 400,
selectmode=mode)
self.listbox.bind("<Double-Button-1>", lambda x: self.execute() )
sortTable = self.dic.keys()
sortTable.sort()
for keys in sortTable:
self.listbox.insert(END, keys)
self.listbox.pack()
self.listbox.selection_set(0)
scrollbar.config(command=self.listbox.yview)
stepButton = Button(frame5, text= 'Next Step',
font = 'Gill_Sans_MT -12 bold' ,
bg = 'dark blue', fg = 'white',
bd = 10, width=12,
command = self.execute)
stepButton.pack(side=TOP, pady =5,padx=4)
def execute(self):
selected = self.listbox.selection_get()
selSplit = selected.split('\n')
if len(selSplit)==1:
tables = self.dic[selSplit[0]]
self.masterselect.destroy()
self.exe(tables)
elif len(selSplit) > 1:
newtables = []
[newtables.append(self.dic[select]) for select in selSplit]
self.masterselect.destroy()
self.exe(newtables)
def openFile(titlestring, desc,ext):
import tkFileDialog
filename = tkFileDialog.askopenfilename( initialdir='C:/',
title=titlestring,defaultextension= '.{0}'.format(ext),
filetypes=[(desc, '*.{0}'.format(ext))])
return filename.split('.')[0]+'.{0}'.format(ext)
def openFolder(titlestring):
import tkFileDialog
folder = tkFileDialog.askdirectory(title=titlestring)
return folder
def genInitialInfo():
db = 'initialphoto.sqlite'
sql_connection = sql.Connection(db) # This is the path to the database. If it doesn't exist, it will be created, though, of course, without the require tables
cursor = sql.Cursor(sql_connection)
mainDB = openFile('Locate Main Database File', 'Spatialite SQL Database', 'sqlite')
mainImages = openFolder('Find Main Images Library Folder')
icons = openFolder('Find Icons Folder')
srid = tkSimpleDialog.askstring('Spatial Reference System', 'Please provide a spatial reference ID (SRID).\nRefer to spatialreference.org for more instructions')
sql_connection = sql.Connection(db) # This is the path to the database. If it doesn't exist, it will be created, though, of course, without the require tables
cursor = sql.Cursor(sql_connection)
try:
createsql = "CREATE TABLE INITIATION ('mainImages' text,'maindb' text,'icons' text, 'srid' text)"
cursor.execute(createsql)
except:
pass
insertsql = "INSERT INTO INITIATION VALUES ('{0}','{1}','{2}','{3}')".format(mainImages, mainDB,icons, srid)
cursor.execute(insertsql)
sql_connection.commit()
tkMessageBox.showinfo('Database Initialized', 'Your settings have been recorded')
standards = mainImages, mainDB, icons,srid
return standards
db = 'initialphoto.sqlite'
if os.path.exists(db):
sql_connection = sql.Connection(db) # This is the path to the database. If it doesn't exist, it will be created, though, of course, without the require tables
cursor = sql.Cursor(sql_connection)
sqlstatement = 'SELECT * FROM INITIATION'
cursor.execute(sqlstatement)
standards = cursor.fetchone()
if not os.path.exists(db) or standards == None:
standards = genInitialInfo()
mainImages, mainDB, icons,srid = standards
if __name__ == '__main__':
#try:
Root = Tk()
Root.tk_strictMotif()
App = FieldImages(mainImages, mainDB, icons,srid, Root)
App.pack(expand='yes',fill='both')
Root.state('zoomed')
Root.title('ICF Field Office Image View')
Root.mainloop()
#except Exception as e:
# print e