Pressing an gtkDialog OK button mulitple times has no effect.

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

Pressing an gtkDialog OK button mulitple times has no effect.

Mark Cooke-2
Hi,

Sorry if this may sound like a simple question, but I've just started
learning gtk/pygtk and still pretty sketchy.

I have a very small/basic app built using Glade, that has a gtk.Dialog
popup window (from a menu toolbar) that allows a user to enter some
details in a few text fields.

I'm then checking to see if they have clicked the OK button (by seeing
if the response is a gtk.RESPONSE_OK), and if they have check to see if
the fields contain the correct details, and if not display an error dialog.

The problem I'm having, is that once they has pressed the OK and if they
have missed any fields, and they then correct the missing fields,
pressing it a second time has no effect.

Is this the best way of dealing with this?


Thanks

Mark Cooke
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Reply | Threaded
Open this post in threaded view
|

Re: Pressing an gtkDialog OK button mulitple times has no effect.

dimitri pater - serpia
Hello,
I am not sure if this helps, but this is how I check missing fields (before submitting data to a database) using a gtkDialog:

    def submitDB(self, widget):
        while True:
            try:
                name = self.wTree.get_widget("entry1").get_text()
                age = self.wTree.get_widget("entry2").get_text()
                size = self.wTree.get_widget("entry3").get_text()
                assert name != ""
                assert age != ""
                assert size != ""
                dataUsr = name, age, size                
                sd = DBStuff.Eb_db(host, user, passwd, db)
                sd.subMit(dataUsr)
                break
            except AssertionError:
                self.wDialog = gtk.glade.XML("project2.glade", "dbWarningEmpty")
                close = self.wDialog.get_widget("dbWarningEmpty")
                response = close.run()
                if response == gtk.RESPONSE_CLOSE:
                    close.destroy()
                break
            except DBStuff.MySQLdb.IntegrityError:
                def callback():
                    self.wDialog = gtk.glade.XML("project2.glade", "dbWarningOverwrite")
                    close = self.wDialog.get_widget("dbWarningOverwrite")
                    response = close.run()
                    if response == gtk.RESPONSE_CANCEL:
                        close.destroy()
                    if response == gtk.RESPONSE_OK:
                        sd.delRow(name)
                        wd = DBStuff.Eb_db(host, user, passwd, db)
                        wd.subMit(dataUsr)
                        close.destroy()
                callback()
                break

bye,
Dimitri

On 6/3/05, Mark Cooke <[hidden email]> wrote:
Hi,

Sorry if this may sound like a simple question, but I've just started
learning gtk/pygtk and still pretty sketchy.

I have a very small/basic app built using Glade, that has a gtk.Dialog
popup window (from a menu toolbar) that allows a user to enter some
details in a few text fields.

I'm then checking to see if they have clicked the OK button (by seeing
if the response is a gtk.RESPONSE_OK), and if they have check to see if
the fields contain the correct details, and if not display an error dialog.

The problem I'm having, is that once they has pressed the OK and if they
have missed any fields, and they then correct the missing fields,
pressing it a second time has no effect.

Is this the best way of dealing with this?


Thanks

Mark Cooke
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



--
Please visit dimitri's website: www.serpia.com
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Reply | Threaded
Open this post in threaded view
|

Re: Pressing an gtkDialog OK button mulitple times has no effect.

Mark Cooke-2
dimitri pater wrote:
> Hello,
> I am not sure if this helps, but this is how I check missing fields
> (before submitting data to a database) using a gtkDialog:

<snip>

Kind of, I probably never made myself clear, checking the data if fine,
but I still have the dilemma, of if they have missed some fields out,
then clicked 'OK', I can bring up a warning box, but they cannot click
'OK' again in the popup box (once they have corrected the fields), as
this does not send the signal out, as it has already been sent.

Mark

_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Reply | Threaded
Open this post in threaded view
|

Re: Pressing an gtkDialog OK button mulitple times has no effect.

Mark Cooke-2
In reply to this post by dimitri pater - serpia
The way I have got it to work
(and this is probaly completely wrong and bad practice, as there should
only be ONE gtk.main() per application), is to rather than use
gtkDialog, create a new gtk.main() & new GtkWindow with all my fields in
and when they click 'OK', validate the fields, and once the fields have
all be completed, run gtk.main_quit() to remove this the new window, so
this does not affect the parent window.

Mark
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Reply | Threaded
Open this post in threaded view
|

Re: Pressing an gtkDialog OK button mulitple times has no effect.

dimitri pater - serpia
mmh, this doesn't sound very "elegant", but if it works: don't break it.
Maybe someone comes up with a better solution. I'm pretty new to PyGtk myself to be honest.

greetz,
Dimitri

On 6/3/05, Mark Cooke <[hidden email]> wrote:
The way I have got it to work
(and this is probaly completely wrong and bad practice, as there should
only be ONE gtk.main() per application), is to rather than use
gtkDialog, create a new gtk.main() & new GtkWindow with all my fields in
and when they click 'OK', validate the fields, and once the fields have
all be completed, run gtk.main_quit() to remove this the new window, so
this does not affect the parent window.

Mark
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



--
Please visit dimitri's website: www.serpia.com
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Reply | Threaded
Open this post in threaded view
|

Re: Pressing an gtkDialog OK button mulitple times has no effect.

Mark Cooke-2
dimitri pater wrote:
> mmh, this doesn't sound very "elegant", but if it works: don't break it.
> Maybe someone comes up with a better solution.

It's not and It doesn';t work, I forgot to run the app in a terminal to
see any output and there was  an errors, once I fixed the error, this
closed both windows :(

I'm now looking into using the set_sensative() option for the button,
setting this to True
and once all the fields have the correct text in, set the set_sensative
back to False, thus enabling the user to click the OK button (hopfully).

But again, being new to gtk, I'm trying several things,
/me hoping that using the code below works:

        while gtk.events_pending():
                gtk.main_iteration()
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Reply | Threaded
Open this post in threaded view
|

Re: Pressing an gtkDialog OK button mulitple times has no effect.

Michael Urman
In reply to this post by dimitri pater - serpia
On 6/2/05, dimitri pater <[hidden email]> wrote something like:
>              try: assert name != ""
>              except AssertionError:

I'd like to put forth a caution on the use of asserts for program
logic. If you run python with -O, the asserts are compiled out:

% echo "assert False" > assert.py
% python assert.py
Traceback (most recent call last):
  File "assert.py", line 1, in ?
    assert False
AssertionError
% python -O assert.py
%
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Reply | Threaded
Open this post in threaded view
|

Re: Pressing an gtkDialog OK button mulitple times has no effect.

Toshio Kuratomi
In reply to this post by Mark Cooke-2
I'm attaching some code from qa-assistant that I believe implements the
behaviour you're asking for.  Here's a summary:
- Create a dialog
- Loop until your dialog is filled out correctly
  + response = dialog.run()  # Get input to your dialog
  + Check that all exit conditions are satisfied
    * If so, exit the loop
    * If not, loop again
- Destroy the dialog

The important part is to realize you need to call dialog.run() each time
you want the user to fill out the dialog again.

-Toshio

_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

dialog.py (4K) Download Attachment
signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Pressing an gtkDialog OK button mulitple times has no effect.

Mark Cooke-2
Toshio Kuratomi wrote:

> The important part is to realize you need to call dialog.run() each time
> you want the user to fill out the dialog again.

I did think of this idea, but was not sure if that would recreate the
window again, after looking at the supplied code, I altered it and it
works perfectly.

Thanks a lot

Mark

_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Reply | Threaded
Open this post in threaded view
|

Re: Pressing an gtkDialog OK button mulitple times has no effect.

Doug Quale
In reply to this post by Mark Cooke-2
Mark Cooke <[hidden email]> writes:

> The problem I'm having, is that once they has pressed the OK and if
> they have missed any fields, and they then correct the missing fields,
> pressing it a second time has no effect.
>
> Is this the best way of dealing with this?

You already got a response to your question that I think works for
you, but I wanted to suggest another possiblity to consider: Don't let
the user click OK if there are missing fields.  Make the OK button
insensitive until all the required fields are valid.  This isn't
always possible or appropriate, but often I think it improves the UI.
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/