Various improvements

This commit is contained in:
Hugo 2024-04-14 22:01:10 +02:00
parent 9af04d3c30
commit 0b0aea6d86
3 changed files with 31 additions and 10 deletions

6
.gitignore vendored
View File

@ -138,3 +138,9 @@ dmypy.json
# Cython debug symbols
cython_debug/
*_creations/
*.exe
*.zip
*.csv
*.txt

BIN
pictionnary.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

View File

@ -67,6 +67,7 @@ class MyPaintWidget(Label):
pen_characteristics = {"current_color": (0,0,0,1),
"current_width": 4
}
bg = None
current_round = 0
current_word = ""
message_label = None
@ -77,6 +78,7 @@ class MyPaintWidget(Label):
super().__init__(**kwargs)
self._keyboard = None
self._load_words()
with self.canvas.before:
Color(1,1,1, mode='rgb')
self.bg = Rectangle(pos=self.pos, size=self.size)
@ -86,7 +88,6 @@ class MyPaintWidget(Label):
self.bind(size=resize_bg, pos=resize_bg)
self._get_keyboard()
self._load_words()
self._output_dir = datetime.now().isoformat(timespec='minutes').replace(":","-") + "_creations"
self._fullscreen = False
self.reset_game()
@ -105,7 +106,11 @@ class MyPaintWidget(Label):
self._wordlist = (word.strip() for word in wordfile.readlines())
self._game_wordlists["possible_wordlist"] = dict.fromkeys(self._wordlist)
except OSError:
Popup(title="Error", content=Label(text=f"Erreur de lecture du fichier '{WORDS_FILE}'")).open()
errmsg = f"Erreur de lecture du fichier '{WORDS_FILE}'"
if self.bg:
Popup(title="Error", content=Label(text=errmsg)).open()
else:
print(errmsg)
self._game_wordlists["possible_wordlist"] = dict()
@ -374,22 +379,25 @@ class GuessWhatIDrawApp(App):
size_button = SizeButton(self.set_cursor_size, 2*i)
self.right_row.add_widget(size_button)
middle_row = BoxLayout(orientation="horizontal", size_hint=(1, 0.8))
middle_row = BoxLayout(orientation="horizontal", size_hint=(1, 0.75))
middle_row.add_widget(self.painter)
middle_row.add_widget(self.right_row)
bottom_row = BoxLayout(orientation='horizontal', spacing=5, size_hint=(1, .1))
bottom_row = BoxLayout(orientation='horizontal', spacing=5, size_hint=(1, .05))
bottom_row.add_widget(togglebtn)
bottom_row.add_widget(clearbtn)
top_row = BoxLayout(orientation='horizontal', spacing=5, size_hint=(1, .1))
self.word_label = Label(text="Mot:", color=[0,0,0,1], halign="left", valign="top")
top_row = BoxLayout(orientation='horizontal', spacing=5, size_hint=(1, .2))
self.word_label = Label(text="Mot:", color=[0,0,0,1], halign="left", valign="top", size_hint=(0.2,1))
def redraw(self, obj):
self.text_size = obj
self.text_size = self.size
self.word_label.bind(size=redraw)
self.time_label = Label(text=f"{self.painter.time}", color=[0,0,0,1])
message_label = Label(color=[0,0,0,1], halign="center")
self.time_label = Label(text=f"{self.painter.time}", color=[0,0,0,1],
font_size='50pt', size_hint=(0.2,1))
message_label = Label(color=[0,0,0,1], halign="center", valign="top",
font_size='40pt', size_hint=(0.6,1))
message_label.bind(size=redraw)
top_row.add_widget(self.word_label)
top_row.add_widget(message_label)
top_row.add_widget(self.time_label)
@ -424,7 +432,7 @@ class GuessWhatIDrawApp(App):
else:
self.painter.game_finished()
self.time_label.text = f"{self.painter.time}"
self.time_label.text = f"{formatTimedelta(self.painter.time)}"
def toggle_background(self, obj):
@ -453,6 +461,13 @@ class GuessWhatIDrawApp(App):
def clear_canvas(self, _):
self.painter.clear_drawing()
def formatTimedelta(time:timedelta):
seconds = int(time.total_seconds())
minutes, reminder = divmod(seconds, 60)
return f"{minutes:02}:{reminder:02}.{int(time.microseconds/10000):02}"
if __name__ == '__main__':
GuessWhatIDrawApp().run()