I'm debugging a user experience bug in a PyGTK program (although the question will probably be applicable to GTK as well), and suddenly realized that the bug is 'triggered' depending on the user executing the program.
I reduced the issue to a very simple script in PyGTK:
import gtk
class PyApp(gtk.Window):
def __init__(self):
super(PyApp, self).__init__()
self.set_size_request(250, 100)
self.set_position(gtk.WIN_POS_CENTER)
self.connect("destroy", gtk.main_quit)
self.set_title("Message dialogs")
ques = gtk.Button("Question")
self.add(ques)
ques.connect("clicked", self.on_ques)
self.show_all()
def on_ques(self, widget):
md = gtk.MessageDialog(self,
gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION,
gtk.BUTTONS_YES_NO, "Are you sure to quit?")
md.run()
md.destroy()
PyApp()
gtk.main()
When I run this on my box as myself, I get this dialog:
Are you sure to quit?
<Yes> No
When I run this on my box as root, I get this dialog:
Are you sure to quit?
<No> Yes
Both users have the same .gtkrc-2.0 file, and I use KDE and don't have anything obvious GTK-related hidden directory in my homedir, so I can't understand where is that preference coming from.
Before someone suggest md.set_default_response(), that's not exactly what I want. I tried to set md.set_default_response(gtk.RESPONSE_YES) after creating the dialog, and yes, the 'Yes' button gets selected, but still the 'No' is printed on the left.
I'd like to understand where this behavior comes from, and try to fix it once for all.
Looking at the GTK+ C sources I finally found the answer.
It seems that the GNOME Human Interface Guidelines advocate the use of the affirmative button at the far right, but in platforms like Windows, the standard is affirmative first, so in widgets that have to deal with buttons you have a function called set_alternative_button_order() that rearrange the buttons in case a global setting called gtk-alternative-button-order is set to 1.
Then the second part of the answer is that KDE tries to mimic Windows. Knowing what I had to look for, I found another gtkrc-2.0 inside KDE, in /home/myuser/.kde/share/config/gtkrc-2.0:gtk-alternative-button-order = 1, in order to make the GTK applications running under KDE as similar as possible to the non-GTK ones.
That's why root had a different behavior, because I never ran KDE as root in my system and it had no such setting in the .kde/ directory.
The moral of the story is that you must set the default button in this type of dialogs, no matter what you get, or otherwise GTK will default to the first one, and this will lead to inconsistent behavior. In my case, in plain GTK the default answer for quitting the program was not to do it, but in Windows or KDE it was to exit.
I hope it's clear and this helps any programmer that has the same problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With