monowidget 0.1__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.
- monowidget/__init__.py +14 -0
- monowidget/_utils/__init__.py +25 -0
- monowidget/_utils/const.py +14 -0
- monowidget/_utils/core.py +104 -0
- monowidget/_utils/ordered_dict.py +240 -0
- monowidget/_utils/qcalendar.py +195 -0
- monowidget/_utils/qdatetime.py +179 -0
- monowidget/_utils/qslabel.py +170 -0
- monowidget/_utils/qslider.py +155 -0
- monowidget/_utils/qspacer.py +15 -0
- monowidget/_utils/qtimeedit.py +112 -0
- monowidget/_utils/rangef.py +59 -0
- monowidget/_utils/reset_button.py +67 -0
- monowidget/_utils/validate_components.py +19 -0
- monowidget/inspector/__init__.py +40 -0
- monowidget/inspector/inspector_area.py +220 -0
- monowidget/inspector/mono_attr_item.py +73 -0
- monowidget/inspector/mono_attr_item_base.py +206 -0
- monowidget/inspector/mono_attr_item_bool.py +52 -0
- monowidget/inspector/mono_attr_item_complex.py +76 -0
- monowidget/inspector/mono_attr_item_datetime.py +173 -0
- monowidget/inspector/mono_attr_item_dict.py +529 -0
- monowidget/inspector/mono_attr_item_factory.py +147 -0
- monowidget/inspector/mono_attr_item_float.py +117 -0
- monowidget/inspector/mono_attr_item_function.py +108 -0
- monowidget/inspector/mono_attr_item_int.py +117 -0
- monowidget/inspector/mono_attr_item_list.py +409 -0
- monowidget/inspector/mono_attr_item_str.py +83 -0
- monowidget/inspector/mono_group.py +126 -0
- monowidget/inspector/mono_runtime.py +409 -0
- monowidget/inspector/mono_separator.py +56 -0
- monowidget/inspector/qmono_inspector.py +71 -0
- monowidget/inspector/ui_classes.py +13 -0
- monowidget/inspector/utils.py +79 -0
- monowidget/main.py +479 -0
- monowidget/mono/__init__.py +10 -0
- monowidget/mono/mono.py +12 -0
- monowidget/mono/mono_attr.py +114 -0
- monowidget-0.1.dist-info/METADATA +443 -0
- monowidget-0.1.dist-info/RECORD +42 -0
- monowidget-0.1.dist-info/WHEEL +5 -0
- monowidget-0.1.dist-info/top_level.txt +1 -0
monowidget/__init__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# monowidget 包初始化文件
|
|
2
|
+
# 导出主要的公共API
|
|
3
|
+
|
|
4
|
+
from .mono import Mono, MonoAttr
|
|
5
|
+
from .inspector import QMonoInspector, QMonoAttrItem
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
# 从_utils导出的所有公共API
|
|
9
|
+
# 从inspector导出的主要组件
|
|
10
|
+
'QMonoInspector',
|
|
11
|
+
'QMonoAttrItem',
|
|
12
|
+
'Mono',
|
|
13
|
+
'MonoAttr',
|
|
14
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# 导入核心功能
|
|
3
|
+
from monowidget._utils.core import *
|
|
4
|
+
|
|
5
|
+
# 导入常量
|
|
6
|
+
from monowidget._utils.const import (
|
|
7
|
+
MONO_FONT, MONO_HEADER_FONT, MONO_TITLE_FONT, MONO_INSPECTOR_FONT,
|
|
8
|
+
GROUP_INDENT, INSPECTOR_SPACE, QMONO_TITLE_COLOR
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
# 导入数据结构
|
|
12
|
+
from monowidget._utils.ordered_dict import *
|
|
13
|
+
from monowidget._utils.rangef import *
|
|
14
|
+
|
|
15
|
+
# 导入自定义组件
|
|
16
|
+
from monowidget._utils.qcalendar import *
|
|
17
|
+
from monowidget._utils.qdatetime import *
|
|
18
|
+
from monowidget._utils.qslabel import *
|
|
19
|
+
from monowidget._utils.qslider import *
|
|
20
|
+
from monowidget._utils.qspacer import *
|
|
21
|
+
from monowidget._utils.qtimeedit import *
|
|
22
|
+
from monowidget._utils.reset_button import *
|
|
23
|
+
|
|
24
|
+
# 导入验证脚本(已禁用)
|
|
25
|
+
# import _utils.validate_components
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Constants
|
|
2
|
+
from monowidget._utils.core import *
|
|
3
|
+
from PyQt6.QtGui import QFont, QColor
|
|
4
|
+
|
|
5
|
+
MONO_FONT = QFont('Consolas', 12, QFont.Weight.Bold)
|
|
6
|
+
MONO_HEADER_FONT = QFont('Consolas', 13, QFont.Weight.Bold)
|
|
7
|
+
MONO_TITLE_FONT = QFont('Consolas', 14, QFont.Weight.Bold)
|
|
8
|
+
MONO_INSPECTOR_FONT = QFont('Consolas', 16, QFont.Weight.Bold)
|
|
9
|
+
|
|
10
|
+
GROUP_INDENT = 32
|
|
11
|
+
INSPECTOR_SPACE = 2
|
|
12
|
+
QMONO_TITLE_COLOR = QColor(32, 144, 245, 225)
|
|
13
|
+
|
|
14
|
+
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import sys
|
|
3
|
+
import re
|
|
4
|
+
import types
|
|
5
|
+
import warnings
|
|
6
|
+
from rbpop import *
|
|
7
|
+
from abc import ABC, abstractmethod
|
|
8
|
+
from typing import Any, Dict, List, Tuple, Optional, Union
|
|
9
|
+
from monowidget._utils.const import *
|
|
10
|
+
from PyQt6.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QLabel, QSpinBox,
|
|
11
|
+
QDoubleSpinBox, QLineEdit, QCheckBox, QComboBox,
|
|
12
|
+
QPushButton, QApplication, QFrame, QScrollArea)
|
|
13
|
+
from PyQt6.QtCore import Qt, QPropertyAnimation, QPoint, QRect, pyqtSignal
|
|
14
|
+
from PyQt6.QtGui import QFont, QPainter, QPen, QColor, QBrush, QPixmap, QIcon
|
|
15
|
+
|
|
16
|
+
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
#region Monoa
|
|
20
|
+
class MonoaRuntimeEvalError(Exception):
|
|
21
|
+
def __init__(self, monoa, msg):
|
|
22
|
+
txt = f"\n\t{str(msg)}\n\n\tLineno:{monoa.lineno}, Target:\n\t\t{monoa}"
|
|
23
|
+
super().__init__(txt)
|
|
24
|
+
|
|
25
|
+
class MonoaRuntimeUnexpectedColor(MonoaRuntimeEvalError): pass
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class MonoaRuntimeDismatchedEnumType(MonoaRuntimeEvalError): pass
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class MonoaRuntimeDismatchedRangeType(MonoaRuntimeEvalError): pass
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def find_value_enum_closest(value: float, enum_list: List[Any]) -> Tuple[int, Any]:
|
|
35
|
+
"""找到最接近 value 的枚举值及其索引。"""
|
|
36
|
+
if not enum_list:
|
|
37
|
+
return -1, value
|
|
38
|
+
closest_value = min(enum_list, key=lambda x: abs(float(x) - value))
|
|
39
|
+
return enum_list.index(closest_value), closest_value
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def str_crop(s, size=200):
|
|
43
|
+
s = str(s)
|
|
44
|
+
if len(s) > size:
|
|
45
|
+
return s[:size] + '...'
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def api_hide_layout_widgets(layout):
|
|
49
|
+
for i in range(layout.count()):
|
|
50
|
+
item = layout.itemAt(i)
|
|
51
|
+
widget = item.widget()
|
|
52
|
+
if widget:
|
|
53
|
+
widget.hide()
|
|
54
|
+
else:
|
|
55
|
+
if item.layout():
|
|
56
|
+
api_hide_layout_widgets(item.layout())
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def api_show_layout_widgets(layout):
|
|
60
|
+
for i in range(layout.count()):
|
|
61
|
+
item = layout.itemAt(i)
|
|
62
|
+
widget = item.widget()
|
|
63
|
+
if widget:
|
|
64
|
+
widget.show()
|
|
65
|
+
else:
|
|
66
|
+
if item.layout():
|
|
67
|
+
api_show_layout_widgets(item.layout())
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def api_create_triangle_pixel(size: int, color: QColor = QColor("black"), direct="down"):
|
|
71
|
+
assert direct in ["down", "right"], "direct must be 'down' or 'right'"
|
|
72
|
+
pm = QPixmap(size, size)
|
|
73
|
+
pm.fill(QColor(0, 0, 0, 0))
|
|
74
|
+
painter = QPainter(pm)
|
|
75
|
+
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
76
|
+
painter.setPen(Qt.PenStyle.NoPen)
|
|
77
|
+
painter.setBrush(color)
|
|
78
|
+
if direct == "down":
|
|
79
|
+
points = [QPoint(0, 0), QPoint(size, 0), QPoint(size // 2, size)]
|
|
80
|
+
else:
|
|
81
|
+
points = [QPoint(0, 0), QPoint(0, size), QPoint(size, size // 2)]
|
|
82
|
+
painter.drawPolygon(*points)
|
|
83
|
+
painter.end()
|
|
84
|
+
return pm
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def api_merge_colors(*qc):
|
|
88
|
+
red_sum, green_sum, blue_sum, alpha_sum = 0, 0, 0, 0
|
|
89
|
+
count = 0
|
|
90
|
+
for color in qc:
|
|
91
|
+
weight, color = (color[0], color[1]) if isinstance(color, tuple) else (1, color)
|
|
92
|
+
red_sum += color.red() * weight
|
|
93
|
+
green_sum += color.green() * weight
|
|
94
|
+
blue_sum += color.blue() * weight
|
|
95
|
+
alpha_sum += color.alpha() * weight
|
|
96
|
+
count += weight
|
|
97
|
+
if count > 0:
|
|
98
|
+
return QColor(red_sum // count, green_sum // count, blue_sum // count, alpha_sum // count)
|
|
99
|
+
return QColor(0, 0, 0, 0)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
#endregion
|
|
103
|
+
|
|
104
|
+
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from monowidget._utils.core import *
|
|
3
|
+
from typing import Any, Dict, List, Iterable, Tuple
|
|
4
|
+
|
|
5
|
+
class IdOrderedDict(dict):
|
|
6
|
+
"""保持键创建顺序的有序字典
|
|
7
|
+
|
|
8
|
+
继承自Python内置dict,提供所有字典方法,同时维护键的创建顺序,并支持键的替换操作
|
|
9
|
+
内部使用一个列表来存储键的顺序
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
def __init__(self, data: Dict = None):
|
|
13
|
+
"""初始化有序字典
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
data: 可选的初始数据字典
|
|
17
|
+
"""
|
|
18
|
+
# 初始化内部键顺序列表
|
|
19
|
+
self._keys = []
|
|
20
|
+
|
|
21
|
+
# 调用父类dict的初始化
|
|
22
|
+
super().__init__()
|
|
23
|
+
|
|
24
|
+
if data is not None:
|
|
25
|
+
if isinstance(data, dict):
|
|
26
|
+
for k, v in data.items():
|
|
27
|
+
self[k] = v
|
|
28
|
+
elif isinstance(data, IdOrderedDict):
|
|
29
|
+
# 复制另一个IdOrderedDict的内容和顺序
|
|
30
|
+
super().update(data)
|
|
31
|
+
self._keys = data._keys.copy()
|
|
32
|
+
else:
|
|
33
|
+
# 处理其他可迭代对象
|
|
34
|
+
for k, v in data:
|
|
35
|
+
self[k] = v
|
|
36
|
+
|
|
37
|
+
def __setitem__(self, key: Any, value: Any):
|
|
38
|
+
"""设置键值对,如果键不存在则添加到顺序列表末尾"""
|
|
39
|
+
if key not in self:
|
|
40
|
+
self._keys.append(key)
|
|
41
|
+
super().__setitem__(key, value)
|
|
42
|
+
|
|
43
|
+
def __getitem__(self, key: Any) -> Any:
|
|
44
|
+
"""获取键对应的值"""
|
|
45
|
+
return super().__getitem__(key)
|
|
46
|
+
|
|
47
|
+
def __delitem__(self, key: Any):
|
|
48
|
+
"""删除键值对,并从顺序列表中移除"""
|
|
49
|
+
if key in self:
|
|
50
|
+
super().__delitem__(key)
|
|
51
|
+
self._keys.remove(key)
|
|
52
|
+
|
|
53
|
+
def __contains__(self, key: Any) -> bool:
|
|
54
|
+
"""检查键是否存在"""
|
|
55
|
+
return super().__contains__(key)
|
|
56
|
+
|
|
57
|
+
def __iter__(self):
|
|
58
|
+
"""迭代所有键,按照创建顺序"""
|
|
59
|
+
return iter(self._keys)
|
|
60
|
+
|
|
61
|
+
def __len__(self) -> int:
|
|
62
|
+
"""返回字典的长度"""
|
|
63
|
+
return super().__len__()
|
|
64
|
+
|
|
65
|
+
def __repr__(self) -> str:
|
|
66
|
+
"""返回字典的字符串表示"""
|
|
67
|
+
items = [f"{repr(k)}: {repr(v)}" for k, v in self.items()]
|
|
68
|
+
return f"IdOrderedDict({{{', '.join(items)}}})"
|
|
69
|
+
|
|
70
|
+
def __str__(self) -> str:
|
|
71
|
+
"""返回字典的字符串表示"""
|
|
72
|
+
return self.__repr__()
|
|
73
|
+
|
|
74
|
+
def replace(self, old_key: Any, new_key: Any) -> bool:
|
|
75
|
+
"""替换键名,保持原有的顺序位置
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
old_key: 要替换的旧键名
|
|
79
|
+
new_key: 新的键名
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
bool: 替换是否成功
|
|
83
|
+
"""
|
|
84
|
+
if old_key not in self:
|
|
85
|
+
return False
|
|
86
|
+
|
|
87
|
+
# 如果新键与旧键相同,不需要操作
|
|
88
|
+
if old_key == new_key:
|
|
89
|
+
return True
|
|
90
|
+
|
|
91
|
+
# 获取旧键的值
|
|
92
|
+
value = self[old_key]
|
|
93
|
+
|
|
94
|
+
# 获取旧键的位置
|
|
95
|
+
index = self._keys.index(old_key)
|
|
96
|
+
|
|
97
|
+
# 删除旧键
|
|
98
|
+
del self[old_key]
|
|
99
|
+
del self._keys[index] # 确保从键列表中删除旧键
|
|
100
|
+
|
|
101
|
+
# 如果新键已存在,先从字典和顺序列表中移除
|
|
102
|
+
if new_key in self:
|
|
103
|
+
del self[new_key]
|
|
104
|
+
if new_key in self._keys:
|
|
105
|
+
self._keys.remove(new_key)
|
|
106
|
+
|
|
107
|
+
# 在原位置插入新键
|
|
108
|
+
self._keys.insert(index, new_key)
|
|
109
|
+
|
|
110
|
+
# 设置新键的值
|
|
111
|
+
super().__setitem__(new_key, value)
|
|
112
|
+
|
|
113
|
+
return True
|
|
114
|
+
|
|
115
|
+
def keys(self) -> List:
|
|
116
|
+
"""返回所有键的列表,按照创建顺序"""
|
|
117
|
+
return self._keys.copy()
|
|
118
|
+
|
|
119
|
+
def values(self) -> List:
|
|
120
|
+
"""返回所有值的列表,按照键的创建顺序"""
|
|
121
|
+
return [self[k] for k in self._keys]
|
|
122
|
+
|
|
123
|
+
def items(self) -> List[Tuple]:
|
|
124
|
+
"""返回所有键值对的列表,按照键的创建顺序"""
|
|
125
|
+
return [(k, self[k]) for k in self._keys]
|
|
126
|
+
|
|
127
|
+
def get(self, key: Any, default: Any = None) -> Any:
|
|
128
|
+
"""获取键对应的值,如果键不存在则返回默认值"""
|
|
129
|
+
return super().get(key, default)
|
|
130
|
+
|
|
131
|
+
def setdefault(self, key: Any, default: Any = None) -> Any:
|
|
132
|
+
"""获取键对应的值,如果键不存在则设置默认值并返回"""
|
|
133
|
+
if key not in self:
|
|
134
|
+
self[key] = default
|
|
135
|
+
return self[key]
|
|
136
|
+
|
|
137
|
+
def update(self, other: Dict) -> None:
|
|
138
|
+
"""更新字典,按照other中的键值对更新当前字典
|
|
139
|
+
|
|
140
|
+
对于other中的每个键值对:
|
|
141
|
+
- 如果键不存在于当前字典,则添加到顺序列表末尾
|
|
142
|
+
- 如果键已存在于当前字典,则更新值但保持顺序不变
|
|
143
|
+
"""
|
|
144
|
+
if isinstance(other, IdOrderedDict):
|
|
145
|
+
# 对于IdOrderedDict,保持其键的顺序
|
|
146
|
+
for k, v in other.items():
|
|
147
|
+
self[k] = v
|
|
148
|
+
else:
|
|
149
|
+
# 对于普通字典或其他可迭代对象,按照迭代顺序添加
|
|
150
|
+
if isinstance(other, dict):
|
|
151
|
+
items = other.items()
|
|
152
|
+
else:
|
|
153
|
+
items = other
|
|
154
|
+
|
|
155
|
+
for k, v in items:
|
|
156
|
+
self[k] = v
|
|
157
|
+
|
|
158
|
+
def clear(self) -> None:
|
|
159
|
+
"""清空字典"""
|
|
160
|
+
super().clear()
|
|
161
|
+
self._keys.clear()
|
|
162
|
+
|
|
163
|
+
def copy(self) -> 'IdOrderedDict':
|
|
164
|
+
"""创建字典的浅拷贝"""
|
|
165
|
+
new_dict = IdOrderedDict()
|
|
166
|
+
new_dict.update(self)
|
|
167
|
+
new_dict._keys = self._keys.copy()
|
|
168
|
+
return new_dict
|
|
169
|
+
|
|
170
|
+
def pop(self, key: Any, default: Any = None) -> Any:
|
|
171
|
+
"""删除并返回指定键的值,如果键不存在则返回默认值"""
|
|
172
|
+
if key in self:
|
|
173
|
+
value = self[key]
|
|
174
|
+
del self[key]
|
|
175
|
+
return value
|
|
176
|
+
elif default is not None:
|
|
177
|
+
return default
|
|
178
|
+
else:
|
|
179
|
+
raise KeyError(key)
|
|
180
|
+
|
|
181
|
+
def popitem(self) -> Tuple[Any, Any]:
|
|
182
|
+
"""删除并返回最后一个键值对"""
|
|
183
|
+
if not self._keys:
|
|
184
|
+
raise KeyError("popitem from an empty IdOrderedDict")
|
|
185
|
+
|
|
186
|
+
key = self._keys[-1]
|
|
187
|
+
value = self[key]
|
|
188
|
+
del self[key]
|
|
189
|
+
return key, value
|
|
190
|
+
|
|
191
|
+
def fromkeys(cls, keys: Iterable, value: Any = None) -> 'IdOrderedDict':
|
|
192
|
+
"""创建一个新的IdOrderedDict,使用给定的键和默认值"""
|
|
193
|
+
new_dict = cls()
|
|
194
|
+
for key in keys:
|
|
195
|
+
new_dict[key] = value
|
|
196
|
+
return new_dict
|
|
197
|
+
|
|
198
|
+
fromkeys = classmethod(fromkeys)
|
|
199
|
+
|
|
200
|
+
def move_to_end(self, key: Any, last: bool = True) -> None:
|
|
201
|
+
"""将指定的键移动到顺序列表的开头或末尾
|
|
202
|
+
|
|
203
|
+
Args:
|
|
204
|
+
key: 要移动的键
|
|
205
|
+
last: True表示移动到末尾,False表示移动到开头
|
|
206
|
+
"""
|
|
207
|
+
if key not in self._dict:
|
|
208
|
+
raise KeyError(key)
|
|
209
|
+
|
|
210
|
+
self._keys.remove(key)
|
|
211
|
+
if last:
|
|
212
|
+
self._keys.append(key)
|
|
213
|
+
else:
|
|
214
|
+
self._keys.insert(0, key)
|
|
215
|
+
|
|
216
|
+
def get_key_at_index(self, index: int) -> Any:
|
|
217
|
+
"""根据索引获取键
|
|
218
|
+
|
|
219
|
+
Args:
|
|
220
|
+
index: 键的索引位置
|
|
221
|
+
|
|
222
|
+
Returns:
|
|
223
|
+
Any: 键的值
|
|
224
|
+
"""
|
|
225
|
+
if index < 0 or index >= len(self._keys):
|
|
226
|
+
raise IndexError("list index out of range")
|
|
227
|
+
return self._keys[index]
|
|
228
|
+
|
|
229
|
+
def get_index_of_key(self, key: Any) -> int:
|
|
230
|
+
"""获取键的索引位置
|
|
231
|
+
|
|
232
|
+
Args:
|
|
233
|
+
key: 要查找的键
|
|
234
|
+
|
|
235
|
+
Returns:
|
|
236
|
+
int: 键的索引位置
|
|
237
|
+
"""
|
|
238
|
+
if key not in self._keys:
|
|
239
|
+
raise KeyError(key)
|
|
240
|
+
return self._keys.index(key)
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"""
|
|
2
|
+
自定义日历组件
|
|
3
|
+
提供现代化的日历选择界面
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from monowidget._utils.core import *
|
|
7
|
+
from PyQt6.QtWidgets import QCalendarWidget
|
|
8
|
+
from PyQt6.QtCore import Qt
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class QMonoCalendarWidget(QCalendarWidget):
|
|
12
|
+
"""现代化日历组件"""
|
|
13
|
+
|
|
14
|
+
def __init__(self, parent=None):
|
|
15
|
+
super().__init__(parent)
|
|
16
|
+
self.setGridVisible(True)
|
|
17
|
+
self.setup_weekday_format()
|
|
18
|
+
self.setup_styles()
|
|
19
|
+
|
|
20
|
+
def setup_styles(self):
|
|
21
|
+
"""设置日历样式 - 改进版本"""
|
|
22
|
+
self.setStyleSheet("""
|
|
23
|
+
QCalendarWidget {
|
|
24
|
+
background-color: white;
|
|
25
|
+
border: 1px solid #e0e0e0;
|
|
26
|
+
border-radius: 8px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* 导航栏月份和年份按钮 - 加宽紧凑版本 */
|
|
30
|
+
QCalendarWidget QToolButton {
|
|
31
|
+
background-color: white;
|
|
32
|
+
border: 1px solid #e0e0e0;
|
|
33
|
+
color: #333;
|
|
34
|
+
font-size: 12px;
|
|
35
|
+
font-weight: bold;
|
|
36
|
+
padding: 4px 12px;
|
|
37
|
+
border-radius: 4px;
|
|
38
|
+
min-width: 80px;
|
|
39
|
+
max-width: 120px;
|
|
40
|
+
min-height: 24px;
|
|
41
|
+
max-height: 24px;
|
|
42
|
+
margin: 1px;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
QCalendarWidget QToolButton:hover {
|
|
46
|
+
background-color: #f5f5f5;
|
|
47
|
+
border-color: #ccc;
|
|
48
|
+
min-height: 24px;
|
|
49
|
+
max-height: 24px;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
QCalendarWidget QToolButton:pressed {
|
|
53
|
+
background-color: #e8e8e8;
|
|
54
|
+
min-height: 24px;
|
|
55
|
+
max-height: 24px;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
QCalendarWidget QToolButton::menu-indicator {
|
|
59
|
+
image: none;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* 月份导航按钮 - 圆形版本 */
|
|
63
|
+
QCalendarWidget QToolButton#qt_calendar_prevmonth,
|
|
64
|
+
QCalendarWidget QToolButton#qt_calendar_nextmonth,
|
|
65
|
+
QCalendarWidget QToolButton#qt_calendar_prevyear,
|
|
66
|
+
QCalendarWidget QToolButton#qt_calendar_nextyear {
|
|
67
|
+
background-color: white;
|
|
68
|
+
border: 1px solid #e0e0e0;
|
|
69
|
+
border-radius: 10px; /* 圆形:半径=宽高的一半 */
|
|
70
|
+
width: 20px;
|
|
71
|
+
height: 20px;
|
|
72
|
+
font-size: 10px;
|
|
73
|
+
qproperty-icon: none;
|
|
74
|
+
margin: 1px;
|
|
75
|
+
min-width: 20px;
|
|
76
|
+
max-width: 20px;
|
|
77
|
+
min-height: 20px;
|
|
78
|
+
max-height: 20px;
|
|
79
|
+
padding: 0px;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
QCalendarWidget QToolButton#qt_calendar_prevmonth {
|
|
83
|
+
qproperty-text: "‹";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
QCalendarWidget QToolButton#qt_calendar_nextmonth {
|
|
87
|
+
qproperty-text: "›";
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
QCalendarWidget QToolButton#qt_calendar_prevyear {
|
|
91
|
+
qproperty-text: "«";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
QCalendarWidget QToolButton#qt_calendar_nextyear {
|
|
95
|
+
qproperty-text: "»";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
QCalendarWidget QToolButton#qt_calendar_prevmonth:hover,
|
|
99
|
+
QCalendarWidget QToolButton#qt_calendar_nextmonth:hover,
|
|
100
|
+
QCalendarWidget QToolButton#qt_calendar_prevyear:hover,
|
|
101
|
+
QCalendarWidget QToolButton#qt_calendar_nextyear:hover {
|
|
102
|
+
background-color: #f5f5f5;
|
|
103
|
+
border-color: #ccc;
|
|
104
|
+
border-radius: 10px; /* 保持圆形 */
|
|
105
|
+
min-height: 20px;
|
|
106
|
+
max-height: 20px;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
QCalendarWidget QToolButton#qt_calendar_prevmonth:pressed,
|
|
110
|
+
QCalendarWidget QToolButton#qt_calendar_nextmonth:pressed,
|
|
111
|
+
QCalendarWidget QToolButton#qt_calendar_prevyear:pressed,
|
|
112
|
+
QCalendarWidget QToolButton#qt_calendar_nextyear:pressed {
|
|
113
|
+
background-color: #e8e8e8;
|
|
114
|
+
border-radius: 10px; /* 保持圆形 */
|
|
115
|
+
min-height: 20px;
|
|
116
|
+
max-height: 20px;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* 星期标题 - 去掉'周'字 */
|
|
120
|
+
QCalendarWidget QTableView QHeaderView::section {
|
|
121
|
+
background-color: #f8f8f8;
|
|
122
|
+
color: #666;
|
|
123
|
+
font-size: 12px;
|
|
124
|
+
font-weight: bold;
|
|
125
|
+
padding: 4px;
|
|
126
|
+
border: none;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/* 设置星期标题文本格式 */
|
|
130
|
+
QCalendarWidget QTableView QHeaderView::section:horizontal {
|
|
131
|
+
text-align: center;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* 日期单元格 */
|
|
135
|
+
QCalendarWidget QTableView {
|
|
136
|
+
alternate-background-color: white;
|
|
137
|
+
selection-background-color: #4CAF50;
|
|
138
|
+
selection-color: white;
|
|
139
|
+
font-size: 12px;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
QCalendarWidget QTableView::item {
|
|
143
|
+
padding: 2px;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
QCalendarWidget QTableView::item:selected {
|
|
147
|
+
background-color: #4CAF50;
|
|
148
|
+
color: white;
|
|
149
|
+
border-radius: 4px;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
QCalendarWidget QTableView::item:hover {
|
|
153
|
+
background-color: #E8F5E8;
|
|
154
|
+
border-radius: 4px;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/* 当前日期高亮 */
|
|
158
|
+
QCalendarWidget QTableView::item:focus {
|
|
159
|
+
background-color: #4CAF50;
|
|
160
|
+
color: white;
|
|
161
|
+
border-radius: 4px;
|
|
162
|
+
}
|
|
163
|
+
""")
|
|
164
|
+
|
|
165
|
+
def set_custom_date_format(self, date_format):
|
|
166
|
+
"""设置自定义日期格式"""
|
|
167
|
+
self.setDisplayFormat(date_format)
|
|
168
|
+
|
|
169
|
+
def get_selected_date(self):
|
|
170
|
+
"""获取选中的日期"""
|
|
171
|
+
return self.selectedDate()
|
|
172
|
+
|
|
173
|
+
def set_minimum_date(self, date):
|
|
174
|
+
"""设置最小可选日期"""
|
|
175
|
+
self.setMinimumDate(date)
|
|
176
|
+
|
|
177
|
+
def set_maximum_date(self, date):
|
|
178
|
+
"""设置最大可选日期"""
|
|
179
|
+
self.setMaximumDate(date)
|
|
180
|
+
|
|
181
|
+
def setup_weekday_format(self):
|
|
182
|
+
"""设置星期显示格式,只显示"一"到"日",去掉周数列"""
|
|
183
|
+
# 设置星期从周一开始
|
|
184
|
+
self.setFirstDayOfWeek(Qt.DayOfWeek.Monday)
|
|
185
|
+
|
|
186
|
+
# 使用单字母格式显示星期,配合中文环境会显示"一"到"日"
|
|
187
|
+
self.setHorizontalHeaderFormat(QCalendarWidget.HorizontalHeaderFormat.SingleLetterDayNames)
|
|
188
|
+
|
|
189
|
+
# 去掉周数列(垂直标题)
|
|
190
|
+
self.setVerticalHeaderFormat(QCalendarWidget.VerticalHeaderFormat.NoVerticalHeader)
|
|
191
|
+
|
|
192
|
+
# 设置中文本地化,确保显示为"一"到"日"
|
|
193
|
+
from PyQt6.QtCore import QLocale
|
|
194
|
+
locale = QLocale(QLocale.Language.Chinese, QLocale.Country.China)
|
|
195
|
+
self.setLocale(locale)
|