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
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"""
|
|
2
|
+
美观的日历选择器组件
|
|
3
|
+
提供更现代化的日期选择界面
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from monowidget._utils.core import *
|
|
7
|
+
from PyQt6.QtWidgets import QDateTimeEdit, QVBoxLayout, QWidget, QHBoxLayout, QLabel
|
|
8
|
+
from PyQt6.QtCore import QDate, QDateTime, QTime
|
|
9
|
+
from monowidget._utils.qcalendar import QMonoCalendarWidget
|
|
10
|
+
from monowidget._utils.qtimeedit import QMonoTimeEdit
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class QMonoDateTimeEdit(QWidget):
|
|
14
|
+
"""现代化日期时间编辑组件,由QMonoCalendarWidget和QMonoTimeEdit组合而成"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, parent=None):
|
|
17
|
+
super().__init__(parent)
|
|
18
|
+
self._setup_ui()
|
|
19
|
+
self._connect_signals()
|
|
20
|
+
|
|
21
|
+
def _setup_ui(self):
|
|
22
|
+
"""设置用户界面"""
|
|
23
|
+
# 创建主布局
|
|
24
|
+
main_layout = QVBoxLayout(self)
|
|
25
|
+
main_layout.setContentsMargins(0, 0, 0, 0)
|
|
26
|
+
main_layout.setSpacing(10)
|
|
27
|
+
|
|
28
|
+
# 创建日期时间编辑框
|
|
29
|
+
self.datetime_edit = QDateTimeEdit()
|
|
30
|
+
self.datetime_edit.setCalendarPopup(True)
|
|
31
|
+
self.datetime_edit.setDisplayFormat("yyyy-MM-dd HH:mm:ss")
|
|
32
|
+
self.datetime_edit.setDateTime(QDateTime.currentDateTime())
|
|
33
|
+
|
|
34
|
+
# 设置日期时间编辑框样式
|
|
35
|
+
self.datetime_edit.setStyleSheet("""
|
|
36
|
+
QDateTimeEdit {
|
|
37
|
+
padding: 8px 12px;
|
|
38
|
+
border: 2px solid #e0e0e0;
|
|
39
|
+
border-radius: 8px;
|
|
40
|
+
background-color: white;
|
|
41
|
+
font-size: 14px;
|
|
42
|
+
min-width: 200px;
|
|
43
|
+
font-family: 'Consolas', 'Monaco', monospace;
|
|
44
|
+
}
|
|
45
|
+
QDateTimeEdit:focus {
|
|
46
|
+
border-color: #4CAF50;
|
|
47
|
+
outline: none;
|
|
48
|
+
background-color: #f9fff9;
|
|
49
|
+
}
|
|
50
|
+
QDateTimeEdit:hover {
|
|
51
|
+
border-color: #bbb;
|
|
52
|
+
}
|
|
53
|
+
QDateTimeEdit::drop-down {
|
|
54
|
+
border: none;
|
|
55
|
+
width: 30px;
|
|
56
|
+
background-color: transparent;
|
|
57
|
+
}
|
|
58
|
+
QDateTimeEdit::down-arrow {
|
|
59
|
+
image: none;
|
|
60
|
+
border-left: 1px solid #e0e0e0;
|
|
61
|
+
margin-left: 5px;
|
|
62
|
+
}
|
|
63
|
+
""")
|
|
64
|
+
|
|
65
|
+
# 创建自定义日历
|
|
66
|
+
self.calendar = QMonoCalendarWidget()
|
|
67
|
+
self.datetime_edit.setCalendarWidget(self.calendar)
|
|
68
|
+
|
|
69
|
+
# 创建时间编辑组件
|
|
70
|
+
self.time_edit = QMonoTimeEdit()
|
|
71
|
+
self.time_edit.set_custom_time_format("HH:mm:ss")
|
|
72
|
+
|
|
73
|
+
# 创建日期显示标签
|
|
74
|
+
date_label = QLabel("日期:")
|
|
75
|
+
date_label.setStyleSheet("""
|
|
76
|
+
QLabel {
|
|
77
|
+
font-size: 13px;
|
|
78
|
+
color: #666;
|
|
79
|
+
font-weight: bold;
|
|
80
|
+
}
|
|
81
|
+
""")
|
|
82
|
+
|
|
83
|
+
# 创建时间显示标签
|
|
84
|
+
time_label = QLabel("时间:")
|
|
85
|
+
time_label.setStyleSheet("""
|
|
86
|
+
QLabel {
|
|
87
|
+
font-size: 13px;
|
|
88
|
+
color: #666;
|
|
89
|
+
font-weight: bold;
|
|
90
|
+
}
|
|
91
|
+
""")
|
|
92
|
+
|
|
93
|
+
# 创建日期时间组合布局
|
|
94
|
+
datetime_layout = QHBoxLayout()
|
|
95
|
+
datetime_layout.addWidget(date_label)
|
|
96
|
+
datetime_layout.addWidget(self.datetime_edit)
|
|
97
|
+
datetime_layout.addWidget(time_label)
|
|
98
|
+
datetime_layout.addWidget(self.time_edit)
|
|
99
|
+
datetime_layout.addStretch()
|
|
100
|
+
|
|
101
|
+
# 添加到主布局
|
|
102
|
+
main_layout.addLayout(datetime_layout)
|
|
103
|
+
|
|
104
|
+
def _connect_signals(self):
|
|
105
|
+
"""连接信号和槽"""
|
|
106
|
+
# 当时间编辑改变时,同步到日期时间编辑
|
|
107
|
+
self.time_edit.timeChanged.connect(self._sync_time_to_datetime)
|
|
108
|
+
|
|
109
|
+
# 当日期时间编辑改变时,同步到时间编辑
|
|
110
|
+
self.datetime_edit.dateTimeChanged.connect(self._sync_datetime_to_time)
|
|
111
|
+
|
|
112
|
+
def _sync_time_to_datetime(self, time):
|
|
113
|
+
"""同步时间到日期时间编辑"""
|
|
114
|
+
current_datetime = self.datetime_edit.dateTime()
|
|
115
|
+
new_datetime = QDateTime(current_datetime.date(), time)
|
|
116
|
+
self.datetime_edit.setDateTime(new_datetime)
|
|
117
|
+
|
|
118
|
+
def _sync_datetime_to_time(self, datetime):
|
|
119
|
+
"""同步日期时间到时间编辑"""
|
|
120
|
+
self.time_edit.setTime(datetime.time())
|
|
121
|
+
|
|
122
|
+
def get_date_time(self):
|
|
123
|
+
"""获取当前日期时间"""
|
|
124
|
+
return self.datetime_edit.dateTime()
|
|
125
|
+
|
|
126
|
+
def set_date_time(self, datetime):
|
|
127
|
+
"""设置日期时间"""
|
|
128
|
+
self.datetime_edit.setDateTime(datetime)
|
|
129
|
+
self.time_edit.setTime(datetime.time())
|
|
130
|
+
|
|
131
|
+
def get_date(self):
|
|
132
|
+
"""获取当前日期"""
|
|
133
|
+
return self.datetime_edit.date()
|
|
134
|
+
|
|
135
|
+
def set_date(self, date):
|
|
136
|
+
"""设置日期"""
|
|
137
|
+
current_time = self.time_edit.time()
|
|
138
|
+
new_datetime = QDateTime(date, current_time)
|
|
139
|
+
self.datetime_edit.setDateTime(new_datetime)
|
|
140
|
+
|
|
141
|
+
def get_time(self):
|
|
142
|
+
"""获取当前时间"""
|
|
143
|
+
return self.time_edit.time()
|
|
144
|
+
|
|
145
|
+
def set_time(self, time):
|
|
146
|
+
"""设置时间"""
|
|
147
|
+
self.time_edit.setTime(time)
|
|
148
|
+
current_date = self.datetime_edit.date()
|
|
149
|
+
new_datetime = QDateTime(current_date, time)
|
|
150
|
+
self.datetime_edit.setDateTime(new_datetime)
|
|
151
|
+
|
|
152
|
+
def set_display_format(self, format_str):
|
|
153
|
+
"""设置显示格式"""
|
|
154
|
+
self.datetime_edit.setDisplayFormat(format_str)
|
|
155
|
+
|
|
156
|
+
def set_date_range(self, min_date, max_date):
|
|
157
|
+
"""设置日期范围"""
|
|
158
|
+
self.datetime_edit.setMinimumDate(min_date)
|
|
159
|
+
self.datetime_edit.setMaximumDate(max_date)
|
|
160
|
+
self.calendar.set_minimum_date(min_date)
|
|
161
|
+
self.calendar.set_maximum_date(max_date)
|
|
162
|
+
|
|
163
|
+
def set_time_range(self, min_time, max_time):
|
|
164
|
+
"""设置时间范围"""
|
|
165
|
+
self.time_edit.set_time_range(min_time, max_time)
|
|
166
|
+
|
|
167
|
+
def set_read_only(self, read_only):
|
|
168
|
+
"""设置只读模式"""
|
|
169
|
+
self.datetime_edit.setReadOnly(read_only)
|
|
170
|
+
self.time_edit.set_read_only(read_only)
|
|
171
|
+
|
|
172
|
+
def is_read_only(self):
|
|
173
|
+
"""检查是否为只读模式"""
|
|
174
|
+
return self.datetime_edit.isReadOnly()
|
|
175
|
+
|
|
176
|
+
def set_enabled(self, enabled):
|
|
177
|
+
"""设置启用状态"""
|
|
178
|
+
self.datetime_edit.setEnabled(enabled)
|
|
179
|
+
self.time_edit.setEnabled(enabled)
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
QShadowLabel
|
|
4
|
+
text: str 显示文本
|
|
5
|
+
color: QColor | None 文字颜色(默认黑色)
|
|
6
|
+
bg_color: QColor | None 背景颜色(None=透明)
|
|
7
|
+
shadow_blur: int 阴影模糊半径(层数)
|
|
8
|
+
shadow_color: QColor | None 阴影颜色(默认文字颜色 1/4 亮度)
|
|
9
|
+
reversed: bool 阴影渐变方向(True=内深外淡)
|
|
10
|
+
alignment: Qt.Alignment 文本对齐方式(默认居中)
|
|
11
|
+
parent: QWidget
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from monowidget._utils.core import *
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class QShadowLabel(QLabel):
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
text: str,
|
|
21
|
+
color: QColor = None,
|
|
22
|
+
bg_color: QColor = None,
|
|
23
|
+
shadow_blur: int = 3,
|
|
24
|
+
shadow_color: QColor = None,
|
|
25
|
+
reversed: bool = False,
|
|
26
|
+
alignment: Qt.AlignmentFlag = Qt.AlignmentFlag.AlignCenter,
|
|
27
|
+
parent=None,
|
|
28
|
+
):
|
|
29
|
+
super().__init__(text, parent)
|
|
30
|
+
|
|
31
|
+
# 文字颜色
|
|
32
|
+
self._txt_color = color or QColor("black")
|
|
33
|
+
# 背景颜色
|
|
34
|
+
self._bg_color = bg_color
|
|
35
|
+
# 阴影半径/层数
|
|
36
|
+
self._radius = max(0, shadow_blur)
|
|
37
|
+
# 阴影颜色:默认取文字颜色 1/4 亮度
|
|
38
|
+
self._shd_color = shadow_color or QColor(
|
|
39
|
+
self._txt_color.red() // 4,
|
|
40
|
+
self._txt_color.green() // 4,
|
|
41
|
+
self._txt_color.blue() // 4,
|
|
42
|
+
self._txt_color.alpha()
|
|
43
|
+
)
|
|
44
|
+
# 渐变方向
|
|
45
|
+
self._reversed = reversed
|
|
46
|
+
# 对齐方式
|
|
47
|
+
self._alignment = alignment
|
|
48
|
+
|
|
49
|
+
# 默认字体(可按需再设)
|
|
50
|
+
self.setFont(QFont("Consolas", 12, QFont.Weight.Bold))
|
|
51
|
+
|
|
52
|
+
# ------------- 属性访问器 -------------
|
|
53
|
+
# 如需运行时调节,可继续添加 setXxx 接口
|
|
54
|
+
def setShadowColor(self, color: QColor):
|
|
55
|
+
self._shd_color = color
|
|
56
|
+
self.update()
|
|
57
|
+
|
|
58
|
+
def setShadowRadius(self, radius: int):
|
|
59
|
+
self._radius = max(0, radius)
|
|
60
|
+
self.update()
|
|
61
|
+
|
|
62
|
+
def setReversed(self, rev: bool):
|
|
63
|
+
self._reversed = rev
|
|
64
|
+
self.update()
|
|
65
|
+
|
|
66
|
+
# ------------- 绘制 -------------
|
|
67
|
+
def paintEvent(self, _):
|
|
68
|
+
painter = QPainter(self)
|
|
69
|
+
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
70
|
+
|
|
71
|
+
# 1. 背景填充
|
|
72
|
+
if self._bg_color:
|
|
73
|
+
painter.fillRect(self.rect(), self._bg_color)
|
|
74
|
+
|
|
75
|
+
# 2. 文字矩形
|
|
76
|
+
rect = self.rect()
|
|
77
|
+
|
|
78
|
+
# 3. 逐层绘制阴影
|
|
79
|
+
init_alpha = self._shd_color.alpha()
|
|
80
|
+
color = QColor(self._shd_color.red(), self._shd_color.green(), self._shd_color.blue())
|
|
81
|
+
|
|
82
|
+
for i in range(self._radius, -1, -1):
|
|
83
|
+
if self._radius == 0:
|
|
84
|
+
coef = 1.0
|
|
85
|
+
else:
|
|
86
|
+
coef = (i / self._radius) if not self._reversed else (1 - i / self._radius)
|
|
87
|
+
color.setAlpha(int(init_alpha * coef + 0.5))
|
|
88
|
+
painter.setPen(color)
|
|
89
|
+
painter.setFont(self.font())
|
|
90
|
+
painter.drawText(
|
|
91
|
+
rect.adjusted(i, i, i, i), # 偏移
|
|
92
|
+
self._alignment,
|
|
93
|
+
self.text()
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
# 4. 绘制前景文字
|
|
97
|
+
painter.setPen(QPen(self._txt_color))
|
|
98
|
+
painter.setFont(self.font())
|
|
99
|
+
painter.drawText(rect, self._alignment, self.text())
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class QMonoLogo(QWidget):
|
|
104
|
+
"""
|
|
105
|
+
水平 Logo,默认文字 “Mono Widget”。
|
|
106
|
+
align 只控制整体在控件内的左 / 中 / 右排布。
|
|
107
|
+
"""
|
|
108
|
+
def __init__(
|
|
109
|
+
self,
|
|
110
|
+
logo_str: str = "Mono Widget",
|
|
111
|
+
parent=None,
|
|
112
|
+
align=Qt.AlignmentFlag.AlignCenter,
|
|
113
|
+
shadow_blur: int = 2, # 新增:阴影半径
|
|
114
|
+
shadow_color: QColor = None, # 新增:阴影颜色
|
|
115
|
+
reversed_shadow: bool = False, # 新增:渐变方向
|
|
116
|
+
):
|
|
117
|
+
super().__init__(parent)
|
|
118
|
+
|
|
119
|
+
self._layout = QHBoxLayout(self)
|
|
120
|
+
self._layout.setContentsMargins(0, 0, 0, 0)
|
|
121
|
+
self._layout.setSpacing(0)
|
|
122
|
+
|
|
123
|
+
self._add_mono_title(
|
|
124
|
+
logo_str,
|
|
125
|
+
align,
|
|
126
|
+
shadow_blur=shadow_blur,
|
|
127
|
+
shadow_color=shadow_color,
|
|
128
|
+
reversed_shadow=reversed_shadow,
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
# 抽出来方便复用
|
|
132
|
+
def _add_mono_title(
|
|
133
|
+
self,
|
|
134
|
+
title: str,
|
|
135
|
+
align: Qt.AlignmentFlag,
|
|
136
|
+
shadow_blur: int,
|
|
137
|
+
shadow_color: QColor,
|
|
138
|
+
reversed_shadow: bool,
|
|
139
|
+
):
|
|
140
|
+
inner = QHBoxLayout()
|
|
141
|
+
|
|
142
|
+
# 左对齐:不添加stretch,直接添加标签
|
|
143
|
+
if align == Qt.AlignmentFlag.AlignLeft:
|
|
144
|
+
pass
|
|
145
|
+
elif align == Qt.AlignmentFlag.AlignCenter:
|
|
146
|
+
inner.addStretch()
|
|
147
|
+
elif align == Qt.AlignmentFlag.AlignRight:
|
|
148
|
+
inner.addStretch()
|
|
149
|
+
|
|
150
|
+
# 用新版 QShadowLabel
|
|
151
|
+
label = QShadowLabel(
|
|
152
|
+
text=title,
|
|
153
|
+
color=QMONO_TITLE_COLOR, # 文字颜色
|
|
154
|
+
bg_color=None, # 背景透明
|
|
155
|
+
shadow_blur=shadow_blur, # 阴影半径
|
|
156
|
+
shadow_color=shadow_color, # 阴影颜色(None 则用默认)
|
|
157
|
+
reversed=reversed_shadow, # 方向
|
|
158
|
+
alignment=Qt.AlignmentFlag.AlignCenter
|
|
159
|
+
)
|
|
160
|
+
label.setFont(MONO_INSPECTOR_FONT)
|
|
161
|
+
|
|
162
|
+
inner.addWidget(label)
|
|
163
|
+
|
|
164
|
+
# 右对齐或居中对齐时添加stretch
|
|
165
|
+
if align == Qt.AlignmentFlag.AlignCenter:
|
|
166
|
+
inner.addStretch()
|
|
167
|
+
elif align == Qt.AlignmentFlag.AlignRight:
|
|
168
|
+
inner.addStretch()
|
|
169
|
+
|
|
170
|
+
self._layout.addLayout(inner)
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from monowidget._utils.core import *
|
|
3
|
+
from PyQt6.QtCore import QRectF, Qt
|
|
4
|
+
from PyQt6.QtGui import QColor, QPainter, QPen
|
|
5
|
+
from PyQt6.QtWidgets import QFrame
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class _QMonoSlider(QFrame):
|
|
9
|
+
monoChanged: pyqtSignal = None
|
|
10
|
+
|
|
11
|
+
@abstractmethod
|
|
12
|
+
def __init__(self, orientation:Qt.Orientation, min_val: any, max_val:any, step:any=1, parent=None):
|
|
13
|
+
super().__init__(parent)
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
@abstractmethod
|
|
17
|
+
def setValue(self, value) -> None:
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
@abstractmethod
|
|
21
|
+
def value(self, value) -> any:
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class QIntSlider(_QMonoSlider):
|
|
26
|
+
monoChanged = pyqtSignal(int)
|
|
27
|
+
|
|
28
|
+
def __init__(self, orientation, min_val: int, max_val: int, step: int = 1, parent=None):
|
|
29
|
+
super().__init__(orientation, min_val, max_val, step, parent)
|
|
30
|
+
self._min = min_val
|
|
31
|
+
self._max = max_val
|
|
32
|
+
self._step = step
|
|
33
|
+
self._value = min_val
|
|
34
|
+
self.setMinimumHeight(30)
|
|
35
|
+
self.setMouseTracking(True)
|
|
36
|
+
self._dragging = False
|
|
37
|
+
|
|
38
|
+
def setValue(self, value: int):
|
|
39
|
+
if self._min <= value <= self._max:
|
|
40
|
+
self._value = value
|
|
41
|
+
self.monoChanged.emit(value)
|
|
42
|
+
self.update() # Trigger paintEvent
|
|
43
|
+
|
|
44
|
+
def value(self) -> int:
|
|
45
|
+
return self._value
|
|
46
|
+
|
|
47
|
+
def mousePressEvent(self, event):
|
|
48
|
+
if event.button() == Qt.MouseButton.LeftButton:
|
|
49
|
+
self._dragging = True
|
|
50
|
+
self._update_value_from_pos(event.position())
|
|
51
|
+
event.accept()
|
|
52
|
+
|
|
53
|
+
def mouseMoveEvent(self, event):
|
|
54
|
+
if self._dragging:
|
|
55
|
+
self._update_value_from_pos(event.position())
|
|
56
|
+
event.accept()
|
|
57
|
+
|
|
58
|
+
def mouseReleaseEvent(self, event):
|
|
59
|
+
if event.button() == Qt.MouseButton.LeftButton:
|
|
60
|
+
self._dragging = False
|
|
61
|
+
event.accept()
|
|
62
|
+
|
|
63
|
+
def _update_value_from_pos(self, pos):
|
|
64
|
+
rect = self.rect().adjusted(5, 5, -5, -5)
|
|
65
|
+
ratio = max(0, min(1, (pos.x() - rect.x()) / rect.width()))
|
|
66
|
+
value = self._min + ratio * (self._max - self._min)
|
|
67
|
+
value = round(value / self._step) * self._step
|
|
68
|
+
self.setValue(int(value))
|
|
69
|
+
|
|
70
|
+
def paintEvent(self, event):
|
|
71
|
+
painter = QPainter(self)
|
|
72
|
+
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
73
|
+
|
|
74
|
+
# Plain style - no background, just groove and handle
|
|
75
|
+
rect = self.rect().adjusted(5, 5, -5, -5)
|
|
76
|
+
|
|
77
|
+
# Draw groove only
|
|
78
|
+
groove_rect = QRectF(rect.x(), rect.center().y() - 2, rect.width(), 4)
|
|
79
|
+
painter.setBrush(QColor(220, 220, 220))
|
|
80
|
+
painter.setPen(Qt.PenStyle.NoPen)
|
|
81
|
+
painter.drawRoundedRect(groove_rect, 2, 2)
|
|
82
|
+
|
|
83
|
+
# Draw handle
|
|
84
|
+
ratio = (self._value - self._min) / (self._max - self._min)
|
|
85
|
+
handle_x = rect.x() + ratio * rect.width()
|
|
86
|
+
handle_rect = QRectF(handle_x - 6, rect.center().y() - 6, 12, 12)
|
|
87
|
+
painter.setBrush(QColor(66, 133, 244)) # Google blue
|
|
88
|
+
painter.setPen(Qt.PenStyle.NoPen)
|
|
89
|
+
painter.drawEllipse(handle_rect)
|
|
90
|
+
|
|
91
|
+
class QDoubleSlider(_QMonoSlider):
|
|
92
|
+
monoChanged = pyqtSignal(float)
|
|
93
|
+
|
|
94
|
+
def __init__(self, orientation, min_val: float, max_val: float, step: float = 0.1, parent=None):
|
|
95
|
+
super().__init__(orientation, min_val, max_val, step, parent)
|
|
96
|
+
self._min = min_val
|
|
97
|
+
self._max = max_val
|
|
98
|
+
self._step = step
|
|
99
|
+
self._value = min_val
|
|
100
|
+
self.setMinimumHeight(30)
|
|
101
|
+
self.setMouseTracking(True)
|
|
102
|
+
self._dragging = False
|
|
103
|
+
|
|
104
|
+
def setValue(self, value: float):
|
|
105
|
+
if self._min <= value <= self._max:
|
|
106
|
+
self._value = value
|
|
107
|
+
self.monoChanged.emit(value)
|
|
108
|
+
self.update() # Trigger paintEvent
|
|
109
|
+
|
|
110
|
+
def value(self) -> float:
|
|
111
|
+
return self._value
|
|
112
|
+
|
|
113
|
+
def mousePressEvent(self, event):
|
|
114
|
+
if event.button() == Qt.MouseButton.LeftButton:
|
|
115
|
+
self._dragging = True
|
|
116
|
+
self._update_value_from_pos(event.position())
|
|
117
|
+
event.accept()
|
|
118
|
+
|
|
119
|
+
def mouseMoveEvent(self, event):
|
|
120
|
+
if self._dragging:
|
|
121
|
+
self._update_value_from_pos(event.position())
|
|
122
|
+
event.accept()
|
|
123
|
+
|
|
124
|
+
def mouseReleaseEvent(self, event):
|
|
125
|
+
if event.button() == Qt.MouseButton.LeftButton:
|
|
126
|
+
self._dragging = False
|
|
127
|
+
event.accept()
|
|
128
|
+
|
|
129
|
+
def _update_value_from_pos(self, pos):
|
|
130
|
+
rect = self.rect().adjusted(5, 5, -5, -5)
|
|
131
|
+
ratio = max(0, min(1, (pos.x() - rect.x()) / rect.width()))
|
|
132
|
+
value = self._min + ratio * (self._max - self._min)
|
|
133
|
+
value = round(value / self._step) * self._step
|
|
134
|
+
self.setValue(float(value))
|
|
135
|
+
|
|
136
|
+
def paintEvent(self, event):
|
|
137
|
+
painter = QPainter(self)
|
|
138
|
+
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
139
|
+
|
|
140
|
+
# Plain style - no background, just groove and handle
|
|
141
|
+
rect = self.rect().adjusted(5, 5, -5, -5)
|
|
142
|
+
|
|
143
|
+
# Draw groove only
|
|
144
|
+
groove_rect = QRectF(rect.x(), rect.center().y() - 2, rect.width(), 4)
|
|
145
|
+
painter.setBrush(QColor(220, 220, 220))
|
|
146
|
+
painter.setPen(Qt.PenStyle.NoPen)
|
|
147
|
+
painter.drawRoundedRect(groove_rect, 2, 2)
|
|
148
|
+
|
|
149
|
+
# Draw handle
|
|
150
|
+
ratio = (self._value - self._min) / (self._max - self._min)
|
|
151
|
+
handle_x = rect.x() + ratio * rect.width()
|
|
152
|
+
handle_rect = QRectF(handle_x - 6, rect.center().y() - 6, 12, 12)
|
|
153
|
+
painter.setBrush(QColor(66, 133, 244)) # Google blue
|
|
154
|
+
painter.setPen(Qt.PenStyle.NoPen)
|
|
155
|
+
painter.drawEllipse(handle_rect)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from monowidget._utils.core import *
|
|
3
|
+
|
|
4
|
+
class QMonoSpacer(QWidget):
|
|
5
|
+
def __init__(self, height: int = 20, parent=None):
|
|
6
|
+
super().__init__(parent)
|
|
7
|
+
self.setFixedHeight(height)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class QMonoSeparator(QFrame):
|
|
11
|
+
def __init__(self, parent=None):
|
|
12
|
+
super().__init__(parent)
|
|
13
|
+
self.setFrameShape(QFrame.Shape.HLine)
|
|
14
|
+
self.setFrameShadow(QFrame.Shadow.Sunken)
|
|
15
|
+
self.setLineWidth(1)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""
|
|
2
|
+
自定义时间编辑组件
|
|
3
|
+
提供现代化的时间输入界面
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from monowidget._utils.core import *
|
|
7
|
+
from PyQt6.QtWidgets import QTimeEdit
|
|
8
|
+
from PyQt6.QtCore import QTime, Qt
|
|
9
|
+
from PyQt6.QtGui import QFont
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class QMonoTimeEdit(QTimeEdit):
|
|
13
|
+
"""现代化时间编辑组件"""
|
|
14
|
+
|
|
15
|
+
def __init__(self, parent=None):
|
|
16
|
+
super().__init__(parent)
|
|
17
|
+
self.setDisplayFormat("HH:mm:ss")
|
|
18
|
+
self.setTime(QTime.currentTime())
|
|
19
|
+
self.setup_styles()
|
|
20
|
+
self.setup_behavior()
|
|
21
|
+
|
|
22
|
+
def setup_styles(self):
|
|
23
|
+
"""设置时间编辑框样式"""
|
|
24
|
+
self.setStyleSheet("""
|
|
25
|
+
QTimeEdit {
|
|
26
|
+
padding: 6px 12px;
|
|
27
|
+
border: 2px solid #e0e0e0;
|
|
28
|
+
border-radius: 8px;
|
|
29
|
+
background-color: white;
|
|
30
|
+
font-size: 14px;
|
|
31
|
+
min-width: 120px;
|
|
32
|
+
font-family: 'Consolas', 'Monaco', monospace;
|
|
33
|
+
}
|
|
34
|
+
QTimeEdit:focus {
|
|
35
|
+
border-color: #4CAF50;
|
|
36
|
+
outline: none;
|
|
37
|
+
background-color: #f9fff9;
|
|
38
|
+
}
|
|
39
|
+
QTimeEdit:hover {
|
|
40
|
+
border-color: #bbb;
|
|
41
|
+
}
|
|
42
|
+
QTimeEdit::drop-down {
|
|
43
|
+
border: none;
|
|
44
|
+
width: 25px;
|
|
45
|
+
background-color: transparent;
|
|
46
|
+
}
|
|
47
|
+
QTimeEdit::down-arrow {
|
|
48
|
+
image: none;
|
|
49
|
+
border-left: 1px solid #e0e0e0;
|
|
50
|
+
margin-left: 5px;
|
|
51
|
+
}
|
|
52
|
+
QTimeEdit::up-button, QTimeEdit::down-button {
|
|
53
|
+
width: 20px;
|
|
54
|
+
height: 12px;
|
|
55
|
+
border: none;
|
|
56
|
+
background-color: #f5f5f5;
|
|
57
|
+
border-radius: 3px;
|
|
58
|
+
}
|
|
59
|
+
QTimeEdit::up-button:hover, QTimeEdit::down-button:hover {
|
|
60
|
+
background-color: #e0e0e0;
|
|
61
|
+
}
|
|
62
|
+
QTimeEdit::up-button:pressed, QTimeEdit::down-button:pressed {
|
|
63
|
+
background-color: #4CAF50;
|
|
64
|
+
color: white;
|
|
65
|
+
}
|
|
66
|
+
""")
|
|
67
|
+
|
|
68
|
+
def setup_behavior(self):
|
|
69
|
+
"""设置时间编辑框行为"""
|
|
70
|
+
# 设置字体
|
|
71
|
+
font = QFont("Consolas", 10)
|
|
72
|
+
font.setStyleHint(QFont.StyleHint.Monospace)
|
|
73
|
+
self.setFont(font)
|
|
74
|
+
|
|
75
|
+
# 设置对齐方式
|
|
76
|
+
self.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
77
|
+
|
|
78
|
+
# 启用日历弹窗
|
|
79
|
+
self.setCalendarPopup(False)
|
|
80
|
+
|
|
81
|
+
def set_custom_time_format(self, time_format):
|
|
82
|
+
"""设置自定义时间格式"""
|
|
83
|
+
self.setDisplayFormat(time_format)
|
|
84
|
+
|
|
85
|
+
def get_time(self):
|
|
86
|
+
"""获取当前时间"""
|
|
87
|
+
return self.time()
|
|
88
|
+
|
|
89
|
+
def set_time_range(self, min_time, max_time):
|
|
90
|
+
"""设置时间范围"""
|
|
91
|
+
self.setMinimumTime(min_time)
|
|
92
|
+
self.setMaximumTime(max_time)
|
|
93
|
+
|
|
94
|
+
def set_min_time(self, min_time):
|
|
95
|
+
"""设置最小时间"""
|
|
96
|
+
self.setMinimumTime(min_time)
|
|
97
|
+
|
|
98
|
+
def set_max_time(self, max_time):
|
|
99
|
+
"""设置最大时间"""
|
|
100
|
+
self.setMaximumTime(max_time)
|
|
101
|
+
|
|
102
|
+
def set_read_only(self, read_only):
|
|
103
|
+
"""设置只读模式"""
|
|
104
|
+
self.setReadOnly(read_only)
|
|
105
|
+
if read_only:
|
|
106
|
+
self.setStyleSheet(self.styleSheet() + """
|
|
107
|
+
QTimeEdit:read-only {
|
|
108
|
+
background-color: #f5f5f5;
|
|
109
|
+
color: #666;
|
|
110
|
+
border-color: #ddd;
|
|
111
|
+
}
|
|
112
|
+
""")
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from monowidget._utils.core import *
|
|
3
|
+
import math
|
|
4
|
+
from typing import Iterator, Union
|
|
5
|
+
|
|
6
|
+
Number = Union[int, float]
|
|
7
|
+
|
|
8
|
+
class rangef:
|
|
9
|
+
"""
|
|
10
|
+
浮点数版 range
|
|
11
|
+
支持切片、索引、len、迭代,行为尽量与内置 range 保持一致。
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
def __init__(self, start: Number, stop: Number = None, step: Number = 1.0) -> None:
|
|
15
|
+
if stop is None: # 类似 range(n) 的用法
|
|
16
|
+
start, stop = 0.0, start
|
|
17
|
+
self.start = float(start)
|
|
18
|
+
self.stop = float(stop)
|
|
19
|
+
self.step = float(step)
|
|
20
|
+
|
|
21
|
+
if self.step == 0:
|
|
22
|
+
raise ValueError("rangef() step must not be zero")
|
|
23
|
+
|
|
24
|
+
# 计算元素个数
|
|
25
|
+
self._len = max(0, int(math.ceil((self.stop - self.start) / self.step)))
|
|
26
|
+
|
|
27
|
+
def __iter__(self) -> Iterator[float]:
|
|
28
|
+
n = 0
|
|
29
|
+
while n < self._len:
|
|
30
|
+
yield self.start + n * self.step
|
|
31
|
+
n += 1
|
|
32
|
+
|
|
33
|
+
def __len__(self) -> int:
|
|
34
|
+
return self._len
|
|
35
|
+
|
|
36
|
+
def __getitem__(self, idx: int) -> float:
|
|
37
|
+
if not -self._len <= idx < self._len:
|
|
38
|
+
raise IndexError("rangef object index out of range")
|
|
39
|
+
if idx < 0:
|
|
40
|
+
idx += self._len
|
|
41
|
+
return self.start + idx * self.step
|
|
42
|
+
|
|
43
|
+
def __reversed__(self) -> Iterator[float]:
|
|
44
|
+
n = self._len - 1
|
|
45
|
+
while n >= 0:
|
|
46
|
+
yield self.start + n * self.step
|
|
47
|
+
n -= 1
|
|
48
|
+
|
|
49
|
+
def __repr__(self) -> str:
|
|
50
|
+
if self.start == 0 and self.step == 1.0:
|
|
51
|
+
return f"rangef({self.stop})"
|
|
52
|
+
if self.step == 1.0:
|
|
53
|
+
return f"rangef({self.start}, {self.stop})"
|
|
54
|
+
return f"rangef({self.start}, {self.stop}, {self.step})"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
if __name__ == '__main__':
|
|
58
|
+
# 基本功能测试
|
|
59
|
+
pass
|