Пример #1
0
class AnalyticalFunction(HasTraits):

    No_of_all_curves = Int(3)
    expression1 = Expression('x**2', auto_set=False, enter_set=True)
    expression2 = Expression('x**2.3', auto_set=False, enter_set=True)
    expression3 = Expression('x**2.6', auto_set=False, enter_set=True)
    refresh = Button('redraw')

    def _refresh_fired(self):

        #creates an empty plot data container as a list of MFnLineArray classes
        self.mfn.lines = self.No_of_all_curves * [MFnLineArray()]

        xdata = linspace(0, 10, 100)
        fneval1 = frompyfunc(lambda x: eval(self.expression1), 1, 1)
        fneval2 = frompyfunc(lambda x: eval(self.expression2), 1, 1)
        fneval3 = frompyfunc(lambda x: eval(self.expression3), 1, 1)
        self.mfn.lines[0] = MFnLineArray(xdata=xdata, ydata=fneval1(xdata))
        self.mfn.lines[1] = MFnLineArray(xdata=xdata, ydata=fneval2(xdata))
        self.mfn.lines[2] = MFnLineArray(xdata=xdata, ydata=fneval3(xdata))
        self.mfn.data_changed = True

    mfn = Instance(MFnMultiLine)

    def _mfn_default(self):
        return MFnMultiLine()

    @on_trait_change('expression')
    def update_mfn(self):
        self._refresh_fired()

    view_mpl = View(HGroup(Item('expression1'), Item('expression2'),
                           Item('expression3'), Item('refresh')),
                    Item('mfn',
                         editor=MFnMatplotlibEditor(adapter=a),
                         show_label=False),
                    resizable=True,
                    scrollable=True,
                    height=0.5,
                    width=0.5)

    view_chaco = View(HGroup(Item('expression1'), Item('expression2'),
                             Item('expression3'), Item('refresh')),
                      Item('mfn',
                           editor=MFnChacoEditor(adapter=a),
                           resizable=True,
                           show_label=False),
                      resizable=True,
                      scrollable=True,
                      height=0.5,
                      width=0.5)
Пример #2
0
class ODE1D(ODE):
    """ A generic 1D ODE """
    name = '1D ODE'
    num_vars = 1
    vars = List(['x'])
    equation = Expression('1-x')

    def eval(self, X, t):
        return eval(self.equation_, numpy.__dict__, locals())
Пример #3
0
        class Foo(HasTraits):
            # The default value set in the class definition is "0"
            bar = Expression()

            default_calls = Int(0)

            def _bar_default(self):
                self.default_calls += 1
                return "1"
Пример #4
0
class AnalyticalFunction(HasTraits):

    expression = Expression('x**2', auto_set=False, enter_set=True)
    refresh = Button('redraw')

    def _refresh_fired(self):
        xdata = linspace(0.001, 10, 10000)
        fneval = frompyfunc(lambda x: eval(self.expression), 1, 1)
        ydata = fneval(xdata)
        self.mfn.set(xdata=xdata, ydata=ydata)
        self.mfn.data_changed = True

    mfn = Instance(MFnLineArray)

    def _mfn_default(self):
        return MFnLineArray()

    @on_trait_change('expression')
    def update_mfn(self):
        self._refresh_fired()

    view_mpl = View(HGroup(Item('expression'), Item('refresh')),
                    Item('mfn',
                         editor=MFnMatplotlibEditor(adapter=a),
                         show_label=False),
                    resizable=True,
                    scrollable=True,
                    height=0.5,
                    width=0.5)

    view_chaco = View(HGroup(Item('expression'), Item('refresh')),
                      Item('mfn',
                           editor=MFnChacoEditor(adapter=a),
                           resizable=True,
                           show_label=False),
                      resizable=True,
                      scrollable=True,
                      height=0.3,
                      width=0.3)
Пример #5
0
# Styles for user interface elements:
EditorStyle = style_trait = Trait(
    'simple',
    TraitPrefixList(
        'simple',
        'custom',
        'text',
        'readonly'),
    cols=4)

# Group layout trait:
Layout = Trait('normal',
               TraitPrefixList('normal', 'split', 'tabbed', 'flow', 'fold'))

# Trait for the default object being edited:
AnObject = Expression('object')

# The default dock style to use:
DockStyle = dock_style_trait = Enum('fixed', 'horizontal', 'vertical', 'tab',
                                    desc="the default docking style to use")

# The category of elements dragged out of the view:
ExportType = Str(desc='the category of elements dragged out of the view')

# Delegate a trait value to the object's **container** trait:
ContainerDelegate = container_delegate = Delegate('container',
                                                  listenable=False)

# An identifier for the external help context:
HelpId = help_id_trait = Str(desc="the external help context identifier")
Пример #6
0
 class BaseFoo(HasTraits):
     # The default value set in the class definition is "0"
     bar = Expression()
Пример #7
0
        class Foo(HasTraits):
            bar = Expression()

            def _bar_default(self):
                return "{x=y"
Пример #8
0
 class Foo(HasTraits):
     # The default value set in the class definition is "0"
     bar = Expression(default_value="1")
Пример #9
0
 class Foo(HasTraits):
     bar = Expression()
Пример #10
0
# -------------------------------------------------------------------------
#  Trait definitions:
# -------------------------------------------------------------------------

# Orientation trait:
Orientation = PrefixList(("vertical", "horizontal"))

# Styles for user interface elements:
EditorStyle = style_trait = PrefixList(
    ("simple", "custom", "text", "readonly"), cols=4)

# Group layout trait:
Layout = PrefixList(("normal", "split", "tabbed", "flow", "fold"))

# Trait for the default object being edited:
AnObject = Expression("object")

# The default dock style to use:
DockStyle = dock_style_trait = Enum(
    "fixed",
    "horizontal",
    "vertical",
    "tab",
    desc="the default docking style to use",
)

# The category of elements dragged out of the view:
ExportType = Str(desc="the category of elements dragged out of the view")

# Delegate a trait value to the object's **container** trait:
ContainerDelegate = container_delegate = Delegate("container",