diff --git a/src/openmwplayer/modules/openmwplayer_paths.py b/src/openmwplayer/modules/openmwplayer_paths.py index f431b2b..1ee6eea 100644 --- a/src/openmwplayer/modules/openmwplayer_paths.py +++ b/src/openmwplayer/modules/openmwplayer_paths.py @@ -2,6 +2,12 @@ from ...shared.shared_paths import SharedPaths from .openmwplayer_settings import OpenMWPlayerSettings from pathlib import Path +try: + from PyQt5.QtCore import QCoreApplication, QStandardPaths + from PyQt5.QtWidgets import QFileDialog +except: + from PyQt6.QtCore import QCoreApplication, QStandardPaths + from PyQt6.QtWidgets import QFileDialog import os class OpenMWPlayerPaths(SharedPaths): @@ -21,12 +27,12 @@ def openMWCfgPath(self): # Grab the default path if it exists. defaultLocation = Path(QStandardPaths.locate(QStandardPaths.DocumentsLocation, str(Path("My Games", "OpenMW", "openmw.cfg")))) if defaultLocation.is_file(): - self.__organizer.setPluginSetting(self.name(), "openmwcfgpath", str(defaultLocation)) + self.organiser.setPluginSetting("OpenMWPlayer", "openmwcfgpath", str(defaultLocation)) return defaultLocation # Otherwise, get the user to provide a path. - manualPath = Path(QFileDialog.getOpenFileName(self._parentWidget(), self.__tr("Locate OpenMW Config File"), ".", "OpenMW Config File (openmw.cfg)")[0]) - self.__organizer.setPluginSetting(self.name(), "openmwcfgpath", str(manualPath)) + manualPath = Path(QFileDialog.getOpenFileName(None, "Locate OpenMW Config File", ".", "OpenMW Config File (openmw.cfg)")[0]) + self.organiser.setPluginSetting("OpenMWPlayer", "openmwcfgpath", str(manualPath)) return manualPath def openMwCustomSettingsPath(self, profile): diff --git a/src/openmwplayer/openmwplayer.py b/src/openmwplayer/openmwplayer.py index e07c21d..750f385 100644 --- a/src/openmwplayer/openmwplayer.py +++ b/src/openmwplayer/openmwplayer.py @@ -31,10 +31,14 @@ def runOpenMW(self, appName): fileName = appPath.name if fileName in self._openMwExeNames: # Export settings to OpenMW + qInfo("OpenMWPlayer: OpenMW exe detected, exporting setup.") self.exportMOSetup() - + qInfo("OpenMWPlayer: OpenMW setup export complete.") + # Run app separately. + qInfo("OpenMWPlayer: Running selected exe.") os.startfile(appName) + return False else: return True diff --git a/src/openmwplayer/openmwplayer_plugin.py b/src/openmwplayer/openmwplayer_plugin.py index 0a3c68e..0acfe40 100644 --- a/src/openmwplayer/openmwplayer_plugin.py +++ b/src/openmwplayer/openmwplayer_plugin.py @@ -7,26 +7,15 @@ except: from PyQt6.QtCore import QCoreApplication, qInfo -class OpenMWPlayerPlugin(SharedPlugin, mobase.IPlugin): +class OpenMWPlayerPlugin(SharedPlugin): def __init__(self): - super().__init__("OpenMWPlayer", "OpenMW Player", mobase.VersionInfo(0, 0, 3, mobase.ReleaseType.ALPHA)) + super().__init__("OpenMWPlayer", "OpenMW Player", mobase.VersionInfo(0, 0, 4, mobase.ReleaseType.ALPHA)) def init(self, organiser=mobase.IOrganizer): - self.organiser = organiser - self.openMWPlayer = OpenMWPlayer(self.organiser) - self.organiser.onAboutToRun(lambda appName: self.runOpenMW(appName)) + self.openMWPlayer = OpenMWPlayer(organiser) return super().init(organiser) - def name(self): - return self.baseName() - - def displayName(self): - return "OpenMW Player" - - def description(self): - return self.__tr("Launches OpenMW executables using the current mod setup enabled in Mod Organizer 2.") - def __tr(self, trstr): return QCoreApplication.translate(self.pluginName, trstr) @@ -34,7 +23,4 @@ def settings(self): """ Current list of game settings for Mod Organizer. """ return [ mobase.PluginSetting("openmwcfgpath",self.__tr("Path to openmw.cfg"),"/Path/To/OpenMW/openmw.cfg") - ] - - def runOpenMW(self, appName): - self.openMWPlayer.runOpenMW(appName) \ No newline at end of file + ] \ No newline at end of file diff --git a/src/openmwplayer/plugins/openmwplayer_plugin_launcher.py b/src/openmwplayer/plugins/openmwplayer_plugin_launcher.py index e69de29..820ec17 100644 --- a/src/openmwplayer/plugins/openmwplayer_plugin_launcher.py +++ b/src/openmwplayer/plugins/openmwplayer_plugin_launcher.py @@ -0,0 +1,28 @@ +import mobase +from pathlib import Path +from ..openmwplayer_plugin import OpenMWPlayerPlugin +try: + from PyQt5.QtCore import QCoreApplication, qInfo +except: + from PyQt6.QtCore import QCoreApplication, qInfo + +class OpenMWPlayerPluginLauncher(OpenMWPlayerPlugin, mobase.IPlugin): + + def __init__(self): + super().__init__() + + def init(self, organiser=mobase.IOrganizer): + organiser.onAboutToRun(lambda appName: self.runOpenMW(appName)) + return super().init(organiser) + + def name(self): + return self.baseName() + + def description(self): + return self.__tr("Launches OpenMW executables using the current mod setup enabled in Mod Organizer 2.") + + def __tr(self, trstr): + return QCoreApplication.translate(self.pluginName, trstr) + + def runOpenMW(self, appName): + return self.openMWPlayer.runOpenMW(appName) \ No newline at end of file diff --git a/src/openmwplayer/plugins/openmwplayer_tool_manage.py b/src/openmwplayer/plugins/openmwplayer_tool_manage.py index e69de29..301b7b9 100644 --- a/src/openmwplayer/plugins/openmwplayer_tool_manage.py +++ b/src/openmwplayer/plugins/openmwplayer_tool_manage.py @@ -0,0 +1,164 @@ +try: + from PyQt5.QtWidgets import QFileDialog, QFileIconProvider, QInputDialog, QLineEdit, QWidget + from PyQt5.QtCore import QCoreApplication, qInfo, QSize, QStandardPaths + from PyQt5 import QtGui, QtWidgets, QtCore + from PyQt5.QtWidgets import QFileIconProvider + qtHorizontal = QtCore.Qt.Horizontal + qtCancel = QtWidgets.QDialogButtonBox.Cancel + qtOkay = QtWidgets.QDialogButtonBox.Ok + qtStaysOnTop = QtCore.Qt.WindowStaysOnTopHint + qtSizePolicy = QtWidgets.QSizePolicy + qtItemView = QtWidgets.QAbstractItemView + qtItemFlag = QtCore.Qt + qtCheckState = QtCore.Qt + qtMatchFlag = QtCore.Qt +except: + from PyQt6.QtWidgets import QFileDialog, QFileIconProvider, QInputDialog, QLineEdit, QWidget + from PyQt6.QtCore import QCoreApplication, qInfo, QSize, QStandardPaths + from PyQt6 import QtGui, QtWidgets, QtCore + from PyQt6.QtWidgets import QFileIconProvider + qtHorizontal = QtCore.Qt.Orientation.Horizontal + qtCancel = QtWidgets.QDialogButtonBox.StandardButton.Cancel + qtOkay = QtWidgets.QDialogButtonBox.StandardButton.Ok + qtStaysOnTop = QtCore.Qt.WindowType.WindowStaysOnTopHint + qtSizePolicy = QtWidgets.QSizePolicy.Policy + qtItemView = QtWidgets.QAbstractItemView.SelectionMode + qtItemFlag = QtCore.Qt.ItemFlag + qtCheckState = QtCore.Qt.CheckState + qtMatchFlag = QtCore.Qt.MatchFlag +from ..openmwplayer_plugin import OpenMWPlayerPlugin +from ...shared.shared_icons import SharedIcons +import mobase, re + +class OpenMWPlayerManageTool(OpenMWPlayerPlugin, mobase.IPluginTool): + + def __init__(self): + super().__init__() + + def init(self, organiser=mobase.IOrganizer): + res = super().init(organiser) + self.dialog = self.getDialog() + return res + + def __tr(self, trstr): + return QCoreApplication.translate(self.pluginName, trstr) + + def master(self): + return self.pluginName + + def settings(self): + return [] + + def icon(self): + return self.icons.openMwIcon() + + def name(self): + return self.baseName() + " Manage Tool" + + def description(self): + return self.__tr("Manage OpenMW Player settings.") + + def display(self): + self.dialog.show() + self.bindPlugins() + + def bindPlugins(self): + self.addText.setText(str(self.openMWPlayer.paths.openMWCfgPath())) + + profile = self.organiser.profile().name() + groundCoverCustom = self.openMWPlayer.paths.openMwGrassSettingsPath(profile) + groundCoverFiles = [] + if not groundCoverCustom.exists(): + with groundCoverCustom.open("x") as custNew: + custNew.write("\n") + with groundCoverCustom.open("r") as custGrnd: + for line in custGrnd: + line = line.replace("\n", "") + if len(line) > 0: + groundCoverFiles.append(line) + + self.profileSelect.clear() + for name in self.organiser.pluginList().pluginNames(): + item = QtWidgets.QListWidgetItem() + item.setText(name) + item.setFlags(qtItemFlag.ItemIsUserCheckable|qtItemFlag.ItemIsEnabled) + item.setCheckState(qtCheckState.Unchecked) + self.profileSelect.addItem(item) + + for name in groundCoverFiles: + for itm in self.profileSelect.findItems(name, qtMatchFlag.MatchExactly): + itm.setCheckState(qtCheckState.Checked) + + + def selectOpenMWCfg(self): + manualPath = QFileDialog.getOpenFileName(self._parentWidget(), self.__tr("Locate OpenMW Config File"), ".", "OpenMW Config File (openmw.cfg)")[0] + self.organiser.setPluginSetting(self.name(), "openmwcfgpath", str(manualPath)) + self.addText.setText(str(manualPath)) + + def changePluginState(self): + selected = [] + for x in range(self.profileSelect.count()): + p = self.profileSelect.item(x) + if p.checkState() == qtCheckState.Checked: + selected.append(p.text()) + + profile = self.organiser.profile().name() + groundCoverCustom = self.openMWPlayer.paths.openMwGrassSettingsPath(profile) + with groundCoverCustom.open("w") as custGrnd: + for item in selected: + custGrnd.write(item + "\n") + + def getDialog(self): + dialog = QtWidgets.QDialog() + dialog.setObjectName("dialog") + dialog.resize(475, 340) + dialog.setWindowIcon(self.icons.syncIcon()) + dialog.setWindowTitle("OpenMW Player") + self.dialogLayout = QtWidgets.QVBoxLayout(dialog) + self.dialogLayout.setContentsMargins(5, 5, 5, 5) + self.dialogLayout.setSpacing(5) + self.dialogLayout.setObjectName("dialogLayout") + + self.addWidget = QtWidgets.QWidget(dialog) + self.addWidget.setObjectName("addWidget") + self.addLayout = QtWidgets.QHBoxLayout(self.addWidget) + self.addLayout.setContentsMargins(0, 0, 0, 0) + self.addLayout.setSpacing(5) + self.addLayout.setObjectName("addLayout") + self.addText = QtWidgets.QLabel(self.addWidget) + self.addText.setObjectName("addText") + self.addButton = QtWidgets.QPushButton(self.addWidget) + sizePolicy = QtWidgets.QSizePolicy(qtSizePolicy.Fixed, qtSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.addButton.sizePolicy().hasHeightForWidth()) + self.addButton.setSizePolicy(sizePolicy) + self.addButton.setIcon(self.icons.linkIcon()) + self.addButton.setObjectName("addButton") + self.addButton.setText("OpenMW.cfg") + self.addButton.clicked.connect(self.selectOpenMWCfg) + self.addLayout.addWidget(self.addButton) + self.addLayout.addWidget(self.addText) + self.dialogLayout.addWidget(self.addWidget) + + self.gcvWidget = QtWidgets.QWidget(dialog) + self.gcvWidget.setObjectName("gcvWidget") + self.gcvLayout = QtWidgets.QHBoxLayout(self.gcvWidget) + self.gcvLayout.setContentsMargins(0, 0, 0, 0) + self.gcvLayout.setSpacing(5) + self.gcvLayout.setObjectName("gcvLayout") + self.gcvText = QtWidgets.QLabel(self.gcvWidget) + self.gcvText.setText("Select Groundcover Plugins") + self.gcvText.setObjectName("gcvText") + self.gcvLayout.addWidget(self.gcvText) + self.dialogLayout.addWidget(self.gcvWidget) + + self.profileSelect = QtWidgets.QListWidget(dialog) + self.profileSelect.setSelectionMode(qtItemView.MultiSelection) + self.profileSelect.setObjectName("profileSelect") + self.profileSelect.itemChanged.connect(self.changePluginState) + self.dialogLayout.addWidget(self.profileSelect) + + QtCore.QMetaObject.connectSlotsByName(dialog) + + return dialog \ No newline at end of file diff --git a/src/openmwplayer_init.py b/src/openmwplayer_init.py index ef2d71d..d36c049 100644 --- a/src/openmwplayer_init.py +++ b/src/openmwplayer_init.py @@ -1,7 +1,9 @@ import mobase -from .openmwplayer.openmwplayer_plugin import OpenMWPlayerPlugin +from .openmwplayer.plugins.openmwplayer_plugin_launcher import OpenMWPlayerPluginLauncher +from .openmwplayer.plugins.openmwplayer_tool_manage import OpenMWPlayerManageTool def createPlugins(): return [ - OpenMWPlayerPlugin() + OpenMWPlayerPluginLauncher(), + OpenMWPlayerManageTool() ] \ No newline at end of file diff --git a/src/shared/icons/ui-openmw.ico b/src/shared/icons/ui-openmw.ico new file mode 100644 index 0000000..31129fb Binary files /dev/null and b/src/shared/icons/ui-openmw.ico differ diff --git a/src/shared/shared_icons.py b/src/shared/shared_icons.py index d269e4c..c1a97bd 100644 --- a/src/shared/shared_icons.py +++ b/src/shared/shared_icons.py @@ -97,4 +97,7 @@ def filterIcon(self): return self.icon("ui-filter.ico") def recycleIcon(self): - return self.icon("ui-recycle.ico") \ No newline at end of file + return self.icon("ui-recycle.ico") + + def openMwIcon(self): + return self.icon("ui-openmw.ico") \ No newline at end of file diff --git a/tools/icons.psd b/tools/icons.psd index 1874157..51f174b 100644 Binary files a/tools/icons.psd and b/tools/icons.psd differ