Advertisement
danfalck

Untitled

Feb 6th, 2012
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.87 KB | None | 0 0
  1. from PyQt4 import QtGui,QtCore
  2. from PyQt4 import uic
  3. #from PySide import QtGui,QtCore
  4.  
  5. def getMainWindow():
  6.     "returns the main window"
  7.     # using QtGui.qApp.activeWindow() isn't very reliable because if another
  8.     # widget than the mainwindow is active (e.g. a dialog) the wrong widget is
  9.     # returned
  10.     toplevel = QtGui.qApp.topLevelWidgets()
  11.     for i in toplevel:
  12.         if i.metaObject().className() == "Gui::MainWindow":
  13.             return i
  14.     raise Exception("No main window found")
  15.  
  16. def getComboView(mw):
  17.     dw=mw.findChildren(QtGui.QDockWidget)
  18.     for i in dw:
  19.         if str(i.objectName()) == "Combo View":
  20.             return i.findChild(QtGui.QTabWidget)
  21.     raise Exception("No tab widget found")
  22.  
  23. def show_it(tabparent,tabchild,name,ui_file):
  24.     tabparent = getComboView(getMainWindow())
  25.     tabchild=QtGui.QDialog()
  26.     tabparent.addTab(tabchild, name)
  27.     uic.loadUi(ui_file, tabchild)
  28.     tabchild.show()
  29.  
  30. def remove_tab(tabparent,index):
  31.     tabparent.removeTab(index)
  32.  
  33.  
  34. class test(object):
  35.     def setupUi(self,object):
  36.         self.pushButton = QtGui.QPushButton(object)
  37.         self.pushButton.setText("The Button")
  38.         QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.make_it_happen)
  39.  
  40.     def make_it_happen(self):
  41.         FreeCAD.Console.PrintMessage('You pressed the button!\n')
  42.  
  43. def make_it_happen():
  44.     FreeCAD.Console.PrintMessage('You pressed the button!\n')
  45.  
  46. class TaskPanelTest:
  47.     def setupUi(self):
  48.         self.tab = getComboView(getMainWindow())
  49.         self.tab2=QtGui.QWidget()
  50.         self.tab.addTab(self.tab2,"A Special Tab")
  51.         #set the variable from the exp1.py file
  52.         Form =self.tab2
  53.         #copy paste code from 'pyuic4 exp1.ui > exp1.py' etc....
  54.         Form.setObjectName("Form")
  55.         Form.resize(400, 300)
  56.         self.pushButton = QtGui.QPushButton(Form)
  57.         self.pushButton.setGeometry(QtCore.QRect(290, 10, 93, 27))
  58.         self.pushButton.setObjectName("pushButton")
  59.         self.lineEdit = QtGui.QLineEdit(Form)
  60.         self.lineEdit.setGeometry(QtCore.QRect(170, 10, 113, 27))
  61.         self.lineEdit.setObjectName("lineEdit")
  62.  
  63.         #show the tab in all it's glory
  64.         self.tab2.show()
  65.         self. tab.setCurrentIndex(2) #set our new tab active
  66.         #connect pushbuttons to functions
  67.         QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), make_it_happen)
  68.  
  69.  
  70.         self.retranslateUi(Form)
  71.         QtCore.QMetaObject.connectSlotsByName(Form)
  72.  
  73.     def retranslateUi(self, Form):
  74.         Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
  75.         self.pushButton.setText(QtGui.QApplication.translate("Form", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
  76.  
  77.  
  78.     def killtab(self):
  79.         self.tab.removeTab(2)
  80.  
  81. panel1 = TaskPanelTest()
  82. panel1.setupUi()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement