Philipp Hörist pushed to branch master at gajim / gajim

Commits:
61ad7836 by Philipp Hörist at 2017-12-08T19:50:48+01:00
Add new interface to raise dialogs

- - - - -


2 changed files:

- + gajim/dialog_messages.py
- gajim/gui_interface.py


Changes:

=====================================
gajim/dialog_messages.py
=====================================
--- /dev/null
+++ b/gajim/dialog_messages.py
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2017 Philipp Hörist <philipp AT hoerist.com>
+#
+# This file is part of Gajim.
+#
+# Gajim is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Gajim is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
+
+from collections import namedtuple
+
+from gi.repository import GLib
+
+from gajim.common.app import app
+
+Message = namedtuple('Message', ['title', 'text', 'dialog'])
+
+messages = {}
+
+
+def get_dialog(name, *args, **kwargs):
+    message = messages.get(name, None)
+    if message is None:
+        raise ValueError('Dialog %s does not exist' % name)
+
+    # Set transient window
+    transient_for = kwargs.get('transient_for', None)
+    if transient_for is None:
+        transient_for = app.get_active_window()
+    else:
+        del kwargs['transient_for']
+
+    if args:
+        message_text = message.text % args
+    else:
+        message_text = message.text % kwargs
+    dialog = message.dialog(message.title,
+                            GLib.markup_escape_text(message_text),
+                            transient_for=transient_for)
+    return dialog


=====================================
gajim/gui_interface.py
=====================================
--- a/gajim/gui_interface.py
+++ b/gajim/gui_interface.py
@@ -67,6 +67,7 @@ from gajim import gui_menu_builder
 from gajim import dialogs
 from gajim import notify
 from gajim import message_control
+from gajim.dialog_messages import get_dialog
 
 from gajim.chat_control_base import ChatControlBase
 from gajim.chat_control import ChatControl
@@ -143,6 +144,10 @@ class Interface:
 
             cls(obj.pri_txt, GLib.markup_escape_text(obj.sec_txt))
 
+    @staticmethod
+    def raise_dialog(name, *args, **kwargs):
+        get_dialog(name, *args, **kwargs)
+
     def handle_ask_new_nick(self, account, room_jid, parent_win):
         title = _('Unable to join group chat')
         prompt = _('Your desired nickname in group chat\n'



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/commit/61ad783658266a6036dec0287136e34ee047bb2b

---
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/commit/61ad783658266a6036dec0287136e34ee047bb2b
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to