Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for PySide6's snake_case __feature__ #67

Open
HealsCodes opened this issue Oct 20, 2022 · 2 comments
Open

Support for PySide6's snake_case __feature__ #67

HealsCodes opened this issue Oct 20, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@HealsCodes
Copy link

When using qasync together with the snake_case feature of PySide6 the following messages will be printed every few milliseconds:

Traceback (most recent call last):
File "REDACTED/.venv/lib/python3.10/site-packages/qasync/init.py", line 287, in timerEvent
self.killTimer(timerid)
Traceback (most recent call last):
File "REDACTED/.venv/lib/python3.10/site-packages/qasync/init.py", line 285, in timerEvent
del self.__callbacks[timerid]
KeyError: 1

The base issue is that snake_case causes PySide to export all methods in snake_case instead of camelCase.
A fix would be for qasync to check for the existence of the expected method and otherwise assume snake_case:

class _SimpleTimer(QtCore.QObject):
    def __killTimer(self, timerId):
        try:
          self.killTimer(timerId)
        except AttributeError:
          self.kill_timer(timerId)

snake_case is one of the new features added in PySide6 which cane be user enabled but affect the whole runtime.
true_property would be another which replaces the .getXY() and .xy pairs with real assignable object properties.

Both of them can be enabled like this:

import PySide6
from __feature__ import (snake_case, true_property)
@hosaka
Copy link
Collaborator

hosaka commented Nov 15, 2022

Would be quite a change to add support for this, at least snake_case and true_property would have to be separate PRs. I am not able to even run a basic app:

Traceback (most recent call last):
  File "E:\qasync\qasync\__init__.py", line 347, in __init__
    signaller.signal.connect(lambda callback, args: self.call_soon(callback, *args))
AttributeError: 'Signaller' object has no attribute 'disconnectNotify'

Is there anything special about installing pyside6 with snake_case enabled? If we could pick-up which features are enabled and use different variants based on that, instead of a bunch of try/excepts, I could look into it.

@HealsCodes
Copy link
Author

HealsCodes commented Nov 15, 2022

Is there anything special about installing pyside6 with snake_case enabled? If we could pick-up which features are enabled and use different variants based on that, instead of a bunch of try/excepts, I could look into it.

Sadly, no.
Both are features you can enable at runtime and part of the normal PySide6 as is available from PyPi.
And sadly no way I know off to test in a module like qasync if the parent module has them enabled outside of inspecting a "known good" class like QObject.

>>> import PySide6
>>> from PySide6.QtCore import QObject

>>> hasattr(QObject, 'objectName')
True

>>> hasattr(QObject, 'setObjectName')
True

>>> hasattr(QObject, 'object_name')
False


>>> from __feature__ import(snake_case, true_property)

>>> hasattr(QObject, 'objectName')
False

>>> hasattr(QObject, 'setObjectName')
False

>>> hasattr(QObject, 'object_name')
True

Something like this would work to check the current state:

from PySide6.QtCore import QObject

def is_snake_case_enabled() -> bool:
    return hasattr(QObject, 'object_name')

def is_true_property_enabled() -> bool:
    return hasattr(QObject, 'setObjectName') == False and hasattr(QObject, 'set_object_name') == False

@hosaka hosaka added the enhancement New feature or request label Nov 16, 2022
@hosaka hosaka changed the title Nasty error loop if used together with PySide6's snake_case __feature__ Support for PySide6's snake_case __feature__ Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants