Skip to content

Commit

Permalink
Merge pull request #26 from AresConnor/master
Browse files Browse the repository at this point in the history
修复了无法启动的问题,优化了Dialog
  • Loading branch information
LxHTT authored Mar 26, 2023
2 parents 4eb4059 + 3624721 commit a83f0a2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 80 deletions.
134 changes: 58 additions & 76 deletions MCSL2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from json import dumps, loads
from os import getcwd, mkdir, remove, sep
from os import getcwd, mkdir, sep
from os import path as ospath
from shutil import copy
from sys import argv, exit
Expand All @@ -26,6 +26,7 @@
# Initialize MainWindow
class MCSL2MainWindow(QMainWindow, Ui_MCSL2_MainWindow):
def __init__(self):
InitMCSL()
super(MCSL2MainWindow, self).__init__()
self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
effect = QGraphicsDropShadowEffect(self)
Expand Down Expand Up @@ -78,6 +79,7 @@ def __init__(self):
self.javaFindWorkThreadFactory.FinishSignalConnect = self.OnJavaFindWorkThreadFinished
# create java finder workThread instance and start
self.javaFindWorkThreadFactory.Create().start()

def paintEvent(self, event):
pat2 = QPainter(self)
pat2.setRenderHint(pat2.Antialiasing)
Expand Down Expand Up @@ -351,7 +353,7 @@ def SaveMinecraftServer(self):
NameStatus = 0

# Pop-up determine
# Create List
# Create List
ChkVal = []
ChkVal.append(MinMemStatus)
ChkVal.append(MaxMemStatus)
Expand Down Expand Up @@ -484,7 +486,7 @@ def SaveMinecraftServer(self):
else:
CanCreate = 0
Tip = "你什么都没设置好呢\n\n(恼"
#终于写完了.jpg
# 终于写完了.jpg

# Server processor
if CanCreate == 0:
Expand Down Expand Up @@ -548,21 +550,12 @@ def AutoDetectJava(self):
@pyqtSlot(list)
def JavaDetectFinished(self, _JavaPaths: list):
global JavaPaths
JavaPaths = _JavaPaths
if not ospath.exists(r"./MCSL2"):
pass
else:
if ospath.exists(r"./MCSL2/AutoDetectJavaHistory.txt"):
with open(r"./MCSL2/AutoDetectJavaHistory.txt", 'w', encoding='utf-8') as SaveFoundedJava:
SaveFoundedJava.writelines([p + '\n' for p in JavaPaths])
SaveFoundedJava.close()
else:
with open(r"./MCSL2/AutoDetectJavaHistory.txt", 'w+', encoding='utf-8') as InitFoundedJava:
InitFoundedJava.write("")
InitFoundedJava.close()
with open(r"./MCSL2/AutoDetectJavaHistory.txt", 'w', encoding='utf-8') as SaveFoundedJava:
SaveFoundedJava.writelines([p + '\n' for p in JavaPaths])
SaveFoundedJava.close()

with open("MCSL2/AutoDetectJavaHistory.txt", 'w+', encoding='utf-8') as SaveFoundedJava:
JavaPaths = list({p[:-1] for p in SaveFoundedJava.readlines()}.union(set(JavaPaths)).union(set(_JavaPaths)))
# 获取新发现的Java路径,或者用户选择的Java路径
SaveFoundedJava.writelines([p + '\n' for p in JavaPaths])

@pyqtSlot(int)
def OnJavaFindWorkThreadFinished(self, sequenceNumber):

Expand All @@ -575,7 +568,6 @@ def OnJavaFindWorkThreadFinished(self, sequenceNumber):
self.Auto_Find_Java_PushButton.setEnabled(True)
# 更新self.ChooseJavaScrollAreaVerticalLayout中的内容


def ShowFoundedJavaList_Back(self):
self.FunctionsStackedWidget.setCurrentIndex(1)
self.Blue2.setStyleSheet(
Expand Down Expand Up @@ -1079,21 +1071,15 @@ def InitSelectJavaSubWidget(self):
# 清空self.ChooseJavaScrollAreaVerticalLayout下的所有子控件
for i in reversed(range(self.ChooseJavaScrollAreaVerticalLayout.count())):
self.ChooseJavaScrollAreaVerticalLayout.itemAt(i).widget().setParent(None)
if ospath.exists(r"./MCSL2/AutoDetectJavaHistory.txt"):
with open(r"./MCSL2/AutoDetectJavaHistory.txt", 'w+', encoding='utf-8') as InitFoundedJava:
InitFoundedJava.write("")
InitFoundedJava.close()
with open(r"./MCSL2/AutoDetectJavaHistory.txt", 'w', encoding='utf-8') as SaveFoundedJava:
SaveFoundedJava.writelines([p + '\n' for p in JavaPaths])
SaveFoundedJava.close()

# 重新添加子控件
if len(JavaPaths) == 0:
if ospath.exists(r"MCSL2/AutoDetectJavaHistory.txt"):
with open(r"./MCSL2/AutoDetectJavaHistory.txt", 'r', encoding='utf-8') as ReadFoundedJava:
if ospath.exists("MCSL2/AutoDetectJavaHistory.txt"):
with open("MCSL2/AutoDetectJavaHistory.txt", 'r', encoding='utf-8') as ReadFoundedJava:
FoundedJavaTMP = [p[:-1] for p in ReadFoundedJava.readlines()]
print(FoundedJavaTMP)
JavaPaths = FoundedJavaTMP

for i in range(len(JavaPaths)):
self.MCSL2_SubWidget_Select = QWidget()
self.MCSL2_SubWidget_Select.setGeometry(QRect(150, 110, 620, 70))
Expand Down Expand Up @@ -1217,50 +1203,48 @@ def CheckUpdate(self):

# Customize dialogs
class MCSL2Dialog(QDialog, Ui_MCSL2_Dialog):
def __init__(self):
def __init__(self, Tip):
super(MCSL2Dialog, self).__init__()
self.setupUi(self)
self.Dialog_label.setText(Tip)


class MCSL2AskDialog(QDialog, Ui_MCSL2_AskDialog):
def __init__(self):
def __init__(self, Tip):
super(MCSL2AskDialog, self).__init__()
self.setupUi(self)
self.Dialog_label.setText(Tip)


# The function of calling MCSL2 Dialog
def CallMCSL2Dialog(Tip, isNeededTwoButtons):
SaveTip = open(r"Tip", "w+")
SaveTip.write(Tip)
SaveTip.close()
if isNeededTwoButtons == 0:
MCSL2Dialog().exec()
remove(r"Tip")
MCSL2Dialog(Tip).exec()
elif isNeededTwoButtons == 1:
MCSL2AskDialog().exec()
remove(r"Tip")
MCSL2AskDialog(Tip).exec()
else:
pass


def InitMCSL(isFirstLaunch):
if isFirstLaunch == 1:
CallMCSL2Dialog(Tip="请注意:\n\n本程序无法在125%的\n\nDPI缩放比下正常运行。\n\n(本提示仅在首次启动出现)",
def InitMCSL():
if not ospath.exists(r"MCSL2"):
mkdir(r"MCSL2")
CallMCSL2Dialog(Tip="请注意:\n\n本程序无法在125%的\n\nDPI缩放比下正常运行。\n(本提示仅在首次启动出现)",
isNeededTwoButtons=0)
if not ospath.exists(r"MCSL2"):
mkdir(r"MCSL2")
mkdir(r"MCSL2/Aria2")
with open(r"./MCSL2/MCSL2_Config.json", "w+", encoding="utf-8") as InitConfig:
ConfigTemplate = ""
InitConfig.write(ConfigTemplate)
InitConfig.close()
with open(r"./MCSL2/MCSL2_ServerList.json", "w+", encoding="utf-8") as InitServerList:
ServerListTemplate = '{\n "MCSLServerList": [\n\n ]\n}'
InitServerList.write(ServerListTemplate)
InitServerList.close()
with open(r"./MCSL2/AutoDetectJavaHistory.txt", 'w+', encoding='utf-8') as InitFoundedJava:
InitFoundedJava.write("")
InitFoundedJava.close()
mkdir(r"MCSL2/Aria2")
with open(r"./MCSL2/MCSL2_Config.json", "w+", encoding="utf-8") as InitConfig:
ConfigTemplate = ""
InitConfig.write(ConfigTemplate)
InitConfig.close()
with open(
r"./MCSL2/MCSL2_ServerList.json", "w+", encoding="utf-8"
) as InitServerList:
ServerListTemplate = '{\n "MCSLServerList": [\n {\n "name": "MCSLReplacer",\n ' \
'"core_file_name": "MCSLReplacer",\n "java_path": "MCSLReplacer",' \
'\n "min_memory": "MCSLReplacer",\n "max_memory": "MCSLReplacer"\n }\n ' \
']\n} '
InitServerList.write(ServerListTemplate)
InitServerList.close()
if not ospath.exists(r"Servers"):
mkdir(r"./Servers")

Expand Down Expand Up @@ -1316,8 +1300,8 @@ def DecodeDownloadJsons(RefreshUrl):
except:
print(DownloadJson)
Tip = "可能解析api内容失败\n\n请检查网络或自己的节点设置"
CallMCSL2Dialog(Tip,isNeededTwoButtons=0)
return -1,-1,-1,-1
CallMCSL2Dialog(Tip, isNeededTwoButtons=0)
return -1, -1, -1, -1


def GetFileVersion(File):
Expand All @@ -1329,22 +1313,20 @@ def GetFileVersion(File):
return Version


# Start MCSL
JavaPath = 0
JavaPaths = []
DiskSymbols = []
SearchStatus = 0
CorePath = ""
DownloadSource = 0
Version = "2.0.1"

QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
MCSLProcess = QApplication(argv)
MCSLMainWindow = MCSL2MainWindow()
MCSLMainWindow.show()
if not ospath.exists(r"MCSL2"):
InitMCSL(isFirstLaunch=1)
else:
InitMCSL(isFirstLaunch=0)
exit(MCSLProcess.exec_())
if __name__ == '__main__':
# Start MCSL
JavaPath = 0
JavaPaths = []
DiskSymbols = []
SearchStatus = 0
CorePath = ""
DownloadSource = 0
Version = "2.0.1"

QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
MCSLProcess = QApplication(argv)
MCSLMainWindow = MCSL2MainWindow()
MCSLMainWindow.show()

exit(MCSLProcess.exec_())
2 changes: 0 additions & 2 deletions MCSL2_AskDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,4 @@ def retranslateUi(self, MCSL2_AskDialog):
MCSL2_AskDialog.setWindowTitle(_translate("MCSL2_AskDialog", "提示"))
self.Dialog_PushButton_Accept.setText(_translate("MCSL2_AskDialog", "确定"))
self.Dialog_PushButton_Cancel.setText(_translate("MCSL2_AskDialog", "取消"))
Tip = open(r"Tip", "r").read()
self.Dialog_label.setText(_translate("MCSL2_AskDialog", Tip))
self.Dialog_PushButton_Accept.clicked.connect(self.close)
2 changes: 0 additions & 2 deletions MCSL2_Dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,4 @@ def retranslateUi(self, MCSL2_Dialog):
_translate = QCoreApplication.translate
MCSL2_Dialog.setWindowTitle(_translate("MCSL2_Dialog", "提示"))
self.Dialog_PushButton.setText(_translate("MCSL2_Dialog", "知道了"))
Tip = open(r"Tip", "r").read()
self.Dialog_label.setText(_translate("MCSL2_Dialog", Tip))
self.Dialog_PushButton.clicked.connect(self.close)

0 comments on commit a83f0a2

Please sign in to comment.