Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
118:76055a209ed9 | 119:ded2431cea5a |
---|---|
25 from quick_frontend.quick_contact_list import QuickContactList | 25 from quick_frontend.quick_contact_list import QuickContactList |
26 from quick_frontend.quick_contact_management import QuickContactManagement | 26 from quick_frontend.quick_contact_management import QuickContactManagement |
27 import urwid | 27 import urwid |
28 from profile_manager import ProfileManager | 28 from profile_manager import ProfileManager |
29 from contact_list import ContactList | 29 from contact_list import ContactList |
30 from custom_widgets import AdvancedEdit | 30 from chat import Chat |
31 from custom_widgets import AdvancedEdit,FocusFrame | |
31 import pdb | 32 import pdb |
32 """from window import Window | 33 """from window import Window |
33 from editbox import EditBox | 34 from editbox import EditBox |
34 from statusbar import StatusBar | 35 from statusbar import StatusBar |
35 from chat import Chat | 36 from chat import Chat |
58 ('selected_focus', 'default,bold', 'dark red'), | 59 ('selected_focus', 'default,bold', 'dark red'), |
59 ('default', 'default', 'default'), | 60 ('default', 'default', 'default'), |
60 ('default_focus', 'default,bold', 'default'), | 61 ('default_focus', 'default,bold', 'default'), |
61 ] | 62 ] |
62 | 63 |
64 class ChatList(QuickChatList): | |
65 """This class manage the list of chat windows""" | |
66 | |
67 def __init__(self, host): | |
68 QuickChatList.__init__(self, host) | |
69 | |
70 def createChat(self, target): | |
71 return Chat(target, self.host) | |
72 | |
63 class PrimitivusApp(QuickApp): | 73 class PrimitivusApp(QuickApp): |
64 | 74 |
65 def __init__(self): | 75 def __init__(self): |
66 self.CM = QuickContactManagement() #FIXME: not the best place | 76 self.CM = QuickContactManagement() #FIXME: not the best place |
67 QuickApp.__init__(self) #XXX: yes it's an unusual place for the constructor of a parent class, but the init order is important | 77 QuickApp.__init__(self) #XXX: yes it's an unusual place for the constructor of a parent class, but the init order is important |
68 | 78 |
69 ## main loop setup ## | 79 ## main loop setup ## |
70 self.main_widget = ProfileManager(self) | 80 self.main_widget = ProfileManager(self) |
71 self.loop = urwid.MainLoop(self.main_widget, const_PALETTE, event_loop=urwid.GLibEventLoop(), unhandled_input=self.key_handler) | 81 self.loop = urwid.MainLoop(self.main_widget, const_PALETTE, event_loop=urwid.GLibEventLoop(), unhandled_input=self.key_handler) |
72 | 82 |
83 ##misc setup## | |
84 self.chat_wins=ChatList(self) | |
85 | |
86 def debug(self): | |
87 """convenience method to reset screen and launch pdb""" | |
88 import os | |
89 os.system('reset') | |
90 print 'Entered debug mode' | |
91 pdb.set_trace() | |
92 | |
93 def redraw(self): | |
94 """redraw the screen""" | |
95 self.loop.draw_screen() | |
96 | |
73 def start(self): | 97 def start(self): |
98 self.i = 0 | |
99 self.loop.set_alarm_in(0,lambda a,b: self.postInit()) | |
74 self.loop.run() | 100 self.loop.run() |
75 | 101 |
76 def key_handler(self, input): | 102 def key_handler(self, input): |
77 if input in ('q', 'Q') or input == 'ctrl x': | 103 if input in ('q', 'Q') or input == 'ctrl x': |
78 raise urwid.ExitMainLoop() | 104 raise urwid.ExitMainLoop() |
79 | 105 elif input == 'ctrl d' and 'D' in self.bridge.getVersion(): #Debug only for dev versions |
106 self.debug() | |
107 | |
80 def __buildMainWidget(self): | 108 def __buildMainWidget(self): |
81 self.contactList = ContactList(self, self.CM) | 109 self.contactList = ContactList(self, self.CM, on_click = self.contactSelected, on_change=lambda w: self.redraw()) |
82 self.center_part = urwid.Columns([self.contactList]) | 110 #self.center_part = urwid.Columns([('weight',2,self.contactList),('weight',8,Chat('',self))]) |
83 self.main_widget = urwid.Frame(self.center_part, footer=AdvancedEdit('> '), focus_part='footer') | 111 self.center_part = urwid.Columns([('weight',2,self.contactList), ('weight',8,urwid.Filler(urwid.Text('')))]) |
112 editBar = AdvancedEdit('> ') | |
113 urwid.connect_signal(editBar,'click',self.onTextEntered) | |
114 self.main_widget = FocusFrame(self.center_part, footer=editBar, focus_part='footer') | |
84 return self.main_widget | 115 return self.main_widget |
85 | 116 |
86 def plug_profile(self, profile_key='@DEFAULT@'): | 117 def plug_profile(self, profile_key='@DEFAULT@'): |
87 self.loop.widget = self.__buildMainWidget() | 118 self.loop.widget = self.__buildMainWidget() |
88 QuickApp.plug_profile(self, profile_key) | 119 QuickApp.plug_profile(self, profile_key) |
92 | 123 |
93 def showPopUp(self, pop_up_widget): | 124 def showPopUp(self, pop_up_widget): |
94 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', 40), 'middle', ('relative', 40)) | 125 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', 40), 'middle', ('relative', 40)) |
95 self.loop.widget = display_widget | 126 self.loop.widget = display_widget |
96 | 127 |
128 def contactSelected(self, contact_list): | |
129 contact = contact_list.get_contact() | |
130 if contact: | |
131 assert(len(self.center_part.widget_list)==2) | |
132 #self.center_part.widget_list.append(self.chat_wins[contact]) | |
133 #self.center_part.column_types.append(('weight',8)) | |
134 self.center_part.widget_list[1] = self.chat_wins[contact] | |
135 | |
136 def onTextEntered(self, editBar): | |
137 contact = self.contactList.get_contact() | |
138 if contact: | |
139 self.bridge.sendMessage(contact, editBar.get_edit_text(), profile_key=self.profile) | |
140 editBar.set_edit_text('') | |
141 | |
97 sat = PrimitivusApp() | 142 sat = PrimitivusApp() |
98 sat.start() | 143 sat.start() |
99 | 144 |