TraitsGUI keeps values from previous run

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

TraitsGUI keeps values from previous run

Timmie
Administrator
Dear all,
I am creating a IPython magic function which uses a TraitsGUI for defining some inputs.
A file editor is used in this GUI to pick the input file.

The whole GUI works well on the first call via
%show_gui

But when I repeat the magic command within the same IPython session, the GUI does not work again.
It either uses the GUI inputs from the previous command run or does not show the file selector dialog of the file editor. The gui starts to "flicker" once I try to selct a file.

What could be the cause for this behaviour?

Thanks in advance for your hints!
Timmie
Reply | Threaded
Open this post in threaded view
|

Re: TraitsGUI keeps values from previous run

Gael Varoquaux
On Wed, Apr 07, 2010 at 04:52:13AM -0800, Timmie wrote:
> I am creating a IPython magic function which uses a TraitsGUI for defining
> some inputs.
> A file editor is used in this GUI to pick the input file.

> The whole GUI works well on the first call via
> %show_gui

> But when I repeat the magic command within the same IPython session, the GUI
> does not work again.
> It either uses the GUI inputs from the previous command run or does not show
> the file selector dialog of the file editor. The gui starts to "flicker"
> once I try to selct a file.

> What could be the cause for this behaviour?

Event loop problems.

What's your IPython version? How do you start ipython (-pylab switch?
if so, which pylab backend)?

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

Re: TraitsGUI keeps values from previous run

Timmie
Administrator
Gael Varoquaux wrote
> What could be the cause for this behaviour?

Event loop problems.
Good that you know the source of the problem.

Gael Varoquaux wrote
What's your IPython version? How do you start ipython (-pylab switch?
if so, which pylab backend)?
I use:
IPython 0.10   [on Py 2.6.2]
I used it without any switch/profile.

How can I get around that event loop problem?

Thanks & regards,
Timmie

Reply | Threaded
Open this post in threaded view
|

Re: TraitsGUI keeps values from previous run

Robert Kern
In reply to this post by Timmie
On Wed, Apr 7, 2010 at 7:52 AM, Timmie <[hidden email]> wrote:

>
> Dear all,
> I am creating a IPython magic function which uses a TraitsGUI for defining
> some inputs.
> A file editor is used in this GUI to pick the input file.
>
> The whole GUI works well on the first call via
> %show_gui
>
> But when I repeat the magic command within the same IPython session, the GUI
> does not work again.
> It either uses the GUI inputs from the previous command run or does not show
> the file selector dialog of the file editor. The gui starts to "flicker"
> once I try to selct a file.
>
> What could be the cause for this behaviour?

We'll need to see some code. Are you using .configure_traits()? You
may need to use .edit_traits() instead.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: TraitsGUI keeps values from previous run

Gael Varoquaux
In reply to this post by Timmie
On Wed, Apr 07, 2010 at 08:49:06AM -0800, Timmie wrote:
> > What's your IPython version? How do you start ipython (-pylab switch?
> > if so, which pylab backend)?

> I use:
> IPython 0.10   [on Py 2.6.2]
> I used it without any switch/profile.

> How can I get around that event loop problem?

Start ipython with '-wthread' and using '.edit_traits()' rather than
.configure_traits()' in your code.

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

Re: TraitsGUI keeps values from previous run

Chris Colbert
On Wed, Apr 7, 2010 at 1:08 PM, Gael Varoquaux
<[hidden email]> wrote:

> On Wed, Apr 07, 2010 at 08:49:06AM -0800, Timmie wrote:
>> > What's your IPython version? How do you start ipython (-pylab switch?
>> > if so, which pylab backend)?
>
>> I use:
>> IPython 0.10   [on Py 2.6.2]
>> I used it without any switch/profile.
>
>> How can I get around that event loop problem?
>
> Start ipython with '-wthread' and using '.edit_traits()' rather than
> .configure_traits()' in your code.
>


If you use the qt4 backend for traits, you don't need to use a
threading switch with Ipython.

Before running Ipython:

export ETS_TOOLKIT='qt4'


> Gaël
> _______________________________________________
> 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: TraitsGUI keeps values from previous run

Timmie
Administrator
Dear all,
thanks for your input.

I tried this out with the example below.

I not that I need to specify -q4thread before stating IPython.
As opposite to what Chris wrote, threading needs to be always enabled.

here are my commands in Ipython used to run the test code:
run eventloop_test.py
x = run_gui()
print x.filechoser.filepath

Is there no way to run such a GUI successivly from a normal of a simple IPython seesion?

Can the below written code be modified in such that the GUI runs nicely without there "-wthread" option?

According to the IPython manual the -[*]threat option is meant for cases where the GUI shall be maintained while still controlling it from the console.
This is not the case here as I just want to use the GUI as kind of a wizard dialog to facilitate input of parameters.
It doesn't need to be further maintained or controlled via the console.

Do you know whether there is a option to confiure IPython to always start in thread mode?

The reason is that I often start IPython from the Windows explorer shell context menu where I cannot add further command line switches.
This explorer shell entry is conviently provided by PythonXY.


Thanks in advance for your help,
Timmie

#### EXAMPLE code # hints appreciated

import IPython.ipapi
ip = IPython.ipapi.get()

import inspect

# set GUI toolkit
from enthought.etsconfig.etsconfig import ETSConfig
ETSConfig.toolkit = "qt4"

from enthought.traits.api import Float, Str, Int, Bool, Enum, CInt, String, Array
from enthought.traits.api import DelegatesTo, HasTraits, \
                                                File, Instance, Function
                                                   
from enthought.traits.ui.api import Item, HGroup, View, \
                                                    FileEditor, ButtonEditor, \
                                                    EnumEditor, CodeEditor
from enthought.traits.ui.menu import OKButton, CancelButton

file_filter=['All data types (*.csv, *.txt, *.dat)',
                'Only CSV files (*.csv)', '*.csv',
                'Only text files (*.txt)', '*.txt',
                'Only data files (*.dat)', '*.dat']

class FileChoser(HasTraits):
    "a file selector with filter for ASCII files"
    id        = 'dataloader.filechose',  
   
     

    filepath = File(editor = FileEditor())
    traits_ui_view = View(Item('filepath', label='Input CSV')
                                    )

class FC(HasTraits):
    "a container for the timeseries loader"
    filechoser = Instance(FileChoser)
   
    view = View(
                Item('filechoser', style='custom', show_label=False, ),
                buttons = [OKButton, CancelButton]
                )

gui = FC(filechoser=FileChoser())

def run_gui():
    gui.edit_traits()
    #gui.configure_traits()

    return gui
   
def file_select(self, arg):
    res = run_gui()
   
    print res.filechoser.filepath
   
    return res.filechoser.filepath

ip.expose_magic('filepath', file_select)
Reply | Threaded
Open this post in threaded view
|

Re: TraitsGUI keeps values from previous run

Chris Colbert
On Sat, Apr 10, 2010 at 6:17 AM, Timmie <[hidden email]> wrote:
>
> Dear all,
> thanks for your input.
>
> I tried this out with the example below.
>
> I not that I need to specify -q4thread before stating IPython.
> As opposite to what Chris wrote, threading needs to be always enabled.
>

That's interesting, the code you posted works just fine on my machine
without using the -q4thread switch. What OS, Python, Qt and PyQt
versions are you using?

I run Kubuntu 9.10 on Python 2.6.4, Qt 4.6, PyQt 4.7

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

Re: TraitsGUI keeps values from previous run

Timmie
Administrator
Hi,
thanks for your reply.

I am using:

Versions:

Python 2.6.2
PyQt 4.5.4
Qt 4.5.2

With PythonXY on Windows XP.
There is an update of PythonXY out which I will try.

Regards,
Timmie
Reply | Threaded
Open this post in threaded view
|

Re: TraitsGUI keeps values from previous run

Chris Colbert
On Sun, Apr 11, 2010 at 9:53 AM, Timmie <[hidden email]> wrote:

>
> Hi,
> thanks for your reply.
>
> I am using:
>
> Versions:
>
> Python 2.6.2
> PyQt 4.5.4
> Qt 4.5.2
>
> With PythonXY on Windows XP.
> There is an update of PythonXY out which I will try.
>
> Regards,
> Timmie
> --
> View this message in context: http://n3.nabble.com/TraitsGUI-keeps-values-from-previous-run-tp702906p711611.html
> Sent from the Enthought Dev mailing list archive at Nabble.com.
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>

Actually, looking into it more. It appears to be a windows issue (more
specifically Python installations without the readline module).

http://www.mail-archive.com/pyqt@.../msg11039.html

Based on Phil's last message there, it appeared he was going to patch
in the work around, but he may not have gotten to it.

Alas, you may be stuck with using the -q4thread switch on Windows.
Unfortunately, the last I heard (around December), the Ipython guys
were going to deprecate the thread switch support in future releases.
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: TraitsGUI keeps values from previous run

Timmie
Administrator
> Actually, looking into it more. It appears to be a windows issue (more
> specifically Python installations without the readline module).
>
> http://www.mail-archive.com/pyqt@.../msg11039.html
Sorry, I cannot read this massage.
Could you please post the subject of the message?

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

Re: TraitsGUI keeps values from previous run

Chris Colbert
Its a fairly long post, so I don't want to spam the list with it. Try
this link instead:

http://www.riverbankcomputing.com/pipermail/pyqt/2007-July/016512.html

On Tue, Apr 13, 2010 at 4:20 PM, Tim Michelsen
<[hidden email]> wrote:

>> Actually, looking into it more. It appears to be a windows issue (more
>> specifically Python installations without the readline module).
>>
>> http://www.mail-archive.com/pyqt@.../msg11039.html
> Sorry, I cannot read this massage.
> Could you please post the subject of the message?
>
> _______________________________________________
> 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