[SOLVED]how to set the Combo View to "Model" from Python

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
piffpoof
Posts: 346
Joined: Sun Nov 30, 2014 11:00 am
Location: Mare Nostrum
Contact:

[SOLVED]how to set the Combo View to "Model" from Python

Post by piffpoof »

hello

I am trying to find out how to set the Combo View to "Model" from Python.

The only code I can find for this is the code listed for "Adding a Tab to the Combo View" on the page "Code Snippets"(http://www.freecadweb.org/wiki/index.ph ... Combo_View). Unfortunately I do not have the PyQt4 library on my version of FreeCAD and so this code will not run.

thanks

Dean

OS: Mac OS X
Word size: 64-bit
Version: 0.14.3703 (Git)
Branch: releases/FreeCAD-0-14
Hash: c6edd47334a3e6f209e493773093db2b9b4f0e40
Python version: 2.7.5
Qt version: 4.8.6
Coin version: 3.1.3
SoQt version: 1.5.0
OCC version: 6.7.0
Last edited by piffpoof on Wed Dec 24, 2014 6:46 am, edited 1 time in total.
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: how to set the Combo View to "Model" from Python

Post by wmayer »

Code: Select all

from PySide import QtCore, QtGui

mw=Gui.getMainWindow()
dw=mw.findChildren(QtGui.QDockWidget)
for i in dw:
  if i.objectName() == "Combo View":
    tab = i.findChild(QtGui.QTabWidget)
    break

tab.setCurrentIndex(1)
User avatar
piffpoof
Posts: 346
Joined: Sun Nov 30, 2014 11:00 am
Location: Mare Nostrum
Contact:

Re: how to set the Combo View to "Model" from Python

Post by piffpoof »

wmayer wrote:

Code: Select all

from PySide import QtCore, QtGui

mw=Gui.getMainWindow()
dw=mw.findChildren(QtGui.QDockWidget)
for i in dw:
  if i.objectName() == "Combo View":
    tab = i.findChild(QtGui.QTabWidget)
    break

tab.setCurrentIndex(1)
thank you,

one small point, I think the last line of code should read

Code: Select all

tab.setCurrentIndex(0)
in order to select the "Model" tab in the Combo View

Dean
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: how to set the Combo View to "Model" from Python

Post by wmayer »

one small point, I think the last line of code should read
yes.
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: how to set the Combo View to "Model" from Python

Post by mario52 »

hi
from PySide "Adding a Tab to the Combo View"

Code: Select all

# create new Tab in ComboView
from PySide import QtGui,QtCore

from PySide import QtGui,QtCore
#from PySide import uic

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)
       elif str(i.objectName()) == "Python Console":
           return i.findChild(QtGui.QTabWidget)
   raise Exception ("No tab widget found")

mw = getMainWindow()
tab = getComboView(getMainWindow())
tab2=QtGui.QDialog()
tab.addTab(tab2,"A Special Tab")

#uic.loadUi("/myTaskPanelforTabs.ui",tab2)
tab2.show()
#tab.removeTab(2)
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
mea08kw
Posts: 82
Joined: Sun Oct 09, 2022 6:22 am

Re: how to set the Combo View to "Model" from Python

Post by mea08kw »

wmayer wrote: Sat Dec 13, 2014 9:03 pm

Code: Select all

from PySide import QtCore, QtGui

mw=Gui.getMainWindow()
dw=mw.findChildren(QtGui.QDockWidget)
for i in dw:
  if i.objectName() == "Combo View":
    tab = i.findChild(QtGui.QTabWidget)
    break

tab.setCurrentIndex(1)
Hi Wmayer

I'm wondering if we could close combo view from Python.

Best Regards,

Mea08kw
mea08kw
Posts: 82
Joined: Sun Oct 09, 2022 6:22 am

Re: how to set the Combo View to "Model" from Python

Post by mea08kw »

mea08kw wrote: Tue Feb 07, 2023 2:51 am
wmayer wrote: Sat Dec 13, 2014 9:03 pm

Code: Select all

from PySide import QtCore, QtGui

mw=Gui.getMainWindow()
dw=mw.findChildren(QtGui.QDockWidget)
for i in dw:
  if i.objectName() == "Combo View":
    tab = i.findChild(QtGui.QTabWidget)
    break

tab.setCurrentIndex(1)
Hi Wmayer

I'm wondering if we could close combo view from Python.

Best Regards,

Mea08kw
Last post has been solved by executing i.close().

One more question: as FreeCAD's Task system will automatically add OK/Cancel buttons, I'm wondering how to remove those two buttons or edit the signal slot in those two buttons?
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: [SOLVED]how to set the Combo View to "Model" from Python

Post by wmayer »

One more question: as FreeCAD's Task system will automatically add OK/Cancel buttons, I'm wondering how to remove those two buttons or edit the signal slot in those two buttons?
You cannot modify the existing signal/slot connections. What you can do is to hide the buttons with

Code: Select all

from PySide import QtWidgets
mw = Gui.getMainWindow()
box = mw.findChild(QtWidgets.QDialogButtonBox)
for btn in box.buttons():
    btn.hide()
mea08kw
Posts: 82
Joined: Sun Oct 09, 2022 6:22 am

Re: [SOLVED]how to set the Combo View to "Model" from Python

Post by mea08kw »

wmayer wrote: Tue Feb 07, 2023 10:53 am
One more question: as FreeCAD's Task system will automatically add OK/Cancel buttons, I'm wondering how to remove those two buttons or edit the signal slot in those two buttons?
You cannot modify the existing signal/slot connections. What you can do is to hide the buttons with

Code: Select all

from PySide import QtWidgets
mw = Gui.getMainWindow()
box = mw.findChild(QtWidgets.QDialogButtonBox)
for btn in box.buttons():
    btn.hide()
Thanks for your code.

In the meantime, I found we could edit the connections by def accept(self) and def reject(self)
mea08kw
Posts: 82
Joined: Sun Oct 09, 2022 6:22 am

Re: [SOLVED]how to set the Combo View to "Model" from Python

Post by mea08kw »

In addition, I'm wondering if "Model" tab and "Tasks" tab can be hidden in combo view. If it can be only deleted, will the document or object items be deleted also?
Post Reply