Open Kochise opened 1 year ago
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.
O-kayyy...
@Kochise There's currently no way to do this via Enaml. You're welcome to submit a PR implementing this.
Will see what I can do. Thank for the tip.
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)
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