def main(): """Main app function.""" # Create the app app = QApplication(sys.argv) # Setup app translator app_translator = QTranslator() i18n_dir = Path(BASE_DIR, VM_PATHS.i18n) i18n_file = i18n_dir.joinpath(''.join(('videomorph_', LOCALE[:2], '.qm'))) if i18n_file.exists(): trans = i18n_dir.joinpath('videomorph_{0}'.format(LOCALE)).__str__() app_translator.load(trans) app.installTranslator(app_translator) # Create the Main Window main_win = VideoMorphMW() # Check for conversion library and run if main_win.library.path: if len(sys.argv) > 1: # If it is running from console run_on_console(app, main_win) else: # Or is running on GUI main_win.show() sys.exit(app.exec_()) else: msg_box = QMessageBox(QMessageBox.Critical, main_win.tr('Error!'), main_win.no_library_msg, QMessageBox.NoButton, main_win) msg_box.addButton("&Ok", QMessageBox.AcceptRole) if msg_box.exec_() == QMessageBox.AcceptRole: qApp.closeAllWindows()
def baslangicKotrolFonksiyon(self): self.baslaDugme.setDisabled(True) cikti = self.tr("#Log dosyası oluşturuluyor...\n") self.ciktiYazilari.setText(cikti) f = open("/tmp/kurulum.log", "w") kurulum_dosya = "/root/ayarlar/kurulum.yml" if not os.path.exists(kurulum_dosya): QMessageBox.warning( self, "Hata", self. tr(""""Milis kurulumu için gerekli olan /root/ayarlar/kurulum.yml \n dosyası bulunamadı. Milis yükleyici sonladırılacak!""" )) qApp.closeAllWindows() else: cikti += self.tr("#Yml dosyası kopyalanıyor...\n") cikti += self.ebeveyn.komutCalistirFonksiyon("cp " + kurulum_dosya + " /opt/kurulum.yml") self.ciktiYazilari.setText(cikti) self.ebeveyn.kurulum_oku(self.ebeveyn.kurulum_dosya) cikti += "============================\n" + self.tr( "İşlem tamamlandı devam edebilirsiniz") self.ciktiYazilari.setText(cikti) self.ebeveyn.ileriDugme.setDisabled(False)
def onUseChineseDialog(self): dialog = ChangeLanguage2Dialog(self) setConfValue("Lang", "zh_CN") if dialog.exec() == QDialog.Accepted: qApp.closeAllWindows() QProcess.startDetached(qApp.applicationFilePath(), []) else: dialog.close()
def bolumCoz(self,hedef): komut="umount -l "+hedef try: os.system(komut) except OSError as e: QMessageBox.warning(self,self.tr("Hata"),str(e)) qApp.closeAllWindows() self.surecCubugu.setValue(100) self.kurulumBilgisiLabel.setText(hedef+self.tr(" çözüldü."))
def bolumBagla(self, hedef, baglam): komut = "mount " + hedef + " " + baglam try: os.system(komut) self.surecCubugu.setValue(100) except OSError as e: QMessageBox.warning(self, self.tr("Hata"), str(e)) qApp.closeAllWindows() self.kurulumBilgisiLabel.setText(hedef + " " + baglam + self.tr(" altına bağlandı."))
def __quit__(self): QApplication.instance().closingDown() self.hide() if not self.dlRunTime._shutdown: self.dlRunTime.shutdown() self.in_timer.stop() self.in_timer.deleteLater() self.close() qApp.closeAllWindows() time.sleep(1) del self.dlRunTime QApplication.instance().quit()
def check_conversion_lib(self): """Check if ffmpeg or/and avconv are installed on the system.""" if which(CONV_LIB.ffmpeg) or which(CONV_LIB.avconv): return True else: msg_box = QMessageBox( QMessageBox.Critical, self.tr('Error!'), self.tr('ffmpeg or avconv libraries not found in your system'), QMessageBox.NoButton, self) msg_box.addButton("&Ok", QMessageBox.AcceptRole) if msg_box.exec_() == QMessageBox.AcceptRole: qApp.closeAllWindows() return False
def onUseChineseDialog(self): dialog = ChangeLanguage2Dialog(self) try: data = pickle.load(open("data", "rb")) except EOFError: mData = {"currLanguage": "en_US", "nextLanguage": "en_US"} else: mData = { "currLanguage": data["currLanguage"], "nextLanguage": "zh_CN" } pickle.dump(mData, open("data", "wb")) if dialog.exec() == QDialog.Accepted: qApp.closeAllWindows() QProcess.startDetached(qApp.applicationFilePath(), []) else: dialog.close()
def bolumFormatla(self, hedef): komut = "umount -l " + hedef self.kurulumBilgisiLabel.setText(komut) if os.path.exists(hedef): os.system(komut) self.surecCubugu.setValue(50) komut2 = "mkfs.ext4 -F " + hedef try: os.system(komut2) self.surecCubugu.setValue(100) except OSError as e: QMessageBox.warning(self, self.tr("Hata"), str(e)) qApp.closeAllWindows() self.kurulumBilgisiLabel.setText(hedef + self.tr(" disk bölümü formatlandı.")) else: QMessageBox.warning(self, self.tr("Hata"), self.tr("Disk bulunamadı. Program kapatılacak.")) qApp.closeAllWindows()
def run_app(app): """Run the app.""" # Create the Main Window main_win = VideoMorphMW() # Check for conversion library and run if main_win.conversion_lib.library_path: if len(sys.argv) > 1: # If it is running from console run_on_console(app, main_win) else: # Or is running on GUI main_win.show() sys.exit(app.exec_()) else: msg_box = QMessageBox(QMessageBox.Critical, main_win.tr('Error!'), main_win.no_library_msg, QMessageBox.NoButton, main_win) msg_box.addButton("&Ok", QMessageBox.AcceptRole) if msg_box.exec_() == QMessageBox.AcceptRole: qApp.closeAllWindows()
def testBaseError_Dialog(qtbot, monkeypatch, fncDir, tmpDir): """Test the error dialog. """ # Block message box monkeypatch.setattr(QMessageBox, "warning", lambda *a: QMessageBox.Yes) qApp.closeAllWindows() nwGUI = novelwriter.main( ["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.wait(20) nwErr = NWErrorMessage(nwGUI) qtbot.addWidget(nwErr) nwErr.show() # Invalid Error Message nwErr.setMessage(Exception, "Faulty Error", 123) assert nwErr.msgBody.toPlainText() == "Failed to generate error report ..." # Valid Error Message with monkeypatch.context() as mp: mp.setattr("PyQt5.QtCore.QSysInfo.kernelVersion", lambda: "1.2.3") nwErr.setMessage(Exception, "Fine Error", None) theMessage = nwErr.msgBody.toPlainText() assert theMessage != "" assert "Fine Error" in theMessage assert "Exception" in theMessage assert "(1.2.3)" in theMessage # No kernel version retrieved with monkeypatch.context() as mp: mp.setattr("PyQt5.QtCore.QSysInfo.kernelVersion", causeException) nwErr.setMessage(Exception, "Almost Fine Error", None) theMessage = nwErr.msgBody.toPlainText() assert theMessage != "" assert "(Unknown)" in theMessage nwErr._doClose() nwErr.close() nwGUI.closeMain()
def testBaseError_Handler(qtbot, monkeypatch, fncDir, tmpDir): """Test the error handler. This test doesn'thave any asserts, but it checks that the error handler handles potential exceptions. The test will fail if excpetions are not handled. """ monkeypatch.setattr(QMessageBox, "warning", lambda *a: QMessageBox.Yes) qApp.closeAllWindows() nwGUI = novelwriter.main( ["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.wait(20) # Normal shutdown with monkeypatch.context() as mp: mp.setattr(NWErrorMessage, "exec_", lambda *a: None) mp.setattr("PyQt5.QtWidgets.qApp.exit", lambda *a: None) exceptionHandler(Exception, "Error Message", None) # Should not crash when no GUI is found with monkeypatch.context() as mp: mp.setattr(NWErrorMessage, "exec_", lambda *a: None) mp.setattr("PyQt5.QtWidgets.qApp.exit", lambda *a: None) mp.setattr("PyQt5.QtWidgets.qApp.topLevelWidgets", lambda: []) exceptionHandler(Exception, "Error Message", None) # Should handle qApp failing with monkeypatch.context() as mp: mp.setattr(NWErrorMessage, "exec_", lambda *a: None) mp.setattr("PyQt5.QtWidgets.qApp.exit", lambda *a: None) mp.setattr("PyQt5.QtWidgets.qApp.topLevelWidgets", causeException) exceptionHandler(Exception, "Error Message", None) # Should handle failing to close main GUI with monkeypatch.context() as mp: mp.setattr(NWErrorMessage, "exec_", lambda *a: None) mp.setattr("PyQt5.QtWidgets.qApp.exit", lambda *a: None) mp.setattr(nwGUI, "closeMain", causeException) exceptionHandler(Exception, "Error Message", None) nwGUI.closeMain()
def testBaseError_Handler(qtbot, monkeypatch, fncDir, tmpDir): """Test the error handler. This test doesn'thave any asserts, but it checks that the error handler handles potential exceptions. The test will fail if excpetions are not handled. """ qApp.closeAllWindows() nwGUI = nw.main( ["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) # Normal shutdown monkeypatch.setattr(NWErrorMessage, "exec_", lambda *args: None) monkeypatch.setattr("PyQt5.QtWidgets.qApp.exit", lambda *args: None) exceptionHandler(Exception, "Error Message", None) monkeypatch.undo() # Should not crash when no GUI is found monkeypatch.setattr(NWErrorMessage, "exec_", lambda *args: None) monkeypatch.setattr("PyQt5.QtWidgets.qApp.exit", lambda *args: None) monkeypatch.setattr("PyQt5.QtWidgets.qApp.topLevelWidgets", lambda: []) exceptionHandler(Exception, "Error Message", None) monkeypatch.undo() # Should handle qApp failing monkeypatch.setattr(NWErrorMessage, "exec_", lambda *args: None) monkeypatch.setattr("PyQt5.QtWidgets.qApp.exit", lambda *args: None) monkeypatch.setattr("PyQt5.QtWidgets.qApp.topLevelWidgets", causeException) exceptionHandler(Exception, "Error Message", None) monkeypatch.undo() # Should handle failing to close main GUI monkeypatch.setattr(NWErrorMessage, "exec_", lambda *args: None) monkeypatch.setattr("PyQt5.QtWidgets.qApp.exit", lambda *args: None) monkeypatch.setattr(nwGUI, "closeMain", causeException) exceptionHandler(Exception, "Error Message", None) monkeypatch.undo() nwGUI.closeMain()
def testBaseError_Dialog(qtbot, monkeypatch, fncDir, tmpDir): """Test the error dialog. """ qApp.closeAllWindows() nwGUI = nw.main( ["--testmode", "--config=%s" % fncDir, "--data=%s" % tmpDir]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) nwErr = NWErrorMessage(nwGUI) qtbot.addWidget(nwErr) nwErr.show() # Invalid Error Message nwErr.setMessage(Exception, "Faulty Error", 123) assert nwErr.msgBody.toPlainText() == "Failed to generate error report ..." # Valid Error Message monkeypatch.setattr("PyQt5.QtCore.QSysInfo.kernelVersion", lambda: "1.2.3") nwErr.setMessage(Exception, "Fine Error", None) theMessage = nwErr.msgBody.toPlainText() assert theMessage assert "Fine Error" in theMessage assert "Exception" in theMessage assert "(1.2.3)" in theMessage monkeypatch.undo() # No kernel version retrieved monkeypatch.setattr("PyQt5.QtCore.QSysInfo.kernelVersion", causeException) nwErr.setMessage(Exception, "Almost Fine Error", None) theMessage = nwErr.msgBody.toPlainText() assert theMessage assert "(Unknown)" in theMessage monkeypatch.undo() nwErr._doClose() nwErr.close() nwGUI.closeMain()
def testErrorDialog(qtbot, nwFuncTemp, nwTemp): qApp.closeAllWindows() nwGUI = nw.main( ["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) nwErr = NWErrorMessage(nwGUI) qtbot.addWidget(nwErr) nwErr.show() # Invalid Error nwErr.setMessage(Exception, "Faulty Error", 123) assert nwErr.msgBody.toPlainText() == "Failed to generate error report ..." # Valid Error nwErr.setMessage(Exception, "First Error", None) theMessage = nwErr.msgBody.toPlainText() assert theMessage assert "First Error" in theMessage assert "Exception" in theMessage nwErr._doClose() nwErr.close() theMessage = exceptionHandler(Exception, "Second Error", None, testMode=True) assert theMessage assert "Second Error" in theMessage assert "Exception" in theMessage nwGUI.closeMain()
def closeEvent(self,event): logging.warning ("Exiting") qApp.closeAllWindows() qApp.exit() sys.exit(0)
def deneDugmeFonksiyon(self): qApp.closeAllWindows()
def quitEvent(self): if self.auth_window: self.auth_window.logout(self.logoutConfirmation()) qApp.closeAllWindows() self.deleteLater()
def closeEvent(self,event): warning ("Exiting") qApp.closeAllWindows() qApp.exit() exit(0)