[wxPython] modeless wxDialog?

I want to create a modeless wxDialog box which nonetheless takes various actions when it closes. Which events do I have to capture and/or which handler functions should I override to do this?

If someone has a code example using a modeless dialog, that would be appreciated as well.

Thanks in advance,
David Fox

···

__________________________________________________________________
Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/

I want to create a modeless wxDialog box which nonetheless takes various

actions when it closes. Which events do I have to capture and/or which
handler functions should I override to do this?

A dialog shown with Show(true) instead of ShowModal() will be modeless. Use
EVT_CLOSE to catch when it closes just like frames.

···

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

> I want to create a modeless wxDialog box which nonetheless takes various
actions when it closes. Â Which events do I have to capture and/or which
handler functions should I override to do this?
>

A dialog shown with Show(true) instead of ShowModal() will be modeless. Â Use
EVT_CLOSE to catch when it closes just like frames.

Sorry, I don't think I made myself clear.

I define

class MyDialog(wxDialog)

and create OK and Cancel buttons.

The function I pass to EVT_CLOSE only gets called when
I click the system close button. However, the dialog box
also vanishes (through Show(0)?) when the OK or Cancel
buttons are clicked (assuming they are given the
standard IDs wxID_OK and wxID_CANCEL). I want
to do something in these cases as well.

I thought maybe I could override the Show method, but when
I do so, MyDialog.Show(self, value) only gets called with
value=1, never with value = 0.

I can use EVT_BUTTON(wxID_OK, func) to call func when the
OK button is clicked. Then func can take whatever action
I want and then call Show(0) explicitly (which DOES call
my Show method). I just thought there might be standard
way of doing this automatically.

Incidentally, the documentation seems to suggest that
wxDialog defines OnOK and OnCancel methods to call EndModal
(for a modal dialog) or SetReturnCode and Show(0) (for a
modeless dialog). wxDialog behaves as suggested by these
descriptions, but if I try to call them from my button handlers
I get an AttributeError. Do these methods exist in
wxWindows but not in wxPython? Or are they simply
examples of how the default behaviour could be mimicked by
a user-defined method?

David Fox

···

__________________________________________________________________
Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/

> I want to create a modeless wxDialog box which nonetheless takes various
actions when it closes. Which events do I have to capture and/or which
handler functions should I override to do this?
>

A dialog shown with Show(true) instead of ShowModal() will be modeless. Use
EVT_CLOSE to catch when it closes just like frames.

Sorry, I don't think I made myself clear.

I define

class MyDialog(wxDialog)

and create OK and Cancel buttons.

The function I pass to EVT_CLOSE only gets called when
I click the system close button. However, the dialog box
also vanishes (through Show(0)?) when the OK or Cancel
buttons are clicked (assuming they are given the
standard IDs wxID_OK and wxID_CANCEL). I want
to do something in these cases as well.

I thought maybe I could override the Show method, but when
I do so, MyDialog.Show(self, value) only gets called with
value=1, never with value = 0.

I can use EVT_BUTTON(wxID_OK, func) to call func when the
OK button is clicked. Then func can take whatever action
I want and then call Show(0) explicitly (which DOES call
my Show method). I just thought there might be standard
way of doing this automatically.

Incidentally, the documentation seems to suggest that
wxDialog defines OnOK and OnCancel methods to call EndModal
(for a modal dialog) or SetReturnCode and Show(0) (for a
modeless dialog). wxDialog behaves as suggested by these
descriptions, but if I try to call them from my button handlers
I get an AttributeError. Do these methods exist in
wxWindows but not in wxPython? Or are they simply
examples of how the default behaviour could be mimicked by
a user-defined method?

David Fox

···

__________________________________________________________________
Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/

Sorry, I don't think I made myself clear.

I define

class MyDialog(wxDialog)

and create OK and Cancel buttons.

The function I pass to EVT_CLOSE only gets called when
I click the system close button. However, the dialog box
also vanishes (through Show(0)?) when the OK or Cancel

Actually, in addition to a couple other things the default button handlers
call EndModal which sets the "return code" and then calls Show(FALSE).

buttons are clicked (assuming they are given the
standard IDs wxID_OK and wxID_CANCEL). I want
to do something in these cases as well.

I thought maybe I could override the Show method, but when
I do so, MyDialog.Show(self, value) only gets called with
value=1, never with value = 0.

Nope, search the archives for messages about "virtual methods" and learn why
most of them are not implemented for wxPython, (for C++ --> Python
overloading.)

I can use EVT_BUTTON(wxID_OK, func) to call func when the
OK button is clicked. Then func can take whatever action
I want and then call Show(0) explicitly (which DOES call
my Show method). I just thought there might be standard
way of doing this automatically.

Just call event.Skip() from your event handler and then return. When
control returns to the event table searcher it will then coninue to look for
a handler, eventually finding the default in wxDialog.

Incidentally, the documentation seems to suggest that
wxDialog defines OnOK and OnCancel methods to call EndModal
(for a modal dialog) or SetReturnCode and Show(0) (for a
modeless dialog). wxDialog behaves as suggested by these
descriptions, but if I try to call them from my button handlers
I get an AttributeError. Do these methods exist in
wxWindows but not in wxPython? Or are they simply
examples of how the default behaviour could be mimicked by
a user-defined method?

They are there but not exposed to wxPython since you're not supposed to be
calling parent class event handlers anyway. They're in the docs so there is
a place to describe default behaviour.

···

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

a similar but related topic:
I'm in the process of converting a module to work with a multithreaded app,
and in the process, all of the ShowModal()s have to go.
Alot of my dialogs are little alerts and such which use wxMessageDialog.
Rather than creating a bunch of new classes from scratch, I'd like to simply
use the wxMessageDialog but override the functions associated with wxID_OK
and wxID_CANCEL. Suggestions as to how to do this?

i.e.,

def OnOK(self, event):
    action to perform...
    self.Destroy()

or something similar??

thanks.
Steve

p.s. David, if you're in need of code to see how event handling with a
modeless dialog works (it's pretty easy though) - let me know: I have lots
of wxKarma to pay back here. :wink:

···

----- Original Message -----
From: Robin Dunn <robin@alldunn.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Thursday, April 12, 2001 7:32 PM
Subject: Re: [wxPython] modeless wxDialog?

> I want to create a modeless wxDialog box which nonetheless takes various
actions when it closes. Which events do I have to capture and/or which
handler functions should I override to do this?
>

A dialog shown with Show(true) instead of ShowModal() will be modeless.

Use

EVT_CLOSE to catch when it closes just like frames.

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

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

If only I'd known what I was getting myself into with multithreading. :slight_smile:

So I've rewritten most of my app to get rid of ShowModals, but there are two
left that are looking like a pain to write from scratch, and they are:
wxFileDialog and wxHtmlEasyPrinting. plus all of the functionality, oh my.

Is the code for these dialogs readily available in the wx distro, because I
can't seem to find it for the widgets themselves.. (?)

Any other suggestions on getting around this problem would be really
helpful, but I'm sure I'm going to have to face the music here.

thanks.
Steve

Hi,

Steve A. wrote:

So I've rewritten most of my app to get rid of ShowModals, but
there are two left that are looking like a pain to write from
scratch, and they are: wxFileDialog and wxHtmlEasyPrinting. plus
all of the functionality, oh my.

Huh? What has wxHtmlEasyPrinting to do with dialogs and/or modality?

Is the code for these dialogs readily available in the wx distro,
because I can't seem to find it for the widgets themselves.. (?)

Huh? Of course everything is in the distro, nobody could compile it
otherwise...

VS

Huh? What has wxHtmlEasyPrinting to do with dialogs and/or modality?

wxHtmlEasyPrinting spits out a dialog that allows you to choose printing
preferences - it does it modally which breaks the program flow of the rest
of my app.

Huh? Of course everything is in the distro, nobody could compile it

otherwise...

dumb question on my part. what I meant to ask was: WHERE in the distro is
this code to be found because I'm not having luck figuring out where it is.

best,
Steve

···

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

If only I'd known what I was getting myself into with multithreading. :slight_smile:

So I've rewritten most of my app to get rid of ShowModals, but there are

two

left that are looking like a pain to write from scratch, and they are:
wxFileDialog and wxHtmlEasyPrinting. plus all of the functionality, oh

my.

Is the code for these dialogs readily available in the wx distro, because

I

can't seem to find it for the widgets themselves.. (?)

Yes, for the file dialog look in wx/src/generic/filedlg.cpp and the html
classes will be in wx/src/html. (With headers under wx/include/wx/generic
and wx/include/wx/html.)

Any other suggestions on getting around this problem would be really
helpful, but I'm sure I'm going to have to face the music here.

I'm wondering why your dialogs can't be modal? Do you relaly need to let
the user interact with other windows while the file dialog is shown?

···

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

I'm in the process of converting a module to work with a multithreaded

app,

and in the process, all of the ShowModal()s have to go.
Alot of my dialogs are little alerts and such which use wxMessageDialog.
Rather than creating a bunch of new classes from scratch, I'd like to

simply

use the wxMessageDialog but override the functions associated with wxID_OK
and wxID_CANCEL. Suggestions as to how to do this?

i.e.,

def OnOK(self, event):
    action to perform...
    self.Destroy()

or something similar??

Unfortunatly this problably won't work (on wxMSW at least) as the wx common
dialog classes are just wrappers around the common dialog win32 API
functions. There is no real wxWindow and there is no wx Event handling
happening. You'll have to make your own message dialog to do what you want.

p.s. David, if you're in need of code to see how event handling with a
modeless dialog works (it's pretty easy though) - let me know: I have lots
of wxKarma to pay back here. :wink:

One way you can balance your wxKarma by adding to the FAQ or Cookbook at
http://wxpython.org/cgi-bin/wiki

···

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

I'm wondering why your dialogs can't be modal? Do you relaly need to let
the user interact with other windows while the file dialog is shown?

Thank you very much (again). As per your question, the app I'm writing is
an instant-messaging/ conferencing program. Suppose that you're busy
transferring a file or have incoming 'events' that need to be displayed on
the main gui; at the same time you are trying to print out a list of
contacts. I'm thinking that the incoming events wouldn't show up until
after you've finished with the wxHtmlPrinting dialogs, etc. , and that this
would result in a very blocky environment. I would be thrilled to learn
otherwise though(!) :slight_smile:

Also, will ShowModal() break the flow of the gui only, or will other non-gui
network events in separate threads also be affected? (curious ).

best,
Stephen

I've given this whole problem some more thought.

What it seems to come down to is this: MOST of my dialogs would ideally be
shown using ShowModal(); however, a few of them should be deployed with
Show(true) so that you'd be able to interact with several windows at once (a
contact manager, a teleconferencing agent, a telnet client).

Thus, I'd have 3 or 4 main windows that should be able to run concurrently
with Show(true) and each of those should be able to produce dialogs with
ShowModal() that won't break the flow of any of the other main windows.

Is this possible with multithreading? If I create a child thread, will
ShowModal() dialogs spawned from the child interfere with the flow of the
parent?? Seems to me that I tried something like this on the first go-round
and kept getting GTK errors specific to multithreaded GUIs.

One way you can balance your wxKarma by adding to the FAQ or Cookbook at
http://wxpython.org/cgi-bin/wiki

btw (Robin), thanks for the link to wix-pee-wik-ee - I do have some
ListCtrl code that may make life a lot easier for others. I'll try to clean
it up and post it in the next couple weeks.

I'm thinking that the incoming events wouldn't show up until
after you've finished with the wxHtmlPrinting dialogs, etc. , and that

this

would result in a very blocky environment. I would be thrilled to learn
otherwise though(!) :slight_smile:

Also, will ShowModal() break the flow of the gui only, or will other

non-gui

network events in separate threads also be affected? (curious ).

ShowModal basicly just prevents other windows from being activated and
recieving focus. Other events still receive and process events (with one
exception**) For example, while you have a file dialog open, drag it over
other windows and you'll see that they get repainted, or in the demo start
the wxTimer demo and then go to one of the common dialog demos and you'll
see that timer events are still delivered and the log window is still
updated.

**The exception is that on Windows when using one of the win32 common dialog
wrappers (wxFileDialog, wxFontDialog, etc.) then the wxWindows idle time
events don't happen since the event loop is happening inside the win32 api
instead of in wx code. This does not seem so bad until you realize that
events delivered from alternate threads using wxPostEvent actually get
delivered in idle time. You can see this in the demo by starting the
Threads sample and then opening the wxFileDilaog sample. The threads are
still running but the events they send to the GUI are queueed until the file
dialog is dismissed. The good news however is that this only affects the
win32 common dialogs. When using dialogs derived from wxDialog that you
create yourself the events coming from wxPostEvent are processed normally.

···

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

I've given this whole problem some more thought.

What it seems to come down to is this: MOST of my dialogs would ideally be
shown using ShowModal(); however, a few of them should be deployed with
Show(true) so that you'd be able to interact with several windows at once

(a

contact manager, a teleconferencing agent, a telnet client).

Do they havbe to be dialogs? How about a wxFrame with a wxPanel within it
containing the controls?

Thus, I'd have 3 or 4 main windows that should be able to run concurrently
with Show(true) and each of those should be able to produce dialogs with
ShowModal() that won't break the flow of any of the other main windows.

I remember there being some discussion on wx-dev some time back about the
differences between doing app-modal and parent-modal dialogs. In other
words, does ShowModal block the whole app or does it just block the dialog's
parent(s) up to a top-level window. I don't remember what the resolution
was nor if it's possible to create both types of modality now... You might
want to hunt through the list archives:

    http://lists.wxwindows.org/search/

You can try this: Make your 3 or 4 Main windows be wxFrames with no parent
(None) and see what happens when one of them opens a wxDialog with the frame
as the parent.

Is this possible with multithreading? If I create a child thread, will
ShowModal() dialogs spawned from the child interfere with the flow of the
parent?? Seems to me that I tried something like this on the first

go-round

and kept getting GTK errors specific to multithreaded GUIs.

You can't do GUI stuff from alternate threads. (I suppose there should be
FAQ entries about this...)

All calls to methods of GUI objects and event handlers need to happen on the
main thread. In wxPython the main thread is the one that first imports the
wxPython.wx module. Other threads can send events to the main thread using
wxPostEvent as is done in the Threads sample in the wxPython demo.

···

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

I have a question about a design concept I have been toying with and I am
afraid I don't see all the nuances of its implementation using wxPython. I
hope that some one can give me some broad guide lines on this, including
whether the design is at all possible with wxPython.

I would like to develop a web application for document management
(imaging, workflow etc) which can be deployed either on an Intranet or as
as ASP app over the Internet. I am thinking of using Zope on the server
side and wxPython on the client side. Here are some of the requirements.

The client is to be very light weight with only some
networking/marshalling code. Most of the GUI objects live on the server in
their logical application objects. Based on the context of the user (e.g.
user vs. administrator) or the application (e.g. document storage vs.
retrieval or workflow que vs. workflow designer) the appropriate GUI
objects will be loaded from the server, only the first time OR if the
version has changed, registered with the client and the appropriate events
wired via a switchboard object to other required objects etc. The objects
can be pyc files and version info can be centralized in a database.

This way I can concentrate on the application on the server entirely and
also not worry about complex client side installs etc. Also down the road
if I choose to change the GUI representation of an object (say from a list
view to tree view) I can just do it on the server and all clients will
have it immediately.

I considered doing this with object serialization in Java and was a bit
taken aback when I saw the complexity of Java.

···

--
  .-. | Bakki Kudva__________________Open Source EDMS______
  oo> > Navaco ph: 814-833-2592
/`'\ | 420 Pasadena Drive fax: 603-947-5747
(\_;/) | Erie, PA 16505 http://www.navaco.com/

My company is working on a similar concept. I posted a message about it to
this list a month ago. Essentially we are building a sandbox client that
has an auto-updating capability as you describe. Our app is currently being
delivered to Internet Explorer, and the fundamental flaws in that client,
and the reliance on Microsoft, have caused us to begin creating our own
internet client. Please contact me if you wish to discuss this further.
I'd be pleased to hear anyone elses comments on this idea.

Joshua

···

----- Original Message -----
From: "Bakki Kudva" <bakki@navaco.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Monday, April 16, 2001 9:07 AM
Subject: [wxPython] Dynamic Gui

I have a question about a design concept I have been toying with and I am
afraid I don't see all the nuances of its implementation using wxPython. I
hope that some one can give me some broad guide lines on this, including
whether the design is at all possible with wxPython.

I would like to develop a web application for document management
(imaging, workflow etc) which can be deployed either on an Intranet or as
as ASP app over the Internet. I am thinking of using Zope on the server
side and wxPython on the client side. Here are some of the requirements.

The client is to be very light weight with only some
networking/marshalling code. Most of the GUI objects live on the server in
their logical application objects. Based on the context of the user (e.g.
user vs. administrator) or the application (e.g. document storage vs.
retrieval or workflow que vs. workflow designer) the appropriate GUI
objects will be loaded from the server, only the first time OR if the
version has changed, registered with the client and the appropriate events
wired via a switchboard object to other required objects etc. The objects
can be pyc files and version info can be centralized in a database.

This way I can concentrate on the application on the server entirely and
also not worry about complex client side installs etc. Also down the road
if I choose to change the GUI representation of an object (say from a list
view to tree view) I can just do it on the server and all clients will
have it immediately.

I considered doing this with object serialization in Java and was a bit
taken aback when I saw the complexity of Java.
--
  .-. | Bakki Kudva__________________Open Source EDMS______
  oo> > Navaco ph: 814-833-2592
/`'\ | 420 Pasadena Drive fax: 603-947-5747
(\_;/) | Erie, PA 16505 http://www.navaco.com/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

Do they have to be dialogs? How about a wxFrame with a wxPanel within it
containing the controls?

Actually, the main windows are wxFrames containing windows and controls. I got caught up
using "dialog" because I was changing all the dialogs associated with those main windows
to be modeless.

You can try this: Make your 3 or 4 Main windows be wxFrames with no parent
(None) and see what happens when one of them opens a wxDialog with the frame
as the parent.

Unfortuantely, the ShowModal() appears to block all windows up to the root window, even
when I call secondary windows with None as parent and 'self' as parent for their dialogs..

class MainWin()
   secondary_win = MyWin(None, -1, etc...)

class MyWin(blah blah blah)
   wxFrame.__init__(...)
   etc. etc.
   dialog = MyDlg(self, etc..)
   dialog.ShowModal()

dialog will block MainWIn...

Since I barely know a lick of C and no C++, it seems like the easiest way out of this dilemna
is to fork a process and open up the secondary window as its own app. Unfortunately, this
means I am going to have to poll for changes to shared files and update accordingly rather
than using the EVT system (which is fantastic, btw).

thanks for the (as always) generous reply.
-stephen

simple question, I think.

I'm giving the user to browse for an image file which when selected will
then be displayed. Right now, I'm using wxBitmap and it's set up to only
accept jpegs. I'd like to be able to set any of the major image filetypes
though dynamically: jpeg, gif, png, xpm, bitmap... is wxImage the way to
go with this, and is there a simple wxMethod for doing this, or will I need
to first use some if/else statements to determine image type?

thanks,
steve

simple question, I think.

Yep.

I'm giving the user to browse for an image file which when selected will
then be displayed. Right now, I'm using wxBitmap and it's set up to only
accept jpegs. I'd like to be able to set any of the major image filetypes
though dynamically: jpeg, gif, png, xpm, bitmap... is wxImage the way to
go with this, and is there a simple wxMethod for doing this, or will I

need

to first use some if/else statements to determine image type?

wxBitmap will fall back to wxImage if it needs to, so doing this should do
it for you:

    img = wxBitmap(file, wxBITMAP_TYPE_ANY)

and don't for get to call

    wxInitAllImageHandlers()

sometime at the begining of your program.

···

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