Python-FastUI-Widgets 1.0.0__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.
- fastuiwidgets/__init__.py +12 -0
- fastuiwidgets/_rc/__init__.py +0 -0
- fastuiwidgets/_rc/resource.py +98835 -0
- fastuiwidgets/common/__init__.py +12 -0
- fastuiwidgets/common/animation.py +530 -0
- fastuiwidgets/common/auto_wrap.py +164 -0
- fastuiwidgets/common/color.py +95 -0
- fastuiwidgets/common/config.py +423 -0
- fastuiwidgets/common/exception_handler.py +31 -0
- fastuiwidgets/common/font.py +38 -0
- fastuiwidgets/common/icon.py +703 -0
- fastuiwidgets/common/image_utils.py +198 -0
- fastuiwidgets/common/overload.py +47 -0
- fastuiwidgets/common/router.py +133 -0
- fastuiwidgets/common/screen.py +25 -0
- fastuiwidgets/common/smooth_scroll.py +141 -0
- fastuiwidgets/common/style_sheet.py +512 -0
- fastuiwidgets/common/theme_listener.py +27 -0
- fastuiwidgets/common/translator.py +14 -0
- fastuiwidgets/components/__init__.py +6 -0
- fastuiwidgets/components/date_time/__init__.py +4 -0
- fastuiwidgets/components/date_time/calendar_picker.py +121 -0
- fastuiwidgets/components/date_time/calendar_view.py +671 -0
- fastuiwidgets/components/date_time/date_picker.py +245 -0
- fastuiwidgets/components/date_time/fast_calendar_view.py +487 -0
- fastuiwidgets/components/date_time/picker_base.py +632 -0
- fastuiwidgets/components/date_time/time_picker.py +223 -0
- fastuiwidgets/components/dialog_box/__init__.py +6 -0
- fastuiwidgets/components/dialog_box/color_dialog.py +414 -0
- fastuiwidgets/components/dialog_box/dialog.py +167 -0
- fastuiwidgets/components/dialog_box/folder_list_dialog.py +307 -0
- fastuiwidgets/components/dialog_box/mask_dialog_base.py +120 -0
- fastuiwidgets/components/dialog_box/message_box_base.py +92 -0
- fastuiwidgets/components/dialog_box/message_dialog.py +65 -0
- fastuiwidgets/components/layout/__init__.py +3 -0
- fastuiwidgets/components/layout/expand_layout.py +96 -0
- fastuiwidgets/components/layout/flow_layout.py +236 -0
- fastuiwidgets/components/layout/v_box_layout.py +41 -0
- fastuiwidgets/components/material/__init__.py +6 -0
- fastuiwidgets/components/material/acrylic_combo_box.py +96 -0
- fastuiwidgets/components/material/acrylic_flyout.py +105 -0
- fastuiwidgets/components/material/acrylic_line_edit.py +27 -0
- fastuiwidgets/components/material/acrylic_menu.py +204 -0
- fastuiwidgets/components/material/acrylic_tool_tip.py +39 -0
- fastuiwidgets/components/material/acrylic_widget.py +42 -0
- fastuiwidgets/components/navigation/__init__.py +9 -0
- fastuiwidgets/components/navigation/breadcrumb.py +350 -0
- fastuiwidgets/components/navigation/navigation_bar.py +416 -0
- fastuiwidgets/components/navigation/navigation_interface.py +268 -0
- fastuiwidgets/components/navigation/navigation_panel.py +657 -0
- fastuiwidgets/components/navigation/navigation_widget.py +686 -0
- fastuiwidgets/components/navigation/pivot.py +272 -0
- fastuiwidgets/components/navigation/segmented_widget.py +174 -0
- fastuiwidgets/components/settings/__init__.py +8 -0
- fastuiwidgets/components/settings/custom_color_setting_card.py +139 -0
- fastuiwidgets/components/settings/expand_setting_card.py +390 -0
- fastuiwidgets/components/settings/folder_list_setting_card.py +134 -0
- fastuiwidgets/components/settings/options_setting_card.py +86 -0
- fastuiwidgets/components/settings/setting_card.py +449 -0
- fastuiwidgets/components/settings/setting_card_group.py +48 -0
- fastuiwidgets/components/widgets/__init__.py +41 -0
- fastuiwidgets/components/widgets/acrylic_label.py +261 -0
- fastuiwidgets/components/widgets/button.py +1059 -0
- fastuiwidgets/components/widgets/card_widget.py +369 -0
- fastuiwidgets/components/widgets/check_box.py +203 -0
- fastuiwidgets/components/widgets/combo_box.py +556 -0
- fastuiwidgets/components/widgets/command_bar.py +636 -0
- fastuiwidgets/components/widgets/cycle_list_widget.py +251 -0
- fastuiwidgets/components/widgets/flip_view.py +430 -0
- fastuiwidgets/components/widgets/flyout.py +521 -0
- fastuiwidgets/components/widgets/frameless_window.py +49 -0
- fastuiwidgets/components/widgets/icon_widget.py +53 -0
- fastuiwidgets/components/widgets/info_badge.py +483 -0
- fastuiwidgets/components/widgets/info_bar.py +596 -0
- fastuiwidgets/components/widgets/label.py +553 -0
- fastuiwidgets/components/widgets/line_edit.py +551 -0
- fastuiwidgets/components/widgets/list_view.py +158 -0
- fastuiwidgets/components/widgets/menu.py +1318 -0
- fastuiwidgets/components/widgets/pips_pager.py +331 -0
- fastuiwidgets/components/widgets/progress_bar.py +311 -0
- fastuiwidgets/components/widgets/progress_ring.py +212 -0
- fastuiwidgets/components/widgets/scroll_area.py +125 -0
- fastuiwidgets/components/widgets/scroll_bar.py +673 -0
- fastuiwidgets/components/widgets/separator.py +43 -0
- fastuiwidgets/components/widgets/slider.py +307 -0
- fastuiwidgets/components/widgets/spin_box.py +306 -0
- fastuiwidgets/components/widgets/stacked_widget.py +211 -0
- fastuiwidgets/components/widgets/state_tool_tip.py +188 -0
- fastuiwidgets/components/widgets/switch_button.py +312 -0
- fastuiwidgets/components/widgets/tab_view.py +804 -0
- fastuiwidgets/components/widgets/table_view.py +360 -0
- fastuiwidgets/components/widgets/teaching_tip.py +657 -0
- fastuiwidgets/components/widgets/tool_tip.py +460 -0
- fastuiwidgets/components/widgets/tree_view.py +216 -0
- fastuiwidgets/multimedia/__init__.py +3 -0
- fastuiwidgets/multimedia/media_play_bar.py +319 -0
- fastuiwidgets/multimedia/media_player.py +124 -0
- fastuiwidgets/multimedia/video_widget.py +93 -0
- fastuiwidgets/window/__init__.py +2 -0
- fastuiwidgets/window/fluent_window.py +413 -0
- fastuiwidgets/window/splash_screen.py +92 -0
- fastuiwidgets/window/stacked_widget.py +66 -0
- python_fastui_widgets-1.0.0.dist-info/METADATA +30 -0
- python_fastui_widgets-1.0.0.dist-info/RECORD +107 -0
- python_fastui_widgets-1.0.0.dist-info/WHEEL +5 -0
- python_fastui_widgets-1.0.0.dist-info/licenses/LICENSE +674 -0
- python_fastui_widgets-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,487 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
from math import ceil
|
3
|
+
from collections import defaultdict, Counter
|
4
|
+
from typing import Type
|
5
|
+
|
6
|
+
from PySide6.QtCore import Qt, Signal, QSize, QDate, QCalendar, QLocale
|
7
|
+
from PySide6.QtGui import QPainter, QColor
|
8
|
+
from PySide6.QtWidgets import QHBoxLayout, QListWidgetItem, QLabel, QWidget, QStackedWidget, QStyle
|
9
|
+
|
10
|
+
from ..widgets.flyout import FlyoutViewBase
|
11
|
+
from ...common.style_sheet import isDarkTheme, themeColor, ThemeColor
|
12
|
+
|
13
|
+
|
14
|
+
from .calendar_view import (ScrollItemDelegate, ScrollViewBase,
|
15
|
+
CalendarViewBase)
|
16
|
+
|
17
|
+
|
18
|
+
class FastScrollItemDelegate(ScrollItemDelegate):
|
19
|
+
""" Fast scroll item delegate """
|
20
|
+
|
21
|
+
def __init__(self, min, max):
|
22
|
+
super().__init__(min, max)
|
23
|
+
self.selectedDate = None
|
24
|
+
self.currentDate = QDate.currentDate()
|
25
|
+
|
26
|
+
def setSelectedDate(self, date: QDate):
|
27
|
+
self.selectedDate = date
|
28
|
+
|
29
|
+
def setCurrentDate(self, date: QDate):
|
30
|
+
self.currentDate = date
|
31
|
+
|
32
|
+
def _drawBackground(self, painter, option, index):
|
33
|
+
date = index.data(Qt.UserRole)
|
34
|
+
if not date:
|
35
|
+
return
|
36
|
+
|
37
|
+
painter.save()
|
38
|
+
|
39
|
+
# outer ring
|
40
|
+
if date != self.selectedDate:
|
41
|
+
painter.setPen(Qt.PenStyle.NoPen)
|
42
|
+
else:
|
43
|
+
painter.setPen(themeColor())
|
44
|
+
|
45
|
+
if date == self.currentDate:
|
46
|
+
if index == self.pressedIndex:
|
47
|
+
painter.setBrush(ThemeColor.LIGHT_2.color())
|
48
|
+
elif option.state & QStyle.StateFlag.State_MouseOver:
|
49
|
+
painter.setBrush(ThemeColor.LIGHT_1.color())
|
50
|
+
else:
|
51
|
+
painter.setBrush(themeColor())
|
52
|
+
else:
|
53
|
+
c = 255 if isDarkTheme() else 0
|
54
|
+
if index == self.pressedIndex:
|
55
|
+
painter.setBrush(QColor(c, c, c, 7))
|
56
|
+
elif option.state & QStyle.StateFlag.State_MouseOver:
|
57
|
+
painter.setBrush(QColor(c, c, c, 9))
|
58
|
+
else:
|
59
|
+
painter.setBrush(Qt.GlobalColor.transparent)
|
60
|
+
|
61
|
+
m = self._itemMargin()
|
62
|
+
painter.drawEllipse(option.rect.adjusted(m, m, -m, -m))
|
63
|
+
painter.restore()
|
64
|
+
|
65
|
+
def _drawText(self, painter, option, index):
|
66
|
+
date = index.data(Qt.UserRole)
|
67
|
+
if not date:
|
68
|
+
return
|
69
|
+
|
70
|
+
painter.save()
|
71
|
+
painter.setFont(self.font)
|
72
|
+
|
73
|
+
if date == self.currentDate:
|
74
|
+
c = 0 if isDarkTheme() else 255
|
75
|
+
painter.setPen(QColor(c, c, c))
|
76
|
+
else:
|
77
|
+
painter.setPen(Qt.white if isDarkTheme() else Qt.black)
|
78
|
+
if not (self.min <= date <= self.max or option.state & QStyle.State_MouseOver) or \
|
79
|
+
index == self.pressedIndex:
|
80
|
+
painter.setOpacity(0.6)
|
81
|
+
|
82
|
+
text = index.data(Qt.DisplayRole)
|
83
|
+
painter.drawText(option.rect, Qt.AlignCenter, text)
|
84
|
+
painter.restore()
|
85
|
+
|
86
|
+
|
87
|
+
class FastYearScrollItemDelegate(FastScrollItemDelegate):
|
88
|
+
""" Year scroll item delegate """
|
89
|
+
|
90
|
+
def _itemMargin(self):
|
91
|
+
return 8
|
92
|
+
|
93
|
+
|
94
|
+
class FastDayScrollItemDelegate(FastScrollItemDelegate):
|
95
|
+
""" Fast day scroll item delegate """
|
96
|
+
|
97
|
+
def _itemMargin(self):
|
98
|
+
return 3
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
class FastScrollViewBase(ScrollViewBase):
|
103
|
+
""" Scroll view base class """
|
104
|
+
|
105
|
+
pageChanged = Signal(int)
|
106
|
+
|
107
|
+
def __init__(self, Delegate: Type[FastScrollItemDelegate], parent=None):
|
108
|
+
super().__init__(Delegate, parent)
|
109
|
+
self.delegate.setRange(*self.currentPageRange())
|
110
|
+
self.delegate.setCurrentDate(self.currentDate)
|
111
|
+
|
112
|
+
def scrollToPage(self, page: int):
|
113
|
+
if not 0 <= page < self.pageCount():
|
114
|
+
return
|
115
|
+
|
116
|
+
self.currentPage = page
|
117
|
+
self._updateItems()
|
118
|
+
self.delegate.setRange(*self.currentPageRange())
|
119
|
+
self.pageChanged.emit(page)
|
120
|
+
|
121
|
+
def wheelEvent(self, e):
|
122
|
+
pass
|
123
|
+
|
124
|
+
def _updateItems(self):
|
125
|
+
""" update the items of current page """
|
126
|
+
pass
|
127
|
+
|
128
|
+
def pageCount(self):
|
129
|
+
return ceil((self.maxYear - self.minYear + 1) / (self.pageRows * self.cols))
|
130
|
+
|
131
|
+
def pageSize(self):
|
132
|
+
return self.pageRows * self.cols
|
133
|
+
|
134
|
+
def _setSelectedDate(self, date: QDate):
|
135
|
+
self.delegate.setSelectedDate(date)
|
136
|
+
self.viewport().update()
|
137
|
+
|
138
|
+
|
139
|
+
class FastYearScrollView(FastScrollViewBase):
|
140
|
+
""" Year scroll view """
|
141
|
+
|
142
|
+
def __init__(self, parent=None):
|
143
|
+
super().__init__(FastYearScrollItemDelegate, parent)
|
144
|
+
self.delegate.setCurrentDate(QDate(self.currentDate.year(), 1, 1))
|
145
|
+
|
146
|
+
def _initItems(self):
|
147
|
+
self.years = list(range(self.minYear, self.maxYear+1))
|
148
|
+
count = self.cols * self.cols
|
149
|
+
years = self.years[:count]
|
150
|
+
self.addItems([str(i) for i in years])
|
151
|
+
|
152
|
+
for i, year in enumerate(years):
|
153
|
+
item = self.item(i)
|
154
|
+
item.setData(Qt.ItemDataRole.UserRole, QDate(year, 1, 1))
|
155
|
+
item.setSizeHint(self.sizeHint())
|
156
|
+
|
157
|
+
def scrollToDate(self, date: QDate):
|
158
|
+
page = (date.year() - self._startYear()) // 10
|
159
|
+
self.scrollToPage(page)
|
160
|
+
|
161
|
+
def currentPageRange(self):
|
162
|
+
year = self.currentPage * 10 + self._startYear()
|
163
|
+
return QDate(year, 1, 1), QDate(year + 9, 1, 1)
|
164
|
+
|
165
|
+
def _startYear(self):
|
166
|
+
if self.minYear % 10 <= 2:
|
167
|
+
return self.minYear - self.minYear % 10
|
168
|
+
|
169
|
+
return self.minYear - self.minYear % 10 + 10
|
170
|
+
|
171
|
+
def _updateItems(self):
|
172
|
+
start, _ = self.currentPageRange()
|
173
|
+
index = (start.year() - self.minYear) % 4
|
174
|
+
left = start.year() - index
|
175
|
+
right = left + 16
|
176
|
+
|
177
|
+
for i, year in enumerate(range(left, right)):
|
178
|
+
item = self.item(i)
|
179
|
+
item.setText(str(year))
|
180
|
+
item.setData(Qt.ItemDataRole.UserRole, QDate(year, 1, 1))
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
class FastMonthScrollView(FastScrollViewBase):
|
185
|
+
""" Month scroll view """
|
186
|
+
|
187
|
+
def __init__(self, parent=None):
|
188
|
+
super().__init__(FastYearScrollItemDelegate, parent)
|
189
|
+
self.delegate.setCurrentDate(QDate(self.currentDate.year(), self.currentDate.month(), 1))
|
190
|
+
|
191
|
+
def _initItems(self):
|
192
|
+
self.months = [
|
193
|
+
self.tr('Jan'), self.tr('Feb'), self.tr('Mar'), self.tr('Apr'),
|
194
|
+
self.tr('May'), self.tr('Jun'), self.tr('Jul'), self.tr('Aug'),
|
195
|
+
self.tr('Sep'), self.tr('Oct'), self.tr('Nov'), self.tr('Dec'),
|
196
|
+
self.tr('Jan'), self.tr('Feb'), self.tr('Mar'), self.tr('Apr'),
|
197
|
+
]
|
198
|
+
self.addItems(self.months)
|
199
|
+
|
200
|
+
# add month items
|
201
|
+
for i in range(len(self.months)):
|
202
|
+
year = i // 12 + self.minYear
|
203
|
+
m = i % 12 + 1
|
204
|
+
item = self.item(i)
|
205
|
+
item.setData(Qt.ItemDataRole.UserRole, QDate(year, m, 1))
|
206
|
+
item.setSizeHint(self.gridSize())
|
207
|
+
|
208
|
+
if year == self.currentDate.year() and m == self.currentDate.month():
|
209
|
+
self.delegate.setCurrentIndex(self.indexFromItem(item))
|
210
|
+
|
211
|
+
def scrollToDate(self, date: QDate):
|
212
|
+
page = date.year() - self.minYear
|
213
|
+
self.scrollToPage(page)
|
214
|
+
|
215
|
+
def currentPageRange(self):
|
216
|
+
year = self.minYear + self.currentPage
|
217
|
+
return QDate(year, 1, 1), QDate(year, 12, 31)
|
218
|
+
|
219
|
+
def pageCount(self):
|
220
|
+
return (self.maxYear - self.minYear + 1) * 12
|
221
|
+
|
222
|
+
def _updateItems(self):
|
223
|
+
year = self.minYear + self.currentPage
|
224
|
+
|
225
|
+
for i in range(16):
|
226
|
+
m = i % 12 + 1
|
227
|
+
y = year + (i > 11)
|
228
|
+
self.item(i).setData(Qt.ItemDataRole.UserRole, QDate(y, m, 1))
|
229
|
+
|
230
|
+
|
231
|
+
class FastDayScrollView(FastScrollViewBase):
|
232
|
+
""" Day scroll view """
|
233
|
+
|
234
|
+
def __init__(self, parent=None):
|
235
|
+
super().__init__(FastDayScrollItemDelegate, parent)
|
236
|
+
self.vBoxLayout = QHBoxLayout(self)
|
237
|
+
|
238
|
+
# add week day labels
|
239
|
+
self.weekDays = [
|
240
|
+
self.tr('Mo'), self.tr('Tu'), self.tr('We'),
|
241
|
+
self.tr('Th'), self.tr('Fr'), self.tr('Sa'), self.tr('Su')
|
242
|
+
]
|
243
|
+
self.weekDayGroup = QWidget(self)
|
244
|
+
self.weekDayLayout = QHBoxLayout(self.weekDayGroup)
|
245
|
+
self.weekDayGroup.setObjectName('weekDayGroup')
|
246
|
+
for day in self.weekDays:
|
247
|
+
label = QLabel(day)
|
248
|
+
label.setObjectName('weekDayLabel')
|
249
|
+
self.weekDayLayout.addWidget(label, 1, Qt.AlignHCenter)
|
250
|
+
|
251
|
+
self.setViewportMargins(0, 38, 0, 0)
|
252
|
+
self.vBoxLayout.setAlignment(Qt.AlignTop)
|
253
|
+
self.vBoxLayout.setContentsMargins(0, 0, 0, 0)
|
254
|
+
self.weekDayLayout.setSpacing(0)
|
255
|
+
self.weekDayLayout.setContentsMargins(3, 12, 3, 12)
|
256
|
+
self.vBoxLayout.addWidget(self.weekDayGroup)
|
257
|
+
|
258
|
+
def gridSize(self) -> QSize:
|
259
|
+
return QSize(44, 44)
|
260
|
+
|
261
|
+
def _initItems(self):
|
262
|
+
self.cols = 7
|
263
|
+
self.pageRows = 6
|
264
|
+
|
265
|
+
startDate = QDate(self.minYear, 1, 1)
|
266
|
+
currentDate = startDate
|
267
|
+
|
268
|
+
# add placeholder
|
269
|
+
bias = currentDate.dayOfWeek() - 1
|
270
|
+
for i in range(bias):
|
271
|
+
item = QListWidgetItem(self)
|
272
|
+
item.setFlags(Qt.ItemFlag.NoItemFlags)
|
273
|
+
self.addItem(item)
|
274
|
+
|
275
|
+
# add day items
|
276
|
+
items, dates = [], []
|
277
|
+
endDate = startDate.addDays(self.pageSize() - bias)
|
278
|
+
while currentDate < endDate:
|
279
|
+
items.append(str(currentDate.day()))
|
280
|
+
dates.append(QDate(currentDate))
|
281
|
+
currentDate = currentDate.addDays(1)
|
282
|
+
|
283
|
+
self.addItems(items)
|
284
|
+
for i in range(bias, self.count()):
|
285
|
+
item = self.item(i)
|
286
|
+
item.setData(Qt.ItemDataRole.UserRole, dates[i-bias])
|
287
|
+
item.setSizeHint(self.gridSize())
|
288
|
+
|
289
|
+
self.delegate.setCurrentIndex(
|
290
|
+
self.model().index(self._dateToRow(self.currentDate)))
|
291
|
+
|
292
|
+
def setDate(self, date: QDate):
|
293
|
+
self.scrollToDate(date)
|
294
|
+
self.delegate.setSelectedDate(date)
|
295
|
+
|
296
|
+
def scrollToDate(self, date: QDate):
|
297
|
+
page = (date.year() - self.minYear) * 12 + date.month() - 1
|
298
|
+
self.scrollToPage(page)
|
299
|
+
|
300
|
+
def currentPageRange(self):
|
301
|
+
date = self._pageToDate()
|
302
|
+
return date, date.addMonths(1).addDays(-1)
|
303
|
+
|
304
|
+
def _pageToDate(self):
|
305
|
+
year = self.currentPage // 12 + self.minYear
|
306
|
+
month = self.currentPage % 12 + 1
|
307
|
+
return QDate(year, month, 1)
|
308
|
+
|
309
|
+
def _dateToRow(self, date: QDate):
|
310
|
+
startDate = QDate(self.minYear, 1, 1)
|
311
|
+
days = startDate.daysTo(date)
|
312
|
+
return days + startDate.dayOfWeek() - 1
|
313
|
+
|
314
|
+
def _updateItems(self):
|
315
|
+
startDate = QDate(self.minYear, 1, 1)
|
316
|
+
bias = startDate.dayOfWeek() - 1
|
317
|
+
|
318
|
+
left = startDate.addMonths(self.currentPage)
|
319
|
+
left = left.addDays(-left.dayOfWeek() + 1)
|
320
|
+
right = left.addDays(self.pageRows * self.cols)
|
321
|
+
|
322
|
+
if self.currentPage == 0:
|
323
|
+
for i in range(bias):
|
324
|
+
self.item(i).setText("")
|
325
|
+
self.item(i).setFlags(Qt.ItemFlag.NoItemFlags)
|
326
|
+
|
327
|
+
currentDate = left
|
328
|
+
for i in range(left.daysTo(right)):
|
329
|
+
item = self.item(i + bias if self.currentPage == 0 else i)
|
330
|
+
if item:
|
331
|
+
item.setText(str(currentDate.day()))
|
332
|
+
item.setData(Qt.ItemDataRole.UserRole, currentDate)
|
333
|
+
currentDate = currentDate.addDays(1)
|
334
|
+
|
335
|
+
def mouseReleaseEvent(self, e):
|
336
|
+
super().mouseReleaseEvent(e)
|
337
|
+
item = self.currentItem()
|
338
|
+
if item:
|
339
|
+
self._setSelectedDate(item.data(Qt.ItemDataRole.UserRole))
|
340
|
+
|
341
|
+
def pageCount(self):
|
342
|
+
return (self.maxYear - self.minYear + 1) * 12
|
343
|
+
|
344
|
+
|
345
|
+
class FastYearCalendarView(CalendarViewBase):
|
346
|
+
""" Year calendar view """
|
347
|
+
|
348
|
+
def __init__(self, parent=None):
|
349
|
+
super().__init__(parent)
|
350
|
+
self.setScrollView(FastYearScrollView(self))
|
351
|
+
self.titleButton.setEnabled(False)
|
352
|
+
|
353
|
+
def _updateTitle(self):
|
354
|
+
left, right = self.scrollView.currentPageRange()
|
355
|
+
self.setTitle(f'{left.year()} - {right.year()}')
|
356
|
+
|
357
|
+
|
358
|
+
class FastMonthCalendarView(CalendarViewBase):
|
359
|
+
""" Month calendar view """
|
360
|
+
|
361
|
+
def __init__(self, parent=None):
|
362
|
+
super().__init__(parent)
|
363
|
+
self.setScrollView(FastMonthScrollView(self))
|
364
|
+
|
365
|
+
def _updateTitle(self):
|
366
|
+
date, _ = self.scrollView.currentPageRange()
|
367
|
+
self.setTitle(str(date.year()))
|
368
|
+
|
369
|
+
def currentPageDate(self) -> QDate:
|
370
|
+
date, _ = self.scrollView.currentPageRange()
|
371
|
+
item = self.scrollView.currentItem()
|
372
|
+
month = item.data(Qt.UserRole).month() if item else 1
|
373
|
+
return QDate(date.year(), month, 1)
|
374
|
+
|
375
|
+
|
376
|
+
class FastDayCalendarView(CalendarViewBase):
|
377
|
+
""" Day calendar view """
|
378
|
+
|
379
|
+
def __init__(self, parent=None):
|
380
|
+
super().__init__(parent)
|
381
|
+
self.setScrollView(FastDayScrollView(self))
|
382
|
+
|
383
|
+
def _updateTitle(self):
|
384
|
+
date = self.currentPageDate()
|
385
|
+
name = QCalendar().monthName(self.locale(), date.month(), date.year())
|
386
|
+
self.setTitle(f'{name} {date.year()}')
|
387
|
+
|
388
|
+
def currentPageDate(self) -> QDate:
|
389
|
+
date, _ = self.scrollView.currentPageRange()
|
390
|
+
return date
|
391
|
+
|
392
|
+
def scrollToDate(self, date: QDate):
|
393
|
+
self.scrollView.scrollToDate(date)
|
394
|
+
self._updateTitle()
|
395
|
+
|
396
|
+
|
397
|
+
class FastCalendarView(FlyoutViewBase):
|
398
|
+
|
399
|
+
dateChanged = Signal(QDate)
|
400
|
+
resetted = Signal()
|
401
|
+
|
402
|
+
def __init__(self, parent=None):
|
403
|
+
super().__init__(parent)
|
404
|
+
self.date = QDate()
|
405
|
+
self._isResetEnabled = False
|
406
|
+
|
407
|
+
self.hBoxLayout = QHBoxLayout(self)
|
408
|
+
self.stackedWidget = QStackedWidget(self)
|
409
|
+
self.yearView = FastYearCalendarView(self)
|
410
|
+
self.monthView = FastMonthCalendarView(self)
|
411
|
+
self.dayView = FastDayCalendarView(self)
|
412
|
+
|
413
|
+
self.__initWidget()
|
414
|
+
|
415
|
+
def __initWidget(self):
|
416
|
+
self.stackedWidget.addWidget(self.dayView)
|
417
|
+
self.stackedWidget.addWidget(self.monthView)
|
418
|
+
self.stackedWidget.addWidget(self.yearView)
|
419
|
+
|
420
|
+
self.hBoxLayout.setContentsMargins(0, 0, 0, 0)
|
421
|
+
self.hBoxLayout.addWidget(self.stackedWidget)
|
422
|
+
|
423
|
+
self.dayView.setDate(QDate.currentDate())
|
424
|
+
|
425
|
+
self.dayView.titleClicked.connect(self._onDayViewTitleClicked)
|
426
|
+
self.monthView.titleClicked.connect(self._onMonthTitleClicked)
|
427
|
+
|
428
|
+
self.monthView.itemClicked.connect(self._onMonthItemClicked)
|
429
|
+
self.yearView.itemClicked.connect(self._onYearItemClicked)
|
430
|
+
self.dayView.itemClicked.connect(self._onDayItemClicked)
|
431
|
+
|
432
|
+
self.monthView.resetted.connect(self._onResetted)
|
433
|
+
self.yearView.resetted.connect(self._onResetted)
|
434
|
+
self.dayView.resetted.connect(self._onResetted)
|
435
|
+
|
436
|
+
def isRestEnabled(self):
|
437
|
+
return self._isResetEnabled
|
438
|
+
|
439
|
+
def setResetEnabled(self, isEnabled: bool):
|
440
|
+
""" set the visibility of reset button """
|
441
|
+
self._isResetEnabled = isEnabled
|
442
|
+
self.yearView.setResetEnabled(isEnabled)
|
443
|
+
self.monthView.setResetEnabled(isEnabled)
|
444
|
+
self.dayView.setResetEnabled(isEnabled)
|
445
|
+
|
446
|
+
def _onResetted(self):
|
447
|
+
self.resetted.emit()
|
448
|
+
self.close()
|
449
|
+
|
450
|
+
def _onDayViewTitleClicked(self):
|
451
|
+
self.stackedWidget.setCurrentWidget(self.monthView)
|
452
|
+
self.monthView.setDate(self.dayView.currentPageDate())
|
453
|
+
|
454
|
+
def _onMonthTitleClicked(self):
|
455
|
+
self.stackedWidget.setCurrentWidget(self.yearView)
|
456
|
+
self.yearView.setDate(self.monthView.currentPageDate())
|
457
|
+
|
458
|
+
def _onMonthItemClicked(self, date: QDate):
|
459
|
+
self.stackedWidget.setCurrentWidget(self.dayView)
|
460
|
+
self.dayView.scrollToDate(date)
|
461
|
+
|
462
|
+
def _onYearItemClicked(self, date: QDate):
|
463
|
+
self.stackedWidget.setCurrentWidget(self.monthView)
|
464
|
+
self.monthView.setDate(date)
|
465
|
+
|
466
|
+
def _onDayItemClicked(self, date: QDate):
|
467
|
+
self.close()
|
468
|
+
if date != self.date:
|
469
|
+
self.date = date
|
470
|
+
self.dateChanged.emit(date)
|
471
|
+
|
472
|
+
def setDate(self, date: QDate):
|
473
|
+
""" set the selected date """
|
474
|
+
self.dayView.setDate(date)
|
475
|
+
self.date = date
|
476
|
+
|
477
|
+
def paintEvent(self, e):
|
478
|
+
painter = QPainter(self)
|
479
|
+
painter.setRenderHints(QPainter.RenderHint.Antialiasing)
|
480
|
+
|
481
|
+
painter.setBrush(
|
482
|
+
QColor(40, 40, 40) if isDarkTheme() else QColor(248, 248, 248))
|
483
|
+
painter.setPen(
|
484
|
+
QColor(23, 23, 23) if isDarkTheme() else QColor(234, 234, 234))
|
485
|
+
|
486
|
+
rect = self.rect().adjusted(1, 1, -1, -1)
|
487
|
+
painter.drawRoundedRect(rect, 8, 8)
|