Code Monkey home page Code Monkey logo

Comments (8)

Insoleet avatar Insoleet commented on September 25, 2024

It happens with every modal dialog.

from quamash.

harvimt avatar harvimt commented on September 25, 2024

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.

Insoleet avatar Insoleet commented on September 25, 2024

Is it possible to use the result of "exec_()" method of QDialogs with such a helper function ?

from quamash.

harvimt avatar harvimt commented on September 25, 2024

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.

harvimt avatar harvimt commented on September 25, 2024

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.

Insoleet avatar Insoleet commented on September 25, 2024

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.

harvimt avatar harvimt commented on September 25, 2024

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.

wolfgang-noichl avatar wolfgang-noichl commented on September 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.