I have this:
oknoGlowne.py - main module :
from oknoNazwa import oknoNazwa
from oknoKola import oknoKola
from oknoIkona import oknoIkona
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class Main(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.initUI()
def initMenu(self):
menu = self.menuBar()
dialog = menu.addMenu("Dialog")
nazwa = QAction("Nazwa okna głównego", self)
nazwa.setCheckable(1)
self.oknoNazwa = oknoNazwa()
nazwa.triggered.connect(lambda: self.oknoNazwa.show())
kola = QAction("Ustaw koła", self)
kola.setCheckable(1)
self.oknoKola = oknoKola()
kola.triggered.connect(lambda: self.oknoKola.show())
ikona = QAction("Zmień ikonę", self)
ikona.setCheckable(1)
self.oknoIkona = oknoIkona()
ikona.triggered.connect(lambda: self.oknoIkona.show())
dialog.addAction(nazwa)
dialog.addAction(kola)
dialog.addAction(ikona)
def initUI(self):
self.setGeometry(100, 100, 300, 200)
self.setMinimumSize(300,200)
self.setWindowTitle("Notatnik")
self.initMenu()
def zmianaNazwy(self, tekst):
self.setWindowTitle(tekst)
def main():
app = QApplication(sys.argv)
okno = Main()
okno.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
And oknoNazwa.py - secondary module:
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class oknoNazwa(QDialog):
def __init__(self):
QDialog.__init__(self)
self.initUI()
def initUI(self):
self.setModal(0)
self.resize(200,60)
self.setWindowTitle("Zmień nazwę")
vbox = QVBoxLayout()
label = QLabel("Podaj nową nazwę programu:")
vbox.addWidget(label)
pole=QLineEdit()
vbox.addWidget(pole)
buttony = QWidget()
vbox.addWidget(buttony)
hbox = QHBoxLayout()
okButton = QPushButton("Zatwierdź")
cancelButton = QPushButton("Anuluj")
hbox.addWidget(okButton)
hbox.addWidget(cancelButton)
buttony.setLayout(hbox)
okButton.clicked.connect(lambda: self.zmienNazwe)
cancelButton.clicked.connect(lambda: self.done(1))
self.setLayout(vbox)
def zmienNazwe(self):
self.Main.zmianaNazwy(self.pole.text())
self.done(1)
How do I call function which belongs to main module - zmianaNazwy() in secondary module which is dialog with textfield containing string value of new main window title. I also want to wrap that function in another function so I can attach it's action to button, but maybe that's unnessesary and a calling a main modules name changing function would be enough. So the question is how do I do that?
As you can see I've tried to do it with like self.main class but that doesn't work, also even the self.done(1) isn't executed, I guess it's because self is taken as QPushButton but I might be wrong so clarify me.
2LDR -> How to call a function from main module in dialog (and assign it to a button action in that dialog) which is in another module which is being called on button press in main module?