[pygtk] Dialog problem

Mattias Nilsson mattias.nilsson@privat.utfors.se
Thu, 13 Jul 2000 21:03:15 +0200


Hi, I have a problem with a dialog. It's similar to an other posting.
I'm interested either in getting a solution for the code below or an
other solution that accomplish the same.

The problem with the code below is that the dialog doesn't go away. If
it has been shown once and closed it pops up as soon as I try to push
one of the button even the button that does nothing!

If the two filenames are the same I want to stop the execution of the
following code until the user either accepts to overwrite or don't want
to overwrite the file.

Thanks
Mattias Nilsson
mattias.nilsson@privat.utfors.se


from gtk import *
from gnome.ui import *
from GDK import *


class App:
  def start(self, *args):
    #emulate input of two files with the same name
    filename1 = 'logo.jpg'
    filename2 = 'logo.jpg'

    overwrite = 0
    if filename1 == filename2:
      overwrite = GnomeMessageBox("Overwrite?", "question",
        STOCK_BUTTON_YES, STOCK_BUTTON_NO).run_and_close()
    if overwrite == 0:
      #this code have to wait to be run if the filenames are the same
      #or run at once if they aren't the same
      print 'doing file conversion'
    else:
      #this code or perhaps no code should be run if the user don't want

      # to overwrite the file.
      print 'doing nothing'

  def main(self):
    main_window = GnomeApp()
    main_window.connect('delete_event', mainquit)
    main_window.show()

    hbox = GtkHBox()
    hbox.show()
    main_window.add(hbox)

    button = GtkButton('Start')
    button.connect('pressed', self.start)
    button.show()
    hbox.add(button)

    button2 = GtkButton('nothing')
    button2.show()
    hbox.add(button2)

    mainloop()

if __name__=='__main__':
  app = App()
  app.main()