annotate frontends/primitivus/primitivus @ 176:a50953ac6191

Primitivus: send_file first draft - a new dialog for choosing a file is work in progress
author Goffi <goffi@goffi.org>
date Thu, 12 Aug 2010 23:09:31 +0800
parents ec6611445a5b
children fdb961f27ae9
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
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
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 from quick_frontend.quick_app import QuickApp
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from quick_frontend.quick_chat_list import QuickChatList
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from quick_frontend.quick_contact_list import QuickContactList
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from quick_frontend.quick_contact_management import QuickContactManagement
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 import urwid
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from profile_manager import ProfileManager
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 113
diff changeset
29 from contact_list import ContactList
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
30 from chat import Chat
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
31 from gateways import GatewaysManager
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
32 import custom_widgets
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 import pdb
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 import logging
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 from logging import debug, info, error
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 import sys, os
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
37 from tools.jid import JID
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
38 from xmlui import XMLUI
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 ### logging configuration FIXME: put this elsewhere ###
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 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
43 format='%(message)s')
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 ###
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 const_APP_NAME = "Primitivus"
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
47 const_PALETTE = [('title', 'black', 'light gray', 'standout,underline'),
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
48 ('selected', 'default', 'dark red'),
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
49 ('selected_focus', 'default,bold', 'dark red'),
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
50 ('default', 'default', 'default'),
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
51 ('default_focus', 'default,bold', 'default'),
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
52 ('alert', 'default,underline', 'default'),
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
53 ('alert_focus', 'default,bold,underline', 'default'),
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
54 ('date', 'light gray', 'default'),
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
55 ('my_nick', 'dark red,bold', 'default'),
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
56 ('other_nick', 'dark cyan,bold', 'default'),
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
57 ('menubar', 'light gray,bold', 'dark red'),
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
58 ('selected_menu', 'light gray,bold', 'dark green'),
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
59 ('menuitem', 'light gray,bold', 'dark red'),
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
60 ('menuitem_focus', 'light gray,bold', 'dark green'),
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
61 ('notifs', 'black,bold', 'yellow'),
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
62 ('card_neutral', 'dark gray', 'white', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
63 ('card_neutral_selected', 'dark gray', 'dark green', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
64 ('card_special', 'brown', 'white', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
65 ('card_special_selected', 'brown', 'dark green', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
66 ('card_red', 'dark red', 'white', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
67 ('card_red_selected', 'dark red', 'dark green', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
68 ('card_black', 'black', 'white', 'standout,underline'),
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
69 ('card_black_selected', 'black', 'dark green', 'standout,underline'),
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
70 ]
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
72 class ChatList(QuickChatList):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
73 """This class manage the list of chat windows"""
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
74
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
75 def __init__(self, host):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
76 QuickChatList.__init__(self, host)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
77
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
78 def createChat(self, target):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
79 return Chat(target, self.host)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
80
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 class PrimitivusApp(QuickApp):
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 def __init__(self):
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 113
diff changeset
84 self.CM = QuickContactManagement() #FIXME: not the best place
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
85 QuickApp.__init__(self)
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 ## main loop setup ##
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
88 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
89 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
90
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
91 ##misc setup##
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
92 self.chat_wins=ChatList(self)
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
93 self.notBar = custom_widgets.NotificationBar()
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
94 urwid.connect_signal(self.notBar,'change',self.onNotification)
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
95 self.__saved_overlay = None
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
96
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
97 def debug(self):
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
98 """convenient method to reset screen and launch pdb"""
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
99 import os
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
100 os.system('reset')
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
101 print 'Entered debug mode'
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
102 pdb.set_trace()
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
103
129
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
104 def write_log(self, log, file_name='/tmp/primitivus_log'):
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
105 """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
106 with open(file_name, 'a') as f:
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 153
diff changeset
107 f.write(log+"\n")
129
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
108
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
109 def redraw(self):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
110 """redraw the screen"""
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
111 self.loop.draw_screen()
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
112
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113 def start(self):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
114 self.i = 0
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
115 self.loop.set_alarm_in(0,lambda a,b: self.postInit())
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116 self.loop.run()
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117
127
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
118 def inputFilter(self, input, raw):
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
119 if self.__saved_overlay and input != ['ctrl s']:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
120 return
127
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
121 for i in input:
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
122 if isinstance(i,tuple):
127
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
123 if i[0] == 'mouse press':
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
124 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
125 input[input.index(i)] = 'up'
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
126 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
127 input[input.index(i)] = 'down'
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
128 return input
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
129
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
130 def keyHandler(self, input):
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
131 if input == 'meta m':
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
132 try:
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
133 if self.main_widget.header == None:
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
134 self.main_widget.header = self.menu_roller
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
135 else:
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
136 self.main_widget.header = None
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
137 except AttributeError:
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
138 pass
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
139 elif input == 'ctrl n':
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
140 """User wants to see next notification"""
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
141 self.notBar.showNext()
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
142 elif input == 'ctrl s':
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
143 """User wants to (un)hide overlay window"""
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
144 if isinstance(self.loop.widget,urwid.Overlay):
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
145 self.__saved_overlay = self.loop.widget
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
146 self.loop.widget = self.main_widget
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
147 else:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
148 if self.__saved_overlay:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
149 self.loop.widget = self.__saved_overlay
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
150 self.__saved_overlay = None
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
151
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
152 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
153 self.debug()
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
154 elif input == 'f2': #user wants to (un)hide the contact_list
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
155 try:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
156 center_widgets = self.center_part.widget_list
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
157 if self.contactList in center_widgets:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
158 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
159 center_widgets.remove(self.contactList)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
160 del self.center_part.column_types[0]
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
161 else:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
162 center_widgets.insert(0, self.contactList)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
163 self.center_part.column_types.insert(0, ('weight', 2))
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
164 except AttributeError:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
165 #The main widget is not built (probably in Profile Manager)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
166 pass
129
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
167 elif input == 'window resize':
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
168 width,height = self.loop.screen_size
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
169 if height<=5 and width<=35:
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
170 if not 'save_main_widget' in dir(self):
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
171 self.save_main_widget = self.loop.widget
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
172 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
173 else:
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
174 if 'save_main_widget' in dir(self):
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
175 self.loop.widget = self.save_main_widget
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
176 del self.save_main_widget
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
177 try:
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
178 return self.menu_roller.checkShortcuts(input)
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
179 except AttributeError:
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
180 return input
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
181
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
182 def __buildMenuRoller(self):
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
183 menu = custom_widgets.Menu(self.loop)
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
184 general = _("General")
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
185 menu.addMenu(general, _("Connect"), self.onConnectRequest)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
186 menu.addMenu(general, _("Disconnect"), self.onDisconnectRequest)
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
187 menu.addMenu(general, _("Parameters"), self.onParam)
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
188 menu.addMenu(general, _("About"), self.onAboutRequest)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
189 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
190 contact = _("Contact")
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
191 menu.addMenu(contact, _("Add contact"), self.onAddContactRequest)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
192 menu.addMenu(contact, _("Remove contact"), self.onRemoveContactRequest)
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
193 communication = _("Communication")
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
194 menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j')
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
195 menu.addMenu(communication, _("Find Gateways"), self.onFindGatewaysRequest, 'meta g')
145
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
196 #additionals menus
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
197 #FIXME: do this in a more generic way (in quickapp)
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
198 add_menus = self.bridge.getMenus()
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
199 def add_menu_cb(menu):
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
200 category, item = menu
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
201 id = self.bridge.callMenu(category, item, "NORMAL")
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
202 self.current_action_ids.add(id)
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
203 for new_menu in add_menus:
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
204 category,item,type = new_menu
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
205 assert(type=="NORMAL") #TODO: manage other types
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
206 menu.addMenu(category, item, add_menu_cb)
c8b231abfe96 Primitivus: additionnal menus management
Goffi <goffi@goffi.org>
parents: 144
diff changeset
207
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
208 menu_roller = custom_widgets.MenuRoller([(_('Main menu'),menu)])
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
209 return menu_roller
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
210
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
211 def __buildMainWidget(self):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
212 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
213 #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
214 self.center_part = urwid.Columns([('weight',2,self.contactList), ('weight',8,urwid.Filler(urwid.Text('')))])
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
215 self.editBar = custom_widgets.AdvancedEdit('> ')
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
216 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
217 self.menu_roller = self.__buildMenuRoller()
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
218 self.main_widget = custom_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
219 return self.main_widget
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
220
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 113
diff changeset
221 def plug_profile(self, profile_key='@DEFAULT@'):
118
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
222 self.loop.widget = self.__buildMainWidget()
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 113
diff changeset
223 QuickApp.plug_profile(self, profile_key)
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
224
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
225 def removePopUp(self, widget=None):
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
226 "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
227 self.loop.widget = self.main_widget
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
228 next_popup = self.notBar.getNextPopup()
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
229 if next_popup:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
230 #we still have popup to show, we display it
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
231 self.showPopUp(next_popup)
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
232
176
a50953ac6191 Primitivus: send_file first draft
Goffi <goffi@goffi.org>
parents: 173
diff changeset
233 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
234 "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
235 if not isinstance(self.loop.widget,urwid.Overlay):
176
a50953ac6191 Primitivus: send_file first draft
Goffi <goffi@goffi.org>
parents: 173
diff changeset
236 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
237 self.loop.widget = display_widget
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
238 else:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
239 self.notBar.addPopUp(pop_up_widget)
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
240
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
241 def notify(self, message):
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
242 """"Notify message to user via notification bar"""
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
243 self.notBar.addMessage(message)
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
244
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
245 def addWindow(self, widget):
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
246 """Display a window if possible,
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
247 else add it in the notification bar queue
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
248 @param widget: BoxWidget"""
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
249 assert(len(self.center_part.widget_list)<=2)
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
250 wid_idx = len(self.center_part.widget_list)-1
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
251 self.center_part.widget_list[wid_idx] = widget
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
252 self.menu_roller.removeMenu(_('Chat menu'))
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
253 self.contactList.unselectAll()
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
254 self.redraw()
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
255
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
256 def removeWindow(self):
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
257 """Remove window showed on the right column"""
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
258 #TODO: to a better Window management than this crappy hack
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
259 assert(len(self.center_part.widget_list)<=2)
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
260 wid_idx = len(self.center_part.widget_list)-1
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
261 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
262 self.center_part.set_focus(0)
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
263 self.redraw()
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
264
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
265 def contactSelected(self, contact_list):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
266 contact = contact_list.get_contact()
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
267 if contact:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
268 assert(len(self.center_part.widget_list)==2)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
269 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
270 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
271
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
272 def onTextEntered(self, editBar):
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
273 """Called when text is entered in the main edit bar"""
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
274 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
275 if contact:
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
276 chat = self.chat_wins[contact]
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
277 self.bridge.sendMessage(contact,
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
278 editBar.get_edit_text(),
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
279 type = "groupchat" if chat.type == 'group' else "chat",
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
280 profile_key=self.profile)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
281 editBar.set_edit_text('')
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
282
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
283 def newMessage(self, from_jid, msg, type, to_jid, profile):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
284 if not self.check_profile(profile):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
285 return
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
286 QuickApp.newMessage(self, from_jid, msg, type, to_jid, profile)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
287 sender = JID(from_jid)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
288 if JID(self.contactList.selected).short != sender.short:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
289 self.contactList.putAlert(sender)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
290
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
291 def onNotification(self, notBar):
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
292 """Called when a new notification has been received"""
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
293 if not isinstance(self.main_widget, custom_widgets.FocusFrame):
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
294 #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
295 return
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
296 if isinstance(self.main_widget.footer,custom_widgets.AdvancedEdit):
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
297 if not self.notBar.canHide():
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
298 #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
299 pile = urwid.Pile([self.notBar, self.editBar])
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
300 self.main_widget.footer = pile
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
301 else:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
302 if not isinstance(self.main_widget.footer, urwid.Pile):
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
303 error(_("INTERNAL ERROR: Unexpected class for main widget's footer"))
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
304 assert(False)
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
305 if self.notBar.canHide():
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
306 #No notification left, we can hide the bar
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
307 self.main_widget.footer = self.editBar
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
308
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
309 def actionResult(self, type, id, data):
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
310 if not id in self.current_action_ids:
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
311 debug (_('unknown id, ignoring'))
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
312 return
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
313 if type == "SUPPRESS":
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
314 self.current_action_ids.remove(id)
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
315 elif type == "XMLUI":
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
316 self.current_action_ids.remove(id)
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
317 debug (_("XML user interface received"))
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
318 misc = {}
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
319 #FIXME FIXME FIXME: must clean all this crap !
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
320 title = _('Form')
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
321 if data['type'] == 'registration':
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
322 title = _('Registration')
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
323 misc['target'] = data['target']
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
324 misc['action_back'] = self.bridge.gatewayRegister
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
325 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
326 if data['type'] == 'registration':
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
327 ui.show('popup')
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
328 else:
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
329 ui.show('window')
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
330 elif type == "ERROR":
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
331 self.current_action_ids.remove(id)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
332 self.showPopUp(custom_widgets.Alert(_("Error"), unicode(data["message"]), ok_cb=self.removePopUp)) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
333 elif type == "RESULT":
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
334 self.current_action_ids.remove(id)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
335 if self.current_action_ids_cb.has_key(id):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
336 callback = self.current_action_ids_cb[id]
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
337 del self.current_action_ids_cb[id]
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
338 callback(data)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
339 elif type == "DICT_DICT":
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
340 self.current_action_ids.remove(id)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
341 if self.current_action_ids_cb.has_key(id):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
342 callback = self.current_action_ids_cb[id]
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
343 del self.current_action_ids_cb[id]
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
344 callback(data)
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
345 else:
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
346 error (_("FIXME FIXME FIXME: type [%s] not implemented") % type)
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
347 raise NotImplementedError
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
348
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
349 ##DIALOGS CALLBACKS##
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
350 def onJoinRoom(self, button, edit):
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
351 self.removePopUp()
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
352 room_jid = JID(edit.get_edit_text())
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
353 if room_jid.is_valid():
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
354 self.bridge.joinMUC(room_jid.domain, room_jid.node, self.profiles[self.profile]['whoami'].node, self.profile)
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
355 else:
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
356 message = _("'%s' is an invalid JID !") % room_jid
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
357 error (message)
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
358 self.showPopUp(custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp))
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
359
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
360 def onAddContact(self, button, edit):
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
361 self.removePopUp()
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
362 jid=JID(edit.get_edit_text())
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
363 if jid.is_valid():
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
364 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
365 else:
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
366 message = _("'%s' is an invalid JID !") % jid
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
367 error (message)
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
368 self.showPopUp(custom_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
369
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
370 def onRemoveContact(self, button):
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
371 self.removePopUp()
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
372 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
373 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
374
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
375 #MENU EVENTS#
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
376 def onConnectRequest(self, menu):
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
377 self.bridge.connect(self.profile)
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
378
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
379 def onDisconnectRequest(self, menu):
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
380 self.bridge.disconnect(self.profile)
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
381
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
382 def onParam(self, menu):
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
383 params = XMLUI(self,xml_data=self.bridge.getParamsUI(self.profile))
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
384 self.addWindow(params)
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
385
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
386 def onExitRequest(self, menu):
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
387 raise urwid.ExitMainLoop()
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
388
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
389 def onJoinRoomRequest(self, menu):
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
390 """User wants to join a MUC room"""
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
391 pop_up_widget = custom_widgets.InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt = 'test@conference.necton2.int', cancel_cb=self.removePopUp, ok_cb=self.onJoinRoom)
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
392 self.showPopUp(pop_up_widget)
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
393
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
394 def onFindGatewaysRequest(self, e):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
395 debug(_("Find Gateways request"))
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
396 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
397 self.current_action_ids.add(id)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
398 self.current_action_ids_cb[id] = self.onGatewaysFound
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
399
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
400 def onAddContactRequest(self, menu):
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
401 pop_up_widget = custom_widgets.InputDialog(_("Adding a contact"), _("Please enter new contact JID"), default_txt = 'name@server.tld', cancel_cb=self.removePopUp, ok_cb=self.onAddContact)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
402 self.showPopUp(pop_up_widget)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
403
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
404 def onRemoveContactRequest(self, menu):
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
405 contact = self.contactList.get_contact()
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
406 if not contact:
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
407 self.showPopUp(custom_widgets.Alert(_("Error"), _("You have not selected any contact to delete !"), ok_cb=self.removePopUp))
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
408 else:
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
409 pop_up_widget = custom_widgets.ConfirmDialog(_("Are you sure you want to delete the contact [%s] ?" % contact), yes_cb=self.onRemoveContact, no_cb=self.removePopUp)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
410 self.showPopUp(pop_up_widget)
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
411
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
412 def onAboutRequest(self, menu):
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
413 self.showPopUp(custom_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
414
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
415 #MISC CALLBACKS#
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
416
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
417 def onGatewaysFound(self, data):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
418 """Called when SàT has found the server gateways"""
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
419 target = data['__private__']['target']
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
420 del data['__private__']
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
421 gatewayManager = GatewaysManager(self, data, server=target)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
422 self.addWindow(gatewayManager)
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
423
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
424 sat = PrimitivusApp()
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
425 sat.start()
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
426