Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

view-zoom #60

Merged
merged 9 commits into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -9,6 +9,4 @@ boards.txt
server/mongo_data
.vscode
venv
boards.txt
=======
.coverage
6 changes: 3 additions & 3 deletions src/internal/models/position.py
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@

@dataclasses.dataclass
class Position:
x: int
y: int
z: int
x: float
y: float
z: float

def __add__(self, other: Position):
return Position(self.x + other.x, self.y + other.y, self.z + other.z)
1 change: 1 addition & 0 deletions src/internal/view/dependencies.py
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ class Dependencies:
canvas: tkinter.Canvas
property_bar: tkinter.ttk.Frame
menu: internal.view.menu.impl.menu.Menu
scaler: float
objects_storage: internal.view.objects.interfaces.IViewObjectStorage
state_machine: internal.view.state_machine.interfaces.IStateMachine
controller: internal.controller.interfaces.IController
84 changes: 47 additions & 37 deletions src/internal/view/modules/card/card_view.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import tkinter.ttk
from typing import List, Callable

import internal.models
import internal.objects.interfaces
import internal.objects.events
import internal.repositories.interfaces
@@ -91,11 +92,13 @@ def adjust_font(self, dependencies: internal.view.dependencies.Dependencies, lar

def _update_coord_from_repo(self, dependencies: internal.view.dependencies.Dependencies):
obj: internal.objects.interfaces.IBoardObjectCard = dependencies.repo.get(self.id)
x = obj.position.x
y = obj.position.y
dependencies.canvas.coords(self.note_id, x, y, x + obj.width, y + obj.height)
dependencies.canvas.coords(self.text_id, x + obj.width / 2, y + obj.height / 2)
dependencies.canvas.itemconfigure(self.text_id, width=obj.width)
x = obj.position.x * dependencies.scaler
y = obj.position.y * dependencies.scaler
width = int(obj.width * dependencies.scaler)
height = int(obj.height * dependencies.scaler)
dependencies.canvas.coords(self.note_id, x, y, x + width, y + height)
dependencies.canvas.coords(self.text_id, x + width / 2, y + height / 2)
dependencies.canvas.itemconfigure(self.text_id, width=width)

def _subscribe_to_repo_object_events(
self, dependencies: internal.view.dependencies.Dependencies
@@ -235,12 +238,12 @@ def _base_widget(
return label, combobox

def _attribute_widget(self,
dependencies: internal.view.dependencies.Dependencies,
obj_id: internal.objects.interfaces.ObjectId,
description: str,
getter: Callable,
setter: Callable
) -> List[tkinter.ttk.Widget]:
dependencies: internal.view.dependencies.Dependencies,
obj_id: internal.objects.interfaces.ObjectId,
description: str,
getter: Callable,
setter: Callable
) -> List[tkinter.ttk.Widget]:
string_var = tkinter.StringVar(value=getter(dependencies, obj_id, description))
label = tkinter.ttk.Label(
dependencies.property_bar,
@@ -262,8 +265,11 @@ def move_to(self, dependencies: internal.view.dependencies.Dependencies, x: int,
self._update_coord_from_repo(dependencies)

def _get_font_update_from_repo(self, dependencies: internal.view.dependencies.Dependencies):
obj: internal.objects.interfaces.IBoardObjectCard = dependencies.repo.get(self.id)
font = obj.font
obj: internal.objects.interfaces.IBoardObjectText = dependencies.repo.get(self.id)
font = internal.models.Font(
obj.font.slant, obj.font.weight, obj.font.color, obj.font.family,
obj.font.size * dependencies.scaler
)
tk_font = internal.view.utils.as_tkinter_object_font(font)
dependencies.canvas.itemconfigure(self.text_id, font=tk_font)
dependencies.canvas.itemconfigure(self.text_id, fill=font.color)
@@ -284,10 +290,17 @@ def _get_color_update_from_repo(self, dependencies: internal.view.dependencies.D
def _get_size_update_from_repo(self, dependencies: internal.view.dependencies.Dependencies):
self._update_coord_from_repo(dependencies)

def _get_font(self, dependencies: internal.view.dependencies.Dependencies):
font = dependencies.canvas.itemcget(self.text_id, 'font')
color = dependencies.canvas.itemcget(self.text_id, 'fill')
return internal.view.utils.as_object_font(font, color)
def _get_font(
self, dependencies: internal.view.dependencies.Dependencies, scaled=False
):
obj: internal.objects.interfaces.IBoardObjectText = dependencies.repo.get(self.id)
font = internal.models.Font(
obj.font.slant, obj.font.weight, obj.font.color, obj.font.family,
obj.font.size * dependencies.scaler
)
if not scaled:
font.size /= dependencies.scaler
return font

def _get_font_slant(self, dependencies: internal.view.dependencies.Dependencies):
return self._get_font(dependencies).slant
@@ -329,26 +342,18 @@ def _set_font_color(self, dependencies: internal.view.dependencies.Dependencies,
font.color = color
dependencies.controller.edit_font(self.id, font=font)

def _get_font_size(self, dependencies: internal.view.dependencies.Dependencies):
return self._get_font(dependencies).size

def _set_font_size(self, dependencies: internal.view.dependencies.Dependencies, size: str):
font = self._get_font(dependencies)
font.size = int(size)
dependencies.controller.edit_font(self.id, font=font)

def _get_card_color(self, dependencies: internal.view.dependencies.Dependencies):
return dependencies.canvas.itemcget(self.note_id, 'fill')

def _set_card_color(self, dependencies: internal.view.dependencies.Dependencies, color: str):
dependencies.controller.edit_color(self.id, color=color)

def _get_card_size(self, dependencies: internal.view.dependencies.Dependencies):
x1, y1, x2, y2 = dependencies.canvas.coords(self.note_id)
obj: internal.objects.interfaces.IBoardObjectCard = dependencies.repo.get(self.id)
# TODO: move size names to consts
if abs(y2 - y1) <= _DEFAULT_SMALL_SIZE:
if abs(obj.width) <= _DEFAULT_SMALL_SIZE:
return 'Small'
elif abs(y2 - y1) <= _DEFAULT_MEDIUM_SIZE:
elif abs(obj.width) <= _DEFAULT_MEDIUM_SIZE:
return 'Medium'
else:
return 'Large'
@@ -361,19 +366,24 @@ def _set_card_size(self, dependencies: internal.view.dependencies.Dependencies,
else:
dependencies.controller.edit_size(self.id, _DEFAULT_LARGE_SIZE, _DEFAULT_LARGE_SIZE)

def _get_attribute(self,
dependencies: internal.view.dependencies.Dependencies,
obj_id: internal.objects.interfaces.ObjectId,
attr_name: str
def scale(self, dependencies: internal.view.dependencies.Dependencies):
self._get_font_update_from_repo(dependencies)

def _get_attribute(
self,
dependencies: internal.view.dependencies.Dependencies,
obj_id: internal.objects.interfaces.ObjectId,
attr_name: str
):
card: internal.objects.interfaces.IBoardObjectCard = dependencies.repo.get(obj_id)
return card.attribute[attr_name]

def _set_attribute(self,
dependencies: internal.view.dependencies.Dependencies,
obj_id: internal.objects.interfaces.ObjectId,
attr_name: str,
value: str
def _set_attribute(
self,
dependencies: internal.view.dependencies.Dependencies,
obj_id: internal.objects.interfaces.ObjectId,
attr_name: str,
value: str
):
dependencies.controller.edit_attribute(obj_id, attr_name, value)

4 changes: 2 additions & 2 deletions src/internal/view/modules/card/states/create_card.py
Original file line number Diff line number Diff line change
@@ -22,8 +22,8 @@ def _predicate_from_root_to_create_text(
if global_dependencies.menu.current_state != CARD_MENU_ENTRY_NAME:
return False

actual_x = int(global_dependencies.canvas.canvasx(event.x))
actual_y = int(global_dependencies.canvas.canvasy(event.y))
actual_x = global_dependencies.canvas.canvasx(event.x)
actual_y = global_dependencies.canvas.canvasy(event.y)

global_dependencies.controller.create_object(
internal.objects.BoardObjectType.CARD,
3 changes: 2 additions & 1 deletion src/internal/view/modules/connector/connector_view.py
Original file line number Diff line number Diff line change
@@ -372,7 +372,8 @@ def set_color(self, dependencies: internal.view.dependencies.Dependencies, color
dependencies.controller.edit_color(self.id, color=color)

def get_width(self, dependencies: internal.view.dependencies.Dependencies):
return int(float(dependencies.canvas.itemcget(self.line_id, 'width')))
obj: internal.objects.interfaces.IBoardObjectConnector = dependencies.repo.get(self.id)
return obj.width

def set_width(self, dependencies: internal.view.dependencies.Dependencies, width: int):
dependencies.controller.edit_width(self.id, width=width)
Original file line number Diff line number Diff line change
@@ -27,8 +27,8 @@ def _on_enter(
global_dependencies
)
state_ctx[_START_ID] = cur_obj.id
x = int(global_dependencies.canvas.canvasx(event.x))
y = int(global_dependencies.canvas.canvasy(event.y))
x = global_dependencies.canvas.canvasx(event.x)
y = global_dependencies.canvas.canvasy(event.y)
# TODO: the project should have default configs like WIDTH of line
# We create pseudo-line, then on leave we delete this line and create line from repo
state_ctx[_CURRENT_CONNECTOR_ID] = global_dependencies.canvas.create_line(
4 changes: 2 additions & 2 deletions src/internal/view/modules/group/states/create_group.py
Original file line number Diff line number Diff line change
@@ -28,8 +28,8 @@ def _get_cur_pos(
global_dependencies: internal.view.dependencies.Dependencies,
event: tkinter.Event
) -> internal.view.utils.geometry.ScreenPosition:
cur_pos_x = int(global_dependencies.canvas.canvasx(event.x))
cur_pos_y = int(global_dependencies.canvas.canvasy(event.y))
cur_pos_x = global_dependencies.canvas.canvasx(event.x)
cur_pos_y = global_dependencies.canvas.canvasy(event.y)
return internal.view.utils.geometry.ScreenPosition(cur_pos_x, cur_pos_y)


Original file line number Diff line number Diff line change
@@ -27,8 +27,8 @@ def _on_enter(
state_ctx: Dict,
event: tkinter.Event
):
x = int(global_dependencies.canvas.canvasx(event.x))
y = int(global_dependencies.canvas.canvasy(event.y))
x = global_dependencies.canvas.canvasx(event.x)
y = global_dependencies.canvas.canvasy(event.y)

obj: Optional[IViewObject] = global_dependencies.objects_storage.get_current_opt(
global_dependencies
@@ -56,9 +56,10 @@ def _on_leave(
event: tkinter.Event
):
# TODO: Z-Coordinate
scaler = global_dependencies.scaler
diff: Position = Position(
state_ctx[_LAST_DRAG_EVENT_X] - state_ctx[_FIRST_DRAG_EVENT_X],
state_ctx[_LAST_DRAG_EVENT_Y] - state_ctx[_FIRST_DRAG_EVENT_Y],
(state_ctx[_LAST_DRAG_EVENT_X] - state_ctx[_FIRST_DRAG_EVENT_X]) / scaler,
(state_ctx[_LAST_DRAG_EVENT_Y] - state_ctx[_FIRST_DRAG_EVENT_Y]) / scaler,
0
)
# TODO: we send difference, if 2 people uses it collapse
@@ -107,8 +108,8 @@ def _handle_event(
logging.warning('move object not found')
return
obj.aligning(dependencies=global_dependencies)
x = int(global_dependencies.canvas.canvasx(event.x))
y = int(global_dependencies.canvas.canvasy(event.y))
x = global_dependencies.canvas.canvasx(event.x)
y = global_dependencies.canvas.canvasy(event.y)
global_dependencies.canvas.move(
state_ctx[_OBJ_ID],
x - state_ctx[_LAST_DRAG_EVENT_X],
13 changes: 7 additions & 6 deletions src/internal/view/modules/pen/pen_view.py
Original file line number Diff line number Diff line change
@@ -45,8 +45,8 @@ def _get_canvas_points_from_repo_object(
obj: internal.objects.interfaces.IBoardObjectPen = dependencies.repo.get(self.id)
points = []
for position in obj.points:
points.append(position.x)
points.append(position.y)
points.append(position.x * dependencies.scaler)
points.append(position.y * dependencies.scaler)
return points

def _subscribe_to_repo_object_events(
@@ -92,7 +92,7 @@ def _get_color_update_from_repo(self, dependencies: internal.view.dependencies.D

def _get_width_update_from_repo(self, dependencies: internal.view.dependencies.Dependencies):
obj: internal.objects.interfaces.IBoardObjectPen = dependencies.repo.get(self.id)
dependencies.canvas.itemconfigure(self.line_id, width=obj.width)
dependencies.canvas.itemconfigure(self.line_id, width=int(obj.width * dependencies.scaler))

def widgets(
self, dependencies: internal.view.dependencies.Dependencies
@@ -151,10 +151,11 @@ def _set_color(self, dependencies: internal.view.dependencies.Dependencies, colo
dependencies.controller.edit_color(self.id, color=color)

def _get_width(self, dependencies: internal.view.dependencies.Dependencies) -> int:
return int(float(dependencies.canvas.itemcget(self.line_id, 'width')))
obj: internal.objects.interfaces.IBoardObjectPen = dependencies.repo.get(self.id)
return obj.width

def _set_width(self, dependencies: internal.view.dependencies.Dependencies, width: int):
dependencies.controller.edit_width(self.id, width=width)
def _set_width(self, dependencies: internal.view.dependencies.Dependencies, width: str):
dependencies.controller.edit_width(self.id, width=int(width))

def destroy(self, dependencies: internal.view.dependencies.Dependencies):
self._unsubscribe_from_repo_object_events(dependencies)
17 changes: 9 additions & 8 deletions src/internal/view/modules/pen/states/create_line.py
Original file line number Diff line number Diff line change
@@ -13,11 +13,12 @@
_CURRENT_LINE_ID = 'line_id'


def _from_canvas_coord_to_object_points(points: list[int]):
def _from_canvas_coord_to_object_points(points: list[int], scaler: float):
positions = []
# TODO: Z-coordinate
for i in range(1, len(points), 2):
positions.append(internal.models.Position(points[i - 1], points[i], 1))
positions.append(
internal.models.Position(points[i - 1] / scaler, points[i] / scaler, 1))
return positions


@@ -26,8 +27,8 @@ def _on_enter(
state_ctx: Dict,
event: tkinter.Event,
):
x = int(global_dependencies.canvas.canvasx(event.x))
y = int(global_dependencies.canvas.canvasy(event.y))
x = global_dependencies.canvas.canvasx(event.x)
y = global_dependencies.canvas.canvasy(event.y)
# TODO: the project should have default configs like WIDTH of line
# We create pseudo-line, then on leave we delete this line and create line from repo
state_ctx[_CURRENT_LINE_ID] = global_dependencies.canvas.create_line(
@@ -49,8 +50,8 @@ def _handle_event(
return
if _CURRENT_LINE_ID not in state_ctx:
return
actual_x = int(global_dependencies.canvas.canvasx(event.x))
actual_y = int(global_dependencies.canvas.canvasy(event.y))
actual_x = global_dependencies.canvas.canvasx(event.x)
actual_y = global_dependencies.canvas.canvasy(event.y)
coord = global_dependencies.canvas.coords(state_ctx[_CURRENT_LINE_ID])
coord.append(actual_x)
coord.append(actual_y)
@@ -65,7 +66,7 @@ def _on_leave(
if _CURRENT_LINE_ID not in state_ctx:
return
points = global_dependencies.canvas.coords(state_ctx[_CURRENT_LINE_ID])
positions = _from_canvas_coord_to_object_points(points)
positions = _from_canvas_coord_to_object_points(points, global_dependencies.scaler)
global_dependencies.controller.create_object(
internal.objects.BoardObjectType.PEN, points=positions
)
@@ -102,4 +103,4 @@ def create_state(state_machine: internal.view.state_machine.interfaces.IStateMac
internal.view.state_machine.interfaces.ROOT_STATE_NAME,
_predicate_from_pen_to_root,
)
return state
return state
4 changes: 2 additions & 2 deletions src/internal/view/modules/table/states/create_table.py
Original file line number Diff line number Diff line change
@@ -27,8 +27,8 @@ def _on_enter(
state_ctx: Dict,
event: tkinter.Event
):
actual_x = int(global_dependencies.canvas.canvasx(event.x))
actual_y = int(global_dependencies.canvas.canvasy(event.y))
actual_x = global_dependencies.canvas.canvasx(event.x)
actual_y = global_dependencies.canvas.canvasy(event.y)

global_dependencies.controller.create_object(
internal.objects.BoardObjectType.TABLE,
4 changes: 2 additions & 2 deletions src/internal/view/modules/text/states/create_text.py
Original file line number Diff line number Diff line change
@@ -22,8 +22,8 @@ def _predicate_from_root_to_create_text(
if global_dependencies.menu.current_state != TEXT_MENU_ENTRY_NAME:
return False

actual_x = int(global_dependencies.canvas.canvasx(event.x))
actual_y = int(global_dependencies.canvas.canvasy(event.y))
actual_x = global_dependencies.canvas.canvasx(event.x)
actual_y = global_dependencies.canvas.canvasy(event.y)

global_dependencies.controller.create_object(
internal.objects.BoardObjectType.TEXT,
Loading