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

Commit 14b7fcf

Browse files
committed
Changed Window to use View class
1 parent 33fb0f5 commit 14b7fcf

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/view.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import tkinter as tk
22
from typing import TypeVar
33
from enum import Enum
4+
from dataclasses import dataclass
45

56
from . import widget
6-
from .animate import Coord, Animater
7+
from .animate import Coord, Animater, Direction
78
from .cache import ImageTk
89

910

@@ -32,54 +33,56 @@ def init(self):
3233
def __coord(self, id):
3334
return Coord(*self.coords(id)[:2])
3435

35-
def __set_image(self, view: ImageTk.PhotoImage, coord: Coord):
36+
def __set_image(self, image: ImageTk.PhotoImage, coord: Coord):
3637
return self.create_image(
3738
coord, image=view, anchor='nw'
3839
)
3940

40-
def __set_widget(self, view: tk.Widget, coord: Coord):
41+
def __set_widget(self, widget: tk.Widget, coord: Coord):
4142
return self.create_window(
4243
coord, window=view, anchor='nw'
4344
)
4445

45-
def __set(self, view, coord, viewtype):
46-
if viewtype == 'image':
47-
wid = self.__set_image(view, coord)
46+
def __set(self, view: View, coord: Coord):
47+
if view.viewtype == ViewType.IMAGE:
48+
wid = self.__set_image(view.data, coord)
49+
elif view.viewtype == ViewType.WIDGET:
50+
wid = self.__set_widget(view.data, coord)
4851
else:
49-
wid = self.__set_widget(view, coord)
52+
raise NotImplementedError
5053
self.views[view] = wid
5154
return wid
5255

53-
def set_view(self, view: tk.Widget, viewtype='image'):
56+
def set_view(self, view: View):
5457
self.current = view
55-
self.__set(self.current, self.origin, viewtype)
58+
self.__set(self.current, self.origin)
5659

57-
def move_view(self, wid, end):
60+
def move_view(self, view: View, end: Coord):
61+
wid = self.views[view]
5862
self.animater.add_motion(
5963
wid, end, speed=self.animation_speed
6064
)
6165

62-
def move_in(self, view, direction: Direction, viewtype='image'):
66+
def move_in(self, view: View, direction: Direction):
6367
distance = self.get_distance(direction)
6468
start = self.origin + distance
6569
wid = self.__set(view, start, viewtype)
66-
self.move_view(wid, self.origin)
70+
self.move_view(view, self.origin)
6771
return wid
6872

69-
def move_out(self, view, direction, viewtype='image'):
70-
wid = self.views[view]
73+
def move_out(self, view: View, direction: Direction):
7174
distance = self.get_distance(direction)
7275
end = self.origin + distance
73-
self.move_view(wid, end)
76+
self.move_view(view, end)
7477
del self.views[view]
7578

76-
def change_view(self, view: tk.Widget, direction: Direction, viewtype='image'):
79+
def change_view(self, view: View, direction: Direction):
7780
if not isinstance(direction, Direction):
7881
direction = Direction[direction.upper()] # Cast string for convenience
7982
self.animater.clear()
8083

81-
self.move_out(self.current, direction, viewtype=viewtype)
82-
self.move_in(view, direction.flip(), viewtype=viewtype)
84+
self.move_out(self.current, direction)
85+
self.move_in(view, direction.flip())
8386

8487
self.animater.start()
8588
self.current = view

0 commit comments

Comments
 (0)