Advertisement
danfalck

add_tab.py

Jan 21st, 2012
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. from PyQt4 import QtGui,QtCore
  2. #from PySide import QtGui,QtCore
  3. import FreeCAD
  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.  
  17.  
  18. def getComboView(mw):
  19.     dw=mw.findChildren(QtGui.QDockWidget)
  20.     for i in dw:
  21.         if str(i.objectName()) == "Combo View":
  22.             return i.findChild(QtGui.QTabWidget)
  23.     raise Exception("No tab widget found")
  24.  
  25. class test(object):
  26.     def setupUi(self,object):
  27.         self.pushButton = QtGui.QPushButton(object)
  28.         self.pushButton.setText("The Button")
  29.         self.pushButton.show()
  30.  
  31.         QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.make_it_happen)
  32.  
  33.     def make_it_happen(self):
  34.         FreeCAD.Console.PrintMessage('You pressed the button!\n')
  35.  
  36.     def kill_the_button(self):
  37.         self.pushButton.hide()
  38.  
  39. mw = getMainWindow()
  40. tab = getComboView(getMainWindow())
  41. tab2 = QtGui.QTabWidget(parent = mw)
  42. tab.addTab(tab2,"A Special Tab")
  43. panel = test()
  44. panel.setupUi(tab2)
  45.  
  46.  
  47.  
  48. #tab.removeTab(2) #remove tab2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement