V
V
Vladislav2019-12-25 10:51:21
Python
Vladislav, 2019-12-25 10:51:21

How to implement automatic interface restart in PyQT5 on error?

There is a front with buttons written in QtWidgets that controls browser emulation via Selenium. Sometimes an incomprehensible bug occurs that closes the interface, but leaves the browser tabs open. How to implement an automatic restart of only the interface, in case of a crash, keeping what is open in the browser?
Simplified backing code to make its structure clear:

from PyQt5 import QtWidgets
    from interface import Ui_MainWindow
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.support import expected_conditions
    from selenium.webdriver.support.wait import WebDriverWait

    driver = webdriver.Chrome(executable_path='C:\chromedriver.exe')
    url = "https://www.google.com/"
    driver.get(url) 

    class ExampleApp(QtWidgets.QMainWindow, Ui_MainWindow):
        def __init__(self):  #связываем функции с UI кнопками
            super().__init__()
            self.setupUi(self)
            self.pushButton.clicked.connect(self.NoAdress)
            self.pushButton_2.clicked.connect(self.SpecTransp)
            self.pushButton_3.clicked.connect(self.NoSvetofor)

        def NoAdress(self):          #функция для кнопки 1
            driver.execute_script('''some js code 1''')

        def SpecTransp(self): #функция для кнопки 2
            driver.execute_script('''some js code 2''')

        def NoSvetofor(self): #функция для кнопки 3
            driver.execute_script('''some js code 3''')

    if __name__ == '__main__':
        app = QtWidgets.QApplication([])
        window = ExampleApp()
        window.show()
        app.exec_()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question