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

[DOC] How to change mouse cursor to "busy" state and back ? #509

Open
Kochise opened this issue Oct 20, 2022 · 6 comments
Open

[DOC] How to change mouse cursor to "busy" state and back ? #509

Kochise opened this issue Oct 20, 2022 · 6 comments

Comments

@Kochise
Copy link

Kochise commented Oct 20, 2022

This there a wait to do this "natively" from within Enaml :

https://stackoverflow.com/questions/8218900/how-can-i-change-the-cursor-shape-with-pyqt

@MatthieuDartiailh
Copy link
Member

No there is currently no native way to do this. I remember looking into it at one point but never spun up a working solution.

@Kochise
Copy link
Author

Kochise commented Oct 20, 2022

O-kayyy...

atari_gem_bee

@bburan
Copy link
Contributor

bburan commented Feb 14, 2023

@Kochise There's currently no way to do this via Enaml. You're welcome to submit a PR implementing this.

@Kochise
Copy link
Author

Kochise commented Feb 15, 2023

Will see what I can do. Thank for the tip.

@pjcunningham
Copy link

pjcunningham commented Jul 13, 2023

Dirty hack (I'm using PySide2):

from enaml.qt.qt_application import QtApplication
from PyQt5.QtGui import QCursor
from enaml.qt import QtCore

class CustomQtApplication(QtApplication):

    def set_wait_cursor(self):
        app = self._qapp
        app.setOverrideCursor(QCursor(QtCore.Qt.WaitCursor))

    def restore_cursor(self):
        app = self._qapp
        app.restoreOverrideCursor()

# redefine deferred_call to use CustomQtApplication
def deferred_call(callback, *args, **kwargs):
    app = CustomQtApplication.instance()
    if app is None:
        raise RuntimeError('Custom Application instance does not exist')
    app.deferred_call(callback, *args, **kwargs)

Example use in thread, referencing this Gist, Simple threads with Enaml

def worker(application: CustomQtApplication, application_model: ApplicationModel, progress_model: ProgressModel):
    deferred_call(application.set_wait_cursor)
    p = 0
    while p <= 100:
        deferred_call(setattr, progress_model, 'value', p)
        deferred_call(application_model.update_log, [f"Incrementing Progress Bar with value:{str(p)}"])
        p += 1
        sleep(0.2)
    deferred_call(setattr, progress_model, 'busy', False)
    deferred_call(application.restore_cursor)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants