annotate frontends/wix/gateways.py @ 29:df3b0b5ac49e

Wix: gateways manager => better presentation
author Goffi <goffi@goffi.org>
date Tue, 08 Dec 2009 02:31:35 +0100
parents c2b131e4e262
children d6b613764dd7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
3
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
5 wix: a SAT frontend
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
7
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
12
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
17
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
21
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
22
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
23
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
24 import wx
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
25 import pdb
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from xml.dom import minidom
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from logging import debug, info, error
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from tools.jid import JID
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
29
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
30
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
31 class GatewaysManager(wx.Frame):
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
32 def __init__(self, host, gateways, title="Gateways manager"):
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
33 super(GatewaysManager, self).__init__(None, title=title)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
34
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
35 self.host = host
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
36 #self.gateways = gateways
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
37
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)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
42
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
43
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
44 self.modified = {} # dict of modified data (i.e. what we have to save)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.ctl_list = {} # usefull to access ctrl, key = (name, category)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
46
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.sizer = wx.BoxSizer(wx.VERTICAL)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
48 self.panel = wx.Panel(self)
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
49 self.panel.sizer = wx.FlexGridSizer(cols=4)
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self.panel.SetSizer(self.panel.sizer)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.panel.SetAutoLayout(True)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.sizer.Add(self.panel, 1, flag=wx.EXPAND)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.SetSizer(self.sizer)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self.SetAutoLayout(True)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
55
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
56 #events
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.Bind(wx.EVT_CLOSE, self.onClose, self)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
58
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self.MakeModal()
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
60 self.panel.sizer.Add(wx.Window(self.panel, -1))
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
61 title_name = wx.StaticText(self.panel, -1, "Name")
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
62 title_name.SetFont(self.bold_font)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
63 title_type = wx.StaticText(self.panel, -1, "Type")
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
64 title_type.SetFont(self.bold_font)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
65 self.panel.sizer.Add(title_name)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
66 self.panel.sizer.Add(title_type)
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
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
69 for gateway in gateways:
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
70 self.addGateway(gateway, gateways[gateway])
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
71
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
72
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
73 self.panel.sizer.Fit(self)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
74
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
75 self.Show()
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
76
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
77 def addGateway(self, gateway, param):
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
78
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
79
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
80
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
81 #First The icon
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
82 isz = (16,16)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
83 im_icon = wx.StaticBitmap(self.panel, -1, wx.ArtProvider.GetBitmap(wx.ART_GO_FORWARD, wx.ART_TOOLBAR, isz))
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
84
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
85 #Then the name
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
86
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
87 label=wx.StaticText(self.panel, -1, param['name'])
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
88 label.SetFont(self.normal_font)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
89
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
90 #Then the transport type message
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
91
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
92 type_label_txt = 'Unknown IM'
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
93
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
94 if param['type'] == 'irc':
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
95 type_label_txt = "Internet Relay Chat"
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
96 elif param['type'] == 'xmpp':
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
97 type_label_txt = "XMPP"
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
98 elif param['type'] == 'qq':
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
99 type_label_txt = "Tencent QQ"
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
100 elif param['type'] == 'simple':
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
101 type_label_txt = "SIP/SIMPLE"
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
102 elif param['type'] == 'icq':
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
103 type_label_txt = "ICQ"
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
104 elif param['type'] == 'yahoo':
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
105 type_label_txt = "Yahoo! Messenger"
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
106 elif param['type'] == 'gadu-gadu':
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
107 type_label_txt = "Gadu-Gadu"
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
108 elif param['type'] == 'aim':
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
109 type_label_txt = "AOL Instant Messenger"
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
110 elif param['type'] == 'msn':
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
111 type_label_txt = 'Windows Live Messenger'
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
112
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
113 type_label_txt = type_label_txt
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
114
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
115 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
116 type_label.SetFont(self.italic_font)
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
117
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
118 #The buttons
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
119 button_font = wx.Font(6, wx.DEFAULT, wx.NORMAL, wx.BOLD)
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
120 reg_button = wx.Button(self.panel, -1, "Register", size=wx.Size(-1, 8))
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
121 reg_button.SetFont(button_font)
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
122
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
123 self.panel.sizer.Add(im_icon)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
124 self.panel.sizer.Add(label)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
125 self.panel.sizer.Add(type_label)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
126 self.panel.sizer.Add(reg_button, 1, wx.EXPAND)
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
127
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
128
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
129 def onClose(self, event):
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
130 """Close event"""
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
131 debug("close")
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
132 #now we save the modifier params
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
133 self.MakeModal(False)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
134 event.Skip()
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
135