1+ #!/usr/bin/env python3
2+ ######################################
3+ # BRAINTECH PRIVATE LIMITED
4+ # JOHN MELODY MELISSA
5+ ######################################
6+ # यह स्क्रिप्ट John Melody द्वारा लिखा गया है।
7+ # PYTHON में पूरी तरह से द्वारा संचालित. सभी
8+ # अधिकार सुरक्षित | इस स्क्रिप्ट का कोई भी
9+ # हिस्सा अनधिकृत पार्टी द्वारा
10+ # पुनरुत्पादित किया जा सकता है।
11+ ######################################
12+ from tkinter .messagebox import *
13+ from tkinter .filedialog import *
14+ from tkinter .filedialog import askopenfilename
15+
16+
17+ class Notepad :
18+ # variables
19+ __root = Tk ()
20+
21+ # default window width and height
22+ __thisWidth = 300
23+ __thisHeight = 300
24+ __thisTextArea = Text (__root )
25+ __thisMenuBar = Menu (__root )
26+ __thisFileMenu = Menu (__thisMenuBar , tearoff = 0 )
27+ __thisEditMenu = Menu (__thisMenuBar , tearoff = 0 )
28+ __thisHelpMenu = Menu (__thisMenuBar , tearoff = 0 )
29+ __thisScrollBar = Scrollbar (__thisTextArea )
30+ __file = None
31+
32+ def __init__ (self , ** kwargs ):
33+ # initialization
34+
35+ # set icon
36+ try :
37+ self .__root .wm_iconbitmap ("logo.ico" ) # GOT TO FIX THIS ERROR (ICON)
38+ except :
39+ pass
40+
41+ # set window size (the default is 300x300)
42+
43+ try :
44+ self .__thisWidth = kwargs ['width' ]
45+ except KeyError :
46+ pass
47+
48+ try :
49+ self .__thisHeight = kwargs ['height' ]
50+ except KeyError :
51+ pass
52+
53+ # set the window text
54+ self .__root .title (" Braintech Braiwave Monitor [TEXT EDITOR] " )
55+ self .__root .iconbitmap ("icon.ico" )
56+
57+ # center the window
58+ screenWidth = self .__root .winfo_screenwidth ()
59+ screenHeight = self .__root .winfo_screenheight ()
60+
61+ left = (screenWidth / 2 ) - (self .__thisWidth / 2 )
62+ top = (screenHeight / 2 ) - (self .__thisHeight / 2 )
63+
64+ self .__root .geometry ('%dx%d+%d+%d' % (self .__thisWidth , self .__thisHeight , left , top ))
65+
66+ # to make the textarea auto resizable
67+ self .__root .grid_rowconfigure (0 , weight = 1 )
68+ self .__root .grid_columnconfigure (0 , weight = 1 )
69+
70+ # add controls (widget)
71+
72+ self .__thisTextArea .grid (sticky = N + E + S + W )
73+
74+ self .__thisFileMenu .add_command (label = "New" , command = self .__newFile )
75+ self .__thisFileMenu .add_command (label = "Open" , command = self .__openFile )
76+ self .__thisFileMenu .add_command (label = "Save" , command = self .__saveFile )
77+ self .__thisFileMenu .add_separator ()
78+ self .__thisFileMenu .add_command (label = "Exit" , command = self .__quitApplication )
79+ self .__thisMenuBar .add_cascade (label = "File" , menu = self .__thisFileMenu )
80+
81+ self .__thisEditMenu .add_command (label = "Cut" , command = self .__cut )
82+ self .__thisEditMenu .add_command (label = "Copy" , command = self .__copy )
83+ self .__thisEditMenu .add_command (label = "Paste" , command = self .__paste )
84+ self .__thisMenuBar .add_cascade (label = "Edit" , menu = self .__thisEditMenu )
85+
86+ self .__thisHelpMenu .add_command (label = "About Notepad" , command = self .__showAbout )
87+ self .__thisMenuBar .add_cascade (label = "Help" , menu = self .__thisHelpMenu )
88+
89+ self .__root .config (menu = self .__thisMenuBar )
90+
91+ self .__thisScrollBar .pack (side = RIGHT , fill = Y )
92+ self .__thisScrollBar .config (command = self .__thisTextArea .yview )
93+ self .__thisTextArea .config (yscrollcommand = self .__thisScrollBar .set )
94+
95+ def __quitApplication (self ):
96+ self .__root .destroy ()
97+ # exit()
98+
99+ def __showAbout (self ):
100+ import credit as software_credit
101+ software_credit ()
102+
103+ def __openFile (self ):
104+
105+ self .__file = askopenfilename (defaultextension = ".txt" ,
106+ filetypes = [("Text File" , "*.txt" ), ("FIF" , "*.fif" ), ("Python" , "*.py" ),
107+ ("C/C++" , "*.c" ), ("BRT" , "*.brt" ), ("EDF" , "*.edf" ), ("CSV" , "*.csv" ),
108+ ("Excel" , "*.xls" ), ("TFF" , "*.tff" ), ("MATLAB" , "*.m" ),
109+ ("Json" , "*.json" ), ("All Files" , "*.*" )])
110+
111+ if self .__file == "" :
112+ # no file to open
113+ self .__file = None
114+ else :
115+ # try to open the file
116+ # set the window title
117+ self .__root .title (os .path .basename (self .__file ) + " - Notepad" )
118+ self .__thisTextArea .delete (1.0 , END )
119+
120+ file = open (self .__file , "r" )
121+
122+ self .__thisTextArea .insert (1.0 , file .read ())
123+
124+ file .close ()
125+
126+ def __newFile (self ):
127+ self .__root .title ("Untitled - Notepad" )
128+ self .__file = None
129+ self .__thisTextArea .delete (1.0 , END )
130+
131+ def __saveFile (self ):
132+
133+ if self .__file == None :
134+ # save as new file
135+ self .__file = asksaveasfilename (initialfile = 'Untitled.txt' , defaultextension = ".txt" ,
136+ filetypes = [("Text File" , "*.txt" ), ("FIF" , "*.fif" ), ("Python" , "*.py" ),
137+ ("C/C++" , "*.c" ), ("BRT" , "*.brt" ), ("EDF" , "*.edf" ),
138+ ("CSV" , "*.csv" ), ("Excel" , "*.xls" ), ("TFF" , "*.tff" ),
139+ ("MATLAB" , "*.m" ), ("Json" , "*.json" ), ("All Files" , "*.*" )])
140+
141+ if self .__file == "" :
142+ self .__file = None
143+ else :
144+ # try to save the file
145+ file = open (self .__file , "w" )
146+ file .write (self .__thisTextArea .get (1.0 , END ))
147+ file .close ()
148+ # change the window title
149+ self .__root .title (os .path .basename (self .__file ) + " - Notepad" )
150+
151+
152+ else :
153+ file = open (self .__file , "w" )
154+ file .write (self .__thisTextArea .get (1.0 , END ))
155+ file .close ()
156+
157+ def __cut (self ):
158+ self .__thisTextArea .event_generate ("<<Cut>>" )
159+
160+ def __copy (self ):
161+ self .__thisTextArea .event_generate ("<<Copy>>" )
162+
163+ def __paste (self ):
164+ self .__thisTextArea .event_generate ("<<Paste>>" )
165+
166+ def run (self ):
167+
168+ # run main application
169+ self .__root .mainloop ()
170+
171+
172+ # run main application
173+ notepad = Notepad (width = 600 , height = 400 )
174+ notepad .run ()
0 commit comments