Python源码示例:PyQt5.QtWidgets.qApp.quit()

示例1
def initMenuBar(self):
        '''
        初始化菜单栏
        '''
        menubar = self.menuBar()
        #self.actionExit.triggered.connect(qApp.quit)    # 按下菜单栏的Exit按钮会退出程序
        #self.actionExit.setStatusTip("退出程序")         # 左下角状态提示
        #self.actionExit.setShortcut('Ctrl+Q')           # 添加快捷键
        exitAct = QAction(QIcon('exit.png'), 'Exit', self)
        exitAct.setShortcut('Ctrl+Q')
        exitAct.triggered.connect(qApp.quit)
        
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(exitAct)
        
        fileMenu = menubar.addMenu('&Help') 
示例2
def new_session_dialog(self):
        """Show the layout-selection dialog"""
        try:
            # Prompt the user for a new layout
            dialog = LayoutSelect()
            if dialog.exec_() != QDialog.Accepted:
                if self._layout is None:
                    # If the user close the dialog, and no layout exists
                    # the application is closed
                    self.finalize()
                    qApp.quit()
                    exit()
                else:
                    return

            # If a valid file is selected load it, otherwise load the layout
            if exists(dialog.filepath):
                self._load_from_file(dialog.filepath)
            else:
                self._new_session(dialog.selected())

        except Exception as e:
            elogging.exception('Startup error', e)
            qApp.quit()
            exit(-1) 
示例3
def initUI(self):               

        exitAct = QAction(QIcon('exit.png'), '&Exit', self)        
        exitAct.setShortcut('Ctrl+Q')
        exitAct.setStatusTip('Exit application')
        exitAct.triggered.connect(qApp.quit)

        self.statusBar()

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(exitAct)

        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('Simple menu')    
        self.show() 
示例4
def ButtonAct(self):
        global ulist
        sender = self.sender()
        ulist += sender.text()
        if sender.text() == '=':
            value = eval(ulist.replace('=',''))
            if value:
                self.Line.setText(str(value))
            ulist = str(value)
        elif sender.text() == 'close':
            qApp.quit()
        elif sender.text() == 'cls':
            ulist = ''
        elif sender.text() == 'bck':
            ulist = ulist[:-4]
        elif sender.text() == 'plus':
            ulist = ulist[:-4]
        self.Text.setText(ulist)
# execute our application 
示例5
def initMenuBar(self):
        '''
        初始化菜单栏
        '''
        menubar = self.menuBar()
        #self.actionExit.triggered.connect(qApp.quit)    # 按下菜单栏的Exit按钮会退出程序
        #self.actionExit.setStatusTip("退出程序")         # 左下角状态提示
        #self.actionExit.setShortcut('Ctrl+Q')           # 添加快捷键
        exitAct = QAction(QIcon('exit.png'), 'Exit', self)
        exitAct.setShortcut('Ctrl+Q')
        exitAct.triggered.connect(qApp.quit)
        
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(exitAct)
        
        fileMenu = menubar.addMenu('&Help') 
示例6
def initToolBar(self):
        '''
        初始化工具栏
        创建一个QAction实例exitAct,然后添加到designer已经创建的默认的工具栏toolBar里面
        '''
        exitAct = QAction(QIcon('exit.png'), 'Exit', self)
        exitAct.setShortcut('Ctrl+Q')
        exitAct.triggered.connect(qApp.quit)
        
        self.toolBar.addAction(exitAct) 
示例7
def initToolBar(self):
        '''
        初始化工具栏
        创建一个QAction实例exitAct,然后添加到designer已经创建的默认的工具栏toolBar里面
        '''
        exitAct = QAction(QIcon('exit.png'), 'Exit', self)
        exitAct.setShortcut('Ctrl+Q')
        exitAct.triggered.connect(qApp.quit)
        
        self.toolBar.addAction(exitAct) 
示例8
def contextMenuEvent(self, event):

           cmenu = QMenu(self)

           newAct = cmenu.addAction("New")
           opnAct = cmenu.addAction("Open")
           quitAct = cmenu.addAction("Quit")
           action = cmenu.exec_(self.mapToGlobal(event.pos()))

           if action == quitAct:
               qApp.quit() 
示例9
def initUI(self):               

        exitAct = QAction(QIcon('exit24.png'), 'Exit', self)
        exitAct.setShortcut('Ctrl+Q')
        exitAct.triggered.connect(qApp.quit)

        self.toolbar = self.addToolBar('Exit')
        self.toolbar.addAction(exitAct)


        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('Toolbar')    
        self.show() 
示例10
def quitApp(self):
        # 退出程序
        self.w.show()  # w.hide() #设置退出时是否显示主窗口
        re = QMessageBox.question(self.w, "提示", "确认退出?", QMessageBox.Yes |
                                  QMessageBox.No, QMessageBox.No)
        if re == QMessageBox.Yes:
            self.tp.setVisible(False)  # 隐藏托盘控件
            qApp.quit()  # 退出程序
            self.w.v2rayL.disconnect() 
示例11
def checkPLAYMODE(self):
        while self.btnset.PLAYMODE == Constants.playmode_pause:
            loop = QEventLoop()
            QTimer.singleShot(10, loop.quit)
            loop.exec_() 
示例12
def menubtn0_clicked(self):
        print("clicked pb_1")
        qApp.quit()
        sys.exit(0) 
示例13
def pb_1_clicked(self):
        print("clicked pb_1")
        qApp.quit()
        sys.exit(0) 
示例14
def show(param, msg="done", time=300):
    loop = QEventLoop()
    QTimer.singleShot(time, loop.quit)
    loop.exec_()

    graphics.update(param)
    graphics.setVisible(True) 
示例15
def closeEvent(self, event):
        '''
        Shows a message box to confirm the wondow closing
        '''

        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() 
示例16
def closeEvent(self, event):
        '''
        Shows a message box to confirm the wondow closing
        '''

        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() 
示例17
def initUi(self):
        # 提示数值范围
        self.label.setText('数值的范围是:{}-{}'.format(self.left, self.right))
        # 按下按钮一,运行 self.guess 函数
        self.pushButton.clicked.connect(self.guess)
        # 按下按钮二,运行 quit 函数
        self.pushButton_2.clicked.connect(qApp.quit)
        # 按下按钮三,运行 self.reset 函数
        self.pushButton_3.clicked.connect(self.reset) 
示例18
def keyPressEvent(self, e):
        # 设置快捷键
        if e.key() == Qt.Key_Return:
            self.guess()
        elif e.key() == Qt.Key_Escape:
            qApp.quit()
        elif e.key() == Qt.Key_R:
            self.reset() 
示例19
def __init__(self, target):
        super().__init__()
        self.target = get_download_target(DownloadTarget.SOFTWARE, target)
        self.download_window = DownloadWindow()
        self.download_window.setStyleSheet(stylesheet)
        self.download_window.cancel_btn.clicked.connect(qApp.quit)
        self.download_window.complete.connect(self.start_main_program) 
示例20
def start_main_program(self):
        """Restart the (updated) main program and close the updater."""
        self.download_window.setVisible(False)
        artemis = QProcess()
        try:
            artemis.startDetached(Constants.EXECUTABLE_NAME)
        except BaseException:
            pass
        qApp.quit() 
示例21
def _check_new_version(self):
        """Check whether there is a new software version available.

        Does something only if the running program is a compiled version."""
        if not IS_BINARY:
            return None
        latest_version = self.version_controller.software.version
        if latest_version is None:
            return False
        if latest_version == self._current_version:
            return False
        answer = pop_up(
            self._owner,
            title=Messages.NEW_VERSION_AVAILABLE,
            text=Messages.NEW_VERSION_MSG(latest_version),
            informative_text=Messages.DOWNLOAD_SUGG_MSG,
            is_question=True,
        ).exec()
        if answer == QMessageBox.Yes:
            if IS_MAC:
                webbrowser.open(self.version_controller.software.url)
            else:
                updater = QProcess()
                command = Constants.UPDATER_SOFTWARE + " " + \
                    self.version_controller.software.url + \
                    " " + self.version_controller.software.hash_code + \
                    " " + str(self.version_controller.software.size)
                try:
                    updater.startDetached(command)
                except BaseException:
                    logging.error("Unable to start updater")
                    pass
                else:
                    qApp.quit()
        return True 
示例22
def initMenu(self):
        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')

        # File menu

        ## add record manually
        addRec = QMenu("Add Record", self)

        act = QAction('Add Car', self)
        act.setStatusTip('Add Car Manually')
        act.triggered.connect(self.addCar)
        addRec.addAction(act)

        act = QAction('Add Rule', self)
        act.setStatusTip('Add Rule Manually')
        act.triggered.connect(self.addRule)
        addRec.addAction(act)

        act = QAction('Add Violation', self)
        act.setStatusTip('Add Violation Manually')
        act.triggered.connect(self.addViolation)
        addRec.addAction(act)

        act = QAction('Add Camera', self)
        act.setStatusTip('Add Camera Manually')
        act.triggered.connect(self.addCamera)
        addRec.addAction(act)

        fileMenu.addMenu(addRec)

        # check archive record ( Create window and add button to restore them)
        act = QAction('&Archives', self)
        act.setStatusTip('Show Archived Records')
        act.triggered.connect(self.showArch)
        fileMenu.addAction(act)

        settingsMenu = menubar.addMenu('&Settings')
        themeMenu = QMenu("Themes", self)
        settingsMenu.addMenu(themeMenu)

        act = QAction('Dark', self)
        act.setStatusTip('Dark Theme')
        act.triggered.connect(lambda: qApp.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()))
        themeMenu.addAction(act)

        act = QAction('White', self)
        act.setStatusTip('White Theme')
        act.triggered.connect(lambda: qApp.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()))
        themeMenu.addAction(act)

        ## Add Exit
        fileMenu.addSeparator()
        act = QAction('&Exit', self)
        act.setShortcut('Ctrl+Q')
        act.setStatusTip('Exit application')
        act.triggered.connect(qApp.quit)
        fileMenu.addAction(act) 
示例23
def initUI(self):
        exitAct = QAction('&Exit', self)
        exitAct.setShortcut('Ctrl+Q')
        exitAct.setStatusTip('Exit application')
        exitAct.triggered.connect(qApp.quit)

        self.statusBar()

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(exitAct)

        self.central_widget = QWidget()
        self.setCentralWidget(self.central_widget)
        lay = QVBoxLayout(self.central_widget)

        label = QLabel(self)
        pixmap = QPixmap('logo.png')
        label.setPixmap(pixmap)

        cb1 = QCheckBox('Check Box 1', self)
        cb1.toggle()

        cb2 = QCheckBox('Check Box 2', self)
        cb2.toggle()

        cb3 = QCheckBox('Check Box 3', self)
        cb3.toggle()

        cb4 = QCheckBox('Check Box 4', self)
        cb4.toggle()

        btn = QPushButton('Install', self)

        lay.addWidget(cb1)
        lay.addWidget(cb2)
        lay.addWidget(cb3)
        lay.addWidget(cb4)
        lay.addWidget(btn)
        lay.addWidget(label)

        self.resize(300, 300)
        self.setWindowTitle('Setup')
        self.center()
        self.show() 
示例24
def initUI(self):
        exitAct = QAction('&Exit', self)
        exitAct.setShortcut('Ctrl+Q')
        exitAct.setStatusTip('Exit application')
        exitAct.triggered.connect(qApp.quit)

        self.statusBar()

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(exitAct)


        label = QLabel(self)
        pixmap = QPixmap('logo.png')
        label.setPixmap(pixmap)


        cb1 = QCheckBox('Check Box 1', self)
        cb1.toggle()
        cb2 = QCheckBox('Check Box 2', self)
        cb2.toggle()
        cb3 = QCheckBox('Check Box 3', self)
        cb3.toggle()
        cb4 = QCheckBox('Check Box 4', self)
        cb4.toggle()

        btn = QPushButton('Install', self)

        vertical_box1 = QVBoxLayout()
        vertical_box1.addWidget(cb1)
        vertical_box1.addWidget(cb2)
        vertical_box1.addWidget(cb3)
        vertical_box1.addWidget(cb4)
        vertical_box1.addWidget(btn)

        vertical_box2 = QVBoxLayout()
        vertical_box2.addWidget(label)

        horizontal_box = QHBoxLayout()
        horizontal_box.addWidget(vertical_box1)


        self.setCentralWidget(horizontal_box)

        # self.setLayout(horizontal_box)

        self.resize(300, 300)
        self.setWindowTitle('Setup')
        self.center()
        self.show() 
示例25
def initUI(self):
        exitAct = QAction('&Exit', self)
        exitAct.setShortcut('Ctrl+Q')
        exitAct.setStatusTip('Exit application')
        exitAct.triggered.connect(qApp.quit)

        self.statusBar()

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(exitAct)

        self.central_widget = QWidget()
        self.setCentralWidget(self.central_widget)

        lay = QHBoxLayout(self.central_widget)

        label = QLabel(self)
        pixmap = QPixmap('logo.png')
        label.setPixmap(pixmap)

        cb1 = QCheckBox('Check Box 1', self)
        cb1.toggle()

        cb2 = QCheckBox('Check Box 2', self)
        cb2.toggle()

        cb3 = QCheckBox('Check Box 3', self)
        cb3.toggle()

        cb4 = QCheckBox('Check Box 4', self)
        cb4.toggle()

        btn = QPushButton('Install', self)

        vertical_box1 = QVBoxLayout()
        vertical_box1.addWidget(cb1)
        vertical_box1.addWidget(cb2)
        vertical_box1.addWidget(cb3)
        vertical_box1.addWidget(cb4)
        vertical_box1.addWidget(btn)

        lay.addWidget(vertical_box1)
        lay.addWidget(label)

        self.resize(300, 300)
        self.setWindowTitle('Setup')
        self.center()
        self.show() 
示例26
def initMenu(self):
        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')

        # File menu

        ## add record manually
        addRec = QMenu("Add Record", self)

        act = QAction('Add Car', self)
        act.setStatusTip('Add Car Manually')
        act.triggered.connect(self.addCar)
        addRec.addAction(act)

        act = QAction('Add Rule', self)
        act.setStatusTip('Add Rule Manually')
        act.triggered.connect(self.addRule)
        addRec.addAction(act)

        act = QAction('Add Violation', self)
        act.setStatusTip('Add Violation Manually')
        act.triggered.connect(self.addViolation)
        addRec.addAction(act)

        act = QAction('Add Camera', self)
        act.setStatusTip('Add Camera Manually')
        act.triggered.connect(self.addCamera)
        addRec.addAction(act)

        fileMenu.addMenu(addRec)

        # check archive record ( Create window and add button to restore them)
        act = QAction('&Archives', self)
        act.setStatusTip('Show Archived Records')
        act.triggered.connect(self.showArch)
        fileMenu.addAction(act)

        settingsMenu = menubar.addMenu('&Settings')
        themeMenu = QMenu("Themes", self)
        settingsMenu.addMenu(themeMenu)

        act = QAction('Dark', self)
        act.setStatusTip('Dark Theme')
        act.triggered.connect(lambda: qApp.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()))
        themeMenu.addAction(act)

        act = QAction('White', self)
        act.setStatusTip('White Theme')
        act.triggered.connect(lambda: qApp.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()))
        themeMenu.addAction(act)

        ## Add Exit
        fileMenu.addSeparator()
        act = QAction('&Exit', self)
        act.setShortcut('Ctrl+Q')
        act.setStatusTip('Exit application')
        act.triggered.connect(qApp.quit)
        fileMenu.addAction(act)