Nov-22-2018, 03:19 PM
Many thanks for fixing the code. I have some questions about your changes:
1. Does your explanation mean that every window instantiated after the main window always needs to be an attribute of another object?
'show_concentration_test_window' method before your fixes:
'__init__' method of 'MainWindow' class before your fixes:
'__init__' method of 'MainWindow' class after your fixes:
2. What's the reason for changing the (constant) class variable 'COLORS' to an object variable 'self.COLORS'?
1. Does your explanation mean that every window instantiated after the main window always needs to be an attribute of another object?
'show_concentration_test_window' method before your fixes:
def show_concentration_test_window(self): concentration_test = ConcentrationTest(self.COLORS, self.get_designated_color()) concentration_test_window = ConcentrationTestWindow(concentration_test, self.get_switch_time()) concentration_test_window.show() concentration_test_window.change_screen_color()'show_concentration_test_window' method after your fixes:
def show_concentration_test_window(self): self.concentration_test = ConcentrationTest(self.COLORS, self.get_designated_color()) self.concentration_test_window = ConcentrationTestWindow(self.concentration_test, self.get_switch_time()) self.concentration_test_window.show() self.concentration_test_window.change_screen_color()
'__init__' method of 'MainWindow' class before your fixes:
class MainWindow(QMainWindow): COLORS = {"Black": QtCore.Qt.black, "Blue": QtCore.Qt.blue, "Cyan": QtCore.Qt.cyan, "Green": QtCore.Qt.green, "Magenta": QtCore.Qt.magenta, "Red": QtCore.Qt.red, "Yellow": QtCore.Qt.yellow} def __init__(self, concentration_test, parent=None): super().__init__(parent) loadUi("mainwindow.ui", self) self.concentration_test = concentration_test self.comboBox_designated_color.addItems(self.COLORS) self.pushButton_start_test.clicked.connect(self.show_concentration_test_window)The declaration of 'concentration_test' seems to be a relic from last refactoring.
'__init__' method of 'MainWindow' class after your fixes:
class MainWindow(QMainWindow): def __init__(self, parent=None): super().__init__() loadUi("mainwindow.ui", self) self.COLORS = {"Black": QtCore.Qt.black, "Blue": QtCore.Qt.blue, "Cyan": QtCore.Qt.cyan, "Green": QtCore.Qt.green, "Magenta": QtCore.Qt.magenta, "Red": QtCore.Qt.red, "Yellow": QtCore.Qt.yellow} self.comboBox_designated_color.addItems(self.COLORS) self.pushButton_start_test.clicked.connect(self.show_concentration_test_window)
2. What's the reason for changing the (constant) class variable 'COLORS' to an object variable 'self.COLORS'?