tkfluent 0.0.2__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.
tkflu/listbox.py ADDED
@@ -0,0 +1,286 @@
1
+ from tkdeft.windows.draw import DSvgDraw
2
+ from tkdeft.windows.canvas import DCanvas
3
+ from tkdeft.windows.drawwidget import DDrawWidget
4
+
5
+
6
+ class FluListBoxDraw(DSvgDraw):
7
+ def create_roundrect(self,
8
+ x1, y1, x2, y2, radius, radiusy=None, temppath=None,
9
+ fill="transparent", outline="black", outline2="black", width=1
10
+ ):
11
+ if radiusy:
12
+ _rx = radius
13
+ _ry = radiusy
14
+ else:
15
+ _rx, _ry = radius, radius
16
+ drawing = self.create_drawing(x2 - x1, y2 - y1, temppath=temppath)
17
+ border = drawing[1].linearGradient(start=(x1, y1), end=(x1, y2), id="DListBox.Border")
18
+ border.add_stop_color("0%", outline)
19
+ border.add_stop_color("100%", outline2)
20
+ drawing[1].defs.add(border)
21
+ drawing[1].add(
22
+ drawing[1].rect(
23
+ (x1, y1), (x2 - x1, y2 - y1), _rx, _ry,
24
+ fill=fill, stroke_width=width,
25
+ stroke=f"url(#{border.get_id()})",
26
+ )
27
+ )
28
+ drawing[1].save()
29
+ return drawing[0]
30
+
31
+
32
+ class FluListBoxCanvas(DCanvas):
33
+ draw = FluListBoxDraw
34
+
35
+ def create_round_rectangle(self,
36
+ x1, y1, x2, y2, r1, r2=None, temppath=None,
37
+ fill="transparent", outline="black", outline2="black", width=1
38
+ ):
39
+ self._img = self.svgdraw.create_roundrect(
40
+ x1, y1, x2, y2, r1, r2, temppath=temppath,
41
+ fill=fill, outline=outline, outline2=outline2, width=width
42
+ )
43
+ self._tkimg = self.svgdraw.create_tksvg_image(self._img)
44
+ return self.create_image(x1, y1, anchor="nw", image=self._tkimg)
45
+
46
+ create_roundrect = create_round_rectangle
47
+
48
+
49
+ class FluListBox(FluListBoxCanvas, DDrawWidget):
50
+ def __init__(self, *args,
51
+ text="",
52
+ width=120,
53
+ height=32,
54
+ command=None,
55
+ font=None,
56
+ mode="light",
57
+ style="standard",
58
+ **kwargs):
59
+ self._init(mode, style)
60
+
61
+ super().__init__(*args, width=width, height=height, **kwargs)
62
+
63
+ if command is None:
64
+ def empty(): pass
65
+
66
+ command = empty
67
+
68
+ self.dconfigure(
69
+ text=text,
70
+ command=command
71
+ )
72
+
73
+ self.bind("<<Clicked>>", lambda event=None: self.focus_set(), add="+")
74
+ self.bind("<<Clicked>>", lambda event=None: self.attributes.command(), add="+")
75
+
76
+ self.bind("<Return>", lambda event=None: self.attributes.command(), add="+") # 可以使用回车键模拟点击
77
+
78
+ if font is None:
79
+ from tkdeft.utility.fonts import SegoeFont
80
+ self.attributes.font = SegoeFont()
81
+
82
+ def _init(self, mode, style):
83
+
84
+ from easydict import EasyDict
85
+
86
+ self.attributes = EasyDict(
87
+ {
88
+ "text": "",
89
+ "command": None,
90
+ "font": None,
91
+
92
+ "rest": {
93
+ "back_color": "#ffffff",
94
+ "border_color": "#f0f0f0",
95
+ "border_color2": "#d6d6d6",
96
+ "border_width": 1,
97
+ "radius": 6,
98
+ "text_color": "#1b1b1b",
99
+ },
100
+ "hover": {
101
+ "back_color": "#fcfcfc",
102
+ "border_color": "#f0f0f0",
103
+ "border_color2": "#d6d6d6",
104
+ "border_width": 1,
105
+ "radius": 6,
106
+ "text_color": "#1b1b1b",
107
+ },
108
+ "pressed": {
109
+ "back_color": "#fdfdfd",
110
+ "border_color": "#f0f0f0",
111
+ "border_color2": "#f0f0f0",
112
+ "border_width": 1,
113
+ "radius": 6,
114
+ "text_color": "#636363",
115
+ }
116
+ }
117
+ )
118
+
119
+ self.theme(mode=mode, style=style)
120
+
121
+ def _draw(self, event=None):
122
+ super()._draw(event)
123
+
124
+ self.delete("all")
125
+
126
+ if self.enter:
127
+ if self.button1:
128
+ _back_color = self.attributes.pressed.back_color
129
+ _border_color = self.attributes.pressed.border_color
130
+ _border_color2 = self.attributes.pressed.border_color2
131
+ _border_width = self.attributes.pressed.border_width
132
+ _radius = self.attributes.pressed.radius
133
+ _text_color = self.attributes.pressed.text_color
134
+ else:
135
+ _back_color = self.attributes.hover.back_color
136
+ _border_color = self.attributes.hover.border_color
137
+ _border_color2 = self.attributes.hover.border_color2
138
+ _border_width = self.attributes.hover.border_width
139
+ _radius = self.attributes.hover.radius
140
+ _text_color = self.attributes.hover.text_color
141
+ else:
142
+ _back_color = self.attributes.rest.back_color
143
+ _border_color = self.attributes.rest.border_color
144
+ _border_color2 = self.attributes.rest.border_color2
145
+ _border_width = self.attributes.rest.border_width
146
+ _radius = self.attributes.rest.radius
147
+ _text_color = self.attributes.rest.text_color
148
+
149
+ self.element_border = self.create_round_rectangle(
150
+ 0, 0, self.winfo_width(), self.winfo_height(), _radius, temppath=self.temppath,
151
+ fill=_back_color, outline=_border_color, outline2=_border_color2, width=_border_width
152
+ )
153
+ self.element_text = self.create_text(
154
+ self.winfo_width() / 2, self.winfo_height() / 2, anchor="center",
155
+ fill=_text_color, text=self.attributes.text, font=self.attributes.font
156
+ )
157
+
158
+ def theme(self, mode="light", style=None):
159
+ self.mode = mode
160
+ if style:
161
+ self.style = style
162
+ if mode.lower() == "dark":
163
+ if style.lower() == "accent":
164
+ self._dark_accent()
165
+ else:
166
+ self._dark()
167
+ else:
168
+ if style.lower() == "accent":
169
+ self._light_accent()
170
+ else:
171
+ self._light()
172
+
173
+ def _light(self):
174
+ self.dconfigure(
175
+ rest={
176
+ "back_color": "#ffffff",
177
+ "border_color": "#f0f0f0",
178
+ "border_color2": "#d6d6d6",
179
+ "border_width": 1,
180
+ "radius": 6,
181
+ "text_color": "#1b1b1b",
182
+ },
183
+ hover={
184
+ "back_color": "#fcfcfc",
185
+ "border_color": "#f0f0f0",
186
+ "border_color2": "#d6d6d6",
187
+ "border_width": 1,
188
+ "radius": 6,
189
+ "text_color": "#1b1b1b",
190
+ },
191
+ pressed={
192
+ "back_color": "#fdfdfd",
193
+ "border_color": "#f0f0f0",
194
+ "border_color2": "#f0f0f0",
195
+ "border_width": 1,
196
+ "radius": 6,
197
+ "text_color": "#636363",
198
+ }
199
+ )
200
+
201
+ def _light_accent(self):
202
+ self.dconfigure(
203
+ rest={
204
+ "back_color": "#005fb8",
205
+ "border_color": "#146cbe",
206
+ "border_color2": "#00396e",
207
+ "border_width": 1,
208
+ "radius": 6,
209
+ "text_color": "#ffffff",
210
+ },
211
+ hover={
212
+ "back_color": "#0359a9",
213
+ "border_color": "#1766b0",
214
+ "border_color2": "#0f4373",
215
+ "border_width": 1,
216
+ "radius": 6,
217
+ "text_color": "#ffffff",
218
+ },
219
+ pressed={
220
+ "back_color": "#005fb8",
221
+ "border_color": "#4389ca",
222
+ "border_color2": "#4389ca",
223
+ "border_width": 1,
224
+ "radius": 6,
225
+ "text_color": "#b4cbe0",
226
+ }
227
+ )
228
+
229
+ def _dark(self):
230
+ self.dconfigure(
231
+ rest={
232
+ "back_color": "#272727",
233
+ "border_color": "#303030",
234
+ "border_color2": "#262626",
235
+ "border_width": 1,
236
+ "radius": 6,
237
+ "text_color": "#ffffff",
238
+ },
239
+ hover={
240
+ "back_color": "#2d2d2d",
241
+ "border_color": "#303030",
242
+ "border_color2": "#262626",
243
+ "border_width": 1,
244
+ "radius": 6,
245
+ "text_color": "#ffffff",
246
+ },
247
+ pressed={
248
+ "back_color": "#212121",
249
+ "border_color": "#2a2a2a",
250
+ "border_color2": "#262626",
251
+ "border_width": 1,
252
+ "radius": 6,
253
+ "text_color": "#cfcfcf",
254
+ }
255
+ )
256
+
257
+ def _dark_accent(self):
258
+ self.dconfigure(
259
+ rest={
260
+ "back_color": "#60cdff",
261
+ "border_color": "#6cd1ff",
262
+ "border_color2": "#56b4df",
263
+ "border_width": 1,
264
+ "radius": 6,
265
+ "text_color": "#000000",
266
+ },
267
+ hover={
268
+ "back_color": "#5abce9",
269
+ "border_color": "#67c1eb",
270
+ "border_color2": "#50a5cc",
271
+ "border_width": 1,
272
+ "radius": 6,
273
+ "text_color": "#000000",
274
+ },
275
+ pressed={
276
+ "back_color": "#52a9d1",
277
+ "border_color": "#60b0d5",
278
+ "border_color2": "#60b0d5",
279
+ "border_width": 1,
280
+ "radius": 6,
281
+ "text_color": "#295468",
282
+ }
283
+ )
284
+
285
+ def invoke(self):
286
+ self.attributes.command()
tkflu/litenav.py ADDED
File without changes
tkflu/scrollbar.py ADDED
@@ -0,0 +1,200 @@
1
+ from tkdeft.windows.draw import DSvgDraw
2
+ from tkdeft.windows.canvas import DCanvas
3
+ from tkdeft.windows.drawwidget import DDrawWidget
4
+
5
+
6
+ class FluScrollBarDraw(DSvgDraw):
7
+ def create_roundrect(self,
8
+ x1, y1, x2, y2, radius, radiusy=None, temppath=None,
9
+ fill="transparent", outline="black", outline2="black", width=1
10
+ ):
11
+ if radiusy:
12
+ _rx = radius
13
+ _ry = radiusy
14
+ else:
15
+ _rx, _ry = radius, radius
16
+ drawing = self.create_drawing(x2 - x1, y2 - y1, temppath=temppath)
17
+ border = drawing[1].linearGradient(start=(x1, y1), end=(x1, y2), id="DButton.Border")
18
+ border.add_stop_color("0%", outline)
19
+ border.add_stop_color("100%", outline2)
20
+ drawing[1].defs.add(border)
21
+ drawing[1].add(
22
+ drawing[1].rect(
23
+ (x1, y1), (x2 - x1, y2 - y1), _rx, _ry,
24
+ fill=fill, stroke_width=width,
25
+ stroke=f"url(#{border.get_id()})",
26
+ )
27
+ )
28
+ drawing[1].save()
29
+ return drawing[0]
30
+
31
+
32
+ class FluScrollBarCanvas(DCanvas):
33
+ draw = FluScrollBarDraw
34
+
35
+ def create_round_rectangle(self,
36
+ x1, y1, x2, y2, r1, r2=None, temppath=None,
37
+ fill="transparent", outline="black", outline2="black", width=1
38
+ ):
39
+ self._img = self.svgdraw.create_roundrect(
40
+ x1, y1, x2, y2, r1, r2, temppath=temppath,
41
+ fill=fill, outline=outline, outline2=outline2, width=width
42
+ )
43
+ self._tkimg = self.svgdraw.create_tksvg_image(self._img)
44
+ return self.create_image(x1, y1, anchor="nw", image=self._tkimg)
45
+
46
+ create_roundrect = create_round_rectangle
47
+
48
+
49
+ class FluScrollBar(FluScrollBarCanvas, DDrawWidget):
50
+ def __init__(self, *args,
51
+ text="",
52
+ width=120,
53
+ height=32,
54
+ command=None,
55
+ font=None,
56
+ mode="light",
57
+ style="standard",
58
+ **kwargs):
59
+ self._init(mode, style)
60
+
61
+ super().__init__(*args, width=width, height=height, **kwargs)
62
+
63
+ if command is None:
64
+ def empty(): pass
65
+
66
+ command = empty
67
+
68
+ self.dconfigure(
69
+ text=text,
70
+ command=command
71
+ )
72
+
73
+ self.bind("<<Clicked>>", lambda event=None: self.focus_set(), add="+")
74
+ self.bind("<<Clicked>>", lambda event=None: self.attributes.command(), add="+")
75
+
76
+ self.bind("<Return>", lambda event=None: self.attributes.command(), add="+") # 可以使用回车键模拟点击
77
+
78
+ if font is None:
79
+ from tkdeft.utility.fonts import SegoeFont
80
+ self.attributes.font = SegoeFont()
81
+
82
+ def _init(self, mode, style):
83
+
84
+ from easydict import EasyDict
85
+
86
+ self.attributes = EasyDict(
87
+ {
88
+ "text": "",
89
+ "command": None,
90
+ "font": None,
91
+
92
+ "rest": {
93
+ "back_color": "#ffffff",
94
+ "border_color": "#f0f0f0",
95
+ "border_color2": "#d6d6d6",
96
+ "border_width": 1,
97
+ "radius": 6,
98
+ "text_color": "#1b1b1b",
99
+ },
100
+ "hover": {
101
+ "back_color": "#fcfcfc",
102
+ "border_color": "#f0f0f0",
103
+ "border_color2": "#d6d6d6",
104
+ "border_width": 1,
105
+ "radius": 6,
106
+ "text_color": "#1b1b1b",
107
+ },
108
+ "pressed": {
109
+ "back_color": "#fdfdfd",
110
+ "border_color": "#f0f0f0",
111
+ "border_color2": "#f0f0f0",
112
+ "border_width": 1,
113
+ "radius": 6,
114
+ "text_color": "#636363",
115
+ }
116
+ }
117
+ )
118
+
119
+ self.theme(mode=mode, style=style)
120
+
121
+ def _draw(self, event=None):
122
+ super()._draw(event)
123
+
124
+ self.delete("all")
125
+
126
+ if self.enter:
127
+ if self.button1:
128
+ _back_color = self.attributes.pressed.back_color
129
+ _border_color = self.attributes.pressed.border_color
130
+ _border_color2 = self.attributes.pressed.border_color2
131
+ _border_width = self.attributes.pressed.border_width
132
+ _radius = self.attributes.pressed.radius
133
+ _text_color = self.attributes.pressed.text_color
134
+ else:
135
+ _back_color = self.attributes.hover.back_color
136
+ _border_color = self.attributes.hover.border_color
137
+ _border_color2 = self.attributes.hover.border_color2
138
+ _border_width = self.attributes.hover.border_width
139
+ _radius = self.attributes.hover.radius
140
+ _text_color = self.attributes.hover.text_color
141
+ else:
142
+ _back_color = self.attributes.rest.back_color
143
+ _border_color = self.attributes.rest.border_color
144
+ _border_color2 = self.attributes.rest.border_color2
145
+ _border_width = self.attributes.rest.border_width
146
+ _radius = self.attributes.rest.radius
147
+ _text_color = self.attributes.rest.text_color
148
+
149
+ self.element_border = self.create_round_rectangle(
150
+ 0, 0, self.winfo_width(), self.winfo_height(), _radius, temppath=self.temppath,
151
+ fill=_back_color, outline=_border_color, outline2=_border_color2, width=_border_width
152
+ )
153
+ self.element_text = self.create_text(
154
+ self.winfo_width() / 2, self.winfo_height() / 2, anchor="center",
155
+ fill=_text_color, text=self.attributes.text, font=self.attributes.font
156
+ )
157
+
158
+ def theme(self, mode="light", style="standard"):
159
+ self.mode = mode
160
+ if style:
161
+ self.style = style
162
+ self._light()
163
+ """if mode.lower() == "dark":
164
+ if style.lower() == "accent":
165
+ self._dark_accent()
166
+ else:
167
+ self._dark()
168
+ else:
169
+ if style.lower() == "accent":
170
+ self._light_accent()
171
+ else:
172
+ self._light()"""
173
+
174
+ def _light(self):
175
+ self.dconfigure(
176
+ rest={
177
+ "back_color": "#ffffff",
178
+ "border_color": "#f0f0f0",
179
+ "border_color2": "#d6d6d6",
180
+ "border_width": 1,
181
+ "radius": 6,
182
+ "text_color": "#1b1b1b",
183
+ },
184
+ hover={
185
+ "back_color": "#fcfcfc",
186
+ "border_color": "#f0f0f0",
187
+ "border_color2": "#d6d6d6",
188
+ "border_width": 1,
189
+ "radius": 6,
190
+ "text_color": "#1b1b1b",
191
+ },
192
+ pressed={
193
+ "back_color": "#fdfdfd",
194
+ "border_color": "#f0f0f0",
195
+ "border_color2": "#f0f0f0",
196
+ "border_width": 1,
197
+ "radius": 6,
198
+ "text_color": "#636363",
199
+ }
200
+ )
tkflu/text.py ADDED
@@ -0,0 +1,188 @@
1
+ from tkdeft.windows.draw import DSvgDraw
2
+ from tkdeft.windows.canvas import DCanvas
3
+ from tkdeft.windows.drawwidget import DDrawWidget
4
+
5
+
6
+ class FluTextDraw(DSvgDraw):
7
+ def create_roundrect(self,
8
+ x1, y1, x2, y2, radius, radiusy=None, temppath=None,
9
+ fill="transparent", outline="black", outline2="black", width=1
10
+ ):
11
+ if radiusy:
12
+ _rx = radius
13
+ _ry = radiusy
14
+ else:
15
+ _rx, _ry = radius, radius
16
+ drawing = self.create_drawing(x2 - x1, y2 - y1, temppath=temppath)
17
+ border = drawing[1].linearGradient(start=(x1, y1), end=(x1, y2), id="DButton.Border")
18
+ border.add_stop_color("0%", outline)
19
+ border.add_stop_color("85%", outline)
20
+ border.add_stop_color("100%", outline2)
21
+ drawing[1].defs.add(border)
22
+ drawing[1].add(
23
+ drawing[1].rect(
24
+ (x1, y1), (x2 - x1, y2 - y1), _rx, _ry,
25
+ fill=fill, stroke_width=width,
26
+ stroke=f"url(#{border.get_id()})",
27
+ )
28
+ )
29
+ drawing[1].save()
30
+ return drawing[0]
31
+
32
+
33
+ class FluTextCanvas(DCanvas):
34
+ draw = FluTextDraw
35
+
36
+ def create_round_rectangle(self,
37
+ x1, y1, x2, y2, r1, r2=None, temppath=None,
38
+ fill="transparent", outline="black", outline2="black", width=1
39
+ ):
40
+ self._img = self.svgdraw.create_roundrect(
41
+ x1, y1, x2, y2, r1, r2, temppath=temppath,
42
+ fill=fill, outline=outline, outline2=outline2, width=width
43
+ )
44
+ self._tkimg = self.svgdraw.create_tksvg_image(self._img)
45
+ return self.create_image(x1, y1, anchor="nw", image=self._tkimg)
46
+
47
+ create_roundrect = create_round_rectangle
48
+
49
+
50
+ class FluText(FluTextCanvas, DDrawWidget):
51
+ def __init__(self, *args,
52
+ width=120,
53
+ height=90,
54
+ font=None,
55
+ cursor="xterm",
56
+ mode="light",
57
+ **kwargs):
58
+ self._init(mode)
59
+
60
+ from tkinter import Text
61
+
62
+ self.text = Text(border=0, width=width, height=height, cursor=cursor)
63
+
64
+ self.text.bind("<Enter>", self._event_enter, add="+")
65
+ self.text.bind("<Leave>", self._event_leave, add="+")
66
+ self.text.bind("<Button-1>", self._event_on_button1, add="+")
67
+ self.text.bind("<ButtonRelease-1>", self._event_off_button1, add="+")
68
+ self.text.bind("<FocusIn>", self._event_focus_in, add="+")
69
+ self.text.bind("<FocusOut>", self._event_focus_out, add="+")
70
+
71
+ super().__init__(*args, width=width, height=height, cursor=cursor, **kwargs)
72
+
73
+ if font is None:
74
+ from tkdeft.utility.fonts import SegoeFont
75
+ self.attributes.font = SegoeFont()
76
+
77
+ def _init(self, mode):
78
+ from easydict import EasyDict
79
+
80
+ self.attributes = EasyDict(
81
+ {
82
+ "font": None,
83
+
84
+ "rest": {},
85
+
86
+ "focus": {}
87
+
88
+ }
89
+ )
90
+
91
+ self.theme(mode=mode)
92
+
93
+ def _draw(self, event=None):
94
+ super()._draw(event)
95
+
96
+ self.text.configure(font=self.attributes.font)
97
+
98
+ self.delete("all")
99
+
100
+ if self.isfocus:
101
+ _back_color = self.attributes.focus.back_color
102
+ _border_color = self.attributes.focus.border_color
103
+ _border_color2 = self.attributes.focus.border_color2
104
+ _border_width = self.attributes.focus.border_width
105
+ _radius = self.attributes.focus.radius
106
+ _text_color = self.attributes.focus.text_color
107
+ else:
108
+ _back_color = self.attributes.rest.back_color
109
+ _border_color = self.attributes.rest.border_color
110
+ _border_color2 = self.attributes.rest.border_color2
111
+ _border_width = self.attributes.rest.border_width
112
+ _radius = self.attributes.rest.radius
113
+ _text_color = self.attributes.rest.text_color
114
+
115
+ self.text.configure(
116
+ background=_back_color, insertbackground=_text_color, foreground=_text_color,
117
+ width=self.winfo_width() - _border_width * 2 - _radius,
118
+ height=self.winfo_height() - _border_width * 2 - _radius
119
+ )
120
+
121
+ self.element_border = self.create_round_rectangle(
122
+ 0, 0, self.winfo_width(), self.winfo_height(), _radius, temppath=self.temppath,
123
+ fill=_back_color, outline=_border_color, outline2=_border_color2, width=_border_width
124
+ )
125
+
126
+ self.element_text = self.create_window(
127
+ self.winfo_width() / 2, self.winfo_height() / 2,
128
+ window=self.text,
129
+ width=self.winfo_width() - _border_width * 2 - _radius,
130
+ height=self.winfo_height() - _border_width * 2 - _radius
131
+ )
132
+
133
+ def _event_focus_in(self, event=None):
134
+ self.isfocus = True
135
+
136
+ self._draw(event)
137
+
138
+ def _event_focus_out(self, event=None):
139
+ self.isfocus = False
140
+
141
+ self._draw(event)
142
+
143
+ def theme(self, mode="light"):
144
+ self.mode = mode
145
+ if mode.lower() == "dark":
146
+ self._dark()
147
+ else:
148
+ self._light()
149
+
150
+ def _light(self):
151
+ self.dconfigure(
152
+ rest={
153
+ "back_color": "#ffffff",
154
+ "border_color": "#f0f0f0",
155
+ "border_color2": "#8d8d8d",
156
+ "border_width": 1,
157
+ "radius": 6,
158
+ "text_color": "#646464",
159
+ },
160
+ focus={
161
+ "back_color": "#ffffff",
162
+ "border_color": "#f0f0f0",
163
+ "border_color2": "#005fb8",
164
+ "border_width": 2,
165
+ "radius": 6,
166
+ "text_color": "#636363",
167
+ }
168
+ )
169
+
170
+ def _dark(self):
171
+ self.dconfigure(
172
+ rest={
173
+ "back_color": "#272727",
174
+ "border_color": "#2c2c2c",
175
+ "border_color2": "#979797",
176
+ "border_width": 1,
177
+ "radius": 6,
178
+ "text_color": "#ffffff",
179
+ },
180
+ focus={
181
+ "back_color": "#1d1d1d",
182
+ "border_color": "#272727",
183
+ "border_color2": "#60cdff",
184
+ "border_width": 2,
185
+ "radius": 6,
186
+ "text_color": "#ffffff",
187
+ }
188
+ )