- Timestamp:
- Nov 27, 2013 9:37:32 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/pjsua2/pjsip-apps/src/pygui/application.py
r4648 r4657 33 33 import accountsetting 34 34 import account 35 import buddy 35 36 import endpoint 36 37 … … 63 64 self.pack(expand='yes', fill='both') 64 65 self.master.title('pjsua2 Demo') 66 self.master.geometry('500x500+100+100') 65 67 66 68 # Logger … … 72 74 # GUI variables 73 75 self.showLogWindow = tk.IntVar() 74 self.showLogWindow.set( 1)76 self.showLogWindow.set(0) 75 77 self.quitting = False 76 78 … … 100 102 t.cfg.port = 0 101 103 self.transportCfgs.append(t) 104 t = SipTransportConfig() 105 t.type = pj.PJSIP_TRANSPORT_TCP 106 t.cfg.port = 0 107 self.transportCfgs.append(t) 102 108 103 109 … … 116 122 node = json.writeNewArray("accounts") 117 123 for acc in self.accList: 118 node.writeObject(acc.cfg); 124 acc_node = node.writeNewContainer("Account") 125 acc_node.writeObject(acc.cfg); 126 127 # Write buddy configs 128 buddy_node = acc_node.writeNewArray("buddies") 129 for bud in acc.buddyList: 130 buddy_node.writeObject(bud.cfg) 131 119 132 json.saveFile(filename) 120 133 … … 141 154 node = json.readArray("accounts") 142 155 while node.hasUnread(): 143 cfg = pj.AccountConfig() 144 cfg.readObject(node) 145 acc_cfgs.append(cfg) 146 156 acc_node = node.readContainer("Account") 157 acc_cfg = pj.AccountConfig() 158 acc_cfg.readObject(acc_node) 159 160 # Load buddy configs 161 buddy_cfgs = [] 162 buddy_node = acc_node.readArray("buddies") 163 while buddy_node.hasUnread(): 164 buddy_cfg = pj.BuddyConfig() 165 buddy_cfg.readObject(buddy_node) 166 buddy_cfgs.append(buddy_cfg) 167 168 acc_cfgs.append((acc_cfg, buddy_cfgs)) 169 170 147 171 # Initialize library 148 172 self.epCfg.uaConfig.userAgent = "pygui-" + self.ep.libVersion().full; … … 155 179 156 180 # Add accounts 157 for cfg in acc_cfgs:181 for cfg, buddy_cfgs in acc_cfgs: 158 182 self._createAcc(cfg) 159 183 acc = self.accList[-1] 184 for buddy_cfg in buddy_cfgs: 185 self._createBuddy(acc, buddy_cfg) 186 160 187 # Start library 161 188 self.ep.libStart() … … 173 200 self.tv.item(iid, text=text, values=values) 174 201 else: 175 self.tv.insert('', 0, iid, open=True, text=text, values=values) 176 self.tv.insert(iid, 0, '', open=True, text='Buddy 1', values=('Online',)) 177 self.tv.insert(iid, 1, '', open=True, text='Buddy 2', values=('Online',)) 202 self.tv.insert('', 'end', iid, open=True, text=text, values=values) 203 204 def updateBuddy(self, bud): 205 iid = 'buddy' + str(bud.randId) 206 text = bud.cfg.uri 207 status = bud.statusText() 208 209 values = (status,) 210 if self.tv.exists(iid): 211 self.tv.item(iid, text=text, values=values) 212 else: 213 self.tv.insert(str(bud.account.randId), 'end', iid, open=True, text=text, values=values) 178 214 179 215 def _createAcc(self, acc_cfg): … … 186 222 self.updateAccount(acc) 187 223 224 def _createBuddy(self, acc, buddy_cfg): 225 bud = buddy.Buddy(self) 226 bud.cfg = buddy_cfg 227 bud.account = acc 228 bud.create(acc, bud.cfg) 229 self.updateBuddy(bud) 230 acc.buddyList.append(bud) 231 188 232 def _createWidgets(self): 189 233 self._createAppMenu() … … 222 266 def _createContextMenu(self): 223 267 top = self.winfo_toplevel() 268 269 # Create Account context menu 224 270 self.accMenu = tk.Menu(top, tearoff=False) 225 271 # Labels, must match with _onAccContextMenu() 226 labels = ['Unregister', 'Reregister', '-', 'Online', 'Invisible', 'Away', 'Busy', '-', 'Settings...', '-', 'Delete...'] 272 labels = ['Unregister', 'Reregister', 'Add buddy...', '-', 273 'Online', 'Invisible', 'Away', 'Busy', '-', 274 'Settings...', '-', 275 'Delete...'] 227 276 for label in labels: 228 277 if label=='-': … … 232 281 self.accMenu.add_command(label=label, command=cmd) 233 282 283 # Create Buddy context menu 284 # Labels, must match with _onAccContextMenu() 285 self.buddyMenu = tk.Menu(top, tearoff=False) 286 labels = ['Video call', 'Audio call', 'Send instant message', '-', 287 'Settings...', '-', 288 'Delete...'] 289 290 for label in labels: 291 if label=='-': 292 self.buddyMenu.add_separator() 293 else: 294 cmd = lambda arg=label: self._onBuddyContextMenu(arg) 295 self.buddyMenu.add_command(label=label, command=cmd) 296 234 297 if (top.tk.call('tk', 'windowingsystem')=='aqua'): 235 298 self.tv.bind('<2>', self._onTvRightClick) … … 251 314 return accs[0] 252 315 316 def _getSelectedBuddy(self): 317 items = self.tv.selection() 318 if not items: 319 return None 320 try: 321 iid = int(items[0][5:]) 322 iid_parent = int(self.tv.parent(items[0])) 323 except: 324 return None 325 326 accs = [acc for acc in self.accList if acc.randId==iid_parent] 327 if not accs: 328 return None 329 330 buds = [b for b in accs[0].buddyList if b.randId==iid] 331 if not buds: 332 return None 333 334 return buds[0] 335 253 336 def _onTvRightClick(self, event): 254 iid = self.tv.identify('item', event.x, event.y) 337 iid = self.tv.identify_row(event.y) 338 #iid = self.tv.identify('item', event.x, event.y) 255 339 if iid: 256 self.tv.selection_ add( (iid,) )340 self.tv.selection_set( (iid,) ) 257 341 acc = self._getSelectedAccount() 258 342 if acc: … … 260 344 else: 261 345 # A buddy is selected 262 pass346 self.buddyMenu.post(event.x_root, event.y_root) 263 347 264 348 def _onAccContextMenu(self, label): … … 272 356 acc.setRegistration(True) 273 357 elif label=='Online': 274 ps = pj. AccountPresenceStatus()358 ps = pj.PresenceStatus() 275 359 ps.isOnline = True 276 360 acc.setOnlineStatus(ps) 277 361 elif label=='Invisible': 278 ps = pj. AccountPresenceStatus()362 ps = pj.PresenceStatus() 279 363 ps.isOnline = False 280 364 acc.setOnlineStatus(ps) 281 365 elif label=='Away': 282 ps = pj. AccountPresenceStatus()366 ps = pj.PresenceStatus() 283 367 ps.isOnline = True 284 368 ps.activity = pj.PJRPID_ACTIVITY_AWAY … … 286 370 acc.setOnlineStatus(ps) 287 371 elif label=='Busy': 288 ps = pj. AccountPresenceStatus()372 ps = pj.PresenceStatus() 289 373 ps.isOnline = True 290 374 ps.activity = pj.PJRPID_ACTIVITY_BUSY … … 305 389 del acc 306 390 self.tv.delete( (iid,) ) 391 elif label=='Add buddy...': 392 cfg = pj.BuddyConfig() 393 dlg = buddy.SettingDialog(self.master, cfg) 394 if dlg.doModal(): 395 self._createBuddy(acc, cfg) 307 396 else: 308 397 assert not ("Unknown menu " + label) 309 398 399 def _onBuddyContextMenu(self, label): 400 bud = self._getSelectedBuddy() 401 if not bud: 402 return 403 acc = bud.account 404 405 if label=='Video call': 406 pass 407 elif label=='Audio call': 408 pass 409 elif label=='Send instant message': 410 pass 411 elif label=='Settings...': 412 subs = bud.cfg.subscribe 413 uri = bud.cfg.uri 414 dlg = buddy.SettingDialog(self.master, bud.cfg) 415 if dlg.doModal(): 416 self.updateBuddy(bud) 417 # URI updated? 418 if uri != bud.cfg.uri: 419 cfg = bud.cfg 420 # del old 421 iid = 'buddy' + str(bud.randId) 422 acc.buddyList.remove(bud) 423 del bud 424 self.tv.delete( (iid,) ) 425 # add new 426 self._createBuddy(acc, cfg) 427 # presence subscribe setting updated 428 elif subs != bud.cfg.subscribe: 429 bud.subscribePresence(bud.cfg.subscribe) 430 elif label=='Delete...': 431 msg = "Do you really want to delete buddy '%s'?" % bud.cfg.uri 432 if msgbox.askquestion('Delete buddy?', msg, default=msgbox.NO) != u'yes': 433 return 434 iid = 'buddy' + str(bud.randId) 435 acc.buddyList.remove(bud) 436 del bud 437 self.tv.delete( (iid,) ) 438 else: 439 assert not ("Unknown menu " + label) 440 310 441 def _onTimer(self): 311 442 if not self.quitting:
Note: See TracChangeset
for help on using the changeset viewer.