Skip to content

Commit

Permalink
feat: create getColor to simple get color from colorGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
ChinaIceF committed Oct 18, 2024
1 parent 146fef3 commit 054c68c
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 20 deletions.
62 changes: 43 additions & 19 deletions examples/Gallery for siui/components/page_widgets/page_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QCursor

from siui.components import SiCircularProgressBar, SiLineEdit, SiOptionCardLinear, SiTitledWidgetGroup, SiWidget, \
SiLineEditWithDeletionButton, SiLineEditWithItemName
from siui.components import (
SiCircularProgressBar,
SiLineEdit,
SiLineEditWithDeletionButton,
SiLineEditWithItemName,
SiOptionCardLinear,
SiTitledWidgetGroup,
SiWidget,
)
from siui.components.combobox import SiComboBox
from siui.components.menu import SiMenu
from siui.components.page import SiPage
from siui.components.progress_bar import SiProgressBar
from siui.components.slider import SiSliderH
from siui.components.spinbox.spinbox import SiIntSpinBox, SiDoubleSpinBox
from siui.components.spinbox.spinbox import SiDoubleSpinBox, SiIntSpinBox
from siui.components.widgets import (
SiCheckBox,
SiDenseHContainer,
Expand All @@ -28,9 +35,8 @@
)
from siui.components.widgets.navigation_bar import SiNavigationBarH, SiNavigationBarV
from siui.components.widgets.table import SiTableView
from siui.core import SiColor
from siui.core import SiGlobal
from siui.core import Si
from siui.components.widgets.timeline import SiTimeLine
from siui.core import Si, SiColor, SiGlobal

from ..option_card import OptionCardPlaneForWidgetDemos
from .components.demo_tables import DemoOsuPlayerRankingTableManager
Expand Down Expand Up @@ -179,7 +185,7 @@ def __init__(self, *args, **kwargs):
# 控件显示效果
self.showup_effect = OptionCardPlaneForWidgetDemos(self)
self.showup_effect.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui"
"/components/widgets/label.py")
"/components/widgets/label.py")
self.showup_effect.setTitle("控件显示效果")

self.demo_widget = SiWidget(self)
Expand Down Expand Up @@ -370,7 +376,7 @@ def __init__(self, *args, **kwargs):
# 简单单行输入组件
self.line_edit = OptionCardPlaneForWidgetDemos(self)
self.line_edit.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/slider/slider.py")
"/widgets/slider/slider.py")
self.line_edit.setTitle("简单单行输入组件")

self.demo_line_edit = SiLineEdit(self)
Expand All @@ -384,7 +390,7 @@ def __init__(self, *args, **kwargs):
# 带删除单行输入组件
self.line_edit_with_del_button = OptionCardPlaneForWidgetDemos(self)
self.line_edit_with_del_button.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/slider/slider.py")
"/widgets/slider/slider.py")
self.line_edit_with_del_button.setTitle("带删除单行输入组件")

self.demo_line_edit_with_del_button = SiLineEditWithDeletionButton(self)
Expand All @@ -398,7 +404,7 @@ def __init__(self, *args, **kwargs):
# 整数微调组件
self.int_spin_box = OptionCardPlaneForWidgetDemos(self)
self.int_spin_box.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/slider/slider.py")
"/widgets/slider/slider.py")
self.int_spin_box.setTitle("整数微调组件")

self.demo_int_spin_box = SiIntSpinBox(self)
Expand All @@ -411,7 +417,7 @@ def __init__(self, *args, **kwargs):
# 浮点数微调组件
self.double_spin_box = OptionCardPlaneForWidgetDemos(self)
self.double_spin_box.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/slider/slider.py")
"/widgets/slider/slider.py")
self.double_spin_box.setTitle("浮点数微调组件")

self.demo_double_spin_box = SiDoubleSpinBox(self)
Expand All @@ -424,7 +430,7 @@ def __init__(self, *args, **kwargs):
# 具名输入框
self.named_line_edit = OptionCardPlaneForWidgetDemos(self)
self.named_line_edit.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/slider/slider.py")
"/widgets/slider/slider.py")
self.named_line_edit.setTitle("具名输入框")

self.demo_named_line_edit_1 = SiLineEditWithItemName(self)
Expand Down Expand Up @@ -484,7 +490,7 @@ def __init__(self, *args, **kwargs):
# 进度条
self.progress_bar_linear = OptionCardPlaneForWidgetDemos(self)
self.progress_bar_linear.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/progress_bar/progress_bar.py")
"/widgets/progress_bar/progress_bar.py")
self.progress_bar_linear.setTitle("进度条")

self.demo_progress_bar = SiProgressBar(self)
Expand Down Expand Up @@ -621,7 +627,7 @@ def __init__(self, *args, **kwargs):
# 下拉菜单
self.combobox = OptionCardPlaneForWidgetDemos(self)
self.combobox.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/progress_bar/progress_bar.py")
"/widgets/progress_bar/progress_bar.py")
self.combobox.setTitle("下拉菜单")

self.demo_combobox = SiComboBox(self)
Expand Down Expand Up @@ -649,7 +655,7 @@ def __init__(self, *args, **kwargs):
# 简单表格
self.table_simple = OptionCardPlaneForWidgetDemos(self)
self.table_simple.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/progress_bar/progress_bar.py")
"/widgets/progress_bar/progress_bar.py")
self.table_simple.setTitle("简单表格")

self.demo_table_simple = SiTableView(self)
Expand Down Expand Up @@ -727,7 +733,7 @@ def __init__(self, *args, **kwargs):
# 水平导航栏
self.navigation_bar_h = OptionCardPlaneForWidgetDemos(self)
self.navigation_bar_h.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/progress_bar/progress_bar.py")
"/widgets/progress_bar/progress_bar.py")
self.navigation_bar_h.setTitle("水平导航栏")

self.demo_navigation_bar_h = SiNavigationBarH(self)
Expand All @@ -746,7 +752,7 @@ def __init__(self, *args, **kwargs):
# 垂直导航栏
self.navigation_bar_v = OptionCardPlaneForWidgetDemos(self)
self.navigation_bar_v.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/progress_bar/progress_bar.py")
"/widgets/progress_bar/progress_bar.py")
self.navigation_bar_v.setTitle("横向导航栏")

self.demo_navigation_bar_v = SiNavigationBarV(self)
Expand All @@ -772,7 +778,7 @@ def __init__(self, *args, **kwargs):
# 水平单项选择栏
self.selection_bar_h = OptionCardPlaneForWidgetDemos(self)
self.selection_bar_h.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/progress_bar/progress_bar.py")
"/widgets/progress_bar/progress_bar.py")
self.selection_bar_h.setTitle("水平单项选择栏")

self.demo_selection_bar_h = SiNavigationBarH(self)
Expand All @@ -792,7 +798,7 @@ def __init__(self, *args, **kwargs):
# 垂直单项选择栏
self.selection_bar_v = OptionCardPlaneForWidgetDemos(self)
self.selection_bar_v.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/progress_bar/progress_bar.py")
"/widgets/progress_bar/progress_bar.py")
self.selection_bar_v.setTitle("垂直单项选择栏")

self.demo_selection_bar_v = SiNavigationBarV(self)
Expand All @@ -811,6 +817,24 @@ def __init__(self, *args, **kwargs):
group.addWidget(self.selection_bar_h)
group.addWidget(self.selection_bar_v)

with self.titled_widgets_group as group:
group.addTitle("时间线")

# 时间线
self.timeline = OptionCardPlaneForWidgetDemos(self)
self.timeline.setSourceCodeURL("https://github.com/ChinaIceF/PyQt-SiliconUI/blob/main/siui/components"
"/widgets/progress_bar/progress_bar.py")
self.timeline.setTitle("时间线")

self.demo_timeline = SiTimeLine(self)

self.timeline.body().addWidget(self.demo_timeline)
self.timeline.body().addPlaceholder(12)
self.timeline.adjustSize()

group.addWidget(self.timeline)


# 添加页脚的空白以增加美观性
self.titled_widgets_group.addPlaceholder(64)

Expand Down
3 changes: 3 additions & 0 deletions siui/components/widgets/abstracts/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def attachment(self):
"""
return self.attachment_

def getColor(self, token):
return self.color_group.fromToken(token)

def colorGroup(self):
"""
Get the color group of this widget
Expand Down
3 changes: 3 additions & 0 deletions siui/components/widgets/abstracts/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def isSiliconWidgetFlagOn(self, flag):
return False
return self.silicon_widget_flags[flag.name]

def getColor(self, token):
return self.color_group.fromToken(token)

def colorGroup(self):
"""
Get the color group of this widget
Expand Down
3 changes: 3 additions & 0 deletions siui/components/widgets/abstracts/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def animationGroup(self):
"""
return self.animation_group

def getColor(self, token):
return self.color_group.fromToken(token)

def colorGroup(self):
"""
Get the color group of this widget
Expand Down
3 changes: 3 additions & 0 deletions siui/components/widgets/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ def reloadStyleSheet(self):
"""
self._lever_move_animation_handler(self.switch_lever.x())

def getColor(self, token):
return self.color_group.fromToken(token)

def colorGroup(self):
"""
Get the color group of this widget
Expand Down
2 changes: 1 addition & 1 deletion siui/components/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from PyQt5.QtSvg import QSvgWidget

from siui.components.widgets.abstracts.label import ABCAnimatedLabel
from siui.core import GlobalFont, Si, SiGlobal, SiQuickAlignmentManager
from siui.core import GlobalFont, Si, SiGlobal, SiQuickAlignmentManager, SiColor
from siui.gui import SiFont


Expand Down
79 changes: 79 additions & 0 deletions siui/components/widgets/timeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from siui.components import SiLabel, SiMasonryContainer, SiSvgLabel, SiWidget
from siui.core import SiColor, SiGlobal


class SiTimeLineItem(SiWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.icon = SiSvgLabel(self)
self.icon.setSvgSize(24, 24)
self.icon.setFixedSize(32, 32)
self.icon.load(SiGlobal.siui.iconpack.get(
"ic_fluent_warning_shield_filled", color_code=self.getColor(SiColor.PROGRESS_BAR_COMPLETING)))
self.icon.move(16, 16)

self.anchor = SiLabel(self)
self.anchor.setFixedSize(24, 24)
self.anchor.setFixedStyleSheet("border-radius: 12px")
self.anchor.setStyleSheet(
f"border: 4px solid {self.colorGroup().fromToken(SiColor.INTERFACE_BG_C)};"
f"background-color: {self.colorGroup().fromToken(SiColor.INTERFACE_BG_E)};"
)
self.anchor.move(64 + 4, 20)

self.anchor_dot = SiLabel(self.anchor)
self.anchor_dot.setFixedSize(8, 8)
self.anchor_dot.setFixedStyleSheet("border-radius: 4px")
self.anchor_dot.move(8, 8)
self.anchor_dot.setStyleSheet(
f"background-color: {self.colorGroup().fromToken(SiColor.INTERFACE_BG_C)};"
)

self.title = SiLabel(self)
# self.title.setTextColor(self.colorGroup().fromToken(SiColor))
self.title.setText("你好世界")
self.title.move(0, 0)
self.title.adjustSize()

self.description = SiLabel(self)
self.description.setText("这是一段解释")
self.description.move(100, self.title.height())
self.description.adjustSize()

def resizeEvent(self, event):
super().resizeEvent(event)
print(event.size().width())
self.title.resize(event.size().width() - 100, self.title.height())
self.description.resize(event.size().width() - 100, self.description.height())
self.description.move(100, self.title.height())


class SiTimeLine(SiMasonryContainer):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.setColumns(1)
self.setColumnWidth(500)

self.track = SiLabel(self)
self.track.setFixedStyleSheet("border-radius: 2px")
self.track.setColor(self.colorGroup().fromToken(SiColor.INTERFACE_BG_E))
self.track.setFixedWidth(4)
self.track.resize(4, 100)
self.track.move(14 + 64, 0)

self.item1 = SiTimeLineItem(self)
self.item2 = SiTimeLineItem(self)

self.addWidget(self.item1)
self.addWidget(self.item2)
# self.arrangeWidgets()

self.setMinimumWidth(500)

def resizeEvent(self, event):
super().resizeEvent(event)

for item in self.widgets():
item.resize(event.size().width(), item.height())

0 comments on commit 054c68c

Please sign in to comment.