Skip to content

Commit

Permalink
refactor: removed incorrect imports, deprecated dict usage when setti…
Browse files Browse the repository at this point in the history
…ng fonts
  • Loading branch information
ChinaIceF committed Sep 28, 2024
2 parents 15569b7 + c9f57fb commit d2985d6
Show file tree
Hide file tree
Showing 25 changed files with 191 additions and 186 deletions.
20 changes: 12 additions & 8 deletions examples/Gallery for siui/components/page_about/page_about.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
from PyQt5.QtGui import QDesktopServices
from PyQt5.QtWidgets import QSizePolicy

from siui.components import SiTitledWidgetGroup, SiOptionCardLinear, SiPushButton, SiSimpleButton, SiPixLabel, \
SiDenseVContainer, SiLabel
from siui.components import (
SiDenseVContainer,
SiLabel,
SiOptionCardLinear,
SiPixLabel,
SiPushButton,
SiSimpleButton,
SiTitledWidgetGroup,
)
from siui.components.page import SiPage
from siui.core import SiColor
from siui.core import SiQuickEffect
from siui.core import SiGlobal
from siui.core import Si
from siui.gui import GlobalFont
from siui.core import GlobalFont, Si, SiColor, SiGlobal, SiQuickEffect
from siui.gui import SiFont


class About(SiPage):
Expand All @@ -35,7 +39,7 @@ def __init__(self, *args, **kwargs):

self.version_label = SiLabel(self)
self.version_label.setSiliconWidgetFlag(Si.AdjustSizeOnTextChanged)
self.version_label.setFont(GlobalFont.M_NORMAL.value)
self.version_label.setFont(SiFont.tokenized(GlobalFont.M_NORMAL))
self.version_label.setStyleSheet(f"color: {self.colorGroup().fromToken(SiColor.TEXT_D)}")
self.version_label.setText("PyQt-SiliconUI")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from siui.components import SiTitledWidgetGroup, SiLabel, SiDenseHContainer, SiDenseVContainer, SiDividedHContainer, \
SiDividedVContainer, SiFlowContainer, SiDraggableLabel, SiSimpleButton, SiPushButton, SiMasonryContainer
from siui.components.page import SiPage
from siui.core import SiColor
from siui.core import SiColor, GlobalFont
from siui.core import SiGlobal
from siui.core import Si
from siui.gui import SiFont
from ..option_card import OptionCardPlaneForWidgetDemos

import random
Expand Down Expand Up @@ -219,7 +220,7 @@ def __init__(self, *args, **kwargs):
for _ in range(15):
label = SiDraggableLabel(self)
button = SiSimpleButton(label)
button.attachment().setFont(SiGlobal.siui.fonts["S_NORMAL"])
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.setFixedHeight(32)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from siui.components import SiDenseHContainer, SiDenseVContainer, SiLabel, SiPixLabel, SiSimpleButton
from siui.core import SiColor
from siui.core import SiGlobal
from siui.gui import GlobalFont, SiFont
from siui.core import GlobalFont, SiColor, SiGlobal
from siui.gui import SiFont
from siui.templates.application.components.message.box import SiSideMessageBox


Expand Down Expand Up @@ -34,7 +33,7 @@ def send_custom_message(type_, auto_close=False, auto_close_duration=1000):
container.setSpacing(0)

info_label = SiLabel()
info_label.setFont(SiFont.fromToken(GlobalFont.S_NORMAL))
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.setText("以下账号已成功登录")
info_label.adjustSize()
Expand All @@ -55,7 +54,7 @@ def send_custom_message(type_, auto_close=False, auto_close_duration=1000):
container_v.setSpacing(0)

name_label = SiLabel()
name_label.setFont(SiFont.fromToken(GlobalFont.M_BOLD))
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.setText("霏泠Ice")
name_label.adjustSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
from PyQt5.QtGui import QFont

from siui.components import SiDenseVContainer, SiLabel, SiPixLabel, SiSimpleButton, SiWidget
from siui.core import SiExpAnimation
from siui.core import SiColor
from siui.core import SiQuickEffect
from siui.core import SiGlobal
from siui.core import Si
from siui.gui import SiFont, GlobalFont
from siui.core import Si, SiColor, SiGlobal, SiQuickEffect
from siui.gui import SiFont


class InfoPanel(SiWidget):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from PyQt5.Qt import QColor

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QGraphicsDropShadowEffect

from siui.components import SiPixLabel
from siui.components.option_card import SiOptionCardLinear, SiOptionCardPlane
Expand All @@ -17,11 +16,8 @@
SiSimpleButton,
SiSwitch,
)
from siui.core import SiColor
from siui.core import SiQuickEffect
from siui.core import SiGlobal
from siui.core import Si
from siui.gui import SiFont, GlobalFont
from siui.core import GlobalFont, Si, SiColor, SiGlobal, SiQuickEffect
from siui.gui import SiFont

from .components.themed_option_card import ThemedOptionCardPlane

Expand Down Expand Up @@ -58,14 +54,14 @@ def __init__(self, *args, **kwargs):
self.title.setAlignment(Qt.AlignVCenter | Qt.AlignLeft)
self.title.setText("Silicon UI")
self.title.setStyleSheet("color: {}".format(SiGlobal.siui.colors["TEXT_A"]))
self.title.setFont(SiGlobal.siui.fonts["XL_NORMAL"])
self.title.setFont(SiFont.tokenized(GlobalFont.XL_NORMAL))

self.subtitle = SiLabel(self.head_area)
self.subtitle.setGeometry(64, 72, 500, 48)
self.subtitle.setAlignment(Qt.AlignVCenter | Qt.AlignLeft)
self.subtitle.setText("A powerful and artistic UI library based on PyQt5")
self.subtitle.setStyleSheet("color: {}".format(SiColor.trans(SiGlobal.siui.colors["TEXT_A"], 0.9)))
self.subtitle.setFont(SiFont.fromToken(GlobalFont.S_DEMI_BOLD))
self.subtitle.setFont(SiFont.tokenized(GlobalFont.S_DEMI_BOLD))

# 创建一个水平容器
self.container_for_cards = SiDenseHContainer(self.head_area)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from siui.components import SiLabel, SiPixLabel
from siui.components.widgets.abstracts.table import ABCSiTabelManager, SiRow
from siui.core import SiColor
from siui.core import Si
from siui.gui import GlobalFont, SiFont
from siui.core import GlobalFont, Si, SiColor
from siui.gui import SiFont


class DemoOsuPlayerRankingTableManager(ABCSiTabelManager):
Expand Down Expand Up @@ -40,7 +39,7 @@ def _value_read_parser(self, row_index, col_index):
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.fromToken(GlobalFont.S_BOLD))
widget.setFont(SiFont.tokenized(GlobalFont.S_BOLD))
widget.setTextColor(self.parent().colorGroup().fromToken(SiColor.TEXT_B))

if col_index == 1:
Expand All @@ -50,9 +49,9 @@ def _value_write_parser(self, row_index, col_index, value):
if col_index == 2:
widget.setTextColor(self.parent().colorGroup().fromToken(SiColor.TEXT_B))
if row_index == 0:
widget.setFont(SiFont.fromToken(GlobalFont.S_BOLD))
widget.setFont(SiFont.tokenized(GlobalFont.S_BOLD))
else:
widget.setFont(SiFont.fromToken(GlobalFont.S_NORMAL))
widget.setFont(SiFont.tokenized(GlobalFont.S_NORMAL))

if col_index == 3:
if value == "100.00%":
Expand Down Expand Up @@ -96,7 +95,7 @@ def _widget_creator(self, col_index):
def on_header_created(self, header: SiRow):
for name in self.parent().column_names:
new_label = SiLabel(self.parent())
new_label.setFont(SiFont.fromToken(GlobalFont.S_BOLD))
new_label.setFont(SiFont.tokenized(GlobalFont.S_BOLD))
new_label.setTextColor(self.parent().colorGroup().fromToken(SiColor.TEXT_D))
new_label.setText(name)
new_label.adjustSize()
Expand Down
7 changes: 3 additions & 4 deletions siui/components/combobox/combobox.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from siui.components.menu.menu import SiMenu
from siui.components.widgets.button import SiSimpleButton
from siui.components.widgets.label import SiLabel
from siui.core import SiColor
from siui.core import Si
from siui.gui.font import GlobalFont, SiFont
from siui.core import GlobalFont, Si, SiColor
from siui.gui.font import SiFont


class SiComboBox(ABCSiComboBox):
Expand All @@ -20,7 +19,7 @@ def __init__(self, *args, **kwargs):
self.menu().setAnimationManager(AnimationManager.EXPAND)

self.value_label = SiLabel(self)
self.value_label.setFont(SiFont.fromToken(GlobalFont.S_NORMAL))
self.value_label.setFont(SiFont.tokenized(GlobalFont.S_NORMAL))
self.value_label.setAlignment(Qt.AlignVCenter)
self.value_label.setFixedHeight(32)
self.value_label.setSiliconWidgetFlag(Si.AdjustSizeOnTextChanged)
Expand Down
6 changes: 3 additions & 3 deletions siui/components/option_card/option_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
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 import SiGlobal
from siui.core import Si
from siui.core import GlobalFont, Si, SiGlobal
from siui.gui import SiFont


class SiOptionCardLinear(SiWidget):
Expand Down Expand Up @@ -118,7 +118,7 @@ def __init__(self, *args, **kwargs):
# 在 header 创建标题
self.title = SiLabel(self)
self.title.setSiliconWidgetFlag(Si.AdjustSizeOnTextChanged)
self.title.setFont(SiGlobal.siui.fonts["M_BOLD"])
self.title.setFont(SiFont.tokenized(GlobalFont.M_BOLD))
self.title.setAlignment(Qt.AlignVCenter | Qt.AlignLeft)
self.title.setFixedHeight(32)

Expand Down
5 changes: 3 additions & 2 deletions siui/components/page/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from siui.components.widgets.container import SiDenseHContainer, SiDenseVContainer
from siui.components.widgets.label import SiLabel
from siui.components.widgets.scrollarea import SiScrollArea
from siui.core import SiGlobal
from siui.core import SiGlobal, GlobalFont
from siui.core import Si
from siui.gui import SiFont


class SiPage(SiDenseVContainer):
Expand Down Expand Up @@ -74,7 +75,7 @@ def setTitle(self, title: str):

# 标题
self.title = SiLabel(self)
self.title.setFont(SiGlobal.siui.fonts["L_BOLD"])
self.title.setFont(SiFont.tokenized(GlobalFont.L_BOLD))
self.title.setFixedHeight(32)
self.title.setContentsMargins(64, 0, 0, 0)
self.title.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
Expand Down
5 changes: 3 additions & 2 deletions siui/components/titled_widget_group/titled_widget_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from siui.components.widgets.container import SiDenseVContainer
from siui.components.widgets.label import SiLabel
from siui.core import SiGlobal
from siui.core import SiGlobal, GlobalFont
from siui.core import Si
from siui.gui import SiFont


class GroupTitle(SiLabel):
Expand All @@ -14,7 +15,7 @@ def __init__(self, *args, **kwargs):

# 标题文字
self.title_label = SiLabel(self)
self.title_label.setFont(SiGlobal.siui.fonts["M_BOLD"])
self.title_label.setFont(SiFont.tokenized(GlobalFont.M_BOLD))
self.title_label.setFixedHeight(26)
self.title_label.setAlignment(Qt.AlignBottom)
self.title_label.setSiliconWidgetFlag(Si.AdjustSizeOnTextChanged)
Expand Down
7 changes: 3 additions & 4 deletions siui/components/tooltip/tooltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

from siui.components.widgets.abstracts.widget import SiWidget
from siui.components.widgets.label import SiLabel
from siui.core import SiGlobal
from siui.gui.font import GlobalFont, SiFont
from siui.core import Si
from siui.core import GlobalFont, Si, SiGlobal
from siui.gui import SiFont


class ToolTipWindow(SiWidget):
Expand Down Expand Up @@ -54,7 +53,7 @@ def __init__(self, *args, **kwargs):
self.text_label.setFixedStyleSheet("padding: 8px")
self.text_label.setSiliconWidgetFlag(Si.InstantResize)
self.text_label.setSiliconWidgetFlag(Si.AdjustSizeOnTextChanged)
self.text_label.setFont(SiFont.fromToken(GlobalFont.S_NORMAL))
self.text_label.setFont(SiFont.tokenized(GlobalFont.S_NORMAL))

# 高光遮罩,当信息刷新时会闪烁一下
self.highlight_mask = SiLabel(self)
Expand Down
5 changes: 3 additions & 2 deletions siui/components/widgets/abstracts/line_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from siui.components.widgets.abstracts.widget import SiWidget
from siui.components.widgets.container import SiDenseHContainer
from siui.components.widgets.label import SiLabel
from siui.core import SiColor
from siui.core import SiColor, GlobalFont
from siui.core import SiGlobal
from siui.gui import SiFont


class SiSimpleLineEdit(QLineEdit):
Expand All @@ -15,7 +16,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

# 设置字体
self.setFont(SiGlobal.siui.fonts["S_NORMAL"])
self.setFont(SiFont.tokenized(GlobalFont.S_NORMAL))

def reloadStyleSheet(self):
self.setStyleSheet(
Expand Down
17 changes: 7 additions & 10 deletions siui/components/widgets/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@

from siui.components.widgets.abstracts import ABCButton, ABCPushButton, ABCToggleButton, LongPressThread
from siui.components.widgets.label import SiIconLabel, SiLabel, SiSvgLabel
from siui.core import SiExpAnimation
from siui.core import SiColor
from siui.core import SiGlobal
from siui.core import Si
from siui.core import GlobalFont, Si, SiColor, SiExpAnimation, SiGlobal
from siui.gui import SiFont
from siui.gui.color_group import SiColorGroup
from siui.gui.font import GlobalFont, SiFont


class SiPushButton(ABCPushButton):
Expand All @@ -25,7 +22,7 @@ def __init__(self, *args, **kwargs):
# 实例化文本标签
self.label = SiIconLabel(self)
self.label.setSiliconWidgetFlag(Si.AdjustSizeOnTextChanged)
self.label.setFont(SiFont.fromToken(GlobalFont.S_NORMAL))
self.label.setFont(SiFont.tokenized(GlobalFont.S_NORMAL))
self.label.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter)

# 设置偏移量,以保证在按钮明亮面显示
Expand Down Expand Up @@ -100,7 +97,7 @@ def __init__(self, *args, **kwargs):
# 实例化文本标签
self.label = SiIconLabel(self)
self.label.setSiliconWidgetFlag(Si.AdjustSizeOnTextChanged)
self.label.setFont(SiFont.fromToken(GlobalFont.S_NORMAL))
self.label.setFont(SiFont.tokenized(GlobalFont.S_NORMAL))
self.label.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter)

# 设置偏移量,以保证在按钮明亮面显示
Expand Down Expand Up @@ -159,7 +156,7 @@ def __init__(self, *args, **kwargs):
# 实例化文本标签
self.label = SiIconLabel(self)
self.label.setSiliconWidgetFlag(Si.AdjustSizeOnTextChanged)
self.label.setFont(SiFont.fromToken(GlobalFont.S_NORMAL))
self.label.setFont(SiFont.tokenized(GlobalFont.S_NORMAL))
self.label.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter)

# 绑定到主体
Expand Down Expand Up @@ -214,7 +211,7 @@ def __init__(self, parent):
# 创建选项文字
self.text_label = SiLabel(self)
self.text_label.setAlignment(Qt.AlignVCenter | Qt.AlignLeft)
self.text_label.setFont(SiFont.fromToken(GlobalFont.S_NORMAL))
self.text_label.setFont(SiFont.tokenized(GlobalFont.S_NORMAL))
self.text_label.setSiliconWidgetFlag(Si.AdjustSizeOnTextChanged)

def reloadStyleSheet(self):
Expand Down Expand Up @@ -334,7 +331,7 @@ def __init__(self, parent):
# 创建选项文字
self.text_label = SiLabel(self)
self.text_label.setAlignment(Qt.AlignVCenter | Qt.AlignLeft)
self.text_label.setFont(SiFont.fromToken(GlobalFont.S_NORMAL))
self.text_label.setFont(SiFont.tokenized(GlobalFont.S_NORMAL))
self.text_label.setSiliconWidgetFlag(Si.AdjustSizeOnTextChanged)

def reloadStyleSheet(self):
Expand Down
7 changes: 3 additions & 4 deletions siui/components/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
from PyQt5.QtSvg import QSvgWidget

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


class SiLabel(ABCAnimatedLabel):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
super().setFont(SiGlobal.siui.fonts["S_NORMAL"])
super().setFont(SiFont.tokenized(GlobalFont.S_NORMAL))


class SiPixLabel(SiLabel):
Expand Down
7 changes: 3 additions & 4 deletions siui/components/widgets/table.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from siui.components import SiLabel, SiMasonryContainer, SiScrollArea, SiWidget
from siui.components.widgets.abstracts.table import ABCSiTabelManager, ABCSiTable, SiRow
from siui.core import SiColor
from siui.core import Si
from siui.gui import GlobalFont, SiFont
from siui.core import GlobalFont, Si, SiColor
from siui.gui import SiFont


class SiTableValueManagerLabels(ABCSiTabelManager):
Expand All @@ -21,7 +20,7 @@ def _widget_creator(self, col_index):
def on_header_created(self, header: SiRow):
for name in self.parent().column_names:
new_label = SiLabel(self.parent())
new_label.setFont(SiFont.fromToken(GlobalFont.S_BOLD))
new_label.setFont(SiFont.tokenized(GlobalFont.S_BOLD))
new_label.setTextColor(self.parent().colorGroup().fromToken(SiColor.TEXT_B))
new_label.setText(name)
new_label.adjustSize()
Expand Down
Loading

0 comments on commit d2985d6

Please sign in to comment.