diff options
author | Yann Leboulanger <asterix@lagaule.org> | 2014-03-23 23:54:54 +0400 |
---|---|---|
committer | Yann Leboulanger <asterix@lagaule.org> | 2014-03-23 23:54:54 +0400 |
commit | fd6689838e4be84502b6a5975b9a5bed043cc88e (patch) | |
tree | 69f1ddcc2a729173194138ecc1cc7ae68e8a9acf /src/dialogs.py | |
parent | 0d869cb192f9af6f65255c3829929f03bafa8152 (diff) |
make buttons in dialog work
Diffstat (limited to 'src/dialogs.py')
-rw-r--r-- | src/dialogs.py | 77 |
1 files changed, 37 insertions, 40 deletions
diff --git a/src/dialogs.py b/src/dialogs.py index bec33f23f..17d0fc49b 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -1381,35 +1381,31 @@ class Dialog(Gtk.Dialog): self.vbox.set_spacing(12) self.set_resizable(False) - possible_responses = {Gtk.STOCK_OK: self.on_response_ok, - Gtk.STOCK_CANCEL: self.on_response_cancel} for stock, response in buttons: b = self.add_button(stock, response) - for response in possible_responses: - if stock == response: - b.connect('clicked', possible_responses[response]) - break if default is not None: self.set_default_response(default) else: self.set_default_response(buttons[-1][1]) - def on_response_ok(self, widget): - if self.user_response_ok: - if isinstance(self.user_response_ok, tuple): - self.user_response_ok[0](*self.user_response_ok[1:]) - else: - self.user_response_ok() - self.destroy() + self.connect('response', self.on_response) - def on_response_cancel(self, widget): - if self.user_response_cancel: - if isinstance(self.user_response_cancel, tuple): - self.user_response_cancel[0](*self.user_response_ok[1:]) - else: - self.user_response_cancel() - self.destroy() + def on_response(self, widget, response_id): + if response_id == Gtk.ResponseType.OK: + if self.user_response_ok: + if isinstance(self.user_response_ok, tuple): + self.user_response_ok[0](*self.user_response_ok[1:]) + else: + self.user_response_ok() + self.destroy() + elif response_id == Gtk.ResponseType.CANCEL: + if self.user_response_cancel: + if isinstance(self.user_response_cancel, tuple): + self.user_response_cancel[0](*self.user_response_ok[1:]) + else: + self.user_response_cancel() + self.destroy() def just_destroy(self, widget): self.destroy() @@ -1431,29 +1427,33 @@ class HigDialog(Gtk.MessageDialog): self.format_secondary_markup(sectext) buttons = self.action_area.get_children() - self.possible_responses = {Gtk.STOCK_OK: on_response_ok, - Gtk.STOCK_CANCEL: on_response_cancel, Gtk.STOCK_YES: on_response_yes, - Gtk.STOCK_NO: on_response_no} - for b in buttons: - for response in self.possible_responses: - if b.get_label() == response: - if not self.possible_responses[response]: - b.connect('clicked', self.just_destroy) - elif isinstance(self.possible_responses[response], tuple): - if len(self.possible_responses[response]) == 1: - b.connect('clicked', self.possible_responses[response][0]) - else: - b.connect('clicked', *self.possible_responses[response]) - else: - b.connect('clicked', self.possible_responses[response]) - break + self.possible_responses = {Gtk.ResponseType.OK: on_response_ok, + Gtk.ResponseType.CANCEL: on_response_cancel, + Gtk.ResponseType.YES: on_response_yes, + Gtk.ResponseType.NO: on_response_no} + self.connect('response', self.on_response) self.connect('destroy', self.on_dialog_destroy) + def on_response(self, dialog, response_id): + if not response_id in self.possible_responses: + return + if not self.possible_responses[response_id]: + self.destroy() + elif isinstance(self.possible_responses[response_id], tuple): + if len(self.possible_responses[response_id]) == 1: + self.possible_responses[response_id][0](dialog) + else: + self.possible_responses[response_id][0](dialog, + *self.possible_responses[response_id][1:]) + else: + self.possible_responses[response_id](dialog) + + def on_dialog_destroy(self, widget): if not self.call_cancel_on_destroy: return - cancel_handler = self.possible_responses[Gtk.STOCK_CANCEL] + cancel_handler = self.possible_responses[Gtk.ResponseType.CANCEL] if not cancel_handler: return False if isinstance(cancel_handler, tuple): @@ -1461,9 +1461,6 @@ class HigDialog(Gtk.MessageDialog): else: cancel_handler(None) - def just_destroy(self, widget): - self.destroy() - def popup(self): """ Show dialog |