Window stacking freedom

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

Window stacking freedom

Thomas Graff
Hello folks


I am writing an application with a basic layout of one main window and
possible several plot windows. The use needs to be able to interact
with the main window when several plot windows is open. So it is
desirable to be able to bring the main window in front of the plot
windows e.g. by cliking on the main window. But if I create the plot
windows "the proper way" by setting the parent parameter, I am not
able to do this. If I don't set the parent paramter I can do this, but
then other undesirable behaviour happends, like plot window stay open
after main window is closed.

So I wonder, is there a way to control this behaviour?

Example code:
from traits.etsconfig.api import ETSConfig
ETSConfig.toolkit = 'qt4'

import traits.api as traits
import traitsui.api as traitsui


class ChildUI(traits.HasTraits):
    traits_view = traitsui.View(
        width=300,
        height=300,
        buttons=[traitsui.OKButton],
        title='A plot window',
        )


class MainUI(traitsui.Handler):
    open_child = traits.Button('Open child window')
    win_hnd = traits.Any()

    def init(self, info):
        self.win_hnd = info.ui.control

    @traits.on_trait_change('open_child')
    def _open_handler(self, obj, name, old, new):
        cu = ChildUI()
        cu.edit_traits(parent=self.win_hnd, kind='nonmodal')

    traits_view = traitsui.View(
        traitsui.Item('open_child', show_label=False),
        buttons=[traitsui.OKButton],
        title='Main window',
        )


mu = MainUI()
mu.configure_traits()


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

Re: Window stacking freedom

Guido Muesch
Hello Thomas,
Hi All,

I somehow hoped for a good answer, because I have a similar problem. A
main window communicating with a remote device, in one case using a
serial connection and in another case a network connection. I want to
be able to fire up a plot window, but I need to keep track if it is
open or not.

Here is what I did:
class MainWindow(HasTraits):
    plotUi = Instance(PlotUi)
    plotUiButton = Button('Show Graph')



2012/12/5 Thomas Graff <[hidden email]>:

> Hello folks
>
>
> I am writing an application with a basic layout of one main window and
> possible several plot windows. The use needs to be able to interact
> with the main window when several plot windows is open. So it is
> desirable to be able to bring the main window in front of the plot
> windows e.g. by cliking on the main window. But if I create the plot
> windows "the proper way" by setting the parent parameter, I am not
> able to do this. If I don't set the parent paramter I can do this, but
> then other undesirable behaviour happends, like plot window stay open
> after main window is closed.
>
> So I wonder, is there a way to control this behaviour?
>
> Example code:
> from traits.etsconfig.api import ETSConfig
> ETSConfig.toolkit = 'qt4'
>
> import traits.api as traits
> import traitsui.api as traitsui
>
>
> class ChildUI(traits.HasTraits):
>     traits_view = traitsui.View(
>         width=300,
>         height=300,
>         buttons=[traitsui.OKButton],
>         title='A plot window',
>         )
>
>
> class MainUI(traitsui.Handler):
>     open_child = traits.Button('Open child window')
>     win_hnd = traits.Any()
>
>     def init(self, info):
>         self.win_hnd = info.ui.control
>
>     @traits.on_trait_change('open_child')
>     def _open_handler(self, obj, name, old, new):
>         cu = ChildUI()
>         cu.edit_traits(parent=self.win_hnd, kind='nonmodal')
>
>     traits_view = traitsui.View(
>         traitsui.Item('open_child', show_label=False),
>         buttons=[traitsui.OKButton],
>         title='Main window',
>         )
>
>
> mu = MainUI()
> mu.configure_traits()
>
>
> Thomas
> _______________________________________________
> 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: Window stacking freedom

Guido Muesch
Sorry, hit the send button too early...

Again (My lame attempt to control a plot window from a main window):

class MainWindow(HasTraits):
    plotUi = Instance(PlotUi)
    plotUiButton = Button('Show Graph')
    ...

    def __init__(self):
        self.plotUi = PlotUi()
        self.activePlotUi = None

    def _plotUiButton_fired(self):
        if self.activePlotUi:
            self.activePlotUi.dispose()
            self.activePlotUi = None
        else:
            self.activePlotUi = self.plotUi.edit_traits()

So by clicking on the "Show Graph" button, the PlotUI window appears
and it again disappears when hitting the button again. However, this
does not work nicely with closing the PlotUI window manually.
So, I was wondering how I can query if such a sub window is currently
displaying or not. Or maybe this is the completly wrong approach.

I admit I am only playing with Traits since two weeks.

Regards
Guido

2012/12/7 Guido Muesch <[hidden email]>:

> Hello Thomas,
> Hi All,
>
> I somehow hoped for a good answer, because I have a similar problem. A
> main window communicating with a remote device, in one case using a
> serial connection and in another case a network connection. I want to
> be able to fire up a plot window, but I need to keep track if it is
> open or not.
>
> Here is what I did:
> class MainWindow(HasTraits):
>     plotUi = Instance(PlotUi)
>     plotUiButton = Button('Show Graph')
>
>
>
> 2012/12/5 Thomas Graff <[hidden email]>:
>> Hello folks
>>
>>
>> I am writing an application with a basic layout of one main window and
>> possible several plot windows. The use needs to be able to interact
>> with the main window when several plot windows is open. So it is
>> desirable to be able to bring the main window in front of the plot
>> windows e.g. by cliking on the main window. But if I create the plot
>> windows "the proper way" by setting the parent parameter, I am not
>> able to do this. If I don't set the parent paramter I can do this, but
>> then other undesirable behaviour happends, like plot window stay open
>> after main window is closed.
>>
>> So I wonder, is there a way to control this behaviour?
>>
>> Example code:
>> from traits.etsconfig.api import ETSConfig
>> ETSConfig.toolkit = 'qt4'
>>
>> import traits.api as traits
>> import traitsui.api as traitsui
>>
>>
>> class ChildUI(traits.HasTraits):
>>     traits_view = traitsui.View(
>>         width=300,
>>         height=300,
>>         buttons=[traitsui.OKButton],
>>         title='A plot window',
>>         )
>>
>>
>> class MainUI(traitsui.Handler):
>>     open_child = traits.Button('Open child window')
>>     win_hnd = traits.Any()
>>
>>     def init(self, info):
>>         self.win_hnd = info.ui.control
>>
>>     @traits.on_trait_change('open_child')
>>     def _open_handler(self, obj, name, old, new):
>>         cu = ChildUI()
>>         cu.edit_traits(parent=self.win_hnd, kind='nonmodal')
>>
>>     traits_view = traitsui.View(
>>         traitsui.Item('open_child', show_label=False),
>>         buttons=[traitsui.OKButton],
>>         title='Main window',
>>         )
>>
>>
>> mu = MainUI()
>> mu.configure_traits()
>>
>>
>> Thomas
>> _______________________________________________
>> 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