4
4
import os
5
5
from tkinter import filedialog
6
6
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
8
8
print ('Made by Matveev_' )
9
9
print ('https://github.com/UnMatveev/IntCode' )
10
10
11
11
py_compiler = 'run.py'
12
12
win = '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"' }
15
14
16
15
def execute (event = True ):
17
16
with open (py_compiler , 'w' , encoding = 'utf-8' ) as f :
18
17
f .write (editArea .get ('1.0' , END ))
19
18
20
- os .system (win ) # or (Linux['ubuntu'])
19
+ os .system (win ) # or (Linux['ubuntu'])
21
20
22
21
23
22
def changes (event = True ):
@@ -89,8 +88,13 @@ def handle_enter(event):
89
88
return "break"
90
89
else :
91
90
indent = len (current_line_text ) - len (current_line_text .lstrip ())
91
+ next_char = editArea .get (cursor_position )
92
92
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 )
94
98
return "break"
95
99
96
100
@@ -120,6 +124,37 @@ def handle_backspace(event):
120
124
return None
121
125
122
126
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
+
123
158
def on_font_change (event ):
124
159
# Обработчик изменения размера шрифта"""
125
160
current_font_size = int (editArea ['font' ].split ()[1 ])
@@ -137,6 +172,17 @@ def on_font_change(event):
137
172
editArea .configure (font = (font , new_font_size ))
138
173
139
174
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
+
140
186
def new_file ():
141
187
editArea .delete ("1.0" , END )
142
188
@@ -165,39 +211,53 @@ def exit_program():
165
211
def about_github ():
166
212
os .system ('start https://github.com/UnMatveev/IntCode' )
167
213
214
+
168
215
ctypes .windll .shcore .SetProcessDpiAwareness (True )
169
216
217
+ sw = '700'
218
+ hw = '500'
219
+ shw = f'{ sw } x{ hw } '
220
+
170
221
root = Tk ()
171
- root .geometry ('700x500' )
222
+ root .geometry (shw )
172
223
root .title (f'IntCode - { py_compiler } ' )
173
- root .iconbitmap ('icon.ico' )
174
224
previousText = ''
175
225
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 ))
182
235
comments = rgb ((166 , 172 , 185 ))
183
- string = rgb ((153 , 199 , 138 ))
236
+ string = rgb ((136 , 201 , 118 ))
184
237
function = rgb ((95 , 211 , 234 ))
185
- background = rgb ((48 , 56 , 65 ))
186
238
font = 'Consolas'
187
- font_size = 20
239
+ font_size = 15
188
240
189
241
repl = [
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 ],
196
251
['".*?"' , string ],
197
252
['\" .*?\" ' , string ],
198
253
['\' .*?\' ' , 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 ],
201
261
['#.*?$' , comments ],
202
262
]
203
263
@@ -208,16 +268,7 @@ def about_github():
208
268
209
269
editArea .pack (fill = BOTH , expand = 1 )
210
270
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.''' )
221
272
222
273
mmenu = Menu (root )
223
274
root .config (menu = mmenu )
@@ -231,10 +282,10 @@ def manera():
231
282
about = Menu (mmenu , tearoff = False )
232
283
233
284
mmenu .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",
238
289
menu=find)
239
290
mmenu.add_cascade(label="View",
240
291
menu=view)
@@ -243,7 +294,7 @@ def manera():
243
294
mmenu.add_cascade(label="Settings",
244
295
menu=settings) """
245
296
mmenu .add_cascade (label = "About" ,
246
- menu = about )
297
+ menu = about )
247
298
248
299
editArea .bind ('<KeyRelease>' , changes )
249
300
editArea .bind ("<KeyPress>" , handle_opening_bracket )
0 commit comments