-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.py
2289 lines (1912 loc) · 89.2 KB
/
main.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
# ///////////////////////////////////////////////////////////////
#
# BY: WANDERSON M.PIMENTA
# PROJECT MADE WITH: Qt Designer and PySide6
# V: 1.0.0
#
# This project can be used freely for all uses, as long as they maintain the
# respective credits only in the Python scripts, any information in the visual
# interface (GUI) can be modified without any implication.
#
# There are limitations on Qt licenses if you want to use your products
# commercially, I recommend reading them on the official website:
# https://doc.qt.io/qtforpython/licenses.html
#
# ///////////////////////////////////////////////////////////////
import codecs
import fileinput
import shutil
import subprocess
import sys
import socket as py_socket
import socket
import os
import platform
import threading
import zipfile
import re
from datetime import datetime
import multiprocessing
from glob import glob
from threading import Thread
from tkinter import Tk
import xml.etree.ElementTree as ET
import chardet
import psutil
from MySignal import my_signal
# IMPORT / GUI AND MODULES AND WIDGETS
# ///////////////////////////////////////////////////////////////
from modules import *
from tool.zip import zip_file
from widgets import *
os.environ["QT_FONT_DPI"] = "96" # FIX Problem for High DPI and Scale above 100%
from tool.socket import *
import requests
from flask import Flask, request, send_file
# SET AS GLOBAL WIDGETS
# ///////////////////////////////////////////////////////////////
widgets = None
global dir
# if getattr(sys, 'frozen', False):
# # 如果是打包后的可执行文件
# dir = sys._MEIPASS+"/env"
# else:
# # 如果是直接运行的脚本
dir = os.getcwd() + "/env"
af = Flask(__name__)
af.config['JSON_AS_ASCII'] = False
method_info_dict = {
'print': '用于打印输出',
'if': '条件语句,根据条件判断执行不同的代码块',
'else': '条件语句的附加分支,如果上面的条件不满足,则执行else块的代码',
'for': '循环语句,用于遍历一个可迭代对象',
'while': '循环语句,根据条件循环执行代码块',
'def': '定义函数',
'import': '导入其他模块',
'from': '从某个模块中导入特定的函数或变量'
}
class PythonHighlighter(QSyntaxHighlighter):
def __init__(self, parent=None):
super().__init__(parent)
self.highlighting_rules = []
# 定义关键字的高亮格式
keyword_format = QTextCharFormat()
keyword_format.setForeground(Qt.yellow)
keyword_format.setFontWeight(QFont.Bold)
keyword_format.setFontPointSize(12)
# 定义字符串的高亮格式
string_format = QTextCharFormat()
string_format.setForeground(Qt.darkGreen)
string_format.setFontPointSize(10)
# 定义数字的高亮格式
number_format = QTextCharFormat()
number_format.setForeground(Qt.darkMagenta)
number_format.setFontPointSize(10)
# 定义注释的高亮格式
comment_format = QTextCharFormat()
comment_format.setForeground(Qt.darkGray)
comment_format.setFontItalic(True)
comment_format.setFontPointSize(10)
# 添加关键字和对应的高亮格式到规则列表
for keyword in method_info_dict:
pattern = QRegularExpression("\\b" + keyword + "\\b", QRegularExpression.CaseInsensitiveOption)
rule = (pattern, keyword_format)
self.highlighting_rules.append(rule)
# 添加字符串的规则
string_pattern = QRegularExpression("\".*?\"")
string_rule = (string_pattern, string_format)
self.highlighting_rules.append(string_rule)
# 添加数字的规则
number_pattern = QRegularExpression("\\b\\d+\\.?\\d*\\b")
number_rule = (number_pattern, number_format)
self.highlighting_rules.append(number_rule)
# 添加注释的规则
comment_pattern = QRegularExpression("//[^\n]*")
comment_rule = (comment_pattern, comment_format)
self.highlighting_rules.append(comment_rule)
# 添加更多语法元素和相应的高亮格式
# ...
def highlightBlock(self, text):
for pattern, format in self.highlighting_rules:
iterator = pattern.globalMatch(text)
while iterator.hasNext():
match = iterator.next()
self.setFormat(match.capturedStart(), match.capturedLength(), format)
class LineNumberArea(QWidget):
def __init__(self, editor: QPlainTextEdit):
super().__init__(editor.editor)
self.editor = editor
def sizeHint(self):
return QSize(self.editor.lineNumberAreaWidth(), 0)
def paintEvent(self, event):
self.editor.lineNumberAreaPaintEvent(event)
class CodeEditor(QWidget):
def __init__(self, editor: QPlainTextEdit,parent=None):
super().__init__(parent)
self.editor = editor
self.lineNumberArea = LineNumberArea(self)
self.editor.blockCountChanged.connect(self.updateLineNumberAreaWidth)
self.editor.updateRequest.connect(self.updateLineNumberArea)
self.editor.cursorPositionChanged.connect(self.highlightCurrentLine)
self.editor.textChanged.connect(self.text_changed)
self.updateLineNumberAreaWidth(0)
def text_changed(self):
# 将光标移动到文本末尾
cursor = self.editor.textCursor()
cursor.movePosition(QTextCursor.End)
self.editor.setTextCursor(cursor)
def lineNumberAreaWidth(self):
digits = 1
max_value = max(1, self.editor.blockCount())
while max_value >= 10:
max_value /= 10
digits += 1
space = 3 + self.editor.fontMetrics().horizontalAdvance('9') * digits
return space
def updateLineNumberAreaWidth(self, _):
self.editor.setViewportMargins(self.lineNumberAreaWidth(), 0, 0, 0)
def updateLineNumberArea(self, rect, dy):
if dy:
self.lineNumberArea.scroll(0, dy)
else:
self.lineNumberArea.update(0, rect.y(), self.lineNumberArea.width(), rect.height())
if rect.contains(self.editor.viewport().rect()):
self.updateLineNumberAreaWidth(0)
# self.editor.verticalScrollBar().setValue(self.editor.verticalScrollBar().maximum())
def resizeEvent(self, event):
self.editor.resizeEvent(event)
cr = self.editor.contentsRect()
self.lineNumberArea.setGeometry(QRect(cr.left(), cr.top(), self.lineNumberAreaWidth(), cr.height()))
def lineNumberAreaPaintEvent(self, event):
painter = QPainter(self.lineNumberArea)
painter.fillRect(event.rect(), Qt.lightGray)
block = self.editor.firstVisibleBlock()
block_number = block.blockNumber()
top = int(self.editor.blockBoundingGeometry(block).translated(self.editor.contentOffset()).top())
bottom = top + int(self.editor.blockBoundingRect(block).height())
while block.isValid() and top <= event.rect().bottom():
if block.isVisible() and bottom >= event.rect().top():
number = str(block_number + 1)
painter.setPen(Qt.black)
painter.drawText(0, top, self.lineNumberArea.width(), self.editor.fontMetrics().height(),
Qt.AlignRight, number)
block = block.next()
top = bottom
bottom = top + int(self.editor.blockBoundingRect(block).height())
block_number += 1
def highlightCurrentLine(self):
extra_selections = []
if not self.editor.isReadOnly():
selection = QTextEdit.ExtraSelection()
style_sheet = "color: #2F4F4F;"
line_color = QColor(style_sheet).lighter(160)
selection.format.setBackground(line_color)
selection.format.setProperty(QTextFormat.FullWidthSelection, True)
selection.cursor = self.editor.textCursor()
selection.cursor.clearSelection()
extra_selections.append(selection)
self.editor.setExtraSelections(extra_selections)
class MainWindow(QMainWindow):
global lognum
lognum = 1
global buildlognum
buildlognum = 1
def __init__(self):
QMainWindow.__init__(self)
self.setMinimumSize(200, 200)
self.setMaximumSize(1800, 1400)
# SET AS GLOBAL WIDGETS
# ///////////////////////////////////////////////////////////////
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
global widgets
widgets = self.ui
print(get_ip())
self.completion_list = []
self.current_index = 0
# USE CUSTOM TITLE BAR | USE AS "False" FOR MAC OR LINUX
# ///////////////////////////////////////////////////////////////
Settings.ENABLE_CUSTOM_TITLE_BAR = True
# APP NAME
# ///////////////////////////////////////////////////////////////
title = "GUI"
description = "MagicHands-IDE"
# APPLY TEXTS
self.setWindowTitle(title)
widgets.titleRightInfo.setText(description)
# TOGGLE MENU
# ///////////////////////////////////////////////////////////////
widgets.toggleButton.clicked.connect(lambda: UIFunctions.toggleMenu(self, True))
# SET UI DEFINITIONS
# ///////////////////////////////////////////////////////////////
UIFunctions.uiDefinitions(self)
# QTableWidget PARAMETERS
# ///////////////////////////////////////////////////////////////
widgets.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
# BUTTONS CLICK
# ///////////////////////////////////////////////////////////////
# LEFT MENUS
widgets.btn_home.clicked.connect(self.buttonClick)
# widgets.btn_widgets.clicked.connect(self.buttonClick)
widgets.btn_debug.clicked.connect(self.buttonClick)
widgets.btn_build.clicked.connect(self.buttonClick)
widgets.btn_serve.clicked.connect(self.buttonClick)
widgets.btn_stop.clicked.connect(self.buttonClick)
widgets.btn_start.clicked.connect(self.buttonClick)
widgets.btn_startcopy.clicked.connect(self.buttonClick)
widgets.btn_ui.clicked.connect(self.buttonClick)
widgets.btn_xml.clicked.connect(self.buttonClick)
widgets.btn_debugfile.clicked.connect(self.buttonClick)
widgets.btn_pro.clicked.connect(self.buttonClick)
widgets.btn_profile.clicked.connect(self.buttonClick)
widgets.btn_proopen.clicked.connect(self.buttonClick)
widgets.btn_exit.clicked.connect(self.buttonClick)
widgets.btn_buildico.clicked.connect(self.buttonClick)
widgets.btn_buildpro.clicked.connect(self.buttonClick)
widgets.btn_buildyes.clicked.connect(self.buttonClick)
# widgets.edit_buildv.clicked.connect(self.buttonClick)
# widgets.edit_buildico.clicked.connect(self.buttonClick)
# widgets.edit_buildpkg.clicked.connect(self.buttonClick)
# widgets.edit_buildpro.clicked.connect(self.buttonClick)
# widgets.edit_buildname.clicked.connect(self.buttonClick)
my_signal.setResult.connect(self.logd)
my_signal.setResult2.connect(self.logd1)
tmpCursor = self.ui.logd.textCursor()
tmpCursor.setPosition(0)
self.ui.logd.setTextCursor(tmpCursor)
tmpCursor = self.ui.buidlod.textCursor()
tmpCursor.setPosition(0)
self.ui.buidlod.setTextCursor(tmpCursor)
self.text_edit = self.ui.daima
style_sheet = "color: white;"
self.text_edit.setStyleSheet(style_sheet)
font = QFont("SimSun", 3) # 设置字体名称为"SimSun",字体大小为12
self.text_edit.setFont(font)
self.text_edit.setGeometry(0, 0, 800, 500)
self.text_edit.textChanged.connect(self.handle_text_changed)
self.text_edit.installEventFilter(self) # 安装事件过滤器以捕获按键事件
self.list_view = self.ui.buquan
self.list_view.setFixedSize(200, 200)
self.list_view.hide()
self.list_view.setSelectionMode(QListView.SingleSelection)
self.list_view.clicked.connect(self.insert_completion)
self.info_edit = self.ui.zhushi
self.info_edit.setGeometry(200, 0, 600, 500)
self.info_edit.setReadOnly(True)
self.ui.tabWidget.setStyleSheet("QTabBar::tab { background-color: rgb(33, 37, 43); } QTabBar::tab:tab {background-color: rgb(33, 37, 43);font:13pt '宋体';color: white;};")
# self.ui.logd.setStyleSheet("color:#00ff00;")
启动判断(0)
my_signal.setResult.emit("欢迎使用---当前版本1.0", 100, 184, 100)
PythonHighlighter(self.text_edit.document())
CodeEditor(self.ui.daima,self)
# EXTRA LEFT BOX
def openCloseLeftBox():
print()
# UIFunctions.toggleLeftBox(self, True)
widgets.toggleLeftBox.clicked.connect(openCloseLeftBox)
widgets.extraCloseColumnBtn.clicked.connect(openCloseLeftBox)
# EXTRA RIGHT BOX
def openCloseRightBox():
UIFunctions.toggleRightBox(self, True)
widgets.settingsTopBtn.clicked.connect(openCloseRightBox)
# SHOW APP
# ///////////////////////////////////////////////////////////////
self.show()
# SET CUSTOM THEME
# ///////////////////////////////////////////////////////////////
useCustomTheme = False
themeFile = "themes\py_dracula_light.qss"
# SET THEME AND HACKS
if useCustomTheme:
# LOAD AND APPLY STYLE
UIFunctions.theme(self, themeFile, True)
# SET HACKS
AppFunctions.setThemeHack(self)
# SET HOME PAGE AND SELECT MENU
# ///////////////////////////////////////////////////////////////
widgets.stackedWidget.setCurrentWidget(widgets.home)
widgets.btn_home.setStyleSheet(UIFunctions.selectMenu(widgets.btn_home.styleSheet()))
# BUTTONS CLICK
# Post here your functions for clicked buttons
# ///////////////////////////////////////////////////////////////
# 创建进程对象,同时传递参数
thread = threading.Thread(target=copy_gradle)
thread.start()
thread = threading.Thread(target=self.auto_save,args=(os.getcwd()+"/备份.txt",10,))
thread.start()
def eventFilter(self, obj, event):
if obj == self.text_edit and event.type() == QKeyEvent.KeyPress and event.key() == Qt.Key_Tab:
self.complete_current_word()
return True
if obj == self.text_edit and event.type() == QKeyEvent.KeyPress and (
event.key() == Qt.Key_Return or event.key() == Qt.Key_Enter):
self.text_edit.insertPlainText("\n")
return True
if obj == self.text_edit and event.type() == QKeyEvent.KeyPress:
key = event.key()
if key == Qt.Key_Up:
self.current_index -= 1
if self.current_index < 0:
self.current_index = len(self.completion_list) - 1
self.update_completion_list()
self.update_info_edit()
return True
elif key == Qt.Key_Down:
self.current_index += 1
if self.current_index >= len(self.completion_list):
self.current_index = 0
self.update_completion_list()
self.update_info_edit()
return True
elif key == Qt.Key_Return or key == Qt.Key_Enter:
self.insert_completion(self.list_view.currentIndex())
return True
if obj == self.list_view and event.type() == QKeyEvent.KeyPress:
key = event.key()
if key == Qt.Key_Up:
self.current_index -= 1
if self.current_index < 0:
self.current_index = len(self.completion_list) - 1
self.update_completion_list()
self.update_info_edit()
return True
elif key == Qt.Key_Down:
self.current_index += 1
if self.current_index >= len(self.completion_list):
self.current_index = 0
self.update_completion_list()
self.update_info_edit()
return True
elif key == Qt.Key_Return or key == Qt.Key_Enter:
self.insert_completion(self.list_view.currentIndex())
return True
return super().eventFilter(obj, event)
def auto_save(self, file_path, interval):
while True:
time.sleep(interval)
print(self.text_edit.toPlainText())
if self.text_edit.toPlainText() != "":
with open(file_path, 'w') as file:
file.write(str(self.text_edit.toPlainText()))
print("自动保存成功")
else:
print("未写入代码")
def handle_text_changed(self):
cursor = self.text_edit.textCursor()
current_pos = cursor.position()
cursor.movePosition(QTextCursor.StartOfLine, QTextCursor.MoveAnchor)
block_number = cursor.blockNumber()
line_text = cursor.block().text()[:current_pos - cursor.block().position()]
words = line_text.split()
if len(words) > 0:
current_word = words[-1]
completion_list = self.get_completion_list(current_word)
self.completion_list = completion_list
self.current_index = 0
self.show_completion_list(completion_list)
else:
self.list_view.hide()
self.info_edit.clear()
def get_completion_list(self, prefix):
# 根据输入前缀获取代码提示列表
suggestions = list(method_info_dict.keys())
return [suggestion for suggestion in suggestions if suggestion.startswith(prefix)]
def show_completion_list(self, completion_list):
# 显示代码提示列表
model = QStandardItemModel()
for completion in completion_list:
item = QStandardItem(completion)
item.setForeground(QBrush(Qt.black))
model.appendRow(item)
self.list_view.setModel(model)
if model.rowCount() > 0:
self.list_view.setCurrentIndex(model.index(0, 0))
self.list_view.show()
self.update_info_edit()
else:
self.list_view.hide()
self.info_edit.clear()
def update_completion_list(self):
# 更新当前选中的代码提示项
model = self.list_view.model()
if model:
new_index = model.index(self.current_index, 0)
self.list_view.setCurrentIndex(new_index)
self.update_info_edit()
def update_info_edit(self):
# 更新单词解释框的内容
selected_index = self.list_view.currentIndex()
model = self.list_view.model()
selected_completion = model.data(selected_index)
method_info = method_info_dict.get(selected_completion, '')
self.info_edit.setStyleSheet("color: black;")
self.info_edit.setPlainText(method_info)
def insert_completion(self, index):
# 插入选中的代码提示项到文本编辑框中
model = self.list_view.model()
completion_index = model.index(index.row(), 0)
completion = model.data(completion_index)
cursor = self.text_edit.textCursor()
while not cursor.atBlockStart() and not cursor.block().text()[cursor.positionInBlock() - 1].isspace():
cursor.movePosition(QTextCursor.Left, QTextCursor.MoveAnchor)
# 向右移动光标直到遇到一个空格或者到达行末尾
while not cursor.atBlockEnd():
# 更新当前光标所在行的文本
line_text = cursor.block().text()
# 检查索引是否越界
if cursor.positionInBlock() >= len(line_text):
break
# 判断当前字符是否为空格
if line_text[cursor.positionInBlock()].isspace():
break
if line_text[cursor.positionInBlock()] == '(':
break
cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor)
selected_text = cursor.selectedText()
block = cursor.block()
text = block.text()
print("text:" + text)
last_word_start = text.rfind(' ', 0, cursor.position()) + 1
last_word = text[last_word_start:cursor.position()]
if last_word == selected_text:
# cursor.setPosition(last_word_start)
cursor.setPosition(cursor.position() + len(last_word), QTextCursor.KeepAnchor)
cursor.removeSelectedText()
cursor.insertText(completion)
self.text_edit.setTextCursor(cursor)
def complete_current_word(self):
# 自动完成当前单词
cursor = self.text_edit.textCursor()
current_pos = cursor.position()
cursor.movePosition(QTextCursor.StartOfLine, QTextCursor.MoveAnchor)
line_text = cursor.block().text()
words = line_text.split()
if len(words) > 0:
current_word_start = cursor.position() + line_text.index(words[-1])
current_word_end = current_word_start + len(words[-1])
cursor.setPosition(current_word_start)
cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor, current_word_end - current_word_start)
selected_index = self.list_view.currentIndex()
self.insert_completion(selected_index)
def jc1(self):
process = multiprocessing.Process(target=copy_gradle)
# 启动进程
process.start()
def buttonClick(self):
# GET BUTTON CLICKED
btn = self.sender()
btnName = btn.objectName()
print("btnName:" + btnName)
# SHOW HOME PAGE
if btnName == "btn_home":
widgets.stackedWidget.setCurrentWidget(widgets.home)
UIFunctions.resetStyle(self, btnName)
btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))
# SHOW WIDGETS PAGE
# if btnName == "btn_widgets":
# widgets.stackedWidget.setCurrentWidget(widgets.widgets)
# UIFunctions.resetStyle(self, btnName)
# btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))
# SHOW NEW PAGE
if btnName == "btn_debug":
widgets.stackedWidget.setCurrentWidget(widgets.debug) # SET PAGE
UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU
# btn_debug
if btnName == "btn_serve":
print("启动服务器")
xintiao()
# af = Flask(__name__)
# af.run(host='192.168.189.128', port=8080)
global command
command = 0
global pngcmd
pngcmd = 0
# 重置指令(0)
# png指令(0)
t = threading.Thread(target=start_flask_app)
t.start()
# ta = Thread(target=mai, args=(21566, "C:/Users/35600/Desktop/ma"))
# ta.start()
if btnName == "btn_start":
self.ui.logd.clear()
global lognum
lognum = 1
print("运行")
项目 = self.ui.edit_debugfile.text()
type_value = self.get_type_from_json(项目 + "/config.json")
print("返回值是字符串" + type_value)
if type_value == "1":
print("返回值是字符串 '1'")
my_signal.setResult.emit("运行(Js脚本项目)-下发时间取决网速(10-30s)", 100, 184, 100)
项目 = self.ui.edit_debugfile.text()
zip_file(项目 + "/js")
zip_file(项目 + "/assets")
zip_file(项目 + "/res")
self.移动文件(项目 + "/js.zip", dir + "/debug/", "js.zip")
self.移动文件(项目 + "/assets.zip", dir + "/debug/", "assets.zip")
self.移动文件(项目 + "/res.zip", dir + "/debug/", "res.zip")
time.sleep(0.1)
os.remove(项目 + "/js.zip")
os.remove(项目 + "/assets.zip")
os.remove(项目 + "/res.zip")
time.sleep(0.1)
zip_file(dir + "/debug")
time.sleep(0.1)
up(dir + "/debug.zip")
重置指令(3)
print(command)
elif type_value == "2":
print("返回值是字符串 '2'")
my_signal.setResult.emit("运行(Java插件项目)-下发时间取决网速(10-30s)", 100, 184, 100)
t = Thread(target=self.debug_java, args=("gradlew assembleDebug", 项目,))
t.start()
print(command)
elif type_value == "3":
print("返回值是字符串 '3'")
my_signal.setResult.emit("运行(Python插件项目)-下发时间取决网速(10-30s)", 100, 184, 100)
t = Thread(target=self.debug_py, args=("gradlew assembleRelease", 项目,))
t.start()
else:
print("返回值不是 '1'、'2' 或 '3'")
# print("操作指令:" + str(command))
# 启动判断(1)
if btnName == "btn_stop":
print("停止")
my_signal.setResult.emit("通知移动端停止", 100, 184, 100)
重置指令(5)
if btnName == "btn_startcopy":
self.ui.logd.clear()
lognum = 1
print("启动剪切板")
my_signal.setResult.emit("运行剪切板Js代码", 100, 184, 100)
项目 = self.ui.edit_debugfile.text()
overwrite_file(项目 + "/build/intermediates/other/js/main.js", get_selected_text())
time.sleep(0.1)
zip_file(项目 + "/build/intermediates/other/js")
zip_file(项目 + "/assets")
zip_file(项目 + "/res")
self.移动文件(项目 + "/build/intermediates/other/js.zip", dir + "/debug/", "js.zip")
self.移动文件(项目 + "/assets.zip", dir + "/debug/", "assets.zip")
self.移动文件(项目 + "/res.zip", dir + "/debug/", "res.zip")
time.sleep(0.1)
os.remove(项目 + "/build/intermediates/other/js.zip")
os.remove(项目 + "/assets.zip")
os.remove(项目 + "/res.zip")
time.sleep(0.1)
zip_file(dir + "/debug")
time.sleep(0.1)
up(dir + "/debug.zip")
# self.解压到指定(项目+"/build/intermediates/js.zip",dir+"/js")
# self.解压到指定(项目 + "/build/intermediates/assets.zip", dir + "/assets")
#
# t = Thread(target=self.调试编译, args=(项目,))
# t.start()
# self.移动文件(项目 + "/build/intermediates/js.zip", "D:/socket/","js.zip")
# time.sleep(0.1)
# os.remove(项目 + "/js.zip")
重置指令(4)
if btnName == "btn_ui":
print("预览ui")
my_signal.setResult.emit("通知移动端展示Ui", 100, 184, 100)
项目 = self.ui.edit_debugfile.text()
zip_file(项目 + "/js")
zip_file(项目 + "/assets")
zip_file(项目 + "/res")
self.移动文件(项目 + "/js.zip", dir + "/debug/", "js.zip")
self.移动文件(项目 + "/assets.zip", dir + "/debug/", "assets.zip")
self.移动文件(项目 + "/res.zip", dir + "/debug/", "res.zip")
time.sleep(0.1)
os.remove(项目 + "/js.zip")
os.remove(项目 + "/assets.zip")
os.remove(项目 + "/res.zip")
time.sleep(0.1)
zip_file(dir + "/debug")
time.sleep(0.1)
up(dir + "/debug.zip")
重置指令(6)
if btnName == "btn_xml":
my_signal.setResult.emit("启动节点工具", 100, 184, 100)
t = Thread(target=xml)
t.start()
# my_signal.setResult.emit("欢迎使用魔幻手---当前版本1.0", 100, 184, 100)
if btnName == "btn_debugfile":
print("选择文件夹")
self.xzxm()
if btnName == "btn_build":
widgets.stackedWidget.setCurrentWidget(widgets.build) # SET PAGE
UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU
if btnName == "btn_buildpro":
# os.getcwd()[:-4] + 'new\\'
print("选择文件夹")
self.xzxm2()
if btnName == "btn_buildico":
# os.getcwd()[:-4] + 'new\\'
print("选择文件夹")
self.xzxm3()
if btnName == "btn_buildyes":
# os.getcwd()[:-4] + 'new\\'
self.ui.buidlod.clear()
global buildlognum
buildlognum = 1
print("编译")
项目 = self.ui.edit_buildpro.text()
图标 = self.ui.edit_buildico.text()
名字 = self.ui.edit_buildname.text()
pkg = self.ui.edit_buildpkg.text()
# gradle(项目+"/build/app/1/app/build.gradle",pkg)
# fi= pkg.replace('.', '/')
# copy_all_files(项目+"/build/app/1/app/src/main/java/pa/magichands/host",项目+"/build/app/1/app/src/main/java/"+fi)
# batch_modify_java_packageee("pa.magichands.host",pkg,项目+"/build/app/1/app/src/main/java/"+fi)
# copy_all_files(项目 + "/build/app/1/app/src/androidTest/java/pa/magichands/host",
# 项目 + "/build/app/1/app/src/androidTest/java/" + fi)
# batch_modify_java_packageee("pa.magichands.host", pkg, 项目 + "/build/app/1/app/src/androidTest/java/" + fi)
# copy_all_files(项目 + "/build/app/1/app/src/test/java/pa/magichands/host",
# 项目 + "/build/app/1/app/src/test/java/" + fi)
# batch_modify_java_packageee("pa.magichands.host", pkg, 项目 + "/build/app/1/app/src/test/java/" + fi)
#
# # copy_all_files(项目 + "/build/app/1/app/src/main/java/pa/magichands/accessibility",
# # 项目 + "/build/app/1/app/src/main/java/pa/magichands/accessibility")
# self.移动文件(图标,项目+"/build/app/1/app/src/main/res/drawable/","ico.jpg")
# modify_string_resource(项目+"/build/app/1/app/src/main/res/values/strings.xml","app_name",名字)
# time.sleep(10)
# delete_folder(项目 + "/build/app/1/app/src/main/java/pa/magichands/host/")
# delete_folder(项目 + "/build/app/1/app/src/androidTest/java/pa/")
# delete_folder(项目 + "/build/app/1/app/src/test/java/pa/")
# self.替换内容(项目+"/build/app/1/app/build.gradle",pkg)
# file = open(项目+"/build/app/1/app/src/main/res/values/strings.xml", 'w');
# file.close()
# with open(项目+"/build/app/1/app/src/main/res/values/strings.xml", "w",encoding='utf-8') as f:
# f.write('<resources><string name="app_name">'+名字+'</string></resources>')
type_value = self.get_type_from_json(项目 + "/config.json")
if type_value == "1":
print("返回值是字符串 '1'")
t = Thread(target=self.cmd2, args=("gradlew assembleDebug assembleRelease", 项目, 图标, 名字, pkg,))
t.start()
elif type_value == "2":
print("返回值是字符串 '2'")
t = Thread(target=self.build_java,
args=("gradlew assembleDebug assembleRelease", 项目, 图标, 名字, pkg,))
t.start()
elif type_value == "3":
print("返回值是字符串 '3'")
t = Thread(target=self.build_py, args=("gradlew assembleRelease", 项目,))
t.start()
else:
print("返回值不是 '1'、'2' 或 '3'")
# self.cmd("D:&&cd D:/magichands/demo/build/app/1&&gradlew assembleRelease")
if btnName == "btn_pro":
widgets.stackedWidget.setCurrentWidget(widgets.pro) # SET PAGE
UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU
if btnName == "btn_profile":
print("选择文件夹")
self.xzxm1()
if btnName == "btn_proopen":
# os.getcwd()[:-4] + 'new\\'
print("创建")
xzk = str(self.ui.comboBox_3.currentIndex())
if xzk == "0":
self.unzip_file(xzk)
elif xzk == "1":
self.unzip_file(xzk)
elif xzk == "2":
self.unzip_file(xzk)
if btnName == "btn_exit":
QMessageBox.information(self, "提示", "开发中", QMessageBox.Ok)
# widgets.stackedWidget.setCurrentWidget(widgets.build) # SET PAGE
# UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
# btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU
# PRINT BTN NAME
print(f'Button "{btnName}" pressed!')
def logd(self, z: str, r: str, g: str, b: str):
global lognum
self.ui.logd.setStyleSheet("color:#00ff00;")
t = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
self.ui.logd.appendPlainText(str(lognum) + "#(" + str(t) + ")" + z)
lognum = lognum + 1
def logd1(self, z: str, r: str, g: str, b: str):
global buildlognum
self.ui.buidlod.setStyleSheet("color:#00ff00;")
t = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
self.ui.buidlod.appendPlainText(str(buildlognum) + "#(" + str(t) + ")" + z)
buildlognum = buildlognum + 1
def xzxm(self):
# global wjj
# 选择文件
# folder_name = QFileDialog.getOpenFileNames(self, 'Open Images', wjj, 'Image files (*.png *.jpg)')
xz = QFileDialog.getExistingDirectory(self, "选择文件夹", "/")
print(xz)
self.ui.edit_debugfile.setText(xz)
def 调试编译(self, path):
print(path)
# while True:
# if not os.path.exists(path):
# print("1")
#
# else:
# break
#
# t = Thread(target=self.cmd, args=("D:&&cd " + path + "/build/intermediates/app&&gradlew assembleRelease",))
# t.start()
self.cmd1("C:&&cd " + path + "/build/intermediates/app&&gradlew assembleDebug")
file = open(dir + "/module/profiles.json", 'w')
file.close()
with open(dir + "/module/profiles.json", "w", encoding='utf-8') as f:
f.write(
'{"AesKey": "","ClassFilterFilePath": "","KeyAlias": "","KeyPassword": "","KeyStorePassword": "","KeyStorePath": "","NewApkPath": "' + path + '/build/intermediates/app/app/build/outputs/apk/debug/app-debug.apk","OldApkPath": "' + dir + '/apk/magichands.apk","OutputDirPath": "' + path + '/build/outputs/module","isForceColdFix": false,"isIgnoreRes": false,"isIgnoreSo": false}')
self.cmd1("C:&&cd " + dir + "/module&&SophixPatchTool --profiles profiles.json")
def xzxm1(self):
# global wjj
# 选择文件
# folder_name = QFileDialog.getOpenFileNames(self, 'Open Images', wjj, 'Image files (*.png *.jpg)')
xz = QFileDialog.getExistingDirectory(self, "选择文件夹", "/")
print(xz)
self.ui.edit_profile.setText(xz)
def xzxm2(self):
# global wjj
# 选择文件
# folder_name = QFileDialog.getOpenFileNames(self, 'Open Images', wjj, 'Image files (*.png *.jpg)')
xz = QFileDialog.getExistingDirectory(self, "选择文件夹", "/")
print(xz)
self.ui.edit_buildpro.setText(xz)
def xzxm3(self):
# global wjj
# 选择文件
# folder_name = QFileDialog.getOpenFileNames(self, 'Open Images', wjj, 'Image files (*.png *.jpg)')
xz = QFileDialog.getOpenFileName(self, "打开图片文件", "/",
"PNG Files(*.png);;JPEG Files(*.jpg);;PGM Files(*.pgm)")
lo = str(xz).split(",")
s = lo[0].split("('")
x = s[1].split("'")
v = x[0]
print(v)
# print(xz)
self.ui.edit_buildico.setText(str(v))
def 创建项目(self):
src = "C:/Users/35600/Desktop/js"
det = self.ui.edit_profile.text() + "/" + self.ui.edit_proname.text() # 目的文件目录
# print("1")
for root, _, fnames in os.walk(src):
for fname in sorted(fnames): # sorted函数把遍历的文件按文件名排序
fpath = os.path.join(root, fname)
shutil.copy(fpath, det) # 完成文件拷贝
print(fname + " 创建项目成功")
def 清空日志(self):
self.ui.logd.clear()
def 替换内容(self, path, pkg):
old = pkg
new = "DSOIGVOISD"
with open(path, 'r+', encoding='utf-8') as filetxt:
lines = filetxt.readlines()
filetxt.seek(0)
for line in lines:
if old in line:
lines = "".join(lines).replace(old, new)
filetxt.write("".join(lines))
def gradle_data(self):
zip_src = dir + "/gradle.zip"
dst_dir = os.path.expanduser("~")
r = zipfile.is_zipfile(zip_src)
if r:
fz = zipfile.ZipFile(zip_src, 'r')
for file in fz.namelist():
fz.extract(file, dst_dir)
else:
print('This is not zip')
def extract_pip_dependencies(self, file_path):
# 读取 JSON 配置文件
with open(file_path, 'r') as file:
config = json.load(file)
# 提取 pip 参数
pip_dependencies = config.get('pip', [])
# 格式化输出
dependencies_str = '\n'.join(f'install "{dependency}"' for dependency in pip_dependencies)
return dependencies_str
def replace_in_file(self, file_path, old_content, new_content):
with open(file_path, 'rb') as file:
raw_content = file.read()
result = chardet.detect(raw_content)
encoding = result['encoding']
with open(file_path, 'r', encoding=encoding) as file:
file_content = file.read()
new_file_content = file_content.replace(old_content, new_content)
with open(file_path, 'w', encoding=encoding) as file:
file.write(new_file_content)
print(f"替换完成:{old_content} 替换为 {new_content}")
def extract_pip_dependencies(self, file_path):
# 读取 JSON 配置文件
with open(file_path, 'r') as file:
config = json.load(file)
# 提取 pip 参数
pip_dependencies = config.get('pip', [])
# 格式化输出
dependencies_str = '\n'.join(f'"{dependency}"' for dependency in pip_dependencies)
return dependencies_str
def get_type_from_json(self, file_path):
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
type_value = data.get('type')
if isinstance(type_value, list):
type_value = ' '.join(type_value)
return type_value
def build_py(self, command: str, 项目):
my_signal.setResult2.emit("开始编译(python插件)-编译时间取决计算机性能(3-5分钟)", 100, 184, 100)
delete_folder(项目 + "/build/ins/py")
time.sleep(10)
copy_all_files(项目 + "/build/intermediates/other/Demo py",
项目 + "/build/ins/py")
time.sleep(10)
copy_all_files(项目 + "/python",