Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# mo.TAIL,
# ostr))
# f.close()
#
# self.window.workbench.edit(File(myf), kind=TextEditor,use_existing=False)
import tempfile
myf = tempfile.mktemp(suffix='.py', prefix='my')
f=open(myf, 'w')
f.write(nbsscript)
f.close()
self.window.workbench.edit(File(myf), kind=TextEditor,use_existing=False)
class ShowNetworks(Action):
tooltip = "Create a 3D Network"
description = "Create a 3D Network"
# The WorkbenchWindow the action is attached to.
window = Any()
def perform(self, event=None):
from cnetwork_action import NetworkParameter
from scripts import netscript
cfile = self.window.application.get_service('cviewer.plugins.cff2.cfile.CFile')
no = NetworkParameter(cfile)
no.edit_traits(kind='livemodal')
if not no.netw[no.graph]['name'] == "None":
if so.labels_da[so.labels].has_key('da_idx'):
labels = so.labels_da[so.labels]['da_idx']
else:
labels = 0
f.write(surfscript % (so.pointset_da[so.pointset]['name'],
so.pointset_da[so.pointset]['da_idx'],
so.faces_da[so.faces]['name'],
so.faces_da[so.faces]['da_idx'],
so.labels_da[so.labels]['name'],
labels))
f.close()
self.window.workbench.edit(File(myf), kind=TextEditor,use_existing=False)
class ShowVolumes(Action):
""" Open a new file in the text editor
"""
tooltip = "Create a volume"
description = "Create a volume"
# The WorkbenchWindow the action is attached to.
window = Any()
def perform(self, event=None):
from cvolume_action import VolumeParameter
from scripts import volslice
cfile = self.window.application.get_service('cviewer.plugins.cff2.cfile.CFile')
so = VolumeParameter(cfile)
so.edit_traits(kind='livemodal')
# The scene manager.
scene_manager = Property(Instance(
'tvtk.plugins.scene.i_scene_manager import ISceneManager'
))
def _get_scene_manager(self):
""" Trait property getter. """
from tvtk.plugins.scene.i_scene_manager import (
ISceneManager
)
return self.window.get_service(ISceneManager)
class NewScene(Action):
""" An action that creates a new TVTK scene. """
#### 'Action' interface ###################################################
name = 'Scene'
def perform(self, event):
""" Performs the action. """
from tvtk.plugins.scene.scene_editor import SceneEditor
editor = self.window.edit(object(), kind=SceneEditor)
return editor
from tvtk.pipeline.browser import PipelineBrowser
######################################################################
# The scene icon.
######################################################################
def mk_scene_icon():
icon_path = os.path.join(resource_path(), 'images', 'scene.ico')
return ImageResource(icon_path)
scene_icon = mk_scene_icon()
######################################################################
# `ExitAction` class.
######################################################################
class ExitAction(Action):
""" Exits the application. """
def __init__(self, window):
""" Creates a new action. """
self._window = window
self.name = "E&xit"
def perform(self):
""" Performs the action. """
self._window.close()
######################################################################
# `SaveImageAction` class.
######################################################################
class SaveImageAction(Action):
"""Saves the rendered scene to an image."""
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
""" Abstract base class for all workbench actions. """
from pyface.workbench.api import WorkbenchWindow
from pyface.action.api import Action
from traits.api import Instance
class WorkbenchAction(Action):
""" Abstract base class for all workbench actions. """
# 'WorkbenchAction' interface -----------------------------------------#
# The workbench window that the action is in.
#
# This is set by the framework.
window = Instance(WorkbenchWindow)
style="toggle",
enabled=(self.marker is not None),
on_perform = self._toggle_axes,
checked = self.show_axes,
),
Action(
image = ImageResource('16x16/fullscreen',
search_path = [self._get_image_path()],
),
tooltip = 'Full Screen (press "q" or "e" or Esc to exit fullscreen)',
style="push",
on_perform = self._full_screen_fired,
),
),
Group(
Action(
image = ImageResource('16x16/save',
search_path = [self._get_image_path()],
),
tooltip = "Save a snapshot of this scene",
on_perform = self._save_snapshot,
),
Action(
image = ImageResource('16x16/configure',
search_path = [self._get_image_path()],
),
tooltip = 'Configure the scene',
style="push",
on_perform = self._configure_scene,
),
search_path = [self._get_image_path()],
),
tooltip = 'Full Screen (press "q" or "e" or ESC to exit fullscreen)',
style="push",
on_perform = self._full_screen_fired,
),
),
Group(
Action(
image = ImageResource('16x16/save',
search_path = [self._get_image_path()],
),
tooltip = "Save a snapshot of this scene",
on_perform = self._save_snapshot,
),
Action(
image = ImageResource('16x16/configure',
search_path = [self._get_image_path()],
),
tooltip = 'Configure the scene',
style="push",
on_perform = self._configure_scene,
),
def __init__(self, **traits):
""" Creates a new application window. """
# Base class constructor.
super(MainWindow, self).__init__(**traits)
# Create an action that exits the application.
exit_action = Action(name="E&xit", on_perform=self.close)
self.exit_action = exit_action
# Test action to toggle visibility of exit action and some action groups
test_action = Action(name="&Toggle", on_perform=self.toggle)
# Add a menu bar.
self.menu_bar_manager = MenuBarManager(
MenuManager(exit_action, name="&File")
)
# Add some tool bars, with the first one subdivided into action groups
self.tool_bar_managers = [
ToolBarManager(
Group(exit_action, exit_action, id="a"),
Group(id="b"), # empty, so will remain hidden
Group(exit_action, exit_action, id="c"),
Group(exit_action, test_action, exit_action, id="d"),
name="Tool Bar 1",
show_tool_names=True,
),
if hasattr(tvtk, 'OrientationMarkerWidget'):
# The tvtk orientation marker widget. This only exists in VTK
# 5.x.
marker = Instance(tvtk.OrientationMarkerWidget, ())
# The tvtk axes that will be shown for the orientation.
axes = Instance(tvtk.AxesActor, ())
else:
marker = None
axes = None
# Determine if the orientation axis is shown or not.
show_axes = false
# The list of actions represented in the toolbar
actions = List(Either(Action, Group))
##########################################################################
# `object` interface
##########################################################################
def __init__(self, parent, **traits):
super(DecoratedScene, self).__init__(parent, **traits)
self._setup_axes_marker()
def __get_pure_state__(self):
"""Allows us to pickle the scene."""
# The control attribute is not picklable since it is a VTK
# object so we remove it.
d = super(DecoratedScene, self).__get_pure_state__()
for x in ['_content', '_panel', '_tool_bar', 'actions']:
d.pop(x, None)
return d
for description, extension in zip(descriptions, extensions):
wildcard += "{} ({})|{}|".format(description,
extension,
extension)
wildcard += "Determine by extension (*.*)|(*.*)"
dlg = FileDialog(parent=self._window.control, action='save as',
wildcard=wildcard, title="Save scene to image")
if dlg.open() == OK:
self._window.scene.save(dlg.path)
######################################################################
# `SaveToClipboardAction` class.
######################################################################
class SaveToClipboardAction(Action):
""" Saves rendered scene to the Clipboard. """
def __init__(self, window):
""" Creates a new action. """
self._window = window
self.name = "&Copy"
def perform(self):
""" Performs the action. """
self._window.scene.save_to_clipboard()
######################################################################
# `SpecialViewAction` class.
######################################################################
class SpecialViewAction(Action):
"""Sets the scene to a particular view."""