forked from qunat/EasyNuitka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EasyNuitka.py
382 lines (367 loc) · 14 KB
/
EasyNuitka.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
# This is a sample Python script.
import os
import sys
import threading
from PyQt5.QtCore import Qt
from PyQt5 import QtWidgets,QtGui
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QStyleFactory
import nuitka
import mainui
import subprocess
import shutil
class MainGui(mainui.Ui_MainWindow, QtWidgets.QMainWindow):
def __init__(self,parent=None):
super(MainGui, self).__init__(parent)
self.setupUi(self)
self.setWindowTitle( "EasyNuitka")
self.setWindowIcon(QIcon("./icon/Nuitka.png"))
self.pushButton.clicked.connect(self.choose_main_py)
self.pushButton_2.clicked.connect(self.set_output_path)
self.pushButton_7.clicked.connect(self.Multithreading_command)
self.pushButton_4.clicked.connect(self.follow_import_to)
self.pushButton_12.clicked.connect(self.follow_import_to_remove)
self.pushButton_20.clicked.connect(self.set_icon)
self.pushButton_19.clicked.connect(self.remove_icon)
self.pushButton_9.clicked.connect(self.quit)
self.pushButton_3.clicked.connect(self.nofollow_import_to)
self.pushButton_10.clicked.connect(self.nofollow_import_to_remove)
self.pushButton_17.clicked.connect(self.include_package_remove)
self.chekbox_clicked_init()
self.command_dict={}
self.command_str=None
self.main_name=None
self.outputpath="./"
self.follow_import_to_document_str=""
self.nofollow_import_to_document_str=""
self.iconname=None
self.iconpath=""
self.compile_module_path=None
self.statusbar.showMessage("The software runs normally")
def choose_main_py(self):
try:
if not self.checkBox_7.isChecked():
file = QtWidgets.QFileDialog.getOpenFileName(self,
"choose main.py", "./",
"All Files (*.py);;Text Files (*.py)")
self.filenpath = file[0]
self.lineEdit.setText(file[0])
self.main_name = self.lineEdit.setText(file[0])
self.filename = self.filenpath.split("/")[-1]
self.filenpath = self.filenpath.replace(self.filename, "")
self.dish = self.filenpath[0:2]
self.statusbar.showMessage("File selected successfully")
else :
directory = QtWidgets.QFileDialog.getExistingDirectory(self, "choose compile module dir", "./")
self.compile_module_path=directory
self.lineEdit.setText(directory)
self.lineEdit_9.setText(self.compile_module_path.split("/")[-1])
self.statusbar.showMessage("Output directory set successfully")
except Exception as e:
self.statusbar.showMessage("File selection failed")
print(e)
def set_output_path(self):
try:
directory = QtWidgets.QFileDialog.getExistingDirectory(self, "getExistingDirectory", "./")
self.outputpath=directory
self.lineEdit_2.setText(directory)
self.statusbar.showMessage("Output directory set successfully")
except Exception as e:
self.statusbar.showMessage("Output directory setting failed")
pass
def get_package_method(self):
#--follow-imports
if self.checkBox.isChecked():
self.lineEdit_3.setEnabled(False)
self.lineEdit_4.setEnabled(False)
self.checkBox_8.setEnabled(False)
self.command_dict[self.checkBox]="--follow-imports"
#print(self.command_dict)
elif not self.checkBox.isChecked():
self.lineEdit_3.setEnabled(True)
self.lineEdit_4.setEnabled(True)
self.checkBox_8.setEnabled(True)
self.command_dict[self.checkBox] = ""
#--nofollow-imports
if self.checkBox_8.isChecked():
self.checkBox.setEnabled(False)
self.command_dict[self.checkBox_8] = "--nofollow-imports"
#print(self.command_dict)
elif not self.checkBox_8.isChecked():
self.checkBox.setEnabled(True)
self.command_dict[self.checkBox_8] = ""
#--module
if self.checkBox_7.isChecked():
self.checkBox.setEnabled(False)
self.checkBox_8.setEnabled(False)
self.checkBox_3.setEnabled(False)
self.checkBox_4.setEnabled(False)
self.lineEdit_3.setEnabled(False)
self.lineEdit_4.setEnabled(False)
self.lineEdit_5.setEnabled(False)
self.lineEdit_8.setEnabled(False)
self.lineEdit_6.setEnabled(False)
self.lineEdit_9.setEnabled(True)
self.radioButton.setEnabled(False)
self.radioButton_2.setEnabled(False)
self.command_dict[self.checkBox_7] = "--module"
#print(self.command_dict)
elif not self.checkBox_7.isChecked():
self.checkBox_3.setEnabled(True)
self.checkBox_4.setEnabled(True)
self.lineEdit_3.setEnabled(True)
self.lineEdit_4.setEnabled(True)
self.lineEdit_5.setEnabled(True)
self.lineEdit_8.setEnabled(True)
self.lineEdit_6.setEnabled(True)
self.lineEdit_9.setEnabled(False)
self.radioButton.setEnabled(True)
self.radioButton_2.setEnabled(True)
self.checkBox_3.setEnabled(True)
self.checkBox_4.setEnabled(True)
if self.checkBox.isChecked():
self.checkBox_8.setEnabled(False)
if self.checkBox_8.isChecked():
self.checkBox.setEnabled(False)
self.command_dict[self.checkBox_7] = ""
#--standalone
if self.checkBox_3.isChecked():
self.checkBox_4.setEnabled(False)
self.checkBox_7.setEnabled(False)
self.command_dict[self.checkBox_3] = "--standalone"
elif not self.checkBox_3.isChecked() and not self.checkBox_7.isChecked():
self.checkBox_7.setEnabled(True)
self.checkBox_4.setEnabled(True)
self.command_dict[self.checkBox_3] = ""
#--onefile
if self.checkBox_4.isChecked():
self.checkBox_3.setEnabled(False)
self.checkBox_7.setEnabled(False)
self.command_dict[self.checkBox_4] = "--onefile"
elif not self.checkBox_4.isChecked() and not self.checkBox_7.isChecked() :
self.checkBox_3.setEnabled(True)
if not self.checkBox_3.isChecked():
self.checkBox_7.setEnabled(True)
self.command_dict[self.checkBox_4] = ""
#--mingw64
if self.checkBox_2.isChecked():
self.checkBox_10.setEnabled(False)
self.command_dict[self.checkBox_2] = "--mingw64"
else:
self.checkBox_10.setEnabled(True)
self.command_dict[self.checkBox_2] = ""
#--show-memory
if self.checkBox_5.isChecked():
self.command_dict[self.checkBox_5] = "--show-memory"
else:
self.command_dict[self.checkBox_5] = ""
#--show-progress
if self.checkBox_6.isChecked():
self.command_dict[self.checkBox_6] = "--show-progress"
else:
self.command_dict[self.checkBox_6] = ""
#-msvc64
if self.checkBox_10.isChecked():
self.checkBox_2.setEnabled(False)
self.command_dict[self.checkBox_10] = "-msvc64"
else:
self.checkBox_2.setEnabled(True)
self.command_dict[self.checkBox_10] = ""
#--include-plugin-pyqt5
if self.checkBox_9.isChecked():
self.command_dict[self.checkBox_9] = "--plugin-enable=pyqt5"
else:
self.command_dict[self.checkBox_9] = ""
#--include-plugin-numpy
if self.checkBox_17.isChecked():
self.command_dict[self.checkBox_17] = "--plugin-enable=numpy"
else:
self.command_dict[self.checkBox_17] = ""
#--include-plugin-torch
if self.checkBox_20.isChecked():
self.command_dict[self.checkBox_20] = "--plugin-enable=torch"
else:
self.command_dict[self.checkBox_20] = ""
#--include-plugin-matplotlib
if self.checkBox_11.isChecked():
self.command_dict[self.checkBox_11] = "--plugin-enable=matplotlib"
else:
self.command_dict[self.checkBox_11] = ""
#--include-plugin-pyqt6
if self.checkBox_13.isChecked():
self.command_dict[self.checkBox_13] = "--plugin-enable=pyqt6"
else:
self.command_dict[self.checkBox_13] = ""
#--include-plugin-pyside2
if self.checkBox_15.isChecked():
self.command_dict[self.checkBox_15] = "--plugin-enable=pyside2"
else:
self.command_dict[self.checkBox_15] = ""
#--include-plugin-pyside6
if self.checkBox_12.isChecked():
self.command_dict[self.checkBox_12] = "--plugin-enable=pyside6"
else:
self.command_dict[self.checkBox_12] = ""
#--include-plugin-no-qt5
if self.checkBox_18.isChecked():
self.command_dict[self.checkBox_18] = "--plugin-enable=no-qt5"
else:
self.command_dict[self.checkBox_18] = ""
#--include-plugin-upx
if self.checkBox_22.isChecked():
self.command_dict[self.checkBox_22] = "--plugin-enable=upx"
else:
self.command_dict[self.checkBox_22] = ""
#--include-plugin-tensorflow
if self.checkBox_19.isChecked():
self.command_dict[self.checkBox_19] = "--plugin-enable=tensorflow"
else:
self.command_dict[self.checkBox_19] = ""
#--include-plugin-pywebview
if self.checkBox_25.isChecked():
self.command_dict[self.checkBox_25] = "--plugin-enable=pywebview"
else:
self.command_dict[self.checkBox_25] = ""
#--include-plugin-tk-inter
if self.checkBox_24.isChecked():
self.command_dict[self.checkBox_24] = "--plugin-enable=tk-inter"
else:
self.command_dict[self.checkBox_24] = ""
#--include-plugin-trio
if self.checkBox_23.isChecked():
self.command_dict[self.checkBox_23] = "--plugin-enable=trio"
else:
self.command_dict[self.checkBox_23] = ""
#--include-plugin-multiprocessing
if self.checkBox_14.isChecked():
self.command_dict[self.checkBox_14] = "--plugin-enable=multiprocessing"
else:
self.command_dict[self.checkBox_14] = ""
#--windows-disable-console
if self.radioButton.isChecked():
self.command_dict[self.radioButton] = "--windows-disable-console"
if self.radioButton_2.isChecked():
self.command_dict[self.radioButton_2] = ""
#Default Enabled
self.lineEdit_5.setEnabled(False)
self.lineEdit_8.setEnabled(False)
self.statusbar.showMessage("Selection succeeded")
def Multithreading_command(self):
t=threading.Thread(target=self.excute_command,args=())
t.start()
self.statusbar.showMessage("packaging is finishing")
def excute_command(self):
try:
self.command_str="python -m nuitka "
for command in self.command_dict.keys():
if self.command_dict[command]=="":
continue
if self.command_dict[command]=="--module":
self.command_dict[command]="--module "+self.compile_module_path.split("/")[-1]+" "+"--include-package="+\
self.lineEdit_9.text()
self.command_str+=self.command_dict[command]+" "
if self.follow_import_to_document_str!="":
self.command_str += "--follow-import-to=" + self.follow_import_to_document_str[0:len(self.follow_import_to_document_str)-1] + " "
if self.follow_import_to_document_str!="":
self.command_str+="--nofollow-import-to="+self.follow_import_to_document_str+" "
self.command_str+="--output-dir="+self.outputpath+" "
if self.iconname!=None:
self.command_str+="--windows-icon-from-ico="+self.iconname+" "
if not self.checkBox_7.isChecked():
self.command_str+=self.filename
print(self.command_str)
if not self.checkBox_7.isChecked():
os.chdir(self.filenpath)
else:
os.chdir(self.compile_module_path)
os.chdir("../")
os.system(self.command_str)
self.statusbar.showMessage("Please wait to start packaging......")
except Exception as e:
self.statusbar.showMessage(e)
#print(e)
def chekbox_clicked_init(self):
self.package_method=[]
self.checkBox_dict = {self.checkBox: "--follow-imports", self.checkBox_8: "--nofollow-imports",
self.checkBox_7: "--module",
self.checkBox_3: "--standalone", self.checkBox_4: "--onefile",
self.checkBox_2: "--mingw64", self.checkBox_5: "--show-memory",
self.checkBox_6: "--show-progress", self.checkBox_10: "-msvc64",
self.checkBox_9: "--include-plugin-pyqt5",
self.checkBox_17: "--include-plugin-numpy",self.checkBox_20:"--include-plugin-torch",
self.checkBox_11:"--include-plugin-matplotlib",self.checkBox_13:"--include-plugin-pyqt6",
self.checkBox_15:"--include-plugin-pyside2",self.checkBox_12:"--include-plugin-pyside6",
self.checkBox_18:"--include-plugin-no-qt5",self.checkBox_22:"--include-plugin-upx",
self.checkBox_19:"--include-plugin-tensorflow",self.checkBox_25:"--include-plugin-pywebview",
self.checkBox_24:"--include-plugin-tk-inter",self.checkBox_23:"--include-plugin-trio",
self.checkBox_14:"--include-plugin-multiprocessing",self.radioButton:"--windows-disable-console",
self.radioButton_2:""}
for check in self.checkBox_dict.keys():
try:
check.clicked.connect(self.get_package_method)
except:
pass
self.lineEdit_9.setEnabled(False)
def nofollow_import_to(self):
self.follow_import_to_document_str=self.lineEdit_3.text()
self.statusbar.showMessage("add module to nofollow_import_to ")
def nofollow_import_to_remove(self):
self.lineEdit_3.setText("Enter module/package ;Separate them with commas")
self.follow_import_to_document_str=""
self.statusbar.showMessage("Removed")
def follow_import_to(self):
try:
directory = QtWidgets.QFileDialog.getExistingDirectory(self, "getExistingDirectory", "./")
self.follow_import_to_document = directory.split("/")[-1]
self.follow_import_to_document_str+=self.follow_import_to_document+","
self.lineEdit_4.setText(self.follow_import_to_document_str)
except Exception as e:
print(e)
pass
def follow_import_to_remove(self):
try:
self.lineEdit_4.setText("Select the folder you want to compile")
except Exception as e:
self.statusbar.showMessage("Removed")
pass
def include_data_files(self):
pass
def set_icon(self):
try:
if not self.checkBox_7.isChecked():
file = QtWidgets.QFileDialog.getOpenFileName(self,
"getOpenFileName", "./",
"All Files (*);;Text Files (*)")
self.iconpath = file[0]
self.lineEdit_6.setText(self.iconpath)
src = self.iconpath
dist = self.filenpath + src.split("/")[-1]
if not os.path.exists(dist):
shutil.copyfile(src, dist)
self.iconname = src.split("/")[-1]
except Exception as e:
print(e)
def remove_icon(self):
self.lineEdit_6.setText("Select icon")
self.statusbar.showMessage("Removed")
def include_data_files(self):
try:
file = QtWidgets.QFileDialog.getOpenFileName(self,
"getOpenFileName", "./",
"All Files (*);;Text Files (*)")
self.include_data_files=file[0]
except Exception as e:
pass
def include_package_remove(self):
self.lineEdit_9.setText("Default to the entire module")
def quit(self):
sys.exit()
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
app = QtWidgets.QApplication(sys.argv)
QApplication.setStyle(QStyleFactory.create('Fusion'))
win = MainGui()
win.show()
sys.exit(app.exec_())
# See PyCharm help at https://www.jetbrains.com/help/pycharm/