Add more infos

master
Guillaume Dott 2017-11-07 14:17:44 +01:00
parent 2617ce35ac
commit dbddbd36c5
1 changed files with 30 additions and 8 deletions

View File

@ -86,25 +86,47 @@ class InfoButton(Button):
super(InfoButton, self).__init__(rect) super(InfoButton, self).__init__(rect)
self.enabled = False self.enabled = False
self.cache = False
self.font = pygame.font.Font(None, 25) self.font = pygame.font.Font(None, 25)
self.logo = pygame.image.load(os.path.dirname(os.path.realpath(__file__)) + '/raspberrypi.png').convert_alpha() 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): def draw_on(self, screen):
if self.enabled: if self.enabled:
screen.blit(self.logo, self.logo.get_rect()) screen.blit(self.logo, self.logo.get_rect())
top = self.logo.get_rect().height + 10 top = self.logo.get_rect().height + 10
text = "COUNT: " + str(self.photoboite.capture_button.count) texts = [
size = self.font.size(text) "DATE: " + self.date(),
ren = self.font.render(text, True, (255, 255, 255)) "COUNT: " + str(self.photoboite.capture_button.count),
screen.blit(ren, (0, top)) "FPS: " + str(self.photoboite.clock.get_fps()),
"DISK USAGE:" + self.disk_usage()
]
text = "FPS: " + str(self.photoboite.clock.get_fps()) i = 0
for text in texts:
size = self.font.size(text) size = self.font.size(text)
ren = self.font.render(text, True, (255, 255, 255)) ren = self.font.render(text, True, (255, 255, 255))
screen.blit(ren, (0, top + 20)) screen.blit(ren, (0, top + i * 20))
i += 1
def run(self): def run(self):
if time.time() - self.timestamp > 0.5: if time.time() - self.timestamp > 0.5: