annotate frontends/src/primitivus/primitivus @ 475:6bb9305e0b9c

frontend: Fix notify import in Primitivus.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 14 Apr 2012 16:26:55 +0200
parents cf005701624b
children 2a072735e459
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Primitivus: a SAT frontend
459
cf005701624b copyleft date update
Goffi <goffi@goffi.org>
parents: 423
diff changeset
6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org)
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 import urwid
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
24 from urwid_satext import sat_widgets
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
25 from sat_frontends.quick_frontend.quick_app import QuickApp
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
26 from sat_frontends.quick_frontend.quick_chat_list import QuickChatList
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
27 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
28 from sat_frontends.quick_frontend.quick_contact_management import QuickContactManagement
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
29 from sat_frontends.primitivus.profile_manager import ProfileManager
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
30 from sat_frontends.primitivus.contact_list import ContactList
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
31 from sat_frontends.primitivus.chat import Chat
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
32 from sat_frontends.primitivus.gateways import GatewaysManager
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
33 from sat_frontends.primitivus.xmlui import XMLUI
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
34 from sat_frontends.primitivus.progress import Progress
475
6bb9305e0b9c frontend: Fix notify import in Primitivus.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 459
diff changeset
35 from sat_frontends.primitivus.notify import Notify
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 import logging
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 from logging import debug, info, error
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 import sys, os
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
39 from sat.tools.jid import JID
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 ### logging configuration FIXME: put this elsewhere ###
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 logging.basicConfig(level=logging.CRITICAL, #TODO: configure it to put messages in a log file
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 format='%(message)s')
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 ###
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 const_APP_NAME = "Primitivus"
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
48 const_PALETTE = [('title', 'black', 'light gray', 'standout,underline'),
192
879beacb8e16 Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents: 189
diff changeset
49 ('title_focus', 'white,bold', 'light gray', 'standout,underline'),
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
50 ('selected', 'default', 'dark red'),
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
51 ('selected_focus', 'default,bold', 'dark red'),
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
52 ('default', 'default', 'default'),
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
53 ('default_focus', 'default,bold', 'default'),
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
54 ('alert', 'default,underline', 'default'),
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
55 ('alert_focus', 'default,bold,underline', 'default'),
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
56 ('date', 'light gray', 'default'),
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
57 ('my_nick', 'dark red,bold', 'default'),
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
58 ('other_nick', 'dark cyan,bold', 'default'),
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
59 ('menubar', 'light gray,bold', 'dark red'),
192
879beacb8e16 Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents: 189
diff changeset
60 ('menubar_focus', 'light gray,bold', 'dark green'),
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
61 ('selected_menu', 'light gray,bold', 'dark green'),
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
62 ('menuitem', 'light gray,bold', 'dark red'),
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
63 ('menuitem_focus', 'light gray,bold', 'dark green'),
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
64 ('notifs', 'black,bold', 'yellow'),
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
65 ('notifs_focus', 'dark red', 'yellow'),
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
66 ('card_neutral', 'dark gray', 'white', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
67 ('card_neutral_selected', 'dark gray', 'dark green', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
68 ('card_special', 'brown', 'white', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
69 ('card_special_selected', 'brown', 'dark green', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
70 ('card_red', 'dark red', 'white', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
71 ('card_red_selected', 'dark red', 'dark green', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
72 ('card_black', 'black', 'white', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
73 ('card_black_selected', 'black', 'dark green', 'standout,underline'),
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
74 ('directory', 'dark cyan, bold', 'default'),
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
75 ('directory_focus', 'dark cyan, bold', 'dark green'),
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
76 ('separator', 'brown', 'default'),
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
77 ('warning', 'light red', 'default'),
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
78 ('progress_normal', 'default', 'black'),
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
79 ('progress_complete', 'default', 'light red'),
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
80 ]
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
82 class ChatList(QuickChatList):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
83 """This class manage the list of chat windows"""
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
84
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
85 def __init__(self, host):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
86 QuickChatList.__init__(self, host)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
87
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
88 def createChat(self, target):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
89 return Chat(target, self.host)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
90
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 class PrimitivusApp(QuickApp):
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93 def __init__(self):
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 113
diff changeset
94 self.CM = QuickContactManagement() #FIXME: not the best place
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
95 QuickApp.__init__(self)
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97 ## main loop setup ##
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
98 self.main_widget = ProfileManager(self)
127
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
99 self.loop = urwid.MainLoop(self.main_widget, const_PALETTE, event_loop=urwid.GLibEventLoop(), input_filter=self.inputFilter, unhandled_input=self.keyHandler)
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
100
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
101 ##misc setup##
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
102 self.chat_wins=ChatList(self)
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
103 self.notBar = sat_widgets.NotificationBar()
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
104 urwid.connect_signal(self.notBar,'change',self.onNotification)
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
105 self.progress_wid = Progress(self)
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
106 urwid.connect_signal(self.notBar.progress,'click',lambda x:self.addWindow(self.progress_wid))
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
107 self.__saved_overlay = None
380
ede26abf6ca1 primitivus: freedesktop notifications (if available) when somebody is talking to us and we have not focus, or our nick is pinged and we have not focus.
Goffi <goffi@goffi.org>
parents: 276
diff changeset
108
ede26abf6ca1 primitivus: freedesktop notifications (if available) when somebody is talking to us and we have not focus, or our nick is pinged and we have not focus.
Goffi <goffi@goffi.org>
parents: 276
diff changeset
109 self.notify = Notify()
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
110
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
111 def debug(self):
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
112 """convenient method to reset screen and launch p(u)db"""
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
113 try:
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
114 import pudb
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
115 pudb.set_trace()
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
116 except:
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
117 import os,pdb
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
118 os.system('reset')
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
119 print 'Entered debug mode'
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
120 pdb.set_trace()
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
121
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
122 def writeLog(self, log, file_name='/tmp/primitivus_log'):
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
123 """method to write log in a temporary file, useful for debugging"""
157
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 153
diff changeset
124 with open(file_name, 'a') as f:
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 153
diff changeset
125 f.write(log+"\n")
129
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
126
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
127 def redraw(self):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
128 """redraw the screen"""
422
5a18c5f08d9b Primitivus: Profile Manager: fixed redraw on profile change + use of AdvandedEdit for login field
Goffi <goffi@goffi.org>
parents: 415
diff changeset
129 try:
5a18c5f08d9b Primitivus: Profile Manager: fixed redraw on profile change + use of AdvandedEdit for login field
Goffi <goffi@goffi.org>
parents: 415
diff changeset
130 self.loop.draw_screen()
5a18c5f08d9b Primitivus: Profile Manager: fixed redraw on profile change + use of AdvandedEdit for login field
Goffi <goffi@goffi.org>
parents: 415
diff changeset
131 except AttributeError:
5a18c5f08d9b Primitivus: Profile Manager: fixed redraw on profile change + use of AdvandedEdit for login field
Goffi <goffi@goffi.org>
parents: 415
diff changeset
132 pass
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
133
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
134 def start(self):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
135 self.i = 0
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
136 self.loop.set_alarm_in(0,lambda a,b: self.postInit())
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
137 self.loop.run()
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
138
127
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
139 def inputFilter(self, input, raw):
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
140 if self.__saved_overlay and input != ['ctrl s']:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
141 return
127
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
142 for i in input:
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
143 if isinstance(i,tuple):
127
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
144 if i[0] == 'mouse press':
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
145 if i[1] == 4: #Mouse wheel up
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
146 input[input.index(i)] = 'up'
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
147 if i[1] == 5: #Mouse wheel down
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
148 input[input.index(i)] = 'down'
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
149 return input
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
150
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
151 def keyHandler(self, input):
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
152 if input == 'meta m':
181
a566f654929e README update:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
153 """User want to (un)hide the menu roller"""
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
154 try:
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
155 if self.main_widget.header == None:
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
156 self.main_widget.header = self.menu_roller
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
157 else:
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
158 self.main_widget.header = None
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
159 except AttributeError:
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
160 pass
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
161 elif input == 'ctrl n':
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
162 """User wants to see next notification"""
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
163 self.notBar.showNext()
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
164 elif input == 'ctrl s':
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
165 """User wants to (un)hide overlay window"""
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
166 if isinstance(self.loop.widget,urwid.Overlay):
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
167 self.__saved_overlay = self.loop.widget
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
168 self.loop.widget = self.main_widget
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
169 else:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
170 if self.__saved_overlay:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
171 self.loop.widget = self.__saved_overlay
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
172 self.__saved_overlay = None
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
173
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
174 elif input == 'ctrl d' and 'D' in self.bridge.getVersion(): #Debug only for dev versions
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
175 self.debug()
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
176 elif input == 'f2': #user wants to (un)hide the contact_list
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
177 try:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
178 center_widgets = self.center_part.widget_list
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
179 if self.contactList in center_widgets:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
180 self.center_part.set_focus(0) #necessary as the focus change to the next object, we can go out of range if we are on the last object of self.center_part
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
181 center_widgets.remove(self.contactList)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
182 del self.center_part.column_types[0]
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
183 else:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
184 center_widgets.insert(0, self.contactList)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
185 self.center_part.column_types.insert(0, ('weight', 2))
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
186 except AttributeError:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
187 #The main widget is not built (probably in Profile Manager)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
188 pass
129
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
189 elif input == 'window resize':
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
190 width,height = self.loop.screen_size
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
191 if height<=5 and width<=35:
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
192 if not 'save_main_widget' in dir(self):
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
193 self.save_main_widget = self.loop.widget
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
194 self.loop.widget = urwid.Filler(urwid.Text(_("Pleeeeasse, I can't even breathe !")))
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
195 else:
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
196 if 'save_main_widget' in dir(self):
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
197 self.loop.widget = self.save_main_widget
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
198 del self.save_main_widget
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
199 try:
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
200 return self.menu_roller.checkShortcuts(input)
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
201 except AttributeError:
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
202 return input
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
203
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
204 def __buildMenuRoller(self):
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
205 menu = sat_widgets.Menu(self.loop)
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
206 general = _("General")
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
207 menu.addMenu(general, _("Connect"), self.onConnectRequest)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
208 menu.addMenu(general, _("Disconnect"), self.onDisconnectRequest)
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
209 menu.addMenu(general, _("Parameters"), self.onParam)
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
210 menu.addMenu(general, _("About"), self.onAboutRequest)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
211 menu.addMenu(general, _("Exit"), self.onExitRequest, 'ctrl x')
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
212 contact = _("Contact")
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
213 menu.addMenu(contact, _("Add contact"), self.onAddContactRequest)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
214 menu.addMenu(contact, _("Remove contact"), self.onRemoveContactRequest)
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
215 communication = _("Communication")
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
216 menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j')
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
217 menu.addMenu(communication, _("Find Gateways"), self.onFindGatewaysRequest, 'meta g')
145
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
218 #additionals menus
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
219 #FIXME: do this in a more generic way (in quickapp)
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
220 add_menus = self.bridge.getMenus()
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
221 def add_menu_cb(menu):
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
222 category, item = menu
219
782319a64ac6 primitivus, wix: added forgotten profile
Goffi <goffi@goffi.org>
parents: 216
diff changeset
223 id = self.bridge.callMenu(category, item, "NORMAL", self.profile)
145
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
224 self.current_action_ids.add(id)
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
225 for new_menu in add_menus:
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
226 category,item,type = new_menu
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
227 assert(type=="NORMAL") #TODO: manage other types
216
783d6a61e0bd primitivus: Q&D workaround for dbus.String issue
Goffi <goffi@goffi.org>
parents: 204
diff changeset
228 menu.addMenu(unicode(category), unicode(item), add_menu_cb)
145
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
229
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
230 menu_roller = sat_widgets.MenuRoller([(_('Main menu'),menu)])
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
231 return menu_roller
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
232
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
233 def __buildMainWidget(self):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
234 self.contactList = ContactList(self, self.CM, on_click = self.contactSelected, on_change=lambda w: self.redraw())
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
235 #self.center_part = urwid.Columns([('weight',2,self.contactList),('weight',8,Chat('',self))])
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
236 self.center_part = urwid.Columns([('weight',2,self.contactList), ('weight',8,urwid.Filler(urwid.Text('')))])
411
b109a79ac72f primitivus: urwid 1.0.0 update (crash was caused by using non unicode caption)
Goffi <goffi@goffi.org>
parents: 405
diff changeset
237 self.editBar = sat_widgets.AdvancedEdit(u'> ')
189
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
238 self.editBar.setCompletionMethod(self._nick_completion)
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
239 urwid.connect_signal(self.editBar,'click',self.onTextEntered)
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
240 self.menu_roller = self.__buildMenuRoller()
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
241 self.main_widget = sat_widgets.FocusFrame(self.center_part, header=self.menu_roller, footer=self.editBar, focus_part='footer')
118
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
242 return self.main_widget
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
243
189
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
244 def _nick_completion(self, text, completion_data):
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
245 """Completion method which complete pseudo in group chat
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
246 for params, see AdvancedEdit"""
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
247 contact = self.contactList.get_contact() ###Based on the fact that there is currently only one contact selectableat once
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
248 if contact:
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
249 chat = self.chat_wins[contact]
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
250 if chat.type != "group":
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
251 return text
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
252 space = text.rfind(" ")
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
253 start = text[space+1:]
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
254 nicks = list(chat.occupants)
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
255 nicks.sort()
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
256 try:
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
257 start_idx=nicks.index(completion_data['last_nick'])+1
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
258 if start_idx == len(nicks):
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
259 start_idx = 0
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
260 except (KeyError,ValueError):
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
261 start_idx = 0
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
262 for idx in range(start_idx,len(nicks)) + range(0,start_idx):
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
263 if nicks[idx].lower().startswith(start.lower()):
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
264 completion_data['last_nick'] = nicks[idx]
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
265 return text[:space+1] + nicks[idx] + (': ' if space < 0 else '')
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
266 return text
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
267
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
268
757518d05833 Primitivus: added nick completion
Goffi <goffi@goffi.org>
parents: 183
diff changeset
269
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 113
diff changeset
270 def plug_profile(self, profile_key='@DEFAULT@'):
415
3348331e0f09 primitivus: fixed screen redraw after plugin profile
Goffi <goffi@goffi.org>
parents: 411
diff changeset
271 self.loop.widget = self.__buildMainWidget()
3348331e0f09 primitivus: fixed screen redraw after plugin profile
Goffi <goffi@goffi.org>
parents: 411
diff changeset
272 self.redraw()
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 113
diff changeset
273 QuickApp.plug_profile(self, profile_key)
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
274
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
275 def removePopUp(self, widget=None):
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
276 "Remove current pop-up, and if there is other in queue, show it"
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
277 self.loop.widget = self.main_widget
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
278 next_popup = self.notBar.getNextPopup()
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
279 if next_popup:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
280 #we still have popup to show, we display it
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
281 self.showPopUp(next_popup)
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
282
176
a50953ac6191 Primitivus: send_file first draft
Goffi <goffi@goffi.org>
parents: 173
diff changeset
283 def showPopUp(self, pop_up_widget, perc_width=40, perc_height=40):
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
284 "Show a pop-up window if possible, else put it in queue"
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
285 if not isinstance(self.loop.widget,urwid.Overlay):
176
a50953ac6191 Primitivus: send_file first draft
Goffi <goffi@goffi.org>
parents: 173
diff changeset
286 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', perc_width), 'middle', ('relative', perc_height))
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
287 self.loop.widget = display_widget
219
782319a64ac6 primitivus, wix: added forgotten profile
Goffi <goffi@goffi.org>
parents: 216
diff changeset
288 self.redraw()
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
289 else:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
290 self.notBar.addPopUp(pop_up_widget)
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
291
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
292 def notify(self, message):
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
293 """"Notify message to user via notification bar"""
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
294 self.notBar.addMessage(message)
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
295
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
296 def addWindow(self, widget):
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
297 """Display a window if possible,
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
298 else add it in the notification bar queue
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
299 @param widget: BoxWidget"""
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
300 assert(len(self.center_part.widget_list)<=2)
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
301 wid_idx = len(self.center_part.widget_list)-1
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
302 self.center_part.widget_list[wid_idx] = widget
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
303 self.menu_roller.removeMenu(_('Chat menu'))
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
304 self.contactList.unselectAll()
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
305 self.redraw()
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
306
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
307 def removeWindow(self):
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
308 """Remove window showed on the right column"""
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
309 #TODO: to a better Window management than this crappy hack
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
310 assert(len(self.center_part.widget_list)<=2)
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
311 wid_idx = len(self.center_part.widget_list)-1
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
312 self.center_part.widget_list[wid_idx] = urwid.Filler(urwid.Text(''))
168
a2655a0a4eac Primitivus: 2 bugs fixes
Goffi <goffi@goffi.org>
parents: 166
diff changeset
313 self.center_part.set_focus(0)
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
314 self.redraw()
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
315
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
316 def addProgress (self, id, message):
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
317 """Follow a SàT progress bar
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
318 @param id: SàT id of the progression
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
319 @param message: message to show to identify the progression"""
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
320 self.progress_wid.addProgress(id, message)
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
321
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
322 def setProgress(self, percentage):
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
323 """Set the progression shown in notification bar"""
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
324 self.notBar.setProgress(percentage)
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
325
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
326 def contactSelected(self, contact_list):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
327 contact = contact_list.get_contact()
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
328 if contact:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
329 assert(len(self.center_part.widget_list)==2)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
330 self.center_part.widget_list[1] = self.chat_wins[contact]
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
331 self.menu_roller.addMenu(_('Chat menu'), self.chat_wins[contact].getMenu())
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
332
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
333 def onTextEntered(self, editBar):
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
334 """Called when text is entered in the main edit bar"""
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
335 contact = self.contactList.get_contact() ###Based on the fact that there is currently only one contact selectableat once
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
336 if contact:
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
337 chat = self.chat_wins[contact]
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
338 self.bridge.sendMessage(contact,
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
339 editBar.get_edit_text(),
276
a00e87d48213 bridge, bridge constructor: fixed mix stuff
Goffi <goffi@goffi.org>
parents: 228
diff changeset
340 mess_type = "groupchat" if chat.type == 'group' else "chat",
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
341 profile_key=self.profile)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
342 editBar.set_edit_text('')
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
343
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
344 def newMessage(self, from_jid, msg, type, to_jid, profile):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
345 if not self.check_profile(profile):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
346 return
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
347 QuickApp.newMessage(self, from_jid, msg, type, to_jid, profile)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
348 sender = JID(from_jid)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
349 if JID(self.contactList.selected).short != sender.short:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
350 self.contactList.putAlert(sender)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
351
182
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
352 def _dialogOkCb(self, widget, data):
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
353 self.removePopUp()
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
354 answer_cb = data[0]
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
355 answer_data = [data[1]] if data[1] else []
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
356 answer_cb(True, *answer_data)
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
357
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
358 def _dialogCancelCb(self, widget, data):
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
359 self.removePopUp()
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
360 answer_cb = data[0]
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
361 answer_data = [data[1]] if data[1] else []
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
362 answer_cb(False, *answer_data)
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
363
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
364
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
365 def showDialog(self, message, title="", type="info", answer_cb = None, answer_data = None):
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
366 if type == 'info':
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
367 popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
182
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
368 elif type == 'error':
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
369 popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
182
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
370 elif type == 'yes/no':
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
371 popup = sat_widgets.ConfirmDialog(unicode(message),
182
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
372 yes_cb=self._dialogOkCb, yes_value = (answer_cb, answer_data),
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
373 no_cb=self._dialogCancelCb, no_value = (answer_cb, answer_data))
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
374 else:
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
375 popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
182
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
376 error(_('unmanaged dialog type: %s'), type)
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
377 self.showPopUp(popup)
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
378
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
379 def onNotification(self, notBar):
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
380 """Called when a new notification has been received"""
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
381 if not isinstance(self.main_widget, sat_widgets.FocusFrame):
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
382 #if we are not in the main configuration, we ignore the notifications bar
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
383 return
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
384 if isinstance(self.main_widget.footer,sat_widgets.AdvancedEdit):
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
385 if not self.notBar.canHide():
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
386 #the notification bar is not visible and has usefull informations, we show it
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
387 pile = urwid.Pile([self.notBar, self.editBar])
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
388 self.main_widget.footer = pile
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
389 else:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
390 if not isinstance(self.main_widget.footer, urwid.Pile):
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
391 error(_("INTERNAL ERROR: Unexpected class for main widget's footer"))
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
392 assert(False)
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
393 if self.notBar.canHide():
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
394 #No notification left, we can hide the bar
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
395 self.main_widget.footer = self.editBar
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
396
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
397 def actionResult(self, type, id, data):
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
398 if not id in self.current_action_ids:
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
399 debug (_('unknown id, ignoring'))
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
400 return
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
401 if type == "SUPPRESS":
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
402 self.current_action_ids.remove(id)
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
403 elif type == "XMLUI":
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
404 self.current_action_ids.remove(id)
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
405 debug (_("XML user interface received"))
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
406 misc = {}
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
407 #FIXME FIXME FIXME: must clean all this crap !
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
408 title = _('Form')
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
409 if data['type'] == 'registration':
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
410 title = _('Registration')
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
411 misc['target'] = data['target']
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
412 misc['action_back'] = self.bridge.gatewayRegister
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
413 ui = XMLUI(self, title=title, xml_data = data['xml'], misc = misc)
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
414 if data['type'] == 'registration':
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
415 ui.show('popup')
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
416 else:
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
417 ui.show('window')
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
418 elif type == "ERROR":
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
419 self.current_action_ids.remove(id)
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
420 self.showPopUp(sat_widgets.Alert(_("Error"), unicode(data["message"]), ok_cb=self.removePopUp)) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
421 elif type == "RESULT":
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
422 self.current_action_ids.remove(id)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
423 if self.current_action_ids_cb.has_key(id):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
424 callback = self.current_action_ids_cb[id]
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
425 del self.current_action_ids_cb[id]
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
426 callback(data)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
427 elif type == "DICT_DICT":
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
428 self.current_action_ids.remove(id)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
429 if self.current_action_ids_cb.has_key(id):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
430 callback = self.current_action_ids_cb[id]
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
431 del self.current_action_ids_cb[id]
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
432 callback(data)
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
433 else:
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
434 error (_("FIXME FIXME FIXME: type [%s] not implemented") % type)
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
435 raise NotImplementedError
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
436
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
437 ##DIALOGS CALLBACKS##
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
438 def onJoinRoom(self, button, edit):
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
439 self.removePopUp()
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
440 room_jid = JID(edit.get_edit_text())
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
441 if room_jid.is_valid():
405
10b4f577d0c0 MUC update to follow wokkel's MUC branch update
Goffi <goffi@goffi.org>
parents: 382
diff changeset
442 self.bridge.joinMUC(room_jid, self.profiles[self.profile]['whoami'].node, {}, self.profile)
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
443 else:
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
444 message = _("'%s' is an invalid JID !") % room_jid
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
445 error (message)
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
446 self.showPopUp(sat_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp))
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
447
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
448 def onAddContact(self, button, edit):
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
449 self.removePopUp()
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
450 jid=JID(edit.get_edit_text())
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
451 if jid.is_valid():
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
452 self.bridge.addContact(jid.short, profile_key=self.profile)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
453 else:
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
454 message = _("'%s' is an invalid JID !") % jid
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
455 error (message)
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
456 self.showPopUp(sat_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp))
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
457
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
458 def onRemoveContact(self, button):
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
459 self.removePopUp()
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
460 info(_("Unsubscribing %s presence"),self.contactList.get_contact())
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
461 self.bridge.delContact(self.contactList.get_contact(), profile_key=self.profile)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
462
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
463 #MENU EVENTS#
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
464 def onConnectRequest(self, menu):
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
465 self.bridge.connect(self.profile)
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
466
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
467 def onDisconnectRequest(self, menu):
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
468 self.bridge.disconnect(self.profile)
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
469
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
470 def onParam(self, menu):
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 422
diff changeset
471 def success(params):
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 422
diff changeset
472 self.addWindow(XMLUI(self,xml_data=params))
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 422
diff changeset
473 def failure(error):
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 422
diff changeset
474 self.showPopUp(sat_widgets.Alert(_("Error"), _("Can't get parameters"), ok_cb=self.removePopUp))
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 422
diff changeset
475 self.bridge.getParamsUI(self.profile, callback=success, errback=failure)
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 422
diff changeset
476
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
477
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
478 def onExitRequest(self, menu):
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
479 QuickApp.onExit(self)
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
480 raise urwid.ExitMainLoop()
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
481
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
482 def onJoinRoomRequest(self, menu):
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
483 """User wants to join a MUC room"""
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
484 pop_up_widget = sat_widgets.InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt = 'room@muc_service.server.tld', cancel_cb=self.removePopUp, ok_cb=self.onJoinRoom)
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
485 self.showPopUp(pop_up_widget)
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
486
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
487 def onFindGatewaysRequest(self, e):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
488 debug(_("Find Gateways request"))
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
489 id = self.bridge.findGateways(self.profiles[self.profile]['whoami'].domain, self.profile)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
490 self.current_action_ids.add(id)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
491 self.current_action_ids_cb[id] = self.onGatewaysFound
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
492
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
493 def onAddContactRequest(self, menu):
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
494 pop_up_widget = sat_widgets.InputDialog(_("Adding a contact"), _("Please enter new contact JID"), default_txt = 'name@server.tld', cancel_cb=self.removePopUp, ok_cb=self.onAddContact)
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
495 self.showPopUp(pop_up_widget)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
496
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
497 def onRemoveContactRequest(self, menu):
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
498 contact = self.contactList.get_contact()
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
499 if not contact:
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
500 self.showPopUp(sat_widgets.Alert(_("Error"), _("You have not selected any contact to delete !"), ok_cb=self.removePopUp))
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
501 else:
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
502 pop_up_widget = sat_widgets.ConfirmDialog(_("Are you sure you want to delete the contact [%s] ?" % contact), yes_cb=self.onRemoveContact, no_cb=self.removePopUp)
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
503 self.showPopUp(pop_up_widget)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
504
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
505 def onAboutRequest(self, menu):
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
506 self.showPopUp(sat_widgets.Alert(_("About"), const_APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp))
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
507
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
508 #MISC CALLBACKS#
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
509
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
510 def onGatewaysFound(self, data):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
511 """Called when SàT has found the server gateways"""
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
512 target = data['__private__']['target']
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
513 del data['__private__']
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
514 gatewayManager = GatewaysManager(self, data, server=target)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
515 self.addWindow(gatewayManager)
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
516
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
517 sat = PrimitivusApp()
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
518 sat.start()
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
519