tinuislider 1.0.0__tar.gz
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.
- tinuislider-1.0.0/LICENSE +201 -0
- tinuislider-1.0.0/PKG-INFO +119 -0
- tinuislider-1.0.0/README.md +104 -0
- tinuislider-1.0.0/pyproject.toml +28 -0
- tinuislider-1.0.0/setup.cfg +4 -0
- tinuislider-1.0.0/tinuislider/__init__.py +9 -0
- tinuislider-1.0.0/tinuislider/centerslider.py +374 -0
- tinuislider-1.0.0/tinuislider.egg-info/PKG-INFO +119 -0
- tinuislider-1.0.0/tinuislider.egg-info/SOURCES.txt +10 -0
- tinuislider-1.0.0/tinuislider.egg-info/dependency_links.txt +1 -0
- tinuislider-1.0.0/tinuislider.egg-info/requires.txt +1 -0
- tinuislider-1.0.0/tinuislider.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tinuislider
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: tinui高级滑动条
|
|
5
|
+
Author-email: Smart-Space <smart-space@qq.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Repository, https://github.com/Smart-Space/TinUISlider
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: tinui
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# TinUISheet
|
|
17
|
+
|
|
18
|
+
[TinUI](https://github.com/Smart-Space/TinUI)的高级滑动条控件。
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
> [!NOTE]
|
|
22
|
+
>
|
|
23
|
+
> `tinuislider`提供`sliderlight`和`sliderdark`两种**样式配色**。
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## CenterSlider
|
|
28
|
+
|
|
29
|
+
<img width="200" src="./screenshots/center.png" />
|
|
30
|
+
|
|
31
|
+
`tinuislider.centerslider.CenterSlider`
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
CenterSlider(
|
|
35
|
+
canvas: BasicTinUI,
|
|
36
|
+
pos: tuple,
|
|
37
|
+
width=200,
|
|
38
|
+
fg="#4554dc",
|
|
39
|
+
activefg="#4554dc",
|
|
40
|
+
bg="#868686",
|
|
41
|
+
buttonbg="#ffffff",
|
|
42
|
+
buttonoutline="#cccccc",
|
|
43
|
+
data=(1, 2, 3, 4, 5),
|
|
44
|
+
start=None, # 默认为中间索引
|
|
45
|
+
direction="x",
|
|
46
|
+
anchor="nw",
|
|
47
|
+
command=None,
|
|
48
|
+
)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
参数与TinUI原生`scalebar`一致。
|
|
52
|
+
|
|
53
|
+
> **注意**,`start`是索引,不是值。
|
|
54
|
+
|
|
55
|
+
> [!tip]
|
|
56
|
+
>
|
|
57
|
+
> 通过`CenterSlider.uid`获取控件标识符,用于TinUI面板布局。其对面板布局的响应与原生`scalebar`一致。
|
|
58
|
+
|
|
59
|
+
#### select(num)
|
|
60
|
+
|
|
61
|
+
选中某一项**索引**。
|
|
62
|
+
|
|
63
|
+
#### disable(sign='#C8C8C8')
|
|
64
|
+
|
|
65
|
+
禁用,`sign`为禁用时标识色。
|
|
66
|
+
|
|
67
|
+
#### active_state()
|
|
68
|
+
|
|
69
|
+
激活控件。
|
|
70
|
+
|
|
71
|
+
#### get()
|
|
72
|
+
|
|
73
|
+
获取当前**选中值**。
|
|
74
|
+
|
|
75
|
+
#### set(value)
|
|
76
|
+
|
|
77
|
+
选中某一项**值**,需要在`data`中。
|
|
78
|
+
|
|
79
|
+
#### 示例
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from tkinter import Tk
|
|
83
|
+
from tinui import ExpandPanel, VerticalPanel
|
|
84
|
+
def on_resize(event):
|
|
85
|
+
rp.update_layout(10,10,event.width-10,event.height-10)
|
|
86
|
+
r=Tk()
|
|
87
|
+
|
|
88
|
+
ui=BasicTinUI(r)
|
|
89
|
+
ui.pack(fill='both',expand=True)
|
|
90
|
+
|
|
91
|
+
slider = CenterSlider(
|
|
92
|
+
canvas=ui,
|
|
93
|
+
pos=(0, 100),
|
|
94
|
+
width=200,
|
|
95
|
+
data=range(-10,11),
|
|
96
|
+
start=3, # start是索引,不是值,所以这里是选中数据中的第4项
|
|
97
|
+
anchor="center",
|
|
98
|
+
command=lambda v: print(f"Selected: {v}")
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
# 获取当前值
|
|
102
|
+
val = slider.get()
|
|
103
|
+
print(f"Current value: {val}")
|
|
104
|
+
slider.set(5) # 设置选中值为 5
|
|
105
|
+
print(f"Value after set: {slider.get()}")
|
|
106
|
+
|
|
107
|
+
rp = ExpandPanel(ui)
|
|
108
|
+
vp = VerticalPanel(ui)
|
|
109
|
+
rp.set_child(vp)
|
|
110
|
+
|
|
111
|
+
ep1 = ExpandPanel(ui)
|
|
112
|
+
vp.add_child(ep1, weight=1)
|
|
113
|
+
ep1.set_child(slider.uid)
|
|
114
|
+
|
|
115
|
+
ui.bind("<Configure>", on_resize)
|
|
116
|
+
|
|
117
|
+
r.mainloop()
|
|
118
|
+
```
|
|
119
|
+
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# TinUISheet
|
|
2
|
+
|
|
3
|
+
[TinUI](https://github.com/Smart-Space/TinUI)的高级滑动条控件。
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
> [!NOTE]
|
|
7
|
+
>
|
|
8
|
+
> `tinuislider`提供`sliderlight`和`sliderdark`两种**样式配色**。
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## CenterSlider
|
|
13
|
+
|
|
14
|
+
<img width="200" src="./screenshots/center.png" />
|
|
15
|
+
|
|
16
|
+
`tinuislider.centerslider.CenterSlider`
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
CenterSlider(
|
|
20
|
+
canvas: BasicTinUI,
|
|
21
|
+
pos: tuple,
|
|
22
|
+
width=200,
|
|
23
|
+
fg="#4554dc",
|
|
24
|
+
activefg="#4554dc",
|
|
25
|
+
bg="#868686",
|
|
26
|
+
buttonbg="#ffffff",
|
|
27
|
+
buttonoutline="#cccccc",
|
|
28
|
+
data=(1, 2, 3, 4, 5),
|
|
29
|
+
start=None, # 默认为中间索引
|
|
30
|
+
direction="x",
|
|
31
|
+
anchor="nw",
|
|
32
|
+
command=None,
|
|
33
|
+
)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
参数与TinUI原生`scalebar`一致。
|
|
37
|
+
|
|
38
|
+
> **注意**,`start`是索引,不是值。
|
|
39
|
+
|
|
40
|
+
> [!tip]
|
|
41
|
+
>
|
|
42
|
+
> 通过`CenterSlider.uid`获取控件标识符,用于TinUI面板布局。其对面板布局的响应与原生`scalebar`一致。
|
|
43
|
+
|
|
44
|
+
#### select(num)
|
|
45
|
+
|
|
46
|
+
选中某一项**索引**。
|
|
47
|
+
|
|
48
|
+
#### disable(sign='#C8C8C8')
|
|
49
|
+
|
|
50
|
+
禁用,`sign`为禁用时标识色。
|
|
51
|
+
|
|
52
|
+
#### active_state()
|
|
53
|
+
|
|
54
|
+
激活控件。
|
|
55
|
+
|
|
56
|
+
#### get()
|
|
57
|
+
|
|
58
|
+
获取当前**选中值**。
|
|
59
|
+
|
|
60
|
+
#### set(value)
|
|
61
|
+
|
|
62
|
+
选中某一项**值**,需要在`data`中。
|
|
63
|
+
|
|
64
|
+
#### 示例
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from tkinter import Tk
|
|
68
|
+
from tinui import ExpandPanel, VerticalPanel
|
|
69
|
+
def on_resize(event):
|
|
70
|
+
rp.update_layout(10,10,event.width-10,event.height-10)
|
|
71
|
+
r=Tk()
|
|
72
|
+
|
|
73
|
+
ui=BasicTinUI(r)
|
|
74
|
+
ui.pack(fill='both',expand=True)
|
|
75
|
+
|
|
76
|
+
slider = CenterSlider(
|
|
77
|
+
canvas=ui,
|
|
78
|
+
pos=(0, 100),
|
|
79
|
+
width=200,
|
|
80
|
+
data=range(-10,11),
|
|
81
|
+
start=3, # start是索引,不是值,所以这里是选中数据中的第4项
|
|
82
|
+
anchor="center",
|
|
83
|
+
command=lambda v: print(f"Selected: {v}")
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# 获取当前值
|
|
87
|
+
val = slider.get()
|
|
88
|
+
print(f"Current value: {val}")
|
|
89
|
+
slider.set(5) # 设置选中值为 5
|
|
90
|
+
print(f"Value after set: {slider.get()}")
|
|
91
|
+
|
|
92
|
+
rp = ExpandPanel(ui)
|
|
93
|
+
vp = VerticalPanel(ui)
|
|
94
|
+
rp.set_child(vp)
|
|
95
|
+
|
|
96
|
+
ep1 = ExpandPanel(ui)
|
|
97
|
+
vp.add_child(ep1, weight=1)
|
|
98
|
+
ep1.set_child(slider.uid)
|
|
99
|
+
|
|
100
|
+
ui.bind("<Configure>", on_resize)
|
|
101
|
+
|
|
102
|
+
r.mainloop()
|
|
103
|
+
```
|
|
104
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tinuislider"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "tinui高级滑动条"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Smart-Space", email = "smart-space@qq.com"},
|
|
14
|
+
]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
requires-python = ">=3.8"
|
|
20
|
+
dependencies = [
|
|
21
|
+
"tinui",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[tool.setuptools]
|
|
25
|
+
packages = ["tinuislider"]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Repository = "https://github.com/Smart-Space/TinUISlider"
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
from tinui import BasicTinUI
|
|
2
|
+
from tinui.TinUI import TinUIString
|
|
3
|
+
|
|
4
|
+
class CenterSlider:
|
|
5
|
+
"""
|
|
6
|
+
中心起点双向滑块控件
|
|
7
|
+
基于 BasicTinUI 的 add_scalebar 逻辑重构,以 pos 为中心,向两侧延伸
|
|
8
|
+
"""
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
canvas: BasicTinUI,
|
|
12
|
+
pos: tuple,
|
|
13
|
+
width=200,
|
|
14
|
+
fg="#4554dc",
|
|
15
|
+
activefg="#4554dc",
|
|
16
|
+
bg="#868686",
|
|
17
|
+
buttonbg="#ffffff",
|
|
18
|
+
buttonoutline="#cccccc",
|
|
19
|
+
data=(1, 2, 3, 4, 5),
|
|
20
|
+
start=None, # 默认为中间索引
|
|
21
|
+
direction="x",
|
|
22
|
+
anchor="nw",
|
|
23
|
+
command=None,
|
|
24
|
+
):
|
|
25
|
+
self.canvas = canvas
|
|
26
|
+
self.pos = list(pos)
|
|
27
|
+
self.width = width
|
|
28
|
+
self.fg = fg
|
|
29
|
+
self.activefg = activefg
|
|
30
|
+
self.bg = bg
|
|
31
|
+
self.buttonbg = buttonbg
|
|
32
|
+
self.buttonoutline = buttonoutline
|
|
33
|
+
self.data = data
|
|
34
|
+
self.direction = direction
|
|
35
|
+
self.anchor = anchor
|
|
36
|
+
self.command = command
|
|
37
|
+
|
|
38
|
+
self.nowselect = 0
|
|
39
|
+
if start is None:
|
|
40
|
+
self.nowselect = len(data) // 2 # 默认中间
|
|
41
|
+
else:
|
|
42
|
+
self.nowselect = start
|
|
43
|
+
|
|
44
|
+
self.dash = [] # 刻度位置列表
|
|
45
|
+
self.uid = None
|
|
46
|
+
self.back = None
|
|
47
|
+
self.active = None
|
|
48
|
+
self.button = None
|
|
49
|
+
self.button_fore = None
|
|
50
|
+
|
|
51
|
+
# 记录拖拽起始位置
|
|
52
|
+
self.startpos = 0
|
|
53
|
+
|
|
54
|
+
self._init_items()
|
|
55
|
+
self._calc_dash()
|
|
56
|
+
self._bind_events()
|
|
57
|
+
self._apply_layout()
|
|
58
|
+
|
|
59
|
+
# 初始化选中状态
|
|
60
|
+
self.select(self.nowselect, send=False)
|
|
61
|
+
|
|
62
|
+
def _init_items(self):
|
|
63
|
+
"""创建基础图形元素"""
|
|
64
|
+
half_width = self.width / 2
|
|
65
|
+
# 计算背景线坐标
|
|
66
|
+
if self.direction == "x":
|
|
67
|
+
back_coords = (self.pos[0] - half_width, self.pos[1] + 8,
|
|
68
|
+
self.pos[0] + half_width, self.pos[1] + 8)
|
|
69
|
+
elif self.direction == "y":
|
|
70
|
+
back_coords = (self.pos[0] + 8, self.pos[1] + half_width,
|
|
71
|
+
self.pos[0] + 8, self.pos[1] - half_width)
|
|
72
|
+
else:
|
|
73
|
+
# 仅这一处提醒
|
|
74
|
+
raise ValueError("Direction must be 'x' or 'y'")
|
|
75
|
+
|
|
76
|
+
self.back = self.canvas.create_line(
|
|
77
|
+
back_coords,
|
|
78
|
+
fill=self.bg,
|
|
79
|
+
width=3,
|
|
80
|
+
capstyle="round",
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
self.uid = TinUIString(f"centerscale-{self.back}")
|
|
84
|
+
self.uid.layout = self.__layout
|
|
85
|
+
self.canvas.itemconfig(self.back, tags=self.uid)
|
|
86
|
+
|
|
87
|
+
def _calc_dash(self):
|
|
88
|
+
"""计算刻度位置,以 pos 为中心分布"""
|
|
89
|
+
half_width = self.width / 2
|
|
90
|
+
step = self.width / (len(self.data) - 1) if len(self.data) > 1 else 0
|
|
91
|
+
|
|
92
|
+
self.dash.clear()
|
|
93
|
+
if self.direction == "x":
|
|
94
|
+
start_x = self.pos[0] - half_width
|
|
95
|
+
for _ in self.data:
|
|
96
|
+
self.dash.append(start_x)
|
|
97
|
+
start_x += step
|
|
98
|
+
else:
|
|
99
|
+
start_y = self.pos[1] + half_width
|
|
100
|
+
for _ in self.data:
|
|
101
|
+
self.dash.append(start_y)
|
|
102
|
+
start_y -= step
|
|
103
|
+
|
|
104
|
+
def _bind_events(self):
|
|
105
|
+
"""绑定事件"""
|
|
106
|
+
init_pos = self.dash[self.nowselect]
|
|
107
|
+
|
|
108
|
+
self.button = f"scalebutton_center-{self.back}"
|
|
109
|
+
|
|
110
|
+
btn_tags = (self.uid, self.button)
|
|
111
|
+
|
|
112
|
+
self.canvas.create_text(
|
|
113
|
+
(init_pos + 9, self.pos[1] + 9) if self.direction == "x" else (self.pos[0] + 8, init_pos + 9),
|
|
114
|
+
text="\uf127",
|
|
115
|
+
font="{Segoe Fluent Icons} 12",
|
|
116
|
+
fill=self.buttonbg,
|
|
117
|
+
tags=btn_tags,
|
|
118
|
+
)
|
|
119
|
+
self.canvas.create_text(
|
|
120
|
+
(init_pos + 9, self.pos[1] + 9) if self.direction == "x" else (self.pos[0] + 8, init_pos + 9),
|
|
121
|
+
text="\uecca",
|
|
122
|
+
font="{Segoe Fluent Icons} 12",
|
|
123
|
+
fill=self.buttonoutline,
|
|
124
|
+
tags=btn_tags,
|
|
125
|
+
)
|
|
126
|
+
self.button_fore = self.canvas.create_text(
|
|
127
|
+
(init_pos + 9, self.pos[1] + 9) if self.direction == "x" else (self.pos[0] + 8, init_pos + 9),
|
|
128
|
+
text="\ue915",
|
|
129
|
+
font="{Segoe Fluent Icons} 12",
|
|
130
|
+
fill=self.fg,
|
|
131
|
+
tags=btn_tags,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
self.canvas.tag_bind(self.button, "<Enter>", lambda _: self.canvas.itemconfig(self.button_fore, fill=self.activefg))
|
|
135
|
+
self.canvas.tag_bind(self.button, "<Leave>", lambda _: self.canvas.itemconfig(self.button_fore, fill=self.fg))
|
|
136
|
+
self.canvas.tag_bind(self.button, "<Button-1>", self._mousedown)
|
|
137
|
+
self.canvas.tag_bind(self.button, "<B1-Motion>", self._drag)
|
|
138
|
+
self.canvas.tag_bind(self.button, "<ButtonRelease-1>", self._check)
|
|
139
|
+
self.canvas.tag_bind(self.back, "<Button-1>", self._checkval)
|
|
140
|
+
|
|
141
|
+
# 激活线
|
|
142
|
+
if self.direction == "x":
|
|
143
|
+
self.active = self.canvas.create_line(
|
|
144
|
+
(self.pos[0], self.pos[1] + 8, init_pos, self.pos[1] + 8),
|
|
145
|
+
fill=self.fg,
|
|
146
|
+
width=3,
|
|
147
|
+
tags=self.uid,
|
|
148
|
+
capstyle="round",
|
|
149
|
+
)
|
|
150
|
+
else:
|
|
151
|
+
self.active = self.canvas.create_line(
|
|
152
|
+
(self.pos[0] + 8, self.pos[1], self.pos[0] + 8, init_pos),
|
|
153
|
+
fill=self.fg,
|
|
154
|
+
width=3,
|
|
155
|
+
tags=self.uid,
|
|
156
|
+
capstyle="round",
|
|
157
|
+
)
|
|
158
|
+
self.canvas.tag_bind(self.active, "<Button-1>", self._checkval)
|
|
159
|
+
|
|
160
|
+
self.canvas.lift(self.button)
|
|
161
|
+
|
|
162
|
+
def __layout(self, x1, y1, x2, y2, expand=False):
|
|
163
|
+
"""面板布局"""
|
|
164
|
+
if not expand:
|
|
165
|
+
dx, dy = self.canvas._BasicTinUI__auto_layout(self.uid, (x1,y1,x2,y2), self.anchor)
|
|
166
|
+
self.pos[0] += dx
|
|
167
|
+
self.pos[1] += dy
|
|
168
|
+
self._rewrite_dash(dx, dy)
|
|
169
|
+
else:
|
|
170
|
+
dx, dy = self.canvas._BasicTinUI__auto_layout(self.uid, (x1,y1,x2,y2), "center")
|
|
171
|
+
self.pos[0] += dx
|
|
172
|
+
self.pos[1] += dy
|
|
173
|
+
self.dash.clear()
|
|
174
|
+
if self.direction == "x":
|
|
175
|
+
self.width = x2 - x1
|
|
176
|
+
dash_t = self.width / (len(self.data) - 1) if len(self.data) > 1 else 0
|
|
177
|
+
s = x1
|
|
178
|
+
self.dash.append(s)
|
|
179
|
+
for _ in self.data[1:]:
|
|
180
|
+
s += dash_t
|
|
181
|
+
self.dash.append(s)
|
|
182
|
+
else:
|
|
183
|
+
self.width = y2 - y1
|
|
184
|
+
dash_t = self.width / (len(self.data) - 1) if len(self.data) > 1 else 0
|
|
185
|
+
s = y2
|
|
186
|
+
self.dash.append(s)
|
|
187
|
+
for _ in self.data[1:]:
|
|
188
|
+
s -= dash_t
|
|
189
|
+
self.dash.append(s)
|
|
190
|
+
self._rewrite_dash(0, 0, False)
|
|
191
|
+
self.select(self.nowselect, send=False)
|
|
192
|
+
|
|
193
|
+
def _apply_layout(self):
|
|
194
|
+
dx, dy = self.canvas._BasicTinUI__auto_anchor(self.uid, self.pos, self.anchor)
|
|
195
|
+
self.pos[0] += dx
|
|
196
|
+
self.pos[1] += dy
|
|
197
|
+
self._rewrite_dash(dx, dy)
|
|
198
|
+
|
|
199
|
+
def _rewrite_dash(self, dx, dy, re_dash=True):
|
|
200
|
+
"""当布局变动时重写刻度位置"""
|
|
201
|
+
if re_dash:
|
|
202
|
+
for i in range(len(self.dash)):
|
|
203
|
+
if self.direction == "x":
|
|
204
|
+
self.dash[i] += dx
|
|
205
|
+
else:
|
|
206
|
+
self.dash[i] += dy
|
|
207
|
+
# 更新背景线坐标
|
|
208
|
+
half_width = self.width / 2
|
|
209
|
+
if self.direction == "x":
|
|
210
|
+
self.canvas.coords(self.back,
|
|
211
|
+
self.pos[0] - half_width, self.pos[1] + 8,
|
|
212
|
+
self.pos[0] + half_width, self.pos[1] + 8)
|
|
213
|
+
else:
|
|
214
|
+
self.canvas.coords(self.back,
|
|
215
|
+
self.pos[0] + 8, self.pos[1] + half_width,
|
|
216
|
+
self.pos[0] + 8, self.pos[1] - half_width)
|
|
217
|
+
|
|
218
|
+
def _mousedown(self, event):
|
|
219
|
+
"""鼠标按下"""
|
|
220
|
+
if self.direction == "x":
|
|
221
|
+
self.startpos = self.canvas.canvasx(event.x)
|
|
222
|
+
else:
|
|
223
|
+
self.startpos = self.canvas.canvasy(event.y)
|
|
224
|
+
self.canvas.itemconfig(self.button_fore, text="\ueccc") # 按下状态图标
|
|
225
|
+
|
|
226
|
+
def _drag(self, event):
|
|
227
|
+
"""拖拽"""
|
|
228
|
+
half_width = self.width / 2
|
|
229
|
+
min_limit = self.pos[0] - half_width if self.direction == "x" else self.pos[1] - half_width
|
|
230
|
+
max_limit = self.pos[0] + half_width if self.direction == "x" else self.pos[1] + half_width
|
|
231
|
+
|
|
232
|
+
if self.direction == "x":
|
|
233
|
+
current_pos = self.canvas.canvasx(event.x)
|
|
234
|
+
move = current_pos - self.startpos
|
|
235
|
+
if current_pos < min_limit or current_pos > max_limit:
|
|
236
|
+
return
|
|
237
|
+
self.canvas.move(self.button, move, 0)
|
|
238
|
+
# 更新激活线 (从中心 pos[0] 到 current_pos)
|
|
239
|
+
self.canvas.coords(self.active, self.pos[0], self.pos[1] + 8, current_pos, self.pos[1] + 8)
|
|
240
|
+
self.startpos = current_pos
|
|
241
|
+
else:
|
|
242
|
+
current_pos = self.canvas.canvasy(event.y)
|
|
243
|
+
move = current_pos - self.startpos
|
|
244
|
+
if current_pos < min_limit or current_pos > max_limit:
|
|
245
|
+
return
|
|
246
|
+
self.canvas.move(self.button, 0, move)
|
|
247
|
+
self.canvas.coords(self.active, self.pos[0] + 8, self.pos[1], self.pos[0] + 8, current_pos)
|
|
248
|
+
self.startpos = current_pos
|
|
249
|
+
|
|
250
|
+
def _check(self, _):
|
|
251
|
+
"""鼠标释放,矫正位置"""
|
|
252
|
+
self.canvas.itemconfig(self.button_fore, text="\ue915") # 恢复图标
|
|
253
|
+
bbox = self.canvas.coords(self.button)
|
|
254
|
+
# 获取按钮中心位置
|
|
255
|
+
if self.direction == "x":
|
|
256
|
+
current_val = bbox[0]
|
|
257
|
+
# 限制在范围内
|
|
258
|
+
half_width = self.width / 2
|
|
259
|
+
move = min(max(current_val, self.pos[0] - half_width), self.pos[0] + half_width)
|
|
260
|
+
self.canvas.move(self.button, move - current_val, 0)
|
|
261
|
+
else:
|
|
262
|
+
current_val = bbox[1]
|
|
263
|
+
half_width = self.width / 2
|
|
264
|
+
move = min(max(current_val, self.pos[1] - half_width), self.pos[1] + half_width)
|
|
265
|
+
self.canvas.move(self.button, 0, move - current_val)
|
|
266
|
+
|
|
267
|
+
# 计算最近的刻度
|
|
268
|
+
rend = min(self.dash, key=lambda x: abs(x - move))
|
|
269
|
+
self.nowselect = self.dash.index(rend)
|
|
270
|
+
|
|
271
|
+
# 更新激活线到精确刻度
|
|
272
|
+
self.select(self.nowselect, send=True)
|
|
273
|
+
|
|
274
|
+
def _checkval(self, event):
|
|
275
|
+
"""点击背景条直接跳转"""
|
|
276
|
+
if self.direction == "x":
|
|
277
|
+
move = self.canvas.canvasx(event.x)
|
|
278
|
+
# 更新激活线视觉
|
|
279
|
+
self.canvas.coords(self.active, self.pos[0], self.pos[1] + 8, move, self.pos[1] + 8)
|
|
280
|
+
# 移动按钮
|
|
281
|
+
bbox = self.canvas.coords(self.button)
|
|
282
|
+
self.canvas.move(self.button, move - bbox[0], 0)
|
|
283
|
+
else:
|
|
284
|
+
move = self.canvas.canvasy(event.y)
|
|
285
|
+
self.canvas.coords(self.active, self.pos[0] + 8, self.pos[1], self.pos[0] + 8, move)
|
|
286
|
+
bbox = self.canvas.coords(self.button)
|
|
287
|
+
self.canvas.move(self.button, 0, move - bbox[1])
|
|
288
|
+
self._check(None)
|
|
289
|
+
|
|
290
|
+
def select(self, num, send=True):
|
|
291
|
+
"""选中某一项"""
|
|
292
|
+
self.nowselect = num
|
|
293
|
+
target_pos = self.dash[num]
|
|
294
|
+
|
|
295
|
+
# 移动按钮到目标位置
|
|
296
|
+
curr_coords = self.canvas.coords(self.button)
|
|
297
|
+
if self.direction == "x":
|
|
298
|
+
move_x = target_pos - curr_coords[0]
|
|
299
|
+
self.canvas.move(self.button, move_x, 0)
|
|
300
|
+
# 更新激活线
|
|
301
|
+
self.canvas.coords(self.active, self.pos[0], self.pos[1] + 8, target_pos, self.pos[1] + 8)
|
|
302
|
+
else:
|
|
303
|
+
move_y = target_pos - curr_coords[1]
|
|
304
|
+
self.canvas.move(self.button, 0, move_y)
|
|
305
|
+
self.canvas.coords(self.active, self.pos[0] + 8, self.pos[1], self.pos[0] + 8, target_pos)
|
|
306
|
+
|
|
307
|
+
if self.command and send:
|
|
308
|
+
self.command(self.data[num])
|
|
309
|
+
|
|
310
|
+
def disable(self, sign="#C8C8C8"):
|
|
311
|
+
"""禁用控件"""
|
|
312
|
+
self.canvas.itemconfig(self.button_fore, state="disable", fill=sign)
|
|
313
|
+
self.canvas.itemconfig(self.back, state="disable")
|
|
314
|
+
self.canvas.itemconfig(self.active, state="disable", fill=sign)
|
|
315
|
+
self.canvas.itemconfig(self.uid, state="disable")
|
|
316
|
+
|
|
317
|
+
def active_state(self):
|
|
318
|
+
"""激活控件"""
|
|
319
|
+
self.canvas.itemconfig(self.uid, state="normal")
|
|
320
|
+
self.canvas.itemconfig(self.button_fore, state="normal", fill=self.fg)
|
|
321
|
+
self.canvas.itemconfig(self.back, state="normal")
|
|
322
|
+
self.canvas.itemconfig(self.active, state="normal", fill=self.fg)
|
|
323
|
+
|
|
324
|
+
def get(self):
|
|
325
|
+
"""获取当前选中的值"""
|
|
326
|
+
return self.data[self.nowselect]
|
|
327
|
+
|
|
328
|
+
def set(self, value):
|
|
329
|
+
"""设置选中的值"""
|
|
330
|
+
if value in self.data:
|
|
331
|
+
idx = self.data.index(value)
|
|
332
|
+
self.select(idx)
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
if __name__ == "__main__":
|
|
336
|
+
from tkinter import Tk
|
|
337
|
+
from tinui import ExpandPanel, VerticalPanel
|
|
338
|
+
def on_resize(event):
|
|
339
|
+
rp.update_layout(10,10,event.width-10,event.height-10)
|
|
340
|
+
r=Tk()
|
|
341
|
+
|
|
342
|
+
ui=BasicTinUI(r)
|
|
343
|
+
ui.pack(fill='both',expand=True)
|
|
344
|
+
|
|
345
|
+
slider = CenterSlider(
|
|
346
|
+
canvas=ui,
|
|
347
|
+
pos=(0, 100),
|
|
348
|
+
width=200,
|
|
349
|
+
data=range(-10,11),
|
|
350
|
+
start=3, # start是索引,不是值,所以这里是选中数据中的第4项
|
|
351
|
+
anchor="center",
|
|
352
|
+
command=lambda v: print(f"Selected: {v}"),
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
# 获取当前值
|
|
356
|
+
val = slider.get()
|
|
357
|
+
print(f"Current value: {val}")
|
|
358
|
+
slider.set(5) # 设置选中值为 5
|
|
359
|
+
print(f"Value after set: {slider.get()}")
|
|
360
|
+
|
|
361
|
+
# 禁用
|
|
362
|
+
# slider.disable()
|
|
363
|
+
|
|
364
|
+
rp = ExpandPanel(ui)
|
|
365
|
+
vp = VerticalPanel(ui)
|
|
366
|
+
rp.set_child(vp)
|
|
367
|
+
|
|
368
|
+
ep1 = ExpandPanel(ui)
|
|
369
|
+
vp.add_child(ep1, weight=1)
|
|
370
|
+
ep1.set_child(slider.uid)
|
|
371
|
+
|
|
372
|
+
ui.bind("<Configure>", on_resize)
|
|
373
|
+
|
|
374
|
+
r.mainloop()
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tinuislider
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: tinui高级滑动条
|
|
5
|
+
Author-email: Smart-Space <smart-space@qq.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Repository, https://github.com/Smart-Space/TinUISlider
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: tinui
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# TinUISheet
|
|
17
|
+
|
|
18
|
+
[TinUI](https://github.com/Smart-Space/TinUI)的高级滑动条控件。
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
> [!NOTE]
|
|
22
|
+
>
|
|
23
|
+
> `tinuislider`提供`sliderlight`和`sliderdark`两种**样式配色**。
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## CenterSlider
|
|
28
|
+
|
|
29
|
+
<img width="200" src="./screenshots/center.png" />
|
|
30
|
+
|
|
31
|
+
`tinuislider.centerslider.CenterSlider`
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
CenterSlider(
|
|
35
|
+
canvas: BasicTinUI,
|
|
36
|
+
pos: tuple,
|
|
37
|
+
width=200,
|
|
38
|
+
fg="#4554dc",
|
|
39
|
+
activefg="#4554dc",
|
|
40
|
+
bg="#868686",
|
|
41
|
+
buttonbg="#ffffff",
|
|
42
|
+
buttonoutline="#cccccc",
|
|
43
|
+
data=(1, 2, 3, 4, 5),
|
|
44
|
+
start=None, # 默认为中间索引
|
|
45
|
+
direction="x",
|
|
46
|
+
anchor="nw",
|
|
47
|
+
command=None,
|
|
48
|
+
)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
参数与TinUI原生`scalebar`一致。
|
|
52
|
+
|
|
53
|
+
> **注意**,`start`是索引,不是值。
|
|
54
|
+
|
|
55
|
+
> [!tip]
|
|
56
|
+
>
|
|
57
|
+
> 通过`CenterSlider.uid`获取控件标识符,用于TinUI面板布局。其对面板布局的响应与原生`scalebar`一致。
|
|
58
|
+
|
|
59
|
+
#### select(num)
|
|
60
|
+
|
|
61
|
+
选中某一项**索引**。
|
|
62
|
+
|
|
63
|
+
#### disable(sign='#C8C8C8')
|
|
64
|
+
|
|
65
|
+
禁用,`sign`为禁用时标识色。
|
|
66
|
+
|
|
67
|
+
#### active_state()
|
|
68
|
+
|
|
69
|
+
激活控件。
|
|
70
|
+
|
|
71
|
+
#### get()
|
|
72
|
+
|
|
73
|
+
获取当前**选中值**。
|
|
74
|
+
|
|
75
|
+
#### set(value)
|
|
76
|
+
|
|
77
|
+
选中某一项**值**,需要在`data`中。
|
|
78
|
+
|
|
79
|
+
#### 示例
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from tkinter import Tk
|
|
83
|
+
from tinui import ExpandPanel, VerticalPanel
|
|
84
|
+
def on_resize(event):
|
|
85
|
+
rp.update_layout(10,10,event.width-10,event.height-10)
|
|
86
|
+
r=Tk()
|
|
87
|
+
|
|
88
|
+
ui=BasicTinUI(r)
|
|
89
|
+
ui.pack(fill='both',expand=True)
|
|
90
|
+
|
|
91
|
+
slider = CenterSlider(
|
|
92
|
+
canvas=ui,
|
|
93
|
+
pos=(0, 100),
|
|
94
|
+
width=200,
|
|
95
|
+
data=range(-10,11),
|
|
96
|
+
start=3, # start是索引,不是值,所以这里是选中数据中的第4项
|
|
97
|
+
anchor="center",
|
|
98
|
+
command=lambda v: print(f"Selected: {v}")
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
# 获取当前值
|
|
102
|
+
val = slider.get()
|
|
103
|
+
print(f"Current value: {val}")
|
|
104
|
+
slider.set(5) # 设置选中值为 5
|
|
105
|
+
print(f"Value after set: {slider.get()}")
|
|
106
|
+
|
|
107
|
+
rp = ExpandPanel(ui)
|
|
108
|
+
vp = VerticalPanel(ui)
|
|
109
|
+
rp.set_child(vp)
|
|
110
|
+
|
|
111
|
+
ep1 = ExpandPanel(ui)
|
|
112
|
+
vp.add_child(ep1, weight=1)
|
|
113
|
+
ep1.set_child(slider.uid)
|
|
114
|
+
|
|
115
|
+
ui.bind("<Configure>", on_resize)
|
|
116
|
+
|
|
117
|
+
r.mainloop()
|
|
118
|
+
```
|
|
119
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
tinuislider/__init__.py
|
|
5
|
+
tinuislider/centerslider.py
|
|
6
|
+
tinuislider.egg-info/PKG-INFO
|
|
7
|
+
tinuislider.egg-info/SOURCES.txt
|
|
8
|
+
tinuislider.egg-info/dependency_links.txt
|
|
9
|
+
tinuislider.egg-info/requires.txt
|
|
10
|
+
tinuislider.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tinui
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tinuislider
|