PyCharm issue, need to restart IDE when code changes

Heads up! You've already completed this tutorial.

DosSantos | 2021-04-07 13:08:58 UTC | #1

@martin I take this opportunity to thank you for your tutorials, very good. One more time i take your code and modified it :blush:. For testing news scripts that is good, but i only have one problem. When I assign the code to a new button I need to restart my IDE. I use pycharm. Is it possible to solve this without other ways ? Thanks

from PyQt5.QtWidgets import QMainWindow, QApplication, QAction
from PyQt5.QtCore import Qt, QThread, QCoreApplication
from PyQt5 import uic

""" *** WARNING """
""" First need create dialog with tree buttons (bt_one, bt_two, bt_tree) with  designer and save file window.ui """

import os # Used in Testing Script
os.system("pyuic5.exe resources\\window.ui -o resources\\")  # Used in Testing Script

from resources.window import Ui_MainWindow
import sys

qtCreatorFile = "resources\\window.ui"  # Type your file path

""" This block used for testing script """
class MainWindow(QMainWindow, Ui_MainWindow):

    def __init__(self):
            super(MainWindow, self).__init__()
            self.reload = None
            self.mainbase = self

    def load_ui(self):
        print("loading ui")
        cls, baseclass = uic.loadUiType(qtCreatorFile)

        self.ui = Window()
        """ Move the central widget from the loaded UI main window our visible one."""


        if not self.reload:
            menu = self.menuBar()
            ui = menu.addMenu("UI")
            self.reload = QAction("Reload UI")
            self.reloadexe = QAction("Reload App")
            self.quit = QAction("Quit")
            self.reload.setShortcut(Qt.CTRL | Qt.Key_A)  # You can reload with >Ctrl-A
            self.reloadexe.setShortcut(Qt.CTRL | Qt.Key_Q)  # You can run test >app  >with Ctrl-Q
            self.quit.setShortcut(Qt.Key_Escape)  # You can terminate with Ctrl-R
            ui.addActions([self.reload, self.reloadexe, self.quit])

    def load_app():
        import os, time
        os.system("pyuic5.exe resources\\window.ui -o resources\\")

""" End block used for testing script """

class MainBase(QMainWindow, Ui_MainWindow):

    def __init__(self):
        super(MainBase, self).__init__()

        cls, baseclass = uic.loadUiType("resources\\window.ui")

        class Window(cls, baseclass):

        self.ui = Window()

        """ First need create tree buttons (bt_one, bt_two, bt_tree) with designer >and save file window.ui """
        self.ui.bt_one.clicked.connect(lambda: self.ui.lineedit.setText("button >one"))

        self.ui.bt_two.clicked.connect(lambda: self.displaytxt("button two"))
        self.ui.bt_tree.clicked.connect(lambda: self.displaytxt("button tree"))
        """ first write "self."  and connection, after this rename to self.ui. ... """
        """ second for test your new button need restart your IDE """
        """ put more connections and all other code bellow """

    def displaytxt(self, x):

""" Used in Testing Script """

def runner():
    from resources.window import Ui_MainWindow
    apptest = QCoreApplication

app = QApplication([])
w = MainWindow()

martin | 2021-04-07 13:12:26 UTC | #2

Hi @DosSantos I missed this when you originally posted it -- I've fixed up the code now so it's clearer. Do you still have this problem/have you found a solution?

You're not the only person who has reported it, but I've not been able to reproduce it myself. That said, normally what I do when developing with Qt is to open a separate terminal (command prompt) and run the code from there. I started doing that when I was using an IDE which would die if the Qt app hung -- it's now just a habit!

Since you're usually just running the same command over and over, it's just a case of hitting the ^ arrow on the keyboard (recall last command) and pressing Enter to repeat.

Would be great to hear of other solutions though.

Over 10,000 developers have bought Create GUI Applications with Python & Qt!
Create GUI Applications with Python & Qt6
Take a look

Downloadable ebook (PDF, ePub) & Complete Source code

Also available from Leanpub and Amazon Paperback

[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]
Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

PyCharm issue, need to restart IDE when code changes was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.