Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt4 import QtGui,QtCore
- from PyQt4 import uic
- #from PySide import QtGui,QtCore
- def getMainWindow():
- "returns the main window"
- # using QtGui.qApp.activeWindow() isn't very reliable because if another
- # widget than the mainwindow is active (e.g. a dialog) the wrong widget is
- # returned
- toplevel = QtGui.qApp.topLevelWidgets()
- for i in toplevel:
- if i.metaObject().className() == "Gui::MainWindow":
- return i
- raise Exception("No main window found")
- def getComboView(mw):
- dw=mw.findChildren(QtGui.QDockWidget)
- for i in dw:
- if str(i.objectName()) == "Combo View":
- return i.findChild(QtGui.QTabWidget)
- raise Exception("No tab widget found")
- def show_it(tabparent,tabchild,name,ui_file):
- tabparent = getComboView(getMainWindow())
- tabchild=QtGui.QDialog()
- tabparent.addTab(tabchild, name)
- uic.loadUi(ui_file, tabchild)
- tabchild.show()
- def remove_tab(tabparent,index):
- tabparent.removeTab(index)
- class test(object):
- def setupUi(self,object):
- self.pushButton = QtGui.QPushButton(object)
- self.pushButton.setText("The Button")
- QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.make_it_happen)
- def make_it_happen(self):
- FreeCAD.Console.PrintMessage('You pressed the button!\n')
- def make_it_happen():
- FreeCAD.Console.PrintMessage('You pressed the button!\n')
- class TaskPanelTest:
- def setupUi(self):
- self.tab = getComboView(getMainWindow())
- self.tab2=QtGui.QWidget()
- self.tab.addTab(self.tab2,"A Special Tab")
- #set the variable from the exp1.py file
- Form =self.tab2
- #copy paste code from 'pyuic4 exp1.ui > exp1.py' etc....
- Form.setObjectName("Form")
- Form.resize(400, 300)
- self.pushButton = QtGui.QPushButton(Form)
- self.pushButton.setGeometry(QtCore.QRect(290, 10, 93, 27))
- self.pushButton.setObjectName("pushButton")
- self.lineEdit = QtGui.QLineEdit(Form)
- self.lineEdit.setGeometry(QtCore.QRect(170, 10, 113, 27))
- self.lineEdit.setObjectName("lineEdit")
- #show the tab in all it's glory
- self.tab2.show()
- self. tab.setCurrentIndex(2) #set our new tab active
- #connect pushbuttons to functions
- QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), make_it_happen)
- self.retranslateUi(Form)
- QtCore.QMetaObject.connectSlotsByName(Form)
- def retranslateUi(self, Form):
- Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
- self.pushButton.setText(QtGui.QApplication.translate("Form", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
- def killtab(self):
- self.tab.removeTab(2)
- panel1 = TaskPanelTest()
- panel1.setupUi()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement