forked from tommycarlsson/cBLUE.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GuiSupport.py
158 lines (118 loc) · 4.78 KB
/
GuiSupport.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
"""
cBLUE (comprehensive Bathymetric Lidar Uncertainty Estimator)
Copyright (C) 2019
Oregon State University (OSU)
Center for Coastal and Ocean Mapping/Joint Hydrographic Center, University of New Hampshire (CCOM/JHC, UNH)
NOAA Remote Sensing Division (NOAA RSD)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Contact:
Christopher Parrish, PhD
School of Construction and Civil Engineering
101 Kearney Hall
Oregon State University
Corvallis, OR 97331
(541) 737-5688
"""
# -*- coding: utf-8 -*-
from tkinter import filedialog, Button, IntVar, Radiobutton, Frame, Label, W
class DirectorySelectButton(object):
"""Button used to get the name of a directing containing
files that need to be imported during processing.
Created: 2017-12-07
@author Timothy Kammerer
"""
def __init__(self, master, frame, direct_type, dir_path, width, callback=None):
"""Initializes the DirectorySelectButton.
@param fileType string
@param openTypes string[]
"""
self.master = master
self.directType = direct_type
self.width = width
self.button = Button(
frame,
text='Choose {} Directory'.format(self.directType),
command=self.callback,
width=width)
self.directoryName = dir_path
self.extraCallback = callback
def grid(self, **args):
"""Wrapper function for self.button.grid."""
self.button.grid(**args)
def set_state(self, state):
"""Sets the state of the button."""
self.button.config(state=state)
def callback(self):
"""Callback for the button.
Gets the directoryName from user with filedialog.
Updates the display to reflect directory choice.
"""
directoryName = filedialog.askdirectory(
initialdir=self.master.lastFileLoc,
title="Select {} File".format(self.directType))
if directoryName == '':
return
self.directoryName = directoryName
self.master.lastFileLoc = self.directoryName
#update the Gui
directoryRoots = self.directoryName.split("/")
displayDirectory = str()
while len(directoryRoots) != 0:
currentLine = directoryRoots.pop(0)
if len(directoryRoots) != 0:
while len(currentLine) + len(directoryRoots[0]) < self.width:
currentLine = "{}\\{}".format(currentLine, directoryRoots.pop(0))
if len(directoryRoots) == 0:
break
displayDirectory = "{}{}".format(displayDirectory, currentLine)
self.button.config(text="{} Directory Set".format(self.directType), fg='darkgreen')
if self.extraCallback is not None:
self.extraCallback()
class RadioFrame:
"""Created: 2017-12-08
@author: Timothy Kammerer
"""
def __init__(self, root, radioName, radioOptions,
startSelect=0, background=None, foreground=None,
callback=None, width=40):
self.frame = Frame(root, background=background)
if radioName != None:
Label(
self.frame,
text=radioName,
width=width,
background=background,
foreground=foreground).grid(row=0)
self.selection = IntVar(self.frame)
self.buttons = list()
for i, opt in enumerate(radioOptions):
self.buttons.append(Radiobutton(
self.frame,
text=opt,
variable=self.selection,
value=i,
command=callback,
background=background,
activebackground=background,
foreground=foreground,
activeforeground=foreground))
self.buttons[i].grid(row=i + 1, sticky=W)
self.buttons[startSelect].select()
def grid(self, **options):
self.frame.grid(**options)
def setState(self, state):
for button in self.buttons:
button.config(state=state)
if __name__ == '__main__':
pass