qcanvas 1.2.0__py3-none-any.whl → 2026.1.19__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. qcanvas/__init__.py +60 -0
  2. qcanvas/app.py +72 -0
  3. qcanvas/backend_connectors/frontend_resource_manager.py +13 -5
  4. qcanvas/backend_connectors/qcanvas_task_master.py +2 -2
  5. qcanvas/icons/__init__.py +5 -5
  6. qcanvas/icons/_icon_type.py +1 -1
  7. qcanvas/icons/icons.qrc +39 -35
  8. qcanvas/icons/rc_icons.py +1298 -1197
  9. qcanvas/settings/__init__.py +6 -0
  10. qcanvas/{util/settings → settings}/_client_settings.py +4 -4
  11. qcanvas/settings/_course_settings.py +54 -0
  12. qcanvas/{util/settings → settings}/_mapped_setting.py +2 -5
  13. qcanvas/{util/settings → settings}/_ui_settings.py +5 -5
  14. qcanvas/theme.py +101 -0
  15. qcanvas/ui/course_viewer/content_tree.py +9 -12
  16. qcanvas/ui/course_viewer/course_tree/_course_icon_generator.py +3 -3
  17. qcanvas/ui/course_viewer/course_tree/course_tree.py +9 -8
  18. qcanvas/ui/course_viewer/course_viewer.py +42 -56
  19. qcanvas/ui/course_viewer/tabs/assignment_tab/assignment_tab.py +107 -29
  20. qcanvas/ui/course_viewer/tabs/assignment_tab/assignment_tree.py +4 -4
  21. qcanvas/ui/course_viewer/tabs/constants.py +1 -0
  22. qcanvas/ui/course_viewer/tabs/content_tab.py +33 -39
  23. qcanvas/ui/course_viewer/tabs/file_tab/file_tab.py +4 -4
  24. qcanvas/ui/course_viewer/tabs/file_tab/file_tree.py +7 -10
  25. qcanvas/ui/course_viewer/tabs/file_tab/pages_file_tree.py +6 -7
  26. qcanvas/ui/course_viewer/tabs/mail_tab/mail_tab.py +50 -27
  27. qcanvas/ui/course_viewer/tabs/mail_tab/mail_tree.py +7 -8
  28. qcanvas/ui/course_viewer/tabs/page_tab/page_tab.py +3 -3
  29. qcanvas/ui/course_viewer/tabs/page_tab/page_tree.py +5 -5
  30. qcanvas/ui/course_viewer/tabs/resource_rich_browser.py +18 -32
  31. qcanvas/ui/course_viewer/tree_widget_data_item.py +1 -1
  32. qcanvas/ui/memory_tree/_tree_memory.py +45 -42
  33. qcanvas/ui/memory_tree/memory_tree_widget.py +22 -18
  34. qcanvas/ui/memory_tree/memory_tree_widget_item.py +3 -3
  35. qcanvas/ui/qcanvas_window/__init__.py +1 -0
  36. qcanvas/ui/{main_ui → qcanvas_window}/course_viewer_container.py +10 -10
  37. qcanvas/ui/{main_ui → qcanvas_window}/options/auto_download_resources_option.py +5 -5
  38. qcanvas/ui/{main_ui → qcanvas_window}/options/quick_sync_option.py +7 -6
  39. qcanvas/ui/{main_ui → qcanvas_window}/options/sync_on_start_option.py +7 -6
  40. qcanvas/ui/{main_ui → qcanvas_window}/options/theme_selection_menu.py +10 -10
  41. qcanvas/ui/{main_ui → qcanvas_window}/qcanvas_window.py +57 -41
  42. qcanvas/ui/{main_ui → qcanvas_window}/status_bar_progress_display.py +5 -6
  43. qcanvas/ui/qml_components/__init__.py +4 -0
  44. qcanvas/ui/qml_components/attachments_pane.py +70 -0
  45. qcanvas/ui/qml_components/comments_pane.py +83 -0
  46. qcanvas/ui/qml_components/qml/AttachmentsList.ui.qml +15 -0
  47. qcanvas/ui/qml_components/qml/AttachmentsListDelegate.qml +77 -0
  48. qcanvas/ui/qml_components/qml/AttachmentsListModel.qml +19 -0
  49. qcanvas/ui/qml_components/qml/AttachmentsPane.qml +11 -0
  50. qcanvas/ui/qml_components/qml/CommentsList.ui.qml +15 -0
  51. qcanvas/ui/qml_components/qml/CommentsListDelegate.ui.qml +118 -0
  52. qcanvas/ui/qml_components/qml/CommentsListModel.qml +56 -0
  53. qcanvas/ui/qml_components/qml/CommentsPane.qml +11 -0
  54. qcanvas/ui/qml_components/qml/DecoratedText.ui.qml +44 -0
  55. qcanvas/ui/qml_components/qml/Spacer.ui.qml +7 -0
  56. qcanvas/ui/qml_components/qml/ThemedRectangle.qml +53 -0
  57. qcanvas/ui/qml_components/qml/__init__.py +3 -0
  58. qcanvas/ui/qml_components/qml/rc_qml.py +709 -0
  59. qcanvas/ui/qml_components/qml/rc_qml.qrc +16 -0
  60. qcanvas/ui/qml_components/qml_bridge_types.py +95 -0
  61. qcanvas/ui/qml_components/qml_pane.py +21 -0
  62. qcanvas/ui/setup/setup_checker.py +1 -1
  63. qcanvas/ui/setup/setup_dialog.py +28 -14
  64. qcanvas/util/auto_downloader.py +9 -7
  65. qcanvas/util/basic_fonts.py +2 -2
  66. qcanvas/util/context_dict.py +12 -0
  67. qcanvas/util/file_icons.py +11 -19
  68. qcanvas/util/layouts.py +5 -7
  69. qcanvas/util/paths.py +17 -6
  70. qcanvas/util/qurl_util.py +1 -1
  71. qcanvas/util/ui_tools.py +118 -8
  72. qcanvas/util/url_checker.py +1 -1
  73. qcanvas-2026.1.19.dist-info/METADATA +95 -0
  74. qcanvas-2026.1.19.dist-info/RECORD +92 -0
  75. {qcanvas-1.2.0.dist-info → qcanvas-2026.1.19.dist-info}/WHEEL +1 -1
  76. qcanvas-2026.1.19.dist-info/entry_points.txt +3 -0
  77. qcanvas/app_start/__init__.py +0 -59
  78. qcanvas/icons/_update_icons.py +0 -89
  79. qcanvas/icons/dark/actions/exit.svg +0 -3
  80. qcanvas/icons/dark/actions/mark_all_read.svg +0 -3
  81. qcanvas/icons/dark/actions/open_downloads.svg +0 -3
  82. qcanvas/icons/dark/actions/quick_login.svg +0 -3
  83. qcanvas/icons/dark/actions/sync.svg +0 -3
  84. qcanvas/icons/dark/branding/logo_transparent.svg +0 -303
  85. qcanvas/icons/dark/options/auto_download.svg +0 -3
  86. qcanvas/icons/dark/options/theme.svg +0 -3
  87. qcanvas/icons/dark/tabs/assignments.svg +0 -3
  88. qcanvas/icons/dark/tabs/mail.svg +0 -3
  89. qcanvas/icons/dark/tabs/pages.svg +0 -3
  90. qcanvas/icons/dark/tree_items/assignment.svg +0 -3
  91. qcanvas/icons/dark/tree_items/mail.svg +0 -3
  92. qcanvas/icons/dark/tree_items/module.svg +0 -3
  93. qcanvas/icons/dark/tree_items/page.svg +0 -3
  94. qcanvas/icons/light/actions/exit.svg +0 -3
  95. qcanvas/icons/light/actions/mark_all_read.svg +0 -3
  96. qcanvas/icons/light/actions/open_downloads.svg +0 -3
  97. qcanvas/icons/light/actions/quick_login.svg +0 -3
  98. qcanvas/icons/light/actions/sync.svg +0 -3
  99. qcanvas/icons/light/branding/logo_transparent.svg +0 -304
  100. qcanvas/icons/light/options/auto_download.svg +0 -3
  101. qcanvas/icons/light/options/ignore_old.svg +0 -3
  102. qcanvas/icons/light/options/include_videos.svg +0 -3
  103. qcanvas/icons/light/options/theme.svg +0 -3
  104. qcanvas/icons/light/tabs/assignments.svg +0 -3
  105. qcanvas/icons/light/tabs/mail.svg +0 -3
  106. qcanvas/icons/light/tabs/pages.svg +0 -3
  107. qcanvas/icons/light/tree_items/assignment.svg +0 -3
  108. qcanvas/icons/light/tree_items/mail.svg +0 -3
  109. qcanvas/icons/light/tree_items/module.svg +0 -3
  110. qcanvas/icons/light/tree_items/page.svg +0 -3
  111. qcanvas/icons/universal/branding/main_icon.svg +0 -325
  112. qcanvas/icons/universal/downloads/download_failed.svg +0 -23
  113. qcanvas/icons/universal/downloads/downloaded.svg +0 -23
  114. qcanvas/icons/universal/downloads/not_downloaded.svg +0 -23
  115. qcanvas/icons/universal/downloads/unknown.svg +0 -6
  116. qcanvas/icons/universal/tabs/assignments_new_content.svg +0 -3
  117. qcanvas/icons/universal/tabs/mail_new_content.svg +0 -3
  118. qcanvas/icons/universal/tabs/pages_new_content.svg +0 -3
  119. qcanvas/icons/universal/tree_items/semester.svg +0 -108
  120. qcanvas/run.py +0 -54
  121. qcanvas/ui/course_viewer/tabs/util.py +0 -11
  122. qcanvas/ui/main_ui/__init__.py +0 -0
  123. qcanvas/util/settings/__init__.py +0 -9
  124. qcanvas/util/themes/__init__.py +0 -2
  125. qcanvas/util/themes/_colour_scheme_helper.py +0 -38
  126. qcanvas/util/themes/_selected_theme.py +0 -10
  127. qcanvas/util/themes/_theme_changed_event.py +0 -17
  128. qcanvas/util/themes/_theme_changer.py +0 -86
  129. qcanvas-1.2.0.dist-info/METADATA +0 -71
  130. qcanvas-1.2.0.dist-info/RECORD +0 -118
  131. qcanvas-1.2.0.dist-info/entry_points.txt +0 -3
  132. /qcanvas/ui/{main_ui → qcanvas_window}/options/__init__.py +0 -0
@@ -0,0 +1,6 @@
1
+ from ._client_settings import _ClientSettings
2
+ from ._ui_settings import _UISettings
3
+ from ._course_settings import course_configs
4
+
5
+ client = _ClientSettings()
6
+ ui = _UISettings()
@@ -1,11 +1,11 @@
1
1
  import logging
2
- from typing import *
2
+ from typing import Optional
3
3
 
4
- from qcanvas_api_clients.canvas import CanvasClientConfig
5
- from qcanvas_api_clients.panopto import PanoptoClientConfig
4
+ from libqcanvas_clients.canvas import CanvasClientConfig
5
+ from libqcanvas_clients.panopto import PanoptoClientConfig
6
6
 
7
7
  from qcanvas.util import paths
8
- from qcanvas.util.settings._mapped_setting import BoolSetting, MappedSetting
8
+ from ._mapped_setting import BoolSetting, MappedSetting
9
9
 
10
10
  _logger = logging.getLogger(__name__)
11
11
 
@@ -0,0 +1,54 @@
1
+ import logging
2
+ from pathlib import Path
3
+
4
+ from aiofile import async_open
5
+ from pydantic import BaseModel, RootModel, Field, ValidationError
6
+
7
+ from qcanvas.util import paths
8
+
9
+ _logger = logging.getLogger(__name__)
10
+
11
+
12
+ class CourseConfigData(BaseModel):
13
+ nickname: str | None = Field(default=None)
14
+
15
+ async def save(self) -> None:
16
+ await course_configs.save()
17
+
18
+
19
+ _CourseConfigurations = RootModel[dict[str, CourseConfigData]]
20
+
21
+
22
+ class _CourseConfig:
23
+ def __init__(self):
24
+ self._root_model = self._load_root_model()
25
+
26
+ def _load_root_model(self) -> _CourseConfigurations:
27
+ if self._storage_path.exists():
28
+ try:
29
+ return _CourseConfigurations.model_validate_json(
30
+ self._storage_path.read_text()
31
+ )
32
+ except ValidationError as e:
33
+ _logger.error("Failed to load course configs", exc_info=e)
34
+
35
+ return _CourseConfigurations({})
36
+
37
+ async def save(self) -> None:
38
+ async with async_open(self._storage_path, "wt") as file:
39
+ await file.write(self._root_model.model_dump_json(indent=4))
40
+
41
+ @property
42
+ def _storage_path(self) -> Path:
43
+ return paths.config_storage() / "course_settings.json"
44
+
45
+ def __getitem__(self, item: str) -> CourseConfigData:
46
+ if item in self._root_model.root:
47
+ return self._root_model.root[item]
48
+ else:
49
+ new_config = CourseConfigData()
50
+ self._root_model.root[item] = new_config
51
+ return new_config
52
+
53
+
54
+ course_configs = _CourseConfig()
@@ -1,14 +1,11 @@
1
1
  import logging
2
- from typing import *
3
2
 
4
- from qtpy.QtCore import QSettings
3
+ from PySide6.QtCore import QSettings
5
4
 
6
5
  _logger = logging.getLogger(__name__)
7
6
 
8
- T = TypeVar("T")
9
7
 
10
-
11
- class MappedSetting(Generic[T]):
8
+ class MappedSetting[T]:
12
9
  """
13
10
  Acts as a proxy for a named value in a QSettings object.
14
11
  Stores the value in memory when initialised and updates it accordingly, to protect it from changes on disk.
@@ -1,16 +1,16 @@
1
1
  import logging
2
2
 
3
- from qtpy.QtCore import QByteArray, QSettings
3
+ from PySide6.QtCore import QByteArray, QSettings
4
4
 
5
- from qcanvas.util.settings._mapped_setting import MappedSetting
6
- from qcanvas.util.themes import default_theme, ensure_theme_is_valid
5
+ from ._mapped_setting import MappedSetting
6
+ from qcanvas.theme import ensure_theme_is_valid
7
7
 
8
8
  _logger = logging.getLogger(__name__)
9
9
 
10
10
 
11
11
  class ThemeSetting(MappedSetting):
12
12
  def __init__(self):
13
- super().__init__(default=default_theme)
13
+ super().__init__(default="auto")
14
14
 
15
15
  def __get__(self, instance, owner):
16
16
  return ensure_theme_is_valid(super().__get__(instance, owner))
@@ -20,7 +20,7 @@ class ThemeSetting(MappedSetting):
20
20
 
21
21
 
22
22
  class _UISettings:
23
- settings = QSettings("QCanvasTeam", "QCanvas")
23
+ settings = QSettings("QCanvasTeam", "UI")
24
24
  theme: ThemeSetting = ThemeSetting()
25
25
  last_geometry: MappedSetting[QByteArray] = MappedSetting()
26
26
  last_window_state: MappedSetting[QByteArray] = MappedSetting()
qcanvas/theme.py ADDED
@@ -0,0 +1,101 @@
1
+ import logging
2
+ from typing import Literal
3
+
4
+ import qdarktheme
5
+ from PySide6.QtCore import QObject, Signal, Property, Slot
6
+ from PySide6.QtGui import QGuiApplication, Qt, QIcon
7
+ from PySide6.QtWidgets import QStyleFactory, QApplication
8
+
9
+ type Theme = Literal["native", "auto", "dark", "light"]
10
+
11
+ _logger = logging.getLogger(__name__)
12
+
13
+
14
+ class _AppTheme(QObject):
15
+ themeChanged = Signal()
16
+ darkModeChanged = Signal()
17
+
18
+ def __init__(self):
19
+ super().__init__()
20
+ self._last_system_theme = QGuiApplication.styleHints().colorScheme()
21
+ self._theme: Theme | None = None
22
+ self._dark_mode: bool | None = None
23
+
24
+ self.darkModeChanged.connect(self._set_icon_paths)
25
+ QGuiApplication.styleHints().colorSchemeChanged.connect(
26
+ self._on_system_theme_changed
27
+ )
28
+
29
+ @Property(bool, notify=darkModeChanged)
30
+ def dark_mode(self) -> bool:
31
+ assert self._theme is not None, "Theme has not been set"
32
+ return self._dark_mode
33
+
34
+ @Property(str, notify=themeChanged)
35
+ def theme(self) -> Theme:
36
+ assert self._theme is not None, "Theme has not been set"
37
+ return self._theme
38
+
39
+ @theme.setter
40
+ def theme(self, value: str):
41
+ value = ensure_theme_is_valid(value)
42
+
43
+ if value != self._theme:
44
+ self._update_theme(value)
45
+
46
+ def _update_theme(self, theme: str):
47
+ if theme is None or (theme == self._theme and theme not in ["native", "auto"]):
48
+ return
49
+
50
+ was_dark_mode = self._dark_mode
51
+
52
+ if theme != "native":
53
+ if theme == "auto":
54
+ self._dark_mode = _is_system_using_dark_mode()
55
+ selected_colour_scheme = "dark" if self._dark_mode else "light"
56
+ else:
57
+ self._dark_mode = theme == "dark"
58
+ selected_colour_scheme = theme
59
+
60
+ if was_dark_mode != self._dark_mode:
61
+ qdarktheme.setup_theme(
62
+ selected_colour_scheme,
63
+ custom_colors={"primary": "e02424"},
64
+ )
65
+
66
+ QApplication.setStyle(QStyleFactory.create("Fusion"))
67
+ else:
68
+ self._dark_mode = _is_system_using_dark_mode()
69
+
70
+ if theme != self._theme:
71
+ self._theme = theme
72
+ self.themeChanged.emit()
73
+
74
+ if was_dark_mode != self._dark_mode:
75
+ self.darkModeChanged.emit()
76
+
77
+ @Slot()
78
+ def _set_icon_paths(self):
79
+ QIcon.setFallbackSearchPaths(
80
+ [":icons/dark" if self._dark_mode else ":icons/light", ":icons/universal"]
81
+ )
82
+
83
+ @Slot()
84
+ def _on_system_theme_changed(self, scheme: Qt.ColorScheme):
85
+ if scheme != self._last_system_theme:
86
+ self._last_system_theme = scheme
87
+ self._update_theme(self._theme)
88
+
89
+
90
+ def _is_system_using_dark_mode() -> bool:
91
+ return QGuiApplication.styleHints().colorScheme() == Qt.ColorScheme.Dark
92
+
93
+
94
+ def ensure_theme_is_valid(theme_name: str) -> Theme:
95
+ if theme_name not in ["auto", "light", "dark", "native"]:
96
+ return "auto"
97
+ else:
98
+ return theme_name
99
+
100
+
101
+ app_theme = _AppTheme()
@@ -1,11 +1,11 @@
1
1
  import logging
2
2
  from abc import abstractmethod
3
- from typing import *
3
+ from typing import Optional, Self, Sequence
4
4
 
5
- import qcanvas_backend.database.types as db
6
- from qcanvas_backend.net.sync.sync_receipt import SyncReceipt
7
- from qtpy.QtCore import QItemSelection, Signal, Slot
8
- from qtpy.QtWidgets import *
5
+ from libqcanvas import db
6
+ from libqcanvas.net.sync.sync_receipt import SyncReceipt
7
+ from PySide6.QtCore import QItemSelection, Signal, Slot
8
+ from PySide6.QtWidgets import QHeaderView, QTreeWidgetItem
9
9
 
10
10
  from qcanvas.ui.course_viewer.tree_widget_data_item import AnyTreeDataItem
11
11
  from qcanvas.ui.memory_tree import MemoryTreeWidget
@@ -13,17 +13,14 @@ from qcanvas.util.basic_fonts import bold_font, normal_font
13
13
 
14
14
  _logger = logging.getLogger(__name__)
15
15
 
16
- T = TypeVar("T")
17
- U = TypeVar("U", bound=Type["ContentTree"])
18
16
 
19
-
20
- class ContentTree(MemoryTreeWidget, Generic[T]):
17
+ class ContentTree[T](MemoryTreeWidget):
21
18
  item_selected = Signal(object)
22
19
 
23
20
  @classmethod
24
- def create_from_receipt(
21
+ def create_from_receipt[U: Self](
25
22
  cls: U, course: db.Course, *, sync_receipt: SyncReceipt
26
- ) -> Type[U]:
23
+ ) -> type[U]:
27
24
  tree = cls(course.id)
28
25
  tree.reload(course, sync_receipt=sync_receipt)
29
26
  return tree
@@ -32,7 +29,7 @@ class ContentTree(MemoryTreeWidget, Generic[T]):
32
29
  self,
33
30
  tree_name: str,
34
31
  *,
35
- emit_selection_signal_for_type: Type,
32
+ emit_selection_signal_for_type: type,
36
33
  ):
37
34
  super().__init__(tree_name)
38
35
  self._reloading = False
@@ -3,9 +3,9 @@ import logging
3
3
  import random
4
4
 
5
5
  from cachetools import cached
6
- from qtpy.QtCore import QByteArray
7
- from qtpy.QtGui import QColor, QPainter, QPixmap
8
- from qtpy.QtSvg import QSvgRenderer
6
+ from PySide6.QtCore import QByteArray
7
+ from PySide6.QtGui import QColor, QPainter, QPixmap
8
+ from PySide6.QtSvg import QSvgRenderer
9
9
 
10
10
  _logger = logging.getLogger(__name__)
11
11
  _transparent = QColor("#00000000")
@@ -1,11 +1,12 @@
1
1
  import logging
2
- from typing import *
2
+ from typing import Sequence
3
3
 
4
- import qcanvas_backend.database.types as db
5
- from qcanvas_backend.net.sync.sync_receipt import SyncReceipt
6
- from qtpy.QtCore import Qt, Signal
4
+ from libqcanvas import db
5
+ from libqcanvas.net.sync.sync_receipt import SyncReceipt
6
+ from PySide6.QtCore import Qt, Signal
7
7
 
8
8
  from qcanvas import icons
9
+ from qcanvas.settings import course_configs
9
10
  from qcanvas.ui.course_viewer.content_tree import ContentTree
10
11
  from qcanvas.ui.course_viewer.course_tree._course_icon_generator import (
11
12
  CourseIconGenerator,
@@ -22,7 +23,7 @@ class _CourseTreeItem(TreeWidgetDataItem):
22
23
  self,
23
24
  id=course.id,
24
25
  data=course,
25
- strings=[course.configuration.nickname or course.name],
26
+ strings=[course_configs[course.id].nickname or course.name],
26
27
  )
27
28
 
28
29
  self._owner = owner
@@ -34,7 +35,7 @@ class _CourseTreeItem(TreeWidgetDataItem):
34
35
  | Qt.ItemFlag.ItemIsEnabled
35
36
  )
36
37
 
37
- def setData(self, column: int, role: int, value: Any):
38
+ def setData(self, column: int, role: int, value: object):
38
39
  if column != 0 or not isinstance(value, str):
39
40
  return super().setData(column, role, value)
40
41
 
@@ -59,11 +60,11 @@ class CourseTree(ContentTree[Sequence[db.Term]]):
59
60
  )
60
61
 
61
62
  def create_tree_items(
62
- self, terms: List[db.Term], sync_receipt: SyncReceipt
63
+ self, terms: list[db.Term], sync_receipt: SyncReceipt
63
64
  ) -> Sequence[MemoryTreeWidgetItem]:
64
65
  widgets = []
65
66
 
66
- for term in reversed(terms):
67
+ for term in terms:
67
68
  term_widget = self._create_term_widget(term)
68
69
  course_icon_generator = CourseIconGenerator(term.id)
69
70
 
@@ -1,33 +1,31 @@
1
1
  import logging
2
2
  from dataclasses import dataclass
3
3
 
4
- import qcanvas_backend.database.types as db
5
- from qcanvas_backend.net.resources.download.resource_manager import ResourceManager
6
- from qcanvas_backend.net.sync.sync_receipt import SyncReceipt
7
- from qtpy.QtCore import Slot
8
- from qtpy.QtGui import QIcon
9
- from qtpy.QtWidgets import *
4
+ from libqcanvas import db
5
+ from libqcanvas.net.resources.download.resource_manager import ResourceManager
6
+ from libqcanvas.net.sync.sync_receipt import SyncReceipt
7
+ from PySide6.QtCore import Slot
8
+ from PySide6.QtGui import QIcon
9
+ from PySide6.QtWidgets import QTabWidget, QVBoxLayout, QWidget
10
10
 
11
11
  from qcanvas import icons
12
12
  from qcanvas.ui.course_viewer.tabs.assignment_tab import AssignmentTab
13
13
  from qcanvas.ui.course_viewer.tabs.mail_tab import MailTab
14
14
  from qcanvas.ui.course_viewer.tabs.page_tab import PageTab
15
- from qcanvas.util.basic_fonts import bold_font
16
15
  from qcanvas.util.layouts import layout
17
- from qcanvas.util.ui_tools import make_truncatable
16
+ import qcanvas.util.ui_tools as ui
18
17
 
19
18
  _logger = logging.getLogger(__name__)
20
19
 
21
20
 
22
21
  @dataclass
23
22
  class _Tab:
24
- index: int
25
23
  icon: QIcon
26
24
  highlighted_icon: QIcon
25
+ update_type: type
27
26
 
28
27
 
29
28
  class CourseViewer(QWidget):
30
-
31
29
  def __init__(
32
30
  self,
33
31
  course: db.Course,
@@ -40,9 +38,9 @@ class CourseViewer(QWidget):
40
38
  self._course_id = course.id
41
39
  self._previous_tab_index = 0
42
40
 
43
- self._course_label = QLabel(course.name)
44
- self._course_label.setFont(bold_font)
45
- make_truncatable(self._course_label)
41
+ self._course_label = ui.label(
42
+ course.name, font=ui.font(point_size=13, bold=True), allow_truncation=True
43
+ )
46
44
 
47
45
  self._pages_tab = PageTab.create_from_receipt(
48
46
  course=course,
@@ -66,7 +64,7 @@ class CourseViewer(QWidget):
66
64
  # )
67
65
 
68
66
  self._tab_widget = QTabWidget()
69
- self._tabs: dict[str, _Tab] = {}
67
+ self._tabs: dict[int, _Tab] = {}
70
68
 
71
69
  # self._setup_tab(
72
70
  # name="Files",
@@ -74,40 +72,45 @@ class CourseViewer(QWidget):
74
72
  # icon=icons.tabs.pages,
75
73
  # highlighted_icon=icons.tabs.pages_new_content,
76
74
  # )
77
- self._setup_tab(
75
+ self._PAGES_TAB = self._set_up_tab(
78
76
  name="Pages",
79
77
  widget=self._pages_tab,
80
78
  icon=icons.tabs.pages,
81
79
  highlighted_icon=icons.tabs.pages_new_content,
80
+ content_update_key=db.Page,
82
81
  )
83
- self._setup_tab(
82
+ self._ASSIGNMENTS_TAB = self._set_up_tab(
84
83
  name="Assignments",
85
84
  widget=self._assignments_tab,
86
85
  icon=icons.tabs.assignments,
87
86
  highlighted_icon=icons.tabs.assignments_new_content,
87
+ content_update_key=db.Assignment,
88
88
  )
89
- self._setup_tab(
89
+ self._MAIL_TAB = self._set_up_tab(
90
90
  name="Mail",
91
91
  widget=self._mail_tab,
92
92
  icon=icons.tabs.mail,
93
93
  highlighted_icon=icons.tabs.mail_new_content,
94
+ content_update_key=db.Message,
94
95
  )
95
96
  # self._tabs.addTab(QLabel("Not implemented"), "Panopto") # The meme lives on!
96
97
 
97
98
  self.setLayout(layout(QVBoxLayout, self._course_label, self._tab_widget))
98
-
99
99
  self._tab_widget.currentChanged.connect(self._tab_changed)
100
-
101
100
  self._highlight_tabs(sync_receipt)
102
- # self._highlight_tab(
103
- # self._tab_widget.tabText(0)
104
- # ) # Because the first tab always gets auto-selected
105
101
 
106
- def _setup_tab(
107
- self, widget: QWidget, icon: QIcon, highlighted_icon: QIcon, name: str
108
- ):
102
+ def _set_up_tab(
103
+ self,
104
+ *,
105
+ widget: QWidget,
106
+ icon: QIcon,
107
+ highlighted_icon: QIcon,
108
+ name: str,
109
+ content_update_key: type,
110
+ ) -> int:
109
111
  index = self._tab_widget.addTab(widget, icon, name)
110
- self._tabs[name] = _Tab(index, icon, highlighted_icon)
112
+ self._tabs[index] = _Tab(icon, highlighted_icon, update_type=content_update_key)
113
+ return index
111
114
 
112
115
  def reload(self, course: db.Course, *, sync_receipt: SyncReceipt) -> None:
113
116
  # self._files_tab.reload(course, sync_receipt=sync_receipt)
@@ -118,39 +121,22 @@ class CourseViewer(QWidget):
118
121
 
119
122
  @Slot(int)
120
123
  def _tab_changed(self, index: int) -> None:
124
+ _logger.debug(f"Index = {index}")
121
125
  if index != -1:
122
- self._unhighlight_tab(self._tab_widget.tabText(self._previous_tab_index))
126
+ _logger.debug(f"Previous tab = {self._previous_tab_index}")
127
+ self._set_tab_highlight(self._previous_tab_index, False)
123
128
  self._previous_tab_index = index
124
129
 
125
130
  def _highlight_tabs(self, sync_receipt: SyncReceipt) -> None:
126
131
  updates = sync_receipt.updates_by_course.get(self._course_id, None)
127
132
 
128
- if updates is not None:
129
- # if len(updates.updated_resources) > 0:
130
- # self._highlight_tab(0)
131
-
132
- if len(updates.updated_pages) > 0:
133
- self._highlight_tab("Pages")
134
- else:
135
- self._unhighlight_tab("Pages")
136
-
137
- if len(updates.updated_assignments) > 0:
138
- self._highlight_tab("Assignments")
139
- else:
140
- self._unhighlight_tab("Assignments")
141
-
142
- if len(updates.updated_messages) > 0:
143
- self._highlight_tab("Mail")
144
- else:
145
- self._unhighlight_tab("Mail")
146
- else:
147
- for tab_name in self._tabs.keys():
148
- self._unhighlight_tab(tab_name)
149
-
150
- def _highlight_tab(self, tab_name: str) -> None:
151
- tab = self._tabs[tab_name]
152
- self._tab_widget.setTabIcon(tab.index, tab.highlighted_icon)
153
-
154
- def _unhighlight_tab(self, tab_name: str) -> None:
155
- tab = self._tabs[tab_name]
156
- self._tab_widget.setTabIcon(tab.index, tab.icon)
133
+ for tab_index, tab in enumerate(self._tabs.values()):
134
+ self._set_tab_highlight(
135
+ tab_index, updates is not None and updates[tab.update_type] is not None
136
+ )
137
+
138
+ def _set_tab_highlight(self, tab_index: int, highlighted: bool) -> None:
139
+ tab = self._tabs[tab_index]
140
+ self._tab_widget.setTabIcon(
141
+ tab_index, tab.highlighted_icon if highlighted else tab.icon
142
+ )