Skip to content
This repository was archived by the owner on Mar 31, 2020. It is now read-only.

Commit 8842847

Browse files
authored
Merge pull request #6 from Zer0897/main-tinder-test
Made use of config file
2 parents 20ef91f + 426fe28 commit 8842847

File tree

4 files changed

+80
-17
lines changed

4 files changed

+80
-17
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pytest = "*"
1111
pillow = "*"
1212
pygame = "*"
1313
aiohttp = "*"
14+
configparser = "*"
1415

1516
[requires]
1617
python_version = "3.7"

Pipfile.lock

Lines changed: 25 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cache.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,37 @@
33
from PIL import Image, ImageTk
44
import os
55
import io
6+
import configparser
67

78

89
class Cache:
9-
'''Class used for caching images and data about the cats.'''
10+
'''Class used for caching images and data about the cats'''
11+
12+
def __init__(self, root):
13+
# setting root
14+
self.root = root
15+
self.screen_x = self.root.winfo_screenwidth()
16+
self.screen_y = self.root.winfo_screenheight()
1017

11-
def __init__(self):
1218
# setting class variables for use later
1319
self.cats = list()
1420
self.session = None
1521

16-
# getting the directory folder for use later when opening files
22+
# get settings
1723
self.dir = os.path.dirname(os.path.realpath(__file__))
24+
cp = configparser.ConfigParser()
25+
cp.read(os.path.join(self.dir, 'settings.ini'))
26+
cp.read('settings.ini')
27+
28+
# for now, let's just look up the DEV settings
29+
# can change this later
30+
# configparser will use values from DEFAULT section if none provided elsewhere
31+
if 'DEV' in cp.sections():
32+
self.config = cp['DEV']
33+
else:
34+
self.config = cp['DEFAULT']
35+
36+
# getting the directory folder for use later when opening files
1837

1938
async def refill(self):
2039
'''Gets a cache of cat data and adds it to the self.cats list'''
@@ -23,8 +42,10 @@ async def refill(self):
2342
if not self.session:
2443
self.session = aiohttp.ClientSession()
2544

45+
cachesize = int(self.config['cachesize'])
46+
2647
# Run 10 times to get 10 cats
27-
for i in range(10):
48+
for i in range(cachesize):
2849
# initialize a dict of cat data
2950
cat_data = dict()
3051

src/mainwindow.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import configparser
12
import tkinter as tk
23
import asyncio
34
from pygame import mixer
5+
import os
46
from cache import Cache
57

68

@@ -11,23 +13,36 @@ def __init__(self):
1113
# setup for pygame mixer
1214
mixer.init()
1315

16+
# get settings
17+
self.dir = os.path.dirname(os.path.realpath(__file__))
18+
cp = configparser.ConfigParser()
19+
cp.read(os.path.join(self.dir, 'settings.ini'))
20+
21+
# for now, let's just look up the DEV settings
22+
# can change this later
23+
# configparser will use values from DEFAULT section if none provided elsewhere
24+
if 'DEV' in cp.sections():
25+
self.config = cp['DEV']
26+
else:
27+
self.config = cp['DEFAULT']
28+
1429
# setting up the tkinter root
1530
self.root = tk.Tk()
16-
self.root.title("Cat Tinder")
17-
self.root.geometry("400x500")
31+
self.root.title(self.config['main.title'])
32+
self.root.geometry(self.config['main.geometry'])
1833
self.root.minsize(400, 500)
1934
self.root.maxsize(400, 500)
20-
self.root.configure(background='black')
35+
self.root.configure(background=self.config['main.background'])
2136
self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
2237

2338
# getting screen width and height for use with teleporting window/jumpscare
2439
self.screen_x = self.root.winfo_screenwidth()
2540
self.screen_y = self.root.winfo_screenheight()
2641

2742
# setting class variables to be used later
28-
self.cache = Cache()
2943
self.jumpscare = False
3044
self.loop = asyncio.get_event_loop()
45+
self.cache = Cache(self.root)
3146

3247
def start(self):
3348
'''Starts the Tinder application'''
@@ -63,7 +78,6 @@ def new_image(self, cat=None):
6378

6479
# if the previous image was a jumpscare, resize the window and reset the variable
6580
if self.jumpscare:
66-
self.root.geometry()
6781
self.root.maxsize(400, 500)
6882
self.jumpscare = False
6983

@@ -134,17 +148,17 @@ def new_image(self, cat=None):
134148
# make a button to allow the user to pass through the image
135149
# Note: since everyone likes scary monsters, only make a Like button
136150
tk.Button(
137-
self.frame, text="Like", background="green",
151+
self.frame, text=self.config['like.text'], background="green",
138152
command=self.new_image).pack(side=tk.BOTTOM)
139153

140154
# image was not a jumpscare, don't do jumpscare things
141155
else:
142156
# setting up like and dislike buttons on opposite sides of the screen
143157
tk.Button(
144-
self.frame, text="Like", background="green",
158+
self.frame, text=self.config['like.text'], background="green",
145159
command=self.new_image).pack(side=tk.RIGHT)
146160
tk.Button(
147-
self.frame, text="Dislike", background="red",
161+
self.frame, text=self.config['dislike.text'], background="red",
148162
command=self.new_image).pack(side=tk.LEFT)
149163

150164
# defining button functions
@@ -183,21 +197,24 @@ def get_bio():
183197

184198
# setting up like/dislike/Back to Photo buttons on the bio screen
185199
tk.Button(
186-
self.frame, text="Like", background="green",
200+
self.frame, text=self.config['like.text'],
201+
background=self.config['like.background'],
187202
command=self.new_image).pack(side=tk.RIGHT)
188203
tk.Button(
189-
self.frame, text="Dislike", background="red",
204+
self.frame, text=self.config['dislike.text'],
205+
background=self.config['dislike.background'],
190206
command=self.new_image).pack(side=tk.LEFT)
191207
tk.Button(
192-
self.root, text="Back To Photo", background="blue",
208+
self.root, text=self.config['back.text'],
209+
background=self.config['back.background'],
193210
command=back_to_photo).pack(side=tk.BOTTOM)
194211

195212
# packing the frame
196213
self.frame.pack()
197214

198215
# making and packing the Bio button for users to look at the cat's bio
199216
tk.Button(
200-
self.frame, text="Bio", background="blue",
217+
self.frame, text=self.config['bio.text'], background=self.config['bio.background'],
201218
command=get_bio).pack(side=tk.BOTTOM)
202219

203220
# packing the frame

0 commit comments

Comments
 (0)