By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,934 Members | 1,366 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,934 IT Pros & Developers. It's quick & easy.

wxpython dialog - do something after ShowModal()?

P: n/a
Hi. I have a modal dialog whcih has a "Browse..." button which pops
up a file selector. This all works fine, but the first thing the user
has to do when they open the dialog is select a file, so I would like
the dialog to automatically call the onBrowse function as soon as the
dialog opens. However, I don't know how to do this.

dlg.ShowModal()
onBrowse()

obviously doesn't work, and neither does the reverse. I was hoping
that the dialog would throw some kind of "I have been shown" event,
but it doesn't (as far as I can tell). How do I make the dialog do
something as soon as it's been shown?

Iain
Jun 27 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Iain King wrote:
Hi. I have a modal dialog whcih has a "Browse..." button which pops
up a file selector. This all works fine, but the first thing the user
has to do when they open the dialog is select a file, so I would like
the dialog to automatically call the onBrowse function as soon as the
dialog opens. However, I don't know how to do this.

dlg.ShowModal()
onBrowse()

obviously doesn't work, and neither does the reverse. I was hoping
that the dialog would throw some kind of "I have been shown" event,
but it doesn't (as far as I can tell). How do I make the dialog do
something as soon as it's been shown?

Iain
If the only things on your modal dialog are Browse and cancel, just call the
wx.FileDialog directly and eliminate the intermediate modal dialog. If not
don't bind the FileDialog to a button, just create an instance of it as the last
you do in the __init__ method of the modal dialog code.

If this doesn't help, you will have better luck posting to wxpython newsgroup.

-Larry
Jun 27 '08 #2

P: n/a
On May 13, 2:20 pm, Larry Bates <larry.ba...@websafe.com`wrote:
Iain King wrote:
Hi. I have a modal dialog whcih has a "Browse..." button which pops
up a file selector. This all works fine, but the first thing the user
has to do when they open the dialog is select a file, so I would like
the dialog to automatically call the onBrowse function as soon as the
dialog opens. However, I don't know how to do this.
dlg.ShowModal()
onBrowse()
obviously doesn't work, and neither does the reverse. I was hoping
that the dialog would throw some kind of "I have been shown" event,
but it doesn't (as far as I can tell). How do I make the dialog do
something as soon as it's been shown?
Iain

If the only things on your modal dialog are Browse and cancel, just call the
wx.FileDialog directly and eliminate the intermediate modal dialog. If not
don't bind the FileDialog to a button, just create an instance of it as the last
you do in the __init__ method of the modal dialog code.

If this doesn't help, you will have better luck posting to wxpython newsgroup.

-Larry
The dialog doesn't only let you call the file dialog, it does other
stuff too. Your suggestion of __init__ sounded promising, but neither
giving the dialog an __init__() method nor an OnInit() method worked.
Thanks anyway.

Iain
Jun 27 '08 #3

P: n/a
On May 13, 2:43 pm, Iain King <iaink...@gmail.comwrote:
On May 13, 2:20 pm, Larry Bates <larry.ba...@websafe.com`wrote:
Iain King wrote:
Hi. I have a modal dialog whcih has a "Browse..." button which pops
up a file selector. This all works fine, but the first thing the user
has to do when they open the dialog is select a file, so I would like
the dialog to automatically call the onBrowse function as soon as the
dialog opens. However, I don't know how to do this.
dlg.ShowModal()
onBrowse()
obviously doesn't work, and neither does the reverse. I was hoping
that the dialog would throw some kind of "I have been shown" event,
but it doesn't (as far as I can tell). How do I make the dialog do
something as soon as it's been shown?
Iain
If the only things on your modal dialog are Browse and cancel, just call the
wx.FileDialog directly and eliminate the intermediate modal dialog. If not
don't bind the FileDialog to a button, just create an instance of it as the last
you do in the __init__ method of the modal dialog code.
If this doesn't help, you will have better luck posting to wxpython newsgroup.
-Larry

The dialog doesn't only let you call the file dialog, it does other
stuff too. Your suggestion of __init__ sounded promising, but neither
giving the dialog an __init__() method nor an OnInit() method worked.
Thanks anyway.

Iain
After having a hunt through the wxpython mailing list archives I found
the answer: the event is EVT_INIT_DIALOG:

dlg.Bind(wx.EVT_INIT_DIALOG, onInit, dlg)

work. Thanks for the pointer.

Iain
Jun 27 '08 #4

P: n/a
En Tue, 13 May 2008 09:41:25 -0300, Iain King <ia******@gmail.com>
escribió:
Hi. I have a modal dialog whcih has a "Browse..." button which pops
up a file selector. This all works fine, but the first thing the user
has to do when they open the dialog is select a file, so I would like
the dialog to automatically call the onBrowse function as soon as the
dialog opens. However, I don't know how to do this.
I've seen you already answered your question. But are you sure that doing
this is a good thing? If you try to be too clever or too helpful the
interfase may become annoying at some times. You can't guess the user's
intention or read his mind.
By example, what if I already have the desired file name copied in the
clipboard? I don't want the file selector to pop up.

I completely *hate* Windows programs with a "Browse for folder" button
that don't let me paste a name, neither start opened at the currently
selected folder.

--
Gabriel Genellina

Jun 27 '08 #5

P: n/a
In article
<a1**********************************@m44g2000hsc. googlegroups.com>,
Iain King <ia******@gmail.comwrote:
Hi. I have a modal dialog whcih has a "Browse..." button which pops
up a file selector. This all works fine, but the first thing the user
has to do when they open the dialog is select a file, so I would like
the dialog to automatically call the onBrowse function as soon as the
dialog opens. However, I don't know how to do this.

dlg.ShowModal()
onBrowse()

obviously doesn't work, and neither does the reverse. I was hoping
that the dialog would throw some kind of "I have been shown" event,
but it doesn't (as far as I can tell). How do I make the dialog do
something as soon as it's been shown?
It's too bad that you found an answer. You _shouldn't_ have your
dialog pop up a file-selection box as soon as it's shown! That's
not the way dialogs usually work, so you're going to confuse
people.

Instead, first pop up the file-selection box, and then pop up
the dialog (without the Browse button) to do whatever else it
does after you've got the filename.
Iain
Jun 27 '08 #6

P: n/a
On May 14, 9:37 pm, "David C. Ullrich" <dullr...@sprynet.comwrote:
In article
<a14c2400-e88b-4d90-80bb-a5fe27fed...@m44g2000hsc.googlegroups.com>,
Iain King <iaink...@gmail.comwrote:
Hi. I have a modal dialog whcih has a "Browse..." button which pops
up a file selector. This all works fine, but the first thing the user
has to do when they open the dialog is select a file, so I would like
the dialog to automatically call the onBrowse function as soon as the
dialog opens. However, I don't know how to do this.
dlg.ShowModal()
onBrowse()
obviously doesn't work, and neither does the reverse. I was hoping
that the dialog would throw some kind of "I have been shown" event,
but it doesn't (as far as I can tell). How do I make the dialog do
something as soon as it's been shown?

It's too bad that you found an answer. You _shouldn't_ have your
dialog pop up a file-selection box as soon as it's shown! That's
not the way dialogs usually work, so you're going to confuse
people.

Instead, first pop up the file-selection box, and then pop up
the dialog (without the Browse button) to do whatever else it
does after you've got the filename.
That's actually what happens - the dialog throws EVT_INIT_DIALOG
before it displays itself. Not that I really agree with you. I don't
think that a "do such-and-such dialog" appearing with a "Select file
for such-and-such" file selector on top of it, the file selector being
in focus, is confusing for the user. Actually, I think it'd be
friendlier - the user can see where the data from the file is going,
so has an immediate reminder of what the (generic) file selector is
for.
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.