是否可以删除/隐藏使用 mayavi 绘制某些内容时默认创建的标准工具栏?我发现这个:如何使用代码删除 python 中的 Mayavi 工具栏
但是我不明白我应该在哪里插入这段代码。有没有像mlab.toolbar.setVisible(False(这样更容易的东西?
import os
os.environ['ETS_TOOLKIT'] = 'qt4'
os.environ['QT_API'] = 'pyqt5'
from traits.api import HasTraits, Instance, on_trait_change
from traitsui.api import View, Item
from mayavi.core.ui.api import MayaviScene, MlabSceneModel, SceneEditor
from PyQt5.QtWidgets import *
from main import Ui_MainWindow
import sys
from traitsui.api import Handler
class Visualization(HasTraits):
scene = Instance(MlabSceneModel, ())
@on_trait_change('scene.activated')
def update_plot(self):
self.scene.mlab.test_points3d()
view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
height=250, width=300, show_label=False),
resizable=True # We need this to resize with the parent widget
)
class DisableToolbarHandler(Handler):
def position(self, info):
editor = info.ui.get_editors('scene')[0]
editor._scene._tool_bar.setVisible(False)
class MayaviQWidget(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
layout = QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
self.visualization = Visualization()
self.ui = self.visualization.edit_traits(handler=DisableToolbarHandler(), kind='subpanel').control
layout.addWidget(self.ui)
self.ui.setParent(self)
class Action(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(Action, self).__init__(parent)
self.setupUi(self)
self.splitter.setSizes([100, 300])
self.splitter_2.setSizes([400, 100])
container = QWidget()
mayavi_widget = MayaviQWidget(container)
self.Layout.addWidget(mayavi_widget)
if __name__ == "__main__":
app = QApplication(sys.argv)
action = Action()
action.show()
sys.exit(app.exec_())
在图形上,这可以很容易地完成,如下所示:
fig = mlab.figure(1)
fig.scene.scene_editor._tool_bar.setVisible(False)