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/__init__.py CHANGED
@@ -13,6 +13,8 @@ from .entry import FluEntry
13
13
  from .frame import FluFrame
14
14
  from .label import FluLabel
15
15
  from .text import FluText
16
+ from .thememanager import FluThemeManager
17
+ from .togglebutton import FluToggleButton
16
18
  from .window import FluWindow
17
19
 
18
20
  FluChip = FluBadge
tkflu/__main__.py CHANGED
@@ -2,35 +2,49 @@ from tkflu import *
2
2
  from tkinter import *
3
3
  from tkinter.font import *
4
4
 
5
- mode = "light"
5
+ root = FluWindow()
6
+ root.iconify
7
+ root.wincustom(way=0)
8
+ root.wm_geometry("180x360")
6
9
 
7
- root = FluWindow(mode=mode)
8
- root.wincustom()
9
- root.wm_geometry("180x320")
10
+ thememanager = FluThemeManager()
10
11
 
11
- frame = FluFrame(mode=mode)
12
+ frame = FluFrame()
12
13
 
13
- badge1 = FluBadge(frame, text="DBadge", width=60, mode=mode)
14
+ badge1 = FluBadge(frame, text="FluBadge", width=60)
14
15
  badge1.pack(padx=5, pady=5)
15
16
 
16
- badge2 = FluBadge(frame, text="DBadge (Accent)", width=110, mode=mode, style="accent")
17
+ badge2 = FluBadge(frame, text="FluBadge (Accent)", width=120, style="accent")
17
18
  badge2.pack(padx=5, pady=5)
18
19
 
19
20
  button1 = FluButton(
20
- frame, text="DButton", command=lambda: print("DDarkButton -> Clicked"), mode=mode
21
+ frame, text="FluButton", command=lambda: print("FluButton -> Clicked")
21
22
  )
22
23
  button1.pack(fill="x", padx=5, pady=5)
23
24
 
24
25
  button2 = FluButton(
25
- frame, text="DButton (Accent)", command=lambda: print("DDarkAccentButton -> Clicked"), style="accent", mode=mode
26
+ frame, text="FluButton (Accent)", command=lambda: print("FluButton (Accent) -> Clicked"), style="accent"
26
27
  )
27
28
  button2.pack(fill="x", padx=5, pady=5)
28
29
 
29
- entry1 = FluEntry(frame, mode=mode)
30
+ def toggle1():
31
+ print(f"FluToggleButton -> Toggled -> Checked: {togglebutton1.dcget('checked')}")
32
+ if togglebutton1.dcget('checked'):
33
+ thememanager.mode("dark")
34
+ else:
35
+ thememanager.mode("light")
36
+
37
+ togglebutton1 = FluToggleButton(
38
+ frame, text="FluToggleButton", command=toggle1
39
+ )
40
+ togglebutton1.pack(fill="x", padx=5, pady=5)
41
+
42
+ entry1 = FluEntry(frame)
30
43
  entry1.pack(fill="x", padx=5, pady=5)
31
44
 
32
- text1 = FluText(frame, mode=mode)
45
+ text1 = FluText(frame)
33
46
  text1.pack(fill="x", padx=5, pady=5)
34
47
 
35
48
  frame.pack(fill="both", expand="yes", side="right", padx=5, pady=5)
49
+
36
50
  root.mainloop()
tkflu/badge.py CHANGED
@@ -47,6 +47,21 @@ class FluBadge(FluBadgeCanvas, DDrawWidget):
47
47
  mode="light",
48
48
  style="standard",
49
49
  **kwargs):
50
+
51
+ """
52
+
53
+ 初始化类
54
+
55
+ :param args: 参照tkinter.Canvas.__init__
56
+ :param text:
57
+ :param width:
58
+ :param height:
59
+ :param font:
60
+ :param mode: Fluent主题模式 分为 “light” “dark”
61
+ :param style:
62
+ :param kwargs: 参照tkinter.Canvas.__init__
63
+ """
64
+
50
65
  self._init(mode, style)
51
66
 
52
67
  super().__init__(*args, width=width, height=height, **kwargs)
@@ -80,6 +95,13 @@ class FluBadge(FluBadgeCanvas, DDrawWidget):
80
95
  self.theme(mode, style)
81
96
 
82
97
  def _draw(self, event=None):
98
+
99
+ """
100
+ 重新绘制组件
101
+
102
+ :param event:
103
+ """
104
+
83
105
  super()._draw(event)
84
106
 
85
107
  self.delete("all")
@@ -99,14 +121,17 @@ class FluBadge(FluBadgeCanvas, DDrawWidget):
99
121
  fill=_text_color, text=self.attributes.text, font=self.attributes.font
100
122
  )
101
123
 
102
- def theme(self, mode, style):
124
+ def theme(self, mode, style=None):
125
+ self.mode = mode
126
+ if style:
127
+ self.style = style
103
128
  if mode.lower() == "dark":
104
- if style.lower() == "accent":
129
+ if self.style.lower() == "accent":
105
130
  self._dark_accent()
106
131
  else:
107
132
  self._dark()
108
133
  else:
109
- if style.lower() == "accent":
134
+ if self.style.lower() == "accent":
110
135
  self._light_accent()
111
136
  else:
112
137
  self._light()
tkflu/button.py CHANGED
@@ -155,14 +155,17 @@ class FluButton(FluButtonCanvas, DDrawWidget):
155
155
  fill=_text_color, text=self.attributes.text, font=self.attributes.font
156
156
  )
157
157
 
158
- def theme(self, mode="light", style="standard"):
158
+ def theme(self, mode, style=None):
159
+ self.mode = mode
160
+ if style:
161
+ self.style = style
159
162
  if mode.lower() == "dark":
160
- if style.lower() == "accent":
163
+ if self.style.lower() == "accent":
161
164
  self._dark_accent()
162
165
  else:
163
166
  self._dark()
164
167
  else:
165
- if style.lower() == "accent":
168
+ if self.style.lower() == "accent":
166
169
  self._light_accent()
167
170
  else:
168
171
  self._light()
tkflu/checkbox.py ADDED
File without changes
tkflu/customwindow2.py ADDED
@@ -0,0 +1,77 @@
1
+ from tkinter import Event, Widget, Tk, Frame
2
+
3
+
4
+ class WindowDragArea(object):
5
+ x, y = 0, 0
6
+
7
+ def __init__(self, window):
8
+ self.window = window
9
+
10
+ def _click(self, event: Event):
11
+ self.x, self.y = event.x, event.y
12
+
13
+ def _window_move(self, event: Event):
14
+ new_x = (event.x - self.x) + self.window.winfo_x()
15
+ new_y = (event.y - self.y) + self.window.winfo_y()
16
+ if new_y <= 0:
17
+ new_y = 0
18
+ self.window.geometry(f"+{new_x}+{new_y}")
19
+
20
+ def bind(self, widget: Widget):
21
+ widget.bind("<Button-1>", self._click)
22
+ widget.bind("<B1-Motion>", lambda event: self._window_move(event))
23
+
24
+ def tag_bind(self, widget: Widget, tag):
25
+ widget.tag_bind(tag, "<Button-1>", self._click)
26
+ widget.tag_bind(tag, "<B1-Motion>", lambda event: self._window_move(event))
27
+
28
+
29
+ class WidgetDragArea(object):
30
+ x, y = 0, 0
31
+
32
+ def __init__(self, widget=None):
33
+ self.widget = widget
34
+
35
+ def _click(self, event: Event):
36
+ self.x, self.y = event.x, event.y
37
+
38
+ def _widget_move(self, event: Event):
39
+ new_x = (event.x - self.x) + self.widget.winfo_x()
40
+ new_y = (event.y - self.y) + self.widget.winfo_y()
41
+ if new_y <= 0:
42
+ new_y = 0
43
+ self.widget.place(x=new_x, y=new_y)
44
+
45
+ def bind(self):
46
+ self.widget.bind("<Button-1>", self._click)
47
+ self.widget.bind("<B1-Motion>", lambda event: self._widget_move(event))
48
+
49
+ def tag_bind(self, tag):
50
+ self.widget.tag_bind(tag, "<Button-1>", self._click)
51
+ self.widget.tag_bind(tag, "<B1-Motion>", lambda event: self._widget_move(event))
52
+
53
+
54
+ def bind_window_drag(window, widget):
55
+ _ = WindowDragArea(window)
56
+ _.bind(widget)
57
+ return _
58
+
59
+
60
+ def tag_bind_window_drag(window, widget, tag):
61
+ _ = WindowDragArea(window)
62
+ _.tag_bind(widget, tag)
63
+ return _
64
+
65
+
66
+ def bind_widget_drag(widget):
67
+ _ = WidgetDragArea(widget)
68
+ _.bind()
69
+ return _
70
+
71
+
72
+ def tag_bind_widget_drag(widget, tag):
73
+ _ = WidgetDragArea(widget)
74
+ _.tag_bind(tag)
75
+ return _
76
+
77
+
tkflu/entry.py CHANGED
@@ -138,6 +138,7 @@ class FluEntry(FluEntryCanvas, DDrawWidget):
138
138
  self._draw(event)
139
139
 
140
140
  def theme(self, mode="light"):
141
+ self.mode = mode
141
142
  if mode.lower() == "dark":
142
143
  self._dark()
143
144
  else:
tkflu/frame.py CHANGED
@@ -30,6 +30,24 @@ class FluFrameDraw(DSvgDraw):
30
30
 
31
31
  class FluFrameCanvas(DCanvas):
32
32
  draw = FluFrameDraw
33
+ frame = None
34
+
35
+ def theme(self, mode="light"):
36
+ self.theme_myself(mode=mode)
37
+
38
+ for widget in self.frame.winfo_children():
39
+ if hasattr(widget, "theme"):
40
+ widget.theme(mode=mode)
41
+ if hasattr(widget, "_draw"):
42
+ widget._draw()
43
+ widget.update()
44
+
45
+ def theme_myself(self, mode="light"):
46
+ self.frame.theme(mode)
47
+ if hasattr(self.frame, "_draw"):
48
+ self.frame._draw()
49
+ self.frame.update()
50
+ self.update()
33
51
 
34
52
  def create_round_rectangle(self,
35
53
  x1, y1, x2, y2, r1, r2=None, temppath=None,
@@ -62,6 +80,7 @@ class FluFrame(Frame, DObject):
62
80
  _, self.temppath = mkstemp(suffix=".svg", prefix="tkdeft.temp.")
63
81
 
64
82
  self.canvas = FluFrameCanvas(master, *args, width=width, height=height, **kwargs)
83
+ self.canvas.frame = self
65
84
 
66
85
  super().__init__(master=self.canvas)
67
86
 
@@ -90,6 +109,7 @@ class FluFrame(Frame, DObject):
90
109
  self.theme(mode)
91
110
 
92
111
  def theme(self, mode="light"):
112
+ self.mode = mode
93
113
  if mode.lower() == "dark":
94
114
  self._dark()
95
115
  else:
@@ -207,3 +227,4 @@ class FluFrame(Frame, DObject):
207
227
 
208
228
  def _event_configure(self, event=None):
209
229
  self._draw(event)
230
+
tkflu/image.py ADDED
File without changes
tkflu/label.py CHANGED
@@ -48,6 +48,7 @@ class FluLabel(DDrawWidget):
48
48
  )
49
49
 
50
50
  def theme(self, mode="light"):
51
+ self.mode = mode
51
52
  if mode.lower() == "dark":
52
53
  self._dark()
53
54
  else:
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