Comments (8)
It happens with every modal dialog.
from quamash.
We've contemplated a "helper" method that works something like this
def function modalDialog(dialog):
future = asyncio.Future()
dialog.finished.connect(lambda r: future.set_result(r))
dialog.open()
return future
It means you can't use the static public helper functions though.
from quamash.
Is it possible to use the result of "exec_()" method of QDialogs with such a helper function ?
from quamash.
Isn't the int sent to the finished
signal the same as the int returned by exec
? (no need for the underscore in Python 3)
basically setup with:
dialog = QMessageBox(...)
dialog.setTitle(...)
then doing either
result = dialog.exec()
or this
result = yield from modalDialog(dialog)
should result in the same thing... I think.
I remember doing this with FileChooser dialogs.
from quamash.
full example
import sys
import itertools
from PyQt5.QtWidgets import QApplication, QMessageBox
import asyncio
import quamash
def dialog_async_exec(dialog):
future = asyncio.Future()
dialog.finished.connect(lambda r: future.set_result(r))
dialog.open()
return future
@asyncio.coroutine
def main():
global app
dialog = QMessageBox(QMessageBox.Question,
"Application Name",
"Hardware failure.\n\nDisk error detected\nDo you want to stop?")
dialog.addButton(QMessageBox.Yes)
dialog.setDefaultButton(QMessageBox.Yes)
dialog.addButton(QMessageBox.No)
dialog.setEscapeButton(QMessageBox.No)
result = yield from dialog_async_exec(dialog)
if result == QMessageBox.Yes:
print('Yes!')
elif result == QMessageBox.No:
print('No!')
else:
print('Something else')
@asyncio.coroutine
def weirdloop():
# this keeps looping to prove the loop is still running
for i in itertools.count():
print('loop count', i)
yield from asyncio.sleep(1)
if __name__ == '__main__':
app = QApplication(sys.argv)
loop = quamash.QEventLoop(app)
asyncio.set_event_loop(loop)
asyncio.async(weirdloop())
with loop:
loop.run_until_complete(main())
from quamash.
Ok thanks. I wonder if quamash could implements such methods, like :
from quamash import QMessageBox
....
yield from QMessageBox.async_question(self, "Test", "Do I bug ?")
from quamash.
oh, it certainly something that could be done... it would just be a lot of
code to write.
I'd probably put it in quamash.utils
and not in the main package though.
I'd certainly accept a PR.
On Sun, Sep 6, 2015 at 3:19 AM, Insoleet [email protected] wrote:
Ok thanks. I wonder if quamash could implements such methods, like :
from quamash import QMessageBox
....
yield from QMessageBox.async_question(self, "Test", "Do I bug ?")—
Reply to this email directly or view it on GitHub
#41 (comment).
from quamash.
Ubuntu 18.04,
Python 3.6.5
Quamash 0.6.1
pyqt5 5.9.2
(same for some version on windows, quamash 0.5.5, ask if interested...)
Interestingly, #41 (comment) now seems to work as well just with dialog.exec()
(loop continues). However, at least sometimes there are errors like
Exception in callback <TaskStepMethWrapper object at 0x7fe51e40c470>()
handle: <Handle <TaskStepMethWrapper object at 0x7fe51e40c470>()>
Traceback (most recent call last):
File "/usr/lib/python3.6/asyncio/events.py", line 145, in _run
self._callback(*self._args)
KeyError: <QSelectorEventLoop running=True closed=False debug=False>
Which are then, if one doesn't know about this issue here, quite hard to identify and fix 😄
from quamash.
Related Issues (20)
- Interest in creating a conda-forge package
- asyncio.async is deprecated since python 3.4.4, use asyncio.ensure_future instead HOT 4
- exceptions not set on pending futures
- unnecessary warnings HOT 6
- Release tagging HOT 1
- PipeServer closure race
- asyncio.create_task is not working
- Intalling quamash using PIP forces install of both pyside2 and pyqt5 HOT 9
- [Bug or Feature Requests] aioredis connect raise 'Event callback failed'
- Problem with Anaconda HOT 1
- the anaconda navigator dose not open HOT 1
- call asyncio.sleep(0.1) RuntimeError: no running event loop
- AttributeError: module 'collections' has no attribute 'Mapping' HOT 1
- [python3.10] implicit float to int conversion
- Update package on PyPI?
- Release 0.6.2 HOT 5
- RuntimeError: no running event loop HOT 1
- Module 'collections' has no attribute 'Mapping' HOT 1
- collections.Mapping has been removed HOT 1
- SyntaxError: Non-ASCII character in quamash/__init__.py
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quamash.