Skip to content

Commit

Permalink
opt: adopt getColor instead of colorGroup.fromToken to simple cod…
Browse files Browse the repository at this point in the history
…ing structure
  • Loading branch information
ChinaIceF committed Oct 18, 2024
1 parent 054c68c commit b8b6cf5
Show file tree
Hide file tree
Showing 36 changed files with 208 additions and 208 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, *args, **kwargs):
self.version_label = SiLabel(self)
self.version_label.setSiliconWidgetFlag(Si.AdjustSizeOnTextChanged)
self.version_label.setFont(SiFont.tokenized(GlobalFont.M_NORMAL))
self.version_label.setStyleSheet(f"color: {self.colorGroup().fromToken(SiColor.TEXT_D)}")
self.version_label.setStyleSheet(f"color: {self.getColor(SiColor.TEXT_D)}")
self.version_label.setText("PyQt-SiliconUI")

version_picture_container.addWidget(self.version_picture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def __init__(self, parent, text):
self.resize(self.width() + 24, self.height())

def reloadStyleSheet(self):
self.setStyleSheet(f"color: {self.colorGroup().fromToken(SiColor.TEXT_B)};"
f"background-color: {self.colorGroup().fromToken(SiColor.INTERFACE_BG_D)}")
self.setStyleSheet(f"color: {self.getColor(SiColor.TEXT_B)};"
f"background-color: {self.getColor(SiColor.INTERFACE_BG_D)}")


class ExampleContainer(SiPage):
Expand Down Expand Up @@ -112,19 +112,19 @@ def __init__(self, *args, **kwargs):
self.indicator_h_80.resize(120, 4)
self.indicator_h_80.setHint("该 Section 宽 120 像素")
self.indicator_h_80.setFixedStyleSheet("border-radius: 2px")
self.indicator_h_80.setColor(SiColor.trans(self.colorGroup().fromToken(SiColor.THEME), 0.2))
self.indicator_h_80.setColor(SiColor.trans(self.getColor(SiColor.THEME), 0.2))

self.indicator_h_120 = SiLabel(self)
self.indicator_h_120.resize(180, 4)
self.indicator_h_120.setHint("该 Section 宽 180 像素")
self.indicator_h_120.setFixedStyleSheet("border-radius: 2px")
self.indicator_h_120.setColor(SiColor.trans(self.colorGroup().fromToken(SiColor.THEME), 0.5))
self.indicator_h_120.setColor(SiColor.trans(self.getColor(SiColor.THEME), 0.5))

self.indicator_h_180 = SiLabel(self)
self.indicator_h_180.resize(240, 4)
self.indicator_h_180.setHint("该 Section 宽 240 像素")
self.indicator_h_180.setFixedStyleSheet("border-radius: 2px")
self.indicator_h_180.setColor(SiColor.trans(self.colorGroup().fromToken(SiColor.THEME), 1.0))
self.indicator_h_180.setColor(SiColor.trans(self.getColor(SiColor.THEME), 1.0))

self.indicator_container_divided_h_container.addWidget(self.indicator_h_80)
self.indicator_container_divided_h_container.addWidget(self.indicator_h_120)
Expand Down Expand Up @@ -163,19 +163,19 @@ def __init__(self, *args, **kwargs):
self.indicator_v_48.resize(4, 48)
self.indicator_v_48.setHint("该 Section 高 48 像素")
self.indicator_v_48.setFixedStyleSheet("border-radius: 2px")
self.indicator_v_48.setColor(SiColor.trans(self.colorGroup().fromToken(SiColor.THEME), 0.2))
self.indicator_v_48.setColor(SiColor.trans(self.getColor(SiColor.THEME), 0.2))

self.indicator_v_64 = SiLabel(self)
self.indicator_v_64.resize(4, 64)
self.indicator_v_64.setHint("该 Section 高 64 像素")
self.indicator_v_64.setFixedStyleSheet("border-radius: 2px")
self.indicator_v_64.setColor(SiColor.trans(self.colorGroup().fromToken(SiColor.THEME), 0.5))
self.indicator_v_64.setColor(SiColor.trans(self.getColor(SiColor.THEME), 0.5))

self.indicator_v_80 = SiLabel(self)
self.indicator_v_80.resize(4, 80)
self.indicator_v_80.setHint("该 Section 高 80 像素")
self.indicator_v_80.setFixedStyleSheet("border-radius: 2px")
self.indicator_v_80.setColor(SiColor.trans(self.colorGroup().fromToken(SiColor.THEME), 1.0))
self.indicator_v_80.setColor(SiColor.trans(self.getColor(SiColor.THEME), 1.0))

self.indicator_container_divided_v_container.addWidget(self.indicator_v_48)
self.indicator_container_divided_v_container.addWidget(self.indicator_v_64)
Expand Down Expand Up @@ -222,7 +222,7 @@ def __init__(self, *args, **kwargs):
button = SiSimpleButton(label)
button.attachment().setFont(SiFont.tokenized(GlobalFont.S_NORMAL))
button.attachment().setText(str(round(random.random(), int(6 * random.random() + 2))))
button.colorGroup().assign(SiColor.BUTTON_OFF, button.colorGroup().fromToken(SiColor.INTERFACE_BG_D))
button.colorGroup().assign(SiColor.BUTTON_OFF, button.getColor(SiColor.INTERFACE_BG_D))
button.setFixedHeight(32)
button.adjustSize()
button.setAttribute(Qt.WA_TransparentForMouseEvents)
Expand Down Expand Up @@ -282,12 +282,12 @@ def __init__(self, *args, **kwargs):
for _ in range(16):
label = SiDraggableLabel(self)
button = SiSimpleButton(label)
button.colorGroup().assign(SiColor.BUTTON_OFF, button.colorGroup().fromToken(SiColor.INTERFACE_BG_D))
button.colorGroup().assign(SiColor.BUTTON_OFF, button.getColor(SiColor.INTERFACE_BG_D))
button.resize(160, int(random.random() * 50 + 70))
button.setAttribute(Qt.WA_TransparentForMouseEvents)
label.button = button
label.setFixedStyleSheet("border-radius: 4px")
label.setColor(self.colorGroup().fromToken(SiColor.INTERFACE_BG_D))
label.setColor(self.getColor(SiColor.INTERFACE_BG_D))
label.resize(button.size())

self.demo_masonry_container.addWidget(label, ani=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ def __init__(self, *args, **kwargs):
self.setFixedWidth(500)
self.icon().load(SiGlobal.siui.iconpack.get("ic_fluent_save_filled",
color_code=SiColor.mix(
self.colorGroup().fromToken(SiColor.SVG_NORMAL),
self.colorGroup().fromToken(SiColor.INTERFACE_BG_B),
self.getColor(SiColor.SVG_NORMAL),
self.getColor(SiColor.INTERFACE_BG_B),
0.05))
)

label = SiLabel(self)
label.setStyleSheet(f"color: {self.colorGroup().fromToken(SiColor.TEXT_E)}")
label.setStyleSheet(f"color: {self.getColor(SiColor.TEXT_E)}")
label.setText(
f'<span style="color: {self.colorGroup().fromToken(SiColor.TEXT_B)}">是否保存刚刚编辑的文件?</span><br>'
f'<span style="color: {self.getColor(SiColor.TEXT_B)}">是否保存刚刚编辑的文件?</span><br>'
"<br>"
"- 田所浩二志.doc<br>"
"- 八十天游览下北泽——从百草园到三味书屋.docx<br>"
Expand All @@ -30,13 +30,13 @@ def __init__(self, *args, **kwargs):
button1 = SiPushButton(self)
button1.setFixedHeight(32)
button1.attachment().setText("继续编辑我的文档")
button1.colorGroup().assign(SiColor.BUTTON_PANEL, self.colorGroup().fromToken(SiColor.INTERFACE_BG_D))
button1.colorGroup().assign(SiColor.BUTTON_PANEL, self.getColor(SiColor.INTERFACE_BG_D))
button1.clicked.connect(SiGlobal.siui.windows["MAIN_WINDOW"].layerModalDialog().closeLayer)

button2 = SiPushButton(self)
button2.setFixedHeight(32)
button2.attachment().setText("保存并退出")
button2.colorGroup().assign(SiColor.BUTTON_PANEL, self.colorGroup().fromToken(SiColor.INTERFACE_BG_D))
button2.colorGroup().assign(SiColor.BUTTON_PANEL, self.getColor(SiColor.INTERFACE_BG_D))
button2.clicked.connect(SiGlobal.siui.windows["MAIN_WINDOW"].layerModalDialog().closeLayer)

self.button3 = SiLongPressButton(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ def send_custom_message(type_, auto_close=False, auto_close_duration=1000):

info_label = SiLabel()
info_label.setFont(SiFont.tokenized(GlobalFont.S_NORMAL))
info_label.setStyleSheet(f"color: {info_label.colorGroup().fromToken(SiColor.TEXT_D)}; padding-left: 16px")
info_label.setStyleSheet(f"color: {info_label.getColor(SiColor.TEXT_D)}; padding-left: 16px")
info_label.setText("以下账号已成功登录")
info_label.adjustSize()

split_line = SiLabel()
split_line.resize(300, 1)
split_line.setFixedStyleSheet("margin-left: 20px")
split_line.setColor(SiColor.trans(split_line.colorGroup().fromToken(SiColor.TEXT_D), 0.3))
split_line.setColor(SiColor.trans(split_line.getColor(SiColor.TEXT_D), 0.3))

avatar = SiPixLabel(container)
avatar.resize(80, 80)
Expand All @@ -55,21 +55,21 @@ def send_custom_message(type_, auto_close=False, auto_close_duration=1000):

name_label = SiLabel()
name_label.setFont(SiFont.tokenized(GlobalFont.M_BOLD))
name_label.setStyleSheet(f"color: {name_label.colorGroup().fromToken(SiColor.TEXT_B)}; padding-left:8px")
name_label.setStyleSheet(f"color: {name_label.getColor(SiColor.TEXT_B)}; padding-left:8px")
name_label.setText("霏泠Ice")
name_label.adjustSize()

button_1 = SiSimpleButton()
button_1.setFixedHeight(22)
button_1.attachment().setText("打开我的主页")
button_1.colorGroup().assign(SiColor.TEXT_B, button_1.colorGroup().fromToken(SiColor.TITLE_INDICATOR))
button_1.colorGroup().assign(SiColor.TEXT_B, button_1.getColor(SiColor.TITLE_INDICATOR))
button_1.adjustSize()
button_1.reloadStyleSheet()

button_2 = SiSimpleButton()
button_2.setFixedHeight(22)
button_2.attachment().setText("退出账号")
button_2.colorGroup().assign(SiColor.TEXT_B, button_2.colorGroup().fromToken(SiColor.TITLE_INDICATOR))
button_2.colorGroup().assign(SiColor.TEXT_B, button_2.getColor(SiColor.TITLE_INDICATOR))
button_2.adjustSize()
button_2.reloadStyleSheet()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ def loadAchievement(self, achievement):

def reloadStyleSheet(self):
super().reloadStyleSheet()
self.title_label.setTextColor(self.colorGroup().fromToken(SiColor.TEXT_A))
self.artist_label.setTextColor(self.colorGroup().fromToken(SiColor.TEXT_A))
self.album_label.setTextColor(self.colorGroup().fromToken(SiColor.TEXT_D))
self.title_label.setTextColor(self.getColor(SiColor.TEXT_A))
self.artist_label.setTextColor(self.getColor(SiColor.TEXT_A))
self.album_label.setTextColor(self.getColor(SiColor.TEXT_D))
self.transition_label.setStyleSheet(
"background-color: qlineargradient("
" x1:0.1, y1:0, x2:1, y2:0,"
f" stop:0 {SiColor.trans(self.colorGroup().fromToken(SiColor.INTERFACE_BG_D), 1.0)},"
f" stop:1 {SiColor.trans(self.colorGroup().fromToken(SiColor.INTERFACE_BG_D), 0.7)}"
f" stop:0 {SiColor.trans(self.getColor(SiColor.INTERFACE_BG_D), 1.0)},"
f" stop:1 {SiColor.trans(self.getColor(SiColor.INTERFACE_BG_D), 0.7)}"
")"
)
self.achievement_label.setStyleSheet(
Expand Down Expand Up @@ -144,7 +144,7 @@ def __init__(self, *args, **kwargs):
self.state_label = SiLabel(self)
self.state_label.resize(64, 128)
self.state_label.setFixedStyleSheet("border-radius: 12px")
self.state_label.setColor(self.colorGroup().fromToken(SiColor.INTERFACE_BG_C))
self.state_label.setColor(self.getColor(SiColor.INTERFACE_BG_C))

self.folded_container = SiDenseVContainer(self.state_label)
self.folded_container.setAlignment(Qt.AlignHCenter)
Expand Down
22 changes: 11 additions & 11 deletions examples/Gallery for siui/components/page_icons/page_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def on_button_clicked():
pyperclip.copy(button.objectName())
SiGlobal.siui.windows["TOOL_TIP"].setText(
f"{button.objectName()}<br>"
f'<span style="color: {button.colorGroup().fromToken(SiColor.TEXT_D)}">复制成功</span>',
f'<span style="color: {button.getColor(SiColor.TEXT_D)}">复制成功</span>',
)
return on_button_clicked

Expand Down Expand Up @@ -69,7 +69,7 @@ def __init__(self, *args, **kwargs):
self.package_operation_container.setAlignment(Qt.AlignCenter)

self.package_selection_description = SiLabel(self)
self.package_selection_description.setStyleSheet(f"color: {self.colorGroup().fromToken(SiColor.TEXT_D)}")
self.package_selection_description.setStyleSheet(f"color: {self.getColor(SiColor.TEXT_D)}")
self.package_selection_description.setAlignment(Qt.AlignVCenter)
self.package_selection_description.setText("当前图标包")
self.package_selection_description.adjustSize()
Expand All @@ -82,12 +82,12 @@ def __init__(self, *args, **kwargs):
self.package_selection_combobox.valueChanged.connect(self.on_package_changed)
self.package_selection_combobox.menu().setShowIcon(False)
self.package_selection_combobox.colorGroup().assign(
SiColor.INTERFACE_BG_B, self.colorGroup().fromToken(SiColor.INTERFACE_BG_A))
SiColor.INTERFACE_BG_B, self.getColor(SiColor.INTERFACE_BG_A))
self.package_selection_combobox.colorGroup().assign(
SiColor.INTERFACE_BG_D, self.colorGroup().fromToken(SiColor.INTERFACE_BG_C))
SiColor.INTERFACE_BG_D, self.getColor(SiColor.INTERFACE_BG_C))

self.search_description = SiLabel(self)
self.search_description.setStyleSheet(f"color: {self.colorGroup().fromToken(SiColor.TEXT_D)}")
self.search_description.setStyleSheet(f"color: {self.getColor(SiColor.TEXT_D)}")
self.search_description.setAlignment(Qt.AlignVCenter)
self.search_description.setText("搜索图标")
self.search_description.adjustSize()
Expand All @@ -97,9 +97,9 @@ def __init__(self, *args, **kwargs):
self.search_input_box.reloadStyleSheet()
self.search_input_box.line_edit.textChanged.connect(self.on_search_text_changed)
self.search_input_box.colorGroup().assign(
SiColor.INTERFACE_BG_B, self.colorGroup().fromToken(SiColor.INTERFACE_BG_A))
SiColor.INTERFACE_BG_B, self.getColor(SiColor.INTERFACE_BG_A))
self.search_input_box.colorGroup().assign(
SiColor.INTERFACE_BG_D, self.colorGroup().fromToken(SiColor.INTERFACE_BG_C))
SiColor.INTERFACE_BG_D, self.getColor(SiColor.INTERFACE_BG_C))

self.package_operation_container.addWidget(self.package_selection_description)
self.package_operation_container.addWidget(self.package_selection_combobox)
Expand Down Expand Up @@ -131,7 +131,7 @@ def __init__(self, *args, **kwargs):
self.page_index_label.setAlignment(Qt.AlignCenter)
self.page_index_label.setFixedSize(128, 32)
self.page_index_label.setSiliconWidgetFlag(Si.AdjustSizeOnTextChanged)
self.page_index_label.setStyleSheet(f"color: {self.colorGroup().fromToken(SiColor.TEXT_D)}")
self.page_index_label.setStyleSheet(f"color: {self.getColor(SiColor.TEXT_D)}")

self.page_down_button = SiPushButton(self)
self.page_down_button.attachment().setText("下一页")
Expand Down Expand Up @@ -198,13 +198,13 @@ def load_icon_page_to(self, page_index, fade_ani=True):

svg_button = SiSimpleButton(widget)
svg_button.colorGroup().assign(SiColor.BUTTON_OFF,
svg_button.colorGroup().fromToken(SiColor.INTERFACE_BG_C))
svg_button.getColor(SiColor.INTERFACE_BG_C))
svg_button.attachment().setSvgSize(32, 32)
svg_button.attachment().load(icon_pack.get_from_data(value, self.colorGroup().fromToken(SiColor.SVG_NORMAL)))
svg_button.attachment().load(icon_pack.get_from_data(value, self.getColor(SiColor.SVG_NORMAL)))
svg_button.setFixedSize(96, 96)
svg_button.setHint(
f"{key}<br>"
f'<span style="color: {self.colorGroup().fromToken(SiColor.TEXT_D)}">点击复制图标名称</span>'
f'<span style="color: {self.getColor(SiColor.TEXT_D)}">点击复制图标名称</span>'
)
svg_button.clicked.connect(get_on_button_clicked_func(widget))
svg_button.reloadStyleSheet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ def _value_write_parser(self, row_index, col_index, value):
widget = self.parent().getRowWidget(row_index)[col_index]
if col_index == 0:
widget.setFont(SiFont.tokenized(GlobalFont.S_BOLD))
widget.setTextColor(self.parent().colorGroup().fromToken(SiColor.TEXT_B))
widget.setTextColor(self.parent().getColor(SiColor.TEXT_B))

if col_index == 1:
widget.load(self.rank_dict[value])
widget.setHint(value)

if col_index == 2:
widget.setTextColor(self.parent().colorGroup().fromToken(SiColor.TEXT_B))
widget.setTextColor(self.parent().getColor(SiColor.TEXT_B))
if row_index == 0:
widget.setFont(SiFont.tokenized(GlobalFont.S_BOLD))
else:
Expand All @@ -57,21 +57,21 @@ def _value_write_parser(self, row_index, col_index, value):
if value == "100.00%":
widget.setTextColor("#B2D844")
else:
widget.setTextColor(self.parent().colorGroup().fromToken(SiColor.TEXT_B))
widget.setTextColor(self.parent().getColor(SiColor.TEXT_B))

if col_index == 4:
widget.load(self.country_dict[value])
widget.setHint(value)

if col_index == 5:
widget.setTextColor(self.parent().colorGroup().fromToken(SiColor.TEXT_THEME))
widget.setTextColor(self.parent().getColor(SiColor.TEXT_THEME))
widget.setHint("Click to view profile")

if col_index in [6, 7, 8, 9, 10]:
if value == "0":
widget.setTextColor(self.parent().colorGroup().fromToken(SiColor.TEXT_E))
widget.setTextColor(self.parent().getColor(SiColor.TEXT_E))
else:
widget.setTextColor(self.parent().colorGroup().fromToken(SiColor.TEXT_B))
widget.setTextColor(self.parent().getColor(SiColor.TEXT_B))

if col_index in [0, 2, 3, 5, 6, 7, 8, 9, 10]:
widget.setText(value)
Expand All @@ -96,7 +96,7 @@ def on_header_created(self, header: SiRow):
for name in self.parent().column_names:
new_label = SiLabel(self.parent())
new_label.setFont(SiFont.tokenized(GlobalFont.S_BOLD))
new_label.setTextColor(self.parent().colorGroup().fromToken(SiColor.TEXT_D))
new_label.setTextColor(self.parent().getColor(SiColor.TEXT_D))
new_label.setText(name)
new_label.adjustSize()
header.container().addWidget(new_label)
Expand Down
2 changes: 1 addition & 1 deletion examples/My-TODOs/components/page_about/page_about.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, *args, **kwargs):
self.version_label = SiLabel(self)
self.version_label.setSiliconWidgetFlag(Si.AdjustSizeOnTextChanged)
self.version_label.setFont(SiFont.tokenized(GlobalFont.M_NORMAL))
self.version_label.setStyleSheet(f"color: {self.colorGroup().fromToken(SiColor.TEXT_D)}")
self.version_label.setStyleSheet(f"color: {self.getColor(SiColor.TEXT_D)}")
self.version_label.setText("PyQt-SiliconUI")

version_picture_container.addWidget(self.version_picture)
Expand Down
Loading

0 comments on commit b8b6cf5

Please sign in to comment.