Aug-15-2018, 03:31 PM
Made for Linux.
On other OS you need to change some paths and "xdg-open" (Line 160) to the right command.
![[Image: 44155887-bae0a224-a0ae-11e8-98e3-7bf613720032.png]](https://user-images.githubusercontent.com/2623542/44155887-bae0a224-a0ae-11e8-98e3-7bf613720032.png)
code on github
On other OS you need to change some paths and "xdg-open" (Line 160) to the right command.
![[Image: 44155887-bae0a224-a0ae-11e8-98e3-7bf613720032.png]](https://user-images.githubusercontent.com/2623542/44155887-bae0a224-a0ae-11e8-98e3-7bf613720032.png)
code on github
#!/usr/bin/python # -*- coding: utf-8 -*- ############################################################################# from PyQt5.QtCore import (QFile, pyqtSignal, Qt, QMimeData, QProcess) from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import (QApplication, QFileDialog, QMainWindow, QMessageBox, QHBoxLayout, QVBoxLayout, QWidget, QLabel, QMessageBox, QToolButton, QLineEdit) from distutils.spawn import find_executable quote = str(chr(34)) squote = str(chr(39)) class MainWindow(QMainWindow): changed = pyqtSignal(QMimeData) def __init__(self): super(MainWindow, self).__init__() btnwidth = 150 self.InFile = '' self.OutFolder = '/tmp' self.cmd = '' self.appname = '' self.process = QProcess() self.process.started.connect(self.shell_started) self.process.finished.connect(self.shell_ended) self.open_process = QProcess() self.setAcceptDrops(True) self.createStatusBar() self.setGeometry(0, 0, 600, 280) self.setFixedSize(600, 280) self.setStyleSheet(myStyleSheet(self)) self.setWindowIcon(QIcon.fromTheme("gnome-mime-text-x-python")) #### path btnInPath = QToolButton() btnInPath.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) btnInPath.setIcon(QIcon.fromTheme("gtk-open")) btnInPath.setText("select Python File") btnInPath.setFixedWidth(btnwidth) btnInPath.clicked.connect(self.openInFile) self.lblInPath = QLabel(self.InFile) hlayout = QHBoxLayout() hlayout.addWidget(btnInPath) hlayout.addWidget(self.lblInPath) #### output path btnOutPath = QToolButton() btnOutPath.setIcon(QIcon.fromTheme("gtk-open")) btnOutPath.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) btnOutPath.setText("select Output Folder") btnOutPath.setFixedWidth(btnwidth) btnOutPath.clicked.connect(self.openOutFolder) self.lblOutPath = QLabel(self.OutFolder) hlayout2 = QHBoxLayout() hlayout2.addWidget(btnOutPath) hlayout2.addWidget(self.lblOutPath) #cmdlbl = QLabel("") createButton = QToolButton() createButton.setIcon(QIcon.fromTheme("gnome-mime-text-x-python")) createButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) createButton.setText("create App") createButton.clicked.connect(self.createSetup) createButton.setFixedWidth(btnwidth) self.exclude = QLineEdit("PyQt4,matplotlib") self.exclude.setPlaceholderText("insert Modules (comma seperated)") self.exclude.setToolTip("insert Modules (comma seperated)") self.include = QLineEdit() self.include.setPlaceholderText("insert Modules (comma seperated)") self.include.setToolTip("insert Modules (comma seperated)") self.include_files = QLineEdit() self.include_files.setPlaceholderText("insert file paths (comma seperated)") self.include_files.setToolTip("insert file paths (comma seperated)") lbl1 = QLabel("include modules:") lbl2 = QLabel("exclude modules:") lbl3 = QLabel("include files:") vlayout = QVBoxLayout() vlayout.addLayout(hlayout) vlayout.addLayout(hlayout2) vlayout.addWidget(lbl1) vlayout.addWidget(self.include) vlayout.addWidget(lbl2) vlayout.addWidget(self.exclude) vlayout.addWidget(lbl3) vlayout.addWidget(self.include_files) vlayout.addWidget(createButton) mywidget = QWidget() mywidget.setLayout(vlayout) self.setCentralWidget(mywidget) self.setWindowTitle("create App with cxfreeze") def check_cxfreeze(self, name): out = find_executable('cxfreeze') if out == None: return False else: return True def dragEnterEvent(self, event): self.statusBar().showMessage("File drop") event.acceptProposedAction() self.changed.emit(event.mimeData()) def dropEvent(self, event): mimeData = event.mimeData() if mimeData.hasUrls(): self.InFile = "\n".join([url.path() for url in mimeData.urls()]) self.lblInPath.setText(self.InFile) name = self.lblInPath.text().partition(".py")[0] name = name.rpartition("/")[-1] self.appname = name if self.OutFolder == "/tmp": self.lblOutPath.setText(self.lblOutPath.text() + "/" + name) self.OutFolder = self.lblOutPath.text() else: self.statusBar().showMessage("no url") event.acceptProposedAction() def openInFile(self): fileName,_ = QFileDialog.getOpenFileName(self, "", "", "Python Files (*.py)") if fileName: self.lblInPath.setText(fileName) self.InFile = fileName name = self.lblInPath.text().partition(".py")[0] name = name.rpartition("/")[-1] self.appname = name if self.OutFolder == "/tmp": self.lblOutPath.setText(self.lblOutPath.text() + "/" + name) self.OutFolder = self.lblOutPath.text() def openOutFolder(self): dlg = QFileDialog() dlg.setFileMode(QFileDialog.Directory) fileName = dlg.getExistingDirectory() if fileName: name = self.lblInPath.text().partition(".py")[0] name = name.rpartition("/")[-1] self.appname = name name = fileName + "/" + name self.lblOutPath.setText(name) self.OutFolder = name def shell_started(self): print("creating '" + self.appname) self.statusBar().showMessage("creating '" + self.appname + squote, 0) def shell_ended(self): print("'" + self.appname + "' created!") self.statusBar().showMessage("'" + self.appname + "' created!", 0) self.open_process.start("xdg-open", [self.OutFolder]) def createSetup(self): mytext = """from cx_Freeze import setup, Executable, build base = None myname = self.appname desc = self.appname vers = "1.4" executables = [Executable(self.infile, base=base, targetName=self.appname)] build_exe_options = {"packages": ["idna"], "include_files": [my_include_files], "excludes": [my_excludes], "includes": [my_includes], "optimize": 2, "build_exe": self.OutFolder, } setup( name = self.appname, options = {"build_exe": build_exe_options}, version = vers, description = desc, executables = executables )""" # self.statusBar().showMessage("creating '" + self.appname, 0) qoute = str(chr(34)) my_excludes = self.exclude.text() if my_excludes != "": my_excludes = quote + my_excludes + quote my_includes = self.include.text() if my_includes != "": my_includes = quote + my_includes + quote my_include_files = self.include_files.text() if my_include_files != "": my_include_files = quote + my_include_files + quote mytext = (mytext.replace("self.OutFolder",quote + self.OutFolder + quote).replace("self.appname", quote + self.appname + quote).replace("self.infile", qoute + self.InFile + quote).replace("my_includes", my_includes).replace("my_excludes", my_excludes)).replace("my_include_files", my_include_files) f = "/tmp/mysetup.py" textfile = open(f, 'w') textfile.write(mytext) textfile.close() self.process.start("python", ["/tmp/mysetup.py", "build"]) def createStatusBar(self): self.statusBar().showMessage("Ready") def msgbox(self, message): QMessageBox.warning(self, "Message", message) def myStyleSheet(self): return """ QToolButton { font-size: 9pt; color: #2e3436; } QLabel { font-weight: bold; font-size: 8pt; color: #204a87; } QStatusBar { font-size: 8pt; color: #3465a4; } QMainWindow { background: #f3f3f3; } QToolButton::hover { background: #babdb6; } """ if __name__ == '__main__': import sys app = QApplication(sys.argv) mainWin = MainWindow() mainWin.show() if mainWin.check_cxfreeze("cxfreeze") == False: QMessageBox.warning(mainWin, "Error", "<b>cxfreeze not found</b><br><br><i>Please install cxfreeze</i>") mainWin.handleQuit() else: mainWin.statusBar().showMessage("Ready * found cxfreeze", 0) sys.exit(app.exec_())