ModOrganizer2 / modorganizer

Mod manager for various PC games. Discord Server: https://discord.gg/ewUVAqyrQX if you would like to be more involved
http://www.nexusmods.com/skyrimspecialedition/mods/6194
GNU General Public License v3.0
2.07k stars 155 forks source link

Python bindings' `mobase.PluginSetting.key` yields errors when accessed #1826

Open Ryan-rsm-McKenzie opened 1 year ago

Ryan-rsm-McKenzie commented 1 year ago

The problem:

When accessing the key attribute on an instance of mobase.PluginSetting an error is thrown reporting TypeError: No Python class registered for C++ class class QString

To Reproduce:

Steps to reproduce the behavior:

  1. Create the following plugin in the plugins directory:
    
    # sample_plugin.py

import typing

import mobase from PyQt5.QtWidgets import QMainWindow, QMessageBox

class SamplePlugin(mobase.IPlugin): def init(self, organizer: mobase.IOrganizer) -> bool: organizer.onUserInterfaceInitialized(self.__onUserInterfaceInitialized) return True

def __onUserInterfaceInitialized(self, window: QMainWindow) -> None:
    setting = self.settings()[0]
    QMessageBox.information(None, "Info", str(setting.key))  # error

def author(self) -> str:
    return "John Doe"

def description(self) -> str:
    return "A sample plugin"

def name(self) -> str:
    return "Sample Plugin"

def settings(self) -> typing.List[mobase.PluginSetting]:
    return [mobase.PluginSetting("my_key", "a sample setting", True)]

def version(self) -> mobase.VersionInfo:
    return mobase.VersionInfo(1, 0, 0)

def createPlugin() -> mobase.IPlugin: return SamplePlugin()



2. Boot up MO2
3. Error

## Environment:

* Mod Organizer Version that exhibits the issue: v2.4.4
* Last Mod Organizer Version that did not exhibit the issue (if applicable): ¯\\\_( ツ )\_/¯
* Desktop OS/version used to run Mod Organizer: Windows 10, 19045.2965

## Details:
Behold the error in all its glory:
https://i.imgur.com/oDzTDvd.png

## Link to Mod Organizer logs:
### USVFS:
https://gist.github.com/Ryan-rsm-McKenzie/8e67177a9908ab88f3ad8e6f5508000b

### MO Interface:
https://gist.github.com/Ryan-rsm-McKenzie/7fbc857ba24d0129e9f3bf9131f5ad60
Al12rs commented 1 year ago

Hi Ryan, only thing that could stand out as a potential problem is the str() around the settings.key. Did you already try without? Otherwise I wouldn't really know what could be the issue

AnyOldName3 commented 1 year ago

QStrings are supposed to be implicitly converted to Python strings, so I guess the explicit conversion bypasses the implicit one and we've never had to deal with that before as no one's tried converting what has a convincing fake ID saying it's a string to another string.

Ryan-rsm-McKenzie commented 1 year ago

Removing the str() doesn't work either

AnyOldName3 commented 1 year ago

The binding is defined here: https://github.com/ModOrganizer2/modorganizer-plugin_python/blob/7c54a45f636bc34ade6e687f33982581d1b0fcf9/src/runner/pythonrunner.cpp#L244

Are any of the other def_readwrite fields of any types working?

Ryan-rsm-McKenzie commented 1 year ago

I tested description and default_value and those both failed with the same error message.

Silarn commented 1 year ago

I'd be curious to know if this still happens on the dev builds which are using qt6. I don't remember if the last release included moving off of boost python, which was also a somewhat recent change.

AnyOldName3 commented 1 year ago

Oh, PyQt5. In that case, the lines I linked are less relevant as a bunch of stuff changed. As well as converting from PyQt5 to PyQt6 (and therefore changing SIP versions and how things are bound), we changed from boost::python to pybind11, so it could also have been something lost from doing that if we did it before the last release.