1+ import configparser
12import tkinter as tk
23import asyncio
34from pygame import mixer
5+ import os
46from cache import Cache
57
6-
78class 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
225242if __name__ == "__main__" :
226243 # start the application
227- Tinder ().start ()
244+ Tinder ().start ()
0 commit comments