44import os
55from tkinter import filedialog
66
7- print ('IntCode, 1.2.0 version' ) # DON'T TOUCH THIS IF YOU CONTRIBUTE SOMETHING
7+ print (f 'IntCode, 1.3 version' ) # DON'T TOUCH THIS IF YOU CONTRIBUTE SOMETHING
88print ('Made by Matveev_' )
99print ('https://github.com/UnMatveev/IntCode' )
1010
1111py_compiler = 'run.py'
1212win = 'start cmd /K "python run.py"'
13- Linux = {'ubuntu' :'gnome-terminal -- bash -c "python3 run.py; exec bash"' }
14-
13+ Linux = {'ubuntu' : 'gnome-terminal -- bash -c "python3 run.py; exec bash"' }
1514
1615def execute (event = True ):
1716 with open (py_compiler , 'w' , encoding = 'utf-8' ) as f :
1817 f .write (editArea .get ('1.0' , END ))
1918
20- os .system (win ) # or (Linux['ubuntu'])
19+ os .system (win ) # or (Linux['ubuntu'])
2120
2221
2322def changes (event = True ):
@@ -89,8 +88,13 @@ def handle_enter(event):
8988 return "break"
9089 else :
9190 indent = len (current_line_text ) - len (current_line_text .lstrip ())
91+ next_char = editArea .get (cursor_position )
9292
93- editArea .insert (INSERT , "\n " + " " * indent )
93+ if next_char in [")" , "]" , "}" ]:
94+ editArea .insert (INSERT , f"\n { ' ' * (indent + 4 )} \n " )
95+ editArea .mark_set (INSERT , f"{ cursor_position } +5c" )
96+ else :
97+ editArea .insert (INSERT , "\n " + " " * indent )
9498 return "break"
9599
96100
@@ -120,6 +124,37 @@ def handle_backspace(event):
120124 return None
121125
122126
127+ def handle_enter_second (event ):
128+ # получаем координаты текущей выделенной области
129+ sel_start , sel_end = editArea .tag_ranges ("sel" )
130+
131+ # если выделения нет, то не обрабатываем
132+ if not sel_start or not sel_end :
133+ return
134+
135+ # получаем текст между выделенными координатами
136+ text = editArea .get (sel_start , sel_end )
137+
138+ # определяем тип скобки, если это скобки вообще
139+ if text in ["()" , "[]" , "{}" ]:
140+ # получаем координаты курсора
141+ cursor = editArea .index (INSERT )
142+
143+ # определяем новые координаты для скобки
144+ row , col = map (int , cursor .split ("." ))
145+ new_row , new_col = row + 2 , col
146+
147+ # перемещаем скобку в новую позицию
148+ editArea .delete (sel_start , sel_end )
149+ editArea .insert (f"{ new_row } .{ new_col } " , text )
150+
151+ # вставляем отступ
152+ editArea .insert (cursor , "\n " + " " * 4 )
153+
154+ # устанавливаем курсор в новую позицию
155+ editArea .mark_set (INSERT , f"{ new_row } .{ new_col + 4 } " )
156+
157+
123158def on_font_change (event ):
124159 # Обработчик изменения размера шрифта"""
125160 current_font_size = int (editArea ['font' ].split ()[1 ])
@@ -137,6 +172,17 @@ def on_font_change(event):
137172 editArea .configure (font = (font , new_font_size ))
138173
139174
175+ def highlight_functions (text ):
176+ # Регулярное выражение для поиска имен функций
177+ pattern = r'\b\w+\('
178+
179+ # Ищем имена функций в тексте и проверяем их наличие в текущем контексте
180+ for match in re .finditer (pattern , text ):
181+ func_name = match .group ()[:- 1 ]
182+ if func_name in globals () or func_name in locals ():
183+ yield match .start (), match .end (), function
184+
185+
140186def new_file ():
141187 editArea .delete ("1.0" , END )
142188
@@ -165,39 +211,53 @@ def exit_program():
165211def about_github ():
166212 os .system ('start https://github.com/UnMatveev/IntCode' )
167213
214+
168215ctypes .windll .shcore .SetProcessDpiAwareness (True )
169216
217+ sw = '700'
218+ hw = '500'
219+ shw = f'{ sw } x{ hw } '
220+
170221root = Tk ()
171- root .geometry ('700x500' )
222+ root .geometry (shw )
172223root .title (f'IntCode - { py_compiler } ' )
173- root .iconbitmap ('icon.ico' )
174224previousText = ''
175225
176- normal = rgb ((216 , 222 , 233 ))
177- keywords = rgb ((181 , 149 , 198 ))
178- keywords_2 = rgb ((102 , 153 , 204 ))
179- keywords_2_italic = rgb ((102 , 153 , 204 ))
180- keywords_3 = rgb ((249 , 123 , 87 ))
181- keywords_4 = rgb ((222 , 85 , 84 ))
226+ background = rgb ((40 , 44 , 52 ))
227+ normal = rgb ((195 , 195 , 195 ))
228+ w1 = rgb ((213 , 95 , 222 ))
229+ w2 = rgb ((88 , 167 , 222 ))
230+ w3 = rgb ((249 , 123 , 87 ))
231+ w4 = rgb ((222 , 85 , 84 ))
232+ w5 = rgb ((41 , 185 , 196 ))
233+ w6 = rgb ((229 , 192 , 123 ))
234+ w7 = rgb ((208 , 140 , 98 ))
182235comments = rgb ((166 , 172 , 185 ))
183- string = rgb ((153 , 199 , 138 ))
236+ string = rgb ((136 , 201 , 118 ))
184237function = rgb ((95 , 211 , 234 ))
185- background = rgb ((48 , 56 , 65 ))
186238font = 'Consolas'
187- font_size = 20
239+ font_size = 15
188240
189241repl = [
190- ['(^| )(False|True|and|as|assert|async|await|break|class|continue|del|elif|else|except|finally|for'
191- '|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|raise|return|try|while|with|yield)($| )' , keywords ],
192- ['(get|write)' , keywords_2 ],
193- ['(print|open)' , keywords_2_italic ],
194- ['(=|\-|\+|\/|\*)' , keywords_3 ],
195- ['(None)' , keywords_4 ],
242+ ['(^| )(and|as|assert|async|await|break|class|continue|del|elif|else|except|finally|for'
243+ '|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|raise|return|try|while|with|yield)($| )' , w1 ],
244+ ['(self|False|True)' , w1 ],
245+ ['\w+(?=\()' , w2 ],
246+ ['"[^"]*"' , string ],
247+ ["'[^']*'" , string ],
248+ ['(get|write|print|open)' , w5 ],
249+ [r'==|!=|>|<|>=|<=|=|\+|\-|\*|\/|\%' , w3 ],
250+ ['(None)' , w4 ],
196251 ['".*?"' , string ],
197252 ['\" .*?\" ' , string ],
198253 ['\' .*?\' ' , string ],
199- ['' , keywords_3 ],
200- ['def' , keywords ],
254+ ['(?<=class\s)\w+' , w6 ],
255+ ['class' , w1 ],
256+ ['(?<=def\s)\w+' , w2 ],
257+ ['def' , w1 ],
258+ ['(?<=\.)\w+' , w2 ],
259+ [r'\b\d+\.\d+\b' , w7 ],
260+ ['(?<!\w)\\ d+(?!\w)' , w7 ],
201261 ['#.*?$' , comments ],
202262]
203263
@@ -208,16 +268,7 @@ def about_github():
208268
209269editArea .pack (fill = BOTH , expand = 1 )
210270
211- editArea .insert ('1.0' , '''import time as t
212-
213- def manera():
214- print('Manera krutit mir')
215-
216- print('Hello, mir')
217-
218- t.sleep(1)
219-
220- manera()''' )
271+ editArea .insert ('1.0' , '''Welcome.''' )
221272
222273mmenu = Menu (root )
223274root .config (menu = mmenu )
@@ -231,10 +282,10 @@ def manera():
231282about = Menu (mmenu , tearoff = False )
232283
233284mmenu .add_cascade (label = "File" ,
234- menu = file )
235- """ mmenu.add_cascade(label="Edit",
236- menu=edit)
237- mmenu.add_cascade(label="Find",
285+ menu = file )
286+ mmenu .add_cascade (label = "Edit" ,
287+ menu = edit )
288+ """ mmenu.add_cascade(label="Find",
238289 menu=find)
239290mmenu.add_cascade(label="View",
240291 menu=view)
@@ -243,7 +294,7 @@ def manera():
243294mmenu.add_cascade(label="Settings",
244295 menu=settings) """
245296mmenu .add_cascade (label = "About" ,
246- menu = about )
297+ menu = about )
247298
248299editArea .bind ('<KeyRelease>' , changes )
249300editArea .bind ("<KeyPress>" , handle_opening_bracket )
0 commit comments