annotate frontends/wix/main_window.py @ 0:c4bc297b82f0

sat: - first public release, initial commit
author goffi@necton2
date Sat, 29 Aug 2009 13:34:59 +0200
parents
children a06a151fc31f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 wix: a SAT frontend
goffi@necton2
parents:
diff changeset
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
goffi@necton2
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
goffi@necton2
parents:
diff changeset
16 GNU General Public License for more details.
goffi@necton2
parents:
diff changeset
17
goffi@necton2
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
21
goffi@necton2
parents:
diff changeset
22
goffi@necton2
parents:
diff changeset
23 import wx
goffi@necton2
parents:
diff changeset
24 from chat import Chat
goffi@necton2
parents:
diff changeset
25 from param import Param
goffi@necton2
parents:
diff changeset
26 import gobject
goffi@necton2
parents:
diff changeset
27 import os.path
goffi@necton2
parents:
diff changeset
28 import pdb
goffi@necton2
parents:
diff changeset
29 from tools.jid import JID
goffi@necton2
parents:
diff changeset
30 from logging import debug, info, error
goffi@necton2
parents:
diff changeset
31 from quick_frontend.quick_chat_list import QuickChatList
goffi@necton2
parents:
diff changeset
32 from quick_frontend.quick_contact_list import QuickContactList
goffi@necton2
parents:
diff changeset
33 from quick_frontend.quick_app import QuickApp
goffi@necton2
parents:
diff changeset
34
goffi@necton2
parents:
diff changeset
35
goffi@necton2
parents:
diff changeset
36 msgOFFLINE = "offline"
goffi@necton2
parents:
diff changeset
37 msgONLINE = "online"
goffi@necton2
parents:
diff changeset
38 idCONNECT = 1
goffi@necton2
parents:
diff changeset
39 idEXIT = 2
goffi@necton2
parents:
diff changeset
40 idPARAM = 3
goffi@necton2
parents:
diff changeset
41 idADD_CONTACT = 4
goffi@necton2
parents:
diff changeset
42 idREMOVE_CONTACT = 5
goffi@necton2
parents:
diff changeset
43 const_DEFAULT_GROUP = "Unclassed"
goffi@necton2
parents:
diff changeset
44 const_STATUS = {"Online":"",
goffi@necton2
parents:
diff changeset
45 "Want to discuss":"chat",
goffi@necton2
parents:
diff changeset
46 "AFK":"away",
goffi@necton2
parents:
diff changeset
47 "Do Not Disturb":"dnd",
goffi@necton2
parents:
diff changeset
48 "Away":"xa"}
goffi@necton2
parents:
diff changeset
49
goffi@necton2
parents:
diff changeset
50 class ChatList(QuickChatList):
goffi@necton2
parents:
diff changeset
51 """This class manage the list of chat windows"""
goffi@necton2
parents:
diff changeset
52
goffi@necton2
parents:
diff changeset
53 def __init__(self, host):
goffi@necton2
parents:
diff changeset
54 QuickChatList.__init__(self, host)
goffi@necton2
parents:
diff changeset
55
goffi@necton2
parents:
diff changeset
56 def createChat(self, name):
goffi@necton2
parents:
diff changeset
57 return Chat(name, self.host)
goffi@necton2
parents:
diff changeset
58
goffi@necton2
parents:
diff changeset
59
goffi@necton2
parents:
diff changeset
60
goffi@necton2
parents:
diff changeset
61 class ContactList(wx.TreeCtrl, QuickContactList):
goffi@necton2
parents:
diff changeset
62 """Customized control to manage contacts."""
goffi@necton2
parents:
diff changeset
63
goffi@necton2
parents:
diff changeset
64 def __init__(self, parent):
goffi@necton2
parents:
diff changeset
65 wx.TreeCtrl.__init__(self, parent, style = wx.TR_HIDE_ROOT | wx.TR_HAS_BUTTONS)
goffi@necton2
parents:
diff changeset
66 QuickContactList.__init__(self)
goffi@necton2
parents:
diff changeset
67 self.jid_ids={}
goffi@necton2
parents:
diff changeset
68 self.groups={}
goffi@necton2
parents:
diff changeset
69 self.root=self.AddRoot("")
goffi@necton2
parents:
diff changeset
70 self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.onActivated, self)
goffi@necton2
parents:
diff changeset
71
goffi@necton2
parents:
diff changeset
72 #icons
goffi@necton2
parents:
diff changeset
73 isz = (16,16)
goffi@necton2
parents:
diff changeset
74 il = wx.ImageList(isz[0], isz[1])
goffi@necton2
parents:
diff changeset
75 self.icon_online = il.Add(wx.ArtProvider_GetBitmap(wx.ART_TICK_MARK, wx.ART_OTHER, isz))
goffi@necton2
parents:
diff changeset
76 self.icon_unavailable = il.Add(wx.ArtProvider_GetBitmap(wx.ART_CROSS_MARK, wx.ART_OTHER, isz))
goffi@necton2
parents:
diff changeset
77 self.AssignImageList(il)
goffi@necton2
parents:
diff changeset
78
goffi@necton2
parents:
diff changeset
79 self.__addNode(const_DEFAULT_GROUP)
goffi@necton2
parents:
diff changeset
80
goffi@necton2
parents:
diff changeset
81 def __addNode(self, label):
goffi@necton2
parents:
diff changeset
82 """Add an item container"""
goffi@necton2
parents:
diff changeset
83 ret=self.AppendItem(self.root, label)
goffi@necton2
parents:
diff changeset
84 self.SetPyData(ret, "[node]")
goffi@necton2
parents:
diff changeset
85 self.SetItemBold(ret)
goffi@necton2
parents:
diff changeset
86 self.groups[label]=ret
goffi@necton2
parents:
diff changeset
87
goffi@necton2
parents:
diff changeset
88 def replace(self, jid, name="", show="", status="", group=""):
goffi@necton2
parents:
diff changeset
89 debug("status = %s show = %s",status, show)
goffi@necton2
parents:
diff changeset
90 if not self.jid_ids.has_key(jid):
goffi@necton2
parents:
diff changeset
91 self.add(jid, name, show, status, group)
goffi@necton2
parents:
diff changeset
92 else:
goffi@necton2
parents:
diff changeset
93 debug ("updating %s",jid)
goffi@necton2
parents:
diff changeset
94 self.__presentItem(jid, name, show, status, group)
goffi@necton2
parents:
diff changeset
95
goffi@necton2
parents:
diff changeset
96 def __presentItem(self, jid, name, show, status, group):
goffi@necton2
parents:
diff changeset
97 """Make a nice presentation of the contact in the list."""
goffi@necton2
parents:
diff changeset
98 id=self.jid_ids[jid]
goffi@necton2
parents:
diff changeset
99 label= "%s [%s] \n %s" % ((name or jid), (show or "online"), status)
goffi@necton2
parents:
diff changeset
100 self.SetItemText(id, label)
goffi@necton2
parents:
diff changeset
101
goffi@necton2
parents:
diff changeset
102 # icon
goffi@necton2
parents:
diff changeset
103 if not show or show=="chat":
goffi@necton2
parents:
diff changeset
104 self.SetItemImage(id, self.icon_online)
goffi@necton2
parents:
diff changeset
105 else:
goffi@necton2
parents:
diff changeset
106 self.SetItemImage(id, self.icon_unavailable)
goffi@necton2
parents:
diff changeset
107
goffi@necton2
parents:
diff changeset
108 #colour
goffi@necton2
parents:
diff changeset
109 if not show:
goffi@necton2
parents:
diff changeset
110 self.SetItemTextColour(id, wx.BLACK)
goffi@necton2
parents:
diff changeset
111 elif show=="chat":
goffi@necton2
parents:
diff changeset
112 self.SetItemTextColour(id, wx.GREEN)
goffi@necton2
parents:
diff changeset
113 elif show=="away":
goffi@necton2
parents:
diff changeset
114 self.SetItemTextColour(id, wx.BLUE)
goffi@necton2
parents:
diff changeset
115 else:
goffi@necton2
parents:
diff changeset
116 self.SetItemTextColour(id, wx.RED)
goffi@necton2
parents:
diff changeset
117
goffi@necton2
parents:
diff changeset
118 def add(self, jid, name="", show="", status="", group=""):
goffi@necton2
parents:
diff changeset
119 """add a contact to the list"""
goffi@necton2
parents:
diff changeset
120 debug ("adding %s",jid)
goffi@necton2
parents:
diff changeset
121 dest_group=group or const_DEFAULT_GROUP
goffi@necton2
parents:
diff changeset
122 if not self.groups.has_key(dest_group):
goffi@necton2
parents:
diff changeset
123 self.__addNode(dest_group)
goffi@necton2
parents:
diff changeset
124 self.jid_ids[jid]=self.AppendItem(self.groups[dest_group], "")
goffi@necton2
parents:
diff changeset
125 self.__presentItem(jid, name, show, status, group)
goffi@necton2
parents:
diff changeset
126 self.SetPyData(self.jid_ids[jid], "[contact]"+jid)
goffi@necton2
parents:
diff changeset
127 self.EnsureVisible(self.jid_ids[jid])
goffi@necton2
parents:
diff changeset
128 self.Refresh() #FIXME: Best way ?
goffi@necton2
parents:
diff changeset
129
goffi@necton2
parents:
diff changeset
130 def remove(self, jid):
goffi@necton2
parents:
diff changeset
131 """remove a contact from the list"""
goffi@necton2
parents:
diff changeset
132 debug ("removing %s",jid)
goffi@necton2
parents:
diff changeset
133 self.Delete(self.jid_ids[jid])
goffi@necton2
parents:
diff changeset
134 del self.jid_ids[jid]
goffi@necton2
parents:
diff changeset
135 self.Refresh() #FIXME: Best way ?
goffi@necton2
parents:
diff changeset
136
goffi@necton2
parents:
diff changeset
137 def onActivated(self, event):
goffi@necton2
parents:
diff changeset
138 """Called when a contact is clicked or activated with keyboard."""
goffi@necton2
parents:
diff changeset
139 if self.GetPyData(event.GetItem()).startswith("[contact]"):
goffi@necton2
parents:
diff changeset
140 self.onActivatedCB(self.GetPyData(event.GetItem())[9:])
goffi@necton2
parents:
diff changeset
141 else:
goffi@necton2
parents:
diff changeset
142 event.Skip()
goffi@necton2
parents:
diff changeset
143
goffi@necton2
parents:
diff changeset
144 def getSelection(self):
goffi@necton2
parents:
diff changeset
145 """Return the selected contact, or an empty string if there is not"""
goffi@necton2
parents:
diff changeset
146 data = self.GetPyData(self.GetSelection())
goffi@necton2
parents:
diff changeset
147 if not data or not data.startswith("[contact]"):
goffi@necton2
parents:
diff changeset
148 return ""
goffi@necton2
parents:
diff changeset
149 return JID(data[9:])
goffi@necton2
parents:
diff changeset
150
goffi@necton2
parents:
diff changeset
151 def registerActivatedCB(self, cb):
goffi@necton2
parents:
diff changeset
152 """Register a callback with manage contact activation."""
goffi@necton2
parents:
diff changeset
153 self.onActivatedCB=cb
goffi@necton2
parents:
diff changeset
154
goffi@necton2
parents:
diff changeset
155 class MainWindow(wx.Frame, QuickApp):
goffi@necton2
parents:
diff changeset
156 """main app window"""
goffi@necton2
parents:
diff changeset
157
goffi@necton2
parents:
diff changeset
158 def __init__(self):
goffi@necton2
parents:
diff changeset
159 wx.Frame.__init__(self,None, title="SAT Wix", size=(400,200))
goffi@necton2
parents:
diff changeset
160
goffi@necton2
parents:
diff changeset
161
goffi@necton2
parents:
diff changeset
162 #Frame elements
goffi@necton2
parents:
diff changeset
163 self.contactList = ContactList(self)
goffi@necton2
parents:
diff changeset
164 self.contactList.registerActivatedCB(self.onContactActivated)
goffi@necton2
parents:
diff changeset
165 self.chat_wins=ChatList(self)
goffi@necton2
parents:
diff changeset
166 self.CreateStatusBar()
goffi@necton2
parents:
diff changeset
167 self.SetStatusText(msgOFFLINE)
goffi@necton2
parents:
diff changeset
168 self.createMenus()
goffi@necton2
parents:
diff changeset
169
goffi@necton2
parents:
diff changeset
170 #ToolBar
goffi@necton2
parents:
diff changeset
171 self.tools=self.CreateToolBar()
goffi@necton2
parents:
diff changeset
172 self.statusBox = wx.ComboBox(self.tools, -1, "Online", choices=const_STATUS.keys(),
goffi@necton2
parents:
diff changeset
173 style=wx.CB_DROPDOWN | wx.CB_READONLY)
goffi@necton2
parents:
diff changeset
174 self.tools.AddControl(self.statusBox)
goffi@necton2
parents:
diff changeset
175 self.tools.AddSeparator()
goffi@necton2
parents:
diff changeset
176 self.statusTxt=wx.TextCtrl(self.tools, -1, style = wx.TE_PROCESS_ENTER)
goffi@necton2
parents:
diff changeset
177 self.tools.AddControl(self.statusTxt)
goffi@necton2
parents:
diff changeset
178 self.Bind(wx.EVT_COMBOBOX, self.onStatusChange, self.statusBox)
goffi@necton2
parents:
diff changeset
179 self.Bind(wx.EVT_TEXT_ENTER, self.onStatusChange, self.statusTxt)
goffi@necton2
parents:
diff changeset
180 self.tools.Disable()
goffi@necton2
parents:
diff changeset
181
goffi@necton2
parents:
diff changeset
182 #events
goffi@necton2
parents:
diff changeset
183 self.Bind(wx.EVT_CLOSE, self.onClose, self)
goffi@necton2
parents:
diff changeset
184
goffi@necton2
parents:
diff changeset
185 QuickApp.__init__(self)
goffi@necton2
parents:
diff changeset
186
goffi@necton2
parents:
diff changeset
187 self.Show()
goffi@necton2
parents:
diff changeset
188
goffi@necton2
parents:
diff changeset
189 def createMenus(self):
goffi@necton2
parents:
diff changeset
190 info("Creating menus")
goffi@necton2
parents:
diff changeset
191 connectMenu = wx.Menu()
goffi@necton2
parents:
diff changeset
192 connectMenu.Append(idCONNECT, "&Connect CTRL-c"," Connect to the server")
goffi@necton2
parents:
diff changeset
193 connectMenu.Append(idPARAM,"&Parameters"," Configure the program")
goffi@necton2
parents:
diff changeset
194 connectMenu.AppendSeparator()
goffi@necton2
parents:
diff changeset
195 connectMenu.Append(idEXIT,"E&xit"," Terminate the program")
goffi@necton2
parents:
diff changeset
196 contactMenu = wx.Menu()
goffi@necton2
parents:
diff changeset
197 contactMenu.Append(idADD_CONTACT, "&Add contact"," Add a contact to your list")
goffi@necton2
parents:
diff changeset
198 contactMenu.Append(idREMOVE_CONTACT, "&Remove contact"," Remove the selected contact from your list")
goffi@necton2
parents:
diff changeset
199 menuBar = wx.MenuBar()
goffi@necton2
parents:
diff changeset
200 menuBar.Append(connectMenu,"&General")
goffi@necton2
parents:
diff changeset
201 menuBar.Append(contactMenu,"&Contacts")
goffi@necton2
parents:
diff changeset
202 self.SetMenuBar(menuBar)
goffi@necton2
parents:
diff changeset
203
goffi@necton2
parents:
diff changeset
204 #events
goffi@necton2
parents:
diff changeset
205 wx.EVT_MENU(self, idCONNECT, self.onConnectRequest)
goffi@necton2
parents:
diff changeset
206 wx.EVT_MENU(self, idPARAM, self.onParam)
goffi@necton2
parents:
diff changeset
207 wx.EVT_MENU(self, idEXIT, self.onExit)
goffi@necton2
parents:
diff changeset
208 wx.EVT_MENU(self, idADD_CONTACT, self.onAddContact)
goffi@necton2
parents:
diff changeset
209 wx.EVT_MENU(self, idREMOVE_CONTACT, self.onRemoveContact)
goffi@necton2
parents:
diff changeset
210
goffi@necton2
parents:
diff changeset
211
goffi@necton2
parents:
diff changeset
212 def newMessage(self, from_jid, msg, type, to_jid):
goffi@necton2
parents:
diff changeset
213 QuickApp.newMessage(self, from_jid, msg, type, to_jid)
goffi@necton2
parents:
diff changeset
214
goffi@necton2
parents:
diff changeset
215 def showAlert(self, message):
goffi@necton2
parents:
diff changeset
216 # TODO: place this in a separate class
goffi@necton2
parents:
diff changeset
217 popup=wx.PopupWindow(self)
goffi@necton2
parents:
diff changeset
218 ### following code come from wxpython demo
goffi@necton2
parents:
diff changeset
219 popup.SetBackgroundColour("CADET BLUE")
goffi@necton2
parents:
diff changeset
220 st = wx.StaticText(popup, -1, message, pos=(10,10))
goffi@necton2
parents:
diff changeset
221 sz = st.GetBestSize()
goffi@necton2
parents:
diff changeset
222 popup.SetSize( (sz.width+20, sz.height+20) )
goffi@necton2
parents:
diff changeset
223 x=(wx.DisplaySize()[0]-popup.GetSize()[0])/2
goffi@necton2
parents:
diff changeset
224 popup.SetPosition((x,0))
goffi@necton2
parents:
diff changeset
225 popup.Show()
goffi@necton2
parents:
diff changeset
226 wx.CallLater(5000,popup.Destroy)
goffi@necton2
parents:
diff changeset
227
goffi@necton2
parents:
diff changeset
228 def showDialog(self, message, title="", type="info"):
goffi@necton2
parents:
diff changeset
229 if type == 'info':
goffi@necton2
parents:
diff changeset
230 flags = wx.OK | wx.ICON_INFORMATION
goffi@necton2
parents:
diff changeset
231 elif type == 'error':
goffi@necton2
parents:
diff changeset
232 flags = wx.OK | wx.ICON_ERROR
goffi@necton2
parents:
diff changeset
233 elif type == 'question':
goffi@necton2
parents:
diff changeset
234 flags = wx.OK | wx.ICON_QUESTION
goffi@necton2
parents:
diff changeset
235 else:
goffi@necton2
parents:
diff changeset
236 flags = wx.OK | wx.ICON_INFORMATION
goffi@necton2
parents:
diff changeset
237 dlg = wx.MessageDialog(self, message, title, flags)
goffi@necton2
parents:
diff changeset
238 answer = dlg.ShowModal()
goffi@necton2
parents:
diff changeset
239 dlg.Destroy()
goffi@necton2
parents:
diff changeset
240 return True if (answer == wx.ID_YES or answer == wx.ID_OK) else False
goffi@necton2
parents:
diff changeset
241
goffi@necton2
parents:
diff changeset
242 def setStatusOnline(self, online=True):
goffi@necton2
parents:
diff changeset
243 """enable/disable controls, must be called when local user online status change"""
goffi@necton2
parents:
diff changeset
244 if online:
goffi@necton2
parents:
diff changeset
245 self.SetStatusText(msgONLINE)
goffi@necton2
parents:
diff changeset
246 self.tools.Enable()
goffi@necton2
parents:
diff changeset
247 else:
goffi@necton2
parents:
diff changeset
248 self.SetStatusText(msgOFFLINE)
goffi@necton2
parents:
diff changeset
249 self.tools.Disable()
goffi@necton2
parents:
diff changeset
250 return
goffi@necton2
parents:
diff changeset
251
goffi@necton2
parents:
diff changeset
252
goffi@necton2
parents:
diff changeset
253 def presenceUpdate(self, jabber_id, type, show, status, priority):
goffi@necton2
parents:
diff changeset
254 QuickApp.presenceUpdate(self, jabber_id, type, show, status, priority)
goffi@necton2
parents:
diff changeset
255
goffi@necton2
parents:
diff changeset
256 def askConfirmation(self, type, id, data):
goffi@necton2
parents:
diff changeset
257 #TODO: refactor this in QuickApp
goffi@necton2
parents:
diff changeset
258 debug ("Confirmation asked")
goffi@necton2
parents:
diff changeset
259 answer_data={}
goffi@necton2
parents:
diff changeset
260 if type == "FILE_TRANSFERT":
goffi@necton2
parents:
diff changeset
261 debug ("File transfert confirmation asked")
goffi@necton2
parents:
diff changeset
262 dlg = wx.MessageDialog(self, "The contact %s wants to send you the file %s\nDo you accept ?" % (data["from"], data["filename"]),
goffi@necton2
parents:
diff changeset
263 'File Request',
goffi@necton2
parents:
diff changeset
264 wx.YES_NO | wx.ICON_QUESTION
goffi@necton2
parents:
diff changeset
265 )
goffi@necton2
parents:
diff changeset
266 answer=dlg.ShowModal()
goffi@necton2
parents:
diff changeset
267 if answer==wx.ID_YES:
goffi@necton2
parents:
diff changeset
268 filename = wx.FileSelector("Where do you want to save the file ?", flags = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
goffi@necton2
parents:
diff changeset
269 if filename:
goffi@necton2
parents:
diff changeset
270 answer_data["dest_path"] = filename
goffi@necton2
parents:
diff changeset
271 self.bridge.confirmationAnswer(id, True, answer_data)
goffi@necton2
parents:
diff changeset
272 self.waitProgress(id, "File Transfer", "Copying %s" % os.path.basename(filename))
goffi@necton2
parents:
diff changeset
273 else:
goffi@necton2
parents:
diff changeset
274 answer = wx.ID_NO
goffi@necton2
parents:
diff changeset
275 if answer==wx.ID_NO:
goffi@necton2
parents:
diff changeset
276 self.bridge.confirmationAnswer(id, False, answer_data)
goffi@necton2
parents:
diff changeset
277
goffi@necton2
parents:
diff changeset
278 dlg.Destroy()
goffi@necton2
parents:
diff changeset
279
goffi@necton2
parents:
diff changeset
280
goffi@necton2
parents:
diff changeset
281
goffi@necton2
parents:
diff changeset
282
goffi@necton2
parents:
diff changeset
283 def progressCB(self, id, title, message):
goffi@necton2
parents:
diff changeset
284 data = self.bridge.getProgress(id)
goffi@necton2
parents:
diff changeset
285 if data:
goffi@necton2
parents:
diff changeset
286 if not data['position']:
goffi@necton2
parents:
diff changeset
287 data['position'] = '0'
goffi@necton2
parents:
diff changeset
288 if not self.pbar:
goffi@necton2
parents:
diff changeset
289 #first answer, we must construct the bar
goffi@necton2
parents:
diff changeset
290 self.pbar = wx.ProgressDialog(title, message, int(data['size']), None,
goffi@necton2
parents:
diff changeset
291 wx.PD_SMOOTH | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME)
goffi@necton2
parents:
diff changeset
292 self.pbar.finish_value = int(data['size'])
goffi@necton2
parents:
diff changeset
293
goffi@necton2
parents:
diff changeset
294 self.pbar.Update(int(data['position']))
goffi@necton2
parents:
diff changeset
295 elif self.pbar:
goffi@necton2
parents:
diff changeset
296 self.pbar.Update(self.pbar.finish_value)
goffi@necton2
parents:
diff changeset
297 return
goffi@necton2
parents:
diff changeset
298
goffi@necton2
parents:
diff changeset
299 wx.CallLater(10, self.progressCB, id, title, message)
goffi@necton2
parents:
diff changeset
300
goffi@necton2
parents:
diff changeset
301 def waitProgress (self, id, title, message):
goffi@necton2
parents:
diff changeset
302 self.pbar = None
goffi@necton2
parents:
diff changeset
303 wx.CallLater(10, self.progressCB, id, title, message)
goffi@necton2
parents:
diff changeset
304
goffi@necton2
parents:
diff changeset
305
goffi@necton2
parents:
diff changeset
306
goffi@necton2
parents:
diff changeset
307 ### events ###
goffi@necton2
parents:
diff changeset
308
goffi@necton2
parents:
diff changeset
309 def onContactActivated(self, jid):
goffi@necton2
parents:
diff changeset
310 debug ("onContactActivated: %s", jid)
goffi@necton2
parents:
diff changeset
311 if self.chat_wins[jid].IsShown():
goffi@necton2
parents:
diff changeset
312 self.chat_wins[jid].Hide()
goffi@necton2
parents:
diff changeset
313 else:
goffi@necton2
parents:
diff changeset
314 self.chat_wins[jid].Show()
goffi@necton2
parents:
diff changeset
315
goffi@necton2
parents:
diff changeset
316 def onConnectRequest(self, e):
goffi@necton2
parents:
diff changeset
317 self.bridge.connect()
goffi@necton2
parents:
diff changeset
318
goffi@necton2
parents:
diff changeset
319 def __updateStatus(self):
goffi@necton2
parents:
diff changeset
320 show = const_STATUS[self.statusBox.GetValue()]
goffi@necton2
parents:
diff changeset
321 status = self.statusTxt.GetValue()
goffi@necton2
parents:
diff changeset
322 self.bridge.setPresence(show=show, status=status)
goffi@necton2
parents:
diff changeset
323
goffi@necton2
parents:
diff changeset
324 def onStatusChange(self, e):
goffi@necton2
parents:
diff changeset
325 debug("Status change request")
goffi@necton2
parents:
diff changeset
326 self.__updateStatus()
goffi@necton2
parents:
diff changeset
327
goffi@necton2
parents:
diff changeset
328 def onParam(self, e):
goffi@necton2
parents:
diff changeset
329 debug("Param request")
goffi@necton2
parents:
diff changeset
330 param=Param(self.bridge.setParam, self.bridge.getParam, self.bridge.getParams, self.bridge.getParamsCategories)
goffi@necton2
parents:
diff changeset
331
goffi@necton2
parents:
diff changeset
332 def onExit(self, e):
goffi@necton2
parents:
diff changeset
333 self.Close()
goffi@necton2
parents:
diff changeset
334
goffi@necton2
parents:
diff changeset
335 def onAddContact(self, e):
goffi@necton2
parents:
diff changeset
336 debug("Add contact request")
goffi@necton2
parents:
diff changeset
337 dlg = wx.TextEntryDialog(
goffi@necton2
parents:
diff changeset
338 self, 'Please enter new contact JID',
goffi@necton2
parents:
diff changeset
339 'Adding a contact', 'name@server.ext')
goffi@necton2
parents:
diff changeset
340
goffi@necton2
parents:
diff changeset
341 if dlg.ShowModal() == wx.ID_OK:
goffi@necton2
parents:
diff changeset
342 jid=JID(dlg.GetValue())
goffi@necton2
parents:
diff changeset
343 if jid.is_valid():
goffi@necton2
parents:
diff changeset
344 self.bridge.addContact(jid.short)
goffi@necton2
parents:
diff changeset
345 else:
goffi@necton2
parents:
diff changeset
346 error ("'%s' is an invalid JID !", jid)
goffi@necton2
parents:
diff changeset
347 #TODO: notice the user
goffi@necton2
parents:
diff changeset
348
goffi@necton2
parents:
diff changeset
349 dlg.Destroy()
goffi@necton2
parents:
diff changeset
350
goffi@necton2
parents:
diff changeset
351 def onRemoveContact(self, e):
goffi@necton2
parents:
diff changeset
352 debug("Remove contact request")
goffi@necton2
parents:
diff changeset
353 target = self.contactList.getSelection()
goffi@necton2
parents:
diff changeset
354 if not target:
goffi@necton2
parents:
diff changeset
355 dlg = wx.MessageDialog(self, "You haven't selected any contact !",
goffi@necton2
parents:
diff changeset
356 'Error',
goffi@necton2
parents:
diff changeset
357 wx.OK | wx.ICON_ERROR
goffi@necton2
parents:
diff changeset
358 )
goffi@necton2
parents:
diff changeset
359 dlg.ShowModal()
goffi@necton2
parents:
diff changeset
360 dlg.Destroy()
goffi@necton2
parents:
diff changeset
361 return
goffi@necton2
parents:
diff changeset
362
goffi@necton2
parents:
diff changeset
363 dlg = wx.MessageDialog(self, "Are you sure you want to delete %s from your roster list ?" % target.short,
goffi@necton2
parents:
diff changeset
364 'Contact suppression',
goffi@necton2
parents:
diff changeset
365 wx.YES_NO | wx.ICON_QUESTION
goffi@necton2
parents:
diff changeset
366 )
goffi@necton2
parents:
diff changeset
367
goffi@necton2
parents:
diff changeset
368 if dlg.ShowModal() == wx.ID_YES:
goffi@necton2
parents:
diff changeset
369 info("Unsubsribing %s presence", target.short)
goffi@necton2
parents:
diff changeset
370 self.bridge.delContact(target.short)
goffi@necton2
parents:
diff changeset
371
goffi@necton2
parents:
diff changeset
372 dlg.Destroy()
goffi@necton2
parents:
diff changeset
373
goffi@necton2
parents:
diff changeset
374 def onClose(self, e):
goffi@necton2
parents:
diff changeset
375 info("Exiting...")
goffi@necton2
parents:
diff changeset
376 e.Skip()
goffi@necton2
parents:
diff changeset
377