How to determine modality of a window

I can make a window modal by calling window.MakeModal(), and I
can make a window modeless by calling window.MakeModal(False),
but how do I determine whether or not the window is already
modal/modeless, as there doesn't appear to be a
window.IsModal()?

···

--
Paul

Paul McNett wrote:

I can make a window modal by calling window.MakeModal(), and I can make a window modeless by calling window.MakeModal(False), but how do I determine whether or not the window is already modal/modeless, as there doesn't appear to be a window.IsModal()?

Maybe you can test whether the window is enabled.

Derrick

Derrick writes:

>I can make a window modal by calling window.MakeModal(), and
> I can make a window modeless by calling
> window.MakeModal(False), but how do I determine whether or
> not the window is already modal/modeless, as there doesn't
> appear to be a
>window.IsModal()?

Maybe you can test whether the window is enabled.

No, not really. Both modeless and modal windows can be enabled
or disabled, separate from their modality setting.

···

--
Paul

Paul McNett wrote:

I can make a window modal by calling window.MakeModal(), and I can make a window modeless by calling window.MakeModal(False), but how do I determine whether or not the window is already modal/modeless, as there doesn't appear to be a window.IsModal()?

MakeModal simply disables all other top level windows (see below,) so there is no simple property for IsModal to return. You could check the status of all other TLWs...

void wxWindowBase::MakeModal(bool modal)
{
     // Disable all other windows
     if ( IsTopLevel() )
     {
         wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
         while (node)
         {
             wxWindow *win = node->GetData();
             if (win != this)
                 win->Enable(!modal);

             node = node->GetNext();
         }
     }
}

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn writes:

MakeModal simply disables all other top level windows (see
below,) so there is no simple property for IsModal to return.
You could check the status of all other TLWs...

Let me get this straight. Say I have (pseudocode):

win1 = wx.Frame()
win2 = wx.Frame()
win3 = wx.Frame()

win1.Enable(False)

win3.SetModal()
win3.SetModal(False)

# At this point, will win1 be implicitly enabled again,
# overriding my explicit win1.Enable(False) called previously?

···

--
Paul

Paul McNett wrote:

Robin Dunn writes:

MakeModal simply disables all other top level windows (see
below,) so there is no simple property for IsModal to return.
You could check the status of all other TLWs...

Let me get this straight. Say I have (pseudocode):

win1 = wx.Frame()
win2 = wx.Frame()
win3 = wx.Frame()

win1.Enable(False)

win3.SetModal()
win3.SetModal(False)

# At this point, will win1 be implicitly enabled again, # overriding my explicit win1.Enable(False) called previously?

Yes, it appears that way. And yes, I agree that it shoudln't. Please enter a bug report about it.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn writes:

Yes, it appears that way. And yes, I agree that it
shoudln't. Please enter a bug report about it.

I'll do that, but before I do, what do you think of wx.Dialog's
IsModal() and ShowModal() functions being moved to wx.Frame?

Now, I haven't really ever used those functions, nor have I
looked at the source code, but I've always thought it felt
wrong that those were defined in wx.Dialog and not more
generally.

And are there use-cases for making individual windows modal? I'm
thinking this is specifically frame-level functionality, not
window-level stuff.

···

--
Paul

Paul McNett wrote:

Robin Dunn writes:

Yes, it appears that way. And yes, I agree that it
shoudln't. Please enter a bug report about it.

I'll do that, but before I do, what do you think of wx.Dialog's IsModal() and ShowModal() functions being moved to wx.Frame?

Now, I haven't really ever used those functions, nor have I looked at the source code, but I've always thought it felt wrong that those were defined in wx.Dialog and not more generally.

IsModal probably could be, well, to wxTopLevelWindow anyway, (it's the base class of both wxDialog and wxFrame.) ShowModal implements it's own event loop and is very specific to wxDialog.

And are there use-cases for making individual windows modal? I'm thinking this is specifically frame-level functionality, not window-level stuff.

Yep, the current implementation of MakeModal does nothing if the window is not a top level window, so it could probably be moved to wxTopLevelWindow as well. It's not my call though.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn writes:

> Now, I haven't really ever used those functions, nor have I
> looked at the source code, but I've always thought it felt
> wrong that those were defined in wx.Dialog and not more
> generally.

IsModal probably could be, well, to wxTopLevelWindow anyway,
(it's the base class of both wxDialog and wxFrame.)
ShowModal implements it's own event loop and is very
specific to wxDialog.

But that is exactly what a modal frame should do: implement its
own event loop. Shouldn't it?

Perhaps I should just be basing my frames on wxDialog instead of
wxFrame, to take advantage of the modal event loop
capabilities.

> And are there use-cases for making individual windows
> modal? I'm thinking this is specifically frame-level
> functionality, not window-level stuff.

Yep, the current implementation of MakeModal does nothing if
the window is not a top level window, so it could probably be
moved to wxTopLevelWindow as well. It's not my call though.

Ok, this is the wrong forum to be discussing this stuff, but
perhaps if it comes up in your discussions with the wxWidgets
hackers you could be an advocate for these changes (getting rid
of MakeModal and making ShowModal and IsModal functions of
wxTopLevelWindow - I'm sure the wxDialog-specific stuff can be
carved out.).

I submitted something on this as a 'feature request' already.

···

--
Paul

I'm having trouble saving a bitmap on Windows using wxPython 2.5.1.5.

I have code that worked under wxPython 2.4.2.4 that draws a waveform diagram
and saves it as a bitmap file. I am in the process of trying to upgrade to
wxPython 2.5.1.5, as I am trying to develop on Windows and Mac OS/X
simultaneously. I have updated my code, changing all of my DrawLine methods
to DrawLineXY, and the code works fine on the Mac. However, the SaveFile
command dies on Windows (Win2K).

For example, If I run:

  print 'WaveformGraphic: About to save Bitmap "%s"' % waveformFilename
  theBitmap.SaveFile(waveformFilename, wx.BITMAP_TYPE_BMP)
  print "WaveformGraphic: Bitmap saved"

the second print statement is never executed, and the bitmap file that is
created crashes my system if I try to look at it, taking 100% of my
processing time until I reboot and complaining of sharing violations if I
try to delete it.

If I use:

  print 'WaveformGraphic: About to save JPEG "%s"' %
(waveformFilename[:-3]+'jpg')
  theBitmap.SaveFile(waveformFilename[:-3]+'jpg', wx.BITMAP_TYPE_JPEG)
  print "WaveformGraphic: JPEG saved"

instead, I get the JPEG graphic I expect.

Has anybody else run into this problem? Any ideas what I can do to work
around it, other than using JPEGs intead of Bitmaps?

Thanks,
David Woods, Ph.D.
Wisconsin Center for Education Research
University of Wisconsin, Madison
http://www.transana.org

David Woods wrote:
[...]

For example, If I run:

  print 'WaveformGraphic: About to save Bitmap "%s"' % waveformFilename
  theBitmap.SaveFile(waveformFilename, wx.BITMAP_TYPE_BMP)
  print "WaveformGraphic: Bitmap saved"

the second print statement is never executed,

Is there any exception?

and the bitmap file that is
created crashes my system if I try to look at it, taking 100% of my
processing time until I reboot and complaining of sharing violations if I
try to delete it.

If I use:

  print 'WaveformGraphic: About to save JPEG "%s"' %
(waveformFilename[:-3]+'jpg')
  theBitmap.SaveFile(waveformFilename[:-3]+'jpg', wx.BITMAP_TYPE_JPEG)
  print "WaveformGraphic: JPEG saved"

instead, I get the JPEG graphic I expect.

Has anybody else run into this problem?

Please enter a bug report about it.

Any ideas what I can do to work
around it, other than using JPEGs intead of Bitmaps?

Have you tried converting the wx.Bitmap to a wx.Image and then saving it
from there? That may work.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!