-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetCon.py
More file actions
3547 lines (3284 loc) · 273 KB
/
NetCon.py
File metadata and controls
3547 lines (3284 loc) · 273 KB
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
import threading
import webbrowser
import tkinter
import pyautogui
import updated_ctk as ctk
from PIL import Image
import os
import sqlite3
import re
import subprocess
import pathlib
import time
import ctypes
import sys
import psutil
from NetConWindows import *
ctk.set_appearance_mode("System")
ctk.set_default_color_theme("dark-blue")
class App(ctk.CTk):
def __init__(self):
super().__init__()
# Загрузка шрифтов (виртуэлная)
def load_private_fonts():
base_dir = pathlib.Path(__file__).resolve().parent
fonts_dir = base_dir / "fonts"
if not fonts_dir.exists():
return
for font in fonts_dir.glob("*.ttf"):
ctypes.windll.gdi32.AddFontResourceExW(
str(font),
0x10,
0
)
# Загрузка файла конфигурации окна приложения
def load_config():
home_dir = pathlib.Path.home()
netcon_dir = home_dir / "NetCon"
config_file = netcon_dir / "config.txt"
default_values = ["English", "None", "Dark", "100%", "Enabled"] # Параметры по умолчанию
try:
if not os.path.exists(config_file):
config_file.parent.mkdir(parents=True, exist_ok=True)
with open(config_file, "w") as f:
f.write(" ".join(default_values))
with open(config_file, "r") as f:
line = f.readline().strip()
values = line.split()
return values
except Exception as e:
return default_values
# Заипсь в файл конфигурации окна приложения
def save_config(param1, param2, param3, param4, param5):
home_dir = pathlib.Path.home()
netcon_dir = home_dir / "NetCon"
config_file = netcon_dir / "config.txt"
with open(config_file, "w") as f:
f.write(f"{param1} {param2} {param3} {param4} {param5}")
def after_close_terminals():
self.deiconify()
self.listbox = CTkListbox(self.tabview.tab("База адресов"), fg_color=("white", "#333333"), border_width=0, button_color=("#e5e5e5", "#212121"), font=ctk.CTkFont(family=("Trebuchet MS"), size=14, weight="normal"), orientation="vertical", orientation2="horizontal", width=560)
self.listbox.grid(row=3, rowspan=6, column=2, columnspan=4, padx=(12, 20), pady=(0, 0), sticky="nsew")
self.listbox.bind('<<ListboxSelect>>', lambda list_var: open_con_listbox())
self.hello_button_1.grid(row=5, column=1, padx=(520, 77), pady=(10, 0), sticky="we")
self.label_hello.grid(row=2, column=1, padx=(115, 0), pady=(0, 0), sticky="w")
self.label_hello2.grid(row=3, column=1, padx=(115, 0), pady=(10, 0), sticky="w")
self.label_hello3.grid(row=4, column=1, padx=(115, 0), pady=(10, 0), sticky="w")
self.label_hello4.grid(row=5, column=1, padx=(115, 0), pady=(10, 0), sticky="w")
self.hello_line2.grid(row=6, column=1, columnspan=1, padx=(120, 120), pady=(0, 0), sticky="nsew")
self.hello_button_1.grid(row=5, column=1, padx=(530, 115), pady=(10, 0), sticky="we")
self.hello_button_2.grid(row=7, column=1, padx=(115, 115), pady=(5, 120), sticky="ew", ipady=5)
self.label_line2.grid(row=3, column=1, columnspan=9, padx=24, pady=(10, 10))
if self.combobox_4.get() != "":
refresh_db_after_scale(name_db, self.listbox)
# Подключение telnet/web
def clicked2(radio):
s_radio = radio.get()
if s_radio == 3:
self.after(150, lambda: self.focus_set())
if self.scaling_optionemenu.get() != "100%":
self.scaling_optionemenu.set(value="100%")
ctk.set_widget_scaling(1)
self.iconify()
serial_con = SerialTerminal()
serial_con(self.appearance_mode_optionemenu.get(), self.opacity, self.language, self)
clear_entry_telnet(self.entry3, self.radio_var)
if serial_con.get() == 1:
self.bind('<Escape>', lambda close: self.close_app())
self.scaling_optionemenu.set(value="100%")
after_close_terminals()
elif str(x3.get()) == "...":
self.entry3.focus_set()
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Поле не должно быть пустым!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='The field must not be empty!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
ip_var = str(x3.get())
list_ip = ip_var.split(".")
for i in range(len(list_ip)): # Проверка на верность формата IP
if str(list_ip[i]) == "":
self.entry3.focus_set()
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Неверный формат IP-адреса!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='Incorrect IP-address format!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
elif int(list_ip[i]) > 255:
self.entry3.focus_set()
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Неверный формат IP-адреса!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='Incorrect IP-address format!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
if s_radio == 1:
self.after(150, lambda: self.focus_set())
select_terminal = SelectTerminal()
select_terminal(self.appearance_mode_optionemenu.get(), str(x3.get()), "Telnet", self.scaling_optionemenu.get(), self, self.opacity, self.language)
if select_terminal.get() == 1:
self.bind('<Escape>', lambda close: self.close_app())
self.scaling_optionemenu.set(value="100%")
after_close_terminals()
elif s_radio == 2:
self.after(150, lambda: self.focus_set())
select_terminal = SelectTerminal()
select_terminal(self.appearance_mode_optionemenu.get(), str(x3.get()), "SSH", self.scaling_optionemenu.get(), self, self.opacity, self.language)
if select_terminal.get() == 1:
self.bind('<Escape>', lambda close: self.close_app())
self.scaling_optionemenu.set(value="100%")
after_close_terminals()
elif s_radio == 4:
self.after(150, lambda: self.focus_set())
web_con = SelectWeb()
web_con(str(x3.get()), self, self.opacity, self.language)
if web_con.get() == 1:
self.bind('<Escape>', lambda close: self.close_app())
# Ping (это БАЗАААААА)
def execute_cmd(ip, type_con, entry):
if ip == "...":
entry.focus_set()
if self.language == "Русский":
self.main_button_1.configure(fg_color="#1F538D")
self.main_button_2.configure(fg_color="#1F538D")
return CTkMessagebox(opacity=self.opacity, message='Поле не должно быть пустым!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
self.main_button_1.configure(fg_color="#1F538D")
self.main_button_2.configure(fg_color="#1F538D")
return CTkMessagebox(opacity=self.opacity, message='The field must not be empty!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
ip_var = ip
list_ip = ip_var.split(".")
for i in range(len(list_ip)): # Проверка на верность формата IP
if str(list_ip[i]) == "":
entry.focus_set()
if self.language == "Русский":
self.main_button_1.configure(fg_color="#1F538D")
self.main_button_2.configure(fg_color="#1F538D")
return CTkMessagebox(opacity=self.opacity, message='Неверный формат IP-адреса!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
self.main_button_1.configure(fg_color="#1F538D")
self.main_button_2.configure(fg_color="#1F538D")
return CTkMessagebox(opacity=self.opacity, message='Incorrect IP-address format!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
if int(list_ip[i]) > 255:
entry.focus_set()
if self.language == "Русский":
self.main_button_1.configure(fg_color="#1F538D")
self.main_button_2.configure(fg_color="#1F538D")
return CTkMessagebox(opacity=self.opacity, message='Неверный формат IP-адреса!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
self.main_button_1.configure(fg_color="#1F538D")
self.main_button_2.configure(fg_color="#1F538D")
return CTkMessagebox(opacity=self.opacity, message='Incorrect IP-address format!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
right_click()
self.after(200, lambda: self.unbind('<Escape>'))
message5 = Loading()
message5(ip, self.textbox, type_con, self, self.opacity, self.language, self.alert_mode)
# if "win" not in self.combobox_ping.get() and "win" not in self.combobox_tracert.get():
self.entry1.configure(state="disabled", border_color=("#8f8f8f", "#444444"), text_color=("gray50", "gray45"))
self.entry_tracert.configure(state="disabled", border_color=("#8f8f8f", "#444444"), text_color=("gray50", "gray45"))
self.combobox_ping.configure(state="disabled", border_color=("#8f8f8f", "#444444"), button_color=("#8f8f8f", "#444444"))
self.combobox_tracert.configure(state="disabled", border_color=("#8f8f8f", "#444444"), button_color=("#8f8f8f", "#444444"))
self.main_button_1.configure(state="disabled", fg_color="#0f334d")
self.main_button_2.configure(state="disabled", fg_color="#0f334d")
self.clear_btn_ip.configure(state="disabled", fg_color="#94440B", image=clear_disabled_img)
self.clear_btn_tracert.configure(state="disabled", fg_color="#94440B", image=clear_disabled_img)
# костыль для того чтобы после остановки пинга на esc бинд на эту же клавишу в основной проге не возвращался сразу(хуй знает как но это работает)
if message5.get() == 1:
self.textbox.configure(state="disabled")
self.entry1.configure(state="normal", border_color=("#979da2", "#565b5e"), text_color=("gray14", "gray84"))
self.entry_tracert.configure(state="normal", border_color=("#979da2", "#565b5e"), text_color=("gray14", "gray84"))
self.combobox_ping.configure(state="readonly", border_color=("#979da2", "#565b5e"), button_color=("#979da2", "#565b5e"))
self.combobox_tracert.configure(state="readonly", border_color=("#979da2", "#565b5e"), button_color=("#979da2", "#565b5e"))
self.main_button_1.configure(state="normal", fg_color="#1F538D")
self.main_button_2.configure(state="normal", fg_color="#1F538D")
self.clear_btn_ip.configure(state="normal", fg_color="#f4740b", image=clear_img)
self.clear_btn_tracert.configure(state="normal", fg_color="#f4740b", image=clear_img)
return right_click()
# IPconfig (Пригодится)
def execute_cmd2(command):
try:
if command == "ipconfig Выберите из списка или введите...":
command = "ipconfig"
if command == "ipconfig Select from the list or enter...":
command = "ipconfig"
cmd_output2 = subprocess.check_output(command, shell=True).decode('cp866')
self.textbox2.configure(state='normal')
self.textbox2.insert('end', " \n")
self.textbox2.insert('end', " 〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉\n")
self.textbox2.insert('end', " \n")
if self.language == "Русский":
self.textbox2.insert('end', " Текущая конфигурация сети:\n")
else:
self.textbox2.insert('end', " Current network configuration:\n")
self.textbox2.insert('end', " \n")
self.textbox2.insert('end', " 〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉\n")
self.textbox2.insert('end', cmd_output2)
self.textbox2.insert('end', " \n")
self.textbox2.insert('end', " 〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉\n")
self.textbox2.see('end')
self.textbox2.configure(state='disabled')
if self.language == "Русский":
if self.alert_mode:
CTkMessagebox(opacity=self.opacity, message='Готово! Смотрите "Console log"', title='Успех!', icon='check', master=self, button_width=self.alert_button_size), right_click()
else:
right_click()
return
else:
if self.alert_mode:
CTkMessagebox(opacity=self.opacity, message='Ready! See the "Console log"', title='Success!', icon='check', master=self, button_width=self.alert_button_size), right_click()
else:
right_click()
return
except:
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Повторите ввод атрибута!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='Re-enter the attribute!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
# Адаптер (вывод его имени тупа тока)
def execute_cmd3(command):
try:
if str(x4.get()) == "" and self.language == "Русский" or str(x4.get()) == "Выберите из списка или введите...":
self.combobox_2.focus_set()
return CTkMessagebox(opacity=self.opacity, message='Поле не должно быть пустым!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
elif str(x4.get()) == "" and self.language == "English" or str(x4.get()) == "Select from the list or enter...":
self.combobox_2.focus_set()
return CTkMessagebox(opacity=self.opacity, message='The field must not be empty!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
cmd_output3 = subprocess.check_output(command, shell=True).decode('cp866')
self.textbox2.configure(state='normal')
self.textbox2.insert('end', cmd_output3)
self.textbox2.insert('end', " 〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉〉\n")
self.textbox2.see('end')
self.textbox2.configure(state='disabled')
if self.language == "Русский":
if self.alert_mode:
CTkMessagebox(opacity=self.opacity, message='Готово! Смотрите "Console log"', title='Успех!', icon='check', master=self, button_width=self.alert_button_size), right_click()
else:
right_click()
return
else:
if self.alert_mode:
CTkMessagebox(opacity=self.opacity, message='Ready! See the "Console log"', title='Success!', icon='check', master=self, button_width=self.alert_button_size), right_click()
else:
right_click()
return
except:
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Повторите ввод имени!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='Re-enter the name!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
# Применение новых настроек адаптера
def execute_cmd3_1(command, dhcp_flag=False):
message = Loading_adapter()
message(command, self.textbox2, self.combobox_3, dhcp_flag, self, self.opacity, self.language, self.alert_mode)
return right_click()
# Параметры адаптера
def execute_cmd4(command):
if str(x8.get()) == "" or str(x5.get()) == "..." or str(x6.get()) == "..." or str(x7.get()) == "...":
self.combobox_3.focus_set()
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Все поля должны быть заполнены!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='All fields must be filled in!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
ip_var = str(x5.get())
mask_var = str(x6.get())
gate_var = str(x7.get())
list_ip = ip_var.split(".")
list_mask = mask_var.split(".")
list_gate = gate_var.split(".")
for i in range(len(list_ip)): # Проверка на верность формата IP
if str(list_ip[i]) == "":
self.entry6.focus_set()
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Неверный формат IP-адреса!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='Incorrect IP address format!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
elif int(list_ip[i]) > 255:
self.entry6.focus_set()
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Неверный формат IP-адреса!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='Incorrect IP address format!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
if str(list_mask[i]) == "":
self.entry7.focus_set()
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Неверный формат Маски!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='Incorrect Mask format!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
elif int(list_mask[i]) > 255:
self.entry7.focus_set()
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Неверный формат Маски!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='Incorrect Mask format!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
if str(list_gate[i]) == "":
self.entry8.focus_set()
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Неверный формат Шлюза!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='Incorrect Gateway format!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
if int(list_gate[i]) > 255:
self.entry8.focus_set()
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Неверный формат Шлюза!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='Incorrect Gateway format!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
# os.system('start cmd /c ' + command)
subprocess.run(command, shell=True, creationflags=subprocess.CREATE_NO_WINDOW)
execute_cmd3_1(str(x8.get())) # САМ ПОНЯЛ КАКОЕ ГОВНО НАПИСАЛ?
return right_click()
# Включение DHCP (нахуй с пляжа)
def execute_cmd5(command):
if str(x8.get()) == "":
self.combobox_3.focus_set()
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Поле «Имя» не должно быть пустым!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='The "Name" field should not be empty!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
if self.language == "Русский":
msg = CTkMessagebox(opacity=self.opacity, message='Вы уверены?', title='Внимание!', icon='warning', option_1="Отмена", option_2="Да", master=self, button_width=200)
else:
msg = CTkMessagebox(opacity=self.opacity, message='Are you sure?', title='Attention!', icon='warning', option_1="Cancel", option_2="Yes", master=self, button_width=200)
msg.focus_set()
response = msg.get()
if response == "Отмена" or response == "Cancel":
return
elif response == "Да" or response == "Yes":
try:
# os.system('start cmd /c ' + command)
subprocess.run(command, shell=True, creationflags=subprocess.CREATE_NO_WINDOW)
execute_cmd3_1(str(x8.get()), dhcp_flag=True)
return right_click()
except:
self.combobox_3.focus_set()
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Повторите ввод имени!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='Re-enter the name!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
# Очистка "console log" (понял вычеркиваем)
def clear_text(textbox, non_click=False):
if self.tabview.get() == "Подключение":
if not non_click:
if self.appearance_mode_optionemenu.get() == "Темная" or self.appearance_mode_optionemenu.get() == "Dark":
self.after(150, lambda: self.anim_hover.animate_hover(self.clear_btn, int("212121", 16), int("333333", 16), int("10101", 16), 10, "up"))
else:
self.after(150, lambda: self.anim_hover.animate_hover(self.clear_btn, int("e5e5e5", 16), int("ffffff", 16), int("20202", 16), 10, "up"))
elif self.tabview.get() == "Параметры сети":
if not non_click:
if self.appearance_mode_optionemenu.get() == "Темная" or self.appearance_mode_optionemenu.get() == "Dark":
self.after(150, lambda: self.anim_hover.animate_hover(self.clear_btn2, int("212121", 16), int("333333", 16), int("10101", 16), 10, "up"))
else:
self.after(150, lambda: self.anim_hover.animate_hover(self.clear_btn2, int("e5e5e5", 16), int("ffffff", 16), int("20202", 16), 10, "up"))
else:
if not non_click:
if self.appearance_mode_optionemenu.get() == "Темная" or self.appearance_mode_optionemenu.get() == "Dark":
self.after(150, lambda: self.anim_hover.animate_hover(self.clear_btn3, int("212121", 16), int("333333", 16), int("10101", 16), 10, "up"))
else:
self.after(150, lambda: self.anim_hover.animate_hover(self.clear_btn3, int("e5e5e5", 16), int("ffffff", 16), int("20202", 16), 10, "up"))
self.focus_set()
if self.tabview.get() == "База адресов" and textbox.get(0) != None:
lock_states_and_binds_during_refresh()
self.listbox.deactivate(0)
self.unbind("<Double-Button-1>")
self.bind("<Button-3>", lambda escape_entry: right_click())
self.unbind("<Delete>") # аналогичная подСТРАХовОЧКА для функции удаления
self.unbind("<BackSpace>")
self.unbind("<Down>")
self.unbind("<Up>")
self.unbind("<Left>")
self.unbind("<Right>")
self.unbind("<Return>")
self.unbind("<F8>")
textbox.delete(0.0, 'end')
return back_states_and_binds_after_refresh()
else:
textbox.configure(state="normal")
textbox.delete(0.0, 'end')
textbox.configure(state="disabled")
# Очистка поля счета элементов в базе при нажатии кнопки очистки listbox (ты че брэдман)
def clear_count():
self.unbind("<Double-Button-1>")
self.bind("<Button-3>", lambda escape_entry: right_click())
self.unbind("<Delete>") # аналогичная подСТРАХовОЧКА для функции удаления
self.unbind("<BackSpace>")
self.unbind("<Down>")
self.unbind("<Up>")
self.unbind("<Left>")
self.unbind("<Right>")
self.unbind("<Return>")
self.unbind("<F8>")
self.textbox3.configure(state="normal")
self.textbox3.delete(0.0, "end")
self.textbox3.configure(state="disabled")
# Очистка "Entry" с IP-адресами (не только) (заебись костыль, чисто выкрутился из ситуации неприятной)
def clear_entry(entry): # Замазка для комбобокса базы данных (всякие костылики хрумки нямки )
self.previous_selected = None
try:
for i in range(0, len(entry.get())):
entry.delete(i)
for i in range(0, len(entry.get())):
entry.delete(i)
return entry.icursor(0), entry.xview(0)
except:
entry.set("")
if not entry.is_focused:
entry.set_placeholder()
# Очистка "Entry" с IP PING и атрибутом (бля ну ты жук внатуре, выкрутился х2)
def clear_entry_ip(entry, combo):
if combo.get() == " None " or combo.get() == "/d" or combo.get() == "/j":
combo.set(value=" None ")
else:
combo.set(value="None")
for i in range(0, len(entry.get())):
entry.delete(i)
for i in range(0, len(entry.get())):
entry.delete(i)
return entry.icursor(0), entry.xview(0)
# Очистка "Entry" с IP TELNET и сбросом типа подключения (не надоело?)
def clear_entry_telnet(entry, radio):
radio.set(value=1)
self.entry3.configure(state="normal", border_color=("#979da2", "#565b5e"), text_color=("gray14", "gray84"))
for i in range(0, len(entry.get())):
entry.delete(i)
for i in range(0, len(entry.get())):
entry.delete(i)
return entry.icursor(0), entry.xview(0)
# Функция дисконнекта (пришлось разделить с обычной очисткой)
def clear_entry_baza(entry):
if self.tabview.get() == "База адресов" and entry.get() != "":
if self.listbox.curselection() != None:
self.listbox.deactivate(0)
self.previous_selected = None
entry.set("")
clear_count()
clear_entry(self.combobox_4)
entry.configure(state="disabled", border_color=("#8f8f8f", "#444444"), button_color=("#8f8f8f", "#444444"))
self.clear_btn3.configure(command=None)
self.help_btn_tab3.configure(command=None)
self.con_button.configure(state="disabled", fg_color="#0f334d")
self.search_button.configure(state="disabled", fg_color="#0f334d")
self.del_button.configure(state="disabled", fg_color="#94440B")
self.update_row_button.configure(state="disabled", fg_color="#0f334d")
self.add_button.configure(state="disabled", fg_color="#0f334d")
self.update_button.configure(state="disabled", fg_color="#0f334d")
self.textbox3.configure(state="disabled", border_color=("#8f8f8f", "#444444"))
if self.language == "Русский":
self.combobox_5.configure(placeholder_text="Требуется подключение к БД...")
else:
self.combobox_5.configure(placeholder_text="A database connection is required...")
clear_entry(self.combobox_5)
self.combobox_5.set_placeholder()
self.combobox_5.configure(state="disabled", border_color=("#8f8f8f", "#444444"), button_color=("#8f8f8f", "#444444"))
self.clear_btn_baza.configure(state="disabled", fg_color="#94440B", image=disconnect_disabled_img)
self.clear_btn_search.configure(state="disabled", fg_color="#94440B", image=clear_disabled_img)
self.combobox_4.bind("<Delete>", lambda del_var: clear_entry(self.combobox_4))
self.update_idletasks()
self.unbind("<Down>")
self.unbind("<Up>")
self.unbind("<Left>")
self.unbind("<Right>")
self.unbind("<Return>")
self.unbind("<F6>")
self.unbind("<F9>")
self.unbind("<F5>") # тута неточна
self.unbind("<Control-Delete>")
self.unbind("<Insert>")
self.unbind("<KeyPress-Control_L>")
self.unbind("<KeyRelease-Control_L>")
#self.listbox.delete(0.0, 'end')
try:
delete_items_in_batches(self.listbox, list(range(self.listbox.size())), self.listbox.size())
except:
delete_items_in_batches(self.listbox, list(range(self.listbox.size())), 1000)
entry.configure(state="normal", border_color=("#979da2", "#565b5e"), button_color=("#979da2", "#565b5e"), command=lambda combo_var: combo_focus(entry, flag=1))
entry.bind("<Return>", lambda combobox_4_var: show_db(name_db, self.listbox))
self.main_button_6.configure(state="normal", fg_color="#1F538D")
self.help_btn_tab3.configure(command=lambda: help(self.tabview.get()))
self.clear_btn3.configure(command=lambda: [clear_text(self.listbox), clear_count()])
if self.language == "Русский":
if self.alert_mode:
CTkMessagebox(opacity=self.opacity, message='Подключение закрыто!', title='Успех!', icon='check', master=self, button_width=self.alert_button_size)
else:
if self.alert_mode:
CTkMessagebox(opacity=self.opacity, message='Connection is closed!', title='Success!', icon='check', master=self, button_width=self.alert_button_size)
return self.after(100, lambda: [self.focus_set(), self.bind("<F9>", lambda open_help: help(self.tabview.get()))])
else:
return
# Формат IP-аддреса для поля "Entry" (нереальная дрочка и попаболь)
def entry_mask_check(text, valid, entry):
ip = re.findall("^\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3}$", text.get())
if len(ip) != 1:
text.set(valid[0])
if ip:
valid[0] = ip[0]
# прыжок на некст 3 цифры
cursor_position = entry.index("insert")
index2 = ip[0][:cursor_position - 1].rfind(u".")
if cursor_position - index2 == 4:
entry.icursor(cursor_position + 1)
# Функция подключения к БД и вывода из нее информации в listbox, также подсчет элементов в ней (ща мы бля выведем твою так называемую БАЗУУУ)
def show_db(name, listbox):
check_db_eng_name(name)
self.main_button_6.configure(state="disabled", fg_color="#0f334d")
self.combobox_4.configure(state="readonly")
self.unbind("<Double-Button-1>")
self.bind("<Button-3>", lambda escape_entry: right_click())
self.unbind("<Delete>") # аналогичная подСТРАХовОЧКА для функции удаления
self.unbind("<BackSpace>")
self.unbind("<Down>")
self.unbind("<Up>")
self.unbind("<Left>")
self.unbind("<Right>")
self.unbind("<Return>")
self.unbind("<F8>")
self.unbind("<Insert>")
self.unbind("<KeyPress-Control_L>")
self.unbind("<KeyRelease-Control_L>")
self.unbind("<F5>")
self.unbind("<F9>")
self.unbind("<Control-Delete>")
self.combobox_4.unbind("<Delete>")
self.combobox_4.unbind("<Return>")
self.textbox3.delete(0.0, "end")
# listbox.delete(0.0, "end")
try:
delete_items_in_batches(self.listbox, list(range(self.listbox.size())), self.listbox.size())
except:
delete_items_in_batches(self.listbox, list(range(self.listbox.size())), 1000)
try:
with sqlite3.connect("db/" + self.name + ".db") as db:
cursor = db.cursor()
cursor.execute("""SELECT ip_address,name FROM net ORDER BY ip_address""")
list2 = cursor.fetchall()
cursor.execute('SELECT COUNT(*) FROM net')
self.total_users = cursor.fetchone()[0]
self.textbox3.configure(state="normal", border_color=("#979da2", "#565b5e"))
self.textbox3.insert('end', self.total_users)
self.textbox3.configure(state="disabled")
db.commit()
cursor.close()
self.con_button.configure(state="normal", fg_color="#1F538D")
self.search_button.configure(state="normal", fg_color="#1F538D")
self.del_button.configure(state="normal", fg_color="#f4740b")
self.update_row_button.configure(state="normal", fg_color="#1F538D")
self.add_button.configure(state="normal", fg_color="#1F538D")
self.update_button.configure(state="normal", fg_color="#1F538D")
if self.language == "Русский":
self.combobox_5.configure(state="normal", border_color=("#979da2", "#565b5e"), button_color=("#979da2", "#565b5e"), placeholder_text="Выберите из списка или введите...")
else:
self.combobox_5.configure(state="normal", border_color=("#979da2", "#565b5e"), button_color=("#979da2", "#565b5e"), placeholder_text="Select from the list or enter...")
self.clear_btn_baza.configure(state="normal", fg_color="#f4740b", image=disconnect_img)
self.clear_btn_search.configure(state="normal", fg_color="#f4740b", image=clear_img)
self.combobox_4.configure(state="readonly", command=lambda combo_var: combo_focus(self.combobox_4, flag=2))
self.main_button_6.configure(state="disabled", fg_color="#0f334d")
self.update_idletasks()
self.insert_with_preview_async(list2)
if self.tabview.get() != "База адресов":
nav_tab4()
self.unbind("<F5>")
self.unbind("<Insert>")
self.unbind("<KeyPress-Control_L>")
self.unbind("<KeyRelease-Control_L>")
self.unbind("<Control-Delete>")
if self.language == "Русский":
if self.alert_mode:
CTkMessagebox(opacity=self.opacity, message=f'Подключение к БД: «{self.rus_name}»\nпрошло успешно!', title='Успех!', icon='check', master=self, button_width=self.alert_button_size)
else:
if self.alert_mode:
CTkMessagebox(opacity=self.opacity, message=f'Connection to DB: «{self.name}»\nwas successful!', title='Success!', icon='check', master=self, button_width=self.alert_button_size)
return self.after(100, lambda: self.focus_set()), self.after(120, lambda: [self.bind("<F6>", lambda del_var: clear_entry_baza(self.combobox_4)), self.bind("<Insert>", lambda insert_var: add_item(name_db, self.listbox)), self.bind("<KeyPress-Control_L>", on_ctrl_press), self.bind("<KeyRelease-Control_L>", on_ctrl_release), self.bind("<F5>", lambda refresh_var: refresh_db(name_db, self.listbox)), self.bind("<F9>", lambda open_help: help(self.tabview.get()))])
except:
self.combobox_4.configure(state="normal")
self.after(150, lambda: [self.combobox_4.focus_set(), self.combobox_4.bind("<Return>", lambda combobox_4_var: show_db(name_db, self.listbox)), self.combobox_4.bind("<Delete>", lambda del_var: clear_entry(self.combobox_4))])
self.main_button_6.configure(state="normal", fg_color="#1F538D")
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Такой БД не существует!\nПовторите ввод или выберите БД из списка.', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='This database does not exist!\nPlease re-enter or select a database from the list.', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
def lock_states_and_binds_during_refresh():
antibug() # Пока в тесте
self.combobox_4.configure(state="disabled", border_color=("#8f8f8f", "#444444"), button_color=("#8f8f8f", "#444444"))
self.clear_btn3.configure(command=None)
self.help_btn_tab3.configure(command=None)
self.update_button.configure(state="disabled", fg_color="#0f334d")
self.add_button.configure(state="disabled", fg_color="#0f334d")
self.update_row_button.configure(state="disabled", fg_color="#0f334d")
self.del_button.configure(state="disabled", fg_color="#94440B")
self.combobox_5.configure(state="disabled", border_color=("#8f8f8f", "#444444"), button_color=("#8f8f8f", "#444444"))
self.search_button.configure(state="disabled", fg_color="#0f334d")
self.con_button.configure(state="disabled", fg_color="#0f334d")
self.after(50, lambda: self.clear_btn_baza.configure(state="disabled", fg_color="#94440B", image=disconnect_disabled_img))
self.after(150, lambda: self.clear_btn_search.configure(state="disabled", fg_color="#94440B", image=clear_disabled_img))
self.update_idletasks()
self.combobox_5.unbind("<Down>")
self.combobox_5.unbind("<Return>")
self.combobox_4.unbind("<Down>")
self.unbind("<Insert>")
self.unbind("<KeyPress-Control_L>")
self.unbind("<KeyRelease-Control_L>")
self.unbind("<F5>")
self.unbind("<F6>")
self.unbind("<F9>")
self.unbind("<Control-Delete>")
return self.after(180, lambda: [app.update(), app.update_idletasks()]) # пока спорно (профит был ток на интеле)
def back_states_and_binds_after_refresh():
self.combobox_4.configure(state="readonly", border_color=("#979da2", "#565b5e"), button_color=("#979da2", "#565b5e"))
self.clear_btn3.configure(command=lambda: [clear_text(self.listbox), clear_count()])
self.help_btn_tab3.configure(command=lambda: help(self.tabview.get()))
self.con_button.configure(state="normal", fg_color="#1F538D")
self.update_button.configure(state="normal", fg_color="#1F538D")
self.add_button.configure(state="normal", fg_color="#1F538D")
self.update_row_button.configure(state="normal", fg_color="#1F538D")
self.del_button.configure(state="normal", fg_color="#f4740b")
self.combobox_5.configure(state="normal", border_color=("#979da2", "#565b5e"), button_color=("#979da2", "#565b5e"))
self.search_button.configure(state="normal", fg_color="#1F538D")
self.after(50, lambda: self.clear_btn_baza.configure(state="normal", fg_color="#f4740b", image=disconnect_img))
self.after(150, lambda: self.clear_btn_search.configure(state="normal", fg_color="#f4740b", image=clear_img))
self.after(100, lambda: [self.combobox_4.bind("<Down>", lambda open_var: self.combobox_4._clicked()), self.bind("<F5>", lambda refresh_var: refresh_db(name_db, self.listbox)), self.bind("<F9>", lambda open_help: help(self.tabview.get()))])
self.after(101, lambda: [self.bind("<Insert>", lambda insert_var: add_item(name_db, self.listbox)), self.bind("<KeyPress-Control_L>", on_ctrl_press), self.bind("<KeyRelease-Control_L>", on_ctrl_release)])
self.after(102, lambda: [self.combobox_5.bind("<Down>", lambda open_var: self.combobox_5._clicked()), self.combobox_5.bind("<Return>", lambda combobox_5_var: search_item(name_db, self.listbox, self.combobox_5.get()))])
self.after(103, lambda: [self.bind("<F6>", lambda del_var: clear_entry_baza(self.combobox_4))])
self.update_idletasks()
if self.tabview.get() != "База адресов":
nav_tab4()
self.unbind("<F5>")
self.unbind("<Insert>")
self.unbind("<KeyPress-Control_L>")
self.unbind("<KeyRelease-Control_L>")
self.unbind("<Control-Delete>")
return self.after(180, lambda: [app.update(), app.update_idletasks()]) # пока спорно
# Оптимизация удаления (для более быстрой работы с базой, заебала эта красота, слишком медленно было)
def delete_items_in_batches(listbox, indices, batch_size):
"""Удаляет элементы из Listbox партиями."""
for i in range(0, len(indices), batch_size):
batch = indices[i:i + batch_size]
for index in sorted(batch, reverse=True): # Удаляем в обратном порядке, чтобы избежать смещения индексов
listbox.delete(index)
self.listbox._parent_canvas.yview("moveto", 0)
# Функция обновления БД (по сути повторный её вывод, но с другим уведомлением лол) (приколист)))))
def refresh_db(name, listbox):
check_db_eng_name(name)
if self.listbox.curselection() != None:
self.listbox.deactivate(0)
lock_states_and_binds_during_refresh()
self.unbind("<Double-Button-1>")
self.bind("<Button-3>", lambda escape_entry: right_click())
self.unbind("<Delete>") # аналогичная подСТРАХовОЧКА для функции удаления
self.unbind("<BackSpace>")
self.unbind("<Down>")
self.unbind("<Up>")
self.unbind("<Left>")
self.unbind("<Right>")
self.unbind("<Return>")
self.unbind("<F8>")
self.textbox3.configure(state="normal")
self.textbox3.delete(0.0, "end")
# listbox.delete(0.0, "end")
try:
delete_items_in_batches(self.listbox, list(range(self.listbox.size())), self.listbox.size())
except:
delete_items_in_batches(self.listbox, list(range(self.listbox.size())), 1000)
try:
with sqlite3.connect("db/" + self.name + ".db") as db:
cursor = db.cursor()
cursor.execute("""SELECT ip_address, name FROM net ORDER BY ip_address""")
list2 = cursor.fetchall()
self.insert_with_preview_async(list2)
cursor.execute('SELECT COUNT(*) FROM net')
self.total_users = cursor.fetchone()[0]
self.textbox3.insert('end', self.total_users)
self.textbox3.configure(state="disabled")
db.commit()
cursor.close()
back_states_and_binds_after_refresh()
if self.language == "Русский":
if self.alert_mode:
CTkMessagebox(opacity=self.opacity, message='Данные обновлены!', title='Успех!', icon='check', master=self, button_width=self.alert_button_size)
return
else:
if self.alert_mode:
CTkMessagebox(opacity=self.opacity, message='Data refreshed!', title='Success!', icon='check', master=self, button_width=self.alert_button_size)
return
except:
if self.language == "Русский":
CTkMessagebox(opacity=self.opacity, message='Требуется подключение к БД!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
CTkMessagebox(opacity=self.opacity, message='A database connection is required!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
return self.after(100, lambda: [self.combobox_4.configure(state="readonly", border_color=("#979da2", "#565b5e"), button_color=("#979da2", "#565b5e")), self.combobox_4.bind("<Down>", lambda open_var: self.combobox_4._clicked())]), self.bind("<F5>", lambda refresh_var: refresh_db(name_db, self.listbox)), self.after(100, lambda: [self.bind("<Insert>", lambda insert_var: add_item(name_db, self.listbox)), self.bind("<KeyPress-Control_L>", on_ctrl_press), self.bind("<KeyRelease-Control_L>", on_ctrl_release)]), self.after(100, lambda: [self.combobox_5.bind("<Down>", lambda open_var: self.combobox_5._clicked()), self.combobox_5.bind("<Return>", lambda combobox_5_var: search_item(name_db, self.listbox, self.combobox_5.get()))]), self.after(100, lambda: [self.bind("<F6>", lambda del_var: clear_entry_baza(self.combobox_4))])
# Обновление без хуйни (почти) для поиска
def refresh_db_after_search(name, listbox):
check_db_eng_name(name)
if self.listbox.curselection() != None:
self.listbox.deactivate(0)
self.unbind("<Double-Button-1>")
self.bind("<Button-3>", lambda escape_entry: right_click())
self.unbind("<Delete>") # аналогичная подсТРАХовОЧКА для функции удаления
self.unbind("<BackSpace>")
self.unbind("<Down>")
self.unbind("<Up>")
self.unbind("<Left>")
self.unbind("<Right>")
self.unbind("<Return>")
self.unbind("<F8>")
self.textbox3.configure(state="normal")
self.textbox3.delete(0.0, "end")
try:
with sqlite3.connect("db/" + self.name + ".db") as db:
cursor = db.cursor()
cursor.execute("""SELECT ip_address, name FROM net ORDER BY ip_address""")
list2 = cursor.fetchall()
self.insert_with_preview_async(list2)
cursor.execute('SELECT COUNT(*) FROM net')
self.total_users = cursor.fetchone()[0]
self.textbox3.insert('end', self.total_users)
self.textbox3.configure(state="disabled")
db.commit()
cursor.close()
if self.language == "Русский":
CTkMessagebox(opacity=self.opacity, message='Ничего не найдено!\nПовторите поиск.', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
CTkMessagebox(opacity=self.opacity, message='Nothing was found!\nRepeat the search.', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
return self.after(195, lambda: self.combobox_5.focus_set())
except:
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Требуется подключение к БД!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='A database connection is required!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
# Обновление без хуйни (почти), используется при выборе базы уже после подключения к первой
def refresh_db_after_reconnect(name, listbox):
check_db_eng_name(name)
if self.listbox.curselection() != None:
self.listbox.deactivate(0)
lock_states_and_binds_during_refresh()
self.unbind("<Double-Button-1>")
self.bind("<Button-3>", lambda escape_entry: right_click())
self.unbind("<Delete>") # аналогичная подСТРАХовОЧКА для функции удаления
self.unbind("<BackSpace>")
self.unbind("<Down>")
self.unbind("<Up>")
self.unbind("<Left>")
self.unbind("<Right>")
self.unbind("<Return>")
self.textbox3.configure(state="normal")
self.textbox3.delete(0.0, "end")
# listbox.delete(0.0, "end")
try:
delete_items_in_batches(self.listbox, list(range(self.listbox.size())), self.listbox.size())
except:
delete_items_in_batches(self.listbox, list(range(self.listbox.size())), 1000)
try:
with sqlite3.connect("db/" + self.name + ".db") as db:
cursor = db.cursor()
cursor.execute("""SELECT ip_address, name FROM net ORDER BY ip_address""")
list2 = cursor.fetchall()
self.insert_with_preview_async(list2)
cursor.execute('SELECT COUNT(*) FROM net')
self.total_users = cursor.fetchone()[0]
self.textbox3.insert('end', self.total_users)
self.textbox3.configure(state="disabled")
db.commit()
cursor.close()
back_states_and_binds_after_refresh()
if self.language == "Русский":
if self.alert_mode:
CTkMessagebox(opacity=self.opacity, message=f'Вы успешно переподключились к\nБД: «{self.rus_name}»!', title='Успех!', icon='check', master=self, button_width=self.alert_button_size)
return
else:
if self.alert_mode:
CTkMessagebox(opacity=self.opacity, message=f'You have successfully reconnected \nto the DB: «{self.name}»!', title='Success!', icon='check', master=self, button_width=self.alert_button_size)
return
except:
return
def check_db_eng_name(name):
self.name = name.get()
self.rus_name = name.get()
if name.get() == "Коммутаторы":
self.name = "Switches"
elif name.get() == "Маршрутизаторы":
self.name = "Routers"
elif name.get() == "Мультиплексоры":
self.name = "Multiplexers"
elif name.get() == "Электропитание":
self.name = "Power supply"
elif name.get() == "Телефоны":
self.name = "Phones"
elif name.get() == "Другое":
self.name = "Other"
# Обновление внатуре без хуйни (отвечаю) для скалинг ивента (после того как заново отрисовали листбоксы поске изм-я скейла)
def refresh_db_after_scale(name, listbox):
check_db_eng_name(name)
self.unbind("<Double-Button-1>")
self.bind("<Button-3>", lambda escape_entry: right_click())
self.unbind("<Delete>") # аналогичная подСТРАХовОЧКА для функции удаления
self.unbind("<BackSpace>")
self.unbind("<Down>")
self.unbind("<Up>")
self.unbind("<Left>")
self.unbind("<Right>")
self.unbind("<Return>")
self.unbind("<F8>")
self.textbox3.configure(state="normal")
self.textbox3.delete(0.0, "end")
# listbox.delete(0.0, "end")
try:
delete_items_in_batches(self.listbox, list(range(self.listbox.size())), self.listbox.size())
except:
delete_items_in_batches(self.listbox, list(range(self.listbox.size())), 1000)
try:
with sqlite3.connect("db/" + self.name + ".db") as db:
cursor = db.cursor()
cursor.execute("""SELECT ip_address, name FROM net ORDER BY ip_address""")
list2 = cursor.fetchall()
self.insert_with_preview_async(list2)
cursor.execute('SELECT COUNT(*) FROM net')
self.total_users = cursor.fetchone()[0]
self.textbox3.insert('end', self.total_users)
self.textbox3.configure(state="disabled")
db.commit()
cursor.close()
except:
return
# Функция выбора элемента в списке lisbox (содержащем БД) и последующего подключения (ультаа)
def selected_item():
self.unbind("<Double-Button-1>")
try:
member = self.listbox.curselection()
list_member = self.listbox.get(member)
s = " "
s2 = (s.join(list_member))
head, sep, tail = s2.partition(s)
con_type_window = SelectCon()
con_type_window(head, self.appearance_mode_optionemenu.get(), self.scaling_optionemenu.get(), self, self.opacity, self.language)
if con_type_window.get() == 1:
self.bind('<Escape>', lambda close: self.close_app())
self.scaling_optionemenu.set(value="100%")
after_close_terminals()
except:
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Выберите элемент для подключения!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='Select an item to connect!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
# Функция удания элемента из БД (вывод обновленной базы после удаления) (осторожнее шевели ручками)
def delete_item(name, listbox):
check_db_eng_name(name)
self.unbind("<Double-Button-1>")
self.previous_selected = None
try:
member = self.listbox.curselection()
list_member = self.listbox.get(member)
s = " "
s2 = (s.join(list_member))
head, sep, tail = s2.partition(s)
sql_string = ('"' + head + '"')
except:
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='Выберите элемент для удаления!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='Select the item to delete!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
if self.language == "Русский":
msg = CTkMessagebox(opacity=self.opacity, message='Вы уверены?', title='Внимание!', icon='warning', option_1="Отмена", option_2="Да", master=self, button_width=200)
else:
msg = CTkMessagebox(opacity=self.opacity, message='Are you sure?', title='Attention!', icon='warning', option_1="Cancel", option_2="Yes", master=self, button_width=200)
msg.focus_set()
response = msg.get()
if response == "Отмена" or response == "Cancel":
return simulate_ctrl_release()
if response == "Да" or response == "Yes":
try:
with sqlite3.connect("db/" + self.name + ".db") as db:
lock_states_and_binds_during_refresh()
cursor = db.cursor()
query = 'DELETE FROM net WHERE ip_address =' + sql_string
cursor.execute(query)
db.commit()
cursor.close()
cursor2 = db.cursor()
cursor2.execute("""SELECT ip_address, name FROM net ORDER BY ip_address""")
self.textbox3.configure(state="normal")
self.textbox3.delete(0.0, "end")
# listbox.delete(0.0, "end")
try:
delete_items_in_batches(self.listbox, list(range(self.listbox.size())), self.listbox.size())
except:
delete_items_in_batches(self.listbox, list(range(self.listbox.size())), 1000)
list2 = cursor2.fetchall()
self.insert_with_preview_async(list2)
cursor2.execute('SELECT COUNT(*) FROM net')
self.total_users = cursor2.fetchone()[0]
self.textbox3.insert('end', self.total_users)
self.textbox3.configure(state="disabled")
cursor2.close()
back_states_and_binds_after_refresh()
if self.language == "Русский":
if self.alert_mode:
CTkMessagebox(opacity=self.opacity, message='Данные успешно удалены!', title='Успех!', icon='check', master=self, button_width=self.alert_button_size)
return
else:
if self.alert_mode:
CTkMessagebox(opacity=self.opacity, message='The data has been Success!fully deleted!', title='Success!', icon='check', master=self, button_width=self.alert_button_size)
return
except:
self.previous_selected = None
back_states_and_binds_after_refresh()
if self.language == "Русский":
return CTkMessagebox(opacity=self.opacity, message='База данных пуста!', title='Ошибка!', icon='cancel', master=self, button_width=self.alert_button_size)
else:
return CTkMessagebox(opacity=self.opacity, message='The database is empty!', title='Error!', icon='cancel', master=self, button_width=self.alert_button_size)
# Массовое удаление выделения на кантроул (геноцид.)
def delete_items(name, listbox):
check_db_eng_name(name)
self.unbind("<Double-Button-1>")
self.previous_selected = None
members = self.listbox.curselection()
count = len(members)
if self.language == "Русский":
if count == 0:
simulate_ctrl_release()
return CTkMessagebox(opacity=self.opacity, message='Выберите элементы для удаления!', title='Ошибка!', icon='cancel', multiselection_on=True, master=self, button_width=self.alert_button_size)
else:
if count == 0:
simulate_ctrl_release()
return CTkMessagebox(opacity=self.opacity, message='Select any items to delete!', title='Error!', icon='cancel', multiselection_on=True, master=self, button_width=self.alert_button_size)
if self.language == "Русский":
msg = CTkMessagebox(opacity=self.opacity, message=f'Вы уверены что хотите\nудалить {count} выбранных элементов?', title='Внимание!', icon='warning', option_1="Отмена", option_2="Да", multiselection_on=True, master=self, button_width=200)
else:
msg = CTkMessagebox(opacity=self.opacity, message=f'Are you sure you want\nto delete {count} selected items?', title='Attention!', icon='warning', option_1="Cancel", option_2="Yes", multiselection_on=True, master=self, button_width=200)
msg.focus_set()
response = msg.get()
if response == "Отмена" or response == "Cancel":
return simulate_ctrl_release()
if response == "Да" or response == "Yes":
simulate_ctrl_release()
sql_strings = []
for index in members:
list_member = self.listbox.get(index)
s = " "
s2 = (s.join(list_member))
head, sep, tail = s2.partition(s)
sql_string = ('"' + head + '"')
sql_strings.append(sql_string)
try:
with sqlite3.connect("db/" + self.name + ".db") as db:
lock_states_and_binds_during_refresh()
for sql_string in sql_strings:
cursor = db.cursor()