-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFilterDialog.py
166 lines (132 loc) · 5.96 KB
/
FilterDialog.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
#Filter Settings dialog box
##Copyright (C) 2012 Magnus Haw
##
##This program is free software: you can redistribute it and/or modify
##it under the terms of the GNU General Public License as published by
##the Free Software Foundation, either version 3 of the License, or
##(at your option) any later version.
##
##This program 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 General Public License for more details.
##
##You should have received a copy of the GNU General Public License
##along with this program. If not, see <http://www.gnu.org/licenses/>.
import wx
import string
#---------------------------------------------------------------------------
# Create and set a help provider. Normally you would do this in
# the app's OnInit as it must be done before any SetHelpText calls.
provider = wx.SimpleHelpProvider()
wx.HelpProvider.Set(provider)
#---------------------------------------------------------------------------
class FilterDialog(wx.Dialog):
def __init__(
self, parent, ID, title, size=wx.DefaultSize, pos=wx.DefaultPosition,
style=wx.DEFAULT_DIALOG_STYLE,
useMetal=False,
):
# Instead of calling wx.Dialog.__init__ we precreate the dialog
# so we can set an extra style that must be set before
# creation, and then we create the GUI object using the Create
# method.
pre = wx.PreDialog()
pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
pre.Create(parent, ID, title, pos, size, style)
# This next step is the most important, it turns this Python
# object into the real wrapper of the dialog (instead of pre)
# as far as the wxPython extension is concerned.
self.PostCreate(pre)
# Now continue with the normal construction of the dialog
# contents
sizer = wx.BoxSizer(wx.VERTICAL)
text_font = wx.Font(15, wx.SWISS, wx.NORMAL, wx.NORMAL)
box = wx.BoxSizer(wx.HORIZONTAL)
##Altitude control section
label = wx.StaticText(self, -1, "Min Altitude")
label.SetHelpText("Minimum altitude cutoff [0-30]")
box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
self.altCtrl = wx.SpinCtrl(self, -1, "", (30, 50))
self.altCtrl.SetRange(0,35)
self.altCtrl.SetValue(25)
box.Add(self.altCtrl, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
box = wx.BoxSizer(wx.HORIZONTAL)
##Limit control
label = wx.StaticText(self, -1, "Max # Objects")
label.SetHelpText("Limits number objects displayed in list")
box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
self.limCtrl = wx.SpinCtrl(self, -1, "", (30, 50))
self.limCtrl.SetRange(10,250)
self.limCtrl.SetValue(50)
box.Add(self.limCtrl, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
self.limCtrl.SetHelpText("Max number objects listed [1,250]")
sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
box = wx.BoxSizer(wx.HORIZONTAL)
##Late hour control section
label = wx.StaticText(self, -1, "Time Cutoff")
label.SetHelpText("Latest hour of observation")
box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
self.lateCtrl = wx.SpinCtrl(self, -1, "", (30, 50))
self.lateCtrl.SetRange(1,24)
self.lateCtrl.SetValue(23)
box.Add(self.lateCtrl, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)
btnsizer = wx.StdDialogButtonSizer()
if wx.Platform != "__WXMSW__":
btn = wx.ContextHelpButton(self)
btnsizer.AddButton(btn)
btn = wx.Button(self, wx.ID_OK)
btn.SetHelpText("The OK button completes the dialog")
btn.SetDefault()
btnsizer.AddButton(btn)
btn = wx.Button(self, wx.ID_CANCEL)
btn.SetHelpText("The Cancel button cancels the dialog.")
btnsizer.AddButton(btn)
btnsizer.Realize()
sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
self.SetSizer(sizer)
sizer.Fit(self)
def GetAltLimLate(self):
signs = dict(zip(['N','S','E','W'],[1,-1,1,-1]))
alt = int(self.altCtrl.GetValue())
late = int(self.lateCtrl.GetValue())
lim = int(self.limCtrl.GetValue())
return alt,lim,late
#---------------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, -1)
b = wx.Button(self, -1, "Filter Settings Dialog", (50,50))
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
def OnButton(self, evt):
dlg = FilterDialog(self, -1, "Filter Settings", size=(300, 200),
style=wx.DEFAULT_DIALOG_STYLE,
useMetal=False,
)
dlg.CenterOnScreen()
# this does not return until the dialog is closed.
val = dlg.ShowModal()
mylat=None
mylong=None
if val == wx.ID_OK:
print "You pressed OK\n"
alt,limit,late=dlg.GetAltLimLate()
print alt,limit,late
else:
print "You pressed Cancel\n"
dlg.Destroy()
return alt,limit,late
#---------------------------------------------------------------------------
if __name__ == '__main__':
import sys
app = wx.App(False) # Create a new app, don't redirect stdout/stderr to a window.
frame = wx.Frame(None)
tp = TestPanel(frame,sys.stdout)
frame.Show(True) # Show the frame.
app.MainLoop()
#---------------------------------------------------------------------------