From dbddbd36c5b242997448bff73134d6d8b49ca206 Mon Sep 17 00:00:00 2001 From: Guillaume Dott Date: Tue, 7 Nov 2017 14:17:44 +0100 Subject: [PATCH] Add more infos --- photoboite.py | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/photoboite.py b/photoboite.py index 9668ba9..48d96b5 100755 --- a/photoboite.py +++ b/photoboite.py @@ -86,25 +86,47 @@ class InfoButton(Button): 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 - text = "COUNT: " + str(self.photoboite.capture_button.count) - size = self.font.size(text) - ren = self.font.render(text, True, (255, 255, 255)) - screen.blit(ren, (0, top)) + texts = [ + "DATE: " + self.date(), + "COUNT: " + str(self.photoboite.capture_button.count), + "FPS: " + str(self.photoboite.clock.get_fps()), + "DISK USAGE:" + self.disk_usage() + ] - text = "FPS: " + str(self.photoboite.clock.get_fps()) - size = self.font.size(text) - ren = self.font.render(text, True, (255, 255, 255)) - screen.blit(ren, (0, top + 20)) + 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: