State of enaml's FileDialog?

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

State of enaml's FileDialog?

Mike Sarahan
Hi guys,

Any idea on why the FileDialog isn't opening?  Here's a quick bit that I think should work:

from enaml.widgets.api import MainWindow, Container, PushButton, FileDialog

enamldef OpenChestDialog(FileDialog):
    title = "WHARR BE YE TREASURE?"
    mode = "open_file"
    closed :: print self.path
enamldef Main(MainWindow): main:
attr dlg = OpenChestDialog(parent = main)
Container:
PushButton:
text = 'open file'
clicked :: dlg.open()
When I click the button, nothing happens. I'm using enaml from git (0.6.6). I may be completely misunderstanding what to do about the "parent" parameter.

Thanks for any tips.

Mike

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

Re: State of enaml's FileDialog?

Chris Colbert
There's a bug if the lifetime management of the dialog, which I haven't gotten around to fixing yet. This issue demonstrates a workaround:



On Sun, Jan 13, 2013 at 8:32 PM, Mike Sarahan <[hidden email]> wrote:
Hi guys,

Any idea on why the FileDialog isn't opening?  Here's a quick bit that I think should work:

from enaml.widgets.api import MainWindow, Container, PushButton, FileDialog

enamldef OpenChestDialog(FileDialog):
    title = "WHARR BE YE TREASURE?"
    mode = "open_file"
    closed :: print self.path
enamldef Main(MainWindow): main:
attr dlg = OpenChestDialog(parent = main)
Container:
PushButton:
text = 'open file'
clicked :: dlg.open()
When I click the button, nothing happens. I'm using enaml from git (0.6.6). I may be completely misunderstanding what to do about the "parent" parameter.

Thanks for any tips.

Mike

_______________________________________________
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: State of enaml's FileDialog?

Mike Sarahan

Thanks! I'll be sure to search the Github issues page next time my google searches come up dry.

Mike


On Jan 14, 2013 3:17 PM, "Chris Colbert" <[hidden email]> wrote:
There's a bug if the lifetime management of the dialog, which I haven't gotten around to fixing yet. This issue demonstrates a workaround:



On Sun, Jan 13, 2013 at 8:32 PM, Mike Sarahan <[hidden email]> wrote:
Hi guys,

Any idea on why the FileDialog isn't opening?  Here's a quick bit that I think should work:

from enaml.widgets.api import MainWindow, Container, PushButton, FileDialog

enamldef OpenChestDialog(FileDialog):
    title = "WHARR BE YE TREASURE?"
    mode = "open_file"
    closed :: print self.path
enamldef Main(MainWindow): main:
attr dlg = OpenChestDialog(parent = main)
Container:
PushButton:
text = 'open file'
clicked :: dlg.open()
When I click the button, nothing happens. I'm using enaml from git (0.6.6). I may be completely misunderstanding what to do about the "parent" parameter.

Thanks for any tips.

Mike

_______________________________________________
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: State of enaml's FileDialog?

John Lund
Here's another approach that work for me.

This work-around does not rely on timing and it makes use of the Include widget, which my be instructional for other uses:

from enaml.widgets.api import (
    Container,
    FileDialog,
    Include,
    PushButton,
    Window,
    )

def dir_dialog_callback(dlg):
    if dlg.result == 'accepted':
        print dlg.path

enamldef Main(Window): main:
    Container:
        PushButton: pb:
            text = 'Browse'
            clicked ::
                dir_dialog = dlg_incld.objects[0]
                dir_dialog.open()

        Include: dlg_incld:
            # Use the Include widget to construct the FileDialog
            # widget at load-time and then open it on demand.
            # Note use of key word arg, destroy_on_close=False,
            # failure to set this kwarg limits use of the widget
            # to one shot.
            objects = [FileDialog(main,
                                mode='directory',
                                callback=dir_dialog_callback,
                                destroy_on_close=False)]


On Tue, Jan 15, 2013 at 8:24 PM, Mike Sarahan <[hidden email]> wrote:

Thanks! I'll be sure to search the Github issues page next time my google searches come up dry.

Mike

 
John Lund
------------------------------
[hidden email]
Office: 281 578-0154

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

Re: State of enaml's FileDialog?

Chris Colbert
If you go that route, you should be able to just get rid of the Include all-together, and declare the FileDialog as a child of the Container.


On Wed, Jan 16, 2013 at 12:30 PM, John Lund <[hidden email]> wrote:
Here's another approach that work for me.

This work-around does not rely on timing and it makes use of the Include widget, which my be instructional for other uses:

from enaml.widgets.api import (
    Container,
    FileDialog,
    Include,
    PushButton,
    Window,
    )

def dir_dialog_callback(dlg):
    if dlg.result == 'accepted':
        print dlg.path

enamldef Main(Window): main:
    Container:
        PushButton: pb:
            text = 'Browse'
            clicked ::
                dir_dialog = dlg_incld.objects[0]
                dir_dialog.open()

        Include: dlg_incld:
            # Use the Include widget to construct the FileDialog
            # widget at load-time and then open it on demand.
            # Note use of key word arg, destroy_on_close=False,
            # failure to set this kwarg limits use of the widget
            # to one shot.
            objects = [FileDialog(main,
                                mode='directory',
                                callback=dir_dialog_callback,
                                destroy_on_close=False)]


On Tue, Jan 15, 2013 at 8:24 PM, Mike Sarahan <[hidden email]> wrote:

Thanks! I'll be sure to search the Github issues page next time my google searches come up dry.

Mike

 
John Lund
------------------------------
[hidden email]
Office: <a href="tel:281%20578-0154" value="+12815780154" target="_blank">281 578-0154

_______________________________________________
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: State of enaml's FileDialog?

John Lund
Thanks - that works nicely.

On Wed, Jan 16, 2013 at 11:46 AM, Chris Colbert <[hidden email]> wrote:
If you go that route, you should be able to just get rid of the Include all-together, and declare the FileDialog as a child of the Container.


On Wed, Jan 16, 2013 at 12:30 PM, John Lund <[hidden email]> wrote:
Here's another approach that work for me.

This work-around does not rely on timing and it makes use of the Include widget, which my be instructional for other uses:

from enaml.widgets.api import (
    Container,
    FileDialog,
    Include,
    PushButton,
    Window,
    )

def dir_dialog_callback(dlg):
    if dlg.result == 'accepted':
        print dlg.path

enamldef Main(Window): main:
    Container:
        PushButton: pb:
            text = 'Browse'
            clicked ::
                dir_dialog = dlg_incld.objects[0]
                dir_dialog.open()

        Include: dlg_incld:
            # Use the Include widget to construct the FileDialog
            # widget at load-time and then open it on demand.
            # Note use of key word arg, destroy_on_close=False,
            # failure to set this kwarg limits use of the widget
            # to one shot.
            objects = [FileDialog(main,
                                mode='directory',
                                callback=dir_dialog_callback,
                                destroy_on_close=False)]


On Tue, Jan 15, 2013 at 8:24 PM, Mike Sarahan <[hidden email]> wrote:

Thanks! I'll be sure to search the Github issues page next time my google searches come up dry.

Mike

 
John Lund
------------------------------
[hidden email]
Office: <a href="tel:281%20578-0154" value="+12815780154" target="_blank">281 578-0154

_______________________________________________
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




--
John Lund
------------------------------
[hidden email]
Office: 281 578-0154

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

Re: State of enaml's FileDialog?

Mike Sarahan
John and Chris,

Thanks to both of you.

For posterity's sake, here is my modified version of my code to to do what John and Chris describe:

from enaml.widgets.api import (
    Container,
    FileDialog,
    Include,
    PushButton,
    Window,
    )

def dir_dialog_callback(dlg):
    if dlg.result == 'accepted':
        print dlg.path

enamldef MyCustomFileDialog(FileDialog):
    title = "WHARR BE YE TREASURE?"
    mode = "open_file"
    callback=dir_dialog_callback
    destroy_on_close=False
        
enamldef Main(Window): main:
    Container:
        MyCustomFileDialog: fd:
            pass
        PushButton: pb:
            text = 'Browse'
            clicked ::
                fd.open()

Chris, out of curiosity, are there downsides to this way of doing things relative to my earlier attempt?  The only difference I see is that we now have the dialog hanging around in memory, rather than being created and destroyed.  It should be small, and not worth considering in terms of resources, right?

Please, don't hurry up on fixing that bug on my account.  I'm quite happy to proceed with this other way of doing things.

Best,
Mike


On Wed, Jan 16, 2013 at 10:06 AM, John Lund <[hidden email]> wrote:
Thanks - that works nicely.


On Wed, Jan 16, 2013 at 11:46 AM, Chris Colbert <[hidden email]> wrote:
If you go that route, you should be able to just get rid of the Include all-together, and declare the FileDialog as a child of the Container.


On Wed, Jan 16, 2013 at 12:30 PM, John Lund <[hidden email]> wrote:
Here's another approach that work for me.

This work-around does not rely on timing and it makes use of the Include widget, which my be instructional for other uses:

from enaml.widgets.api import (
    Container,
    FileDialog,
    Include,
    PushButton,
    Window,
    )

def dir_dialog_callback(dlg):
    if dlg.result == 'accepted':
        print dlg.path

enamldef Main(Window): main:
    Container:
        PushButton: pb:
            text = 'Browse'
            clicked ::
                dir_dialog = dlg_incld.objects[0]
                dir_dialog.open()

        Include: dlg_incld:
            # Use the Include widget to construct the FileDialog
            # widget at load-time and then open it on demand.
            # Note use of key word arg, destroy_on_close=False,
            # failure to set this kwarg limits use of the widget
            # to one shot.
            objects = [FileDialog(main,
                                mode='directory',
                                callback=dir_dialog_callback,
                                destroy_on_close=False)]


On Tue, Jan 15, 2013 at 8:24 PM, Mike Sarahan <[hidden email]> wrote:

Thanks! I'll be sure to search the Github issues page next time my google searches come up dry.

Mike

 
John Lund
------------------------------
[hidden email]
Office: <a href="tel:281%20578-0154" value="+12815780154" target="_blank">281 578-0154

_______________________________________________
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




--
John Lund
------------------------------
[hidden email]
Office: <a href="tel:281%20578-0154" value="+12815780154" target="_blank">281 578-0154

_______________________________________________
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: State of enaml's FileDialog?

Chris Colbert
Mike, 

There really aren't too many downsides to doing it this way since, like you mention, having a single dialog lingering around won't consume much memory and will open faster on subsequent invocations. However, if you are anything like me, the code pedant simply can't abide keeping around persistent dialogs ;-) In reality though, it's simply a matter of preference.

Cheers,

Chris


On Wed, Jan 16, 2013 at 10:51 PM, Mike Sarahan <[hidden email]> wrote:
John and Chris,

Thanks to both of you.

For posterity's sake, here is my modified version of my code to to do what John and Chris describe:

from enaml.widgets.api import (
    Container,
    FileDialog,
    Include,
    PushButton,
    Window,
    )

def dir_dialog_callback(dlg):
    if dlg.result == 'accepted':
        print dlg.path

enamldef MyCustomFileDialog(FileDialog):
    title = "WHARR BE YE TREASURE?"
    mode = "open_file"
    callback=dir_dialog_callback
    destroy_on_close=False
        
enamldef Main(Window): main:
    Container:
        MyCustomFileDialog: fd:
            pass
        PushButton: pb:
            text = 'Browse'
            clicked ::
                fd.open()

Chris, out of curiosity, are there downsides to this way of doing things relative to my earlier attempt?  The only difference I see is that we now have the dialog hanging around in memory, rather than being created and destroyed.  It should be small, and not worth considering in terms of resources, right?

Please, don't hurry up on fixing that bug on my account.  I'm quite happy to proceed with this other way of doing things.

Best,
Mike


On Wed, Jan 16, 2013 at 10:06 AM, John Lund <[hidden email]> wrote:
Thanks - that works nicely.


On Wed, Jan 16, 2013 at 11:46 AM, Chris Colbert <[hidden email]> wrote:
If you go that route, you should be able to just get rid of the Include all-together, and declare the FileDialog as a child of the Container.


On Wed, Jan 16, 2013 at 12:30 PM, John Lund <[hidden email]> wrote:
Here's another approach that work for me.

This work-around does not rely on timing and it makes use of the Include widget, which my be instructional for other uses:

from enaml.widgets.api import (
    Container,
    FileDialog,
    Include,
    PushButton,
    Window,
    )

def dir_dialog_callback(dlg):
    if dlg.result == 'accepted':
        print dlg.path

enamldef Main(Window): main:
    Container:
        PushButton: pb:
            text = 'Browse'
            clicked ::
                dir_dialog = dlg_incld.objects[0]
                dir_dialog.open()

        Include: dlg_incld:
            # Use the Include widget to construct the FileDialog
            # widget at load-time and then open it on demand.
            # Note use of key word arg, destroy_on_close=False,
            # failure to set this kwarg limits use of the widget
            # to one shot.
            objects = [FileDialog(main,
                                mode='directory',
                                callback=dir_dialog_callback,
                                destroy_on_close=False)]


On Tue, Jan 15, 2013 at 8:24 PM, Mike Sarahan <[hidden email]> wrote:

Thanks! I'll be sure to search the Github issues page next time my google searches come up dry.

Mike

 
John Lund
------------------------------
[hidden email]
Office: <a href="tel:281%20578-0154" value="+12815780154" target="_blank">281 578-0154

_______________________________________________
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




--
John Lund
------------------------------
[hidden email]
Office: <a href="tel:281%20578-0154" value="+12815780154" target="_blank">281 578-0154

_______________________________________________
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