tkfluent 0.0.1__py2.py3-none-any.whl → 0.0.2__py2.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/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 CHANGED
@@ -141,6 +141,7 @@ class FluText(FluTextCanvas, DDrawWidget):
141
141
  self._draw(event)
142
142
 
143
143
  def theme(self, mode="light"):
144
+ self.mode = mode
144
145
  if mode.lower() == "dark":
145
146
  self._dark()
146
147
  else:
tkflu/thememanager.py ADDED
@@ -0,0 +1,27 @@
1
+ from .window import FluWindow
2
+
3
+
4
+ class FluThemeManager(object):
5
+ def __init__(self, window: FluWindow = None, mode: str = "light"):
6
+ if window:
7
+ self._window = window
8
+ else:
9
+ from tkinter import _default_root
10
+ self._window = _default_root
11
+ self._mode = mode
12
+ self.mode(self._mode)
13
+ self._window.after(100, lambda: self.mode(self._mode))
14
+
15
+ def mode(self, mode: str):
16
+ self._mode = mode
17
+ if hasattr(self._window, "theme"):
18
+ self._window.theme(mode=mode)
19
+ if hasattr(self._window, "_draw"):
20
+ self._window._draw()
21
+ self._window.update()
22
+ for widget in self._window.winfo_children():
23
+ if hasattr(widget, "theme"):
24
+ widget.theme(mode=mode)
25
+ if hasattr(widget, "_draw"):
26
+ widget._draw()
27
+ widget.update()
tkflu/togglebutton.py ADDED
@@ -0,0 +1,341 @@
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 FluToggleButtonDraw(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="DToggleButton.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 FluToggleButtonCanvas(DCanvas):
33
+ draw = FluToggleButtonDraw
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 FluToggleButton(FluToggleButtonCanvas, 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)
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.toggle(), add="+")
74
+ self.bind("<<Clicked>>", lambda event=None: self.focus_set(), add="+")
75
+ self.bind("<<Clicked>>", lambda event=None: self.attributes.command(), add="+")
76
+
77
+ self.bind("<Return>", lambda event=None: self.attributes.command(), add="+") # 可以使用回车键模拟点击
78
+ self.bind("<Return>", lambda event=None: self.toggle(), add="+") # 可以使用回车键模拟点击
79
+
80
+ if font is None:
81
+ from tkdeft.utility.fonts import SegoeFont
82
+ self.attributes.font = SegoeFont()
83
+
84
+ def _init(self, mode):
85
+
86
+ from easydict import EasyDict
87
+
88
+ self.attributes = EasyDict(
89
+ {
90
+ "text": "",
91
+ "command": None,
92
+ "font": None,
93
+ "checked": False,
94
+
95
+ "uncheck": {
96
+ "rest": {
97
+ "back_color": None,
98
+ "border_color": None,
99
+ "border_color2": None,
100
+ "border_width": None,
101
+ "radius": None,
102
+ "text_color": None,
103
+ },
104
+ "hover": {
105
+ "back_color": None,
106
+ "border_color": None,
107
+ "border_color2": None,
108
+ "border_width": None,
109
+ "radius": None,
110
+ "text_color": None,
111
+ },
112
+ "pressed": {
113
+ "back_color": None,
114
+ "border_color": None,
115
+ "border_color2": None,
116
+ "border_width": None,
117
+ "radius": None,
118
+ "text_color": None,
119
+ }
120
+ },
121
+
122
+ "check": {
123
+ "rest": {
124
+ "back_color": None,
125
+ "border_color": None,
126
+ "border_color2": None,
127
+ "border_width": None,
128
+ "radius": None,
129
+ "text_color": None,
130
+ },
131
+ "hover": {
132
+ "back_color": None,
133
+ "border_color": None,
134
+ "border_color2": None,
135
+ "border_width": None,
136
+ "radius": None,
137
+ "text_color": None,
138
+ },
139
+ "pressed": {
140
+ "back_color": None,
141
+ "border_color": None,
142
+ "border_color2": None,
143
+ "border_width": None,
144
+ "radius": None,
145
+ "text_color": None,
146
+ }
147
+ }
148
+ }
149
+ )
150
+
151
+ self.theme(mode=mode)
152
+
153
+ def _draw(self, event=None):
154
+ super()._draw(event)
155
+
156
+ self.delete("all")
157
+
158
+ if not self.attributes.checked:
159
+ if self.enter:
160
+ if self.button1:
161
+ _back_color = self.attributes.uncheck.pressed.back_color
162
+ _border_color = self.attributes.uncheck.pressed.border_color
163
+ _border_color2 = self.attributes.uncheck.pressed.border_color2
164
+ _border_width = self.attributes.uncheck.pressed.border_width
165
+ _radius = self.attributes.uncheck.pressed.radius
166
+ _text_color = self.attributes.uncheck.pressed.text_color
167
+ else:
168
+ _back_color = self.attributes.uncheck.hover.back_color
169
+ _border_color = self.attributes.uncheck.hover.border_color
170
+ _border_color2 = self.attributes.uncheck.hover.border_color2
171
+ _border_width = self.attributes.uncheck.hover.border_width
172
+ _radius = self.attributes.uncheck.hover.radius
173
+ _text_color = self.attributes.uncheck.hover.text_color
174
+ else:
175
+ _back_color = self.attributes.uncheck.rest.back_color
176
+ _border_color = self.attributes.uncheck.rest.border_color
177
+ _border_color2 = self.attributes.uncheck.rest.border_color2
178
+ _border_width = self.attributes.uncheck.rest.border_width
179
+ _radius = self.attributes.uncheck.rest.radius
180
+ _text_color = self.attributes.uncheck.rest.text_color
181
+ else:
182
+ if self.enter:
183
+ if self.button1:
184
+ _back_color = self.attributes.check.pressed.back_color
185
+ _border_color = self.attributes.check.pressed.border_color
186
+ _border_color2 = self.attributes.check.pressed.border_color2
187
+ _border_width = self.attributes.check.pressed.border_width
188
+ _radius = self.attributes.check.pressed.radius
189
+ _text_color = self.attributes.check.pressed.text_color
190
+ else:
191
+ _back_color = self.attributes.check.hover.back_color
192
+ _border_color = self.attributes.check.hover.border_color
193
+ _border_color2 = self.attributes.check.hover.border_color2
194
+ _border_width = self.attributes.check.hover.border_width
195
+ _radius = self.attributes.check.hover.radius
196
+ _text_color = self.attributes.check.hover.text_color
197
+ else:
198
+ _back_color = self.attributes.check.rest.back_color
199
+ _border_color = self.attributes.check.rest.border_color
200
+ _border_color2 = self.attributes.check.rest.border_color2
201
+ _border_width = self.attributes.check.rest.border_width
202
+ _radius = self.attributes.check.rest.radius
203
+ _text_color = self.attributes.check.rest.text_color
204
+
205
+ self.element_border = self.create_round_rectangle(
206
+ 0, 0, self.winfo_width(), self.winfo_height(), _radius, temppath=self.temppath,
207
+ fill=_back_color, outline=_border_color, outline2=_border_color2, width=_border_width
208
+ )
209
+ self.element_text = self.create_text(
210
+ self.winfo_width() / 2, self.winfo_height() / 2, anchor="center",
211
+ fill=_text_color, text=self.attributes.text, font=self.attributes.font
212
+ )
213
+
214
+ def theme(self, mode="light"):
215
+ self.mode = mode
216
+ if mode.lower() == "dark":
217
+ self._dark()
218
+ else:
219
+ self._light()
220
+
221
+ def _light(self):
222
+ self.dconfigure(
223
+ uncheck={
224
+ "rest": {
225
+ "back_color": "#ffffff",
226
+ "border_color": "#f0f0f0",
227
+ "border_color2": "#d6d6d6",
228
+ "border_width": 1,
229
+ "radius": 6,
230
+ "text_color": "#1b1b1b",
231
+ },
232
+ "hover": {
233
+ "back_color": "#fcfcfc",
234
+ "border_color": "#f0f0f0",
235
+ "border_color2": "#d6d6d6",
236
+ "border_width": 1,
237
+ "radius": 6,
238
+ "text_color": "#1b1b1b",
239
+ },
240
+ "pressed": {
241
+ "back_color": "#fdfdfd",
242
+ "border_color": "#f0f0f0",
243
+ "border_color2": "#f0f0f0",
244
+ "border_width": 1,
245
+ "radius": 6,
246
+ "text_color": "#636363",
247
+ }
248
+ },
249
+ check={
250
+ "rest": {
251
+ "back_color": "#005fb8",
252
+ "border_color": "#146cbe",
253
+ "border_color2": "#00396e",
254
+ "border_width": 1,
255
+ "radius": 6,
256
+ "text_color": "#ffffff",
257
+ },
258
+ "hover": {
259
+ "back_color": "#0359a9",
260
+ "border_color": "#1766b0",
261
+ "border_color2": "#0f4373",
262
+ "border_width": 1,
263
+ "radius": 6,
264
+ "text_color": "#ffffff",
265
+ },
266
+ "pressed": {
267
+ "back_color": "#005fb8",
268
+ "border_color": "#4389ca",
269
+ "border_color2": "#4389ca",
270
+ "border_width": 1,
271
+ "radius": 6,
272
+ "text_color": "#b4cbe0",
273
+ }
274
+ }
275
+ )
276
+
277
+ def _dark(self):
278
+ self.dconfigure(
279
+ uncheck={
280
+ "rest": {
281
+ "back_color": "#272727",
282
+ "border_color": "#303030",
283
+ "border_color2": "#262626",
284
+ "border_width": 1,
285
+ "radius": 6,
286
+ "text_color": "#ffffff",
287
+ },
288
+ "hover": {
289
+ "back_color": "#2d2d2d",
290
+ "border_color": "#303030",
291
+ "border_color2": "#262626",
292
+ "border_width": 1,
293
+ "radius": 6,
294
+ "text_color": "#ffffff",
295
+ },
296
+ "pressed": {
297
+ "back_color": "#212121",
298
+ "border_color": "#2a2a2a",
299
+ "border_color2": "#262626",
300
+ "border_width": 1,
301
+ "radius": 6,
302
+ "text_color": "#cfcfcf",
303
+ }
304
+ },
305
+ check={
306
+ "rest": {
307
+ "back_color": "#60cdff",
308
+ "border_color": "#6cd1ff",
309
+ "border_color2": "#56b4df",
310
+ "border_width": 1,
311
+ "radius": 6,
312
+ "text_color": "#000000",
313
+ },
314
+ "hover": {
315
+ "back_color": "#5abce9",
316
+ "border_color": "#67c1eb",
317
+ "border_color2": "#50a5cc",
318
+ "border_width": 1,
319
+ "radius": 6,
320
+ "text_color": "#000000",
321
+ },
322
+ "pressed": {
323
+ "back_color": "#52a9d1",
324
+ "border_color": "#60b0d5",
325
+ "border_color2": "#60b0d5",
326
+ "border_width": 1,
327
+ "radius": 6,
328
+ "text_color": "#295468",
329
+ }
330
+ }
331
+ )
332
+
333
+ def invoke(self):
334
+ self.attributes.command()
335
+
336
+ def toggle(self):
337
+ if self.attributes.checked:
338
+ self.attributes.checked = False
339
+ else:
340
+ self.attributes.checked = True
341
+ self._draw(None)