Object has no attribute __enaml_call__ - Making widgets importable

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Object has no attribute __enaml_call__ - Making widgets importable

Jaidev Deshpande
Hi,

What's the best way to import widgets that you've already written in
enaml into other enaml UIs? Eg, if I had a UI which had a chaco plot
on the left and a control panel on the right, and then I wanted to use
the same control panel on some data other than the chaco plot, I
should be able to make the control panel container widget importable
from somewhere. How do I create that 'somewhere'?

I tried experimenting that with a simple widget.
Suppose I had a simple PushButton which executed something when
clicked. If I had that button in a MainWindow, this is how I'd do it -

enamldef Main(MainWindow):
    Container:
        .
        .
        .
        . # Some other widgets
        .
        .
        .
        PushButton:
            id: pb
            text = 'Click me'
            clicked ::
                foo()

Now if I had to use pb again, which does the same when clicked, but in
another UI, how should I make this implementation of PushButton
importable?

I tried subclassing from Control class as follows:

from enaml.components.control import Control

class MyPushButton(Control):
    #
    # usual trait validations
    #
    def __init__(self):
        self.text = 'specific_name_for_button'
    #
    #
    # Other such specific definitions
    #

But when I try to use this class, I get the error, "MyPushButton has
no attribute __enaml_call__"

So how are widgets made callable in enaml?

Thanks
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Object has no attribute __enaml_call__ - Making widgets importable

Chris Colbert
Make it an enamldef, you can then import it like any other control.

I will save you the explanation of making a custom enaml widget using the current master branch, because it's overly difficult. This is all fixed in the feature-async branch which will be merged to master soon. Under the new architecture, it's much easier to define new controls and extension in Python.

enamldef FooButton(PushButton):
    text = 'Click me'
    clicked :: foo()


enamldef Main(MainWindow):
    Container:
        .
        .
        .
        . # Some other widgets
        .
        .
        .
        FooButton:
            id: pb


On Tue, Aug 21, 2012 at 9:27 AM, Jaidev Deshpande <[hidden email]> wrote:
Hi,

What's the best way to import widgets that you've already written in
enaml into other enaml UIs? Eg, if I had a UI which had a chaco plot
on the left and a control panel on the right, and then I wanted to use
the same control panel on some data other than the chaco plot, I
should be able to make the control panel container widget importable
from somewhere. How do I create that 'somewhere'?

I tried experimenting that with a simple widget.
Suppose I had a simple PushButton which executed something when
clicked. If I had that button in a MainWindow, this is how I'd do it -

enamldef Main(MainWindow):
    Container:
        .
        .
        .
        . # Some other widgets
        .
        .
        .
        PushButton:
            id: pb
            text = 'Click me'
            clicked ::
                foo()

Now if I had to use pb again, which does the same when clicked, but in
another UI, how should I make this implementation of PushButton
importable?

I tried subclassing from Control class as follows:

from enaml.components.control import Control

class MyPushButton(Control):
    #
    # usual trait validations
    #
    def __init__(self):
        self.text = 'specific_name_for_button'
    #
    #
    # Other such specific definitions
    #

But when I try to use this class, I get the error, "MyPushButton has
no attribute __enaml_call__"

So how are widgets made callable in enaml?

Thanks
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Object has no attribute __enaml_call__ - Making widgets importable

Jaidev Deshpande
On Tue, Aug 21, 2012 at 7:49 PM, Chris Colbert <[hidden email]> wrote:
> Make it an enamldef, you can then import it like any other control.
>
> I will save you the explanation of making a custom enaml widget using the
> current master branch, because it's overly difficult. This is all fixed in
> the feature-async branch which will be merged to master soon.

Do you think I should have a look at the feature-async branch?

> Under the new
> architecture, it's much easier to define new controls and extension in
> Python.
>
> enamldef FooButton(PushButton):
>     text = 'Click me'
>     clicked :: foo()
>

The definition above must be in the same file as the MainWindow, right?

>
> enamldef Main(MainWindow):
>     Container:
>         .
>         .
>         .
>         . # Some other widgets
>         .
>         .
>         .
>         FooButton:
>             id: pb
>
>
> On Tue, Aug 21, 2012 at 9:27 AM, Jaidev Deshpande
> <[hidden email]> wrote:
>>
>> Hi,
>>
>> What's the best way to import widgets that you've already written in
>> enaml into other enaml UIs? Eg, if I had a UI which had a chaco plot
>> on the left and a control panel on the right, and then I wanted to use
>> the same control panel on some data other than the chaco plot, I
>> should be able to make the control panel container widget importable
>> from somewhere. How do I create that 'somewhere'?
>>
>> I tried experimenting that with a simple widget.
>> Suppose I had a simple PushButton which executed something when
>> clicked. If I had that button in a MainWindow, this is how I'd do it -
>>
>> enamldef Main(MainWindow):
>>     Container:
>>         .
>>         .
>>         .
>>         . # Some other widgets
>>         .
>>         .
>>         .
>>         PushButton:
>>             id: pb
>>             text = 'Click me'
>>             clicked ::
>>                 foo()
>>
>> Now if I had to use pb again, which does the same when clicked, but in
>> another UI, how should I make this implementation of PushButton
>> importable?
>>
>> I tried subclassing from Control class as follows:
>>
>> from enaml.components.control import Control
>>
>> class MyPushButton(Control):
>>     #
>>     # usual trait validations
>>     #
>>     def __init__(self):
>>         self.text = 'specific_name_for_button'
>>     #
>>     #
>>     # Other such specific definitions
>>     #
>>
>> But when I try to use this class, I get the error, "MyPushButton has
>> no attribute __enaml_call__"
>>
>> So how are widgets made callable in enaml?
>>
>> Thanks
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
>
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Object has no attribute __enaml_call__ - Making widgets importable

Chris Colbert


On Tue, Aug 21, 2012 at 11:20 AM, Jaidev Deshpande <[hidden email]> wrote:
On Tue, Aug 21, 2012 at 7:49 PM, Chris Colbert <[hidden email]> wrote:
> Make it an enamldef, you can then import it like any other control.
>
> I will save you the explanation of making a custom enaml widget using the
> current master branch, because it's overly difficult. This is all fixed in
> the feature-async branch which will be merged to master soon.

Do you think I should have a look at the feature-async branch?


If you like reading source code, it is well documented and pretty easy to follow. However, most of the examples on that branch are not up to date. So it really depends on you. I'll be starting to look harder and merging it into mainline over the next couple of weeks. 

More correctly, I will move mainline into its own support-only branch, and feature-async will be move wholesale into master.

> Under the new
> architecture, it's much easier to define new controls and extension in
> Python.
>
> enamldef FooButton(PushButton):
>     text = 'Click me'
>     clicked :: foo()
>

The definition above must be in the same file as the MainWindow, right?

It doesn't have to be, you could define it in another .enaml file and just import it.

If you import an enaml file from within another enaml file (at the module leve), you don't need the enaml.imports() context.


>
> enamldef Main(MainWindow):
>     Container:
>         .
>         .
>         .
>         . # Some other widgets
>         .
>         .
>         .
>         FooButton:
>             id: pb
>
>
> On Tue, Aug 21, 2012 at 9:27 AM, Jaidev Deshpande
> <[hidden email]> wrote:
>>
>> Hi,
>>
>> What's the best way to import widgets that you've already written in
>> enaml into other enaml UIs? Eg, if I had a UI which had a chaco plot
>> on the left and a control panel on the right, and then I wanted to use
>> the same control panel on some data other than the chaco plot, I
>> should be able to make the control panel container widget importable
>> from somewhere. How do I create that 'somewhere'?
>>
>> I tried experimenting that with a simple widget.
>> Suppose I had a simple PushButton which executed something when
>> clicked. If I had that button in a MainWindow, this is how I'd do it -
>>
>> enamldef Main(MainWindow):
>>     Container:
>>         .
>>         .
>>         .
>>         . # Some other widgets
>>         .
>>         .
>>         .
>>         PushButton:
>>             id: pb
>>             text = 'Click me'
>>             clicked ::
>>                 foo()
>>
>> Now if I had to use pb again, which does the same when clicked, but in
>> another UI, how should I make this implementation of PushButton
>> importable?
>>
>> I tried subclassing from Control class as follows:
>>
>> from enaml.components.control import Control
>>
>> class MyPushButton(Control):
>>     #
>>     # usual trait validations
>>     #
>>     def __init__(self):
>>         self.text = 'specific_name_for_button'
>>     #
>>     #
>>     # Other such specific definitions
>>     #
>>
>> But when I try to use this class, I get the error, "MyPushButton has
>> no attribute __enaml_call__"
>>
>> So how are widgets made callable in enaml?
>>
>> Thanks
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
>
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Object has no attribute __enaml_call__ - Making widgets importable

Jaidev Deshpande
On Wed, Aug 22, 2012 at 7:15 AM, Chris Colbert <[hidden email]> wrote:

>
>
> On Tue, Aug 21, 2012 at 11:20 AM, Jaidev Deshpande
> <[hidden email]> wrote:
>>
>> On Tue, Aug 21, 2012 at 7:49 PM, Chris Colbert <[hidden email]>
>> wrote:
>> > Make it an enamldef, you can then import it like any other control.
>> >
>> > I will save you the explanation of making a custom enaml widget using
>> > the
>> > current master branch, because it's overly difficult. This is all fixed
>> > in
>> > the feature-async branch which will be merged to master soon.
>>
>> Do you think I should have a look at the feature-async branch?
>>
>
> If you like reading source code, it is well documented and pretty easy to
> follow. However, most of the examples on that branch are not up to date. So
> it really depends on you. I'll be starting to look harder and merging it
> into mainline over the next couple of weeks.
>
> More correctly, I will move mainline into its own support-only branch, and
> feature-async will be move wholesale into master.
>
>> > Under the new
>> > architecture, it's much easier to define new controls and extension in
>> > Python.
>> >
>> > enamldef FooButton(PushButton):
>> >     text = 'Click me'
>> >     clicked :: foo()
>> >
>>
>> The definition above must be in the same file as the MainWindow, right?
>
>
> It doesn't have to be, you could define it in another .enaml file and just
> import it.
>
> If you import an enaml file from within another enaml file (at the module
> leve), you don't need the enaml.imports() context.
>

Oh, didn't know that. Thanks.

>>
>> >
>> > enamldef Main(MainWindow):
>> >     Container:
>> >         .
>> >         .
>> >         .
>> >         . # Some other widgets
>> >         .
>> >         .
>> >         .
>> >         FooButton:
>> >             id: pb
>> >
>> >
>> > On Tue, Aug 21, 2012 at 9:27 AM, Jaidev Deshpande
>> > <[hidden email]> wrote:
>> >>
>> >> Hi,
>> >>
>> >> What's the best way to import widgets that you've already written in
>> >> enaml into other enaml UIs? Eg, if I had a UI which had a chaco plot
>> >> on the left and a control panel on the right, and then I wanted to use
>> >> the same control panel on some data other than the chaco plot, I
>> >> should be able to make the control panel container widget importable
>> >> from somewhere. How do I create that 'somewhere'?
>> >>
>> >> I tried experimenting that with a simple widget.
>> >> Suppose I had a simple PushButton which executed something when
>> >> clicked. If I had that button in a MainWindow, this is how I'd do it -
>> >>
>> >> enamldef Main(MainWindow):
>> >>     Container:
>> >>         .
>> >>         .
>> >>         .
>> >>         . # Some other widgets
>> >>         .
>> >>         .
>> >>         .
>> >>         PushButton:
>> >>             id: pb
>> >>             text = 'Click me'
>> >>             clicked ::
>> >>                 foo()
>> >>
>> >> Now if I had to use pb again, which does the same when clicked, but in
>> >> another UI, how should I make this implementation of PushButton
>> >> importable?
>> >>
>> >> I tried subclassing from Control class as follows:
>> >>
>> >> from enaml.components.control import Control
>> >>
>> >> class MyPushButton(Control):
>> >>     #
>> >>     # usual trait validations
>> >>     #
>> >>     def __init__(self):
>> >>         self.text = 'specific_name_for_button'
>> >>     #
>> >>     #
>> >>     # Other such specific definitions
>> >>     #
>> >>
>> >> But when I try to use this class, I get the error, "MyPushButton has
>> >> no attribute __enaml_call__"
>> >>
>> >> So how are widgets made callable in enaml?
>> >>
>> >> Thanks
>> >> _______________________________________________
>> >> Enthought-Dev mailing list
>> >> [hidden email]
>> >> https://mail.enthought.com/mailman/listinfo/enthought-dev
>> >
>> >
>> >
>> > _______________________________________________
>> > Enthought-Dev mailing list
>> > [hidden email]
>> > https://mail.enthought.com/mailman/listinfo/enthought-dev
>> >
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
>
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev