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/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 ADDED
@@ -0,0 +1,185 @@
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 FluEntryDraw(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 FluEntryCanvas(DCanvas):
34
+ draw = FluEntryDraw
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 FluEntry(FluEntryCanvas, DDrawWidget):
51
+ def __init__(self, *args,
52
+ width=120,
53
+ height=32,
54
+ font=None,
55
+ cursor="xterm",
56
+ textvariable=None,
57
+ mode="light",
58
+ **kwargs):
59
+ self._init(mode)
60
+
61
+ from tkinter import Entry
62
+
63
+ self.entry = Entry(textvariable=textvariable, border=0, cursor=cursor)
64
+
65
+ self.entry.bind("<Enter>", self._event_enter, add="+")
66
+ self.entry.bind("<Leave>", self._event_leave, add="+")
67
+ self.entry.bind("<Button-1>", self._event_on_button1, add="+")
68
+ self.entry.bind("<ButtonRelease-1>", self._event_off_button1, add="+")
69
+ self.entry.bind("<FocusIn>", self._event_focus_in, add="+")
70
+ self.entry.bind("<FocusOut>", self._event_focus_out, add="+")
71
+
72
+ super().__init__(*args, width=width, height=height, cursor=cursor, **kwargs)
73
+
74
+ if font is None:
75
+ from tkdeft.utility.fonts import SegoeFont
76
+ self.attributes.font = SegoeFont()
77
+
78
+ def _init(self, mode):
79
+ from easydict import EasyDict
80
+
81
+ self.attributes = EasyDict(
82
+ {
83
+ "font": None,
84
+
85
+ "rest": {},
86
+
87
+ "focus": {}
88
+
89
+ }
90
+ )
91
+
92
+ self.theme(mode=mode)
93
+
94
+ def _draw(self, event=None):
95
+ super()._draw(event)
96
+
97
+ self.delete("all")
98
+
99
+ self.entry.configure(font=self.attributes.font)
100
+
101
+ if self.isfocus:
102
+ _back_color = self.attributes.focus.back_color
103
+ _border_color = self.attributes.focus.border_color
104
+ _border_color2 = self.attributes.focus.border_color2
105
+ _border_width = self.attributes.focus.border_width
106
+ _radius = self.attributes.focus.radius
107
+ _text_color = self.attributes.focus.text_color
108
+ else:
109
+ _back_color = self.attributes.rest.back_color
110
+ _border_color = self.attributes.rest.border_color
111
+ _border_color2 = self.attributes.rest.border_color2
112
+ _border_width = self.attributes.rest.border_width
113
+ _radius = self.attributes.rest.radius
114
+ _text_color = self.attributes.rest.text_color
115
+
116
+ self.entry.configure(background=_back_color, insertbackground=_text_color, foreground=_text_color)
117
+
118
+ self.element_border = self.create_round_rectangle(
119
+ 0, 0, self.winfo_width(), self.winfo_height(), _radius, temppath=self.temppath,
120
+ fill=_back_color, outline=_border_color, outline2=_border_color2, width=_border_width
121
+ )
122
+
123
+ self.element_text = self.create_window(
124
+ self.winfo_width() / 2, self.winfo_height() / 2,
125
+ window=self.entry,
126
+ width=self.winfo_width() - _border_width * 2 - _radius,
127
+ height=self.winfo_height() - _border_width * 2 - _radius
128
+ )
129
+
130
+ def _event_focus_in(self, event=None):
131
+ self.isfocus = True
132
+
133
+ self._draw(event)
134
+
135
+ def _event_focus_out(self, event=None):
136
+ self.isfocus = False
137
+
138
+ self._draw(event)
139
+
140
+ def theme(self, mode="light"):
141
+ self.mode = mode
142
+ if mode.lower() == "dark":
143
+ self._dark()
144
+ else:
145
+ self._light()
146
+
147
+ def _light(self):
148
+ self.dconfigure(
149
+ rest={
150
+ "back_color": "#ffffff",
151
+ "border_color": "#f0f0f0",
152
+ "border_color2": "#8d8d8d",
153
+ "border_width": 1,
154
+ "radius": 6,
155
+ "text_color": "#646464",
156
+ },
157
+ focus={
158
+ "back_color": "#ffffff",
159
+ "border_color": "#f0f0f0",
160
+ "border_color2": "#005fb8",
161
+ "border_width": 2,
162
+ "radius": 6,
163
+ "text_color": "#636363",
164
+ }
165
+ )
166
+
167
+ def _dark(self):
168
+ self.dconfigure(
169
+ rest={
170
+ "back_color": "#272727",
171
+ "border_color": "#2c2c2c",
172
+ "border_color2": "#979797",
173
+ "border_width": 1,
174
+ "radius": 6,
175
+ "text_color": "#ffffff",
176
+ },
177
+ focus={
178
+ "back_color": "#1d1d1d",
179
+ "border_color": "#272727",
180
+ "border_color2": "#60cdff",
181
+ "border_width": 2,
182
+ "radius": 6,
183
+ "text_color": "#ffffff",
184
+ }
185
+ )
tkflu/frame.py ADDED
@@ -0,0 +1,230 @@
1
+ from tkdeft.windows.draw import DSvgDraw
2
+ from tkdeft.windows.canvas import DCanvas
3
+
4
+
5
+ class FluFrameDraw(DSvgDraw):
6
+ def create_roundrect(self,
7
+ x1, y1, x2, y2, radius, radiusy=None, temppath=None,
8
+ fill="transparent", outline="black", outline2="black", width=1
9
+ ):
10
+ if radiusy:
11
+ _rx = radius
12
+ _ry = radiusy
13
+ else:
14
+ _rx, _ry = radius, radius
15
+ drawing = self.create_drawing(x2 - x1, y2 - y1, temppath=temppath)
16
+ border = drawing[1].linearGradient(start=(x1, y1), end=(x1, y2), id="DButton.Border")
17
+ border.add_stop_color("0%", outline)
18
+ border.add_stop_color("100%", outline2)
19
+ drawing[1].defs.add(border)
20
+ drawing[1].add(
21
+ drawing[1].rect(
22
+ (x1, y1), (x2 - x1, y2 - y1), _rx, _ry,
23
+ fill=fill, stroke_width=width,
24
+ stroke=f"url(#{border.get_id()})",
25
+ )
26
+ )
27
+ drawing[1].save()
28
+ return drawing[0]
29
+
30
+
31
+ class FluFrameCanvas(DCanvas):
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()
51
+
52
+ def create_round_rectangle(self,
53
+ x1, y1, x2, y2, r1, r2=None, temppath=None,
54
+ fill="transparent", outline="black", outline2="black", width=1
55
+ ):
56
+ self._img = self.svgdraw.create_roundrect(
57
+ x1, y1, x2, y2, r1, r2, temppath=temppath,
58
+ fill=fill, outline=outline, outline2=outline2, width=width
59
+ )
60
+ self._tkimg = self.svgdraw.create_tksvg_image(self._img)
61
+ return self.create_image(x1, y1, anchor="nw", image=self._tkimg)
62
+
63
+ create_roundrect = create_round_rectangle
64
+
65
+
66
+ from tkinter import Frame
67
+ from tkdeft.object import DObject
68
+
69
+
70
+ class FluFrame(Frame, DObject):
71
+ def __init__(self,
72
+ master=None,
73
+ *args,
74
+ width=300,
75
+ height=150,
76
+ mode="light",
77
+ **kwargs,
78
+ ):
79
+ from tempfile import mkstemp
80
+ _, self.temppath = mkstemp(suffix=".svg", prefix="tkdeft.temp.")
81
+
82
+ self.canvas = FluFrameCanvas(master, *args, width=width, height=height, **kwargs)
83
+ self.canvas.frame = self
84
+
85
+ super().__init__(master=self.canvas)
86
+
87
+ self._init(mode)
88
+
89
+ self.enter = False
90
+ self.button1 = False
91
+
92
+ self._draw(None)
93
+
94
+ self.canvas.bind("<Configure>", self._event_configure, add="+")
95
+
96
+ def _init(self, mode):
97
+ from easydict import EasyDict
98
+
99
+ self.attributes = EasyDict(
100
+ {
101
+ "back_color": None,
102
+ "border_color": None,
103
+ "border_color2": None,
104
+ "border_width": None,
105
+ "radius": None,
106
+ }
107
+ )
108
+
109
+ self.theme(mode)
110
+
111
+ def theme(self, mode="light"):
112
+ self.mode = mode
113
+ if mode.lower() == "dark":
114
+ self._dark()
115
+ else:
116
+ self._light()
117
+
118
+ def _light(self):
119
+ self.dconfigure(
120
+ back_color="#ffffff",
121
+ border_color="#ebebeb",
122
+ border_color2="#e4e4e4",
123
+ border_width=1,
124
+ radius=6,
125
+ )
126
+
127
+ def _dark(self):
128
+ self.dconfigure(
129
+ back_color="#242424",
130
+ border_color="#303030",
131
+ border_color2="#282828",
132
+ border_width=1,
133
+ radius=6,
134
+ )
135
+
136
+ def pack_info(self):
137
+ return self.canvas.pack_info()
138
+
139
+ def pack_forget(self):
140
+ return self.canvas.pack_forget()
141
+
142
+ def pack_slaves(self):
143
+ return self.canvas.pack_slaves()
144
+
145
+ def pack_propagate(self, flag):
146
+ return self.canvas.pack_propagate()
147
+
148
+ def pack_configure(self, **kwargs):
149
+ return self.canvas.pack_configure(**kwargs)
150
+
151
+ pack = pack_configure
152
+
153
+ def grid_info(self):
154
+ return self.canvas.grid_info()
155
+
156
+ def grid_forget(self):
157
+ return self.canvas.grid_forget()
158
+
159
+ def grid_size(self):
160
+ return self.canvas.grid_size()
161
+
162
+ def grid_remove(self):
163
+ return self.canvas.grid_remove()
164
+
165
+ def grid_anchor(self, anchor=...):
166
+ return self.canvas.grid_anchor(anchor)
167
+
168
+ def grid_slaves(self, row=..., column=...):
169
+ return self.canvas.grid_slaves(row=row, column=column)
170
+
171
+ def grid_propagate(self, flag):
172
+ return self.canvas.grid_propagate(flag)
173
+
174
+ def grid_location(self, x, y):
175
+ return self.canvas.grid_location()
176
+
177
+ def grid_bbox(self, **kwargs):
178
+ return self.canvas.grid_bbox(**kwargs)
179
+
180
+ def grid_configure(self, **kwargs):
181
+ return self.canvas.grid_configure(**kwargs)
182
+
183
+ grid = grid_configure
184
+
185
+ def grid_rowconfigure(self, **kwargs):
186
+ return self.canvas.grid_rowconfigure(**kwargs)
187
+
188
+ def grid_columnconfigure(self, **kwargs):
189
+ return self.canvas.grid_columnconfigure(**kwargs)
190
+
191
+ def place_info(self):
192
+ return self.canvas.grid_info()
193
+
194
+ def place_forget(self):
195
+ return self.canvas.place_forget()
196
+
197
+ def place_slaves(self):
198
+ return self.canvas.place_slaves()
199
+
200
+ def place_configure(self, **kwargs):
201
+ return self.canvas.place_configure(**kwargs)
202
+
203
+ place = place_configure
204
+
205
+ def _draw(self, event=None):
206
+ self.canvas.delete("all")
207
+ self.canvas.config(background=self.canvas.master.cget("background"))
208
+ self.config(background=self.attributes.back_color)
209
+
210
+ _back_color = self.attributes.back_color
211
+ _border_color = self.attributes.border_color
212
+ _border_color2 = self.attributes.border_color2
213
+ _border_width = self.attributes.border_width
214
+ _radius = self.attributes.radius
215
+
216
+ self.element1 = self.canvas.create_round_rectangle(
217
+ 0, 0, self.canvas.winfo_width(), self.canvas.winfo_height(), _radius, temppath=self.temppath,
218
+ fill=_back_color, outline=_border_color, outline2=_border_color2, width=_border_width
219
+ )
220
+
221
+ self.element2 = self.canvas.create_window(
222
+ self.canvas.winfo_width() / 2, self.canvas.winfo_height() / 2,
223
+ window=self,
224
+ width=self.canvas.winfo_width() - _border_width * 2 - _radius,
225
+ height=self.canvas.winfo_height() - _border_width * 2 - _radius
226
+ )
227
+
228
+ def _event_configure(self, event=None):
229
+ self._draw(event)
230
+
tkflu/image.py ADDED
File without changes
tkflu/label.py ADDED
@@ -0,0 +1,65 @@
1
+ from tkdeft.windows.drawwidget import DDrawWidget
2
+
3
+
4
+ class FluLabel(DDrawWidget):
5
+ def __init__(self, *args,
6
+ text="",
7
+ width=120,
8
+ height=32,
9
+ font=None,
10
+ mode="light",
11
+ **kwargs):
12
+ self._init(mode)
13
+
14
+ super().__init__(*args, width=width, height=height, **kwargs)
15
+
16
+ self.dconfigure(
17
+ text=text,
18
+ )
19
+
20
+ if font is None:
21
+ from tkdeft.utility.fonts import SegoeFont
22
+ self.attributes.font = SegoeFont()
23
+
24
+ def _init(self, mode):
25
+
26
+ from easydict import EasyDict
27
+
28
+ self.attributes = EasyDict(
29
+ {
30
+ "text": "",
31
+ "command": None,
32
+ "font": None,
33
+
34
+ "text_color": "#1b1b1b",
35
+ }
36
+ )
37
+
38
+ self.theme(mode=mode)
39
+
40
+ def _draw(self, event=None):
41
+ super()._draw(event)
42
+
43
+ self.delete("all")
44
+
45
+ self.element_text = self.create_text(
46
+ self.winfo_width() / 2, self.winfo_height() / 2, anchor="center",
47
+ fill=self.attributes.text_color, text=self.attributes.text, font=self.attributes.font
48
+ )
49
+
50
+ def theme(self, mode="light"):
51
+ self.mode = mode
52
+ if mode.lower() == "dark":
53
+ self._dark()
54
+ else:
55
+ self._light()
56
+
57
+ def _light(self):
58
+ self.dconfigure(
59
+ text_color="#000000"
60
+ )
61
+
62
+ def _dark(self):
63
+ self.dconfigure(
64
+ text_color="#ffffff"
65
+ )