comparison frontends/primitivus/primitivus @ 120:1ca5f254ce41

primitivus group chat & misc primitivus: new widget: SurroundedText (text with a character repeated around it) primitivus: new decorator LabelLine (like lineBox, but with a label on the top line) wix & primitivus & quick_app: group chat method move to quick_chat wix: when new message, window is not raised anymore, but RequestUserAttention is called instead
author Goffi <goffi@goffi.org>
date Thu, 08 Jul 2010 14:12:18 +0800
parents ded2431cea5a
children 961e0898271f
comparison
equal deleted inserted replaced
119:ded2431cea5a 120:1ca5f254ce41
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 chat import Chat 30 from chat import Chat
31 from custom_widgets import AdvancedEdit,FocusFrame 31 from custom_widgets import AdvancedEdit,FocusFrame,InputDialog,Alert
32 import pdb 32 import pdb
33 """from window import Window 33 """from window import Window
34 from editbox import EditBox 34 from editbox import EditBox
35 from statusbar import StatusBar 35 from statusbar import StatusBar
36 from chat import Chat 36 from chat import Chat
37 from tools.jid import JID""" 37 from tools.jid import JID"""
38 import logging 38 import logging
39 from logging import debug, info, error 39 from logging import debug, info, error
40 #import locale 40 #import locale
41 import sys, os 41 import sys, os
42 from tools.jid import JID
42 #from curses import ascii 43 #from curses import ascii
43 #import locale 44 #import locale
44 #from signal import signal, SIGWINCH 45 #from signal import signal, SIGWINCH
45 #import fcntl 46 #import fcntl
46 #import struct 47 #import struct
102 def key_handler(self, input): 103 def key_handler(self, input):
103 if input in ('q', 'Q') or input == 'ctrl x': 104 if input in ('q', 'Q') or input == 'ctrl x':
104 raise urwid.ExitMainLoop() 105 raise urwid.ExitMainLoop()
105 elif input == 'ctrl d' and 'D' in self.bridge.getVersion(): #Debug only for dev versions 106 elif input == 'ctrl d' and 'D' in self.bridge.getVersion(): #Debug only for dev versions
106 self.debug() 107 self.debug()
108 elif input == 'meta j': #user wants to join a room
109 pop_up_widget = InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt = 'test@conference.necton2.int', cancel_cb=self.removePopUp, ok_cb=self.onJoinRoom)
110 self.showPopUp(pop_up_widget)
107 111
108 def __buildMainWidget(self): 112 def __buildMainWidget(self):
109 self.contactList = ContactList(self, self.CM, on_click = self.contactSelected, on_change=lambda w: self.redraw()) 113 self.contactList = ContactList(self, self.CM, on_click = self.contactSelected, on_change=lambda w: self.redraw())
110 #self.center_part = urwid.Columns([('weight',2,self.contactList),('weight',8,Chat('',self))]) 114 #self.center_part = urwid.Columns([('weight',2,self.contactList),('weight',8,Chat('',self))])
111 self.center_part = urwid.Columns([('weight',2,self.contactList), ('weight',8,urwid.Filler(urwid.Text('')))]) 115 self.center_part = urwid.Columns([('weight',2,self.contactList), ('weight',8,urwid.Filler(urwid.Text('')))])
116 120
117 def plug_profile(self, profile_key='@DEFAULT@'): 121 def plug_profile(self, profile_key='@DEFAULT@'):
118 self.loop.widget = self.__buildMainWidget() 122 self.loop.widget = self.__buildMainWidget()
119 QuickApp.plug_profile(self, profile_key) 123 QuickApp.plug_profile(self, profile_key)
120 124
121 def removePopUp(self): 125 def removePopUp(self, widget=None):
122 self.loop.widget = self.main_widget 126 self.loop.widget = self.main_widget
123 127
124 def showPopUp(self, pop_up_widget): 128 def showPopUp(self, pop_up_widget):
125 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', 40), 'middle', ('relative', 40)) 129 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', 40), 'middle', ('relative', 40))
126 self.loop.widget = display_widget 130 self.loop.widget = display_widget
132 #self.center_part.widget_list.append(self.chat_wins[contact]) 136 #self.center_part.widget_list.append(self.chat_wins[contact])
133 #self.center_part.column_types.append(('weight',8)) 137 #self.center_part.column_types.append(('weight',8))
134 self.center_part.widget_list[1] = self.chat_wins[contact] 138 self.center_part.widget_list[1] = self.chat_wins[contact]
135 139
136 def onTextEntered(self, editBar): 140 def onTextEntered(self, editBar):
137 contact = self.contactList.get_contact() 141 """Called when text is entered in the main edit bar"""
142 contact = self.contactList.get_contact() ###Based on the fact that there is currently only one contact selectableat once
138 if contact: 143 if contact:
139 self.bridge.sendMessage(contact, editBar.get_edit_text(), profile_key=self.profile) 144 chat = self.chat_wins[contact]
145 self.bridge.sendMessage(contact,
146 editBar.get_edit_text(),
147 type = "groupchat" if chat.type == 'group' else "chat",
148 profile_key=self.profile)
140 editBar.set_edit_text('') 149 editBar.set_edit_text('')
150
151 def onJoinRoom(self, button, edit):
152 self.removePopUp()
153 room_jid = JID(edit.get_edit_text())
154 if room_jid.is_valid():
155 self.bridge.joinMUC(room_jid.domain, room_jid.node, self.profiles[self.profile]['whoami'].node, self.profile)
156 else:
157 message = _("'%s' is an invalid JID !") % room_jid
158 error (message)
159 Alert(_("Error"), message, ok_cb=self.removePopUp)
141 160
142 sat = PrimitivusApp() 161 sat = PrimitivusApp()
143 sat.start() 162 sat.start()
144 163