Skip to content

Commit

Permalink
chore: examples in gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
ChinaIceF committed Aug 24, 2024
1 parent a8777df commit 3850fef
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
from siui.components import SiDenseHContainer, SiPixLabel, SiDenseVContainer, SiLabel, SiSimpleButton
from siui.components import SiDenseHContainer, SiDenseVContainer, SiLabel, SiPixLabel, SiSimpleButton
from siui.core.color import SiColor
from siui.core.globals import SiGlobal
from siui.gui import SiFont, GlobalFont
from siui.gui import GlobalFont, SiFont
from siui.templates.application.components.message.box import SiSideMessageBox


def send_simple_message(type_):
def send_simple_message(type_, auto_close=False, auto_close_duration=1000):
fold_after = auto_close_duration if auto_close is True else None
SiGlobal.siui.windows["MAIN_WINDOW"].LayerRightMessageSidebar().send(
"这是一条测试消息\n"
"比具标题信息更加简洁方便",
msg_type=type_,
fold_after=fold_after,
)


def send_titled_message(type_):
def send_titled_message(type_, auto_close=False, auto_close_duration=1000):
fold_after = auto_close_duration if auto_close is True else None
SiGlobal.siui.windows["MAIN_WINDOW"].LayerRightMessageSidebar().send(
title="Sent Successfully",
text="A titled message has been successfully sent to the sidebar.\n" +
"Click this message box for more information.",
msg_type=type_,
slot=lambda: print("You clicked me")
fold_after=fold_after,
)


def send_custom_message(type_):
def send_custom_message(type_, auto_close=False, auto_close_duration=1000):
fold_after = auto_close_duration if auto_close is True else None
container = SiDenseHContainer()
container.setAdjustWidgetsSize(True)
container.setFixedHeight(80)
Expand Down Expand Up @@ -94,4 +98,7 @@ def send_custom_message(type_):
new_message_box.content().container().addPlaceholder(32)
new_message_box.adjustSize()

SiGlobal.siui.windows["MAIN_WINDOW"].LayerRightMessageSidebar().sendMessageBox(new_message_box)
if fold_after is not None:
new_message_box.setFoldAfter(fold_after)

SiGlobal.siui.windows["MAIN_WINDOW"].LayerRightMessageSidebar().sendMessageBox(new_message_box)
90 changes: 69 additions & 21 deletions examples/Gallery for siui/components/page_dialog/page_dialog.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
from PyQt5.QtCore import Qt

from siui.components import SiTitledWidgetGroup, SiPushButton, SiLabel, SiLongPressButton, SiDenseHContainer
from siui.components import (
SiDenseHContainer,
SiOptionCardLinear,
SiPushButton,
SiTitledWidgetGroup,
)
from siui.components.combobox import SiComboBox
from siui.components.page import SiPage
from siui.core.color import SiColor
from siui.components.spinbox.spinbox import SiDoubleSpinBox
from siui.core.globals import SiGlobal
from siui.templates.application.components.dialog.modal import SiModalDialog

from ..option_card import OptionCardPlaneForWidgetDemos
from .components.child_page_example import ChildPageExample
from .components.side_msg_box import send_simple_message, send_titled_message, send_custom_message
from .components.modal_dialog_example import ModalDialogExample
from .components.side_msg_box import send_custom_message, send_simple_message, send_titled_message


class ExampleDialogs(SiPage):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.message_auto_close_duration = None
self.message_auto_close = None
self.message_type = 0

self.setPadding(64)
Expand Down Expand Up @@ -46,35 +52,72 @@ def __init__(self, *args, **kwargs):
self.demo_send_message_to_sidebar = SiPushButton(self)
self.demo_send_message_to_sidebar.resize(128, 32)
self.demo_send_message_to_sidebar.attachment().setText("发送测试信息")
self.demo_send_message_to_sidebar.clicked.connect(lambda: send_simple_message(self.message_type))
self.demo_send_message_to_sidebar.clicked.connect(
lambda: send_simple_message(self.message_type, self.message_auto_close, self.message_auto_close_duration))

self.demo_send_message_to_sidebar_titled = SiPushButton(self)
self.demo_send_message_to_sidebar_titled.resize(128, 32)
self.demo_send_message_to_sidebar_titled.attachment().setText("具标题测试信息")
self.demo_send_message_to_sidebar_titled.clicked.connect(lambda: send_titled_message(self.message_type))
self.demo_send_message_to_sidebar_titled.clicked.connect(
lambda: send_titled_message(self.message_type, self.message_auto_close, self.message_auto_close_duration))

self.demo_send_message_to_sidebar_custom = SiPushButton(self)
self.demo_send_message_to_sidebar_custom.resize(128, 32)
self.demo_send_message_to_sidebar_custom.attachment().setText("发送自定义信息")
self.demo_send_message_to_sidebar_custom.clicked.connect(lambda: send_custom_message(self.message_type))

self.demo_type_combobox = SiComboBox(self)
self.demo_type_combobox.resize(80, 32)
self.demo_type_combobox.addOption("标准", value=0)
self.demo_type_combobox.addOption("成功", value=1)
self.demo_type_combobox.addOption("提示", value=2)
self.demo_type_combobox.addOption("警告", value=3)
self.demo_type_combobox.addOption("错误", value=4)
self.demo_type_combobox.menu().setShowIcon(False)
self.demo_type_combobox.menu().setIndex(0)
self.demo_type_combobox.valueChanged.connect(self.set_message_box_type)
self.demo_send_message_to_sidebar_custom.clicked.connect(
lambda: send_custom_message(self.message_type, self.message_auto_close, self.message_auto_close_duration))

side_message_container.addWidget(self.demo_send_message_to_sidebar)
side_message_container.addWidget(self.demo_send_message_to_sidebar_titled)
side_message_container.addWidget(self.demo_send_message_to_sidebar_custom)

# -- 信息类型
self.ctrl_type_combobox = SiComboBox(self)
self.ctrl_type_combobox.resize(80, 32)
self.ctrl_type_combobox.addOption("标准", value=0)
self.ctrl_type_combobox.addOption("成功", value=1)
self.ctrl_type_combobox.addOption("提示", value=2)
self.ctrl_type_combobox.addOption("警告", value=3)
self.ctrl_type_combobox.addOption("错误", value=4)
self.ctrl_type_combobox.menu().setShowIcon(False)
self.ctrl_type_combobox.menu().setIndex(0)
self.ctrl_type_combobox.valueChanged.connect(self.set_message_box_type)

self.option_card_type = SiOptionCardLinear(self)
self.option_card_type.load(SiGlobal.siui.iconpack.get("ic_fluent_tag_multiple_regular"))
self.option_card_type.setTitle("信息类型", "使用不同的信息类型以提供更直观的提示")
self.option_card_type.addWidget(self.ctrl_type_combobox)

# -- 自动消失
self.ctrl_auto_close = SiComboBox(self)
self.ctrl_auto_close.resize(80, 32)
self.ctrl_auto_close.addOption("禁用", value=False)
self.ctrl_auto_close.addOption("启用", value=True)
self.ctrl_auto_close.menu().setShowIcon(False)
self.ctrl_auto_close.menu().setIndex(0)
self.ctrl_auto_close.valueChanged.connect(self.set_message_box_auto_close)

self.option_card_auto_close = SiOptionCardLinear(self)
self.option_card_auto_close.load(SiGlobal.siui.iconpack.get("ic_fluent_panel_right_contract_regular"))
self.option_card_auto_close.setTitle("自动隐藏", "以降低操作复杂性,或是保留重要信息")
self.option_card_auto_close.addWidget(self.ctrl_auto_close)

# -- 停留时长
self.ctrl_stay_duration = SiDoubleSpinBox(self)
self.ctrl_stay_duration.resize(128, 32)
self.ctrl_stay_duration.lineEdit().textChanged.connect(self.set_message_box_auto_close)
self.ctrl_stay_duration.setValue(1.0)

self.option_card_stay_duration = SiOptionCardLinear(self)
self.option_card_stay_duration.load(SiGlobal.siui.iconpack.get("ic_fluent_timer_regular"))
self.option_card_stay_duration.setTitle("停留时长", "如果自动隐藏被启用,提示消息将在设定的秒数后隐藏")
self.option_card_stay_duration.addWidget(self.ctrl_stay_duration)

self.side_messages.body().setAdjustWidgetsSize(True)
self.side_messages.body().addWidget(side_message_container)
self.side_messages.body().addWidget(self.demo_type_combobox)
self.side_messages.body().addWidget(self.option_card_type)
self.side_messages.body().addWidget(self.option_card_auto_close)
self.side_messages.body().addWidget(self.option_card_stay_duration)
self.side_messages.body().addPlaceholder(12)
self.side_messages.adjustSize()

Expand All @@ -87,7 +130,7 @@ def __init__(self, *args, **kwargs):
# 子页面
self.child_pages = OptionCardPlaneForWidgetDemos(self)
self.child_pages.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/progress_bar/progress_bar.py")
"/widgets/progress_bar/progress_bar.py")
self.child_pages.setTitle("子页面")
self.child_pages.setFixedWidth(800)

Expand All @@ -105,7 +148,7 @@ def __init__(self, *args, **kwargs):
# 模态弹窗
self.modal_dialog = OptionCardPlaneForWidgetDemos(self)
self.modal_dialog.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/progress_bar/progress_bar.py")
"/widgets/progress_bar/progress_bar.py")
self.modal_dialog.setTitle("模态弹窗")
self.modal_dialog.setFixedWidth(800)

Expand All @@ -132,3 +175,8 @@ def __init__(self, *args, **kwargs):
def set_message_box_type(self, type_):
self.message_type = type_

def set_message_box_auto_close(self, value):
if isinstance(value, bool):
self.message_auto_close = value
if isinstance(value, str):
self.message_auto_close_duration = int(float(value) * 1000)
28 changes: 19 additions & 9 deletions examples/Gallery for siui/components/page_widgets/page_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,15 +555,15 @@ def __init__(self, *args, **kwargs):
group.addWidget(self.progress_bar_circular)
group.addWidget(self.progress_bar_circular_indeterminate)

# 菜单测试
# 菜单
with self.titled_widgets_group as group:
group.addTitle("菜单测试")
group.addTitle("菜单")

# 进度条
# 右键菜单
self.menus = OptionCardPlaneForWidgetDemos(self)
self.menus.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/progress_bar/progress_bar.py")
self.menus.setTitle("菜单测试")
self.menus.setTitle("右键菜单")

menu_child_menu_test = SiMenu()
menu_child_menu_test.setFixedWidth(180)
Expand All @@ -583,9 +583,19 @@ def __init__(self, *args, **kwargs):

self.demo_show_menu_button = SiPushButton(self)
self.demo_show_menu_button.resize(128, 32)
self.demo_show_menu_button.attachment().setText("显示菜单")
self.demo_show_menu_button.attachment().setText("点击显示菜单")
self.demo_show_menu_button.clicked.connect(lambda: menu_test.unfold(QCursor.pos().x(), QCursor.pos().y()))

self.menus.body().addWidget(self.demo_show_menu_button)
self.menus.body().addPlaceholder(12)
self.menus.adjustSize()

# 下拉菜单
self.combobox = OptionCardPlaneForWidgetDemos(self)
self.combobox.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/progress_bar/progress_bar.py")
self.combobox.setTitle("下拉菜单")

self.demo_combobox = SiComboBox(self)
self.demo_combobox.resize(256, 32)
self.demo_combobox.addOption("Chicken you are so beautiful")
Expand All @@ -597,12 +607,12 @@ def __init__(self, *args, **kwargs):
self.demo_combobox.menu().setShowIcon(False)
self.demo_combobox.menu().setIndex(3)

self.menus.body().addWidget(self.demo_show_menu_button)
self.menus.body().addWidget(self.demo_combobox)
self.menus.body().addPlaceholder(12)
self.menus.adjustSize()
self.combobox.body().addWidget(self.demo_combobox)
self.combobox.body().addPlaceholder(12)
self.combobox.adjustSize()

group.addWidget(self.menus)
group.addWidget(self.combobox)

# 表格
with self.titled_widgets_group as group:
Expand Down
10 changes: 5 additions & 5 deletions siui/components/option_card/option_card.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
from PyQt5.QtCore import Qt

from siui.components.option_card.abstracts.option_card import ABCSiOptionCardPlane
from siui.components.widgets.abstracts.widget import SiWidget
from siui.components.widgets.container import SiDenseHContainer
from siui.components.widgets.label import SiLabel, SiSvgLabel
from siui.core.globals import SiGlobal
from siui.core.silicon import Si


class SiOptionCardLinear(SiLabel):
"""
水平方向上的、线性放置控件的选项卡组件
"""
class SiOptionCardLinear(SiWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.setFixedStyleSheet("background-color:{}; border-radius:4px".format(SiGlobal.siui.colors["INTERFACE_BG_C"]))
self.panel = SiLabel(self)
self.panel.setFixedStyleSheet(f"background-color:{SiGlobal.siui.colors['INTERFACE_BG_C']}; border-radius:4px")

# 设定最小高度
self.setMinimumHeight(80)
Expand Down Expand Up @@ -98,6 +97,7 @@ def resizeEvent(self, event):
super().resizeEvent(event)
w, h = event.size().width(), event.size().height()

self.panel.resize(w, h)
self.container.resize(w, h)

# 让文字标签充满闲置区域
Expand Down
6 changes: 3 additions & 3 deletions siui/templates/application/components/message/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def send(self,
"padding-bottom: 16px;"
"padding-left: 12px;"
"padding-right: 12px;"
"color: {}".format(self.colorGroup().fromToken(SiColor.TEXT_D))
f"color: {self.colorGroup().fromToken(SiColor.TEXT_D)}"
)
label.setText(text)
new_message_box.content().container().addWidget(label)
Expand All @@ -72,7 +72,7 @@ def send(self,
"padding-bottom: 1px;"
"padding-left: 12px;"
"padding-right: 12px;"
"color: {}".format(self.colorGroup().fromToken(SiColor.TEXT_B))
f"color: {self.colorGroup().fromToken(SiColor.TEXT_B)}"
)
title_label.setText(title)

Expand All @@ -86,7 +86,7 @@ def send(self,
"padding-bottom: 16px;"
"padding-left: 12px;"
"padding-right: 12px;"
"color: {}".format(self.colorGroup().fromToken(SiColor.TEXT_D))
f"color: {self.colorGroup().fromToken(SiColor.TEXT_D)}"
)
description_label.setText(text)

Expand Down

0 comments on commit 3850fef

Please sign in to comment.