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

Commit 3344136

Browse files
committed
ViewTypes implemented
1 parent 14b7fcf commit 3344136

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/front.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from . import widget
44
from .animate import Direction
5-
from .view import Window
5+
from .view import Window, View
66
from .cache import Cache
77

88

@@ -27,21 +27,21 @@ def __next(self):
2727

2828
def __load(self, name, image, data):
2929
self.title.config(text=name)
30-
self.bio.load(data)
30+
self.bio.data.load(data)
3131
self._last = self.image
32-
self.image = image
32+
self.image = View(image, 'image')
3333
self.update()
3434

3535
def __change_image(self, direction: Direction):
3636
self.__next()
37-
self.window.change_view(self.image, direction, viewtype='image')
37+
self.window.change_view(self.image, direction)
3838

3939
def init(self):
4040
self.title = widget.PrimaryLabel(self)
4141
self.window = Window(self)
4242
self.commandbar = widget.SecondaryFrame(self)
4343

44-
self.bio = Bio(self.window)
44+
self.bio = View(Bio(self.window), 'widget')
4545
self.image = None
4646

4747
self.btn_dislike = widget.PrimaryButton(
@@ -66,14 +66,16 @@ def init(self):
6666
self.cache
6767

6868
def cmd_dislike(self):
69-
self.__change_image('LEFT')
69+
self.__change_image('right')
7070

7171
def cmd_like(self):
72-
self.__change_image('RIGHT')
72+
self.__change_image('left')
7373

7474
def cmd_bio(self):
75-
self.window.move_out(self.image, 'UP', 'image')
76-
self.window.move
75+
if self.window.current != self.bio:
76+
self.window.change_view(self.bio, 'up')
77+
else:
78+
self.window.change_view(self.image, 'down')
7779

7880
@property
7981
def cache(self):
@@ -106,6 +108,7 @@ def __make_item(self, name, value):
106108
return item
107109

108110
def load(self, data: dict):
111+
print(data)
109112
for name, val in data.items():
110113
item = self.__make_item(name, val)
111114
item.pack()

src/view.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ class ViewType(Enum):
1616
T = TypeVar('T', ImageTk.PhotoImage, tk.Widget)
1717

1818

19-
@dataclass
2019
class View:
21-
data: T
22-
viewtype: ViewType
20+
21+
def __init__(self, data: T, viewtype: ViewType):
22+
self.data = data
23+
if not isinstance(viewtype, ViewType):
24+
viewtype = ViewType(viewtype.upper()) # Breaks if not string
25+
self.viewtype = viewtype
2326

2427

2528
class Window(widget.PrimaryCanvas):
@@ -35,12 +38,12 @@ def __coord(self, id):
3538

3639
def __set_image(self, image: ImageTk.PhotoImage, coord: Coord):
3740
return self.create_image(
38-
coord, image=view, anchor='nw'
41+
coord, image=image, anchor='nw'
3942
)
4043

4144
def __set_widget(self, widget: tk.Widget, coord: Coord):
4245
return self.create_window(
43-
coord, window=view, anchor='nw'
46+
coord, window=widget, anchor='nw'
4447
)
4548

4649
def __set(self, view: View, coord: Coord):
@@ -66,7 +69,7 @@ def move_view(self, view: View, end: Coord):
6669
def move_in(self, view: View, direction: Direction):
6770
distance = self.get_distance(direction)
6871
start = self.origin + distance
69-
wid = self.__set(view, start, viewtype)
72+
wid = self.__set(view, start)
7073
self.move_view(view, self.origin)
7174
return wid
7275

0 commit comments

Comments
 (0)