def show(self): with traits_enaml.imports(): from enaml_Plotter import PlotMain app = QtApplication() view = PlotMain(plotr=self) view.show() app.start()
def perform(): # the app itself will be launched in its original location # (not the egg) with traits_enaml.imports(): from misc_views import DialogPopup application_manager.create_app() dialog = DialogPopup() dialog.show() run() dialog.close()
def test_auto_view(self): with traits_enaml.imports(): from enaml.widgets.api import Window model = AllTypes() window = Window() window.insert_children(None, (auto_view(model=model), )) with self.event_loop(): window.show() self.check_component_counts(window) self.check_label_text(window)
def test_auto_view(self): with traits_enaml.imports(): from enaml.widgets.api import Window model = AllTypes() window = Window() window.insert_children(None, (auto_view(model=model),)) with self.event_loop(): window.show() self.check_component_counts(window) self.check_label_text(window)
def create_component(self): with traits_enaml.imports(): from employee_view import EmployeeView from employee import Employer, Employee boss_john = Employer(first_name='John', last_name='Paw', company_name="Packrat's Cats") employee_mary = Employee(first_name='Mary', last_name='Sue', boss=boss_john) view = EmployeeView(employee=employee_mary) return view
def _get_dock_items(self): with traits_enaml.imports(): from .dock_items import AttributesItem, DataItem, ModelItem if self.input_data is not None: return [ AttributesItem(name='attributes'), DataItem(name='data'), ModelItem(name='model') ] return [ModelItem(name='model', title_bar_visible=False)]
def create_component(self): with traits_enaml.imports(): from employee_view import EmployeeView from employee import Employer, Employee boss_john = Employer(first_name="John", last_name="Paw", company_name="Packrat's Cats") employee_mary = Employee(first_name="Mary", last_name="Sue", boss=boss_john) view = EmployeeView(employee=employee_mary) return view
def test_find_all_enaml_widgets(self): assistant = self.test_assistant with traits_enaml.imports(): from traits_enaml.testing.tests.enaml_test_container import ( EnamlTestContainer) view, _ = assistant.parse_and_create(ENAML_SOURCE) with assistant.event_loop(): widgets = assistant.find_all_enaml_widgets( view, "EnamlTestContainer") self.assertEqual(len(widgets), 3) for widget in widgets: self.assertIsInstance(widget, EnamlTestContainer)
def parse_and_create(self, source, **kwargs): """ Parses and compiles the source. The source should have a component defined with the name 'MainView'. Arguments --------- source : str The enaml source file kwargs : dict The default attribute values to pass to the component. Returns ------- A tuple of the server and client component trees for the 'MainView' component. """ # This replicates what enaml.runner.main does enaml_ast = parse(source, filename='__enaml_tests__') code = EnamlCompiler.compile(enaml_ast, '__enaml_tests__') enaml_module = types.ModuleType('__tests__') ns = enaml_module.__dict__ with traits_enaml.imports(): six.exec_(code, ns, ns) View = ns['MainView'] enaml_view = View(**kwargs) enaml_view.initialize() if not enaml_view.proxy_is_active: enaml_view.activate_proxy() toolkit_view = enaml_view.proxy # We need to keep a reference to the enaml_module to ensure it does not # get collected. If no reference is kept, enaml operators will not be # able to resolve objects properly (eg. validator = IntValidator(...) # will fail) self.enaml_module = enaml_module return enaml_view, toolkit_view
def ok_pressed(self): code = """ import pandas as pd df = pd.read_json('""" + self.df.to_json() + """') def _view(dataframe): import traits_enaml with traits_enaml.imports(): from misc_views import DialogPopup print 'Launching Enaml UI Builder...' app = application() app.add_plugin(DataFramePlugin(data_frame=dataframe)) app.start() """ code_task = self.application.get_task('canopy.integrated_code_editor') # Make the python pane visible, if it is not if not code_task.python_pane.visible: code_task.python_pane.visible = True # Run the code in the frontend code_task.python_pane.frontend.execute_command(code) ## Launch UI Builder with traits_enaml.imports(): from misc_views import DialogPopup dialog = DialogPopup() dialog.show() app = application() app.add_plugin(DataFramePlugin(data_frame=self.df)) app.start() dialog.close()
* Add Color: Add a slider to control the color of intensity values. * Add Opacity: Adds a control point to adjust the shape of the transfer function, which controls the opacity of intensity values. """ import argparse from contextlib import closing import numpy as np from enaml.qt.qt_application import QtApplication import traits_enaml from ensemble.volren.api import VolumeBoundingBox, VolumeData, VolumeViewer with traits_enaml.imports(): from volume_viewer_window import VolumeViewerWindow def build_volume_data(cmdline_args): if cmdline_args.volume_file is None: volume = example_volume() else: import tables with closing(tables.openFile(cmdline_args.volume_file)) as h5: volume = h5.getNode(cmdline_args.node)[:].T volume_data_kwargs = {'raw_data': volume} if cmdline_args.mask: volume_data_kwargs['mask_data'] = example_volume_mask(volume)
def _get_enaml_view(self): with traits_enaml.imports(): from excel_import_view import ExcelImportView return ExcelImportView()
def _get_enaml_view(self): with traits_enaml.imports(): from fwf_import_view import FWFImportView return FWFImportView()
def create_component(self): with traits_enaml.imports(): from empty_form import EmptyForm return EmptyForm()
class Person(HasTraits): """ A simple class representing a person object. """ last_name = Str() first_name = Str() age = Range(low=0) def _age_changed(self, new): """ Prints out a message whenever the person's age changes. """ msg = "{first} {last} is {age} years old." s = msg.format( first=self.first_name, last=self.last_name, age=self.age, ) print s if __name__ == '__main__': import traits_enaml with traits_enaml.imports(): from person import PersonView john = Person(first_name='John', last_name='Doe', age=42) app = QtApplication() view = PersonView(person=john) view.show() app.start()
def _get_enaml_view(self): with traits_enaml.imports(): from csv_import_view import CSVImportView return CSVImportView()
def init_stdlib(): """ Register all the standard model components. """ from ..object_registry import ObjectFactory, ObjectRegistry from .controls import FactorControl, NumericalControl from .metrics import ValueMetric, RatioMetric, DistributionMetric, \ EntropyMetric, \ UniqueDiscreteMetric, UniqueContinuousMetric, GraphDensityMetric from .composite_scores import LinearCombinationScore, CustomScore, \ PrincipalComponentScore import traits_enaml with traits_enaml.imports(): from .ui.controls import FactorControlView, NumericalControlView from .ui.metrics import ValueMetricView, EntropyMetricView, RatioMetricView, \ DistributionMetricView, UniqueDiscreteMetricView, \ UniqueContinuousMetricView, GraphDensityMetricView from .ui.composite_scores import LinearCombinationScoreView, \ CustomScoreView, PrincipalComponentScoreView ObjectRegistry.instance().add( # Controls ObjectFactory( id = 'factor_control', name = 'Categorical', description = 'Control for a categorical variable', type = FactorControl, ui = FactorControlView, ), ObjectFactory( id = 'numerical_control', name = 'Numerical', description = 'Control for a numerical variable', type = NumericalControl, ui = NumericalControlView, ), # Metrics ObjectFactory( id = 'value_metric', name = 'Simple value', description = 'Compute a simple expression (boolean or numerical)', type = ValueMetric, ui = ValueMetricView, ), ObjectFactory( id = 'entropy_metric', name = 'Entropy', description = 'Compute entropy of groups', type = EntropyMetric, ui = EntropyMetricView, ), ObjectFactory( id = 'ratio_metric', name = 'Ratio', description = 'Compute the ratio between two numerical values', type = RatioMetric, ui = RatioMetricView, ), ObjectFactory( id = 'distribution_metric', name = 'Statistic', description = 'Compute statistics of the group and population data', type = DistributionMetric, ui = DistributionMetricView, ), ObjectFactory( id='unique_discrete_metric', name='Unique (Discrete)', description='Compute the ratio of unique values in each group', type=UniqueDiscreteMetric, ui=UniqueDiscreteMetricView ), ObjectFactory( id = 'unique_continuous_metric', name='Unique (Continuous)', description='Compute the ratio of coefficients of variance in each group', type=UniqueContinuousMetric, ui=UniqueContinuousMetricView ), ObjectFactory( id = 'graph_density_metric', name='Graph Density', description='Compute the density of the links between values within each group', type=GraphDensityMetric, ui=GraphDensityMetricView ), # Composite scores ObjectFactory( id = 'linear_combination_score', name = 'Simple linear combination', description = 'A manually specified linear combination', type = LinearCombinationScore, ui = LinearCombinationScoreView, ), ObjectFactory( id = 'custom_score', name = 'Custom score', description = 'A score computed by an arbitrary expression', type = CustomScore, ui = CustomScoreView, ), ObjectFactory( id = 'principal_component_score', name = 'Principal component analysis', description = 'A composite score using principal component analysis', type = PrincipalComponentScore, ui = PrincipalComponentScoreView ) )