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

bump pyqt6 to 6.7.1 #60

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 2 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme = 'README.md'
requires-python = '>=3.11'
dependencies = [
'adaptix==3.0.0b8',
'PyQt6==6.5.0',
'PyQt6==6.7.1',
'dishka==1.4.0',
'tomli-w==1.1.0',
]
Expand Down Expand Up @@ -82,15 +82,8 @@ ignore = [
'PLR0912',
'C901',
# Not applicable for now
'FIX002',
'TD003',
'TD002',
'ARG001',
'FBT002',
'PGH003',
'ERA001',
'FBT001',
'N802',
'PGH003',
# Does not work correctly
'TC002',
'TC001',
Expand Down
6 changes: 3 additions & 3 deletions src/student_journal/adapters/db/gateway/home_task_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def write_home_task(self, home_task: HomeTask) -> None:
params = home_task_to_list_retort.dump(home_task)
self.cursor.execute(query, params)

def read_home_tasks(self, is_done: bool = False) -> list[HomeTaskReadModel]:
def read_home_tasks(self, *, show_done: bool = False) -> list[HomeTaskReadModel]:
query = """
SELECT Hometask.task_id, Hometask.description, Hometask.is_done,
Lesson.lesson_id as lesson_lesson_id,
Expand All @@ -54,9 +54,9 @@ def read_home_tasks(self, is_done: bool = False) -> list[HomeTaskReadModel]:
JOIN Lesson ON Hometask.lesson_id = Lesson.lesson_id
JOIN Subject ON Lesson.subject_id = Subject.subject_id
"""
if is_done is False:
if show_done is False:
query += " WHERE is_done = ?"
res = self.cursor.execute(query, (is_done,)).fetchall()
res = self.cursor.execute(query, (show_done,)).fetchall()
else:
res = self.cursor.execute(query).fetchall()

Expand Down
1 change: 1 addition & 0 deletions src/student_journal/adapters/db/gateway/subject_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def delete_subject(self, subject_id: SubjectId) -> None:

def read_subjects(
self,
*,
sort_by_title: bool = False,
sort_by_avg_mark: bool = False,
show_empty: bool = True,
Expand Down
6 changes: 5 additions & 1 deletion src/student_journal/application/common/home_task_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ class HomeTaskGateway(Protocol):
def read_home_task(self, task_id: HomeTaskId) -> HomeTask: ...

@abstractmethod
def read_home_tasks(self, is_done: bool = False) -> list[HomeTaskReadModel]: ...
def read_home_tasks(
self,
*,
show_done: bool = False,
) -> list[HomeTaskReadModel]: ...

@abstractmethod
def write_home_task(self, home_task: HomeTask) -> None: ...
Expand Down
1 change: 1 addition & 0 deletions src/student_journal/application/common/subject_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def write_subject(self, subject: Subject) -> None: ...
@abstractmethod
def read_subjects(
self,
*,
sort_by_title: bool = False,
sort_by_avg_mark: bool = False,
show_empty: bool = True,
Expand Down
4 changes: 2 additions & 2 deletions src/student_journal/application/hometask/read_home_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class ReadHomeTasks:
gateway: HomeTaskGateway
idp: IdProvider

def execute(self, is_done: bool = False) -> HomeTasksReadModel:
def execute(self, *, show_done: bool = False) -> HomeTasksReadModel:
student_id = self.idp.get_id()
home_tasks = self.gateway.read_home_tasks(is_done)
home_tasks = self.gateway.read_home_tasks(show_done=show_done)

return HomeTasksReadModel(
student_id=student_id,
Expand Down
7 changes: 4 additions & 3 deletions src/student_journal/application/subject/read_subjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ class ReadSubjects:

def execute(
self,
*,
sort_by_title: bool = False,
sort_by_avg_mark: bool = False,
show_empty: bool = True,
) -> list[SubjectReadModel]:
self.idp.ensure_authenticated()

subjects = self.gateway.read_subjects(
sort_by_title,
sort_by_avg_mark,
show_empty,
sort_by_title=sort_by_title,
sort_by_avg_mark=sort_by_avg_mark,
show_empty=show_empty,
)

return subjects
5 changes: 3 additions & 2 deletions src/student_journal/presentation/widget/dashboard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dishka import Container
from PyQt6.QtGui import QAction
from PyQt6.QtWidgets import QMainWindow, QMenu, QStackedWidget, QWidget
from PyQt6.QtWidgets import QMainWindow, QMenu, QMenuBar, QStackedWidget, QWidget

from student_journal.presentation.widget.help.about import About
from student_journal.presentation.widget.hometask.hometask_list import HomeTaskList
Expand Down Expand Up @@ -91,7 +91,8 @@ def show_widget(self, widget: QWidget) -> None:
self.stacked_widget.setCurrentWidget(widget)

def create_menu_bar(self) -> None:
menu_bar = self.menuBar()
menu_bar = QMenuBar(self)
self.setMenuBar(menu_bar)

help_menu = QMenu("&Помощь", self)
menu_bar.addMenu(help_menu)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def load_home_tasks(self) -> None:
self.ui.list_hometask.clear()
with self.container() as r_container:
command = r_container.get(ReadHomeTasks)
tasks = command.execute(self.show_done).home_tasks
tasks = command.execute(show_done=self.show_done).home_tasks

for task in tasks:
task_text = f"{task.subject.title}: {task.description[:50]}"
Expand Down Expand Up @@ -88,10 +88,14 @@ def on_context_menu(self, position: QtCore.QPoint) -> None:
mark_done_action = menu.addAction("Выполнено")
delete_action = menu.addAction("Удалить")

if mark_done_action is None or delete_action is None:
raise RuntimeError("Hometask list context actions is None")

mark_done_action.triggered.connect(lambda: self.mark_task_done(item))
delete_action.triggered.connect(lambda: self.delete_task(item))

menu.exec(self.ui.list_hometask.viewport().mapToGlobal(position))
if (viewport := self.ui.list_hometask.viewport()) is not None:
menu.exec(viewport.mapToGlobal(position))

def mark_task_done(self, item: QListWidgetItem) -> None:
task_id: HomeTaskId = item.data(0x100)
Expand Down
64 changes: 47 additions & 17 deletions src/student_journal/presentation/widget/lesson/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ def __init__(self, container: Container) -> None:

self.model = QStandardItemModel()
self.ui.days_table.setModel(self.model)
self.ui.days_table.horizontalHeader().setSectionResizeMode(
QtWidgets.QHeaderView.ResizeMode.Stretch,
)

self.setup_table()

Expand All @@ -86,12 +83,23 @@ def __init__(self, container: Container) -> None:
self.place_add_buttons()

def setup_table(self) -> None:
if (header := self.ui.days_table.horizontalHeader()) is not None:
header.setSectionResizeMode(
QtWidgets.QHeaderView.ResizeMode.Stretch,
)
else:
raise RuntimeError("Header in Schedule is None!")

self.ui.days_table.setDragEnabled(True)
self.ui.days_table.setAcceptDrops(True)
self.ui.days_table.setDropIndicatorShown(True)
self.ui.days_table.setDefaultDropAction(QtCore.Qt.DropAction.MoveAction)
self.ui.days_table.viewport().setAcceptDrops(True)
self.ui.days_table.viewport().installEventFilter(self)

if (viewport := self.ui.days_table.viewport()) is not None:
viewport.setAcceptDrops(True)
viewport.installEventFilter(self)
else:
raise RuntimeError("Viewport in Schedule is None!")
self.ui.days_table.setEditTriggers(
QtWidgets.QAbstractItemView.EditTrigger.NoEditTriggers,
)
Expand All @@ -105,7 +113,14 @@ def place_add_buttons(self) -> None:
layout.addWidget(btn)
btn.clicked.connect(self.add_new_lesson)

def eventFilter(self, source: QtCore.QObject, event: QtCore.QEvent) -> bool:
def eventFilter(
self,
source: QtCore.QObject | None,
event: QtCore.QEvent | None,
) -> bool:
if event is None or source is None:
return super().eventFilter(source, event)

if source == self.ui.days_table.viewport():
if event.type() == QtCore.QEvent.Type.DragEnter:
self.dragEnterEvent(event) # type: ignore
Expand All @@ -120,16 +135,25 @@ def eventFilter(self, source: QtCore.QObject, event: QtCore.QEvent) -> bool:
return True
return super().eventFilter(source, event)

def dragEnterEvent(self, event: QDragEnterEvent) -> None:
if event.mimeData().hasFormat("application/x-qabstractitemmodeldatalist"):
def dragEnterEvent(self, event: QDragEnterEvent | None) -> None:
if event is None or (mimedata := event.mimeData()) is None:
return

if mimedata.hasFormat("application/x-qabstractitemmodeldatalist"):
event.acceptProposedAction()

def dragMoveEvent(self, event: QDragMoveEvent) -> None:
if event.mimeData().hasFormat("application/x-qabstractitemmodeldatalist"):
def dragMoveEvent(self, event: QDragMoveEvent | None) -> None:
if event is None or (mimedata := event.mimeData()) is None:
return

if mimedata.hasFormat("application/x-qabstractitemmodeldatalist"):
event.acceptProposedAction()

def dropEvent(self, event: QDropEvent) -> None:
if not self.week_start:
def dropEvent(self, event: QDropEvent | None) -> None:
if event is None:
return

if self.week_start is None:
return

index = self.ui.days_table.indexAt(event.position().toPoint())
Expand All @@ -144,7 +168,7 @@ def dropEvent(self, event: QDropEvent) -> None:

source_item = self.model.item(source_index.row(), source_index.column())
if source_item is None:
return # type: ignore
return

lesson_id: LessonId = source_item.data(0x100)

Expand Down Expand Up @@ -273,8 +297,8 @@ def fetch_subjects_for_lessons(
lessons: list[LessonId],
) -> dict[LessonId, Subject]:
with self.container() as r_container:
gateway = r_container.get(LessonGateway)
return gateway.read_subjects_for_lessons(lessons) # type: ignore
gateway: LessonGateway = r_container.get(LessonGateway)
return gateway.read_subjects_for_lessons(lessons)

def copy_to_next_week(self) -> None:
if not self.week_start:
Expand Down Expand Up @@ -399,7 +423,7 @@ def on_lesson_clicked(self, index: QtCore.QModelIndex) -> None:
item = self.model.item(index.row(), index.column())

if item is None:
return # type: ignore
return

lesson_id: LessonId = item.data(0x100)

Expand All @@ -415,8 +439,14 @@ def on_context_menu(self, position: QtCore.QPoint) -> None:
lesson_id: LessonId = item.data(0x100)
menu = QtWidgets.QMenu()
delete_action = menu.addAction("Удалить")

if delete_action is None:
raise RuntimeError("Schedule context action is None!")

delete_action.triggered.connect(lambda: self.delete_lesson(lesson_id))
menu.exec(self.ui.days_table.viewport().mapToGlobal(position))

if (viewport := self.ui.days_table.viewport()) is not None:
menu.exec(viewport.mapToGlobal(position))

def delete_lesson(self, lesson_id: LessonId) -> None:
with self.container() as r_container:
Expand Down
8 changes: 5 additions & 3 deletions src/student_journal/presentation/widget/subject/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ def __init__(self, container: Container) -> None:
self.ui.refresh.clicked.connect(self.on_refresh)
self.ui.sorting.currentIndexChanged.connect(self.on_sort_changed)
self.ui.show_without_mark.stateChanged.connect(self.on_toggle_without_mark)
self.ui.table.horizontalHeader().setSectionResizeMode(
QHeaderView.ResizeMode.Stretch,
)

if (header := self.ui.table.horizontalHeader()) is not None:
header.setSectionResizeMode(
QHeaderView.ResizeMode.Stretch,
)

self.load_subjects()

Expand Down
1 change: 0 additions & 1 deletion tests/gateway/lesson/test_lesson_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def test_read(

def test_read_not_exist(
lesson_gateway: LessonGateway,
cursor: Cursor,
) -> None:
with pytest.raises(LessonNotFoundError):
lesson_gateway.read_lesson(LESSON_ID, student_timezone)
Expand Down
1 change: 0 additions & 1 deletion tests/gateway/student/test_student_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def test_read(

def test_read_not_exist(
student_gateway: StudentGateway,
cursor: Cursor,
) -> None:
with pytest.raises(StudentNotFoundError):
student_gateway.read_student(STUDENT_ID)
Expand Down
Loading