tkfluent 0.0.3__py3-none-any.whl → 0.0.5__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/popupmenu.py CHANGED
@@ -1,35 +1,10 @@
1
- from tkinter import Toplevel
2
1
  from .frame import FluFrame
2
+ from .popupwindow import FluPopupWindow
3
3
 
4
4
 
5
- class FluPopupMenuWindow(Toplevel):
6
- def __init__(self, *args, transparent_color="#ffefa2", mode="light", width=100, height=46, **kwargs):
7
- super().__init__(*args, background=transparent_color, **kwargs)
8
-
9
- self.theme(mode=mode)
10
-
11
- self.geometry(f"{width}x{height}")
12
-
13
- self.transient_color = transparent_color
14
- self.overrideredirect(True)
15
- self.attributes("-transparentcolor", transparent_color)
16
-
17
- self.withdraw()
18
-
19
- self.bind("<FocusOut>", self._event_focusout)
20
-
21
- def _event_focusout(self, event=None):
22
- self.withdraw()
23
-
24
- def popup(self, x, y):
25
- self.geometry(f"+{x}+{y}")
26
-
27
- def theme(self, mode=None):
28
- if mode:
29
- self.mode = mode
30
- for widget in self.winfo_children():
31
- if hasattr(widget, "theme"):
32
- widget.theme(mode=self.mode.lower())
5
+ class FluPopupMenuWindow(FluPopupWindow):
6
+ def __init__(self, *args, **kwargs):
7
+ super().__init__(*args, **kwargs)
33
8
 
34
9
 
35
10
  class FluPopupMenu(FluFrame):
tkflu/popupwindow.py ADDED
@@ -0,0 +1,31 @@
1
+ from tkinter import Toplevel
2
+
3
+
4
+ class FluPopupWindow(Toplevel):
5
+ def __init__(self, *args, transparent_color="#ebebeb", mode="light", width=100, height=46, **kwargs):
6
+ super().__init__(*args, background=transparent_color, **kwargs)
7
+
8
+ self.theme(mode=mode)
9
+
10
+ self.geometry(f"{width}x{height}")
11
+
12
+ self.transient_color = transparent_color
13
+ self.overrideredirect(True)
14
+ self.attributes("-transparentcolor", transparent_color)
15
+
16
+ self.withdraw()
17
+
18
+ self.bind("<FocusOut>", self._event_focusout, add="+")
19
+
20
+ def _event_focusout(self, event=None):
21
+ self.withdraw()
22
+
23
+ def popup(self, x, y):
24
+ self.geometry(f"+{x}+{y}")
25
+
26
+ def theme(self, mode=None):
27
+ if mode:
28
+ self.mode = mode
29
+ for widget in self.winfo_children():
30
+ if hasattr(widget, "theme"):
31
+ widget.theme(mode=self.mode.lower())
tkflu/text.py CHANGED
@@ -2,30 +2,51 @@ from tkdeft.windows.draw import DSvgDraw
2
2
  from tkdeft.windows.canvas import DCanvas
3
3
  from tkdeft.windows.drawwidget import DDrawWidget
4
4
 
5
+ from .designs.text import text
6
+
5
7
 
6
8
  class FluTextDraw(DSvgDraw):
7
9
  def create_roundrect(self,
8
10
  x1, y1, x2, y2, radius, radiusy=None, temppath=None,
9
- fill="transparent", outline="black", outline2="black", width=1
11
+ fill="transparent", fill_opacity=1,
12
+ stop1="0.93", outline="black", outline_opacity=1,
13
+ stop2="0.94", outline2=None, outline2_opacity=1,
14
+ width=1
10
15
  ):
11
16
  if radiusy:
12
17
  _rx = radius
13
18
  _ry = radiusy
14
19
  else:
15
20
  _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)
21
+ drawing = self.create_drawing(x2 - x1, y2 - y1, temppath=temppath, fill="none")
22
+ if outline2:
23
+ border = drawing[1].linearGradient(start=(x1, y1 + 1), end=(x1, y2 - 1), id="DButton.Border",
24
+ gradientUnits="userSpaceOnUse")
25
+ border.add_stop_color(stop1, outline, outline_opacity)
26
+ border.add_stop_color(stop2, outline2, outline2_opacity)
27
+ drawing[1].defs.add(border)
28
+ stroke = f"url(#{border.get_id()})"
29
+ stroke_opacity = 1
30
+ else:
31
+ stroke = outline
32
+ stroke_opacity = outline_opacity
33
+
22
34
  drawing[1].add(
23
35
  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()})",
36
+ (x1 + 1, y1 + 1), (x2 - x1 - 2, y2 - y1 - 2), _rx, _ry,
37
+ id="Base",
38
+ fill=fill, fill_opacity=fill_opacity,
27
39
  )
28
40
  )
41
+ drawing[1].add(
42
+ drawing[1].rect(
43
+ (x1 + 0.5, y1 + 0.5), (x2 - x1 - 1, y2 - y1 - 1), _rx, _ry,
44
+ id="Base",
45
+ fill="white", fill_opacity="0",
46
+ stroke=stroke, stroke_width=width, stroke_opacity=stroke_opacity,
47
+ )
48
+ )
49
+ #print("FluEntry", drawing[0])
29
50
  drawing[1].save()
30
51
  return drawing[0]
31
52
 
@@ -35,11 +56,15 @@ class FluTextCanvas(DCanvas):
35
56
 
36
57
  def create_round_rectangle(self,
37
58
  x1, y1, x2, y2, r1, r2=None, temppath=None,
38
- fill="transparent", outline="black", outline2="black", width=1
59
+ fill="transparent", fill_opacity=1, stop1="0.93", stop2="0.94",
60
+ outline="black", outline2="black", outline_opacity=1, outline2_opacity=1,
61
+ width=1
39
62
  ):
40
63
  self._img = self.svgdraw.create_roundrect(
41
64
  x1, y1, x2, y2, r1, r2, temppath=temppath,
42
- fill=fill, outline=outline, outline2=outline2, width=width
65
+ fill=fill, fill_opacity=fill_opacity, stop1=stop1, stop2=stop2,
66
+ outline=outline, outline2=outline2, outline_opacity=outline_opacity, outline2_opacity=outline2_opacity,
67
+ width=width
43
68
  )
44
69
  self._tkimg = self.svgdraw.create_tksvg_image(self._img)
45
70
  return self.create_image(x1, y1, anchor="nw", image=self._tkimg)
@@ -54,6 +79,7 @@ class FluText(FluTextCanvas, DDrawWidget):
54
79
  font=None,
55
80
  cursor="xterm",
56
81
  mode="light",
82
+ state="normal",
57
83
  **kwargs):
58
84
  self._init(mode)
59
85
 
@@ -72,9 +98,12 @@ class FluText(FluTextCanvas, DDrawWidget):
72
98
 
73
99
  self.bind("<FocusIn>", self._event_focus_in, add="+")
74
100
 
75
- if font is None:
76
- from tkdeft.utility.fonts import SegoeFont
77
- self.attributes.font = SegoeFont()
101
+ self.dconfigure(
102
+ state=state,
103
+ )
104
+
105
+ from .defs import set_default_font
106
+ set_default_font(font, self.attributes)
78
107
 
79
108
  def _init(self, mode):
80
109
  from easydict import EasyDict
@@ -82,11 +111,12 @@ class FluText(FluTextCanvas, DDrawWidget):
82
111
  self.attributes = EasyDict(
83
112
  {
84
113
  "font": None,
114
+ "state": "normal",
85
115
 
86
116
  "rest": {},
87
-
88
- "focus": {}
89
-
117
+ "hover": {},
118
+ "pressed": {},
119
+ "disabled": {},
90
120
  }
91
121
  )
92
122
 
@@ -95,24 +125,43 @@ class FluText(FluTextCanvas, DDrawWidget):
95
125
  def _draw(self, event=None):
96
126
  super()._draw(event)
97
127
 
128
+ width = self.winfo_width()
129
+ height = self.winfo_height()
130
+
98
131
  self.text.configure(font=self.attributes.font)
99
132
 
100
133
  self.delete("all")
101
134
 
102
- if self.isfocus:
103
- _back_color = self.attributes.focus.back_color
104
- _border_color = self.attributes.focus.border_color
105
- _border_color2 = self.attributes.focus.border_color2
106
- _border_width = self.attributes.focus.border_width
107
- _radius = self.attributes.focus.radius
108
- _text_color = self.attributes.focus.text_color
135
+ state = self.dcget("state")
136
+
137
+ _dict = None
138
+
139
+ if state == "normal":
140
+ if self.isfocus:
141
+ _dict = self.attributes.pressed
142
+ else:
143
+ if self.enter:
144
+ _dict = self.attributes.hover
145
+ else:
146
+ _dict = self.attributes.rest
147
+ self.text.configure(state="normal")
109
148
  else:
110
- _back_color = self.attributes.rest.back_color
111
- _border_color = self.attributes.rest.border_color
112
- _border_color2 = self.attributes.rest.border_color2
113
- _border_width = self.attributes.rest.border_width
114
- _radius = self.attributes.rest.radius
115
- _text_color = self.attributes.rest.text_color
149
+ _dict = self.attributes.disabled
150
+ self.text.configure(state="disabled")
151
+
152
+ _stop1 = _dict.stop1
153
+ _stop2 = _dict.stop2
154
+ _back_color = _dict.back_color
155
+ _back_opacity = _dict.back_opacity
156
+ _border_color = _dict.border_color
157
+ _border_color_opacity = _dict.border_color_opacity
158
+ _border_color2 = _dict.border_color2
159
+ _border_color2_opacity = _dict.border_color2_opacity
160
+ _border_width = _dict.border_width
161
+ _radius = _dict.radius
162
+ _text_color = _dict.text_color
163
+ _underline_fill = _dict.underline_fill
164
+ _underline_width = _dict.underline_width
116
165
 
117
166
  self.text.configure(
118
167
  background=_back_color, insertbackground=_text_color, foreground=_text_color,
@@ -121,10 +170,20 @@ class FluText(FluTextCanvas, DDrawWidget):
121
170
  )
122
171
 
123
172
  self.element_border = self.create_round_rectangle(
124
- 0, 0, self.winfo_width(), self.winfo_height(), _radius, temppath=self.temppath,
125
- fill=_back_color, outline=_border_color, outline2=_border_color2, width=_border_width
173
+ 0, 0, width, height, _radius, temppath=self.temppath,
174
+ fill=_back_color, fill_opacity=_back_opacity, stop1=_stop1, stop2=_stop2,
175
+ outline=_border_color, outline_opacity=_border_color_opacity, outline2=_border_color2,
176
+ outline2_opacity=_border_color2_opacity,
177
+ width=_border_width
126
178
  )
127
179
 
180
+ if _underline_fill:
181
+ self.element_line = self.create_line(
182
+ _radius / 3 + _border_width, self.winfo_height() - _radius / 3,
183
+ self.winfo_width() - _radius / 3 - _border_width * 2, self.winfo_height() - _radius / 3,
184
+ width=_underline_width, fill=_underline_fill
185
+ )
186
+
128
187
  self.element_text = self.create_window(
129
188
  self.winfo_width() / 2, self.winfo_height() / 2,
130
189
  window=self.text,
@@ -149,42 +208,92 @@ class FluText(FluTextCanvas, DDrawWidget):
149
208
  else:
150
209
  self._light()
151
210
 
152
- def _light(self):
211
+ def _theme(self, mode):
212
+ r = text(mode, "rest")
213
+ h = text(mode, "hover")
214
+ p = text(mode, "pressed")
215
+ d = text(mode, "disabled")
153
216
  self.dconfigure(
154
217
  rest={
155
- "back_color": "#ffffff",
156
- "border_color": "#e5e5e5",
157
- "border_color2": "#8d8d8d",
158
- "border_width": 1,
159
- "radius": 6,
160
- "text_color": "#646464",
218
+ "back_color": r["back_color"],
219
+ "back_opacity": r["back_opacity"],
220
+
221
+ "stop1": r["stop1"],
222
+ "border_color": r["border_color"],
223
+ "border_color_opacity": r["border_color_opacity"],
224
+
225
+ "stop2": r["stop2"],
226
+ "border_color2": r["border_color2"],
227
+ "border_color2_opacity": r["border_color2_opacity"],
228
+
229
+ "border_width": r["border_width"],
230
+ "radius": r["radius"],
231
+ "text_color": r["text_color"],
232
+
233
+ "underline_fill": r["underline_fill"],
234
+ "underline_width": r["underline_width"]
235
+ },
236
+ hover={
237
+ "back_color": h["back_color"],
238
+ "back_opacity": h["back_opacity"],
239
+
240
+ "stop1": h["stop1"],
241
+ "border_color": h["border_color"],
242
+ "border_color_opacity": h["border_color_opacity"],
243
+
244
+ "stop2": h["stop2"],
245
+ "border_color2": h["border_color2"],
246
+ "border_color2_opacity": h["border_color2_opacity"],
247
+
248
+ "border_width": h["border_width"],
249
+ "radius": h["radius"],
250
+ "text_color": h["text_color"],
251
+
252
+ "underline_fill": h["underline_fill"],
253
+ "underline_width": r["underline_width"]
254
+ },
255
+ pressed={
256
+ "back_color": p["back_color"],
257
+ "back_opacity": p["back_opacity"],
258
+
259
+ "stop1": p["stop1"],
260
+ "border_color": p["border_color"],
261
+ "border_color_opacity": p["border_color_opacity"],
262
+
263
+ "stop2": p["stop2"],
264
+ "border_color2": p["border_color2"],
265
+ "border_color2_opacity": p["border_color2_opacity"],
266
+
267
+ "border_width": p["border_width"],
268
+ "radius": p["radius"],
269
+ "text_color": p["text_color"],
270
+
271
+ "underline_fill": p["underline_fill"],
272
+ "underline_width": r["underline_width"]
161
273
  },
162
- focus={
163
- "back_color": "#ffffff",
164
- "border_color": "#e5e5e5",
165
- "border_color2": "#005fb8",
166
- "border_width": 2,
167
- "radius": 6,
168
- "text_color": "#636363",
274
+ disabled={
275
+ "back_color": d["back_color"],
276
+ "back_opacity": r["back_opacity"],
277
+
278
+ "stop1": d["stop1"],
279
+ "border_color": d["border_color"],
280
+ "border_color_opacity": d["border_color_opacity"],
281
+
282
+ "stop2": d["stop2"],
283
+ "border_color2": d["border_color2"],
284
+ "border_color2_opacity": d["border_color2_opacity"],
285
+
286
+ "border_width": d["border_width"],
287
+ "radius": d["radius"],
288
+ "text_color": d["text_color"],
289
+
290
+ "underline_fill": d["underline_fill"],
291
+ "underline_width": r["underline_width"]
169
292
  }
170
293
  )
171
294
 
295
+ def _light(self):
296
+ self._theme("light")
297
+
172
298
  def _dark(self):
173
- self.dconfigure(
174
- rest={
175
- "back_color": "#272727",
176
- "border_color": "#2c2c2c",
177
- "border_color2": "#979797",
178
- "border_width": 1,
179
- "radius": 6,
180
- "text_color": "#ffffff",
181
- },
182
- focus={
183
- "back_color": "#1d1d1d",
184
- "border_color": "#272727",
185
- "border_color2": "#60cdff",
186
- "border_width": 2,
187
- "radius": 6,
188
- "text_color": "#ffffff",
189
- }
190
- )
299
+ self._theme("dark")