Continued working on logogame
This commit is contained in:
Voussoir 2015-03-14 23:28:17 -07:00
parent d9f16c22af
commit 9d81c4ff7b
7 changed files with 111 additions and 20 deletions

BIN
Logogame/images/kagenui.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

BIN
Logogame/images/python.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

BIN
Logogame/images/reddit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
Logogame/images/vega.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

View file

@ -29,22 +29,28 @@ class LogoGame:
self.color_green = '#31f13a'
self.color_red = '#e23939'
self.logos_per_row = 6
self.logo_padx = 10
self.logo_pady = 10
self.dbindex_id = 0
self.dbindex_images = 1
self.dbindex_name = 2
self.dbindex_solutions = 3
self.dbindex_name = 1
self.dbindex_solutions = 2
self.dbindex_images = 3
self.dbindex_tag = 4
self.dbindex_solved = 5
self.sql = sqlite3.connect('logos.db')
self.cur = self.sql.cursor()
self.stats_main = self.stats_load('stats')
self.playerstats_load(self.stats_main.playername)
self.logos_load()
self.tkinter_elements = []
self.logo_elements = []
self.tag_elements = []
self.active_tags = set()
self.all_tags = []
self.all_logos = []
self.logos_load()
self.w = 1062
self.h = 600
@ -65,14 +71,27 @@ class LogoGame:
self.t.mainloop()
def logos_load(self):
self.all_logos = []
self.cur.execute('SELECT * FROM logos')
self.all_logos = self.cur.fetchall()
fetch = self.cur.fetchall()
for item in fetch:
logo = Generic()
logo.id = item[self.dbindex_id]
logo.images = item[self.dbindex_images].split(',')
logo.name = item[self.dbindex_name]
logo.solutions = item[self.dbindex_solutions].split(',')
logo.tags = item[self.dbindex_tag].split(',')
logo.solved = self.playerstats_hassolved(logo.id)
self.all_logos.append(logo)
self.all_tags = self.get_all_tags()
self.all_tags.append('Completed')
def destroy_all_elements(self):
self.tag_elements = []
self.destroy_all_logos()
while len(self.tkinter_elements) > 0:
self.tkinter_elements[0].destroy()
del self.tkinter_elements[0]
self.destroy_all_logos()
def destroy_all_logos(self):
while len(self.logo_elements) > 0:
@ -153,35 +172,92 @@ class LogoGame:
#self.frame_gamearea = tkinter.Frame(self.t, bg='#f00')
#self.frame_gamearea.pack(expand=True, fill='both', anchor='w')
#
self.frame_gametaglist = tkinter.Frame(self.t)
self.frame_gametaglist.pack(expand=True, fill='y', anchor='e')
self.frame_posttoolbar = tkinter.Frame(self.t)
self.frame_posttoolbar.pack(expand=True, fill='both')
self.tkinter_elements.append(self.frame_posttoolbar)
#
self.frame_gametaglist = tkinter.Frame(self.frame_posttoolbar)
self.frame_gametaglist.pack(expand=True, fill='y', side='left', anchor='w')
self.tkinter_elements.append(self.frame_gametaglist)
#
self.frame_logoarea = tkinter.Frame(self.frame_posttoolbar)
self.frame_logoarea.pack(expand=True, fill='both', anchor='e')
self.tkinter_elements.append(self.frame_logoarea)
#
button_applytag = tkinter.Button(self.frame_gametaglist, text='Apply', command=self.gui_rebuild_game)
button_applytag.grid(row=0, column=0, sticky='w')
alltags = self.get_all_tags()
for tag in alltags:
#
for i in range(len(self.all_tags)):
tag = self.all_tags[i]
intvar = tkinter.IntVar()
intvar.title=tag
intvar.tag=tag
checkbox = tkinter.Checkbutton(self.frame_gametaglist, text=tag, variable=intvar)
checkbox.intvar = intvar
checkbox.grid(row=alltags.index(tag)+1, column=0, sticky='w')
checkbox.grid(row=i+1, column=0, sticky='w')
intvar.set(1)
self.tkinter_elements.append(checkbox)
self.tag_elements.append(checkbox)
self.active_tags.add(tag)
self.gui_rebuild_game()
###
def gui_rebuild_game(self, *b):
self.destroy_all_logos()
w = self.t.winfo_width()
h = self.t.winfo_height()
resizemeter = w / 9
row = 0
col = 0
for element in self.tag_elements:
if element.intvar.get() == 1:
self.active_tags.add(element.intvar.tag)
elif element.intvar.tag in self.active_tags:
self.active_tags.remove(element.intvar.tag)
for logo in self.all_logos:
if not any(tag in self.active_tags for tag in logo.tags):
continue
if logo.solved is True and 'Completed' not in self.active_tags:
continue
logoframe = tkinter.Frame(self.frame_logoarea)
logoframe.pack_propagate(0)
self.logo_elements.append(logoframe)
imageframe = tkinter.Frame(logoframe, width=resizemeter, height=resizemeter)
imageframe.pack_propagate(0)
imageframe.grid(row=0, column=0, sticky='n')
label_image = tkinter.Label(imageframe)
label_image.pack(anchor='center', expand=True, fill='both')
label_name = tkinter.Label(logoframe)
entry_name = tkinter.Entry(logoframe)
if logo.solved is True:
i = self.png_load(logo.images[-1], resizemeter)
label_image.configure(image=i)
label_image.i = i
label_name.configure(text=logo.name)
label_name.grid(row=1, column=0, sticky='s')
else:
i = self.png_load(logo.images[0], resizemeter)
label_image.configure(image=i)
label_image.i = i
entry_name.grid(row=1, column=0, sticky='s')
self.tkinter_elements.append(logoframe)
logoframe.id = logo.id
logoframe.entry_name = entry_name
logoframe.label_name = label_name
logoframe.label_image = label_image
logoframe.grid(row=row, column=col, padx=self.logo_padx, pady=self.logo_pady)
col += 1
col = col % self.logos_per_row
if col == 0:
row += 1
def gui_build_logo(self, *b):
self.destroy_all_elements()
###
def playername_set(self, newname):
if newname != self.stats_main.playername:
self.cur.execute('UPDATE stats SET value=? WHERE key="playername"', [newname])
@ -191,6 +267,8 @@ class LogoGame:
if self.label_playerhash:
self.label_playerhash.configure(text=playerhash)
for logo in self.all_logos:
logo.solved = self.playerstats_hassolved(logo.id)
print('Name: ' + self.stats_main.playername)
def sha8(self, text):
@ -202,12 +280,13 @@ class LogoGame:
def png_load(self, filename, resize=None):
if filename[-4:] != '.png':
filename = filename + '.png'
filename = 'images/' + filename
i = Image.open(filename)
if resize:
ratio = resize / max(i.size)
newx = int(i.size[0] * ratio)
newy = int(i.size[1] * ratio)
i = i.resize([newx, newy])
i = i.resize([newx, newy], resample=Image.ANTIALIAS)
i = ImageTk.PhotoImage(i)
return i
@ -246,12 +325,19 @@ class LogoGame:
self.sql_player.commit()
def playerstats_get(self, key):
self.cur_execute.execute('SELECT * FROM stats WHERE key=?', [key])
f = cur.fetchone()
self.cur_player.execute('SELECT * FROM stats WHERE key=?', [key])
f = self.cur_player.fetchone()
if f:
return f[1]
return None
def playerstats_hassolved(self, logoid):
key = 'hassolved_%d' % logoid
val = self.playerstats_get(key)
if val is None:
return False
return True
def strip_to_filename(self, s):
for badchar in self.WINDOWS_BADCHARS:
s = s.replace(badchar, '')
@ -266,6 +352,7 @@ class LogoGame:
itemtags = itemtags.replace(', ', ',')
itemtags = itemtags.split(',')
alltags += itemtags
alltags = list(set(alltags))
alltags.sort()
return alltags

View file

@ -4,9 +4,13 @@ from PIL import ImageTk
t=tkinter.Tk()
def png(filename):
im = Image.open('images/%s.png' % filename)
im = ImageTk.PhotoImage(im)
return im
im = Image.open('images/swirl_00.png')
im = ImageTk.PhotoImage(im)
im = png('jarate')
l = tkinter.Label(t, text="heyo", image=im)
l.im = im
l.pack()