-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
executable file
·157 lines (128 loc) · 5.46 KB
/
gui.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2012, Leonardo Leite
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from Tkinter import *
from threading import Timer
from PIL import Image, ImageTk
from round import Round
import properties
import figures
COLOR = 'light salmon'
class RoundInterface(object):
def __init__(self, names):
self.clock = 0
self.clocking = False
self.names = names
self.root = Toplevel()
self.root.title("Forest Gump")
frame = Frame(self.root, bg=COLOR)
frame.pack()
title = Label(frame, text="Forest Gump, o contador de histórias", font=('times', 50, 'bold'), bg=COLOR)
title.pack()
rock_path = figures.rock()
self.tkimg = ImageTk.PhotoImage(Image.open(rock_path))
self.image_label = Label(frame, image=self.tkimg, width=400, height=300, bg=COLOR)
self.image_label.pack()
self.word_label = Label(frame, text='Carregado imagens', font=('times', 100, 'bold'), bg=COLOR)
self.word_label.pack()
self.clock_label = Label(frame, text=self.clock, font=('times', 70, 'bold'), bg=COLOR)
self.clock_label.pack()
def start(self):
self.root.mainloop()
def start_clock(self):
self.clocking = True
self.__clock()
def __clock(self):
self.clock += 1
self.clock_label.configure(text=self.clock)
if (self.clocking):
Timer(1, self.__clock, ()).start()
def stop_clock(self):
self.clocking = False
def print_word(self, word, img_path):
self.word_label.configure(text=word)
if not img_path:
img_path = "resources/img/nothing.png"
if word in self.names:
img_path = "resources/img/avatar.png"
self.tkimg = ImageTk.PhotoImage(Image.open(img_path))
self.image_label.configure(image=self.tkimg)
def stop(self):
self.word_label.configure(text='ACABOU!')
self.tkimg = ImageTk.PhotoImage(Image.open('resources/img/stop.jpg'))
self.image_label.configure(image=self.tkimg)
self.stop_clock()
def rock(self):
self.word_label.configure(text="Let's rock!")
class Interface(object):
def __init__(self, lists=[]):
self.root = Tk()
self.lists = lists
self.root.title("Forest Gump")
master_frame = Frame(self.root, bg=COLOR)
master_frame.pack()
title = Label(master_frame, text="Forest Gump, o contador de histórias", font=('times', 30, 'bold'), bg=COLOR)
title.pack(side=TOP)
left_frame = Frame(master_frame, bg=COLOR, border=10)
left_frame.pack(side=LEFT)
right_frame = Frame(master_frame, bg=COLOR)
right_frame.pack(side=RIGHT)
self.tkimg = ImageTk.PhotoImage(Image.open("resources/img/uncle_sam.jpg"))
image_label = Label(right_frame, image=self.tkimg, width=400, height=300, bg=COLOR)
image_label.pack(side=RIGHT)
lists_frame = Frame(right_frame, bg=COLOR, border=5)
lists_frame.pack(side=LEFT)
lists_label = Label(lists_frame, text="Cartuchos", font=('times', 12), bg=COLOR, border=5)
lists_label.pack(side=TOP)
self.cbs = []
self.cb_values = []
for i, l in enumerate(self.lists):
self.cb_values.append(IntVar())
check = Checkbutton(lists_frame, text=l, bg=COLOR, border=5, var=self.cb_values[i])
self.cbs.append(check)
check.pack(side=BOTTOM)
names_label = Label(left_frame, text="Jogadores (um por linha):", font=('times', 12), bg=COLOR, border=5)
names_label.pack()
self.names_text = Text(left_frame, height=10, width=40, border=5)
self.names_text.pack()
button_frame = Frame(left_frame, border=5, bg=COLOR)
button_frame.pack()
name_button = Button(button_frame, text="Inicia rodada", command=self.start_round)
name_button.pack()
def start(self):
self.root.mainloop()
def start_round(self):
names = self.__get_names()
lists = self.__get_selected_lists()
interface = RoundInterface(names)
words_per_round = properties.WORDS_PER_ROUND
word_time_interval = properties.WORD_TIME_INTERVAL
img_from_wiki = properties.LOAD_IMAGES_FROM_WIKIPEDIA
round = Round(words_per_round, word_time_interval, names, lists, interface, img_from_wiki)
round.start()
def __get_names(self):
"""Retrieve players names from interface"""
names_str = self.names_text.get(1.0, END)
names = names_str.splitlines()
return names
def __get_selected_lists(self):
"""Retrieve selected lists from interface (checkbox checked)"""
selected = []
for i, l in enumerate(self.lists):
if self.cb_values[i].get():
selected.append(l)
return selected