Mercurial > libervia-backend
annotate frontends/primitivus/primitivus @ 119:ded2431cea5a
Primitivus: chat window / text sending.
Primitivus has now the most basics features \o/
- core: new getVersion method
- primitivus: new debug key (C-d), only work if SàT is in dev version (D in version)
- quick_app: new post_init method, used for automatique task like auto-plug
- primitivus: lists now use genericList (Box) or List (Flow)
- primitivus: List now manage correctly its size
- primitivus: new FocusFrame widget which manage focus changing with 'tab'
- primitivus: advancedEdit now manage 'click' signal
- primitivus: contactList now manager 'change' and 'click' signals
- primitivus: Chat window now working
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 05 Jul 2010 19:13:36 +0800 |
parents | 76055a209ed9 |
children | 1ca5f254ce41 |
rev | line source |
---|---|
112 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 Primitivus: a SAT frontend | |
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org) | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 | |
23 from quick_frontend.quick_app import QuickApp | |
24 from quick_frontend.quick_chat_list import QuickChatList | |
25 from quick_frontend.quick_contact_list import QuickContactList | |
26 from quick_frontend.quick_contact_management import QuickContactManagement | |
27 import urwid | |
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 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
31 from custom_widgets import AdvancedEdit,FocusFrame |
112 | 32 import pdb |
33 """from window import Window | |
34 from editbox import EditBox | |
35 from statusbar import StatusBar | |
36 from chat import Chat | |
37 from tools.jid import JID""" | |
38 import logging | |
39 from logging import debug, info, error | |
40 #import locale | |
41 import sys, os | |
42 #from curses import ascii | |
43 #import locale | |
44 #from signal import signal, SIGWINCH | |
45 #import fcntl | |
46 #import struct | |
47 #import termios | |
48 #from boxsizer import BoxSizer | |
49 | |
50 | |
51 ### logging configuration FIXME: put this elsewhere ### | |
52 logging.basicConfig(level=logging.CRITICAL, #TODO: configure it to put messages in a log file | |
53 format='%(message)s') | |
54 ### | |
55 | |
56 const_APP_NAME = "Primitivus" | |
113 | 57 const_PALETTE = [('title', 'black', 'light gray', 'standout,underline'), |
58 ('selected', 'default', 'dark red'), | |
59 ('selected_focus', 'default,bold', 'dark red'), | |
60 ('default', 'default', 'default'), | |
61 ('default_focus', 'default,bold', 'default'), | |
62 ] | |
112 | 63 |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
64 class ChatList(QuickChatList): |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
65 """This class manage the list of chat windows""" |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
66 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
67 def __init__(self, host): |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
68 QuickChatList.__init__(self, host) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
69 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
70 def createChat(self, target): |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
71 return Chat(target, self.host) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
72 |
112 | 73 class PrimitivusApp(QuickApp): |
74 | |
75 def __init__(self): | |
116
7c482ecac0ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
76 self.CM = QuickContactManagement() #FIXME: not the best place |
112 | 77 QuickApp.__init__(self) #XXX: yes it's an unusual place for the constructor of a parent class, but the init order is important |
78 | |
79 ## main loop setup ## | |
117 | 80 self.main_widget = ProfileManager(self) |
112 | 81 self.loop = urwid.MainLoop(self.main_widget, const_PALETTE, event_loop=urwid.GLibEventLoop(), unhandled_input=self.key_handler) |
82 | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
83 ##misc setup## |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
84 self.chat_wins=ChatList(self) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
85 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
86 def debug(self): |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
87 """convenience method to reset screen and launch pdb""" |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
88 import os |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
89 os.system('reset') |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
90 print 'Entered debug mode' |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
91 pdb.set_trace() |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
92 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
93 def redraw(self): |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
94 """redraw the screen""" |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
95 self.loop.draw_screen() |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
96 |
112 | 97 def start(self): |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
98 self.i = 0 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
99 self.loop.set_alarm_in(0,lambda a,b: self.postInit()) |
112 | 100 self.loop.run() |
101 | |
102 def key_handler(self, input): | |
103 if input in ('q', 'Q') or input == 'ctrl x': | |
104 raise urwid.ExitMainLoop() | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
105 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
|
106 self.debug() |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
107 |
112 | 108 def __buildMainWidget(self): |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
109 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
|
110 #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
|
111 self.center_part = urwid.Columns([('weight',2,self.contactList), ('weight',8,urwid.Filler(urwid.Text('')))]) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
112 editBar = AdvancedEdit('> ') |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
113 urwid.connect_signal(editBar,'click',self.onTextEntered) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
114 self.main_widget = FocusFrame(self.center_part, footer=editBar, focus_part='footer') |
118
76055a209ed9
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
115 return self.main_widget |
112 | 116 |
116
7c482ecac0ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
117 def plug_profile(self, profile_key='@DEFAULT@'): |
118
76055a209ed9
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
118 self.loop.widget = self.__buildMainWidget() |
116
7c482ecac0ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
119 QuickApp.plug_profile(self, profile_key) |
117 | 120 |
121 def removePopUp(self): | |
122 self.loop.widget = self.main_widget | |
123 | |
124 def showPopUp(self, pop_up_widget): | |
125 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', 40), 'middle', ('relative', 40)) | |
126 self.loop.widget = display_widget | |
112 | 127 |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
128 def contactSelected(self, contact_list): |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
129 contact = contact_list.get_contact() |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
130 if contact: |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
131 assert(len(self.center_part.widget_list)==2) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
132 #self.center_part.widget_list.append(self.chat_wins[contact]) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
133 #self.center_part.column_types.append(('weight',8)) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
134 self.center_part.widget_list[1] = self.chat_wins[contact] |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
135 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
136 def onTextEntered(self, editBar): |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
137 contact = self.contactList.get_contact() |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
138 if contact: |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
139 self.bridge.sendMessage(contact, editBar.get_edit_text(), profile_key=self.profile) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
140 editBar.set_edit_text('') |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
118
diff
changeset
|
141 |
112 | 142 sat = PrimitivusApp() |
143 sat.start() | |
117 | 144 |