I have two widget: The first (Form1) have a combobox. If I using this combobox 
that is show on console. (#This is good) But I would like using this variable 
on second widget (Form2), but I don't show it. (#This is bad) How can I use 
this "text" variable on my Form2 widget?

import sys

from functools import partial
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4 import QtGui, QtCore
from math import sqrt
from time import gmtime, strftime

text = ""

    class Form1(QWidget):
        showForm2Signal = pyqtSignal()

        def __init__(self, parent=None):
            super(Form1, self).__init__(parent)

            self.comboBox = QtGui.QComboBox(self)
            self.comboBox.addItem("Text 1")
            self.comboBox.addItem("Text 2")
            self.comboBox.addItem("Text 3")
            self.comboBox.addItem("Text 4")
            self.comboBox.addItem("Text 5")
            self.comboBox.addItem("Text 6")
            self.comboBox.addItem("Text 7")
            self.comboBox.move(20, 20)
            self.comboBox.resize(360,30)
            self.comboBox.currentIndexChanged.connect(self.selectionchange)

            layout = QVBoxLayout(self)

            ok_button = QtGui.QPushButton("OK", self)
            ok_button.resize(ok_button.minimumSizeHint())
            ok_button.move(0,340)
            ok_button.resize(400,60)
            ok_button.setStyleSheet("color: #25373D; background-color: #71BA51; 
 font-size: 16pt; font-weight: bold;")

            ok_button.clicked.connect(self.showForm2Signal.emit)

        def selectionchange(self,i):     
            text = self.comboBox.currentText()
            #This is good
            print text

    class Form2(QWidget):
        showForm1Signal = pyqtSignal()

        def __init__(self, parent=None):
            super(Form2, self).__init__(parent)
            #This is bad
            print text
            self.backButton = QPushButton("Back", self)
            self.backButton.clicked.connect(self.showForm1Signal.emit)


    class MainWidget(QWidget):
        def __init__(self, parent=None):
            super(MainWidget, self).__init__(parent)
            self.stack = QStackedWidget()
            layout = QVBoxLayout(self)
            layout.addWidget(self.stack)
            layout.setContentsMargins(0, 0, 0, 0)
            self.setGeometry(0, 0, 400, 400)
            self.setWindowTitle("TEST")
            self.form1 = Form1(self)
            self.form2 = Form2(self)
            self.stack.addWidget(self.form1)
            self.stack.addWidget(self.form2)

            
self.form1.showForm2Signal.connect(partial(self.stack.setCurrentWidget,self.form2))
            
self.form2.showForm1Signal.connect(partial(self.stack.setCurrentWidget,self.form1))
            self.stack.setCurrentWidget(self.form1)  
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        w = MainWidget()
        w.show()
        app.exec_()
        sys.exit()

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/a7bf6ef8-6dfd-45cf-9c8b-7b64f21ff6f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to