forked from UCSD-TIES/DVS-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguitest.py
More file actions
311 lines (239 loc) · 11.5 KB
/
guitest.py
File metadata and controls
311 lines (239 loc) · 11.5 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/user/bin/env python
import wx, os
# file filter for pictures: bitmap and jpeg files
IMGMASK = "JPEG Files(*.jpg;*.jpeg;*.jpe;*.jfif) " \
"|*.jpg; *.jpeg; *.jpe; *.jfif|" \
"Raw Files |*.cr2; *crw|" \
"All Files |*.*"
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, pos=(0,0), size=wx.DisplaySize())
self.panel = wx.Panel(self)
self.CreateStatusBar()
self.PhotoMaxSize = 440
# Setting up the menu.
filemenu = wx.Menu()
#wx.ID_ABOUT and wx.ID_EXIT are standard IDs provided by wxWidget
menuAbout = filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
filemenu.AppendSeparator()
menuExit = filemenu.Append(wx.ID_EXIT,"&Exit"," Terminate the program")
# Creating the menubar.
menuBar = wx.MenuBar()
menuBar.Append(filemenu, "&File")
self.SetMenuBar(menuBar)
# Set events.
self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
# Passes to createWidgets method definition
self.createWidgets()
self.panel.Show(True)
self.Show(True)
#----------------------------------------------------------------------------
def createWidgets(self):
# Welcome message
welcome = "Welcome to DVS!"
welcomeFont = wx.Font(13, wx.NORMAL, wx.NORMAL, wx.BOLD)
welcomemsg = wx.StaticText(self.panel, -1, welcome)
welcomemsg.SetFont(welcomeFont)
# Horizontal Image
horImg = wx.EmptyImage(440,440)
self.horImgCtrl = wx.StaticBitmap(self.panel, wx.ID_ANY,
wx.BitmapFromImage(horImg))
# Displays path of horizontal image
self.horPhotoTxt = wx.TextCtrl(self.panel, size=(350,-1))
horiBtn = wx.Button(self.panel, label='Horizontal')
horiBtn.Bind(wx.EVT_BUTTON, self.horOpenFile)
# Vertical Image
# I did this the dumb way because I don't know how to use parameters
# in Python :/ So I made an exact replica of a method.. haha. Might
# be helpful to differentiate, however.
vertImg = wx.EmptyImage(440,440)
self.vertImgCtrl = wx.StaticBitmap(self.panel, wx.ID_ANY,
wx.BitmapFromImage(vertImg))
# Displays path of vertical image
self.vertPhotoTxt = wx.TextCtrl(self.panel, size=(350,-1))
vertiBtn = wx.Button(self.panel, label='Vertical')
vertiBtn.Bind(wx.EVT_BUTTON, self.vertOpenFile)
# Confirm Button
confBtn = wx.Button(self.panel, label='Confirm')
confBtn.Bind(wx.EVT_BUTTON, lambda event: self.checkConf(event, self.horPhotoTxt.GetValue(),self.vertPhotoTxt.GetValue()))
#------------------------------------------------------------------------------
# Resolve Layout Issues
self.full = wx.BoxSizer(wx.VERTICAL)
self.header = wx.BoxSizer(wx.HORIZONTAL)
self.body = wx.BoxSizer(wx.HORIZONTAL)
self.leftSizer = wx.BoxSizer(wx.VERTICAL)
self.rightSizer = wx.BoxSizer(wx.VERTICAL)
self.horBrowseAndText = wx.BoxSizer(wx.HORIZONTAL)
self.vertBrowseAndText = wx.BoxSizer(wx.HORIZONTAL)
self.footer = wx.BoxSizer(wx.HORIZONTAL)
# This aligns the whole layout vertically, including header, body,
# and bottom line (staticLine).
self.full.Add(self.header, 0, wx.ALL | wx.CENTER, 5)
self.full.Add(wx.StaticLine(self.panel, wx.ID_ANY),
0, wx.ALL|wx.EXPAND, 5)
self.full.Add(self.body, 0, wx.ALL | wx.CENTER, 5)
self.full.Add(wx.StaticLine(self.panel, wx.ID_ANY),
0, wx.ALL|wx.EXPAND, 5)
self.full.Add(self.footer, 0, wx.ALL | wx.ALIGN_RIGHT, 5)
# This centers the welcome message ("Welcome to DVS!") and puts
# it at the top.
self.header.Add(welcomemsg, 0, wx.ALL | wx.EXPAND | wx.CENTER, 5)
self.footer.Add(confBtn, 0, wx.ALL | wx.EXPAND, 5)
# This portions the left side of the layout, including left
# image, left browse button (horizontal button), and left text
# control box, which contains the path of the horizontal image.
self.body.Add(self.leftSizer, 0, wx.LEFT | wx.EXPAND, 5)
self.leftSizer.Add(self.horImgCtrl, 0, wx.ALL | wx.LEFT, 5)
# Within the leftSizer container, we have a miniature sizer, called
# horBrowseAndText, which allows us to format the text control box
# and the horizontal browse button.
self.leftSizer.Add(self.horBrowseAndText, 0, wx.ALL | wx.LEFT |
wx.EXPAND, 5)
self.horBrowseAndText.Add(self.horPhotoTxt, 0, wx.ALL | wx.LEFT, 5)
self.horBrowseAndText.Add(horiBtn, 0, wx.ALL | wx.LEFT, 5)
# This portions the right side of the layout, including right image,
# right browse button (vertical button), and right text control box,
# which contains the path of the horizontal image.
self.body.Add(self.rightSizer, 0, wx.RIGHT | wx.EXPAND, 5)
self.rightSizer.Add(self.vertImgCtrl, 0, wx.ALL | wx.RIGHT, 5)
# Within the rightSizer container, we have a miniature sizer called
# vertBrowseAndText, which allows us to format the text control box
# and the vertical browse button.
self.rightSizer.Add(self.vertBrowseAndText, 0, wx.ALL | wx.RIGHT |
wx.EXPAND, 5)
self.vertBrowseAndText.Add(self.vertPhotoTxt, 0, wx.ALL | wx.RIGHT, 5)
self.vertBrowseAndText.Add(vertiBtn, 0, wx.ALL | wx.RIGHT, 5)
self.panel.SetSizer(self.full)
self.panel.Layout()
def checkConf(self, event, horiImg, vertImg):
if horiImg == '' and vertImg == '':
errorTxt1 = "No Images Detected, Please Enter Images"
errMsg1 = wx.MessageDialog(self, errorTxt1, "No Images Detected", wx.OK)
errMsg1.ShowModal()
errMsg1.Destroy()
elif horiImg == '':
errorTxt2 = "No Horizontal Image Detected, Please Enter a Horizontal Image"
errMsg2 = wx.MessageDialog(self, errorTxt2, "No Horizontal Image", wx.OK)
errMsg2.ShowModal()
errMsg2.Destroy()
elif vertImg == '':
errorTxt3 = "No Vertical Image Detected, Please Enter a Vertical Image"
errMsg3 = wx.MessageDialog(self, errorTxt3, "No Vertical Image", wx.OK)
errMsg3.ShowModal()
errMsg3.Destroy()
#---------------------------------------------------------------------------
def OnAbout(self,e):
# A message dialog box with an OK button. wx.OK is a standard ID in wxWidgets.
aboutText = "Eye Diagnostic Program: Please Enter a Vertical and Horizontal Photo"
dlg = wx.MessageDialog( self, aboutText, "About Sample Editor", wx.OK )
dlg.ShowModal() # Show it
dlg.Destroy() # finally destroy it when finished.
def OnExit(self,e):
self.Close(True) # Close the frame.
def horOpenFile(self, event):
horDlg = wx.FileDialog(self, "Choose a file", os.getcwd(), "", IMGMASK,
wx.OPEN)
if horDlg.ShowModal() == wx.ID_OK:
horPath = horDlg.GetPath()
self.horPhotoTxt.SetValue(horPath)
self.horOnPaint() # moved to make code more stable
# Can't load image from file '': file does not exist
horDlg.Destroy()
def horOnPaint(self):
horFilepath = self.horPhotoTxt.GetValue()
horImg = wx.Image(horFilepath, wx.BITMAP_TYPE_ANY)
# scale the image, preserving the aspect ratio
horW = horImg.GetWidth()
horH = horImg.GetHeight()
if horW > horH:
NewhorW = self.PhotoMaxSize
NewhorH = self.PhotoMaxSize * horH / horW
else:
NewhorH = self.PhotoMaxSize
NewhorW = self.PhotoMaxSize * horW / horH
horImg = horImg.Scale(NewhorW,NewhorH)
self.horImgCtrl.SetBitmap(wx.BitmapFromImage(horImg))
self.panel.Refresh()
def vertOpenFile(self, event):
vertDlg = wx.FileDialog(self, "Choose a file", os.getcwd(), "", IMGMASK,
wx.OPEN)
if vertDlg.ShowModal() == wx.ID_OK:
vertPath = vertDlg.GetPath()
self.vertPhotoTxt.SetValue(vertPath)
self.vertOnPaint() # moved to make code more stable
vertDlg.Destroy()
#self.OnPaint2()
def vertOnPaint(self):
vertFilepath = self.vertPhotoTxt.GetValue()
vertImg = wx.Image(vertFilepath, wx.BITMAP_TYPE_ANY)
# scale the image, preserving the aspect ratio
vertW = vertImg.GetWidth()
vertH = vertImg.GetHeight()
if vertW > vertH:
NewvertW = self.PhotoMaxSize
NewvertH = self.PhotoMaxSize * vertH / vertW
else:
NewvertH = self.PhotoMaxSize
NewvertW = self.PhotoMaxSize * vertW / vertH
vertImg = vertImg.Scale(NewvertW,NewvertH)
self.vertImgCtrl.SetBitmap(wx.BitmapFromImage(vertImg))
self.panel.Refresh()
if __name__ == '__main__':
app = wx.App(False)
frame = MyFrame(None, 'Digital Vision Screening')
app.MainLoop()
#old stuff
"""
import wx, os
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, pos = (0, 0), size=wx.DisplaySize())
panel = wx.Panel(self)
IMGMASK = "JPEG Files |*.jpg|" \
".BMP Files |*.bmp|" \
"All Files |*.*"
# frame size = (width, length)
horizontal = wx.Button(panel, 1, 'Horizontal', (50, 130), (110, -1))
vertical = wx.Button(panel, 2, 'Vertical', (400, 130), (110, -1))
self.Bind(wx.EVT_BUTTON, self.openFile, horizontal)
self.Bind(wx.EVT_BUTTON, self.openFile, vertical)
#Welcome message
welcome = 'Welcome to DVS!'
# SetPointSize(self, 20)
wx.StaticText(panel, -1, welcome, pos=(250,10))
# Setting up the menu.
filemenu = wx.Menu()
#wx.ID_ABOUT and wx.ID_EXIT are standard IDs provided by wxWIdget
menuAbout = filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
filemenu.AppendSeparator()
menuExit = filemenu.Append(wx.ID_EXIT,"&Exit"," Terminate the program")
# Creating the menubar.
menuBar = wx.MenuBar()
menuBar.Append(filemenu, "&File")
self.SetMenuBar(menuBar)
# Set events.
self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
#Button to close
xButton=wx.Button(panel,label="Close", pos=(500,600))
xButton.Bind(wx.EVT_BUTTON, self.OnExit)
self.Show(True)
#add image in screens
def OnAbout(self,e):
# A message dialog box with an OK button. wx.OK is a standard ID in wxWidgets.
dlg = wx.MessageDialog( self, "A small text editor", "About Sample Editor", wx.OK )
dlg.ShowModal() # Show it
dlg.Destroy() # finally destroy it when finished.
def OnExit(self,e):
self.Close(True) # Close the frame.
def openFile(self, event):
dlg = wx.FileDialog(self, "Choose a file", os.getcwd(), "", "*.*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
mypath = os.path.basename(path)
dlg.Destroy()
app = wx.App(False)
frame = MyFrame(None, 'Digital Vision Screening')
app.MainLoop()
"""