modal dialog not staying on top

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

modal dialog not staying on top

Gary Ruben-2
I am opening a directory dialog (pyface DirectoryDialog) in a TraitsUI
(v4.1.0) application and would like it to stay on top but when the mouse
pointer moves over the chaco panel underneath it, it loses focus and the
main application window pops to the front. How do I stop this?

Based on this suggestion by Bryce Hendrix
http://article.gmane.org/gmane.comp.python.enthought.devel/24420/match=modal

I tried adding a global dir_dialog_open flag as follows

def _bt_export_file_changed(self):
   global dir_dialog_open
   dir_dialog_open = True
   dlg = DirectoryDialog(default_path=self.most_recent_path)
   if dlg.open() == OK:
     ...
   dir_dialog_open = False

and set enabled_when in the chaco window view

   traits_view = View(
                   UItem(
                     'plot',
                     editor=ComponentEditor(),
                     show_label=False,
                     enabled_when = 'dir_dialog_open==False', # doesn't
disable interaction
                     # enabled_when = 'False', # <- this works
                 ),
                 resizable=True,
             )

but this doesn't work: the chaco panel interaction isn't disabled - I
can still pan and zoom my plots.
If I replace the enabled_when test with enabled_when='False', the chaco
tool interaction is disabled as expected (no pan or zoom) and the dialog
no longer loses focus when the mouse moves over the chaco window.
Any ideas?

--
Gary Ruben

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

Re: modal dialog not staying on top

Gary Ruben-2
As a way of bumping this question, I'm wondering whether anyone has any
other suggestions for creating a modal dialog that will stay on top? Do
you think going to the effort of creating a wx dialog directly will be
more successful, or are there other directory chooser dialogs available
in the traitsui/pyface frameworks?

Gary

On 11/12/2012 1:18 PM, Gary Ruben wrote:

> I am opening a directory dialog (pyface DirectoryDialog) in a TraitsUI
> (v4.1.0) application and would like it to stay on top but when the mouse
> pointer moves over the chaco panel underneath it, it loses focus and the
> main application window pops to the front. How do I stop this?
>
> Based on this suggestion by Bryce Hendrix
> http://article.gmane.org/gmane.comp.python.enthought.devel/24420/match=modal
>
> I tried adding a global dir_dialog_open flag as follows
>
> def _bt_export_file_changed(self):
>     global dir_dialog_open
>     dir_dialog_open = True
>     dlg = DirectoryDialog(default_path=self.most_recent_path)
>     if dlg.open() == OK:
>       ...
>     dir_dialog_open = False
>
> and set enabled_when in the chaco window view
>
>     traits_view = View(
>                     UItem(
>                       'plot',
>                       editor=ComponentEditor(),
>                       show_label=False,
>                       enabled_when = 'dir_dialog_open==False', # doesn't
> disable interaction
>                       # enabled_when = 'False', # <- this works
>                   ),
>                   resizable=True,
>               )
>
> but this doesn't work: the chaco panel interaction isn't disabled - I
> can still pan and zoom my plots.
> If I replace the enabled_when test with enabled_when='False', the chaco
> tool interaction is disabled as expected (no pan or zoom) and the dialog
> no longer loses focus when the mouse moves over the chaco window.
> Any ideas?

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

Re: modal dialog not staying on top

Gary Ruben-2
I think the problem here that modal dialogs as implemented by pyface
don't have the parent wx.Frame handle specified? I see that the
DirectoryDialog allows specification of a parent handle. Does pyface
have a way of retrieving the handle of the main application's frame to
pass to DirectoryDialog(parent=?)

To demonstrate the problem on a standalone wx example:

import wx

app = wx.PySimpleApp()
mainFrame = wx.Frame(None, title="Click inside me")
def onMouseUp(event):
     #~ dlg = wx.DirDialog(parent=mainFrame) # <- works
     dlg = wx.DirDialog(parent=None)         # <- doesn't work
     dlg.ShowModal()

mainFrame.Bind(wx.EVT_LEFT_UP, onMouseUp)
mainFrame.Show()
app.SetTopWindow(mainFrame)
app.MainLoop()

On 20/12/2012 10:07 AM, Gary Ruben wrote:

> As a way of bumping this question, I'm wondering whether anyone has any
> other suggestions for creating a modal dialog that will stay on top? Do
> you think going to the effort of creating a wx dialog directly will be
> more successful, or are there other directory chooser dialogs available
> in the traitsui/pyface frameworks?
>
> Gary
>
> On 11/12/2012 1:18 PM, Gary Ruben wrote:
>> I am opening a directory dialog (pyface DirectoryDialog) in a TraitsUI
>> (v4.1.0) application and would like it to stay on top but when the mouse
>> pointer moves over the chaco panel underneath it, it loses focus and the
>> main application window pops to the front. How do I stop this?
>>
>> Based on this suggestion by Bryce Hendrix
>> http://article.gmane.org/gmane.comp.python.enthought.devel/24420/match=modal
>>
>> I tried adding a global dir_dialog_open flag as follows
>>
>> def _bt_export_file_changed(self):
>>      global dir_dialog_open
>>      dir_dialog_open = True
>>      dlg = DirectoryDialog(default_path=self.most_recent_path)
>>      if dlg.open() == OK:
>>        ...
>>      dir_dialog_open = False
>>
>> and set enabled_when in the chaco window view
>>
>>      traits_view = View(
>>                      UItem(
>>                        'plot',
>>                        editor=ComponentEditor(),
>>                        show_label=False,
>>                        enabled_when = 'dir_dialog_open==False', # doesn't
>> disable interaction
>>                        # enabled_when = 'False', # <- this works
>>                    ),
>>                    resizable=True,
>>                )
>>
>> but this doesn't work: the chaco panel interaction isn't disabled - I
>> can still pan and zoom my plots.
>> If I replace the enabled_when test with enabled_when='False', the chaco
>> tool interaction is disabled as expected (no pan or zoom) and the dialog
>> no longer loses focus when the mouse moves over the chaco window.
>> Any ideas?
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>


--
Gary Ruben
Software Engineer
VeRSI - Victorian eResearch Strategic Initiative
e. [hidden email]
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: modal dialog not staying on top

Gary Ruben-2
I finally found one way to do this, which is wx-specific. Posting here
for future reference.

import wx
...
myFrame = wx.GetApp().GetTopWindow()
dlg = DirectoryDialog(parent=myFrame, style='modal')

On 20/12/2012 2:40 PM, Gary Ruben wrote:

> I think the problem here that modal dialogs as implemented by pyface
> don't have the parent wx.Frame handle specified? I see that the
> DirectoryDialog allows specification of a parent handle. Does pyface
> have a way of retrieving the handle of the main application's frame to
> pass to DirectoryDialog(parent=?)
>
> To demonstrate the problem on a standalone wx example:
>
> import wx
>
> app = wx.PySimpleApp()
> mainFrame = wx.Frame(None, title="Click inside me")
> def onMouseUp(event):
>       #~ dlg = wx.DirDialog(parent=mainFrame) # <- works
>       dlg = wx.DirDialog(parent=None)         # <- doesn't work
>       dlg.ShowModal()
>
> mainFrame.Bind(wx.EVT_LEFT_UP, onMouseUp)
> mainFrame.Show()
> app.SetTopWindow(mainFrame)
> app.MainLoop()
>
> On 20/12/2012 10:07 AM, Gary Ruben wrote:
>> As a way of bumping this question, I'm wondering whether anyone has any
>> other suggestions for creating a modal dialog that will stay on top? Do
>> you think going to the effort of creating a wx dialog directly will be
>> more successful, or are there other directory chooser dialogs available
>> in the traitsui/pyface frameworks?
>>
>> Gary
>>
>> On 11/12/2012 1:18 PM, Gary Ruben wrote:
>>> I am opening a directory dialog (pyface DirectoryDialog) in a TraitsUI
>>> (v4.1.0) application and would like it to stay on top but when the mouse
>>> pointer moves over the chaco panel underneath it, it loses focus and the
>>> main application window pops to the front. How do I stop this?
>>>
>>> Based on this suggestion by Bryce Hendrix
>>> http://article.gmane.org/gmane.comp.python.enthought.devel/24420/match=modal
>>>
>>> I tried adding a global dir_dialog_open flag as follows
>>>
>>> def _bt_export_file_changed(self):
>>>       global dir_dialog_open
>>>       dir_dialog_open = True
>>>       dlg = DirectoryDialog(default_path=self.most_recent_path)
>>>       if dlg.open() == OK:
>>>         ...
>>>       dir_dialog_open = False
>>>
>>> and set enabled_when in the chaco window view
>>>
>>>       traits_view = View(
>>>                       UItem(
>>>                         'plot',
>>>                         editor=ComponentEditor(),
>>>                         show_label=False,
>>>                         enabled_when = 'dir_dialog_open==False', # doesn't
>>> disable interaction
>>>                         # enabled_when = 'False', # <- this works
>>>                     ),
>>>                     resizable=True,
>>>                 )
>>>
>>> but this doesn't work: the chaco panel interaction isn't disabled - I
>>> can still pan and zoom my plots.
>>> If I replace the enabled_when test with enabled_when='False', the chaco
>>> tool interaction is disabled as expected (no pan or zoom) and the dialog
>>> no longer loses focus when the mouse moves over the chaco window.
>>> Any ideas?
>>
>> _______________________________________________
>> 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