PyQt6 Compatibility

This commit is contained in:
Jeremy Rimpo
2021-12-06 10:26:32 -06:00
parent eadab929de
commit 7bb295e358
3 changed files with 42 additions and 33 deletions
+15 -15
View File
@@ -16,12 +16,12 @@ import os
import pathlib
import sys
from PyQt5.QtCore import QCoreApplication, qCritical, QFileInfo, Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QDialogButtonBox, QFileSystemModel, QLabel, QListWidget, QListWidgetItem, QMessageBox, QVBoxLayout
from FNISTool import FNISTool
from PyQt6.QtCore import QCoreApplication, qCritical, QFileInfo, Qt
from PyQt6.QtGui import QIcon, QFileSystemModel
from PyQt6.QtWidgets import QDialogButtonBox, QLabel, QListWidget, QListWidgetItem, QMessageBox, QVBoxLayout, QDialog
if "mobase" not in sys.modules:
import mock_mobase as mobase
import mobase
patchListNames = {
"Skyrim": "PatchList.txt",
@@ -46,9 +46,9 @@ class Patch:
def asQListWidgetItem(self):
listItem = QListWidgetItem(self.text_for_patch, None, 0)
listItem.setFlags(listItem.flags() | Qt.ItemIsUserCheckable)
listItem.setFlags(listItem.flags() | Qt.ItemFlag.ItemIsUserCheckable)
# We can't set the hidden status until the item is actually in a list
listItem.setData(Qt.UserRole, self.patchid)
listItem.setData(Qt.ItemDataRole.UserRole, self.patchid)
return listItem
@@ -136,13 +136,13 @@ class FNISPatches(mobase.IPluginTool):
for patch in availablePatches.values():
listItem = patch.asQListWidgetItem()
if patch.patchid in enabledPatches:
listItem.setCheckState(Qt.Checked)
listItem.setCheckState(Qt.CheckState.Checked)
else:
listItem.setCheckState(Qt.Unchecked)
listItem.setCheckState(Qt.CheckState.Unchecked)
listWidget.addItem(listItem)
listItem.setHidden(patch.hidden)
buttonBox = QDialogButtonBox(QDialogButtonBox.Save | QDialogButtonBox.Cancel)
buttonBox = QDialogButtonBox(QDialogButtonBox.StandardButton.Save | QDialogButtonBox.StandardButton.Cancel)
buttonBox.accepted.connect(dialog.accept)
buttonBox.rejected.connect(dialog.reject)
@@ -153,15 +153,15 @@ class FNISPatches(mobase.IPluginTool):
dialog.setLayout(layout)
result = dialog.exec()
if result == QDialog.Rejected:
if result == QDialog.DialogCode.Rejected:
# Cancel was pressed
return
enabledPatches = set()
for i in range(0, listWidget.count()):
listItem = listWidget.item(i)
if listItem.checkState() == Qt.Checked:
enabledPatches.add(listItem.data(Qt.UserRole))
if listItem.checkState() == Qt.CheckState.Checked:
enabledPatches.add(listItem.data(Qt.ItemDataRole.UserRole))
self.__saveEnabledPatches(enabledPatches)
def __tr(self, str):
@@ -186,11 +186,11 @@ class FNISPatches(mobase.IPluginTool):
def __getModDirectory(self):
modDirectory = None
modList = self.__organizer.modsSortedByProfilePriority()
modList = self.__organizer.modList().allModsByProfilePriority()
# Get the first managed mod so we can access the mods directory.
for mod in modList:
if (self.__organizer.modList().state(mod) & 0x2) != 0:
modDirectory = pathlib.Path(self.__organizer.getMod(mod).absolutePath()).parent
modDirectory = pathlib.Path(self.__organizer.modList().getMod(mod).absolutePath()).parent
break
return modDirectory
+16 -17
View File
@@ -16,12 +16,11 @@ import os
import pathlib
import sys
from PyQt5.QtCore import QCoreApplication, qCritical, QFileInfo
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QFileDialog, QFileSystemModel, QMessageBox
from PyQt6.QtCore import QCoreApplication, qCritical, QFileInfo
from PyQt6.QtGui import QIcon, QFileSystemModel
from PyQt6.QtWidgets import QFileDialog, QMessageBox
if "mobase" not in sys.modules:
import mock_mobase as mobase
import mobase
class FNISMissingException(Exception):
"""Thrown if GenerateFNISforUsers.exe path can't be found"""
@@ -186,10 +185,10 @@ class FNISTool(mobase.IPluginTool):
redirectOutput = bool(self.__organizer.pluginSetting(self.name(), "output-to-mod"))
initialised = bool(self.__organizer.pluginSetting(self.name(), "initialised"))
if not initialised:
result = QMessageBox.question(self.__parentWidget, self.__tr("Output to a mod?"), self.__tr("Fore's New Idles in Skyrim can output either to Mod Organizer's VFS (potentially overwriting files from multiple mods) or to a separate mod. Would you like FNIS to output to a separate mod? This setting can be updated in the Plugins tab of the Mod Organizer Settings menu."), QMessageBox.StandardButtons(QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel))
if result == QMessageBox.Yes:
result = QMessageBox.question(self.__parentWidget, self.__tr("Output to a mod?"), self.__tr("Fore's New Idles in Skyrim can output either to Mod Organizer's VFS (potentially overwriting files from multiple mods) or to a separate mod. Would you like FNIS to output to a separate mod? This setting can be updated in the Plugins tab of the Mod Organizer Settings menu."), QMessageBox.StandardButton(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No | QMessageBox.StandardButton.Cancel))
if result == QMessageBox.StandardButton.Yes:
redirectOutput = True
elif result == QMessageBox.No:
elif result == QMessageBox.StandardButton.No:
redirectOutput = False
else:
# the user pressed cancel
@@ -202,10 +201,10 @@ class FNISTool(mobase.IPluginTool):
redirectLogs = bool(self.__organizer.pluginSetting(self.name(), "output-logs-to-mod"))
initialised = bool(self.__organizer.pluginSetting(self.name(), "initialised"))
if not initialised:
result = QMessageBox.question(self.__parentWidget, self.__tr("Output logs to a mod?"), self.__tr("Any new logs generated when running FNIS will end up in Mod Organizer's overwrite folder. Would you like these logs to be output to a separate mod? This setting can be updated in the Plugins tab of the Mod Organizer Settings menu."), QMessageBox.StandardButtons(QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel))
if result == QMessageBox.Yes:
result = QMessageBox.question(self.__parentWidget, self.__tr("Output logs to a mod?"), self.__tr("Any new logs generated when running FNIS will end up in Mod Organizer's overwrite folder. Would you like these logs to be output to a separate mod? This setting can be updated in the Plugins tab of the Mod Organizer Settings menu."), QMessageBox.StandardButton(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No | QMessageBox.StandardButton.Cancel))
if result == QMessageBox.StandardButton.Yes:
redirectLogs = True
elif result == QMessageBox.No:
elif result == QMessageBox.StandardButton.No:
redirectLogs = False
else:
# the user pressed cancel
@@ -222,7 +221,7 @@ class FNISTool(mobase.IPluginTool):
if not pathlibPath.is_dir() or not isAMod:
QMessageBox.information(self.__parentWidget, self.__tr("Choose an output mod"), self.__tr("Please choose an output mod for Fore's New Idles in Skyrim. This must be a directory in Mod Organizer's mods directory, and you can create one if you do not have one already. This mod will not be available to the VFS when FNIS is run, so do not choose a mod you use for anything else. This setting can be updated in the Plugins tab of the Mod Organizer Settings menu."))
while not pathlibPath.is_dir() or not isAMod:
path = QFileDialog.getExistingDirectory(self.__parentWidget, self.__tr("Choose an output mod"), str(modDirectory), QFileDialog.ShowDirsOnly)
path = QFileDialog.getExistingDirectory(self.__parentWidget, self.__tr("Choose an output mod"), str(modDirectory), QFileDialog.Option.ShowDirsOnly)
if not path:
# cancel was pressed
raise UnknownOutputPreferenceException
@@ -237,7 +236,7 @@ class FNISTool(mobase.IPluginTool):
empty = False
break
if not empty:
if QMessageBox.question(self.__parentWidget, self.__tr("Mod not empty"), self.__tr("The selected mod already contains files. Are you sure want to use it as the output mod?"), QMessageBox.StandardButtons(QMessageBox.Yes | QMessageBox.No)) == QMessageBox.Yes:
if QMessageBox.question(self.__parentWidget, self.__tr("Mod not empty"), self.__tr("The selected mod already contains files. Are you sure want to use it as the output mod?"), QMessageBox.StandardButton(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)) == QMessageBox.StandardButton.Yes:
# Proceed normally - the user is happy
pass
else:
@@ -258,7 +257,7 @@ class FNISTool(mobase.IPluginTool):
if not pathlibPath.is_dir() or not isAMod or isSameAsFnisOutput:
QMessageBox.information(self.__parentWidget, self.__tr("Choose an output mod"), self.__tr("Please choose an output mod for logs for Fore's New Idles in Skyrim. This must be a directory in Mod Organizer's mods directory, must not be the same as the FNIS output mod, and you can create one if you do not have one already. This setting can be updated in the Plugins tab of the Mod Organizer Settings menu."))
while not pathlibPath.is_dir() or not isAMod or isSameAsFnisOutput:
path = QFileDialog.getExistingDirectory(self.__parentWidget, self.__tr("Choose a log output mod"), str(modDirectory), QFileDialog.ShowDirsOnly)
path = QFileDialog.getExistingDirectory(self.__parentWidget, self.__tr("Choose a log output mod"), str(modDirectory), QFileDialog.Option.ShowDirsOnly)
if not path:
# cancel was pressed
raise UnknownOutputPreferenceException
@@ -277,7 +276,7 @@ class FNISTool(mobase.IPluginTool):
empty = False
break
if not empty:
if QMessageBox.question(self.__parentWidget, self.__tr("Mod not empty"), self.__tr("The selected mod already contains files. Are you sure want to use it as the output mod?"), QMessageBox.StandardButtons(QMessageBox.Yes | QMessageBox.No)) == QMessageBox.Yes:
if QMessageBox.question(self.__parentWidget, self.__tr("Mod not empty"), self.__tr("The selected mod already contains files. Are you sure want to use it as the output mod?"), QMessageBox.StandardButton(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)) == QMessageBox.StandardButton.Yes:
# Proceed normally - the user is happy
pass
else:
@@ -322,8 +321,8 @@ class FNISTool(mobase.IPluginTool):
break
if (self.__organizer.modList().state(fnisModName) & mobase.ModState.active) == 0:
# FNIS is installed to an inactive mod
result = QMessageBox.question(self.__parentWidget, self.__tr("FNIS mod deactivated"), self.__tr("Fore's New Idles in Skyrim is installed to an inactive mod. Press OK to activate it or Cancel to quit the tool"), QMessageBox.StandardButtons(QMessageBox.Ok | QMessageBox.Cancel))
if result == QMessageBox.Ok:
result = QMessageBox.question(self.__parentWidget, self.__tr("FNIS mod deactivated"), self.__tr("Fore's New Idles in Skyrim is installed to an inactive mod. Press OK to activate it or Cancel to quit the tool"), QMessageBox.StandardButton(QMessageBox.StandardButton.Ok | QMessageBox.StandardButton.Cancel))
if result == QMessageBox.StandardButton.Ok:
self.__organizer.modList().setActive(fnisModName, True)
else:
raise FNISInactiveException
+11 -1
View File
@@ -1,3 +1,13 @@
import os
import sys
from FNISTool import FNISTool
from PyQt6.QtCore import QFileInfo, QCoreApplication
from PyQt6.QtGui import QFileSystemModel, QIcon
from PyQt6.QtWidgets import QMessageBox
import mobase
class FNISToolReset(mobase.IPluginTool):
def __init__(self):
super(FNISToolReset, self).__init__()
@@ -52,7 +62,7 @@ class FNISToolReset(mobase.IPluginTool):
def display(self):
result = QMessageBox.question(self.__parentWidget, self.__tr("Reset settings?"), self.__tr("Would you like to reset the options that pop up when you first ran \"{}\"?").format(self.__mainToolName()))
if (result == QMessageBox.Yes):
if result == QMessageBox.StandardButton.Yes:
self.__organizer.setPluginSetting(self.__mainToolName(), "initialised", False)
def __tr(self, str):