Building on https://www.freecadweb.org/wiki/Macro_T ... Visibility, and as an exercise on my way to learn the dev side of FreeCAD, here is a new version that hides and restores all views so that the 3d view gets all the space. Run the macro again to restore the Report view, the Console view etc ....
It now deals with all 6 views instead of just 3. The .py file is used to keep visibility state info between macro calls.
vi_toggle_panels_visibility .FCMacro
Code: Select all
# coding: utf-8
r"""macro to toggle visibility of the views
The view configuration is hidden/restored on each call to this macro
The views layout is kept as is.
"""
from PySide import QtCore, QtGui
# global variables/state-keeping module
import vi_toggle_panels_visibility as state
def get_widget_by_name(widget_name, widgets):
r"""Retrieve a view widget by its name
Parameters
----------
widget_name : str
The name of the widget (e.g. 'Console view')
widgets : list
List of Qt widgets
Returns
-------
The widget that corresponds to the name parameter
"""
for dw in widgets:
if dw.objectName() == widget_name:
return dw
# The next 2 calls must be separated or the reference to the children disappear
# -> C++ object already deleted (must be a PySide bug)
mw = FreeCADGui.getMainWindow()
widgets_ = mw.findChildren(QtGui.QDockWidget)
widget_names = [w.objectName() for w in widgets_]
if state.calls % 2 == 0:
state.widget_states = {w: w.isVisible() for w in
[get_widget_by_name(name, widgets_)
for name in widget_names]}
state.calls += 1
for widget, is_visible in state.widget_states.items():
if widget.isVisible():
widget.hide()
else:
if is_visible:
widget.show()
else:
widget.hide()
Code: Select all
# coding: utf-8
r"""Cross macro calls global variables so that the views state can be restored
on every second call to the macro"""
calls = 0
widget_states = {}
https://www.freecadweb.org/wiki/File:Ma ... bility.png
Copy the FCMacro and the py file to the Macro folder.
If the name of the py file is changed, the FCMacro import must be changed accordingly.
Happy toggling ! I hope you find it useful.