Mercurial > libervia-backend
annotate frontends/src/wix/gateways.py @ 760:73a0077f80cc
backend, frontends: XMLUI refactoring:
- session_id is resent in result data if found in incoming data
- list now use distinct labels and values (label is the one displayed, value is the one used for everything else)
- misc refactoring
/!\ urwid SàtExt must be updated ! /!\
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 24 Dec 2013 15:19:18 +0100 |
parents | 84a6e83157c2 |
children | bfabeedbf32e |
rev | line source |
---|---|
28 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
4 # wix: a SAT frontend |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) |
28 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
10 # (at your option) any later version. |
28 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
15 # GNU Affero General Public License for more details. |
28 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
28 | 19 |
20 | |
21 | |
22 import wx | |
23 import pdb | |
24 from xml.dom import minidom | |
25 from logging import debug, info, error | |
225
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
26 from sat.tools.jid import JID |
227 | 27 from sat_frontends.quick_frontend.quick_gateways import QuickGatewaysManager |
28 | 28 |
173 | 29 class GatewaysManager(wx.Frame,QuickGatewaysManager): |
28 | 30 |
70 | 31 def __init__(self, host, gateways, title=_("Gateways manager"), server=None): |
173 | 32 wx.Frame.__init__(self, None, title=title) |
33 QuickGatewaysManager.__init__(self, host, gateways, server) | |
28 | 34 |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
35 if server: |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
36 self.SetTitle(title+" (%s)" % server) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
37 |
29
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
38 #Fonts |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
39 self.normal_font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.NORMAL) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
40 self.bold_font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
41 self.italic_font = wx.Font(8, wx.DEFAULT, wx.FONTSTYLE_ITALIC, wx.NORMAL) |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
42 self.button_font = wx.Font(6, wx.DEFAULT, wx.NORMAL, wx.BOLD) |
29
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
43 |
28 | 44 |
45 self.modified = {} # dict of modified data (i.e. what we have to save) | |
46 self.ctl_list = {} # usefull to access ctrl, key = (name, category) | |
47 | |
48 self.sizer = wx.BoxSizer(wx.VERTICAL) | |
173 | 49 warning = wx.TextCtrl(self, -1, value=self.WARNING_MSG, style = wx.TE_MULTILINE | |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
50 wx.TE_READONLY | |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
51 wx.TE_LEFT) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
52 warning.SetFont(self.bold_font) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
53 self.sizer.Add(warning, 0, wx.EXPAND) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
54 warning.ShowPosition(0) |
28 | 55 self.panel = wx.Panel(self) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
56 self.panel.sizer = wx.FlexGridSizer(cols=5) |
28 | 57 self.panel.SetSizer(self.panel.sizer) |
58 self.panel.SetAutoLayout(True) | |
59 self.sizer.Add(self.panel, 1, flag=wx.EXPAND) | |
60 self.SetSizer(self.sizer) | |
61 self.SetAutoLayout(True) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
62 |
28 | 63 #events |
64 self.Bind(wx.EVT_CLOSE, self.onClose, self) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
65 |
28 | 66 self.MakeModal() |
29
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
67 self.panel.sizer.Add(wx.Window(self.panel, -1)) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
68 title_name = wx.StaticText(self.panel, -1, "Name") |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
69 title_name.SetFont(self.bold_font) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
70 title_type = wx.StaticText(self.panel, -1, "Type") |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
71 title_type.SetFont(self.bold_font) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
72 self.panel.sizer.Add(title_name) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
73 self.panel.sizer.Add(title_type) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
74 self.panel.sizer.Add(wx.Window(self.panel, -1)) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
75 self.panel.sizer.Add(wx.Window(self.panel, -1)) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
76 |
28 | 77 for gateway in gateways: |
78 self.addGateway(gateway, gateways[gateway]) | |
79 | |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
80 self.ext_server_panel = wx.Panel(self) |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
81 self.ext_server_panel.sizer = wx.BoxSizer(wx.HORIZONTAL) |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
82 self.ext_server_panel.SetSizer(self.ext_server_panel.sizer) |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
83 self.ext_server_panel.SetAutoLayout(True) |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
84 self.sizer.Add(self.ext_server_panel, 0, flag=wx.EXPAND) |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
85 |
70 | 86 ext_server_label = wx.StaticText(self.ext_server_panel, -1, _("Use external XMPP server: ")) |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
87 ext_server_label.SetFont(wx.ITALIC_FONT) |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
88 self.ext_server_text = wx.TextCtrl(self.ext_server_panel, -1) |
70 | 89 ext_server_button = wx.Button(self.ext_server_panel, -1, _("GO !")) |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
90 self.ext_server_panel.Bind(wx.EVT_BUTTON, self.browseExternalServer, ext_server_button) |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
91 |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
92 self.ext_server_panel.sizer.Add(ext_server_label) |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
93 self.ext_server_panel.sizer.Add(self.ext_server_text, 1, flag=wx.EXPAND) |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
94 self.ext_server_panel.sizer.Add(ext_server_button) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
95 |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
96 #self.panel.sizer.Fit(self) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
97 self.sizer.Fit(self) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
98 |
28 | 99 self.Show() |
100 | |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
101 def browseExternalServer(self, event): |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
102 """Open the gateway manager on given server""" |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
103 server = self.ext_server_text.GetValue() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
104 debug(_("Opening gateways manager on [%s]") % server) |
102 | 105 id = self.host.bridge.findGateways(server, self.host.profile) |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
106 self.host.current_action_ids.add(id) |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
107 self.host.current_action_ids_cb[id] = self.host.onGatewaysFound |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
108 self.MakeModal(False) |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
109 self.Destroy() |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
110 |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
111 |
28 | 112 def addGateway(self, gateway, param): |
113 | |
114 #First The icon | |
115 isz = (16,16) | |
116 im_icon = wx.StaticBitmap(self.panel, -1, wx.ArtProvider.GetBitmap(wx.ART_GO_FORWARD, wx.ART_TOOLBAR, isz)) | |
117 | |
29
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
118 #Then the name |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
119 |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
120 label=wx.StaticText(self.panel, -1, param['name']) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
121 label.SetFont(self.normal_font) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
122 |
28 | 123 #Then the transport type message |
173 | 124 type_label_txt = self.getGatewayDesc(param['type']) |
28 | 125 |
126 type_label = wx.StaticText(self.panel, -1, type_label_txt) | |
29
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
127 type_label.SetFont(self.italic_font) |
28 | 128 |
129 #The buttons | |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
130 def register_cb(event): |
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
131 """Called when register button is clicked""" |
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
132 gateway_jid = event.GetEventObject().gateway_jid |
102 | 133 id = self.host.bridge.in_band_register(gateway_jid, self.host.profile) |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
134 self.host.current_action_ids.add(id) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
135 self.MakeModal(False) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
136 self.Destroy() |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
137 |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
138 def unregister_cb(event): |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
139 """Called when unregister button is clicked""" |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
140 gateway_jid = event.GetEventObject().gateway_jid |
102 | 141 id = self.host.bridge.gatewayRegister("CANCEL",gateway_jid, None, self.host.profile) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
142 self.host.current_action_ids.add(id) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
143 self.MakeModal(False) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
144 self.Destroy() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
145 |
70 | 146 reg_button = wx.Button(self.panel, -1, _("Register"), size=wx.Size(-1, 8)) |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
147 reg_button.SetFont(self.button_font) |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
148 reg_button.gateway_jid = JID(gateway) |
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
149 self.panel.Bind(wx.EVT_BUTTON, register_cb, reg_button) |
70 | 150 unreg_button = wx.Button(self.panel, -1, _("Unregister"), size=wx.Size(-1, 8)) |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
151 unreg_button.SetFont(self.button_font) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
152 unreg_button.gateway_jid = JID(gateway) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
153 self.panel.Bind(wx.EVT_BUTTON, unregister_cb, unreg_button) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
154 |
29
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
155 self.panel.sizer.Add(im_icon) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
156 self.panel.sizer.Add(label) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
157 self.panel.sizer.Add(type_label) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
158 self.panel.sizer.Add(reg_button, 1, wx.EXPAND) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
159 self.panel.sizer.Add(unreg_button, 1, wx.EXPAND) |
28 | 160 |
161 | |
162 def onClose(self, event): | |
163 """Close event""" | |
70 | 164 debug(_("close")) |
28 | 165 self.MakeModal(False) |
166 event.Skip() | |
167 |