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

Commit 7557cff

Browse files
committed
Image positioning
1 parent 9b42961 commit 7557cff

File tree

4 files changed

+37
-28
lines changed

4 files changed

+37
-28
lines changed

src/animate.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def __eq__(self):
235235

236236

237237
class Window(widget.PrimaryCanvas):
238-
animation_speed = 2
238+
animation_speed = 3
239239
_current = None
240240

241241
def init(self):
@@ -249,25 +249,29 @@ def clear(self):
249249
self.delete(self._current)
250250
self.update()
251251

252+
def __set(self, view: tk.Widget, coord: Coord):
253+
return self.create_window(
254+
coord, window=view, anchor='nw'
255+
)
256+
252257
def set_view(self, view: tk.Widget):
253258
self.clear()
254-
self._current = self.create_window(self.origin, window=view)
259+
self._current = self.__set(view, self.origin)
255260

256261
def change_view(self, view: tk.Widget, direction: Direction):
257262
if not isinstance(direction, Direction):
258263
direction = Direction[direction.upper()] # Cast string for convenience
259264

260265
if direction in (Direction.UP, Direction.DOWN):
261-
edge = self.winfo_screenheight()
266+
dist = self.winfo_height()
262267
elif direction in (Direction.LEFT, Direction.RIGHT):
263-
edge = self.winfo_screenwidth()
268+
dist = self.winfo_width()
264269
else:
265270
raise NotImplementedError
266-
267-
pos = self.__coord(self._current)
268-
end = pos + edge
269-
beg = pos - edge
270-
wid = self.create_window(beg, window=view)
271+
edge = direction * dist
272+
end = self.origin + edge
273+
beg = self.origin - edge
274+
wid = self.__set(view, beg)
271275

272276
self.animater.clear()
273277
self.animater.add_motion(self._current, end, speed=self.animation_speed)
@@ -278,4 +282,4 @@ def change_view(self, view: tk.Widget, direction: Direction):
278282

279283
@property
280284
def origin(self):
281-
return Coord(0, 0)
285+
return Coord(self.winfo_x(), self.winfo_y())

src/front.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1+
import asyncio
2+
13
from . import widget
24
from .animate import Window, Direction
5+
from .cache import Cache
36

47

58
class Front(widget.PrimaryFrame):
69

7-
_cache: list = None
10+
cachesize = 10
811

912
def __next(self):
1013
data: dict = self.cache.pop()
1114
data.pop('jumpscare') # not using it for now
12-
name = data.pop('name')
15+
if 'name' in data: # TODO Fix
16+
name = data.pop('name')
17+
else:
18+
name = 'None'
1319
image = data.pop('image')
1420
self.__load(name, image, data)
1521

@@ -49,6 +55,9 @@ def init(self):
4955
self.btn_dislike.pack(side='left')
5056
self.btn_like.pack(side='right')
5157

58+
self._loop = asyncio.get_event_loop()
59+
self.cache = Cache(self.window)
60+
5261
def cmd_dislike(self):
5362
self.__change_image('LEFT')
5463

@@ -60,9 +69,9 @@ def cmd_bio(self):
6069

6170
@property
6271
def cache(self):
63-
if self._cache is None:
64-
return AttributeError('cache has not been set.')
65-
return self._cache
72+
if len(self._cache.cats) < self.cachesize:
73+
self._loop.run_until_complete(self._cache.refill())
74+
return self._cache.cats
6675

6776
@cache.setter
6877
def cache(self, data: list):

src/main.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,13 @@ def __init__(self, *args, **kwds):
2222
self.title = title
2323
mixer.init()
2424

25-
self.loop = asyncio.get_event_loop()
26-
self.cache = Cache(self)
27-
2825
self.geometry = '400x500'
2926
self.minsize(400, 500)
3027
self.maxsize(400, 500)
3128

3229
self.front = Front(self)
33-
self.front.pack(fill='both', expand=True)
3430

35-
self.__cache()
36-
self.front.cache = self.cache.cats
37-
38-
def __cache(self):
39-
self.loop.run_until_complete(self.cache.refill())
31+
self.front.pack(fill='both', expand=True)
4032

4133

4234
class Tinder:
@@ -62,8 +54,8 @@ def __init__(self):
6254
self.root = tk.Tk()
6355
self.root.title(self.config['main.title'])
6456
self.root.geometry(self.config['main.geometry'])
65-
self.root.minsize(400, 500)
66-
self.root.maxsize(400, 500)
57+
self.root.minsize(1000, 1000)
58+
self.root.maxsize(1000, 1000)
6759
self.root.configure(background=self.config['main.background'])
6860
# self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
6961

src/widget.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ def __init__(self, *args, **kwds):
7373

7474

7575
class PrimaryLabel(tk.Label):
76-
DEFAULT = {}
76+
DEFAULT = {
77+
'font': ('Courier', 17)
78+
}
7779

7880
def __init__(self, *args, **kwds):
7981
self.DEFAULT.update(kwds)
@@ -83,7 +85,9 @@ def __init__(self, *args, **kwds):
8385

8486

8587
class PrimaryCanvas(tk.Canvas):
86-
DEFAULT = {}
88+
DEFAULT = {
89+
'bg': 'black'
90+
}
8791

8892
def __init__(self, *args, **kwds):
8993
self.DEFAULT.update(kwds)

0 commit comments

Comments
 (0)