Skip to content

Commit

Permalink
Merge pull request #10 from Kainkun/revival
Browse files Browse the repository at this point in the history
Revival
  • Loading branch information
Kainkun authored Nov 6, 2022
2 parents 750f7e0 + d92c5d1 commit 1145c58
Show file tree
Hide file tree
Showing 26 changed files with 942 additions and 950 deletions.
2 changes: 1 addition & 1 deletion BuildOneDir.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
call Generate.bat
pyinstaller --onedir --specpath .\build --workpath .\build\temp --distpath .\build --paths .\generated --icon ..\images\Unity.ico .\UnityLauncher.py
pyinstaller --onedir --noconsole --specpath .\build --workpath .\build\temp --distpath .\build --paths .\generated --add-data ..\unityFiles\UnityLauncher\MenuItems.cs;.\unityFiles\UnityLauncher --add-data ..\unityFiles\UnityLauncher\TextureScale.cs;.\unityFiles\UnityLauncher --icon ..\images\Unity.ico .\UnityLauncher.py
pause
2 changes: 1 addition & 1 deletion BuildOneFile.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
call Generate.bat
pyinstaller --onefile --noconsole --specpath .\build --workpath .\build\temp --distpath .\build\UnityLauncher --paths .\generated --icon ..\images\Unity.ico .\UnityLauncher.py
pyinstaller --onefile --noconsole --specpath .\build --workpath .\build\temp --distpath .\build\UnityLauncher --paths .\generated --add-data ..\unityFiles\UnityLauncher\MenuItems.cs;.\unityFiles\UnityLauncher --add-data ..\unityFiles\UnityLauncher\TextureScale.cs;.\unityFiles\UnityLauncher --icon ..\images\Unity.ico .\UnityLauncher.py
pause
5 changes: 0 additions & 5 deletions Generate.bat

This file was deleted.

6 changes: 6 additions & 0 deletions Generate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
New-Item -ItemType Directory -Force -Path generated
pyuic5 -x designer/UnityLauncher.ui -o generated/UnityLauncherGenerated.py
pyuic5 -x designer/FolderList.ui -o generated/FolderListGenerated.py
pyuic5 -x designer/Settings.ui -o generated/SettingsGenerated.py
pyrcc5 designer/resources.qrc -o generated/resources_rc.py
((Get-Content -path generated/UnityLauncherGenerated.py -Raw) -replace 'import resources_rc','import generated.resources_rc') | Set-Content -Path generated/UnityLauncherGenerated.py
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
To build the executable files from source, run either **BuildOneDir.bat** or **BuildOneFile.bat**.
These scripts will compile the project to folder named "build".

If you make any changes to the UI via Qt Designer, make sure to run the **Generate.bat** script!
If you make any changes to the UI via Qt Designer, make sure to run the **Generate.ps1** script!
This ensures that corresponding "generated/*.py" files are kept up to date, which is used by the code.
141 changes: 91 additions & 50 deletions UnityLauncher.py
Original file line number Diff line number Diff line change
@@ -1,88 +1,130 @@
from src.SettingsDialog import SettingsDialog
from src.ProjectData import ProjectData
from src.Config import Config
from generated.UnityLauncherGenerated import Ui_MainWindow
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QtCore
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), 'generated'))

if(os.path.basename(sys.executable) == "UnityLauncher.exe"):
applicationPath = os.path.dirname(sys.executable)
if (os.path.basename(sys.executable) == "UnityLauncher.exe"):
# applicationPath = os.path.dirname(sys.executable)
os.environ["UNITY_LAUNCHER_APPLICATION_PATH"] = os.path.dirname(sys.executable)
else:
applicationPath = os.path.abspath(".")
# applicationPath = os.path.abspath(".")
os.environ["UNITY_LAUNCHER_APPLICATION_PATH"] = os.path.abspath(".")

from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import QtWidgets

from generated.UnityLauncherGenerated import Ui_MainWindow
from src.Config import Config
from src.ProjectData import ProjectData
from src.SettingsDialog import SettingsDialog
class LauncherMainWindow(QtWidgets.QMainWindow):
def __init__(self, *args):
QtWidgets.QMainWindow.__init__(self, *args)
self.config: Config = Config()
ui = UiImplement(self)
ui.setupUi(self)
x, y = self.config.getWindowPosition()
w, h = self.config.getWindowSize()
self.resize(QtCore.QSize(w, h))
self.move(QtCore.QPoint(x, y))

def closeEvent(self, closeEvent: QtGui.QCloseEvent):
self.config.readChanges()
self.config.setWindowSize((self.size().width(), self.size().height()))
self.config.setWindowPosition((self.pos().x(), self.pos().y()))
self.config.writeChanges()
return super().closeEvent(closeEvent)


class UiImplement(Ui_MainWindow):

def __init__(self, parent: LauncherMainWindow):
super().__init__()
self.parent = parent

def setupUi(self, MainWindow):
super().setupUi(MainWindow)
self.addProjectsToList()
self.projectTree.setColumnWidth(0,150)
self.projectTree.setColumnWidth(1,200)
self.projectTree.setColumnWidth(2,600)
self.projectTree.setColumnWidth(3,200)
self.projectTree.setColumnWidth(4,200)
self.projectTree.header().setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeMode.Fixed)
self.projectTree.setColumnWidth(0, 150)
self.projectTree.setColumnWidth(1, 200)
self.projectTree.setColumnWidth(2, 600)
self.projectTree.setColumnWidth(3, 200)
self.projectTree.setColumnWidth(4, 200)
self.projectTree.header().setSectionResizeMode(
0, QtWidgets.QHeaderView.ResizeMode.Fixed)
self.projectTree.sortItems(3, QtCore.Qt.SortOrder.AscendingOrder)
self.projectTree.itemClicked.connect(lambda item: self.projectClicked(item))
self.projectTree.itemClicked.connect(
lambda item: self.projectClicked(item))
self.projectTree.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.projectTree.customContextMenuRequested.connect(lambda position: self.projectContextMenu(position))
self.projectTree.customContextMenuRequested.connect(
lambda position: self.projectContextMenu(position))

self.SettingsButton.clicked.connect(lambda: self.__openSettings())
self.searchLineEdit.textChanged.connect(lambda text: self.searchBarChanged(text))
self.searchLineEdit.textChanged.connect(
lambda text: self.searchBarChanged(text))

def addProjectsToList(self):
config = Config()

for projectsFolderPath in config.getProjectFolders():
if(not os.path.exists(projectsFolderPath)):
print('Error: Projects Folder "{0}" Does Not Exist'.format(projectsFolderPath))
self.parent.config.readChanges()
for projectsFolderPath in self.parent.config.getProjectFolders():
if (not os.path.exists(projectsFolderPath)):
print('Error: Projects Folder "{0}" Does Not Exist'.format(
projectsFolderPath))
continue

for projectFolderName in os.listdir(projectsFolderPath):
projectPath = os.path.join(projectsFolderPath, projectFolderName)
projectPath = os.path.join(
projectsFolderPath, projectFolderName)

if(not os.path.exists(projectPath)):
print('Error: Project Folder "{0}" Does Not Exist'.format(projectPath))
if (not os.path.exists(projectPath)):
print('Error: Project Folder "{0}" Does Not Exist'.format(
projectPath))
continue

editorVersionPath = os.path.join(projectPath, r"ProjectSettings\ProjectVersion.txt")
if(not os.path.exists(editorVersionPath)):
print('Error: ProjectVersion.txt not found for "{0}"'.format(projectFolderName))
editorVersionPath = os.path.join(
projectPath, r"ProjectSettings\ProjectVersion.txt")
if (not os.path.exists(editorVersionPath)):
print('Error: ProjectVersion.txt not found for "{0}"'.format(
projectFolderName))
continue
with open(editorVersionPath) as versionPathFile:
firstline = versionPathFile.readline().rstrip()
editorVersion = firstline.split(" ")[1]

unityPath = None
for unityEditorFolder in config.getEditorFolders():
tryUnityPath = os.path.join(unityEditorFolder, editorVersion, r"Editor\Unity.exe")
if(os.path.exists(tryUnityPath)):
for unityEditorFolder in self.parent.config.getEditorFolders():
tryUnityPath = os.path.join(
unityEditorFolder, editorVersion, r"Editor\Unity.exe")
if (os.path.exists(tryUnityPath)):
unityPath = tryUnityPath
break

ProjectData(self.projectTree, projectFolderName, projectPath, unityPath, editorVersion)

ProjectData(self.projectTree, projectFolderName,
projectPath, unityPath, editorVersion)

def projectClicked(self, item: QtWidgets.QTreeWidgetItem):
item.data(0, QtCore.Qt.UserRole).openProject()
success = item.data(0, QtCore.Qt.UserRole).openProject()
if(not success):
msg = QtWidgets.QMessageBox(self.parent)
# msg.setIcon(QtWidgets.QMessageBox.warning())
msg.setText("Missing Unity Version")
msg.setIcon(QtWidgets.QMessageBox.Warning)
msg.setInformativeText('Unity version {0} does not exist in the settings folders'.format(item.data(0, QtCore.Qt.UserRole).editorVersion))
msg.setWindowTitle("Error")
msg.exec_()

def projectContextMenu(self, position: QtCore.QPoint):
item = self.projectTree.itemAt(position)
if(item == None):
if (item == None):
return
projectData = item.data(0, QtCore.Qt.UserRole)
menu = QtWidgets.QMenu()
menu.addAction("Set Icon", lambda: projectData.setIcon())
menu.addAction("Set Description", lambda: projectData.setDescription())
menu.addSeparator()
menu.addAction("Show in Explorer", lambda: projectData.showInExplorer())
menu.addAction("Show in Explorer",
lambda: projectData.showInExplorer())
menu.addSeparator()
menu.addAction("Add Editor Scripts", lambda: projectData.AddEditorScripts())
menu.addAction("Add Editor Scripts",
lambda: projectData.AddEditorScripts())
menu.addSeparator()
menu.addAction("Delete Project", lambda: projectData.deleteProject())
menu.exec(self.projectTree.mapToGlobal(position))
Expand All @@ -92,28 +134,27 @@ def searchBarChanged(self, text: str):
item = self.projectTree.topLevelItem(index)
searchText = ''.join(filter(str.isalnum, text.lower()))
itemText = ''.join(filter(str.isalnum, item.text(1).lower()))
if(searchText in itemText):
if (searchText in itemText):
item.setHidden(False)
else:
item.setHidden(True)

def __openSettings(self):
settings = SettingsDialog(self.centralwidget)
settings.exec()

# After we close the settings, reload all of the projects.
self.projectTree.clear()
self.addProjectsToList()


def main():
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = UiImplement()
ui.setupUi(MainWindow)

MainWindow = LauncherMainWindow()
MainWindow.show()

sys.exit(app.exec_())


if __name__ == "__main__":
main()
main()
21 changes: 7 additions & 14 deletions designer/UnityLauncher.ui
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,6 @@ QHeaderView::down-arrow
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="newProjectButton">
<property name="text">
<string>New Project</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="SettingsButton">
<property name="text">
<string>Settings</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="searchLineEdit">
<property name="placeholderText">
Expand All @@ -111,6 +97,13 @@ QHeaderView::down-arrow
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="SettingsButton">
<property name="text">
<string>Settings</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
2 changes: 1 addition & 1 deletion generated/FolderListGenerated.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'designer/FolderList.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
Expand Down
2 changes: 1 addition & 1 deletion generated/SettingsGenerated.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'designer/Settings.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
Expand Down
17 changes: 7 additions & 10 deletions generated/UnityLauncherGenerated.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'designer/UnityLauncher.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
Expand Down Expand Up @@ -75,16 +75,13 @@ def setupUi(self, MainWindow):
self.titleLabel.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.titleLabel.setObjectName("titleLabel")
self.gridLayout.addWidget(self.titleLabel, 0, 0, 2, 1)
self.newProjectButton = QtWidgets.QPushButton(self.topWidget)
self.newProjectButton.setObjectName("newProjectButton")
self.gridLayout.addWidget(self.newProjectButton, 0, 1, 1, 1)
self.SettingsButton = QtWidgets.QPushButton(self.topWidget)
self.SettingsButton.setObjectName("SettingsButton")
self.gridLayout.addWidget(self.SettingsButton, 0, 2, 1, 1)
self.searchLineEdit = QtWidgets.QLineEdit(self.topWidget)
self.searchLineEdit.setClearButtonEnabled(True)
self.searchLineEdit.setObjectName("searchLineEdit")
self.gridLayout.addWidget(self.searchLineEdit, 1, 1, 1, 2)
self.SettingsButton = QtWidgets.QPushButton(self.topWidget)
self.SettingsButton.setObjectName("SettingsButton")
self.gridLayout.addWidget(self.SettingsButton, 0, 2, 1, 1)
self.gridLayout.setColumnStretch(0, 5)
self.gridLayout.setColumnStretch(1, 1)
self.gridLayout.setColumnStretch(2, 1)
Expand Down Expand Up @@ -112,16 +109,15 @@ def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Unity Launcher"))
self.titleLabel.setText(_translate("MainWindow", "Projects"))
self.newProjectButton.setText(_translate("MainWindow", "New Project"))
self.SettingsButton.setText(_translate("MainWindow", "Settings"))
self.searchLineEdit.setPlaceholderText(_translate("MainWindow", "Search"))
self.SettingsButton.setText(_translate("MainWindow", "Settings"))
self.projectTree.setSortingEnabled(True)
self.projectTree.headerItem().setText(0, _translate("MainWindow", "ICON"))
self.projectTree.headerItem().setText(1, _translate("MainWindow", "NAME"))
self.projectTree.headerItem().setText(2, _translate("MainWindow", "DESCRIPTION"))
self.projectTree.headerItem().setText(3, _translate("MainWindow", "MODIFIED"))
self.projectTree.headerItem().setText(4, _translate("MainWindow", "EDITOR VERSION"))
import resources_rc
import generated.resources_rc


if __name__ == "__main__":
Expand All @@ -132,3 +128,4 @@ def retranslateUi(self, MainWindow):
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

Loading

0 comments on commit 1145c58

Please sign in to comment.