-
Notifications
You must be signed in to change notification settings - Fork 2
/
pyyyc_v06.py
224 lines (173 loc) · 5.87 KB
/
pyyyc_v06.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
218
219
220
221
222
223
224
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from builtins import super
from six import string_types
def confirm_color(func):
""" This wrapper validates colors, either 'red', 'green', 'blue', or
rgb color
"""
def confirm(self, value):
if value == 'red':
value = [255, 0, 0]
if value == 'green':
value = [0, 255, 0]
if value == 'blue':
value = [0, 0, 255]
if not isinstance(value, (list, tuple)) or not len(value) == 3:
raise ValueError('{}: must be rgb color'.format(value))
for v in value:
if not isinstance(v, int):
raise ValueError('{}: rgb must be ints'.format(value))
if not 0 <= v < 256:
raise ValueError('{}: rgb must be 0-255'.format(value))
return func(self, value)
return confirm
def confirm_float(func):
""" This wrapper validates floats """
def confirm(self, value):
if not isinstance(value, float):
raise ValueError('{}: must be float'.format(value))
return func(self, value)
return confirm
def confirm_int(func):
""" This wrapper validates integers """
def confirm(self, value):
if not isinstance(value, int):
raise ValueError('{}: must be int'.format(value))
return func(self, value)
return confirm
def confirm_str(func):
""" This wrapper validates strings """
def confirm(self, value):
if not isinstance(value, string_types):
raise ValueError('{}: must be string'.format(value))
return func(self, value)
return confirm
class ReallyBasicPresentation(object):
""" class ReallyBasicPresentation
This class contains info about really basic presentations.
Inputs:
presenter - All presentations have presenters
"""
def __init__(self, presenter):
self.presenter = presenter
@property
def presenter(self):
return self._presenter
@presenter.setter
@confirmStr
def presenter(self, value):
self._presenter = value
class NormalPresentation(ReallyBasicPresentation):
""" class NormalPresentation
This class contains some more normal presentation stuff.
Inputs:
topic - Most normal presentations have a topic
time_limit - and a time limit
"""
def __init__(self, presenter, topic, time_limit):
super().__init__(presenter)
self.topic = topic
self.time_limit = time_limit
@property
def topic(self):
return self._topic
@topic.setter
@confirm_str
def topic(self, value):
self._topic = value
@property
def time_limit(self):
return self._time_limit
@time_limit.setter
@confirm_float
def time_limit(self, value):
self._time_limit = value
class PowerpointPresentation(NormalPresentation):
""" class PowerpointPresentation
This class contains some additional ppt stuff.
Inputs:
nslides - Number of slides
slide_color - Background color, rgb
"""
def __init__(self, presenter, topic, time_limit, nslides, slide_color):
super().__init__(presenter, topic, time_limit)
self.nslides = nslides
self.slide_color = slide_color
@property
def nslides(self):
return self._nslides
@nslides.setter
@confirm_int
def nslides(self, value):
self._nslides = value
@property
def slide_color(self):
return self._slide_color
@slide_color.setter
@confirm_color
def slide_color(self, value):
self._slide_color = value
class PyYYCPresentation(PowerpointPresentation):
""" class PyYYCPresentation
This class generates some really useful info about PyYYC presentations.
"""
def summarize(self):
"""Print a short description of the presentation. Useful for
press junkets.
"""
print('Pythonista {name} talking about {topic}.'.format(
name=self.presenter,
topic=self.topic
))
def time_per_slide(self):
"""Time available for each slide"""
return self.time_limit / self.nslides
def strains_eyes(self):
"""Determines if the slides will cause eye strain"""
return(any([rgb > 200 for rgb in self.slide_color]) and
any([rgb < 50 for rgb in self.slide_color]))
class YYCjsPresentation(PowerpointPresentation):
""" class YYCjsPresentation
This class generates some really useful info about YYCjs presentations.
"""
def summarize(self):
"""Print a short description of the presentation. Useful for
press junkets.
"""
print('JavaScripter {name} talking about {topic}.'.format(
name=self.presenter,
topic=self.topic
))
def time_per_slide(self):
"""Time available for each slide"""
return self.time_limit / self.nslides
def strains_eyes(self):
"""Determines if the slides will cause eye strain"""
return False
class FreeSpiritPresentation(ReallyBasicPresentation):
""" class FreeSpiritPresentation
These presentations are just silly.
Inputs:
favorite_color - Presenter's favorite color
"""
def __init__(self, presenter, favorite_color):
super().__init__(self, presenter)
self.favorite_color = favorite_color
@property
def favorite_color(self):
return self._favorite_color
@favorite_color.setter
@confirm_color
def favorite_color(self, value):
self._favorite_color = value
def summarize(self):
"""Print a short description of the presentation. Useful for
press junkets.
"""
print('{name} loves {topic}.'.format(
name=self.presenter,
topic=self.favorite_color
))