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

Commit b291be7

Browse files
committed
Fixing config file
1 parent 71d07b0 commit b291be7

File tree

4 files changed

+82
-20
lines changed

4 files changed

+82
-20
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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,36 @@
33
from PIL import Image, ImageTk
44
import os
55
import io
6-
6+
import configparser
77

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

11-
def __init__(self):
1217
# setting class variables for use later
1318
self.cats = list()
1419
self.session = None
1520

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

1937
async def refill(self):
2038
'''Gets a cache of cat data and adds it to the self.cats list'''
@@ -23,8 +41,10 @@ async def refill(self):
2341
if not self.session:
2442
self.session = aiohttp.ClientSession()
2543

44+
cachesize = int(self.config['cachesize'])
45+
2646
# Run 10 times to get 10 cats
27-
for i in range(10):
47+
for i in range(cachesize):
2848
# initialize a dict of cat data
2949
cat_data = dict()
3050

src/mainwindow.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
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

6-
78
class Tinder:
89
'''The main class for the application.'''
910

1011
def __init__(self):
1112
# setup for pygame mixer
1213
mixer.init()
1314

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

2337
# getting screen width and height for use with teleporting window/jumpscare
2438
self.screen_x = self.root.winfo_screenwidth()
2539
self.screen_y = self.root.winfo_screenheight()
2640

2741
# setting class variables to be used later
28-
self.cache = Cache()
2942
self.jumpscare = False
3043
self.loop = asyncio.get_event_loop()
44+
self.cache = Cache(self.root)
3145

3246
def start(self):
3347
'''Starts the Tinder application'''
@@ -38,6 +52,7 @@ def start(self):
3852
# starting the program loop
3953
self.new_image()
4054

55+
4156
def all_children(self):
4257
'''Used to get all children of the root window
4358
@@ -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
@@ -224,4 +241,4 @@ def on_closing(self):
224241
# checks if this file is the main file being run
225242
if __name__ == "__main__":
226243
# start the application
227-
Tinder().start()
244+
Tinder().start()

0 commit comments

Comments
 (0)