tkgraphicsview 1.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.
@@ -0,0 +1,141 @@
1
+ import tkinter as tk
2
+ from ._tkgraphicsview import *
3
+ from .colors import colors
4
+
5
+ _initialized = False
6
+
7
+ TOP = 1
8
+ BOTTOM = 2
9
+ LEFT = 3
10
+ RIGHT = 4
11
+ CENTER = 5
12
+
13
+ def _str2intcolor(strcolor: str) -> int:
14
+ if not isinstance(strcolor, str):
15
+ raise ValueError(f'Invalid color: `{strcolor}`, color must be a string')
16
+ if (color := colors.get(strcolor)) is not None:
17
+ return color
18
+ if len(strcolor) != 7 or strcolor[0] != '#':
19
+ raise ValueError(f'Invalid color: `{strcolor}`')
20
+ intcolor = int(strcolor[1:], base=16)
21
+ b = intcolor & 0xff
22
+ g = (intcolor >> 8) & 0xff
23
+ r = (intcolor >> 16) & 0xff
24
+ return (((b << 8) | g) << 8) | r
25
+
26
+ class TkGraphicsView(tk.Label):
27
+ def __init__(self, master, width, height):
28
+ global _initialized
29
+ if not _initialized:
30
+ Setup(master.interpaddr())
31
+ _initialized = True
32
+
33
+ self.width = width
34
+ self.height = height
35
+ self._image = tk.PhotoImage(width=width, height=height)
36
+ values = CreateGraphicsView(str(self._image), width, height)
37
+ self._tgvaddr = values[0]
38
+ self.fontheight = values[1]
39
+ super().__init__(master, image=self._image, bg='white', bd=0,
40
+ highlightthickness=0)
41
+
42
+ self.brushcolor = '#ffffff'
43
+ self._brushcolor = 0xffffff
44
+ self.pencolor = '#000000'
45
+ self._pencolor = 0x000000
46
+ self.textcolor = '#000000'
47
+ self._textcolor = 0x000000
48
+ self.penwidth = 1
49
+ self.fontfamily = 'Segoe UI'
50
+ self.fontsize = 12
51
+
52
+ self.drawrectangle(-1, -1, width+2, height+2)
53
+ self.flush()
54
+
55
+ def flush(self):
56
+ Flush(self._tgvaddr)
57
+
58
+ def measuretext(self, text: str):
59
+ return GetTextWidth(self._tgvaddr, text)
60
+
61
+ def drawrectangle(self, x: int, y: int, width: int, height: int):
62
+ DrawRectangle(self._tgvaddr, x, y, width, height)
63
+
64
+ def drawellipse(self, x: int, y: int, width: int, height: int):
65
+ DrawEllipse(self._tgvaddr, x, y, width, height)
66
+
67
+ def drawtext(self, x: int, y: int, text: str, vanchor: int = LEFT, hanchor: int = TOP):
68
+ if vanchor == LEFT and hanchor == TOP:
69
+ DrawText(self._tgvaddr, x, y, text)
70
+ return
71
+
72
+ drawx = x
73
+ drawy = y
74
+
75
+ if vanchor != LEFT:
76
+ textwidth = self.measuretext(text)
77
+ if vanchor == CENTER:
78
+ drawx -= textwidth // 2
79
+ elif vanchor == RIGHT:
80
+ drawx -= textwidth
81
+ else:
82
+ raise ValueError(f'`vanchor` value can only be: LEFT, RIGHT or CENTER')
83
+
84
+ if hanchor != TOP:
85
+ if hanchor == CENTER:
86
+ drawy -= self.fontheight // 2
87
+ elif hanchor == BOTTOM:
88
+ drawy -= self.fontheight
89
+ else:
90
+ raise ValueError(f'`hanchor` value can only be: TOP, BOTTOM or CENTER')
91
+
92
+ DrawText(self._tgvaddr, drawx, drawy, text)
93
+
94
+ def configure(self, brushcolor: str = None, pencolor: str = None,
95
+ penwidth: int = None, textcolor: str = None,
96
+ fontfamily: str = None, fontsize: int = None):
97
+ fontupdate = False
98
+ if brushcolor is not None:
99
+ self._brushcolor = _str2intcolor(brushcolor)
100
+ self.brushcolor = brushcolor
101
+ SetBrush(self._tgvaddr, self._brushcolor)
102
+ if self.penwidth == 0:
103
+ SetPen(self._tgvaddr, 0, self._brushcolor)
104
+
105
+ if pencolor is not None:
106
+ self._pencolor = _str2intcolor(pencolor)
107
+ self.pencolor = pencolor
108
+ if self.penwidth != 0:
109
+ SetPen(self._tgvaddr, self.penwidth, self._pencolor)
110
+
111
+ if textcolor is not None:
112
+ self._textcolor = _str2intcolor(textcolor)
113
+ self.textcolor = textcolor
114
+ SetTextOptions(self._tgvaddr, "", 0, self._textcolor, STO_COLOR)
115
+
116
+ if penwidth is not None:
117
+ if penwidth < 0:
118
+ raise ValueError('penwidth should be a whole number')
119
+ self.penwidth = penwidth
120
+ pencolor = self._pencolor
121
+ if self.penwidth == 0:
122
+ pencolor = self._brushcolor
123
+ SetPen(self._tgvaddr, self.penwidth, pencolor)
124
+
125
+ if fontfamily is not None:
126
+ self.fontfamily = fontfamily
127
+ fontupdate = True
128
+
129
+ if fontsize is not None:
130
+ self.fontsize = fontsize
131
+ fontupdate = True
132
+
133
+ if fontupdate:
134
+ self.fontheight = SetTextOptions(
135
+ self._tgvaddr,
136
+ self.fontfamily,
137
+ self.fontsize,
138
+ 0,
139
+ STO_FONT | STO_COLOR
140
+ )
141
+
Binary file
@@ -0,0 +1,291 @@
1
+ colors = {
2
+ 'white': 0xffffff,
3
+ 'black': 0x000000,
4
+
5
+ 'red': 3550459,
6
+ 'red50': 15921918,
7
+ 'red100': 14869247,
8
+ 'red200': 13224447,
9
+ 'red300': 10658559,
10
+ 'red400': 6776063,
11
+ 'red500': 3550459,
12
+ 'red600': 721127,
13
+ 'red700': 458945,
14
+ 'red800': 1181599,
15
+ 'red900': 1710210,
16
+ 'red950': 591942,
17
+
18
+ 'orange': 27135,
19
+ 'orange50': 15595519,
20
+ 'orange100': 13954559,
21
+ 'orange200': 10999551,
22
+ 'orange300': 6994175,
23
+ 'orange400': 297471,
24
+ 'orange500': 27135,
25
+ 'orange600': 18933,
26
+ 'orange700': 13770,
27
+ 'orange800': 11679,
28
+ 'orange900': 797310,
29
+ 'orange950': 398148,
30
+
31
+ 'amber': 39678,
32
+ 'amber50': 15465471,
33
+ 'amber100': 13038590,
34
+ 'amber200': 8775422,
35
+ 'amber300': 3199743,
36
+ 'amber400': 47615,
37
+ 'amber500': 39678,
38
+ 'amber600': 29153,
39
+ 'amber700': 19899,
40
+ 'amber800': 15511,
41
+ 'amber900': 406395,
42
+ 'amber950': 72006,
43
+
44
+ 'yellow': 45552,
45
+ 'yellow50': 15269118,
46
+ 'yellow100': 12777982,
47
+ 'yellow200': 8777983,
48
+ 'yellow300': 2154495,
49
+ 'yellow400': 51197,
50
+ 'yellow500': 45552,
51
+ 'yellow600': 34768,
52
+ 'yellow700': 24486,
53
+ 'yellow800': 19337,
54
+ 'yellow900': 671347,
55
+ 'yellow950': 270403,
56
+
57
+ 'lime': 53116,
58
+ 'lime50': 15204087,
59
+ 'lime100': 13303020,
60
+ 'lime200': 10090968,
61
+ 'lime300': 5371067,
62
+ 'lime400': 59034,
63
+ 'lime500': 53116,
64
+ 'lime600': 42334,
65
+ 'lime700': 32073,
66
+ 'lime800': 25404,
67
+ 'lime900': 938805,
68
+ 'lime950': 208409,
69
+
70
+ 'green': 5294336,
71
+ 'green50': 16055792,
72
+ 'green100': 15203548,
73
+ 'green200': 13629625,
74
+ 'green300': 11071867,
75
+ 'green400': 7528197,
76
+ 'green500': 5294336,
77
+ 'green600': 4105728,
78
+ 'green700': 3572224,
79
+ 'green800': 3171841,
80
+ 'green900': 2839565,
81
+ 'green950': 1388035,
82
+
83
+ 'emerald': 8240128,
84
+ 'emerald50': 16121324,
85
+ 'emerald100': 15071952,
86
+ 'emerald200': 13628580,
87
+ 'emerald300': 11921758,
88
+ 'emerald400': 9622528,
89
+ 'emerald500': 8240128,
90
+ 'emerald600': 6723840,
91
+ 'emerald700': 5601792,
92
+ 'emerald800': 4546560,
93
+ 'emerald900': 3886848,
94
+ 'emerald950': 2239488,
95
+
96
+ 'teal': 10992384,
97
+ 'teal50': 16449008,
98
+ 'teal100': 15858635,
99
+ 'teal200': 15005590,
100
+ 'teal300': 14019654,
101
+ 'teal400': 12506368,
102
+ 'teal500': 10992384,
103
+ 'teal600': 9016832,
104
+ 'teal700': 7305216,
105
+ 'teal800': 5922560,
106
+ 'teal900': 4869899,
107
+ 'teal950': 3026690,
108
+
109
+ 'cyan': 14399488,
110
+ 'cyan50': 16776940,
111
+ 'cyan100': 16710350,
112
+ 'cyan200': 16643234,
113
+ 'cyan300': 16640595,
114
+ 'cyan400': 15913728,
115
+ 'cyan500': 14399488,
116
+ 'cyan600': 12096000,
117
+ 'cyan700': 9794816,
118
+ 'cyan800': 7888640,
119
+ 'cyan900': 6573584,
120
+ 'cyan950': 4535045,
121
+
122
+ 'sky': 16033280,
123
+ 'sky50': 16775664,
124
+ 'sky100': 16708319,
125
+ 'sky200': 16705208,
126
+ 'sky300': 16766068,
127
+ 'sky400': 16759808,
128
+ 'sky500': 16033280,
129
+ 'sky600': 13730816,
130
+ 'sky700': 11036928,
131
+ 'sky800': 9066752,
132
+ 'sky900': 7358978,
133
+ 'sky950': 4861701,
134
+
135
+ 'blue': 16744235,
136
+ 'blue50': 16774895,
137
+ 'blue100': 16706267,
138
+ 'blue200': 16767934,
139
+ 'blue300': 16762254,
140
+ 'blue400': 16753233,
141
+ 'blue500': 16744235,
142
+ 'blue600': 16538901,
143
+ 'blue700': 15091476,
144
+ 'blue800': 12074009,
145
+ 'blue900': 9320732,
146
+ 'blue950': 5645334,
147
+
148
+ 'indigo': 16736097,
149
+ 'indigo50': 16773870,
150
+ 'indigo100': 16771040,
151
+ 'indigo200': 16765638,
152
+ 'indigo300': 16757667,
153
+ 'indigo400': 16746108,
154
+ 'indigo500': 16736097,
155
+ 'indigo600': 16136527,
156
+ 'indigo700': 14101827,
157
+ 'indigo800': 11282999,
158
+ 'indigo900': 8727601,
159
+ 'indigo950': 5052958,
160
+
161
+ 'violet': 16732558,
162
+ 'violet50': 16774133,
163
+ 'violet100': 16706029,
164
+ 'violet200': 16766685,
165
+ 'violet300': 16757956,
166
+ 'violet400': 16745638,
167
+ 'violet500': 16732558,
168
+ 'violet600': 16654975,
169
+ 'violet700': 15140976,
170
+ 'violet800': 12586589,
171
+ 'violet900': 10098509,
172
+ 'violet950': 6819119,
173
+
174
+ 'purple': 16729773,
175
+ 'purple50': 16774650,
176
+ 'purple100': 16771315,
177
+ 'purple200': 16766185,
178
+ 'purple300': 16757466,
179
+ 'purple400': 16743106,
180
+ 'purple500': 16729773,
181
+ 'purple600': 16388248,
182
+ 'purple700': 14352514,
183
+ 'purple800': 11538798,
184
+ 'purple900': 9115225,
185
+ 'purple950': 6685500,
186
+
187
+ 'fuchsia': 16460513,
188
+ 'fuchsia50': 16774397,
189
+ 'fuchsia100': 16771322,
190
+ 'fuchsia200': 16764918,
191
+ 'fuchsia300': 16754932,
192
+ 'fuchsia400': 16739053,
193
+ 'fuchsia500': 16460513,
194
+ 'fuchsia600': 14549192,
195
+ 'fuchsia700': 11993256,
196
+ 'fuchsia800': 9699722,
197
+ 'fuchsia900': 7869298,
198
+ 'fuchsia950': 5177419,
199
+
200
+ 'pink': 10105846,
201
+ 'pink50': 16315133,
202
+ 'pink100': 15984636,
203
+ 'pink200': 15257340,
204
+ 'pink300': 14001661,
205
+ 'pink400': 11953403,
206
+ 'pink500': 10105846,
207
+ 'pink600': 7733478,
208
+ 'pink700': 6029510,
209
+ 'pink800': 4980899,
210
+ 'pink900': 4395142,
211
+ 'pink950': 2360401,
212
+
213
+ 'rose': 5644543,
214
+ 'rose50': 15921663,
215
+ 'rose100': 15131903,
216
+ 'rose200': 13880575,
217
+ 'rose300': 11379199,
218
+ 'rose400': 8283135,
219
+ 'rose500': 5644543,
220
+ 'rose600': 4129004,
221
+ 'rose700': 3539143,
222
+ 'rose800': 3539109,
223
+ 'rose900': 3541131,
224
+ 'rose950': 1573453,
225
+
226
+ 'stone': 7041401,
227
+ 'stone50': 16382714,
228
+ 'stone100': 16053749,
229
+ 'stone200': 15001063,
230
+ 'stone300': 13751254,
231
+ 'stone400': 10199206,
232
+ 'stone500': 7041401,
233
+ 'stone600': 5067607,
234
+ 'stone700': 3883076,
235
+ 'stone800': 2368809,
236
+ 'stone900': 1513756,
237
+ 'stone950': 592396,
238
+
239
+ 'neutral': 7566195,
240
+ 'neutral50': 16448250,
241
+ 'neutral100': 16119285,
242
+ 'neutral200': 15066597,
243
+ 'neutral300': 13948116,
244
+ 'neutral400': 10592673,
245
+ 'neutral500': 7566195,
246
+ 'neutral600': 5395026,
247
+ 'neutral700': 4210752,
248
+ 'neutral800': 2500134,
249
+ 'neutral900': 1513239,
250
+ 'neutral950': 657930,
251
+
252
+ 'zinc': 8089969,
253
+ 'zinc50': 16448250,
254
+ 'zinc100': 16119028,
255
+ 'zinc200': 15197412,
256
+ 'zinc300': 14210260,
257
+ 'zinc400': 11116447,
258
+ 'zinc500': 8089969,
259
+ 'zinc600': 6050386,
260
+ 'zinc700': 4603711,
261
+ 'zinc800': 2762535,
262
+ 'zinc900': 1775640,
263
+ 'zinc950': 723209,
264
+
265
+ 'gray': 8548970,
266
+ 'gray50': 16513785,
267
+ 'gray100': 16184563,
268
+ 'gray200': 15460325,
269
+ 'gray300': 14472657,
270
+ 'gray400': 11510169,
271
+ 'gray500': 8548970,
272
+ 'gray600': 6640970,
273
+ 'gray700': 5456182,
274
+ 'gray800': 3746078,
275
+ 'gray900': 2627600,
276
+ 'gray950': 1181443,
277
+
278
+ 'slate': 9335906,
279
+ 'slate50': 16579320,
280
+ 'slate100': 16381425,
281
+ 'slate200': 15788258,
282
+ 'slate300': 14865866,
283
+ 'slate400': 12165520,
284
+ 'slate500': 9335906,
285
+ 'slate600': 7099717,
286
+ 'slate700': 5783857,
287
+ 'slate800': 4008221,
288
+ 'slate900': 2823951,
289
+ 'slate950': 1574402,
290
+
291
+ }
@@ -0,0 +1,3 @@
1
+ Metadata-Version: 2.4
2
+ Name: tkgraphicsview
3
+ Version: 1.0.0
@@ -0,0 +1,7 @@
1
+ tkgraphicsview/__init__.py,sha256=d2p1SOH1aIJiUOO_dM7OjVe8IuL1Evizt0md8XD-yhM,4869
2
+ tkgraphicsview/_tkgraphicsview.pyd,sha256=xmQIKTC21OyFIBXorunBKOormC5-09VWmb-QKBXNsUI,104448
3
+ tkgraphicsview/colors.py,sha256=QrLKXLL3bLjpcFQWJlo_LXPtWc5v93iC7ydlPRParn0,7212
4
+ tkgraphicsview-1.0.0.dist-info/METADATA,sha256=8qv-sGdX88hSzGKB13DN-BJux2vy0tukm7e_uqPYYXk,61
5
+ tkgraphicsview-1.0.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
6
+ tkgraphicsview-1.0.0.dist-info/top_level.txt,sha256=zLhJsO_2PhxiNUM5yn10MfzctHhGuawT68YWWeEEcr0,15
7
+ tkgraphicsview-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ tkgraphicsview