Why do the default button order and button change when a user runs PyGTK / GTK?

I am debugging a user error in PyGTK (although the question is probably applicable to GTK as well), and I suddenly realized that the error is "triggered" depending on the user running the program.

I reduced the problem 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 inbox like me, I get this dialog:

 Are you sure to quit? <Yes> No 

When I run this in my inbox 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 hidden directory related to GTK in my homedir, so I can't figure out where this preference comes from.

Before anyone suggests md.set_default_response (), this is not quite what I want. I tried to set md.set_default_response (gtk.RESPONSE_YES) after creating the dialog, and yes, the "Yes" button will be selected, but still, "No" will be printed on the left.

I would like to understand where this comes from and try to fix it once for everyone.

+6
source share
1 answer

Looking at the sources of GTK + C, I finally found the answer.

It seems that the GNOME Human Interface Guidelines protects the use of the affirmative button in the far right corner, but on platforms like Windows, the standard is primary, so in widgets that have to deal with buttons, you have the set_alternative_button_order () function that rearrange the buttons in in case the global setting called gtk-alternative-button-order is set to 1.

Then the second part of the answer is that KDE is trying to mimic Windows. Knowing what I had to search, I found another gtkrc-2.0 inside KDE in /home/myuser/.kde/share/config/gtkrc-2.0:gtk-alternative-button-order = 1 to make GTK applications working under KDE, as similar as possible to non-GTK.

That's why root had a different behavior, because I had never run KDE as root on my system, and it didn't have that setting in the .kde / directory.

The moral of the story is that you should set the default button in this type of dialog, no matter what you get, or else GTK will be the first by default, and this will lead to inconsistent behavior. In my case, in the usual GTK, the default for refusing the program was not to do this, but in Windows or KDE it had to exit.

I hope this is clear, and it helps any programmer who has the same problem.

+7
source

Source: https://habr.com/ru/post/917572/


All Articles