| # Licensed to the Apache Software Foundation (ASF) under one or more |
| # contributor license agreements. See the NOTICE file distributed with |
| # this work for additional information regarding copyright ownership. |
| # The ASF licenses this file to You under the Apache License, Version 2.0 |
| # (the "License"); you may not use this file except in compliance with |
| # the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| """ |
| ZetCode PyQt5 tutorial |
| |
| This program shows a confirmation |
| message box when we click on the close |
| button of the application window. |
| |
| author: Jan Bodnar |
| website: zetcode.com |
| last edited: January 2015 |
| """ |
| |
| import sys |
| from PyQt5.QtWidgets import QWidget, QMessageBox, QApplication |
| from userale.ale import Ale |
| |
| class Example(QWidget): |
| |
| def __init__(self): |
| super().__init__() |
| |
| self.initUI() |
| |
| |
| def initUI(self): |
| |
| self.setGeometry(300, 300, 250, 150) |
| self.setWindowTitle('Message box') |
| self.show() |
| |
| |
| def closeEvent(self, event): |
| |
| reply = QMessageBox.question(self, 'Message', |
| "Are you sure to quit?", QMessageBox.Yes | |
| QMessageBox.No, QMessageBox.No) |
| |
| if reply == QMessageBox.Yes: |
| event.accept() |
| else: |
| event.ignore() |
| |
| |
| def test_close (): |
| |
| app = QApplication(sys.argv) |
| ex = Example() |
| ale = Ale () |
| # install globally |
| app.installEventFilter (ale) |
| |
| sys.exit(app.exec_()) |