[chirp_devel] [PATCH] Set alternative button order on dialogboxes conforming with GNU guidelines. #8271
# HG changeset patch # User Kosta A. ve7kcy@gmail.com # Date 1610993502 28800 # Mon Jan 18 10:11:42 2021 -0800 # Node ID 7d96e985768fea578a7cef39209e755ff23a22bd # Parent 449b7221660c5de1a7b2a61ce8766083c645715c Set alternative button order on dialogboxes conforming with GNU guidelines. #8271
diff --git a/chirp/ui/clone.py b/chirp/ui/clone.py --- a/chirp/ui/clone.py +++ b/chirp/ui/clone.py @@ -45,7 +45,8 @@
class CloneSettingsDialog(gtk.Dialog): def __make_field(self, label, widget): - l = gtk.Label(label) + l = gtk.Label(label + ":") + l.set_alignment(1.0, 0.5) self.__table.attach(l, 0, 1, self.__row, self.__row+1) self.__table.attach(widget, 1, 2, self.__row, self.__row+1) self.__row += 1 @@ -151,14 +152,12 @@ gtk.STOCK_OK, gtk.RESPONSE_OK) gtk.Dialog.__init__(self, title, parent=parent, + buttons=buttons, flags=gtk.DIALOG_MODAL) + self.set_default_response(gtk.RESPONSE_OK) + self.set_alternative_button_order([gtk.RESPONSE_OK, + gtk.RESPONSE_CANCEL]) self.__make_ui(settings) - self.__cancel_button = self.add_button(gtk.STOCK_CANCEL, - gtk.RESPONSE_CANCEL) - self.__okay_button = self.add_button(gtk.STOCK_OK, - gtk.RESPONSE_OK) - self.__okay_button.grab_default() - self.__okay_button.grab_focus()
def run(self): r = gtk.Dialog.run(self) diff --git a/chirp/ui/importdialog.py b/chirp/ui/importdialog.py --- a/chirp/ui/importdialog.py +++ b/chirp/ui/importdialog.py @@ -578,12 +578,15 @@ ACTION = _("Import")
def __init__(self, src_radio, dst_radio, parent=None): + buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, + gtk.STOCK_OK, gtk.RESPONSE_OK) gtk.Dialog.__init__(self, - buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK, - gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL), + buttons=buttons, title=self.TITLE, parent=parent) - + self.set_default_response(gtk.RESPONSE_OK) + self.set_alternative_button_order([gtk.RESPONSE_OK, + gtk.RESPONSE_CANCEL]) self.col_import = 0 self.col_nloc = 1 self.col_oloc = 2 diff --git a/chirp/ui/inputdialog.py b/chirp/ui/inputdialog.py --- a/chirp/ui/inputdialog.py +++ b/chirp/ui/inputdialog.py @@ -33,6 +33,8 @@
self.label = gtk.Label() self.label.set_size_request(300, 100) + self.label.set_alignment(0.0, 0.5) + # pylint: disable-msg=E1101 self.vbox.pack_start(self.label, 1, 1, 0)
@@ -53,8 +55,13 @@ gtk.STOCK_OK, gtk.RESPONSE_OK) gtk.Dialog.__init__(self, buttons=buttons, **args)
+ self.set_default_response(gtk.RESPONSE_OK) + self.set_alternative_button_order([gtk.RESPONSE_OK, + gtk.RESPONSE_CANCEL]) + self.label = gtk.Label() self.label.set_size_request(300, 100) + self.label.set_alignment(0.0, 0.5) # pylint: disable-msg=E1101 self.vbox.pack_start(self.label, 1, 1, 0) self.label.show() @@ -69,8 +76,6 @@ self.vbox.pack_start(self.choice, 1, 1, 0) self.choice.show()
- self.set_default_response(gtk.RESPONSE_OK) -
class EditableChoiceDialog(ChoiceDialog): editable = True @@ -85,6 +90,7 @@ def __init__(self, exception, **args): gtk.MessageDialog.__init__(self, buttons=gtk.BUTTONS_OK, type=gtk.MESSAGE_ERROR, **args) + self.set_default_response(gtk.RESPONSE_OK) self.set_property("text", _("An error has occurred")) self.format_secondary_text(str(exception))
@@ -97,15 +103,17 @@
class FieldDialog(gtk.Dialog): - def __init__(self, **kwargs): - if "buttons" not in kwargs.keys(): - kwargs["buttons"] = (gtk.STOCK_OK, gtk.RESPONSE_OK, - gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) + def __init__(self, **args): + buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, + gtk.STOCK_OK, gtk.RESPONSE_OK) + + gtk.Dialog.__init__(self, buttons=buttons, **args) + + self.set_default_response(gtk.RESPONSE_OK) + self.set_alternative_button_order([gtk.RESPONSE_OK, + gtk.RESPONSE_CANCEL])
self.__fields = {} - self.set_default_response(gtk.RESPONSE_OK) - - gtk.Dialog.__init__(self, **kwargs)
def response(self, _): LOG.debug("Blocking response") @@ -114,7 +122,8 @@ def add_field(self, label, widget, validator=None): box = gtk.HBox(True, 2)
- lab = gtk.Label(label) + lab = gtk.Label(label + ":") + lab.set_alignment(1.0, 0.5) lab.show()
widget.set_size_request(150, -1) @@ -135,9 +144,12 @@
class OverwriteDialog(gtk.MessageDialog): def __init__(self, filename): - gtk.Dialog.__init__(self, - buttons=(_("Overwrite"), gtk.RESPONSE_OK, - gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) + + buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, + gtk.STOCK_OK, gtk.RESPONSE_OK) + gtk.Dialog.__init__(self, buttons=buttons) + self.set_alternative_button_order([gtk.RESPONSE_OK, + gtk.RESPONSE_CANCEL])
self.set_property("text", _("File Exists"))
@@ -146,12 +158,3 @@ "Do you want to overwrite it?").format(name=filename)
self.format_secondary_text(text) - -if __name__ == "__main__": - # pylint: disable-msg=C0103 - d = FieldDialog(buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK)) - d.add_field("Foo", gtk.Entry()) - d.add_field("Bar", make_choice(["A", "B"])) - d.run() - gtk.main() - d.destroy() diff --git a/chirp/ui/mainapp.py b/chirp/ui/mainapp.py --- a/chirp/ui/mainapp.py +++ b/chirp/ui/mainapp.py @@ -160,10 +160,14 @@ for i in range(0, self.tabs.get_n_pages()): esets.append(self.tabs.get_nth_page(i))
+ buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, + gtk.STOCK_OK, gtk.RESPONSE_OK) d = gtk.Dialog(title="Diff Radios", - buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK, - gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL), + buttons=buttons, parent=self) + d.set_default_response(gtk.RESPONSE_OK) + d.set_alternative_button_order([gtk.RESPONSE_OK, + gtk.RESPONSE_CANCEL])
label = gtk.Label("") label.set_markup("<b>-1</b> for either Mem # does a full-file hex " + @@ -295,9 +299,13 @@ lab.show() choice = miscwidgets.make_choice(sorted(radiolist.keys()), False, sorted(radiolist.keys())[0]) + buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, + gtk.STOCK_OK, gtk.RESPONSE_OK) d = gtk.Dialog(title="Detection Failed", - buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK, - gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) + buttons=buttons) + d.set_default_response(gtk.RESPONSE_OK) + d.set_alternative_button_order([gtk.RESPONSE_OK, + gtk.RESPONSE_CANCEL]) d.vbox.pack_start(lab, 0, 0, 0) d.vbox.pack_start(choice, 0, 0, 0) d.vbox.set_spacing(5) @@ -811,11 +819,16 @@ return False
if eset.is_modified(): + buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, + gtk.STOCK_NO, gtk.RESPONSE_NO, + gtk.STOCK_YES, gtk.RESPONSE_YES) dlg = miscwidgets.YesNoDialog( title=_("Save Changes?"), parent=self, - buttons=(gtk.STOCK_YES, gtk.RESPONSE_YES, - gtk.STOCK_NO, gtk.RESPONSE_NO, - gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) + buttons=buttons) + dlg.set_default_response(gtk.RESPONSE_YES) + dlg.set_alternative_button_order([gtk.RESPONSE_YES, + gtk.RESPONSE_NO, + gtk.RESPONSE_CANCEL]) dlg.set_text(_("File is modified, save changes before closing?")) res = dlg.run() dlg.destroy() @@ -1603,10 +1616,14 @@ radio_name = "%s %s %s" % (eset.rthread.radio.VENDOR, eset.rthread.radio.MODEL, eset.rthread.radio.VARIANT) + buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, + gtk.STOCK_OK, gtk.RESPONSE_OK) d = gtk.Dialog(title=_("Select Columns"), parent=self, - buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK, - gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) + buttons=buttons) + d.set_default_response(gtk.RESPONSE_OK) + d.set_alternative_button_order([gtk.RESPONSE_OK, + gtk.RESPONSE_CANCEL])
vbox = gtk.VBox() vbox.show() diff --git a/chirp/ui/memdetail.py b/chirp/ui/memdetail.py --- a/chirp/ui/memdetail.py +++ b/chirp/ui/memdetail.py @@ -176,7 +176,7 @@
def _add(self, tab, row, name, editor, text, colindex=0): label = gtk.Label(text + ":") - label.set_alignment(0.0, 0.5) + label.set_alignment(1.0, 0.5) label.show() tab.attach(label, colindex, colindex + 1, row, row + 1, xoptions=gtk.FILL, yoptions=0, xpadding=6, ypadding=3) @@ -288,12 +288,16 @@
def __init__(self, features, memory, parent=None): self._memory = memory + buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, + gtk.STOCK_OK, gtk.RESPONSE_OK) gtk.Dialog.__init__(self, title="Memory Properties", flags=gtk.DIALOG_MODAL, parent=parent, - buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK, - gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) + buttons=buttons) + self.set_default_response(gtk.RESPONSE_OK) + self.set_alternative_button_order([gtk.RESPONSE_OK, + gtk.RESPONSE_CANCEL]) self.set_size_request(-1, 500) self._tips = gtk.Tooltips()
diff --git a/chirp/ui/memedit.py b/chirp/ui/memedit.py --- a/chirp/ui/memedit.py +++ b/chirp/ui/memedit.py @@ -57,6 +57,7 @@ class ValueErrorDialog(gtk.MessageDialog): def __init__(self, exception, **args): gtk.MessageDialog.__init__(self, buttons=gtk.BUTTONS_OK, **args) + self.set_default_response(gtk.RESPONSE_OK) self.set_property("text", _("Invalid value for this field")) self.format_secondary_text(str(exception))
@@ -1471,20 +1472,27 @@ loc, filled = store.get(iter, self.col(_("Loc")), self.col("_filled")) if filled and not always: + buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, + gtk.STOCK_NO, gtk.RESPONSE_NO, + _("Yes to All"), gtk.RESPONSE_ACCEPT, + gtk.STOCK_YES, gtk.RESPONSE_YES) d = miscwidgets.YesNoDialog(title=_("Overwrite?"), - buttons=(gtk.STOCK_YES, 1, - gtk.STOCK_NO, 2, - gtk.STOCK_CANCEL, 3, - "All", 4)) + parent=None, + buttons=buttons) + d.set_default_response(gtk.RESPONSE_YES) + d.set_alternative_button_order([gtk.RESPONSE_YES, + gtk.RESPONSE_ACCEPT, + gtk.RESPONSE_NO, + gtk.RESPONSE_CANCEL]) d.set_text( _("Overwrite location {number}?").format(number=loc)) r = d.run() d.destroy() - if r == 4: + if r == gtk.RESPONSE_ACCEPT: always = True - elif r == 3: + elif r == gtk.RESPONSE_CANCEL: break - elif r == 2: + elif r == gtk.RESPONSE_NO: iter = store.iter_next(iter) continue
@@ -1502,16 +1510,20 @@ errs = [x for x in msgs if isinstance(x, chirp_common.ValidationError)] if errs: + buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, + gtk.STOCK_OK, gtk.RESPONSE_OK) d = miscwidgets.YesNoDialog(title=_("Incompatible Memory"), - buttons=(gtk.STOCK_OK, 1, - gtk.STOCK_CANCEL, 2)) + buttons=buttons) + d.set_default_response(gtk.RESPONSE_OK) + d.set_alternative_button_order([gtk.RESPONSE_OK, + gtk.RESPONSE_CANCEL]) d.set_text( _("Pasted memory {number} is not compatible with " "this radio because:").format(number=src_number) + os.linesep + os.linesep.join(msgs)) r = d.run() d.destroy() - if r == 2: + if r == gtk.RESPONSE_CANCEL: break else: iter = store.iter_next(iter) diff --git a/chirp/ui/miscwidgets.py b/chirp/ui/miscwidgets.py --- a/chirp/ui/miscwidgets.py +++ b/chirp/ui/miscwidgets.py @@ -603,9 +603,13 @@
class YesNoDialog(gtk.Dialog): def __init__(self, title="", parent=None, buttons=None): - gtk.Dialog.__init__(self, title=title, parent=parent, buttons=buttons) + gtk.Dialog.__init__(self, + title=title, + parent=parent, + buttons=buttons)
self._label = gtk.Label("") + self._label.set_alignment(0.0, 0.5) self._label.show()
# pylint: disable-msg=E1101 diff --git a/chirp/ui/settingsedit.py b/chirp/ui/settingsedit.py --- a/chirp/ui/settingsedit.py +++ b/chirp/ui/settingsedit.py @@ -135,7 +135,7 @@
# Label label = gtk.Label(element.get_shortname() + ":") - label.set_alignment(0.0, 0.5) + label.set_alignment(1.0, 0.5) label.show()
table.attach(label, 0, 1, row, row + 1, diff --git a/chirp/ui/shiftdialog.py b/chirp/ui/shiftdialog.py --- a/chirp/ui/shiftdialog.py +++ b/chirp/ui/shiftdialog.py @@ -26,10 +26,11 @@
class ShiftDialog(gtk.Dialog): def __init__(self, rthread, parent=None): + buttons = (gtk.STOCK_CLOSE, gtk.RESPONSE_OK) gtk.Dialog.__init__(self, title=_("Shift"), - buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_OK)) - + buttons=buttons) + self.set_default_response(gtk.RESPONSE_OK) self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
self.rthread = rthread
participants (1)
-
Kosta A.