tkmacos 2.0.0__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.
tkmacos/__init__.py ADDED
@@ -0,0 +1,31 @@
1
+ # Modified by the tkmacos fork; see NOTICE for details.
2
+ # Copyright 2021 Saad Mairaj
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ """
17
+ This module provides some modified widgets of Tkinter which works better on macos
18
+ and some more useful functions and classes as well. For example Button of tkmacos which
19
+ looks and feels exactly like a native tkinter button can change its background
20
+ and foreground colors.
21
+
22
+ TkMacos is the maintained fork of the original tkmacosx project.
23
+ """
24
+
25
+ __version__ = '2.0.0'
26
+ __author__ = 'Saad Mairaj'
27
+
28
+ from tkmacos.variables import ColorVar, DictVar, SaveVar
29
+ from tkmacos.widgets import Button, CircleButton, Colorscale, Radiobutton, Marquee, SFrame
30
+ from tkmacos.utils import (check_appearance, check_light_dark,
31
+ delta, hex_to_rgb, get_shade, gradient)
tkmacos/__main__.py ADDED
@@ -0,0 +1,324 @@
1
+ # Modified by the tkmacos fork; see NOTICE for details.
2
+ # Copyright 2021 Saad Mairaj
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import random
17
+ import tkinter as tk
18
+
19
+ from tkinter import font
20
+ from tkinter import ttk
21
+ from tkinter.colorchooser import askcolor
22
+
23
+ from tkmacos import SFrame, Button, Colorscale, ColorVar
24
+ from tkmacos.utils import check_light_dark
25
+
26
+
27
+ def grid(root, row, column):
28
+ "Defines rows and columns if grid method is used"
29
+ for y in range(column):
30
+ tk.Grid.columnconfigure(root, y, weight=1)
31
+ for x in range(row):
32
+ tk.Grid.rowconfigure(root, x, weight=1)
33
+
34
+
35
+ def sort_random_values(fn):
36
+ def wrapper(*args, **kwargs):
37
+ value = fn(*args, **kwargs)
38
+ if isinstance(value, (list, tuple)) and len(value) == 1:
39
+ return value[0]
40
+ return value
41
+ return wrapper
42
+
43
+
44
+ def choices(seq, k):
45
+ "Random choices."
46
+ return tuple(random.choice(seq) for i in range(k))
47
+
48
+
49
+ @sort_random_values
50
+ def get_random_colors(k=1):
51
+ return ["#%06x" % random.randint(0, 0xFFFFFF) for n in range(k)]
52
+
53
+
54
+ @sort_random_values
55
+ def get_random_font(k=1):
56
+ def family():
57
+ return random.choice(font.families())
58
+
59
+ def weight():
60
+ return random.choice(('bold', 'normal'))
61
+
62
+ def slant():
63
+ return random.choice(('italic', 'roman'))
64
+
65
+ def underline():
66
+ return random.choice((True, False))
67
+
68
+ overstrike = underline
69
+ return tuple(font.Font(family=family(), weight=weight(),
70
+ slant=slant(), underline=underline(),
71
+ overstrike=overstrike(), size=30,) for i in range(k))
72
+
73
+
74
+ @sort_random_values
75
+ def get_random_size(k=1, start=10, end=200):
76
+ return tuple(choices([i for i in range(start, end)], k=k))
77
+
78
+
79
+ @sort_random_values
80
+ def get_random_relief(k=1):
81
+ return choices(('flat', 'groove', 'raised',
82
+ 'ridge', 'solid', 'sunken'), k=k)
83
+
84
+
85
+ class Sample(tk.Tk):
86
+ def __init__(self):
87
+ tk.Tk.__init__(self)
88
+ self.resizable(0, 0)
89
+ self.geometry('420x700+300+100')
90
+ self.title('Mac OSX Button Testing')
91
+ self.wm_attributes('-modified', 1)
92
+ self.main_color = ColorVar(value='#ffe6f4')
93
+ self['bg'] = self.main_color
94
+ grid(self, 25, 5)
95
+ self.L1 = tk.Label(self, text='Comparison',
96
+ bg=self.main_color, font=('', 18, 'bold'))
97
+ self.L1.grid(row=0, column=0, columnspan=5, sticky='nsew')
98
+ Button(self, text='Hello').grid(row=1, column=1, sticky='s')
99
+ ttk.Button(self, text='Hello').grid(row=1, column=3, sticky='s')
100
+ tk.Button(self, text='Hello').grid(row=1, column=2, sticky='s')
101
+ tk.Label(self, bg=self.main_color, font=('', 10),
102
+ text='(Mac OSX)').grid(row=2, column=1, sticky='n',)
103
+ tk.Label(self, bg=self.main_color, font=('', 10),
104
+ text='(ttk themed)').grid(row=2, column=3, sticky='n')
105
+ tk.Label(self, bg=self.main_color, font=('', 10),
106
+ text='(Default)').grid(row=2, column=2, sticky='n')
107
+ ttk.Separator(self, orient='vertical').grid(
108
+ row=3, column=0, columnspan=5, sticky='ew')
109
+
110
+ # ------------ Seperator -------------
111
+
112
+ # ------------ Demonstration ------------
113
+
114
+ self.sfr = SFrame(self, bg=self.main_color)
115
+ self.sfr.grid(rowspan=27, columnspan=5, sticky='nsew')
116
+ for i in range(5):
117
+ self.sfr.grid_columnconfigure(i, weight=1)
118
+ self.L2 = tk.Label(self.sfr, text='Demonstration',
119
+ bg=self.main_color, font=('', 20, 'bold'))
120
+ self.L2.grid(row=1, column=0, columnspan=5,
121
+ sticky='new', pady=(20, 10))
122
+
123
+ # ------------ Active Color ------------
124
+
125
+ self.L3 = tk.Label(self.sfr, text='1. Change Active color', bg=self.main_color,
126
+ font=('', 15, 'bold'))
127
+ self.L3.grid(row=2, column=0, columnspan=5, sticky='nsew', pady=10)
128
+ self.L4 = tk.Label(self.sfr, text='The active color can be changed to any gradient color.',
129
+ bg=self.main_color, font=('', 10))
130
+ self.L4.grid(row=3, column=0, columnspan=5, sticky='new')
131
+ self.B1 = Button(self.sfr, text='Press Me', pady=20)
132
+ self.B1.grid(row=4, column=0, columnspan=5, pady=20)
133
+ self.C1 = tk.StringVar(value='Select')
134
+ self.L5 = tk.Label(self.sfr, text='From',
135
+ bg=self.main_color, font=('', 12))
136
+ self.L5.grid(row=5, column=1, sticky='ew')
137
+
138
+ self.L6 = tk.Label(self.sfr, text='To',
139
+ bg=self.main_color, font=('', 12))
140
+ self.L6.grid(row=5, column=3, sticky='ew')
141
+
142
+ button_container1 = tk.Frame(self.sfr, bg=self.main_color)
143
+ button_container1.grid(row=6, column=0, columnspan=5,
144
+ sticky='ew', pady=10, padx=10)
145
+ button_container1.columnconfigure(0, weight=1)
146
+ button_container1.columnconfigure(1, weight=1)
147
+ self.Om1_b = Button(button_container1, text='Change Color',
148
+ bg='#d0c0ea', borderless=1)
149
+ self.Om1_b.grid(row=0, column=0, padx=(0, 2), sticky='ew')
150
+ self.Om2_b = Button(button_container1, text='Change Color',
151
+ bg="#d0c0ea", borderless=1)
152
+ self.Om2_b.grid(row=0, column=1, sticky='ew')
153
+ self.Om1_b['command'] = lambda: self.change_active_color(1)
154
+ self.Om2_b['command'] = lambda: self.change_active_color(2)
155
+
156
+ # ------------ Background Color ------------
157
+
158
+ self.L7 = tk.Label(self.sfr, text='2. Change Background color', bg=self.main_color,
159
+ font=('', 15, 'bold'))
160
+ self.L7.grid(row=7, column=0, columnspan=5,
161
+ sticky='nsew', pady=(50, 0))
162
+ self.L8 = tk.Label(self.sfr, text='Click on the button to choose the color.',
163
+ bg=self.main_color, font=('', 10))
164
+ self.L8.grid(row=8, column=0, columnspan=5, sticky='new', pady=10)
165
+
166
+ self.B2 = Button(self.sfr, text='Color me',
167
+ font=('', 30,), pady=10)
168
+ self.B2.grid(row=9, column=0, columnspan=5, sticky='', pady=20)
169
+
170
+ button_container2 = tk.Frame(self.sfr, bg=self.main_color)
171
+ button_container2.grid(row=10, column=0, columnspan=5,
172
+ sticky='ew', pady=10, padx=10)
173
+ button_container2.columnconfigure(0, weight=1)
174
+ button_container2.columnconfigure(1, weight=1)
175
+ self.B3 = Button(button_container2, text='Change Background Color',
176
+ bg='#d0c0ea', borderless=1)
177
+ self.B3['command'] = lambda: self.B2.config(bg=askcolor()[1])
178
+ self.B3.grid(row=0, column=0, padx=(0, 2))
179
+ self.B4 = Button(button_container2, text='Change Foreground Color',
180
+ bg="#d0c0ea", borderless=1)
181
+ self.B4['command'] = lambda: self.B2.config(fg=askcolor()[1])
182
+ self.B4.grid(row=0, column=1)
183
+
184
+ # ------------ Borderless ------------
185
+
186
+ self.L9 = tk.Label(self.sfr, text='3. Switch Between Borderless', bg=self.main_color,
187
+ font=('', 15, 'bold'))
188
+ self.L9.grid(row=11, column=0, columnspan=5,
189
+ sticky='sew', pady=(50, 0))
190
+ self.L10 = tk.Label(self.sfr, text="""
191
+ In borderless it will blend with its parent widget background color.
192
+ Give parameter `borderless = True / False` to use it.""", bg=self.main_color, font=('', 10))
193
+ self.L10.grid(row=12, column=0, columnspan=5, sticky='new')
194
+
195
+ self.B5 = Button(self.sfr, text='No Borders', borderless=1, height=40,
196
+ bg='#212F3D', fg='white', activebackground=("#EAECEE", "#212F3D"))
197
+ self.B5.grid(row=13, columnspan=5, pady=(20, 5))
198
+
199
+ self.B6 = Button(self.sfr, text='No Borders', borderless=1, height=40,
200
+ bg='#F7DC6F', fg='#21618C', activebackground=('#B3B6B7', '#58D68D'))
201
+ self.B6.grid(row=14, columnspan=5, pady=(0, 20))
202
+ self.var1 = tk.BooleanVar(value=True)
203
+ self.CB1 = tk.Checkbutton(self.sfr, text='Toggle Borderless', variable=self.var1,
204
+ bg=self.main_color, command=self.change_borderless_state)
205
+ self.CB1.grid(row=15, columnspan=5, pady=(0, 10))
206
+
207
+ # ------------ Bordercolor ------------
208
+
209
+ self.L11 = tk.Label(self.sfr, text='4. Change Bordercolor', bg=self.main_color,
210
+ font=('', 15, 'bold'))
211
+ self.L11.grid(row=16, column=0, columnspan=5,
212
+ sticky='sew', pady=(50, 0))
213
+ self.L12 = tk.Label(self.sfr, text="Change Bordercolor of the button\nNote: if borderless=True, then the bordercolor won't work.",
214
+ bg=self.main_color, font=('', 10))
215
+ self.L12.grid(row=17, column=0, columnspan=5, sticky='new')
216
+
217
+ self.B7 = Button(self.sfr, text='Button', pady=10,
218
+ padx=5, font=('Zapfino', 12, 'bold'))
219
+ self.B7.grid(row=18, columnspan=5, pady=30)
220
+
221
+ self.CS1 = Colorscale(self.sfr, value='hex', mousewheel=1,
222
+ command=lambda e: self.B7.config(bordercolor=e))
223
+ self.CS1.grid(row=19, columnspan=5, sticky='ew', padx=10)
224
+
225
+ self.CS2 = Colorscale(self.sfr, value='hex', mousewheel=1,
226
+ gradient=('#FCF6F5', '#990011'),
227
+ command=lambda e: self.B7.config(bg=e))
228
+ self.CS2.grid(row=20, columnspan=5, sticky='ew', padx=10, pady=5)
229
+
230
+ self.CS3 = Colorscale(self.sfr, value='hex', mousewheel=1,
231
+ gradient=('green', 'yellow'),
232
+ command=lambda e: self.B7.config(fg=e))
233
+ self.CS3.grid(row=21, columnspan=5, sticky='ew', padx=10)
234
+
235
+ self.CS4 = Colorscale(self.sfr, value='hex', mousewheel=1,
236
+ gradient=('pink', 'purple'),
237
+ command=lambda e: self.B7.config(overforeground=e))
238
+ self.CS4.grid(row=22, columnspan=5, sticky='ew', padx=10, pady=5)
239
+
240
+ # ------------ Random button styling ------------
241
+ self.L11 = tk.Label(self.sfr, text='5. Button Styling', bg=self.main_color,
242
+ font=('', 15, 'bold'))
243
+ self.L11.grid(row=23, column=0, columnspan=5,
244
+ sticky='sew', pady=(50, 0))
245
+ self.L12 = tk.Label(self.sfr, text="Press the button to ramdomise the style of the button.",
246
+ bg=self.main_color, font=('', 10))
247
+ self.L12.grid(row=24, column=0, columnspan=5, sticky='new')
248
+
249
+ self.B10 = Button(self.sfr, text='Button', borderless=1)
250
+ self.B10.grid(row=25, columnspan=5, pady=20)
251
+
252
+ self.B11 = Button(self.sfr, text='Change Style', borderless=1, fg='#21618C',
253
+ activebackground=('#B3B6B7', '#58D68D'), command=self.change_button_style)
254
+ self.B11.grid(row=26, columnspan=5, ipady=5)
255
+
256
+ self.button_clicks = 1
257
+ self.Text1 = tk.Text(self.sfr, background=self.main_color, highlightthickness=0,
258
+ relief='sunken', height=20, bd=2, padx=10)
259
+ self.Text1.grid(row=27, columnspan=5, pady=20, padx=20)
260
+ self.sfr._avoid_mousewheel(
261
+ (self.Text1, self.CS1, self.CS2, self.CS3, self.CS4))
262
+ self.change_button_style()
263
+ self.update_idletasks()
264
+
265
+ def change_active_color(self, num):
266
+ hexcode = askcolor()[1]
267
+ if num == 1:
268
+ self.Om1_b['bg'] = self.Om1_b['text'] = hexcode
269
+ self.Om1_b['fg'] = check_light_dark(hexcode)
270
+ else:
271
+ self.Om2_b['bg'] = self.Om2_b['text'] = hexcode
272
+ self.Om2_b['fg'] = check_light_dark(hexcode)
273
+ self.B1['activebackground'] = (self.Om1_b['bg'], self.Om2_b['bg'])
274
+
275
+ def change_borderless_state(self):
276
+ if self.var1.get():
277
+ self.B5['borderless'] = 1
278
+ self.B6['borderless'] = 1
279
+ else:
280
+ self.B5['borderless'] = 0
281
+ self.B6['borderless'] = 0
282
+
283
+ def change_button_style(self):
284
+ cnf = dict(
285
+ foreground=get_random_colors(),
286
+ background=get_random_colors(),
287
+ activebackground=get_random_colors(2),
288
+ activeforeground=get_random_colors(),
289
+ overrelief=get_random_relief(),
290
+ relief=get_random_relief(),
291
+ highlightthickness=get_random_size(1, 1, 5),
292
+ borderwidth=get_random_size(1, 1, 5),
293
+ font=get_random_font(),
294
+ highlightbackground=get_random_colors(),
295
+ focuscolor=get_random_colors(),
296
+ overbackground=get_random_colors(),
297
+ overforeground=get_random_colors(),
298
+ )
299
+ self.B10.config(**cnf)
300
+
301
+ self.Text1.insert('end', '\n\nBUTTON STYLE %s\n\n' %
302
+ self.button_clicks)
303
+ for k, v in cnf.items():
304
+ if k == 'font':
305
+ self.Text1.insert('end', 'font:\n')
306
+ for i, j in v.config().items():
307
+ self.Text1.insert('end', '\t%s\t\t= %s\n' % (i, j))
308
+ else:
309
+ self.Text1.insert('end', '%s\t\t\t= %s\n' % (k, v))
310
+ self.Text1.see('end')
311
+ self.Text1.insert('end', '\n\n'+'-'*40)
312
+ self.button_clicks += 1
313
+ self.sfr['canvas'].yview_moveto('1.0')
314
+ self.update_idletasks()
315
+
316
+
317
+ def main():
318
+ "Demonstration of tkmacos."
319
+ Sample().mainloop()
320
+
321
+
322
+ # Testing Demo
323
+ if __name__ == "__main__":
324
+ main()
@@ -0,0 +1,20 @@
1
+ # Modified by the tkmacos fork; see NOTICE for details.
2
+ # Copyright 2021 Saad Mairaj
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ from tkmacos.basewidgets.button_base import ButtonBase
17
+ from tkmacos.basewidgets.colorscale_base import ColorscaleBase
18
+ from tkmacos.basewidgets.marquee_base import MarqueeBase
19
+ from tkmacos.basewidgets.radiobutton_base import RadiobuttonBase
20
+ from tkmacos.basewidgets.sframe_base import SFrameBase