RinUI 0.0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. RinUI/__init__.py +4 -0
  2. RinUI/__pycache__/__init__.cpython-38.pyc +0 -0
  3. RinUI/assets/fonts/FluentSystemIcons-Index.js +5256 -0
  4. RinUI/assets/fonts/FluentSystemIcons-Resizable.ttf +0 -0
  5. RinUI/assets/img/default_app_icon.png +0 -0
  6. RinUI/components/Base.qml +79 -0
  7. RinUI/components/BasicInput/Button.qml +148 -0
  8. RinUI/components/BasicInput/CheckBox.qml +99 -0
  9. RinUI/components/BasicInput/ComboBox.qml +160 -0
  10. RinUI/components/BasicInput/DropDownButton.qml +21 -0
  11. RinUI/components/BasicInput/Hyperlink.qml +18 -0
  12. RinUI/components/BasicInput/RadioButton.qml +95 -0
  13. RinUI/components/BasicInput/Slider.qml +212 -0
  14. RinUI/components/BasicInput/Switch.qml +102 -0
  15. RinUI/components/BasicInput/ToggleButton.qml +11 -0
  16. RinUI/components/BasicInput/ToolButton.qml +31 -0
  17. RinUI/components/ContextMenu.qml +184 -0
  18. RinUI/components/DateAndTime/PickerView.qml +217 -0
  19. RinUI/components/DateAndTime/TimePicker.qml +115 -0
  20. RinUI/components/DialogsAndFlyouts/Dialog.qml +106 -0
  21. RinUI/components/DialogsAndFlyouts/DialogButtonBox.qml +47 -0
  22. RinUI/components/DialogsAndFlyouts/Flyout.qml +144 -0
  23. RinUI/components/DialogsAndFlyouts/Popup.qml +106 -0
  24. RinUI/components/FocusIndicator.qml +33 -0
  25. RinUI/components/IconWidget.qml +52 -0
  26. RinUI/components/Indicator.qml +90 -0
  27. RinUI/components/Layout/Expander.qml +160 -0
  28. RinUI/components/Layout/SettingExpander.qml +67 -0
  29. RinUI/components/Layout/SettingItem.qml +71 -0
  30. RinUI/components/ListAndCollections/Clip.qml +22 -0
  31. RinUI/components/ListAndCollections/Frame.qml +44 -0
  32. RinUI/components/ListAndCollections/ListView.qml +105 -0
  33. RinUI/components/ListAndCollections/ListViewDelegate.qml +83 -0
  34. RinUI/components/ListAndCollections/SettingCard.qml +73 -0
  35. RinUI/components/ListAndCollections/TableView.qml +82 -0
  36. RinUI/components/ListAndCollections/TableViewDelegate.qml +89 -0
  37. RinUI/components/MenusAndToolbars/Menu.qml +149 -0
  38. RinUI/components/MenusAndToolbars/MenuBar.qml +43 -0
  39. RinUI/components/MenusAndToolbars/MenuItem.qml +119 -0
  40. RinUI/components/MenusAndToolbars/MenuItemGroup.qml +43 -0
  41. RinUI/components/MenusAndToolbars/MenuSeparator.qml +14 -0
  42. RinUI/components/MenusAndToolbars/ToolSeparator.qml +17 -0
  43. RinUI/components/Navigation/ErrorPage.qml +48 -0
  44. RinUI/components/Navigation/NavigationBar.qml +179 -0
  45. RinUI/components/Navigation/NavigationItem.qml +193 -0
  46. RinUI/components/Navigation/NavigationSubItem.qml +103 -0
  47. RinUI/components/Navigation/NavigationView.qml +210 -0
  48. RinUI/components/Navigation/SelectorBar.qml +58 -0
  49. RinUI/components/ScrollBar.qml +163 -0
  50. RinUI/components/ScrollView.qml +13 -0
  51. RinUI/components/Shadow.qml +48 -0
  52. RinUI/components/StatusAndInfo/InfoBadge.qml +78 -0
  53. RinUI/components/StatusAndInfo/InfoBar.qml +246 -0
  54. RinUI/components/StatusAndInfo/ProgressBar.qml +127 -0
  55. RinUI/components/StatusAndInfo/Toast.qml +237 -0
  56. RinUI/components/StatusAndInfo/ToolTip.qml +93 -0
  57. RinUI/components/Text/SpinBox.qml +134 -0
  58. RinUI/components/Text/Text.qml +44 -0
  59. RinUI/components/Text/TextField.qml +94 -0
  60. RinUI/components/Text/TextInput.qml +29 -0
  61. RinUI/components/Utils/Blur.qml +42 -0
  62. RinUI/components/qmldir +76 -0
  63. RinUI/config/rin_ui.json +8 -0
  64. RinUI/core/__init__.py +3 -0
  65. RinUI/core/__pycache__/__init__.cpython-38.pyc +0 -0
  66. RinUI/core/__pycache__/config.cpython-38.pyc +0 -0
  67. RinUI/core/__pycache__/launcher.cpython-38.pyc +0 -0
  68. RinUI/core/__pycache__/theme.cpython-38.pyc +0 -0
  69. RinUI/core/config.py +109 -0
  70. RinUI/core/launcher.py +144 -0
  71. RinUI/core/theme.py +342 -0
  72. RinUI/hooks/__init__.py +3 -0
  73. RinUI/hooks/hook-RinUI.py +3 -0
  74. RinUI/qmldir +92 -0
  75. RinUI/themes/dark.qml +137 -0
  76. RinUI/themes/light.qml +137 -0
  77. RinUI/themes/qmldir +7 -0
  78. RinUI/themes/theme.qml +126 -0
  79. RinUI/themes/utils.qml +28 -0
  80. RinUI/utils/Animation.qml +12 -0
  81. RinUI/utils/FloatLayer.qml +123 -0
  82. RinUI/utils/FontIconLoader.qml +14 -0
  83. RinUI/utils/Position.qml +19 -0
  84. RinUI/utils/Severity.qml +13 -0
  85. RinUI/utils/Typography.qml +17 -0
  86. RinUI/utils/qmldir +5 -0
  87. RinUI/windows/CtrlBtn.qml +119 -0
  88. RinUI/windows/FluentPage.qml +92 -0
  89. RinUI/windows/FluentWindow.qml +32 -0
  90. RinUI/windows/FluentWindowBase.qml +157 -0
  91. RinUI/windows/TitleBar.qml +132 -0
  92. RinUI/windows/qmldir +8 -0
  93. RinUI/windows/window/ApplicationWindow.qml +9 -0
  94. RinUI/windows/window/Window.qml +112 -0
  95. rinui-0.0.9.data/data/LICENSE +21 -0
  96. rinui-0.0.9.data/data/README.md +90 -0
  97. rinui-0.0.9.dist-info/LICENSE +21 -0
  98. rinui-0.0.9.dist-info/METADATA +105 -0
  99. rinui-0.0.9.dist-info/RECORD +102 -0
  100. rinui-0.0.9.dist-info/WHEEL +5 -0
  101. rinui-0.0.9.dist-info/entry_points.txt +2 -0
  102. rinui-0.0.9.dist-info/top_level.txt +1 -0
@@ -0,0 +1,134 @@
1
+ import QtQuick 2.15
2
+ import Qt5Compat.GraphicalEffects
3
+ import QtQuick.Controls.Basic 2.15
4
+ import "../../themes"
5
+ import "../../components"
6
+
7
+
8
+ SpinBox {
9
+ id: root
10
+ editable: true
11
+
12
+ property color primaryColor: Theme.currentTheme.colors.primaryColor
13
+
14
+ contentItem: TextInput {
15
+ selectByMouse: true
16
+ text: root.textFromValue(root.value, root.locale)
17
+ horizontalAlignment: Qt.AlignLeft
18
+ verticalAlignment: Qt.AlignVCenter
19
+
20
+ readOnly: !root.editable
21
+ validator: root.validator
22
+ inputMethodHints: Qt.ImhFormattedNumbersOnly
23
+ }
24
+
25
+ implicitWidth: Math.max(implicitWidth + upBtn.width + downBtn.width + 8, 124)
26
+
27
+ // 背景 / Background //
28
+ background: Rectangle {
29
+ id: background
30
+ anchors.fill: parent
31
+ radius: Theme.currentTheme.appearance.buttonRadius
32
+ color: Theme.currentTheme.colors.controlColor
33
+ clip: true
34
+ border.width: Theme.currentTheme.appearance.borderWidth
35
+ border.color: Theme.currentTheme.colors.controlBorderColor
36
+
37
+ layer.enabled: true
38
+ layer.smooth: true
39
+ layer.effect: OpacityMask {
40
+ maskSource: Rectangle {
41
+ width: background.width
42
+ height: background.height
43
+ radius: background.radius
44
+ }
45
+ }
46
+
47
+ // 底部指示器 / indicator //
48
+ Rectangle {
49
+ id: indicator
50
+ width: parent.width
51
+ anchors.horizontalCenter: parent.horizontalCenter
52
+ anchors.bottom: parent.bottom
53
+ radius: 999
54
+ height: root.activeFocus ? Theme.currentTheme.appearance.borderWidth * 2 : Theme.currentTheme.appearance.borderWidth
55
+ color: root.activeFocus ? primaryColor : Theme.currentTheme.colors.textControlBorderColor
56
+
57
+ Behavior on color { ColorAnimation { duration: Utils.animationSpeed; easing.type: Easing.OutQuint } }
58
+ Behavior on height { NumberAnimation { duration: Utils.animationSpeed; easing.type: Easing.OutQuint } }
59
+ }
60
+ }
61
+
62
+ up.indicator: ToolButton {
63
+ id: upBtn
64
+ flat: true
65
+ z: 9
66
+ focusPolicy: editable ? Qt.StrongFocus : Qt.NoFocus
67
+ implicitWidth: 32
68
+ implicitHeight: 24
69
+ anchors.top: parent.top
70
+ anchors.right: downBtn.left
71
+ anchors.bottom: parent.bottom
72
+ anchors.margins: 4
73
+ anchors.bottomMargin: 6
74
+ icon.name: "ic_fluent_chevron_up_20_regular"
75
+ size: 16
76
+ color: Theme.currentTheme.colors.textSecondaryColor
77
+ hoverable: editable
78
+ onClicked: increase()
79
+ }
80
+
81
+ down.indicator: ToolButton {
82
+ id: downBtn
83
+ z: 9
84
+ flat: true
85
+ focusPolicy: editable ? Qt.StrongFocus : Qt.NoFocus
86
+ implicitWidth: 32
87
+ implicitHeight: 24
88
+ anchors.top: parent.top
89
+ anchors.right: parent.right
90
+ anchors.bottom: parent.bottom
91
+ anchors.margins: 4
92
+ anchors.bottomMargin: 6
93
+ icon.name: "ic_fluent_chevron_down_20_regular"
94
+ size: 16
95
+ color: Theme.currentTheme.colors.textSecondaryColor
96
+ hoverable: editable
97
+ onClicked: decrease()
98
+ }
99
+
100
+ leftPadding: 12
101
+ rightPadding: 12
102
+ topPadding: 5
103
+ bottomPadding: 7
104
+
105
+ Behavior on opacity { NumberAnimation { duration: Utils.animationSpeed; easing.type: Easing.OutQuint } }
106
+
107
+ // 状态变化
108
+ states: [
109
+ State {
110
+ name: "disabled"
111
+ when: !enabled
112
+ PropertyChanges { // 禁用时禁止改变属性
113
+ target: root;
114
+ opacity: !editable ? 1 : 0.4
115
+ }
116
+ },
117
+ State {
118
+ name: "pressed&focused"
119
+ when: activeFocus
120
+ PropertyChanges {
121
+ target: background;
122
+ color: Theme.currentTheme.colors.controlInputActiveColor
123
+ }
124
+ },
125
+ State {
126
+ name: "hovered"
127
+ when: hovered
128
+ PropertyChanges {
129
+ target: background;
130
+ color: Theme.currentTheme.colors.controlSecondaryColor
131
+ }
132
+ }
133
+ ]
134
+ }
@@ -0,0 +1,44 @@
1
+ import QtQuick
2
+ import QtQuick.Controls
3
+ import "../../themes"
4
+ import "../../utils"
5
+
6
+ Text {
7
+ id: label
8
+ property int typography: Typography.Body
9
+
10
+ color: targetColor
11
+ property color targetColor: Theme.currentTheme.colors.textColor // 目标颜色,用于切换动画
12
+ wrapMode: Text.WordWrap
13
+
14
+ // 主题切换动画 TODO: 会坠机
15
+ // Behavior on color {
16
+ // ColorAnimation {
17
+ // duration: Utils.appearanceSpeed
18
+ // easing.type: Easing.OutQuart
19
+ // }
20
+ // }
21
+
22
+ font.pixelSize: {
23
+ switch (typography) {
24
+ case Typography.Display: return Theme.currentTheme.typography.displaySize;
25
+ case Typography.TitleLarge: return Theme.currentTheme.typography.titleLargeSize;
26
+ case Typography.Title: return Theme.currentTheme.typography.titleSize;
27
+ case Typography.Subtitle: return Theme.currentTheme.typography.subtitleSize;
28
+ case Typography.Body: return Theme.currentTheme.typography.bodySize;
29
+ case Typography.BodyStrong: return Theme.currentTheme.typography.bodyStrongSize;
30
+ case Typography.BodyLarge: return Theme.currentTheme.typography.bodyLargeSize;
31
+ case Typography.Caption: return Theme.currentTheme.typography.captionSize;
32
+ default: return Theme.currentTheme.typography.bodySize;
33
+ }
34
+ }
35
+
36
+ font.family: Utils.fontFamily
37
+
38
+ font.bold: typography === Typography.Display ||
39
+ typography === Typography.TitleLarge ||
40
+ typography === Typography.Title ||
41
+ typography === Typography.Subtitle ||
42
+ typography === Typography.BodyLarge ||
43
+ typography === Typography.BodyStrong
44
+ }
@@ -0,0 +1,94 @@
1
+ import QtQuick 2.15
2
+ import Qt5Compat.GraphicalEffects
3
+ import QtQuick.Controls.Basic 2.15
4
+ import "../../themes"
5
+
6
+ TextField {
7
+ id: root
8
+
9
+ property bool frameless: false
10
+ property bool editable: true
11
+ property color primaryColor: Theme.currentTheme.colors.primaryColor
12
+
13
+ selectByMouse: true
14
+ enabled: editable
15
+
16
+ // 背景 / Background //
17
+ background: Rectangle {
18
+ id: background
19
+ anchors.fill: parent
20
+ radius: Theme.currentTheme.appearance.buttonRadius
21
+ color: frameless ? "transparent" : Theme.currentTheme.colors.controlColor
22
+ clip: true
23
+ border.width: Theme.currentTheme.appearance.borderWidth
24
+ border.color: frameless ? root.activeFocus ? Theme.currentTheme.colors.controlBorderColor : "transparent" :
25
+ Theme.currentTheme.colors.controlBorderColor
26
+
27
+ layer.enabled: true
28
+ layer.smooth: true
29
+ layer.effect: OpacityMask {
30
+ maskSource: Rectangle {
31
+ width: background.width
32
+ height: background.height
33
+ radius: background.radius
34
+ }
35
+ }
36
+
37
+ // 底部指示器 / indicator //
38
+ Rectangle {
39
+ id: indicator
40
+ width: parent.width
41
+ anchors.horizontalCenter: parent.horizontalCenter
42
+ anchors.bottom: parent.bottom
43
+ radius: 999
44
+ height: root.activeFocus ? Theme.currentTheme.appearance.borderWidth * 2 : Theme.currentTheme.appearance.borderWidth
45
+ color: root.activeFocus ? primaryColor : frameless ? "transparent" : Theme.currentTheme.colors.textControlBorderColor
46
+
47
+ Behavior on color { ColorAnimation { duration: Utils.animationSpeed; easing.type: Easing.OutQuint } }
48
+ Behavior on height { NumberAnimation { duration: Utils.animationSpeed; easing.type: Easing.OutQuint } }
49
+ }
50
+ }
51
+
52
+ Behavior on opacity { NumberAnimation { duration: Utils.animationSpeed; easing.type: Easing.OutQuint } }
53
+
54
+
55
+ // 字体 / Font //
56
+ font.pixelSize: Theme.currentTheme.typography.bodySize
57
+
58
+ selectionColor: Theme.currentTheme.colors.primaryColor
59
+ color: Theme.currentTheme.colors.textColor
60
+ placeholderTextColor: Theme.currentTheme.colors.textSecondaryColor
61
+
62
+ leftPadding: 12
63
+ rightPadding: 12
64
+ topPadding: 5
65
+ bottomPadding: 7
66
+
67
+ // 状态变化
68
+ states: [
69
+ State {
70
+ name: "disabled"
71
+ when: !enabled
72
+ PropertyChanges { // 禁用时禁止改变属性
73
+ target: root;
74
+ opacity: !editable ? 1 : 0.4
75
+ }
76
+ },
77
+ State {
78
+ name: "pressed&focused"
79
+ when: activeFocus
80
+ PropertyChanges {
81
+ target: background;
82
+ color: Theme.currentTheme.colors.controlInputActiveColor
83
+ }
84
+ },
85
+ State {
86
+ name: "hovered"
87
+ when: hovered
88
+ PropertyChanges {
89
+ target: background;
90
+ color: Theme.currentTheme.colors.controlSecondaryColor
91
+ }
92
+ }
93
+ ]
94
+ }
@@ -0,0 +1,29 @@
1
+ import QtQuick 2.15
2
+ import Qt5Compat.GraphicalEffects
3
+ import QtQuick.Controls.Basic 2.15
4
+ import "../../themes"
5
+ import "../../components"
6
+
7
+
8
+ TextInput {
9
+ id: root
10
+ property int typography: Typography.Body
11
+ selectByMouse: true
12
+
13
+ color: Theme.currentTheme.colors.textColor
14
+ selectionColor: Theme.currentTheme.colors.primaryColor
15
+
16
+ font.pixelSize: {
17
+ switch (typography) {
18
+ case Typography.Display: return Theme.currentTheme.typography.displaySize;
19
+ case Typography.TitleLarge: return Theme.currentTheme.typography.titleLargeSize;
20
+ case Typography.Title: return Theme.currentTheme.typography.titleSize;
21
+ case Typography.Subtitle: return Theme.currentTheme.typography.subtitleSize;
22
+ case Typography.Body: return Theme.currentTheme.typography.bodySize;
23
+ case Typography.BodyStrong: return Theme.currentTheme.typography.bodyStrongSize;
24
+ case Typography.BodyLarge: return Theme.currentTheme.typography.bodyLargeSize;
25
+ case Typography.Caption: return Theme.currentTheme.typography.captionSize;
26
+ default: return Theme.currentTheme.typography.bodySize;
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,42 @@
1
+ import QtQuick
2
+ import Qt5Compat.GraphicalEffects
3
+ import FluentUI
4
+
5
+ Item {
6
+ id: control
7
+ property color tintColor: Qt.rgba(1, 1, 1, 1)
8
+ property real tintOpacity: 0.65
9
+ property real luminosity: 0.01
10
+ property real noiseOpacity: 0.02
11
+ property var target
12
+ property int blurRadius: 32
13
+ property rect targetRect: Qt.rect(control.x, control.y, control.width,control.height)
14
+
15
+ ShaderEffectSource {
16
+ id: effect_source
17
+ anchors.fill: parent
18
+ visible: false
19
+ sourceRect: control.targetRect
20
+ sourceItem: control.target
21
+ }
22
+ FastBlur {
23
+ id: fast_blur
24
+ anchors.fill: parent
25
+ source: effect_source
26
+ radius: control.blurRadius
27
+ }
28
+ Rectangle {
29
+ anchors.fill: parent
30
+ color: Qt.rgba(1, 1, 1, luminosity)
31
+ }
32
+ Rectangle {
33
+ anchors.fill: parent
34
+ color: Qt.rgba(tintColor.r, tintColor.g, tintColor.b, tintOpacity)
35
+ }
36
+ Image {
37
+ anchors.fill: parent
38
+ source: "qrc:/qt/qml/FluentUI/Image/noise.png"
39
+ fillMode: Image.Tile
40
+ opacity: control.noiseOpacity
41
+ }
42
+ }
@@ -0,0 +1,76 @@
1
+ module RinUI.Components
2
+
3
+ Base 1.0 Base.qml
4
+ Shadow 1.0 Shadow.qml
5
+ FocusIndicator 1.0 FocusIndicator.qml
6
+
7
+ IconWidget 1.0 IconWidget.qml
8
+
9
+ ContextMenu 1.0 ContextMenu.qml
10
+
11
+
12
+ ScrollBar 1.0 ScrollBar.qml
13
+ ScrollView 1.0 ScrollView.qml
14
+
15
+ # Basic Input
16
+ Button 1.0 BasicInput/Button.qml
17
+ HyperlinkButton 1.0 BasicInput/HyperlinkButton.qml
18
+ Slider 1.0 BasicInput/Slider.qml
19
+ Hyperlink 1.0 BasicInput/Hyperlink.qml
20
+ ToolButton 1.0 BasicInput/ToolButton.qml
21
+ Switch 1.0 BasicInput/Switch.qml
22
+ RadioButton 1.0 BasicInput/RadioButton.qml
23
+
24
+ # Date & Time
25
+ PickerView 1.0 DateAndTime/PickerView.qml
26
+ # TimePicker 1.0 DateAndTime/TimePicker.qml
27
+
28
+ # Dialogs & Flyouts
29
+ Dialog 1.0 DialogsAndFlyouts/Dialog.qml
30
+ DialogButtonBox 1.0 DialogsAndFlyouts/DialogButtonBox.qml
31
+ Flyout 1.0 DialogsAndFlyouts/Flyout.qml
32
+ Popup 1.0 DialogsAndFlyouts/Popup.qml
33
+
34
+ # Layout
35
+ Expander 1.0 Layout/Expander.qml
36
+
37
+ # Status & Info
38
+ InfoBar 1.0 StatusAndInfo/InfoBar.qml
39
+ ProgressBar 1.0 StatusAndInfo/ProgressBar.qml
40
+ ToolTip 1.0 StatusAndInfo/ToolTip.qml
41
+
42
+ # Text
43
+ TextField 1.0 Text/TextField.qml
44
+ TextInput 1.0 Text/TextInput.qml
45
+ Text 1.0 Text/Text.qml
46
+
47
+ # Menus & Toolbars
48
+ Menu 1.0 MenusAndToolbars/Menu.qml
49
+ MenuItem 1.0 MenusAndToolbars/MenuItem.qml
50
+ MenuItemGroup 1.0 MenusAndToolbars/MenuItemGroup.qml
51
+ MenuSeparator 1.0 MenusAndToolbars/MenuSeparator.qml
52
+ ToolSeparator 1.0 MenusAndToolbars/ToolSeparator.qml
53
+ MenuBar 1.0 MenusAndToolbars/MenuBar.qml
54
+
55
+ # Navigation
56
+ NavigationView 1.0 Navigation/NavigationView.qml
57
+ NavigationBar 1.0 Navigation/NavigationBar.qml
58
+ NavigationItem 1.0 Navigation/NavigationItem.qml
59
+ NavigationSubItem 1.0 Navigation/NavigationSubItem.qml
60
+
61
+ # ListAndCollections
62
+ Frame 1.0 ListAndCollections/Frame.qml
63
+ Clip 1.0 ListAndCollections/Clip.qml
64
+ # ListView 1.0 ListAndCollections/ListView.qml
65
+ ListViewDelegate 1.0 ListAndCollections/ListViewDelegate.qml
66
+ TableViewDelegate 1.0 ListAndCollections/TableViewDelegate.qml
67
+
68
+ Indicator 1.0 Indicator.qml
69
+
70
+
71
+ singleton Theme 1.0 ../themes/theme.qml
72
+ singleton Typography 1.0 ../utils/Typography.qml
73
+ singleton Severity 1.0 ../utils/Severity.qml
74
+ singleton Position 1.0 ../utils/Position.qml
75
+
76
+ FloatLayer 1.0 ../utils/FloatLayer.qml
@@ -0,0 +1,8 @@
1
+ {
2
+ "language": "zh_CN",
3
+ "theme": {
4
+ "current_theme": "Auto"
5
+ },
6
+ "theme_color": "#605ed2",
7
+ "backdrop_effect": "mica"
8
+ }
RinUI/core/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .theme import ThemeManager
2
+ from .launcher import RinUIWindow
3
+ from .config import DEFAULT_CONFIG, ConfigCenter, PATH, Theme, BackdropEffect
RinUI/core/config.py ADDED
@@ -0,0 +1,109 @@
1
+ import os
2
+ import json
3
+ import platform
4
+ from enum import Enum
5
+
6
+
7
+ def is_win11():
8
+ if is_windows():
9
+ if platform.release() >= '10' and int(platform.version().split('.')[2]) >= 22000:
10
+ return True
11
+ return False
12
+
13
+
14
+ def is_win10():
15
+ if is_windows():
16
+ if platform.release() >= '10' and int(platform.version().split('.')[2]) >= 19000:
17
+ return True
18
+ return False
19
+
20
+
21
+ def is_windows():
22
+ return platform.system() == 'Windows'
23
+
24
+
25
+ BASE_DIR = os.path.abspath(os.getcwd())
26
+ PATH = os.path.join(BASE_DIR, "RinUI/config")
27
+ DEFAULT_CONFIG = {
28
+ "language": "zh_CN",
29
+ "theme": {
30
+ "current_theme": "Auto",
31
+ },
32
+ "win10_feat": {
33
+ "backdrop_light": 0xA6FFFFFF,
34
+ "backdrop_dark": 0xA6000000,
35
+ },
36
+ "theme_color": "#605ed2",
37
+ "backdrop_effect": "mica" if is_win11() else "acrylic" if is_win10() else "none",
38
+ }
39
+
40
+
41
+ class Theme(Enum):
42
+ Auto = "Auto"
43
+ Dark = "Dark"
44
+ Light = "Light"
45
+
46
+
47
+ class BackdropEffect(Enum):
48
+ None_ = "none"
49
+ Acrylic = "acrylic"
50
+ Mica = "mica"
51
+ Tabbed = "tabbed"
52
+
53
+
54
+ class ConfigCenter:
55
+ def __init__(self, path, filename):
56
+ self.path = path
57
+ self.filename = filename
58
+ self.config = {}
59
+ self.full_path = os.path.join(self.path, self.filename)
60
+
61
+ def load_config(self, default_config):
62
+ if default_config is None:
63
+ print('Warning: "default_config" is None, use empty config instead.')
64
+ default_config = {}
65
+ # 如果文件存在,加载配置
66
+ if os.path.exists(self.full_path):
67
+ with open(self.full_path, 'r', encoding='utf-8') as f:
68
+ self.config = json.load(f)
69
+ else:
70
+ self.config = default_config # 如果文件不存在,使用默认配置
71
+ self.save_config()
72
+
73
+ def update_config(self): # 更新配置
74
+ try:
75
+ with open(self.full_path, 'r', encoding='utf-8') as f:
76
+ self.config = json.load(f)
77
+ except Exception as e:
78
+ print(f'Error: {e}')
79
+ self.config = {}
80
+
81
+ def upload_config(self, key=str or list, value=None):
82
+ if type(key) is str:
83
+ self.config[key] = value
84
+ elif type(key) is list:
85
+ for k in key:
86
+ self.config[k] = value
87
+ else:
88
+ raise TypeError('key must be str or list')
89
+ self.save_config()
90
+
91
+ def save_config(self):
92
+ try:
93
+ # 确保配置文件目录存在
94
+ if not os.path.exists(self.path):
95
+ os.makedirs(self.path)
96
+ with open(self.full_path, 'w', encoding='utf-8') as f:
97
+ json.dump(self.config, f, ensure_ascii=False, indent=4)
98
+ except Exception as e:
99
+ print(f'Error: {e}')
100
+
101
+ def __getitem__(self, key):
102
+ return self.config.get(key)
103
+
104
+ def __setitem__(self, key, value):
105
+ self.config[key] = value
106
+ self.save_config()
107
+
108
+ def __repr__(self):
109
+ return json.dumps(self.config, ensure_ascii=False, indent=4)