Compare commits
No commits in common. "master" and "v1.0.0" have entirely different histories.
1
.gitignore
vendored
@ -1 +0,0 @@
|
||||
__pycache__
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
300
film.svg
Normal file
@ -0,0 +1,300 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="800"
|
||||
height="480"
|
||||
viewBox="0 0 211.66666 127"
|
||||
version="1.1"
|
||||
id="svg8"
|
||||
inkscape:version="0.92.2 5c3e80d, 2017-08-06"
|
||||
sodipodi:docname="film.svg"
|
||||
inkscape:export-filename="/home/gdott9/prog/photoboite/film.png"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-ydpi="96">
|
||||
<defs
|
||||
id="defs2" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.7"
|
||||
inkscape:cx="-27.035262"
|
||||
inkscape:cy="235.80716"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
units="px"
|
||||
inkscape:window-width="1916"
|
||||
inkscape:window-height="1041"
|
||||
inkscape:window-x="1680"
|
||||
inkscape:window-y="18"
|
||||
inkscape:window-maximized="0"
|
||||
showguides="true"
|
||||
inkscape:guide-bbox="true" />
|
||||
<metadata
|
||||
id="metadata5">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-169.99998)">
|
||||
<path
|
||||
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:46.70000076;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="M 0 0 L 0 480 L 800 480 L 800 0 L 0 0 z M 95.380859 34.939453 L 704.61914 34.939453 C 712.58576 34.939453 719 41.351744 719 49.318359 L 719 430.68164 C 719 438.64826 712.58576 445.06055 704.61914 445.06055 L 95.380859 445.06055 C 87.414244 445.06055 81 438.64826 81 430.68164 L 81 49.318359 C 81 41.351744 87.414244 34.939453 95.380859 34.939453 z "
|
||||
transform="matrix(0.26458333,0,0,0.26458333,0,169.99998)"
|
||||
id="rect815" />
|
||||
<rect
|
||||
ry="3.1763959"
|
||||
y="68.898209"
|
||||
x="21.609423"
|
||||
height="107.36983"
|
||||
width="168.80417"
|
||||
id="rect825"
|
||||
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:13.44665909;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<g
|
||||
id="g884"
|
||||
transform="matrix(1.3669969,0,0,1.3669969,-1.1178441,-87.867666)">
|
||||
<rect
|
||||
ry="1.6657715"
|
||||
y="168.17415"
|
||||
x="3.0459228"
|
||||
height="7.7397852"
|
||||
width="11.091684"
|
||||
id="rect840"
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<rect
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect844"
|
||||
width="11.091684"
|
||||
height="7.7397852"
|
||||
x="3.0459228"
|
||||
y="178.68185"
|
||||
ry="1.6657715" />
|
||||
<rect
|
||||
ry="1.6657715"
|
||||
y="189.18956"
|
||||
x="3.0459228"
|
||||
height="7.7397852"
|
||||
width="11.091684"
|
||||
id="rect846"
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<rect
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect848"
|
||||
width="11.091684"
|
||||
height="7.7397852"
|
||||
x="3.0459228"
|
||||
y="199.69727"
|
||||
ry="1.6657715" />
|
||||
<rect
|
||||
ry="1.6657715"
|
||||
y="210.20496"
|
||||
x="3.0459228"
|
||||
height="7.7397852"
|
||||
width="11.091684"
|
||||
id="rect850"
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<rect
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect852"
|
||||
width="11.091684"
|
||||
height="7.7397852"
|
||||
x="3.0459228"
|
||||
y="220.71266"
|
||||
ry="1.6657715" />
|
||||
<rect
|
||||
ry="1.6657715"
|
||||
y="231.22035"
|
||||
x="3.0459228"
|
||||
height="7.7397852"
|
||||
width="11.091684"
|
||||
id="rect854"
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<rect
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect856"
|
||||
width="11.091684"
|
||||
height="7.7397852"
|
||||
x="3.0459228"
|
||||
y="241.72806"
|
||||
ry="1.6657715" />
|
||||
<rect
|
||||
ry="1.6657715"
|
||||
y="252.23576"
|
||||
x="3.0459228"
|
||||
height="7.7397852"
|
||||
width="11.091684"
|
||||
id="rect858"
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<rect
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect860"
|
||||
width="11.091684"
|
||||
height="7.7397852"
|
||||
x="3.0459228"
|
||||
y="262.74347"
|
||||
ry="1.6657715" />
|
||||
<rect
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect836"
|
||||
width="11.091684"
|
||||
height="7.7397852"
|
||||
x="3.0459228"
|
||||
y="273.25116"
|
||||
ry="1.6657715" />
|
||||
<rect
|
||||
ry="1.6657715"
|
||||
y="283.75888"
|
||||
x="3.0459228"
|
||||
height="7.7397852"
|
||||
width="11.091684"
|
||||
id="rect838"
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<rect
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect841"
|
||||
width="11.091684"
|
||||
height="7.7397852"
|
||||
x="3.0459228"
|
||||
y="294.26657"
|
||||
ry="1.6657715" />
|
||||
</g>
|
||||
<rect
|
||||
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:13.44665909;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect905"
|
||||
width="168.80417"
|
||||
height="107.36983"
|
||||
x="21.609423"
|
||||
y="291.26645"
|
||||
ry="3.1763959" />
|
||||
<g
|
||||
transform="matrix(1.3669969,0,0,1.3669969,189.38216,-87.867666)"
|
||||
id="g4581">
|
||||
<rect
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect4555"
|
||||
width="11.091684"
|
||||
height="7.7397852"
|
||||
x="3.0459228"
|
||||
y="168.17415"
|
||||
ry="1.6657715" />
|
||||
<rect
|
||||
ry="1.6657715"
|
||||
y="178.68185"
|
||||
x="3.0459228"
|
||||
height="7.7397852"
|
||||
width="11.091684"
|
||||
id="rect4557"
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<rect
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect4559"
|
||||
width="11.091684"
|
||||
height="7.7397852"
|
||||
x="3.0459228"
|
||||
y="189.18956"
|
||||
ry="1.6657715" />
|
||||
<rect
|
||||
ry="1.6657715"
|
||||
y="199.69727"
|
||||
x="3.0459228"
|
||||
height="7.7397852"
|
||||
width="11.091684"
|
||||
id="rect4561"
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<rect
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect4563"
|
||||
width="11.091684"
|
||||
height="7.7397852"
|
||||
x="3.0459228"
|
||||
y="210.20496"
|
||||
ry="1.6657715" />
|
||||
<rect
|
||||
ry="1.6657715"
|
||||
y="220.71266"
|
||||
x="3.0459228"
|
||||
height="7.7397852"
|
||||
width="11.091684"
|
||||
id="rect4565"
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<rect
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect4567"
|
||||
width="11.091684"
|
||||
height="7.7397852"
|
||||
x="3.0459228"
|
||||
y="231.22035"
|
||||
ry="1.6657715" />
|
||||
<rect
|
||||
ry="1.6657715"
|
||||
y="241.72806"
|
||||
x="3.0459228"
|
||||
height="7.7397852"
|
||||
width="11.091684"
|
||||
id="rect4569"
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<rect
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect4571"
|
||||
width="11.091684"
|
||||
height="7.7397852"
|
||||
x="3.0459228"
|
||||
y="252.23576"
|
||||
ry="1.6657715" />
|
||||
<rect
|
||||
ry="1.6657715"
|
||||
y="262.74347"
|
||||
x="3.0459228"
|
||||
height="7.7397852"
|
||||
width="11.091684"
|
||||
id="rect4573"
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<rect
|
||||
ry="1.6657715"
|
||||
y="273.25116"
|
||||
x="3.0459228"
|
||||
height="7.7397852"
|
||||
width="11.091684"
|
||||
id="rect4575"
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<rect
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect4577"
|
||||
width="11.091684"
|
||||
height="7.7397852"
|
||||
x="3.0459228"
|
||||
y="283.75888"
|
||||
ry="1.6657715" />
|
||||
<rect
|
||||
ry="1.6657715"
|
||||
y="294.26657"
|
||||
x="3.0459228"
|
||||
height="7.7397852"
|
||||
width="11.091684"
|
||||
id="rect4579"
|
||||
style="opacity:1;fill:#fcffff;fill-opacity:1;stroke:none;stroke-width:9.07567692;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 12 KiB |
386
photoboite.py
@ -1,6 +1,388 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import io, os, sys, time, pygame
|
||||
import photoboite
|
||||
|
||||
photoboite.Photoboite().run()
|
||||
try:
|
||||
import picamera
|
||||
|
||||
class Camera:
|
||||
def __init__(self, rect):
|
||||
self.rect = rect
|
||||
self.camera = picamera.PiCamera()
|
||||
self.camera.led = False
|
||||
self.camera.resolution = (self.rect.width, self.rect.height)
|
||||
self.rgb = bytearray(self.rect.width * self.rect.height * 4)
|
||||
|
||||
def close(self):
|
||||
self.camera.close()
|
||||
|
||||
def take(self, name):
|
||||
name = name + '.jpg'
|
||||
self.camera.resolution = (3280, 2464)
|
||||
self.camera.capture(name)
|
||||
self.camera.resolution = (self.rect.width, self.rect.height)
|
||||
return name
|
||||
|
||||
def stream(self):
|
||||
stream = io.BytesIO()
|
||||
self.camera.capture(stream, use_video_port=True, format='rgba', resize=(self.rect.width, self.rect.height))
|
||||
stream.seek(0)
|
||||
stream.readinto(self.rgb)
|
||||
stream.close()
|
||||
img = pygame.image.frombuffer(self.rgb, (self.rect.width, self.rect.height), 'RGBA')
|
||||
|
||||
return pygame.transform.flip(img, True, False)
|
||||
|
||||
def draw_on(self, screen):
|
||||
screen.blit(self.stream(), self.rect)
|
||||
|
||||
|
||||
except:
|
||||
class Camera:
|
||||
def __init__(self, rect):
|
||||
self.rect = rect
|
||||
self.img = pygame.transform.scale(pygame.image.load('tournesol.jpg'), (self.rect.width, self.rect.height))
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
def take(self, name):
|
||||
print('Take picture! ' + name)
|
||||
return 'tournesol.jpg'
|
||||
|
||||
def draw_on(self, screen):
|
||||
screen.blit(self.img, self.rect)
|
||||
|
||||
|
||||
|
||||
class Button:
|
||||
def __init__(self, rect):
|
||||
self.rect = rect
|
||||
self.pressed = False
|
||||
self.enabled = True
|
||||
|
||||
def draw_on(self, screen):
|
||||
pass
|
||||
|
||||
def is_pressed(self, pos):
|
||||
return self.rect.collidepoint(pos)
|
||||
|
||||
def press(self):
|
||||
self.pressed = True
|
||||
|
||||
def unpress(self):
|
||||
self.pressed = False
|
||||
self.run()
|
||||
|
||||
def run(self):
|
||||
pass
|
||||
|
||||
class InfoButton(Button):
|
||||
def __init__(self, rect, photoboite):
|
||||
self.count = 0
|
||||
self.timestamp = 0
|
||||
self.photoboite = photoboite
|
||||
|
||||
super(InfoButton, self).__init__(rect)
|
||||
|
||||
self.enabled = False
|
||||
self.cache = False
|
||||
|
||||
self.font = pygame.font.Font(None, 25)
|
||||
self.logo = pygame.image.load(os.path.dirname(os.path.realpath(__file__)) + '/raspberrypi.png').convert_alpha()
|
||||
|
||||
def date(self):
|
||||
if not self.cache:
|
||||
self.date_string = str(time.strftime('%Y-%m-%d %H:%M:%S'))
|
||||
return self.date_string
|
||||
|
||||
def disk_usage(self):
|
||||
if not self.cache:
|
||||
st = os.statvfs('/')
|
||||
free = round(st.f_bavail * st.f_frsize / 1073741824)
|
||||
total = round(st.f_blocks * st.f_frsize / 1073741824)
|
||||
used = round((st.f_blocks - st.f_bfree) * st.f_frsize / 1073741824)
|
||||
|
||||
self.disk_usage_string = str(used) + "G / " + str(total) + "G (free: " + str(free) + "G)"
|
||||
|
||||
return self.disk_usage_string
|
||||
|
||||
def draw_on(self, screen):
|
||||
if self.enabled:
|
||||
screen.blit(self.logo, self.logo.get_rect())
|
||||
|
||||
top = self.logo.get_rect().height + 10
|
||||
|
||||
texts = [
|
||||
"DATE: " + self.date(),
|
||||
"COUNT: " + str(self.photoboite.capture_button.count),
|
||||
"FPS: " + str(self.photoboite.clock.get_fps()),
|
||||
"DISK USAGE:" + self.disk_usage()
|
||||
]
|
||||
|
||||
i = 0
|
||||
for text in texts:
|
||||
size = self.font.size(text)
|
||||
ren = self.font.render(text, True, (255, 255, 255))
|
||||
screen.blit(ren, (0, top + i * 20))
|
||||
|
||||
i += 1
|
||||
|
||||
def run(self):
|
||||
if time.time() - self.timestamp > 0.5:
|
||||
self.count = 1
|
||||
else:
|
||||
self.count += 1
|
||||
|
||||
self.timestamp = time.time()
|
||||
|
||||
if self.count >= 2:
|
||||
self.enabled = not self.enabled
|
||||
|
||||
class PowerButton(Button):
|
||||
def __init__(self, rect):
|
||||
self.count = 0
|
||||
self.timestamp = 0
|
||||
|
||||
super(PowerButton, self).__init__(rect)
|
||||
|
||||
def run(self):
|
||||
if time.time() - self.timestamp > 0.5:
|
||||
self.count = 1
|
||||
self.timestamp = time.time()
|
||||
else:
|
||||
self.count += 1
|
||||
self.timestamp = time.time()
|
||||
|
||||
if self.count >= 5:
|
||||
os.system('sudo poweroff')
|
||||
|
||||
class CaptureButton(Button):
|
||||
countdown = 3
|
||||
|
||||
def __init__(self, size, topleft, photoboite):
|
||||
self.up_image = pygame.image.load(os.path.dirname(os.path.realpath(__file__)) + '/button-up.png').convert_alpha()
|
||||
self.up_image = pygame.transform.smoothscale(self.up_image, (size, size))
|
||||
|
||||
self.down_image = pygame.image.load(os.path.dirname(os.path.realpath(__file__)) + '/button-down.png').convert_alpha()
|
||||
self.down_image = pygame.transform.smoothscale(self.down_image, (size, size))
|
||||
|
||||
rect = self.up_image.get_rect()
|
||||
rect.topleft = topleft
|
||||
|
||||
super(CaptureButton, self).__init__(rect)
|
||||
self.photoboite = photoboite
|
||||
self.elapsed = 0
|
||||
self.capture_mode = False
|
||||
self.count = 0
|
||||
|
||||
self.background_rect = pygame.Rect(0, self.photoboite.screen.get_height() - 80, self.photoboite.screen.get_width(), 80)
|
||||
self.background = pygame.Surface((self.background_rect.width, self.background_rect.height))
|
||||
self.background.fill((0, 0, 0))
|
||||
self.background.set_alpha(150)
|
||||
|
||||
self.font = pygame.font.Font(None, 80)
|
||||
|
||||
self.photo_film = pygame.image.load(os.path.dirname(os.path.realpath(__file__)) + '/film.png').convert_alpha()
|
||||
|
||||
def draw_on(self, screen):
|
||||
if self.enabled:
|
||||
if self.pressed:
|
||||
screen.blit(self.down_image, self.rect)
|
||||
else:
|
||||
screen.blit(self.up_image, self.rect)
|
||||
if self.capture_mode and self.elapsed < CaptureButton.countdown:
|
||||
screen.blit(self.background, self.background_rect.topleft)
|
||||
|
||||
text = str(CaptureButton.countdown - self.elapsed)
|
||||
size = self.font.size(text)
|
||||
ren = self.font.render(text, True, (255, 255, 255))
|
||||
ren.set_alpha(150)
|
||||
|
||||
topleft = (self.rect.topleft[0] + self.rect.width / 2 - size[0] / 2, self.rect.topleft[1] + self.rect.height / 2 - size[1] / 2)
|
||||
top = self.background_rect.top + self.background_rect.height / 2 - size[1] / 2
|
||||
left = self.background_rect.left + self.background_rect.width / 2 - size[0] / 2
|
||||
screen.blit(ren, (left, top))
|
||||
|
||||
def run(self):
|
||||
pygame.event.set_blocked((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP))
|
||||
self.capture_mode = True
|
||||
self.enabled = False
|
||||
|
||||
capture = Capture(self.count)
|
||||
self.count += 1
|
||||
|
||||
for i in range(3):
|
||||
wait = True
|
||||
start = time.time()
|
||||
while wait:
|
||||
self.elapsed = int(time.time() - start)
|
||||
if self.elapsed >= CaptureButton.countdown:
|
||||
wait = False
|
||||
|
||||
self.photoboite.event()
|
||||
self.photoboite.draw()
|
||||
pygame.display.flip()
|
||||
|
||||
capture.take(self.photoboite.camera)
|
||||
pygame.time.wait(600)
|
||||
|
||||
for photo in capture.photos:
|
||||
self.photoboite.screen.blit(photo.capture, (81, 0))
|
||||
self.photoboite.screen.blit(self.photo_film, (0, 0))
|
||||
pygame.display.flip()
|
||||
pygame.time.wait(800)
|
||||
self.photoboite.event()
|
||||
|
||||
pygame.time.wait(200)
|
||||
|
||||
pygame.event.set_allowed((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP))
|
||||
self.capture_mode = False
|
||||
self.enabled = True
|
||||
self.photoboite.sleep.move()
|
||||
|
||||
|
||||
class Capture:
|
||||
def __init__(self, uid):
|
||||
self.uid = uid
|
||||
self.photos = []
|
||||
|
||||
def take(self, camera):
|
||||
self.photos.append(Photo(self.uid, len(self.photos)).take(camera))
|
||||
|
||||
|
||||
class Photo:
|
||||
def __init__(self, cid, uid):
|
||||
self.cid = cid
|
||||
self.uid = uid
|
||||
|
||||
def take(self, camera):
|
||||
self.name = "photos/%s-%04d-%04d" % (time.strftime('%Y%m%d-%H%M%S'), self.cid, self.uid)
|
||||
self.capture = pygame.transform.smoothscale(pygame.image.load(camera.take(self.name)), (638, 480))
|
||||
|
||||
return self
|
||||
|
||||
|
||||
class SleepMode:
|
||||
def __init__(self, seconds, screen):
|
||||
self.enabled = True
|
||||
self.drawn = False
|
||||
self.seconds = seconds
|
||||
|
||||
self.screen = screen
|
||||
|
||||
self.clicker = pygame.image.load(os.path.dirname(os.path.realpath(__file__)) + '/clicker.png').convert_alpha()
|
||||
self.clicker_rect = self.clicker.get_rect()
|
||||
self.clicker_rect.topleft = ((self.screen.get_width() - self.clicker_rect.width) / 2, (self.screen.get_height() - self.clicker_rect.height) / 2)
|
||||
|
||||
def move(self):
|
||||
self.last_action = time.time()
|
||||
|
||||
def event(self):
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.MOUSEBUTTONUP or event.type == pygame.KEYUP:
|
||||
self.move()
|
||||
self.enabled = False
|
||||
|
||||
def draw(self):
|
||||
if not self.drawn:
|
||||
self.screen.fill((255,255,255))
|
||||
self.screen.blit(self.clicker, self.clicker_rect)
|
||||
pygame.display.flip()
|
||||
self.drawn = True
|
||||
|
||||
def sleep(self):
|
||||
if time.time() - self.last_action > self.seconds:
|
||||
self.enabled = True
|
||||
self.drawn = False
|
||||
|
||||
class Photoboite:
|
||||
def __init__(self):
|
||||
self.screen = self.screen()
|
||||
pygame.font.init()
|
||||
|
||||
pygame.mouse.set_visible(False)
|
||||
|
||||
self.buttons = []
|
||||
|
||||
button_size = int(self.screen.get_height() / 4)
|
||||
topleft = (self.screen.get_width() - button_size) / 2, self.screen.get_height() - button_size - 10
|
||||
|
||||
self.capture_button = CaptureButton(button_size, topleft, self)
|
||||
self.buttons.append(self.capture_button)
|
||||
self.buttons.append(PowerButton(pygame.Rect(self.screen.get_width() - 50, 0, 50, 50)))
|
||||
self.buttons.append(InfoButton(pygame.Rect(0, 0, 50, 50), self))
|
||||
|
||||
camera_rect = pygame.Rect(0, 0, 800, 480)
|
||||
self.camera = Camera(camera_rect)
|
||||
|
||||
self.clock = pygame.time.Clock()
|
||||
|
||||
self.sleep = SleepMode(30, self.screen)
|
||||
|
||||
|
||||
def screen(self):
|
||||
if os.getenv('DISPLAY'):
|
||||
pygame.display.init()
|
||||
display = pygame.display.Info()
|
||||
return pygame.display.set_mode((800, 480))
|
||||
else:
|
||||
drivers = ['directfb', 'fbcon', 'svgalib']
|
||||
found = False
|
||||
for driver in drivers:
|
||||
if not os.getenv('SDL_VIDEODRIVER'):
|
||||
os.putenv('SDL_VIDEODRIVER', driver)
|
||||
try:
|
||||
pygame.display.init()
|
||||
except pygame.error as e:
|
||||
print('Driver: {0} failed.'.format(driver))
|
||||
continue
|
||||
found = True
|
||||
break
|
||||
|
||||
if not found:
|
||||
raise Exception('No suitable video driver found!')
|
||||
|
||||
return pygame.display.set_mode()
|
||||
|
||||
def draw(self):
|
||||
self.clock.tick(60)
|
||||
|
||||
self.camera.draw_on(self.screen)
|
||||
|
||||
for button in self.buttons:
|
||||
button.draw_on(self.screen)
|
||||
|
||||
def event(self):
|
||||
for event in pygame.event.get():
|
||||
self.sleep.move()
|
||||
|
||||
if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.unicode == 'q':
|
||||
self.quit()
|
||||
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||
for button in self.buttons:
|
||||
if button.is_pressed(event.pos):
|
||||
button.press()
|
||||
elif event.type == pygame.MOUSEBUTTONUP:
|
||||
for button in self.buttons:
|
||||
if button.is_pressed(event.pos):
|
||||
button.unpress()
|
||||
|
||||
def run(self):
|
||||
pressed = False
|
||||
while True:
|
||||
if self.sleep.enabled:
|
||||
self.sleep.event()
|
||||
self.sleep.draw()
|
||||
self.clock.tick(60)
|
||||
else:
|
||||
self.event()
|
||||
self.draw()
|
||||
self.sleep.sleep()
|
||||
pygame.display.flip()
|
||||
|
||||
def quit(self):
|
||||
self.camera.close()
|
||||
sys.exit()
|
||||
|
||||
Photoboite().run()
|
||||
|
@ -1,135 +0,0 @@
|
||||
import io, os, sys, time, pygame, random
|
||||
import photoboite.screens, photoboite.buttons, photoboite.buttons.config
|
||||
|
||||
try:
|
||||
import picamera
|
||||
|
||||
class Camera:
|
||||
def __init__(self, rect):
|
||||
self.rect = rect
|
||||
self.camera = picamera.PiCamera()
|
||||
self.camera.led = False
|
||||
self.camera.resolution = (self.rect.width, self.rect.height)
|
||||
self.rgb = bytearray(self.rect.width * self.rect.height * 4)
|
||||
|
||||
def close(self):
|
||||
self.camera.close()
|
||||
|
||||
def take(self, name):
|
||||
name = name + '.jpg'
|
||||
self.camera.resolution = (3280, 2464)
|
||||
self.camera.capture(name)
|
||||
self.camera.resolution = (self.rect.width, self.rect.height)
|
||||
return name
|
||||
|
||||
def stream(self):
|
||||
stream = io.BytesIO()
|
||||
self.camera.capture(stream, use_video_port=True, format='rgba', resize=(self.rect.width, self.rect.height))
|
||||
stream.seek(0)
|
||||
stream.readinto(self.rgb)
|
||||
stream.close()
|
||||
img = pygame.image.frombuffer(self.rgb, (self.rect.width, self.rect.height), 'RGBA')
|
||||
|
||||
return pygame.transform.flip(img, True, False)
|
||||
|
||||
def draw_on(self, screen):
|
||||
screen.blit(self.stream(), self.rect)
|
||||
|
||||
|
||||
except:
|
||||
class Camera:
|
||||
def __init__(self, rect):
|
||||
self.rect = rect
|
||||
self.img = pygame.transform.scale(pygame.image.load(os.path.dirname(os.path.realpath(__file__)) + '/../images/tournesol.jpg'), (self.rect.width, self.rect.height))
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
def take(self, name):
|
||||
print('Take picture! ' + name)
|
||||
return os.path.dirname(os.path.realpath(__file__)) + '/../images/tournesol.jpg'
|
||||
|
||||
def draw_on(self, screen):
|
||||
screen.blit(self.img, self.rect)
|
||||
|
||||
|
||||
|
||||
class Capture:
|
||||
def __init__(self, uid):
|
||||
self.uid = uid
|
||||
self.photos = []
|
||||
|
||||
def take(self, camera):
|
||||
self.photos.append(Photo(self.uid, len(self.photos)).take(camera))
|
||||
|
||||
|
||||
class Photo:
|
||||
def __init__(self, cid, uid):
|
||||
self.cid = cid
|
||||
self.uid = uid
|
||||
|
||||
def take(self, camera):
|
||||
self.name = "photos/%s-%04d-%04d" % (time.strftime('%Y%m%d-%H%M%S'), self.cid, self.uid)
|
||||
|
||||
surface = pygame.Surface((646, 488))
|
||||
surface.fill((255, 255, 255))
|
||||
surface.blit(pygame.transform.smoothscale(pygame.image.load(camera.take(self.name)), (638, 480)), (4, 4))
|
||||
|
||||
self.capture = pygame.transform.rotate(surface.convert_alpha(), random.randrange(-20, 20, 4))
|
||||
|
||||
return self
|
||||
|
||||
|
||||
class Photoboite:
|
||||
def __init__(self):
|
||||
self.screen = self.screen()
|
||||
pygame.font.init()
|
||||
|
||||
pygame.mouse.set_visible(False)
|
||||
|
||||
self.clock = pygame.time.Clock()
|
||||
|
||||
self.config = photoboite.screens.Config(self)
|
||||
self.sleep = photoboite.screens.Sleep(30, self)
|
||||
self.capture = photoboite.screens.Capture(self, self.sleep)
|
||||
|
||||
|
||||
def screen(self):
|
||||
if os.getenv('DISPLAY'):
|
||||
pygame.display.init()
|
||||
display = pygame.display.Info()
|
||||
return pygame.display.set_mode((800, 480))
|
||||
else:
|
||||
drivers = ['directfb', 'fbcon', 'svgalib']
|
||||
found = False
|
||||
for driver in drivers:
|
||||
if not os.getenv('SDL_VIDEODRIVER'):
|
||||
os.putenv('SDL_VIDEODRIVER', driver)
|
||||
try:
|
||||
pygame.display.init()
|
||||
except pygame.error as e:
|
||||
print('Driver: {0} failed.'.format(driver))
|
||||
continue
|
||||
found = True
|
||||
break
|
||||
|
||||
if not found:
|
||||
raise Exception('No suitable video driver found!')
|
||||
|
||||
return pygame.display.set_mode()
|
||||
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
if self.config.enabled:
|
||||
self.config.run()
|
||||
elif self.sleep.enabled:
|
||||
self.sleep.run()
|
||||
else:
|
||||
self.capture.run()
|
||||
|
||||
self.clock.tick(60)
|
||||
|
||||
def quit(self):
|
||||
self.capture.quit()
|
||||
sys.exit()
|
@ -1,215 +0,0 @@
|
||||
import os, time, pygame, photoboite
|
||||
|
||||
class Button:
|
||||
def __init__(self, rect):
|
||||
self.rect = rect
|
||||
self.pressed = False
|
||||
self.enabled = True
|
||||
|
||||
def draw_on(self, screen):
|
||||
pass
|
||||
|
||||
def is_pressed(self, pos):
|
||||
return self.rect.collidepoint(pos)
|
||||
|
||||
def press(self):
|
||||
self.pressed = True
|
||||
|
||||
def unpress(self):
|
||||
self.pressed = False
|
||||
self.run()
|
||||
|
||||
def run(self):
|
||||
pass
|
||||
|
||||
class ConfigButton(Button):
|
||||
def __init__(self, rect, config):
|
||||
self.config = config
|
||||
|
||||
self.count = 0
|
||||
self.timestamp = 0
|
||||
|
||||
super(ConfigButton, self).__init__(rect)
|
||||
|
||||
def run(self):
|
||||
if time.time() - self.timestamp > 0.5:
|
||||
self.count = 1
|
||||
self.timestamp = time.time()
|
||||
else:
|
||||
self.count += 1
|
||||
self.timestamp = time.time()
|
||||
|
||||
if self.count >= 5:
|
||||
self.config.activate()
|
||||
|
||||
|
||||
class InfoButton(Button):
|
||||
def __init__(self, rect, photoboite):
|
||||
self.count = 0
|
||||
self.timestamp = 0
|
||||
self.photoboite = photoboite
|
||||
|
||||
super(InfoButton, self).__init__(rect)
|
||||
|
||||
self.enabled = False
|
||||
self.cache = False
|
||||
|
||||
self.font = pygame.font.Font(None, 25)
|
||||
self.logo = pygame.image.load(os.path.dirname(os.path.realpath(__file__)) + '/../../images/raspberrypi.png').convert_alpha()
|
||||
|
||||
def date(self):
|
||||
if not self.cache:
|
||||
self.date_string = str(time.strftime('%Y-%m-%d %H:%M:%S'))
|
||||
return self.date_string
|
||||
|
||||
def disk_usage(self):
|
||||
if not self.cache:
|
||||
st = os.statvfs('/')
|
||||
free = round(st.f_bavail * st.f_frsize / 1073741824)
|
||||
total = round(st.f_blocks * st.f_frsize / 1073741824)
|
||||
used = round((st.f_blocks - st.f_bfree) * st.f_frsize / 1073741824)
|
||||
|
||||
self.disk_usage_string = str(used) + "G / " + str(total) + "G (free: " + str(free) + "G)"
|
||||
|
||||
return self.disk_usage_string
|
||||
|
||||
def draw_on(self, screen):
|
||||
if self.enabled:
|
||||
screen.blit(self.logo, self.logo.get_rect())
|
||||
|
||||
top = self.logo.get_rect().height + 10
|
||||
|
||||
texts = [
|
||||
"DATE: " + self.date(),
|
||||
"COUNT: " + str(self.photoboite.capture.capture_button.count),
|
||||
"FPS: " + str(self.photoboite.clock.get_fps()),
|
||||
"DISK USAGE:" + self.disk_usage()
|
||||
]
|
||||
|
||||
i = 0
|
||||
for text in texts:
|
||||
size = self.font.size(text)
|
||||
ren = self.font.render(text, True, (255, 255, 255))
|
||||
screen.blit(ren, (0, top + i * 20))
|
||||
|
||||
i += 1
|
||||
|
||||
def run(self):
|
||||
if time.time() - self.timestamp > 0.5:
|
||||
self.count = 1
|
||||
else:
|
||||
self.count += 1
|
||||
|
||||
self.timestamp = time.time()
|
||||
|
||||
if self.count >= 2:
|
||||
self.enabled = not self.enabled
|
||||
|
||||
|
||||
class PowerButton(Button):
|
||||
def __init__(self, rect):
|
||||
self.count = 0
|
||||
self.timestamp = 0
|
||||
|
||||
super(PowerButton, self).__init__(rect)
|
||||
|
||||
def run(self):
|
||||
if time.time() - self.timestamp > 0.5:
|
||||
self.count = 1
|
||||
self.timestamp = time.time()
|
||||
else:
|
||||
self.count += 1
|
||||
self.timestamp = time.time()
|
||||
|
||||
if self.count >= 5:
|
||||
os.system('sudo poweroff')
|
||||
|
||||
class CaptureButton(Button):
|
||||
countdown = 3
|
||||
|
||||
def __init__(self, size, topleft, photoboite):
|
||||
self.up_image = pygame.image.load(os.path.dirname(os.path.realpath(__file__)) + '/../../images/button-up.png').convert_alpha()
|
||||
self.up_image = pygame.transform.smoothscale(self.up_image, (size, size))
|
||||
|
||||
self.down_image = pygame.image.load(os.path.dirname(os.path.realpath(__file__)) + '/../../images/button-down.png').convert_alpha()
|
||||
self.down_image = pygame.transform.smoothscale(self.down_image, (size, size))
|
||||
|
||||
rect = self.up_image.get_rect()
|
||||
rect.topleft = topleft
|
||||
|
||||
super(CaptureButton, self).__init__(rect)
|
||||
self.photoboite = photoboite
|
||||
self.elapsed = 0
|
||||
self.capture_mode = False
|
||||
self.count = 0
|
||||
|
||||
self.background_rect = pygame.Rect(0, self.photoboite.screen().get_height() - 80, self.photoboite.screen().get_width(), 80)
|
||||
self.background = pygame.Surface((self.background_rect.width, self.background_rect.height))
|
||||
self.background.fill((0, 0, 0))
|
||||
self.background.set_alpha(150)
|
||||
|
||||
self.font = pygame.font.Font(None, 80)
|
||||
|
||||
def draw_on(self, screen):
|
||||
if self.enabled:
|
||||
if self.pressed:
|
||||
screen.blit(self.down_image, self.rect)
|
||||
else:
|
||||
screen.blit(self.up_image, self.rect)
|
||||
if self.capture_mode and self.elapsed < CaptureButton.countdown:
|
||||
screen.blit(self.background, self.background_rect.topleft)
|
||||
|
||||
text = str(CaptureButton.countdown - self.elapsed)
|
||||
size = self.font.size(text)
|
||||
ren = self.font.render(text, True, (255, 255, 255))
|
||||
ren.set_alpha(150)
|
||||
|
||||
topleft = (self.rect.topleft[0] + self.rect.width / 2 - size[0] / 2, self.rect.topleft[1] + self.rect.height / 2 - size[1] / 2)
|
||||
top = self.background_rect.top + self.background_rect.height / 2 - size[1] / 2
|
||||
left = self.background_rect.left + self.background_rect.width / 2 - size[0] / 2
|
||||
screen.blit(ren, (left, top))
|
||||
|
||||
def run(self):
|
||||
pygame.event.set_blocked((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP))
|
||||
self.capture_mode = True
|
||||
self.enabled = False
|
||||
|
||||
capture = photoboite.Capture(self.count)
|
||||
self.count += 1
|
||||
|
||||
for i in range(3):
|
||||
wait = True
|
||||
start = time.time()
|
||||
while wait:
|
||||
self.elapsed = int(time.time() - start)
|
||||
if self.elapsed >= CaptureButton.countdown:
|
||||
wait = False
|
||||
|
||||
self.photoboite.event()
|
||||
self.photoboite.draw()
|
||||
pygame.display.flip()
|
||||
|
||||
capture.take(self.photoboite.camera)
|
||||
pygame.time.wait(600)
|
||||
|
||||
self.photoboite.screen().fill((200,200,200))
|
||||
|
||||
width = self.photoboite.screen().get_width()
|
||||
height = self.photoboite.screen().get_height()
|
||||
|
||||
for photo in capture.photos:
|
||||
photo_width = photo.capture.get_width()
|
||||
photo_height = photo.capture.get_height()
|
||||
|
||||
lefttop = ((width - photo_width) / 2, (height - photo_height) / 2)
|
||||
self.photoboite.screen().blit(photo.capture, lefttop)
|
||||
pygame.display.flip()
|
||||
pygame.time.wait(800)
|
||||
self.photoboite.event()
|
||||
|
||||
pygame.time.wait(200)
|
||||
|
||||
pygame.event.set_allowed((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP))
|
||||
self.capture_mode = False
|
||||
self.enabled = True
|
||||
self.photoboite.sleep.move()
|
@ -1,9 +0,0 @@
|
||||
import photoboite.buttons
|
||||
|
||||
class Close(photoboite.buttons.Button):
|
||||
def __init__(self, rect, config):
|
||||
self.config = config
|
||||
super(Close, self).__init__(rect)
|
||||
|
||||
def run(self):
|
||||
self.config.deactivate()
|
@ -1,133 +0,0 @@
|
||||
import os, time, sys, pygame
|
||||
import photoboite
|
||||
|
||||
class Capture:
|
||||
def __init__(self, main, sleep):
|
||||
self.main = main
|
||||
self.sleep = sleep
|
||||
|
||||
self.buttons = []
|
||||
|
||||
button_size = int(self.main.screen.get_height() / 4)
|
||||
topleft = (self.main.screen.get_width() - button_size) / 2, self.main.screen.get_height() - button_size - 10
|
||||
|
||||
self.capture_button = photoboite.buttons.CaptureButton(button_size, topleft, self)
|
||||
self.buttons.append(self.capture_button)
|
||||
self.buttons.append(photoboite.buttons.PowerButton(pygame.Rect(self.main.screen.get_width() - 50, 0, 50, 50)))
|
||||
self.buttons.append(photoboite.buttons.InfoButton(pygame.Rect(0, 0, 50, 50), self.main))
|
||||
self.buttons.append(photoboite.buttons.ConfigButton(pygame.Rect(0, self.main.screen.get_height() - 50, 50, 50), self.main.config))
|
||||
|
||||
camera_rect = pygame.Rect(0, 0, 800, 480)
|
||||
self.camera = photoboite.Camera(camera_rect)
|
||||
|
||||
def draw(self):
|
||||
self.camera.draw_on(self.main.screen)
|
||||
|
||||
for button in self.buttons:
|
||||
button.draw_on(self.main.screen)
|
||||
|
||||
def event(self):
|
||||
for event in pygame.event.get():
|
||||
self.sleep.move()
|
||||
|
||||
if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.unicode == 'q':
|
||||
self.main.quit()
|
||||
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||
for button in self.buttons:
|
||||
if button.is_pressed(event.pos):
|
||||
button.press()
|
||||
elif event.type == pygame.MOUSEBUTTONUP:
|
||||
for button in self.buttons:
|
||||
if button.is_pressed(event.pos):
|
||||
button.unpress()
|
||||
|
||||
def screen(self):
|
||||
return self.main.screen
|
||||
|
||||
def quit(self):
|
||||
self.camera.close()
|
||||
|
||||
def run(self):
|
||||
self.event()
|
||||
self.draw()
|
||||
self.sleep.sleep()
|
||||
pygame.display.flip()
|
||||
|
||||
class Config:
|
||||
def __init__(self, main):
|
||||
self.main = main
|
||||
self.enabled = False
|
||||
self.drawn = False
|
||||
|
||||
self.buttons = []
|
||||
|
||||
self.buttons.append(photoboite.buttons.config.Close(pygame.Rect(self.main.screen.get_width() - 50, 0, 50, 50), self))
|
||||
|
||||
def activate(self):
|
||||
self.enabled = True
|
||||
self.drawn = False
|
||||
|
||||
def deactivate(self):
|
||||
self.enabled = False
|
||||
|
||||
def draw(self):
|
||||
if not self.drawn:
|
||||
self.main.screen.fill((255,255,255))
|
||||
pygame.display.flip()
|
||||
self.drawn = True
|
||||
|
||||
def event(self):
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.unicode == 'q':
|
||||
self.main.quit()
|
||||
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||
for button in self.buttons:
|
||||
if button.is_pressed(event.pos):
|
||||
button.press()
|
||||
elif event.type == pygame.MOUSEBUTTONUP:
|
||||
for button in self.buttons:
|
||||
if button.is_pressed(event.pos):
|
||||
button.unpress()
|
||||
|
||||
def run(self):
|
||||
self.event()
|
||||
self.draw()
|
||||
|
||||
class Sleep:
|
||||
def __init__(self, seconds, main):
|
||||
self.enabled = True
|
||||
self.drawn = False
|
||||
self.seconds = seconds
|
||||
|
||||
self.main = main
|
||||
|
||||
self.clicker = pygame.image.load(os.path.dirname(os.path.realpath(__file__)) + '/../../images/clicker.png').convert_alpha()
|
||||
self.clicker_rect = self.clicker.get_rect()
|
||||
self.clicker_rect.topleft = ((self.main.screen.get_width() - self.clicker_rect.width) / 2, (self.main.screen.get_height() - self.clicker_rect.height) / 2)
|
||||
|
||||
def move(self):
|
||||
self.last_action = time.time()
|
||||
|
||||
def event(self):
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.unicode == 'q':
|
||||
self.main.quit()
|
||||
elif event.type == pygame.MOUSEBUTTONUP or event.type == pygame.KEYUP:
|
||||
self.move()
|
||||
self.enabled = False
|
||||
|
||||
def draw(self):
|
||||
if not self.drawn:
|
||||
self.main.screen.fill((255,255,255))
|
||||
self.main.screen.blit(self.clicker, self.clicker_rect)
|
||||
pygame.display.flip()
|
||||
self.drawn = True
|
||||
|
||||
def run(self):
|
||||
self.event()
|
||||
self.draw()
|
||||
|
||||
def sleep(self):
|
||||
if time.time() - self.last_action > self.seconds:
|
||||
self.enabled = True
|
||||
self.drawn = False
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 133 KiB After Width: | Height: | Size: 133 KiB |