Skip to content

Commit acc0ea9

Browse files
authored
Merge pull request ChinaIceF#68 from ChinaIceF/reconst
修改 README,移除pyside6支持
2 parents 7ab29a5 + b88c53f commit acc0ea9

File tree

7 files changed

+138
-49
lines changed

7 files changed

+138
-49
lines changed

README.md

+8-29
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
</a>
77

88
<h2 align="center">PyQt-SiliconUI</h2>
9-
<p align="center">基于 PyQt5 / PySide6 的UI框架,灵动、优雅而轻便</p>
10-
11-
</p>
9+
<p align="center">基于 PyQt5 的UI框架,灵动、优雅而轻便</p>
10+
1211

1312
## 写在最前面
1413
### 注意:重构进行中
@@ -21,17 +20,12 @@
2120
为你造成的不便敬请谅解,欢迎你参与项目重构
2221

2322
## 如何使用
24-
### 下载合适的代码
25-
**当前分支 main**
26-
如果你希望运行 PyQt5,请下载 main 分支的代码
27-
如果你希望运行 PySide6,请下载 PySide6 分支的代码,为了保证兼容性,本项目在 PySide6 6.1.3 上开发
28-
2923
### 运行 Silicon Gallery
30-
下载源代码,解压并安装包
24+
* 下载源代码,解压并安装
3125
```cmd
3226
python setup.py install
3327
```
34-
运行`./examples/Gallery/start.py`即可体验 Silicon UI 现有的功能和效果
28+
* 运行`./examples/Gallery/start.py`即可体验 Silicon UI 现有的功能和效果
3529

3630
在 Silicon Gallery 中,你可以了解:
3731
* 各种控件以及其样式
@@ -40,29 +34,14 @@ python setup.py install
4034
* ***更多内容等待我们共同创造***
4135

4236
### 创建相似的 Silicon 应用
43-
``./examples/Gallery/ui.py`` 中,展示了一般 Silicon 应用的构建方法,其工作目录应具有以下结构:
44-
* **components文件夹**,其中存放各个选项卡的界面
45-
* **ui.py**,文件名取决于你的调用方式,重要的是其中应包含 Silicon 应用的构建类,并调用 components 文件夹以构建各个界面
46-
同时,你也需注意控件和对象间的从属关系,以 Glaze 为例,它中控件的从属关系如下
47-
48-
> silicon.SiTabArea
49-
>> silicon.SiTab
50-
>>> silicon.SiFrame
51-
>>>> silicon.SiCategory
52-
>>>>> silicon.SiOptionButton
53-
>>>>> silicon.SiOptionSwitch
54-
>>>>> silicon.SiOptionComboBox
55-
>>>>> ......
37+
* 根据我们提供的模板,你可以轻松创建于 Silicon Gallery 风格相似的应用,只需要用 `siui.templates.application.SiliconApplication` 代替正常项目中 `QMainWindow`,并调用方法来创建页面即可
5638

5739
### 在其他项目中使用
58-
Silicon UI 的控件并不仅限于在 Silicon 应用中使用,你可以在任意项目中调用它们,并据你喜好进行自定义
59-
60-
## 更新日志
61-
更新日志现在已经移动到 Silicon Gallery 中,日志从 2024.6.25 开始记录
40+
* Silicon UI 的控件并不仅限于在 Silicon 应用中使用,你可以在任意项目中调用它们,并据你喜好进行自定义
6241

6342
## License
64-
本项目采用 GPL-3.0 License,详见[这里](LICENSE)
65-
同时,本项目允许非商业使用。对于商业使用,敬请期待购买商用许可的版本。
43+
* 本项目遵循 GPL-3.0 License,详见[这里](LICENSE)
44+
* 同时,本项目仅允许非商业开源使用。对于商业使用,敬请期待购买商用许可的版本。
6645

6746
## 声明
6847
* 请注意,Silicon Gallery 使用了 FLATICON 的图标,**这些图标不应被认为是 Silicon UI 的一部分**,你可以前往 [FLATICON的网站](https://flaticon.com) 免注册、免下载其他文件、免费获取这些图标,但应在使用时注意遵守他们的有关条款规定

examples/Gallery/components/ExperimentField.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def __init__(self, parent):
213213

214214
self.scrollarea = SiScrollArea(self)
215215
self.scrollarea.setFixedHeight(256)
216-
self.scrollarea.setWidget(self.alabel)
216+
self.scrollarea.setAttachment(self.alabel)
217217

218218
# 新测试
219219
self.titled_widget_group = SiTitledWidgetGroup(self)

examples/template_test/start.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
from PyQt5.QtWidgets import QApplication
44

5-
from siui.templates.application import SiliconApplication
5+
from ui import MySiliconApp
6+
67

78

89
if __name__ == "__main__":
910
app = QApplication(sys.argv)
10-
window = SiliconApplication()
11+
window = MySiliconApp()
1112
window.show()
1213
sys.exit(app.exec_())

examples/template_test/ui.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from siui.templates.application import SiliconApplication
2+
from siui.
3+
4+
5+
class MySiliconApp(SiliconApplication):
6+
def __init__(self, *args, **kwargs):
7+
super().__init__(*args, **kwargs)
8+
9+
self.init_my_app_ui()
10+
11+
def init_my_app_ui(self):
12+
self.page1 =

siui/components/page/__init__.py

Whitespace-only changes.

siui/components/page/page.py

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
from PyQt5.QtCore import Qt
2+
3+
from siui.components.widgets.container import SiDenseVContainer
4+
from siui.components.widgets.label import SiLabel
5+
from siui.components.widgets.scrollarea import SiScrollArea
6+
from siui.core.globals import SiGlobal
7+
8+
9+
class SiPage(SiDenseVContainer):
10+
def __init__(self, *args, **kwargs):
11+
super().__init__(*args, **kwargs)
12+
self.setSpacing(0)
13+
14+
# 滚动区域宽度限制
15+
self.scroll_maximum_width = 10000
16+
17+
# 左对齐横坐标偏移量
18+
self.x_offset_on_align_left = 0
19+
20+
# 滚动区域对齐方式
21+
self.scroll_alignment = Qt.AlignCenter
22+
23+
# 标题
24+
self.title = SiLabel(self)
25+
self.title.setFixedStyleSheet("padding-left: 64px")
26+
self.title.setFont(SiGlobal.siui.fonts["L_BOLD"])
27+
self.title.setFixedHeight(32)
28+
self.title.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
29+
self.title.setAutoAdjustSize(True)
30+
31+
# 滚动区域
32+
self.scroll_area = SiScrollArea(self)
33+
34+
self.addPlaceholder(32)
35+
self.addWidget(self.title)
36+
self.addPlaceholder(32)
37+
self.addWidget(self.scroll_area)
38+
39+
def setScrollMaximumWidth(self, width: int):
40+
"""
41+
设置滚动区域的子控件的最大宽度
42+
:param width: 最大宽度
43+
:return:
44+
"""
45+
self.scroll_maximum_width = width
46+
self.resize(self.size())
47+
48+
def setScrollAlignment(self, a0):
49+
"""
50+
设置滚动区域的对齐方式
51+
:param a0: Qt 枚举值
52+
"""
53+
if a0 not in [Qt.AlignCenter, Qt.AlignLeft, Qt.AlignRight]:
54+
raise ValueError(f"Invalid alignment value: {a0}")
55+
self.scroll_alignment = a0
56+
self.resize(self.size())
57+
58+
def setXOffsetOnAlignLeft(self, offset):
59+
"""
60+
当内容中置时,横坐标的偏移量
61+
:param offset: 像素数
62+
"""
63+
self.x_offset_on_align_left = offset
64+
self.resize(self.size())
65+
66+
def reloadStyleSheet(self):
67+
super().reloadStyleSheet()
68+
self.title.setStyleSheet("color: {}".format(SiGlobal.siui.colors["TEXT_A"]))
69+
70+
def resizeEvent(self, event):
71+
super().resizeEvent(event)
72+
size = event.size()
73+
74+
self.scroll_area.resize(size.width(), size.height() - 96)
75+
self.scroll_area.attachment().setFixedWidth(min(size.width(), self.scroll_maximum_width))
76+
77+
# 处理对齐
78+
if self.scroll_alignment == Qt.AlignCenter:
79+
scroll_widget_x = (size.width() - self.scroll_area.attachment().width())//2 + self.x_offset_on_align_left
80+
elif self.scroll_alignment == Qt.AlignLeft:
81+
scroll_widget_x = 0
82+
elif self.scroll_alignment == Qt.AlignRight:
83+
scroll_widget_x = size.width() - self.scroll_area.attachment().width()
84+
else:
85+
raise ValueError(f"Invalid alignment value: {self.scroll_alignment}")
86+
87+
self.scroll_area.attachment().move(scroll_widget_x, self.scroll_area.attachment().y())
88+
89+
90+

siui/components/widgets/scrollarea.py

+24-17
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, *args, **kwargs):
1111
super().__init__(*args, **kwargs)
1212

1313
# 定义一个占位用的子控件
14-
self.widget = SiLabel(self)
14+
self.attachment_ = SiLabel(self)
1515

1616
# 定义滚动条的框架
1717
self.scroll_bar_frame_vertical = SiLabel(self)
@@ -34,7 +34,7 @@ def __init__(self, *args, **kwargs):
3434
self.widget_scroll_animation.setBias(1)
3535
self.widget_scroll_animation.setCurrent([0, 0])
3636
self.widget_scroll_animation.setTarget([0, 0])
37-
self.widget_scroll_animation.ticked.connect(lambda pos: self.widget.move(int(pos[0]), int(pos[1])))
37+
self.widget_scroll_animation.ticked.connect(lambda pos: self.attachment_.move(int(pos[0]), int(pos[1])))
3838

3939
def reloadStyleSheet(self):
4040
"""
@@ -45,36 +45,43 @@ def reloadStyleSheet(self):
4545
self.scroll_bar_vertical.setStyleSheet(f"background-color: {SiGlobal.siui.colors['SCROLL_BAR']}")
4646
self.scroll_bar_horizontal.setStyleSheet(f"background-color: {SiGlobal.siui.colors['SCROLL_BAR']}")
4747

48-
def setWidget(self, widget):
48+
def setAttachment(self, widget):
4949
"""
5050
绑定子控件,作为滚动的部件
5151
:param widget:
5252
:return:
5353
"""
54-
self.widget.deleteLater()
54+
self.attachment_.deleteLater()
5555

56-
self.widget = widget
57-
self.widget.setParent(self)
58-
self.widget.lower()
56+
self.attachment_ = widget
57+
self.attachment_.setParent(self)
58+
self.attachment_.lower()
59+
60+
def attachment(self):
61+
"""
62+
获取被绑定控件
63+
:return: 被绑定控件
64+
"""
65+
return self.attachment_
5966

6067
def _scroll_vertical_handler(self, pos):
6168
# 计算目标纵坐标
6269
_, y = pos
6370
progress = y / (self.height() - self.scroll_bar_vertical.height())
64-
target = - int(progress * (self.widget.height() - self.height()))
71+
target = - int(progress * (self.attachment_.height() - self.height()))
6572

6673
# 设置目标值并尝试启动
67-
self.widget_scroll_animation.setTarget([self.widget.x(), target])
74+
self.widget_scroll_animation.setTarget([self.attachment_.x(), target])
6875
self.widget_scroll_animation.try_to_start()
6976

7077
def _scroll_horizontal_handler(self, pos):
7178
# 计算目标横坐标
7279
x, _ = pos
7380
progress = x / (self.width() - self.scroll_bar_horizontal.width())
74-
target = - int(progress * (self.widget.width() - self.width()))
81+
target = - int(progress * (self.attachment_.width() - self.width()))
7582

7683
# 设置目标值并尝试启动
77-
self.widget_scroll_animation.setTarget([target, self.widget.y()])
84+
self.widget_scroll_animation.setTarget([target, self.attachment_.y()])
7885
self.widget_scroll_animation.try_to_start()
7986

8087
def resizeEvent(self, event):
@@ -87,20 +94,20 @@ def resizeEvent(self, event):
8794

8895
# 判断长宽是否超过自身的长宽,从而确定是否显示滚动条
8996
# 水平
90-
if self.widget.width() <= self.width():
97+
if self.attachment_.width() <= self.width():
9198
self.scroll_bar_horizontal.setVisible(False)
9299
else:
93100
self.scroll_bar_horizontal.setVisible(True)
94101

95102
# 竖直
96-
if self.widget.height() <= self.height():
103+
if self.attachment_.height() <= self.height():
97104
self.scroll_bar_vertical.setVisible(False)
98105
else:
99106
self.scroll_bar_vertical.setVisible(True)
100107

101108
# 根据滚动区域的大小和子控件的大小,计算出滚动条的长度或宽度
102-
self.scroll_bar_horizontal.resize(self.width() * self.width() // self.widget.width(), 8)
103-
self.scroll_bar_vertical.resize(8, self.height() * self.height() // self.widget.height())
109+
self.scroll_bar_horizontal.resize(self.width() * self.width() // self.attachment_.width(), 8)
110+
self.scroll_bar_vertical.resize(8, self.height() * self.height() // self.attachment_.height())
104111

105112
# 设置拖动限制
106113
self.scroll_bar_horizontal.setMoveLimits(0, 0, self.width(), 8)
@@ -118,11 +125,11 @@ def wheelEvent(self, event):
118125

119126
# 根据滚动方向,目标值加或减滚动强度,并更新目标值
120127
target[1] += strength if event.angleDelta().y() > 0 else -strength
121-
target[1] = min(0, max(self.height() - self.widget.height(), target[1])) # 防止滚出限制范围
128+
target[1] = min(0, max(self.height() - self.attachment_.height(), target[1])) # 防止滚出限制范围
122129
self.widget_scroll_animation.setTarget(target)
123130

124131
# 计算滚动条的目标位置
125-
process = -target[1] / (self.widget.height() - self.height())
132+
process = -target[1] / (self.attachment_.height() - self.height())
126133
scroll_bar_vertical_target_y = int(process * (self.height() - self.scroll_bar_vertical.height()))
127134

128135
# 如果竖直方向滚动条可见,尝试启动动画

0 commit comments

Comments
 (0)