Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_views_request(self):
self.workbench.register(TaskManagerManifest())
core = self.workbench.get_plugin(u'enaml.workbench.core')
com = u'hqc_meas.task_manager.views_request'
with enaml.imports():
from hqc_meas.tasks.views.base_task_views import ComplexView
views, miss = core.invoke_command(com,
{'task_classes': ['ComplexTask']},
self)
assert_in('ComplexTask', views)
assert_equal(views['ComplexTask'], ComplexView)
assert_equal(miss, [])
# -*- coding: utf-8 -*-
#==============================================================================
# module : test_workspace.py
# author : Matthieu Dartiailh
# license : MIT license
#==============================================================================
import enaml
from enaml.workbench.api import Workbench
import os
import logging
from configobj import ConfigObj
from nose.tools import (assert_in, assert_not_in, assert_equal, assert_true,
assert_is_instance, assert_false)
from hqc_meas.debug.debugger_workspace import LOG_ID
with enaml.imports():
from enaml.workbench.core.core_manifest import CoreManifest
from enaml.workbench.ui.ui_manifest import UIManifest
from hqc_meas.utils.state.manifest import StateManifest
from hqc_meas.utils.preferences.manifest import PreferencesManifest
from hqc_meas.utils.log.manifest import LogManifest
from hqc_meas.tasks.manager.manifest import TaskManagerManifest
from hqc_meas.instruments.manager.manifest import InstrManagerManifest
from hqc_meas.debug.debugger_manifest import DebuggerManifest
from hqc_meas.app_manifest import HqcAppManifest
from .helpers import (TestSuiteManifest, TestDebugger, TestDebuggerView,
tester)
from ..util import (complete_line, process_app_events, close_all_windows,
remove_tree, create_test_dir)
# license : MIT license
# =============================================================================
""" This module gather routines linked to building tasks.
Save for build_task_from_config, all this function are rather method of the
TaskManager and should be called on their own. There are implemented here only
to simplify the manager.
"""
from enaml.widgets.api import FileDialogEx
from hqc_meas.tasks.api import RootTask
from .templates import load_template
import enaml
with enaml.imports():
from .builder_view import (TemplateSelectorView, BuilderView)
def build_task(manager, parent_ui=None):
""" Open a dialog to include a task in a task hierarchy.
Parameters:
----------
manager : TaskManagerPlugin
Instance of the current task manager plugin.
parent_ui : optional
Optional parent widget for the dialog.
Returns:
-------
def init_ui():
""" Do the enaml import and set up of the UI
Parameters
----------
data_muggler : databroker.muggler.data.DataMuggler
"""
global view
with enaml.imports():
from databroker.replay.gui.pipeline_hitting_mds import (PipelineView,
MplConfigs)
c_c_combo_fitter = MultiFitController(valid_models=valid_models)
scalar_collection = ScalarCollection()
scalar_collection.data_muggler = dm
scalar_collection.multi_fit_controller = c_c_combo_fitter
view = PipelineView()
configs = MplConfigs()
configs.config_model = scalar_collection._conf
# provide the pipeline view with its attributes
view.plot_options = configs
view.grab_latest = grab_latest
view.get_current_scanid = get_current_scanid
view.scalar_collection=scalar_collection
view.multi_fit_controller = c_c_combo_fitter
# -*- coding: utf-8 -*-
import enaml
with enaml.imports():
from .editor_manifest import ExecutionEditorManifest
def add_item(self, parent):
"""
Create a new item dialog window and handle the result
"""
with enaml.imports():
from widgets.dialogs import AddAWGDialog
dialogBox = AddAWGDialog(
parent,
modelNames=[i.__name__ for i in self.possibleItems],
objText="AWG")
dialogBox.exec_()
if dialogBox.result:
if dialogBox.newLabel not in self.itemDict.keys():
self.itemDict[dialogBox.newLabel] = self.possibleItems[
dialogBox.newModelNum](label=dialogBox.newLabel)
self.displayList.append(dialogBox.newLabel)
if dialogBox.auto_populate_channels and self.populate_physical_channels is not None:
self.populate_physical_channels(
[self.itemDict[dialogBox.newLabel]])
else:
print("WARNING: Can't use duplicate label %s" %
def _register_manifest(self, path, manifest_name):
""" Register a manifest given its module name and its name.
NB : the path should be a dot separated string referring to a package
in sys.path. It should be an absolute path.
"""
try:
with enaml.imports():
module = import_module(path)
manifest = getattr(module, manifest_name)
plugin = manifest()
self.workbench.register(plugin)
self._manifest_ids.append(plugin.id)
except Exception as e:
logger = logging.getLogger(__name__)
mess = 'Failed to register manifest: {}, error : {}'
logger.error(mess.format(path, e))
print('generating doc for %s' % script_name)
script_title = script_name.replace('_', ' ').title()
script_image_name = 'ex_' + script_name + '.png'
image_path = os.path.join(docs_path, 'images', script_image_name)
rst_path = os.path.join(
docs_path, 'ex_' + script_name + '.rst')
relative_script_path = script_path[
script_path.find('examples'):].replace('\\', '/')
# Add the script to the Python Path
old_python_path = sys.path
sys.path = sys.path + [os.path.dirname(script_path)]
snapshot_success = False
with enaml.imports():
try:
mod = __import__(script_name)
save_snapshot_of_module(mod, image_path)
snapshot_success = True
except Exception as err:
print('Could not snapshot: %s' % script_name)
print(' %s' % err)
finally:
# The import leaves behind a cache. Clean it up.
enaml_cache_dir = os.path.join(
os.path.dirname(script_path), '__enamlcache__')
shutil.rmtree(enaml_cache_dir)
# Restore Python path.
sys.path = old_python_path
def get_registered_styles(name):
# lazy import the stdlib module in case it's never needed.
global _dock_area_styles
if _dock_area_styles is None:
import enaml
with enaml.imports():
from enaml.stdlib import dock_area_styles
_dock_area_styles = dock_area_styles
return _dock_area_styles.get_registered_styles(name)
for ct in range(3):
ax.add_patch( Rectangle((-1.25, ct), 1, 1, clip_on=False, edgecolor="none", facecolor=reds(float(badCounts[ct])/pixelCounts.max()) ) )
ax.text(-0.75, ct+0.5, errorTexts[ct], fontsize=16, horizontalalignment="center", verticalalignment="center")
plt.colorbar(img)
return fig
if __name__ == '__main__':
#Load the library
lib = ctypes.cdll.LoadLibrary("libbbnfpga.so")
#Slow down the count rate to 100MHz/200
lib.write_register(CLKRATE_REG, 200)
counter = PulseCounter(lib=lib)
with enaml.imports():
from PulseCounterView import PulseCounterMainWin
app = QtApplication()
# Create a view and show it.
fig, ax = plt.subplots(1)
view = PulseCounterMainWin(counter=counter, fig=fig, lib=lib)
view.show()
app.start()