annotate frontends/wix/gateways.py @ 28:c2b131e4e262

wix: new gateways manager
author Goffi <goffi@goffi.org>
date Sun, 06 Dec 2009 13:27:54 +0100
parents
children df3b0b5ac49e
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
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
37
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
38 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
39 self.ctl_list = {} # usefull to access ctrl, key = (name, category)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
40
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
41 self.sizer = wx.BoxSizer(wx.VERTICAL)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
42 self.panel = wx.Panel(self)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
43 self.panel.sizer = wx.BoxSizer(wx.VERTICAL)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
44 self.panel.SetSizer(self.panel.sizer)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.panel.SetAutoLayout(True)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.sizer.Add(self.panel, 1, flag=wx.EXPAND)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.SetSizer(self.sizer)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
48 self.SetAutoLayout(True)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
49
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
50 #events
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.Bind(wx.EVT_CLOSE, self.onClose, self)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
52
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.MakeModal()
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
54
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
55 for gateway in gateways:
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self.addGateway(gateway, gateways[gateway])
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
57
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.panel.sizer.Fit(self)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
60
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
61 self.Show()
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
62
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
63 def addGateway(self, gateway, param):
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
64 sizer = wx.BoxSizer(wx.HORIZONTAL)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
65
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
66 bold_font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
67 italic_font = wx.Font(8, wx.DEFAULT, wx.FONTSTYLE_ITALIC, wx.NORMAL)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
68
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
69
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
70 #First The icon
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
71 isz = (16,16)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
72 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
73
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
74 #Then the transport type message
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
75
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
76 type_label_txt = 'Unknown IM'
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
77
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
78 if param['type'] == 'msn':
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
79 type_label_txt = 'Windows Live Messenger'
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 type_label_txt = " " + type_label_txt + " "
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
82
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
83 type_label = wx.StaticText(self.panel, -1, type_label_txt)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
84 type_label.SetFont(bold_font)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
85
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
86 #Then the name
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
87
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
88 label=wx.StaticText(self.panel, -1, '('+param['name']+')')
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
89 label.SetFont(italic_font)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
90
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
91 #The buttons
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
92 bold_font2 = wx.Font(6, wx.DEFAULT, wx.NORMAL, wx.BOLD)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
93 reg_button = wx.Button(self.panel, -1, "Register", size=wx.Size(-1, 8))
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
94 reg_button.SetFont(bold_font2)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
95
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
96 sizer.Add(im_icon)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
97 sizer.Add(type_label)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
98 sizer.Add(label, 1, wx.EXPAND)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
99 sizer.Add(reg_button, 1, wx.EXPAND)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
100 self.panel.sizer.Add(sizer, flag=wx.EXPAND)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
101
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
102
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
103 def onClose(self, event):
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
104 """Close event"""
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
105 debug("close")
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
106 #now we save the modifier params
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
107 self.MakeModal(False)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
108 event.Skip()
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
109