-
Notifications
You must be signed in to change notification settings - Fork 0
/
hybridnotepad.py
1577 lines (1331 loc) · 68.3 KB
/
hybridnotepad.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from tkinter import *
from tkinter.ttk import *
import tkinter.font as font
from tkinter.filedialog import *
from math import *
import PIL.Image as Image
import PIL.ImageTk as ImageTk
import PIL.ImageGrab as ImageGrab
from PIL import ImageTk, Image
from sys import argv
import os
import sys
import speech_recognition as sr
import pyttsx3
from win32 import win32api
from pyautogui import *
import gtts
from playsound import playsound
# GOTO
GotoTextBox = 0 # here , we have A vala option for text
GotoFont = 0 # here, we have , font style ,
GotoMenuFile = 0 # here we have Menu bars, File handling , aboutus
GotoTextEditor = 0 # here we have font styles , Italic, bold etc and design vala font , infact it is 3rd row
GotoItems = 0 # it contain , all the general items , pencil , rubber etc
GotoBrushes = 0 # it contain brushes
GotoColorBox = 0 # color box
GotoOutline = 0 # outline and fill option
GotoShapes = 0 # shapes
GotoMoreColors = 0
""" Created By Ayush Bisht
Date of completion : 10 june 2020
"""
def resource_path(relative_path):
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath("."), relative_path)
# Main window ............
win = Tk()
win.title("INDIpaint")
win.geometry("1000x600")
# ...............................
# Global variables ...............................................
outLinevar = 'black'
fillvar = ''
X, Y, z, sx, sy, cs, choosebox, zsize = 0, 0, 0, 0, 0, 1, 1, 0
dsp = [20, 30, 50, 60]
all_width = [1, 30, 30]
se = [0, 0, 0, 0]
dColor, Color1, Color2 = "#000000", "#000000", "#ffffff"
text = Text()
dataFromNotePad = ""
x0, y0, w, h = 0, 0, 0, 0
textIndex = -1
TextInPaint = ""
option = "paint"
CursorSet = "arrow"
# ......................................................................
# https://pythonexamples.org/python-tkinter-button-change-font/#:~:text=You%20can%20also%20change%20font,font%20size%20of%20tkinter%20button.
mfont = font.Font(size="15", family='Courier', weight='bold')
win['padx'] = 30
win["bg"] = "black"
win.columnconfigure(0, weight=200)
win.rowconfigure(0, weight=1)
win.rowconfigure(1, weight=0)
win.rowconfigure(2, weight=450)
optionLabel = LabelFrame(win, width='500', height='200', bg="white")
optionLabel.grid(row=0, sticky='nsew', padx=12, pady=2)
textLabel = LabelFrame(win, width='500', height=20, bg="white")
textLabel.grid(row=1, column=0, sticky='nsew', padx=10, pady=2)
contentLabel = Canvas(win, width="500", height="150", highlightthickness=1, highlightbackground="black",
background="white", cursor=CursorSet)
contentLabel.grid(row=2, column=0, sticky='news')
optionLabel.rowconfigure(0, weight=10)
optionLabel.columnconfigure(0, weight=30)
optionLabel.columnconfigure(1, weight=30)
optionLabel.columnconfigure(2, weight=30)
optionLabel.columnconfigure(3, weight=0)
optionLabel.columnconfigure(4, weight=0)
optionLabel.columnconfigure(5, weight=0)
optionLabel.columnconfigure(6, weight=20)
optionLabel.columnconfigure(7, weight=30)
items = LabelFrame(optionLabel, text='Tools', labelanchor='s', takefocus=True, fg="grey")
items.grid(row=0, column=0, sticky='nwes', pady=3, padx=1)
Brushes = LabelFrame(optionLabel, text='Brushes', labelanchor='s', takefocus=True, fg="grey")
Brushes.grid(row=0, column=1, sticky='nwes', padx=1, pady=3)
shapes = LabelFrame(optionLabel, text='Shapes', labelanchor='s', takefocus=True, fg="grey")
shapes.grid(row=0, column=2, sticky='nwes', padx=1, pady=3)
out_fill = LabelFrame(optionLabel, relief="flat")
out_fill.grid(row=0, column=3, sticky="nwes", padx=1, pady=3)
size = LabelFrame(optionLabel, text='Size', labelanchor='s', takefocus=True, fg="grey")
size.grid(row=0, column=4, sticky='nwes', padx=1, pady=3)
colorSelect = LabelFrame(optionLabel, takefocus=True, relief="flat", height=2)
colorSelect.grid(row=0, column=5, sticky='nwes', padx=1, pady=3)
colorbox = LabelFrame(optionLabel, text='colorbox', labelanchor='s', takefocus=True, fg="grey")
colorbox.grid(row=0, column=6, sticky='nwes', padx=1, pady=3)
editColor = LabelFrame(optionLabel, text="edit colors", labelanchor='s', takefocus=True, fg="grey")
editColor.grid(row=0, column=7, sticky='nwes', padx=1, pady=3)
GotoTextBox = 1
# Text Box ..................................................................................................................................
""" endCO is used to get the last coordinate of the rectangle on which we are suppose to insert our text , it basically uses TEXT( ) widget to take the input which is passed off to create_text( )
so as to add text to canvas widget.
"""
def endCO(event):
global se, x0, y0, w
global t, text, dataFromNotePad, textInCanvas
class Struct(object):
pass
data = Struct()
data.win = win
if se[0] < event.x:
x0 = se[0]
else:
x0 = event.x
if se[1] < event.y:
y0 = se[1]
else:
y0 = event.y
w, h = abs(event.x - se[0]), abs(event.y - se[1])
text = Text(contentLabel, width=int(w / 11), height=int(h / 21))
fontText = font.Font(family=fontFamilyVar.get(), size=SizeVar.get(), weight=BoldVar.get(),
slant=ItalicVar.get(), underline=UnderVar.get(), overstrike=OverVar.get())
text.configure(font=fontText, foreground=Color1)
t = contentLabel.create_window(x0, y0, window=text, anchor='nw')
contentLabel.delete(textInCanvasIndexer)
"""
initialCO is used to get the initial coordinate of that rectangle with whose reference we are suppose to add text in our canvas widget
"""
def initialCO(event):
global se, t, textInCanvas, textInCanvasIndexer, textIndex
if textIndex<1000:
textIndex += 1
textInCanvasIndexer = textInCanvas[textIndex]
se[0], se[1] = event.x, event.y
contentLabel.delete(t)
""" Here , that rectangle is created .
"""
def textShape(event):
global se, k
contentLabel.delete(k)
k = contentLabel.create_rectangle(se[0], se[1], event.x, event.y, fill="white", outline="white")
""" here, it clarify wheather you complete you text or not, when completes TextInPaint become "" , and text is added to canvas widget
"""
def selector(s):
global t, text, dataFromNotePad, textInCanvas, se, x0, y0, k, w, h, Color1, fontType, textInCanvasIndexer
global TextInPaint
TextInPaint = s
fontText = font.Font(family=fontFamilyVar.get(), size=SizeVar.get(), weight=BoldVar.get(),
slant=ItalicVar.get(), underline=UnderVar.get(), overstrike=OverVar.get())
if TextInPaint == "text":
contentLabel.bind("<ButtonRelease-1>", endCO)
contentLabel.bind("<Button-1>", initialCO)
contentLabel.bind("<B1-Motion>", textShape)
else:
dataFromNotePad = text.get(1.0, END)
textInCanvasIndexer = contentLabel.create_text(x0, y0, text=dataFromNotePad, font=fontText, width=w,
anchor='nw', fill=Color1)
contentLabel.delete(t)
contentLabel.delete(k)
""" here , event is bind to mouse , so that when you press mouse right button then text is added to you canvas widget
"""
def TextChange(event):
global TextInPaint, polyy1, polyx1, choosebox
if z==4:
selector("")
TextInPaint = ""
polyx1, polyy1 = 0, 0
choosebox = 1
k = contentLabel.create_rectangle(0, 0, 0, 0)
textInCanvas = [contentLabel.create_text(0, 0)] * 1000
textInCanvasIndexer = textInCanvas[0]
t = contentLabel.create_window(0, 0)
# .................................................................................................................................................................
GotoFont = 1
# Font Size and Style ........................................................................
SizeVar = IntVar()
SizeVar.set(15)
fontFamilyVar = StringVar()
fontFamilyVar.set("Arial")
""" It set the font size for our text editor feature
"""
def getSizeofFont():
SizeVar.set(textButtonS.get())
fontText = font.Font(family=fontFamilyVar.get(), size=SizeVar.get(), weight=BoldVar.get(),
slant=ItalicVar.get(), underline=UnderVar.get(), overstrike=OverVar.get())
text.configure(font=fontText, foreground=Color1)
Notepad.configure(font=fontText, foreground=Color1)
""" It set the font family for our text editor feature
"""
def fontFamilyFun():
global fontFamilyVar
fontSt = vb.get()
fontText = font.Font(family=fontFamilyVar.get(), size=SizeVar.get(), weight=BoldVar.get(),
slant=ItalicVar.get(), underline=UnderVar.get(), overstrike=OverVar.get())
fontFamilyVar.set(lis[fontSt])
fontText = font.Font(family=fontFamilyVar.get(), size=SizeVar.get(), weight=BoldVar.get(),
slant=ItalicVar.get(), underline=UnderVar.get(), overstrike=OverVar.get())
text.configure(font=fontText, foreground=Color1)
Notepad.configure(font=fontText, foreground=Color1)
fontFamily["font"] = (fontFamilyVar.get, 10)
# ............................................................................................
GotoMenuFile = 1
# Menu Bar and File Handling .............................................................................
Notepad = Text()
notepadWin = contentLabel.create_window(0, 0)
notePadData = StringVar()
FileSave = None
ScreenShotSave = None
imgt = [None] * 100
imageIndex = 0
""" paintfile : This one is the main component of this program, as it did all the stuffs like opeing new file , saving , printing etc
"""
def paintfile(s):
global ScreenShotSave, imgCanvas, imgt, imageIndex,ir, ic, it, iet, irt, ih1, ih2
xind = win.winfo_rootx() + contentLabel.winfo_x()
yind = win.winfo_rooty() + contentLabel.winfo_y()
xx = xind + contentLabel.winfo_width()
yy = yind + contentLabel.winfo_height()
if s == "save":
if ScreenShotSave == None:
ScreenShotSave = asksaveasfilename(initialfile='Untitled.png',
defaultextension=".png",
filetypes=[("All Files", "*.*"),
("png", "*.png"), ("jpg", "*.jpg"), ("gif", "*.gif")])
if ScreenShotSave == "":
ScreenShotSave = None
ImageGrab.grab(bbox=(xind, yind, xx, yy)).save(ScreenShotSave)
elif s == "save_as":
ScreenShotSave = asksaveasfilename(initialfile='Untitled.png',
defaultextension=".png",
filetypes=[("All Files", "*.*"),
("png", "*.png"), ("jpg", "*.jpg"), ("gif", "*.gif")])
ImageGrab.grab(bbox=(xind, yind, xx, yy)).save(ScreenShotSave)
elif s == "new":
ir, ic, it, iet, irt, ih1, ih2 = -1, -1, -1, -1, -1, -1, -1
contentLabel.delete(ALL)
elif s == "open":
openImageFile = askopenfilename(defaultextension=".png",
filetypes=[("All Files", "*.*"),
("png", "*.png"), ("jpg", "*.jpg"), ("gif", "*.gif")])
# PIL(python imaging library) is used to work 30 more image formats
# http://effbot.org/tkinterbook/photoimage.htm
resource_path(openImageFile)
imgResize = Image.open(openImageFile)
imgResize = imgResize.resize((xx - xind, yy - yind), Image.ANTIALIAS)
imgt[imageIndex] = ImageTk.PhotoImage(imgResize)
contentLabel.create_image(0, 0, image=imgt[imageIndex], anchor=NW)
imageIndex += 1
elif s == "print":
if ScreenShotSave != None:
os.startfile(ScreenShotSave, "print")
elif s == "exit":
# t = askokcancel("Quit", "Do you really wish to quit?")
win.destroy()
# win.destroy()
def Choice(s):
global notePadData, notepadWin, Notepad, FileSave, option
class Struct(object):
pass
option = "text"
Data = Struct()
Data.win = win
if s == "text":
Notepad = Text(contentLabel, width=500, height=500)
fontText = font.Font(family=fontFamilyVar.get(), size=SizeVar.get(), weight=BoldVar.get(),
slant=ItalicVar.get(), underline=UnderVar.get(), overstrike=OverVar.get())
Notepad.configure(font=fontText, foreground=Color1)
notepadWin = contentLabel.create_window(0, 0, window=Notepad, anchor='nw')
elif s == "save":
print(Notepad.index("insert"))
if FileSave == None:
FileSave = asksaveasfilename(initialfile='Untitled.txt',
defaultextension=".txt",
filetypes=[("All Files", "*.*"),
("Text Documents", "*.txt")])
if FileSave == "":
FileSave = None
else:
file = open(FileSave, 'w')
file.write(Notepad.get(1.0, END))
file.close()
else:
file = open(FileSave, 'w')
file.write(Notepad.get(1.0, END))
file.close()
elif s == "save_as":
FileSave = asksaveasfilename(initialfile='Untitled.txt',
defaultextension=".txt",
filetypes=[("All Files", "*.*"),
("Text Documents", "*.txt")])
if FileSave == "":
FileSave = None
else:
file = open(FileSave, 'w')
file.write(Notepad.get(1.0, END))
file.close()
elif s == "new":
Notepad.delete(1.0, END)
elif s == "print":
if FileSave != None:
os.startfile(FileSave, "print")
elif s == "exit":
option = "paint"
contentLabel.delete(notepadWin)
def about_us():
print("about us")
about = Tk()
about.title("ABOUT US")
about.geometry("500x500")
aboutText = Text(about, width=90, height=90, )
aboutText.insert("end",
"\t\t\t About - Us \n\n\n Hello friends this is Ayush Bisht and I am a rising software engineer.Lets discuss few things about this application -- IndiPaint ,whch was"
" developed and designed under the guidance of expert seniors of BTKIT Dwarahat. This application is an open source software , user can modified its code "
" according to their needs and desire. My main aim is to implement our Knowledge and creates something new which could help ohters. Indipaint is an INDIAN software"
" and freely available to all. This project helps the students to learn Python Programming more precisely. This project gonna be a fun for the beginer who are neophyte in this"
" domain , they can easily learn all the major concept of GUI programmming and can create their own projects or their own self made software..."
"\n thank you all\n Project Manager \n Ayush Bisht \n............... Happy Coding ")
fontText = font.Font(family=fontFamilyVar.get(), size=SizeVar.get(), weight=BoldVar.get(),
slant=ItalicVar.get(), underline=UnderVar.get(), overstrike=OverVar.get())
aboutText.configure(font=fontText, foreground=Color1)
aboutText.pack()
about.mainloop()
menuBar = Menu(win)
file = Menu(menuBar, tearoff=0)
menuBar.add_cascade(label='File', menu=file)
file.add_command(label='New', command=lambda: paintfile("new"))
file.add_command(label='Open', command=lambda: paintfile("open"))
file.add_command(label='Save', command=lambda: paintfile("save"))
file.add_command(label='Save as', command=lambda: paintfile("save_as"))
file.add_command(label='Print', command=lambda: paintfile("print"))
file.add_command(label='About Us', command=lambda: about_us())
file.add_command(label='Exit', command=lambda: paintfile("exit"))
home = Menu(menuBar, tearoff=0)
menuBar.add_cascade(label='Home', menu=home)
home.add_command(label="NOTEPAD", command=lambda: Choice('text'))
home.add_command(label='New', command=lambda: Choice('new'))
home.add_command(label='Save', command=lambda: Choice('save'))
home.add_command(label='Save as', command=lambda: Choice('save_as'))
home.add_command(label='Print', command=lambda: Choice('print'))
home.add_command(label='PAINT', command=lambda: Choice('exit'))
# ...........................................................................................
GotoTextEditor = 1
# Text Editor ..........................................................................................................
ItalicVar = StringVar()
BoldVar = StringVar()
UnderVar = BooleanVar()
OverVar = BooleanVar()
ItalicVar.set("roman")
BoldVar.set("normal")
UnderVar.set(False)
OverVar.set(False)
def getTextStyle():
if var1.get():
ItalicVar.set("italic")
else:
ItalicVar.set("roman")
if var2.get():
BoldVar.set("bold")
else:
BoldVar.set("normal")
if var3.get():
UnderVar.set(True)
else:
UnderVar.set(False)
if var4.get():
OverVar.set(True)
else:
OverVar.set(False)
fontText = font.Font(family=fontFamilyVar.get(), size=SizeVar.get(), weight=BoldVar.get(),
slant=ItalicVar.get(), underline=UnderVar.get(), overstrike=OverVar.get())
text.configure(font=fontText, foreground=Color1)
Notepad.configure(font=fontText, foreground=Color1)
textLabel.rowconfigure(0, weight=0)
textLabel.columnconfigure(0, weight=15)
textLabel.columnconfigure(1, weight=17)
textLabel.columnconfigure(2, weight=10)
textLabel.columnconfigure(3, weight=10)
fontFamilyFrame = LabelFrame(textLabel, height=1, foreground="white", background="black")
fontFamilyFrame.grid(row=0, column=0, sticky="news", padx=0)
fontFamily = Menubutton(fontFamilyFrame, textvariable=fontFamilyVar, anchor='n', font=(fontFamilyVar.get(), 10),
foreground="white", background="black")
fontFamily.menu5 = Menu(fontFamily, foreground="white", background="black")
fontFamily["menu"] = fontFamily.menu5
lis = list()
for fonter in font.families():
lis.append(fonter)
vb = IntVar()
vb.set(990)
for i in range(0, len(lis)):
fontFamily.menu5.add_radiobutton(label=lis[i], command=fontFamilyFun, variable=vb, value=i, background="black",
foreground="white")
fontFamily.pack(expand=True, fill=BOTH)
var1, var2, var3, var4 = IntVar(), IntVar(), IntVar(), IntVar()
textStyle = LabelFrame(textLabel, width=10)
textStyle.grid(row=0, column=1, sticky="nws", padx=10)
textButtonI = Checkbutton(textStyle, text="I",
font=font.Font(family="stika heading", size=10, slant="italic", weight="bold"), relief="flat",
width=5, variable=var1, command=getTextStyle, indicatoron=0, foreground="white",
background="black", selectcolor=Color1)
textButtonI.pack(expand=True, fill=BOTH, side=LEFT, padx=10)
textButtonB = Checkbutton(textStyle, text="B", font=font.Font(family="stika heading", size=10, weight="bold"),
relief="flat", width=5, variable=var2, command=getTextStyle, indicatoron=0,
foreground="white", background="black", selectcolor=Color1)
textButtonB.pack(expand=True, side=LEFT, fill=BOTH, padx=10)
textButtonU = Checkbutton(textStyle, text="U",
font=font.Font(family="stika heading", size=10, weight="bold", underline=True), relief="flat",
width=5, variable=var3, command=getTextStyle, indicatoron=0, foreground="white",
background="black", selectcolor=Color1)
textButtonU.pack(expand=True, fill=BOTH, side=LEFT, padx=10)
textButtonO = Checkbutton(textStyle, text="abc",
font=font.Font(family="stika heading", size=10, weight="bold", overstrike=True),
relief="flat", width=5, variable=var4, command=getTextStyle, indicatoron=0,
foreground="white", background="black", selectcolor=Color1)
textButtonO.pack(expand=True, fill=BOTH, side=LEFT, padx=10)
textButtonS = Spinbox(textStyle, width=5, from_=1, to=100, command=getSizeofFont, foreground="white",
background="black", font=font.Font(family="stika heading", size=11, weight="bold"))
textButtonS.pack(expand=True, fill=BOTH, side=LEFT, padx=10)
designsImageList = ["Drectangle.png", "Dcircle.png", "Dtria.png", "Dtriangle.png", "Dheart.png", "Dstar.png"]
DesignList = [None] * 6
DesignImageList = [None] * 6
for i in range(0, 6):
resource_path(".img\\"+designsImageList[i])
DesignList[i] = Image.open(".img\\"+designsImageList[i])
DesignList[i] = DesignList[i].resize((60, 60), Image.ANTIALIAS)
DesignImageList[i] = ImageTk.PhotoImage(DesignList[i])
design = LabelFrame(textLabel, width=50, foreground="white", background="black")
design.grid(row=0, column=3, sticky='news')
design_menu = Menubutton(design, text="Designs", anchor='n', foreground="white", background="black")
design_menu.menu = Menu(design_menu, foreground="white", background="black")
design_menu["menu"] = design_menu.menu
design_menu.menu.add_radiobutton(command=lambda: shapesChoose('d1'), image=DesignImageList[0], background="black")
design_menu.menu.add_radiobutton(command=lambda: shapesChoose('d2'), image=DesignImageList[1], background="black")
design_menu.menu.add_radiobutton(command=lambda: shapesChoose('d3'), image=DesignImageList[2], background="black")
design_menu.menu.add_radiobutton(command=lambda: shapesChoose('d4'), image=DesignImageList[3], background="black")
design_menu.menu.add_radiobutton(command=lambda: shapesChoose('d5'), image=DesignImageList[4], background="black")
design_menu.menu.add_radiobutton(command=lambda: shapesChoose('d6'), image=DesignImageList[5], background="black")
design_menu.pack(expand=True, fill=BOTH)
# ....................................................................................................................
GotoItems = 1
# Items for Paint ...............................................
def paint(event):
x2 = 0
y2 = 0
global X, Y, z, dColor, Color2, Color1, all_width, polyx1, polyy1, zindex, CursorSet
polyx1, polyy1 = 0, 0
if event.state == 1032:
dColor = Color2
else:
dColor = Color1
if X == 0 and Y == 0:
x1, y1 = (event.x), (event.y)
x2, y2 = (event.x + 1), (event.y + 1)
else:
x1, y1 = X, Y
x2, y2 = (event.x), (event.y)
X = x2
Y = y2
if z == 0:
if all_width[z] <= 4:
contentLabel.create_line(x1, y1, x2, y2, fill=dColor)
else:
contentLabel.create_rectangle(x1, y1, x2, y2, fill=dColor, width=all_width[zsize], outline=dColor)
elif z == 1:
contentLabel.create_oval(x1, y1, x2 - 0.5, y2 + 1, fill=dColor, outline=dColor, width=3)
elif z == 2:
contentLabel.create_rectangle(x1, y1, x2 - 1, y2 + 1, fill="white", outline="white", width=all_width[zsize])
def reset(event):
global X, Y
X = 0
Y = 0
def items_f(p):
global choosebox, polyx1, polyy1
global z, TextInPaint
if p == 4:
TextInPaint = "text"
selector("text")
z=p
else:
TextInPaint = ""
polyx1, polyy1 = 0, 0
choosebox = 1
z = p
contentLabel.bind("<ButtonRelease-1>", reset)
contentLabel.bind("<B1-Motion>", paint)
contentLabel.bind("<ButtonRelease-3>", reset)
contentLabel.bind("<B3-Motion>", paint)
items.rowconfigure(0, weight=1)
items.rowconfigure(1, weight=1)
items.columnconfigure(0, weight=1)
items.columnconfigure(1, weight=1)
items.columnconfigure(2, weight=1)
resource_path(".img\\pencil.png")
pencilIMG = Image.open(".img\\pencil.png")
pencilIMG = pencilIMG.resize((20, 20), Image.ANTIALIAS)
PencilImg = ImageTk.PhotoImage(pencilIMG)
resource_path(".img\\pen.png")
penIMG = Image.open(".img\\pen.png")
penIMG = penIMG.resize((20, 20), Image.ANTIALIAS)
PenImg = ImageTk.PhotoImage(penIMG)
resource_path(".img\\abc.png")
textIMG = Image.open(".img\\abc.png")
textIMG = textIMG.resize((20, 20), Image.ANTIALIAS)
TextImg = ImageTk.PhotoImage(textIMG)
resource_path(".img\\eraser.png")
eraserIMG = Image.open(".img\\eraser.png")
eraserIMG = eraserIMG.resize((20, 20), Image.ANTIALIAS)
EraserImg = ImageTk.PhotoImage(eraserIMG)
resource_path(".img\\fill.png")
fillIMG = Image.open(".img\\fill.png")
fillIMG = fillIMG.resize((20, 20), Image.ANTIALIAS)
FillImg = ImageTk.PhotoImage(fillIMG)
resource_path(".img\\search.png")
zoomIMG = Image.open(".img\\search.png")
zoomIMG = zoomIMG.resize((20, 20), Image.ANTIALIAS)
ZoomImg = ImageTk.PhotoImage(zoomIMG)
pencil = Button(items, command=lambda: items_f(0), width=35, image=PencilImg, compound=CENTER, relief="flat")
pencil.grid(row=0, column=0, )
pen = Button(items, command=lambda: items_f(1), width=35, image=PenImg, compound=CENTER, relief="flat")
pen.grid(row=0, column=1)
eraser = Button(items, command=lambda: items_f(2), width=35, image=EraserImg, compound=CENTER, relief="flat")
eraser.grid(row=1, column=0)
colorpicker = Button(items, command=lambda: items_f(3), width=35, image=FillImg, compound=CENTER, relief="flat")
colorpicker.grid(row=1, column=1)
TEXT = Button(items, command=lambda: items_f(4), width=35, image=TextImg, compound=CENTER, relief="flat")
TEXT.grid(row=0, column=2)
zoom = Button(items, command=lambda: items_f(5), width=35, image=ZoomImg, compound=CENTER, relief="flat")
zoom.grid(row=1, column=2)
GotoBrushes = 1
# Brushes ..........................................................................................
brushType = 0
def paintBrush(event):
global brushType, polyx1, polyy1, X, Y, fillvar,tcolor
x, y = event.x, event.y
polyx1, polyy1 = 0, 0
tcolor = "black"
if fillvar == '' and outLinevar == '':
tcolor = "black"
else:
tcolor = fillvar
if event.state == 1032:
dColor = Color2
else:
dColor = Color1
if X == 0 and Y == 0:
x1, y1 = (event.x), (event.y)
x2, y2 = (event.x + 1), (event.y + 1)
else:
x1, y1 = X, Y
x2, y2 = (event.x), (event.y)
X = x2
Y = y2
if brushType == 0:
contentLabel.create_oval(x1, y1, x2 - 1, y2 + 1, fill=dColor, outline=dColor, width=all_width[zsize] + 10)
elif brushType == 1:
contentLabel.create_text(x, y, text=".", fill=dColor)
contentLabel.create_text(x + 10, y + 10, text=".", fill=dColor)
contentLabel.create_text(x + 10, y, text=".", fill=dColor)
contentLabel.create_text(x, y + 10, text=".", fill=dColor)
contentLabel.create_text(x - 10, y - 10, text=".", fill=dColor)
contentLabel.create_text(x, y - 10, text=".", fill=dColor)
contentLabel.create_text(x - 10, y, text=".", fill=dColor)
contentLabel.create_text(x + 10, y - 10, text=".", fill=dColor)
contentLabel.create_text(x - 10, y + 10, text=".", fill=dColor)
contentLabel.create_text(x - 13, y, text=".", fill=dColor)
contentLabel.create_text(x + 13, y - 14, text=".", fill=dColor)
contentLabel.create_text(x - 16, y + 14, text=".", fill=dColor)
contentLabel.create_text(x - 6, y, text=".", fill=dColor)
contentLabel.create_text(x + 12, y - 10, text=".", fill=dColor)
contentLabel.create_text(x - 4, y + 1, text=".", fill=dColor)
contentLabel.create_text(x - 7, y + 5, text=".", fill=dColor)
contentLabel.create_text(x + 1, y - 14, text=".", fill=dColor)
contentLabel.create_text(x - 6, y + 14, text=".", fill=dColor)
contentLabel.after(40)
elif brushType == 2:
contentLabel.create_rectangle(x1, y1, x2 - 1, y2 + 1, fill=dColor, outline=dColor, width=all_width[zsize] + 20)
elif brushType == 3:
contentLabel.create_rectangle(x1, y1, x2 - 1, y2 + 1, fill=Color1, outline=Color1, width=all_width[zsize])
contentLabel.create_rectangle(x1, y1 + 2, x2 - 1, y2 + 3, fill=Color2, outline=Color2, width=all_width[zsize])
contentLabel.create_rectangle(x1, y1 + 4, x2 - 1, y2 + 5, fill=Color1, outline=Color1, width=all_width[zsize])
contentLabel.create_rectangle(x1, y1 + 6, x2 - 1, y2 + 7, fill=Color2, outline=Color2, width=all_width[zsize])
contentLabel.create_rectangle(x1, y1 + 8, x2 - 1, y2 + 9, fill=Color1, outline=Color1, width=all_width[zsize])
contentLabel.create_rectangle(x1, y1 + 10, x2 - 1, y2 + 11, fill=Color2, outline=Color2, width=all_width[zsize])
def brush_f(s):
global brushType, TextInPaint
TextInPaint = ""
brushType = s
contentLabel.bind("<ButtonRelease-1>", reset)
contentLabel.bind("<B1-Motion>", paintBrush)
contentLabel.bind("<ButtonRelease-3>", reset)
contentLabel.bind("<B3-Motion>", paintBrush)
def size_f(c):
global all_width, zsize
all_width[zsize] = c
resource_path(".img\\brush.png")
MainIMG = Image.open(".img\\brush.png")
MainIMG = MainIMG.resize((50, 50), Image.ANTIALIAS)
MainImg = ImageTk.PhotoImage(MainIMG)
resource_path(".img\\brush1.png")
brush1IMG = Image.open(".img\\brush1.png")
brush1IMG = brush1IMG.resize((20, 20), Image.ANTIALIAS)
Brush1Img = ImageTk.PhotoImage(brush1IMG)
resource_path(".img\\brush2.png")
brush2IMG = Image.open(".img\\brush2.png")
brush2IMG = brush2IMG.resize((20, 20), Image.ANTIALIAS)
Brush2Img = ImageTk.PhotoImage(brush2IMG)
resource_path(".img\\brush3.png")
brush3IMG = Image.open(".img\\brush3.png")
brush3IMG = brush3IMG.resize((20, 20), Image.ANTIALIAS)
Brush3Img = ImageTk.PhotoImage(brush3IMG)
resource_path(".img\\brush4.png")
brush4IMG = Image.open(".img\\brush4.png")
brush4IMG = brush4IMG.resize((20, 20), Image.ANTIALIAS)
Brush4Img = ImageTk.PhotoImage(brush4IMG)
brush_menu = Menubutton(Brushes, anchor='n', image=MainImg, compound=CENTER)
brush_menu.menu = Menu(brush_menu)
brush_menu["menu"] = brush_menu.menu
brush_menu.menu.add_radiobutton(command=lambda: brush_f(0), background="white", image=Brush1Img, compound=LEFT,
label="Small")
brush_menu.menu.add_radiobutton(command=lambda: brush_f(2), background="white", image=Brush2Img, compound=LEFT,
label="Large")
brush_menu.menu.add_radiobutton(command=lambda: brush_f(1), background="white", image=Brush3Img, compound=LEFT,
label="Sprayer")
brush_menu.menu.add_radiobutton(command=lambda: brush_f(3), background="white", image=Brush4Img, compound=LEFT,
label="Roller")
brush_menu.pack()
resource_path(".img\\size.png")
sizeIMG = Image.open(".img\\size.png")
sizeIMG = sizeIMG.resize((45, 65), Image.ANTIALIAS)
SizeIMG = ImageTk.PhotoImage(sizeIMG)
size_menu = Menubutton(size, anchor='n', image=SizeIMG, compound=CENTER)
size_menu.menu = Menu(size_menu, foreground="white", background="black")
size_menu["menu"] = size_menu.menu
size_menu.menu.add_radiobutton(label="SIZE 1",
command=lambda: size_f(3), background="black", foreground="white",
font=font.Font(family="Sitka Heading", size=9))
size_menu.menu.add_radiobutton(label="SIZE 2",
command=lambda: size_f(15), background="black", foreground="white",
font=font.Font(family="Sitka Heading", size=9))
size_menu.menu.add_radiobutton(label="SIZE 3",
command=lambda: size_f(30), background="black", foreground="white",
font=font.Font(family="Sitka Heading", size=9))
size_menu.menu.add_radiobutton(label="SIZE 4",
command=lambda: size_f(40), font=font.Font(family="Sitka Heading", size=9),
background="black", foreground="white")
size_menu.pack()
# ..................................................................................................................................
GotoColorBox = 1
# Color BOX ..............................................................................
def setColor(colour):
global Color1, Color2, cs, outLinevar, fillvar
if cs == 1:
Color1 = colour
fillvar = Color1
else:
Color2 = colour
outLinevar = Color2
color1 = LabelFrame(colorSelect, text="Color 1", labelanchor='s', relief='flat')
color1.grid(row=0, column=0, sticky='news', padx=2, pady=2)
color1b = Button(color1, relief='flat', background=Color1, command=lambda: colorS(1))
color1b.pack(fill=BOTH, expand=True)
color2 = LabelFrame(colorSelect, text="Color 2", labelanchor='s', relief='flat')
color2.grid(row=0, column=1, sticky='news', padx=2, pady=2)
color2b = Button(color2, relief='flat', background=Color2, command=lambda: colorS(2))
color2b.pack(fill=BOTH, expand=True)
fontText = font.Font(family=fontFamilyVar.get(), size=SizeVar.get(), weight=BoldVar.get(),
slant=ItalicVar.get(), underline=UnderVar.get(), overstrike=OverVar.get())
text.configure(font=fontText, foreground=Color1)
if Color1 != "#FFFFFF":
textButtonI["selectcolor"] = Color1
textButtonU["selectcolor"] = Color1
textButtonB["selectcolor"] = Color1
textButtonO["selectcolor"] = Color1
def colorS(t):
global cs
cs = t
color1 = LabelFrame(colorSelect, text="Color 1", labelanchor='s', relief='flat')
color1.grid(row=0, column=0, sticky='news', padx=2, pady=2)
color1b = Button(color1, relief='flat', background=Color1, command=lambda: colorS(1))
color1b.pack(fill=BOTH, expand=True)
color2 = LabelFrame(colorSelect, text="Color 2", labelanchor='s', relief='flat')
color2.grid(row=0, column=1, sticky='news', padx=2, pady=2)
color2b = Button(color2, relief='flat', background=Color2, command=lambda: colorS(2))
color2b.pack(fill=BOTH, expand=True)
fontText = font.Font(family=fontFamilyVar.get(), size=SizeVar.get(), weight=BoldVar.get(),
slant=ItalicVar.get(), underline=UnderVar.get(), overstrike=OverVar.get())
text.configure(font=fontText, foreground=Color1)
colorbox.rowconfigure(0)
colorbox.rowconfigure(1)
colorbox.columnconfigure(0)
colorbox.columnconfigure(1)
colorbox.columnconfigure(2)
colorbox.columnconfigure(3)
colorbox.columnconfigure(4)
colorbox.columnconfigure(5)
colorbox.columnconfigure(6)
c1 = Button(colorbox, width=2, command=lambda: setColor("#FF3333"), background="#FF3333", relief="flat")
c1.grid(row=0, column=0, padx=4, pady=5)
c2 = Button(colorbox, width=2, command=lambda: setColor("#FF6B33"), background="#FF6B33", relief="flat")
c2.grid(row=0, column=1, padx=4, pady=5)
c3 = Button(colorbox, width=2, command=lambda: setColor("#FFFFFF"), background="#FFFFFF", relief="flat")
c3.grid(row=0, column=2, padx=4, pady=5)
c4 = Button(colorbox, width=2, command=lambda: setColor("#FFB833"), background="#FFB833", relief="flat")
c4.grid(row=0, column=3, padx=4, pady=5)
c5 = Button(colorbox, width=2, command=lambda: setColor("#FFE933"), background="#FFE933", relief="flat")
c5.grid(row=0, column=4, padx=4, pady=5)
c6 = Button(colorbox, width=2, command=lambda: setColor("#A8FF33"), background="#A8FF33", relief="flat")
c6.grid(row=0, column=5, padx=4, pady=5)
c7 = Button(colorbox, width=2, command=lambda: setColor("#49FF33"), background="#49FF33", relief="flat")
c7.grid(row=0, column=6, padx=4, pady=5)
c8 = Button(colorbox, width=2, command=lambda: setColor("#33FF6B"), background="#33FF6B", relief="flat")
c8.grid(row=1, column=0, padx=4, pady=1)
c9 = Button(colorbox, width=2, command=lambda: setColor("#07531C"), background="#07531C", relief="flat")
c9.grid(row=1, column=1, padx=4, pady=1)
c10 = Button(colorbox, width=2, command=lambda: setColor("#13E2DF"), background="#13E2DF", relief="flat")
c10.grid(row=1, column=2, padx=4, pady=1)
c11 = Button(colorbox, width=2, command=lambda: setColor("#13B0E2"), background="#13B0E2", relief="flat")
c11.grid(row=1, column=3, padx=4, pady=1)
c12 = Button(colorbox, width=2, command=lambda: setColor("#1339E2"), background="#1339E2", relief="flat")
c12.grid(row=1, column=4, padx=4, pady=1)
c13 = Button(colorbox, width=2, command=lambda: setColor("#B613E2"), background="#B613E2", relief="flat")
c13.grid(row=1, column=5, padx=4, pady=1)
c14 = Button(colorbox, width=2, command=lambda: setColor("#E21374"), background="#E21374", relief="flat")
c14.grid(row=1, column=6, padx=4, pady=1)
colorSelect.rowconfigure(0, weight=0)
colorSelect.columnconfigure(0, weight=40)
colorSelect.columnconfigure(1, weight=40)
color1 = Labelframe(colorSelect, text="Color 1", labelanchor='s', height=2)
color1.grid(row=0, column=0, sticky='news', padx=2, pady=2)
color1b = Button(color1, relief='flat', background=Color1, command=lambda: colorS(1), width=2, height=2)
color1b.pack(fill=BOTH)
color2 = Labelframe(colorSelect, text="Color 2", labelanchor='s', height=2)
color2.grid(row=0, column=1, sticky='news', padx=2, pady=2)
color2b = Button(color2, relief='flat', background=Color2, command=lambda: colorS(2), width=2, height=2)
color2b.pack(fill=BOTH)
# ...............................................................................
GotoOutline = 1
# outline and fill color ..........................................
def out(s):
global Color2, outLinevar
if s == "OSC":
outLinevar = Color2
elif s == "NO":
outLinevar = ''
def Fill(s):
global fillvar, Color1
if s == "FSC":
fillvar = Color1
elif s == "NF":
fillvar = ''
resource_path(".img\\outline.png")
outlineIMG = Image.open(".img\\outline.png")
outlineIMG = outlineIMG.resize((15, 15), Image.ANTIALIAS)
Outline1Img = ImageTk.PhotoImage(outlineIMG)
resource_path(".img\\fill.png")
fillColorIMG = Image.open(".img\\fill.png")
fillColorIMG = fillColorIMG.resize((15, 15), Image.ANTIALIAS)
FillColor1IMG = ImageTk.PhotoImage(fillColorIMG)
outFrame = LabelFrame(out_fill, relief="flat")
outFrame.pack(pady=1, side=TOP)
fillFrame = LabelFrame(out_fill, relief="flat")
fillFrame.pack(pady=1, side=TOP)
outButton = Menubutton(outFrame, text="outline", anchor='n', image=Outline1Img, compound=LEFT, relief="flat")
outButton.menu2 = Menu(outButton, foreground="white", background="black")
outButton["menu"] = outButton.menu2
outButton.menu2.add_radiobutton(label="No Outline", command=lambda: out("NO"),
font=font.Font(family="Sitka Heading", size=9), background="black", foreground="white")
outButton.menu2.add_radiobutton(label="Solid Color", command=lambda: out("OSC"),
font=font.Font(family="Sitka Heading", size=9), background="black", foreground="white")
outButton.pack(side=TOP)
fillButton = Menubutton(fillFrame, text="fill color", image=FillColor1IMG, compound=LEFT, relief="flat")
fillButton.menu3 = Menu(fillButton, foreground="white", background="black")
fillButton["menu"] = fillButton.menu3
fillButton.menu3.add_radiobutton(label="No fill", command=lambda: Fill("NF"),
font=font.Font(family="Sitka Heading", size=9), background="black", foreground="white")
fillButton.menu3.add_radiobutton(label="Solid Color", command=lambda: Fill("FSC"),
font=font.Font(family="Sitka Heading", size=9), background="black", foreground="white")
fillButton.pack(side=TOP)
# .................................................................................
GotoShapes = 1
# shapes RECTANGLE , TRAINGLE , CIRCLE , OVAL , STAR ETC ............................................................
ir, ic, it, iet, irt, ih1, ih2 = -1, -1, -1, -1, -1, -1, -1
px, py, polyi = 0, 0, -1
X, Y = 0, 0
sti = -1
polyx1, polyy1 = 0, 0
shapeType = "rectangle"
def coordinate(event):
global sx, sy, polyx1, polyy1
sx, sy = event.x, event.y
if polyx1 == 0 and polyy1 == 0:
polyx1, polyy1 = event.x, event.y
def paintShapes(event):
global X, sx, sy, r1s, c1s, shapeType, Y, outLinevar, fillvar, t1s, et1s, et1, rt1s, h1s, h2s, star1
global px, py, poly1, polyx1, polyy1
px, py = 0, 0
if shapeType == "rectangle":
polyx1, polyy1 = 0, 0
contentLabel.delete(r1s)
r1s = contentLabel.create_rectangle(sx, sy, event.x, event.y, outline=outLinevar, fill=fillvar)
elif shapeType == "circle":
polyx1, polyy1 = 0, 0
contentLabel.delete(c1s)
c1s = contentLabel.create_oval(sx, sy, event.x, event.y, outline=outLinevar, fill=fillvar)
elif shapeType == 'triangle':
polyx1, polyy1 = 0, 0
contentLabel.delete(t1s)
t1s = contentLabel.create_polygon(sx, sy, event.x + 100, event.y, event.x - 100, event.y, outline=outLinevar,
fill=fillvar)
elif shapeType == 'Etriangle':
polyx1, polyy1 = 0, 0
contentLabel.delete(et1s)
et1s = contentLabel.create_polygon(sx, sy, event.x, event.y, 2 * sx - event.x, event.y, outline=outLinevar,
fill=fillvar)
elif shapeType == "Rtriangle":
polyx1, polyy1 = 0, 0
contentLabel.delete(rt1s)
rt1s = contentLabel.create_polygon(sx, sy, event.x, event.y, sx, event.y, outline=outLinevar, fill=fillvar)
elif shapeType == "heart":
polyx1, polyy1 = 0, 0
if fillvar != '':
contentLabel.delete(h1s)
contentLabel.delete(h2s)
h1s = contentLabel.create_polygon(sx, sy, sx - (event.x - sx) / 3, sy - (event.y - sy) / 10,
sx - (event.x - sx) / 2, sy + (event.y - sy) / 4, sx + (event.x - sx) / 9,
event.y, smooth=True, fill=fillvar, outline=outLinevar)
h2s = contentLabel.create_polygon(sx, sy, sx + (event.x - sx) / 3, sy - (event.y - sy) / 10,
sx + (event.x - sx) / 2, sy + (event.y - sy) / 4, sx - (event.x - sx) / 9,
event.y, smooth=True, fill=fillvar, outline=outLinevar)
else:
contentLabel.delete(h1s)
contentLabel.delete(h2s)