Philipp Hörist pushed to branch master at gajim / gajim
Commits: ca037665 by Philipp Hörist at 2019-03-26T20:55:51Z Remove unused imports
- - - - - bbada2ec by Philipp Hörist at 2019-03-26T22:49:45Z Improve NewConfirmationDialog
- Add setting for modal/non-modal - Add default transient - Dont call run() it only returns after response
- - - - - 4c062bf9 by Philipp Hörist at 2019-03-26T22:53:12Z Call show() on new dialogs
- run() was removed from the dialog because it blocks
- - - - - 760b94f2 by Philipp Hörist at 2019-03-26T23:14:00Z Add NewConfirmationCheckDialog
- - - - -
4 changed files:
- gajim/gtk/dialogs.py - gajim/gtk/themes.py - gajim/history_manager.py - gajim/roster_window.py
Changes:
===================================== gajim/gtk/dialogs.py ===================================== @@ -15,6 +15,7 @@ from collections import namedtuple
from gi.repository import Gtk +from gi.repository import Pango
from gajim.common import app from gajim.common import helpers @@ -53,6 +54,11 @@ class DialogButton(namedtuple('DialogButton', ('response text callback args ' default_kwargs['response'] = Gtk.ResponseType.OK default_kwargs['text'] = _('Delete') default_kwargs['action'] = ButtonAction.DESTRUCTIVE + + elif type_ == 'Remove': + default_kwargs['response'] = Gtk.ResponseType.OK + default_kwargs['text'] = _('Remove') + default_kwargs['action'] = ButtonAction.DESTRUCTIVE else: raise ValueError('Unknown button type: %s ' % type_)
@@ -990,12 +996,16 @@ class ChangePasswordDialog(Gtk.Dialog):
class NewConfirmationDialog(Gtk.MessageDialog): - def __init__(self, title, text, sec_text, buttons, transient_for=None): + def __init__(self, title, text, sec_text, buttons, + modal=True, transient_for=None): + if transient_for is None: + transient_for = app.app.get_active_window() Gtk.MessageDialog.__init__(self, title=title, text=text, transient_for=transient_for, - message_type=Gtk.MessageType.QUESTION) + message_type=Gtk.MessageType.QUESTION, + modal=modal)
self._buttons = {}
@@ -1012,8 +1022,6 @@ class NewConfirmationDialog(Gtk.MessageDialog):
self.connect('response', self._on_response)
- self.run() - def _on_response(self, _dialog, response): if response == Gtk.ResponseType.DELETE_EVENT: # Look if DELETE_EVENT is mapped to another response @@ -1031,6 +1039,40 @@ class NewConfirmationDialog(Gtk.MessageDialog): button.callback(*button.args, **button.kwargs) self.destroy()
+ def show(self): + self.show_all() + + +class NewConfirmationCheckDialog(NewConfirmationDialog): + def __init__(self, title, text, sec_text, check_text, + buttons, modal=True, transient_for=None): + NewConfirmationDialog.__init__(self, + title, + text, + sec_text, + buttons, + transient_for=transient_for, + modal=modal) + + self._checkbutton = Gtk.CheckButton.new_with_mnemonic(check_text) + self._checkbutton.set_can_focus(False) + self._checkbutton.set_margin_start(30) + self._checkbutton.set_margin_end(30) + label = self._checkbutton.get_child() + label.set_line_wrap(True) + label.set_max_width_chars(50) + label.set_halign(Gtk.Align.START) + label.set_line_wrap_mode(Pango.WrapMode.WORD) + label.set_margin_start(10) + + self.get_content_area().add(self._checkbutton) + + def _on_response(self, _dialog, response): + button = self._buttons.get(response) + if button is not None: + button.args.insert(0, self._checkbutton.get_active()) + super()._on_response(_dialog, response) +
class ShortcutsWindow: def __init__(self):
===================================== gajim/gtk/themes.py ===================================== @@ -24,7 +24,6 @@ from gajim.common import app from gajim.common.nec import NetworkEvent from gajim.common.i18n import _ from gajim.common.const import StyleAttr -from gajim.common.const import ButtonAction
from gajim.gtk.dialogs import ErrorDialog from gajim.gtk.dialogs import DialogButton @@ -326,7 +325,7 @@ class Themes(Gtk.ApplicationWindow): _('Do you want to permanently delete this theme?'), [DialogButton.make('Cancel'), DialogButton.make('Delete', callback=_remove_theme)], - transient_for=self) + transient_for=self).show()
@staticmethod def _on_destroy(*args):
===================================== gajim/history_manager.py ===================================== @@ -44,7 +44,6 @@ from gi.repository import Gio from gi.repository import Pango
from gajim.common import app -from gajim.common import i18n from gajim.common import configpaths from gajim.common.i18n import _ from gajim.common.i18n import ngettext @@ -578,7 +577,7 @@ class HistoryManager: paths_len, liststore[list_of_paths[0]][0]), [DialogButton.make('Cancel'), DialogButton.make('Delete', callback=on_ok)], - transient_for=self._ui.history_manager_window) + transient_for=self._ui.history_manager_window).show()
def _delete_logs(self, liststore, list_of_paths): paths_len = len(list_of_paths) @@ -615,7 +614,7 @@ class HistoryManager: paths_len), [DialogButton.make('Cancel'), DialogButton.make('Delete', callback=on_ok)], - transient_for=self._ui.history_manager_window) + transient_for=self._ui.history_manager_window).show()
def on_search_db_button_clicked(self, widget): text = self._ui.search_entry.get_text()
===================================== gajim/roster_window.py ===================================== @@ -71,6 +71,8 @@ from gajim.gtk.dialogs import InputDialog from gajim.gtk.dialogs import WarningDialog from gajim.gtk.dialogs import InformationDialog from gajim.gtk.dialogs import NonModalConfirmationDialog +from gajim.gtk.dialogs import NewConfirmationCheckDialog +from gajim.gtk.dialogs import DialogButton from gajim.gtk.join_groupchat import JoinGroupchatWindow from gajim.gtk.single_message import SingleMessageWindow from gajim.gtk.add_contact import AddNewContactWindow @@ -3347,7 +3349,7 @@ class RosterWindow: """ Remove a contact. list_ is a list of (contact, account) tuples """ - def on_ok(is_checked, list_): + def on_ok(is_checked): remove_auth = True if len(list_) == 1: contact = list_[0][0] @@ -3366,8 +3368,8 @@ class RosterWindow: contact.show = 'offline' app.contacts.add_contact(account, contact) self.add_contact(contact.jid, account) - def on_ok2(list_): - on_ok(False, list_) + def on_ok2(): + on_ok(False)
if len(list_) == 1: contact = list_[0][0] @@ -3380,19 +3382,22 @@ class RosterWindow: ConfirmationDialog(pritext, sectext + \ _('By removing this contact you also remove authorization ' 'resulting in them always seeing you as offline.'), - on_response_ok=(on_ok2, list_)) + on_response_ok=on_ok2) elif _('Not in Roster') in contact.get_shown_groups(): # Contact is not in roster ConfirmationDialog(pritext, sectext + \ - _('Do you want to continue?'), on_response_ok=(on_ok2, - list_)) + _('Do you want to continue?'), on_response_ok=on_ok2) else: - ConfirmationDialogCheck(pritext, sectext + \ + NewConfirmationCheckDialog( + _('Remove'), + pritext, sectext + \ _('By removing this contact you also by default remove ' - 'authorization resulting in them always seeing you as' - ' offline.'), - _('I want this contact to know my status after removal'), - on_response_ok=(on_ok, list_)) + 'authorization resulting in them always seeing you as' + ' offline.'), + _('_I want this contact to know my status after removal'), + [DialogButton.make('Cancel'), + DialogButton.make('Remove', callback=on_ok)], + modal=False).show() else: # several contact to remove at the same time pritext = _('Contacts will be removed from your roster') @@ -3403,8 +3408,7 @@ class RosterWindow: sectext = _('By removing these contacts:%s\nyou also remove ' 'authorization resulting in them always seeing you as ' 'offline.') % jids - ConfirmationDialog(pritext, sectext, - on_response_ok=(on_ok2, list_)) + ConfirmationDialog(pritext, sectext, on_response_ok=on_ok2)
def on_send_custom_status(self, widget, contact_list, show, group=None): """
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/acd9f67d926e9c971aba82ef08cc2bfe1f...