PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 607 - make QApplication more Pythonic
: make QApplication more Pythonic
Status: CLOSED WONTFIX
Product: PySide
Classification: Unclassified
Component: PySide
: HEAD
: All All
: P4 enhancement
Assigned To: renato filho
:
:
:
  Show dependency treegraph
 
Reported: 2011-01-11 15:31 EET by Farsmo
Modified: 2011-02-17 19:19 EET (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Farsmo 2011-01-11 15:31:19 EET
QApplication.exec_() is designed around C++: it's convenient to have exec_()
return a value instead of calling exit() because it makes additional cleanup
much easier.

But in Python, sys.exit() only raises an exception, which can be intercepted if
needed. So there is no reason not to automatically raise an exception. In order
to both fix the ugly exec_() and maintain compatibility with programs that
don't expect exec_() to raise an exception, I propose to simply define

def execute(self):
    sys.exit(self.exec_())

or, perhaps it would be wiser to define:

def execute(self):
    code = self.exec_()
    if code!=0:
        sys.exit(code)

so that execution does not stop if exec_() is successful.


Likewise, I don't think there is any reason for QApplication to demand passing
sys.argv: unlike in C++, it doesn't have to be manually passed, so
QApplication() could be QApplication(sys.argv).


So the typical program prologue would change from

if __name__=="__main__":
    import sys
    app = QApplication(sys.argv)
    ...
    sys.exit(app.exec_())

to

if __name__=="__main__":
    app = QApplication()
    ...
    app.execute()


The icing on the cake would be to use the with statement:

if __name__=="__main__":
    with QApplication():
      ...

where QApplication's __exit__ would simply be execute().
Comment 1 Matti Airas 2011-01-12 06:50:31 EET
Thanks for the bug report. Personally, I think the ideas are good. However, I
think these kinds of proposals should be first presented on the mailing list to
be properly discussed with a wider audience (we want to keep any design
decisions public, and at least for the bigger issues the PSEP process to be
used).

I'm leaving this unconfirmed for now.
Comment 2 Hugo Parente Lima 2011-02-08 13:59:16 EET
As this proposal was partially rejected on mailing list[1] and rejected by
PySide core devs, I'll mark it as WONTFIX.

[1] http://groups.google.com/group/pyside/browse_thread/thread/7eb0c1aee073d518
Comment 3 Hugo Parente Lima 2011-02-17 19:19:04 EET
Closing bug due to 1.0.0~rc1 release.