-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmenu.py
executable file
·217 lines (159 loc) · 6.63 KB
/
submenu.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
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
#!/usr/bin/env python
# :set ts=4 sw=4 expandtab
#------------------------------------------------------------------------
# Copyright (c) 2019, EGB13.net
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * The names of its contributors may not be used to endorse or promote
# products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#------------------------------------------------------------------------
################################################################################
# -- submenu class; each instance is one set of related selections
################################################################################
class submenu :
VERSION = "$Revision: 1.4 $ $Date: 2019/06/23 18:12:57 $"
def __init__ (self, name) :
self.name = name
self.selection = -1
self.prompts = []
self.values = []
self.count = 0
def additem (self, prompt, value, selected) :
# -- Add an item to a menu and return its index
self.prompts.append(prompt)
self.values.append(value)
self.count = len(self.values)
if selected or self.selection < 0 :
self.selection = self.count - 1
return (self.count - 1)
def setval (self, valix) :
# -- set selection index
if valix >= 0 and valix < self.count :
self.selection = valix
return valix
else :
return -1
def value (self) :
# -- return the value of the current selection
if self.count <= 0 :
return
if self.selection < 0 or self.selection >= self.count :
self.selection = 0
return self.values[self.selection]
def current (self) :
#-- return display prompt and value of the current selection
if self.count <= 0 :
return "", ""
else :
return self.prompts[self.selection], self.values[self.selection]
def selnext (self) :
# -- Increment the selection and return new prompt & value
if self.count <= 0 :
return "", ""
else :
self.selection += 1
if self.selection >= self.count :
self.selection = 0
return self.prompts[self.selection], self.values[self.selection]
def whichat (self, which) :
# -- return prompt and value at the given index modulo set size
if self.count <= 0 :
return "", ""
which = which % self.count
return self.prompts[which], self.values[which]
if __name__ == "__main__" :
################################################################################
# -- Initialize menu set
################################################################################
# ---------------------------------
# -- Resolution
resolutions = submenu ("Resolution")
resolutions.additem ('1920x1080 16:9', '1920x1080', 0)
resolutions.additem ('1280x720 16:9', '1280x720', 1)
resolutions.additem ('1640x922 16:9', '1640x922', 0)
resolutions.additem ('2592x1944 4:3', '2592x1944', 0)
resolutions.additem ('1296x972 4:3', '1296x972', 0)
resolutions.additem ('800x600 4:3', '800x600', 0)
resolutions.additem ('640x480 4:3', '640x480', 0)
# ---------------------------------
# -- Capture Mode
modes = submenu ("Mode")
modes.additem ('Frames', 'F', 0)
modes.additem ('Video', 'V', 1)
# ---------------------------------
# -- Frames per Second
fps = submenu ("FPS")
fps.additem ('18', 18, 0)
fps.additem ('24', 24, 1)
fps.additem ('30', 30, 0)
# ---------------------------------
# -- Recording Length in seconds
mn=60
hr=mn*60
dy=hr*24
mo=dy*30.5
yr=dy*365.25
reclen = submenu ("Recording length")
reclen.additem ('10 minutes', 10*mn, 0)
reclen.additem ('30 minutes', 30*mn, 0)
reclen.additem ('1 hour', hr, 0)
reclen.additem ('2 hours', 2*hr, 0)
reclen.additem ('3 hours', 3*hr, 0)
reclen.additem ('6 hours', 6*hr, 0)
reclen.additem ('12 hours', 12*hr, 0)
reclen.additem ('24 hours', 24*hr, 0)
reclen.additem ('forever', 12*yr, 1) # 12 years feels like forever
# ---------------------------------
# -- Cycle reclen in new recordings
cycle = submenu ("Cycles")
cycle.additem ('Once', 0, 1)
cycle.additem ('Repeat', 1, 0)
#-- The set that comprises the whole menu system
menus = [resolutions, modes, fps, reclen, cycle]
################################################################################
# -- Exercise the menus
################################################################################
print cycle.VERSION+"\n"
for menu in menus :
print menu.name
for ix in range (0, menu.count) :
prompt, val = menu.whichat (ix)
print "\t", prompt,
if ix == menu.selection :
print "*"
else :
print
print "\nCycle FPS:\n"
for ix in range (0, fps.count) :
prompt, val = fps.selnext()
print prompt
print "\nCurrent Values:\n"
print "--------------------------------"
for menu in menus :
prompt, value = menu.current()
print "%s: %s" % (menu.name, prompt)
print "--------------------------------"
print "\nIncrement reclen\n"
prompt, value = reclen.selnext()
print prompt
print "\nreclen prompts\n"
print reclen.prompts