Mercurial > libervia-backend
comparison frontends/primitivus/primitivus @ 137:227394eb080c
Primitivus: menu are now managed and fully working
- new class MenuRoller for manager different menus
- Chat window now create is own menu
- some menu items added for general/contact menus
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 16 Jul 2010 20:25:06 +0800 |
parents | 6cad483a6d84 |
children | 80661755ea8d |
comparison
equal
deleted
inserted
replaced
136:d6c0fe7489af | 137:227394eb080c |
---|---|
127 | 127 |
128 def keyHandler(self, input): | 128 def keyHandler(self, input): |
129 if input == 'meta m': | 129 if input == 'meta m': |
130 try: | 130 try: |
131 if self.main_widget.header == None: | 131 if self.main_widget.header == None: |
132 self.main_widget.header = self.menu | 132 self.main_widget.header = self.menu_roller |
133 else: | 133 else: |
134 self.main_widget.header = None | 134 self.main_widget.header = None |
135 except AttributeError: | 135 except AttributeError: |
136 pass | 136 pass |
137 elif input == 'ctrl d' and 'D' in self.bridge.getVersion(): #Debug only for dev versions | 137 elif input == 'ctrl d' and 'D' in self.bridge.getVersion(): #Debug only for dev versions |
158 else: | 158 else: |
159 if 'save_main_widget' in dir(self): | 159 if 'save_main_widget' in dir(self): |
160 self.loop.widget = self.save_main_widget | 160 self.loop.widget = self.save_main_widget |
161 del self.save_main_widget | 161 del self.save_main_widget |
162 try: | 162 try: |
163 return self.menu.checkShortcuts(input) | 163 return self.menu_roller.checkShortcuts(input) |
164 except AttributeError: | 164 except AttributeError: |
165 return input | 165 return input |
166 | 166 |
167 def __buildMainMenu(self): | 167 def __buildMenuRoller(self): |
168 menu = custom_widgets.Menu(self.loop) | 168 menu = custom_widgets.Menu(self.loop) |
169 connect = _("Connect") | 169 general = _("General") |
170 menu.addMenu(connect, connect, self.onConnectRequest) | 170 menu.addMenu(general, _("Connect"), self.onConnectRequest) |
171 menu.addMenu(connect, _("Disconnect"), self.onDisconnectRequest) | 171 menu.addMenu(general, _("Disconnect"), self.onDisconnectRequest) |
172 menu.addMenu(connect, _("Exit"), self.onExitRequest, 'ctrl x') | 172 menu.addMenu(general, _("About"), self.onAboutRequest) |
173 menu.addMenu(general, _("Exit"), self.onExitRequest, 'ctrl x') | |
174 contact = _("Contact") | |
175 menu.addMenu(contact, _("Add contact"), self.onAddContactRequest) | |
176 menu.addMenu(contact, _("Remove contact"), self.onRemoveContactRequest) | |
173 communication = _("Communication") | 177 communication = _("Communication") |
174 menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j') | 178 menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j') |
175 return menu | 179 menu_roller = custom_widgets.MenuRoller([(_('Main menu'),menu)]) |
180 return menu_roller | |
176 | 181 |
177 def __buildMainWidget(self): | 182 def __buildMainWidget(self): |
178 self.contactList = ContactList(self, self.CM, on_click = self.contactSelected, on_change=lambda w: self.redraw()) | 183 self.contactList = ContactList(self, self.CM, on_click = self.contactSelected, on_change=lambda w: self.redraw()) |
179 #self.center_part = urwid.Columns([('weight',2,self.contactList),('weight',8,Chat('',self))]) | 184 #self.center_part = urwid.Columns([('weight',2,self.contactList),('weight',8,Chat('',self))]) |
180 self.center_part = urwid.Columns([('weight',2,self.contactList), ('weight',8,urwid.Filler(urwid.Text('')))]) | 185 self.center_part = urwid.Columns([('weight',2,self.contactList), ('weight',8,urwid.Filler(urwid.Text('')))]) |
181 editBar = custom_widgets.AdvancedEdit('> ') | 186 editBar = custom_widgets.AdvancedEdit('> ') |
182 urwid.connect_signal(editBar,'click',self.onTextEntered) | 187 urwid.connect_signal(editBar,'click',self.onTextEntered) |
183 self.menu = self.__buildMainMenu() | 188 self.menu_roller = self.__buildMenuRoller() |
184 self.main_widget = custom_widgets.FocusFrame(self.center_part, header=self.menu, footer=editBar, focus_part='footer') | 189 self.main_widget = custom_widgets.FocusFrame(self.center_part, header=self.menu_roller, footer=editBar, focus_part='footer') |
185 return self.main_widget | 190 return self.main_widget |
186 | 191 |
187 def plug_profile(self, profile_key='@DEFAULT@'): | 192 def plug_profile(self, profile_key='@DEFAULT@'): |
188 self.loop.widget = self.__buildMainWidget() | 193 self.loop.widget = self.__buildMainWidget() |
189 QuickApp.plug_profile(self, profile_key) | 194 QuickApp.plug_profile(self, profile_key) |
197 | 202 |
198 def contactSelected(self, contact_list): | 203 def contactSelected(self, contact_list): |
199 contact = contact_list.get_contact() | 204 contact = contact_list.get_contact() |
200 if contact: | 205 if contact: |
201 assert(len(self.center_part.widget_list)==2) | 206 assert(len(self.center_part.widget_list)==2) |
202 #self.center_part.widget_list.append(self.chat_wins[contact]) | |
203 #self.center_part.column_types.append(('weight',8)) | |
204 self.center_part.widget_list[1] = self.chat_wins[contact] | 207 self.center_part.widget_list[1] = self.chat_wins[contact] |
208 self.menu_roller.addMenu(_('Chat Menu'), self.chat_wins[contact].getMenu()) | |
205 | 209 |
206 def onTextEntered(self, editBar): | 210 def onTextEntered(self, editBar): |
207 """Called when text is entered in the main edit bar""" | 211 """Called when text is entered in the main edit bar""" |
208 contact = self.contactList.get_contact() ###Based on the fact that there is currently only one contact selectableat once | 212 contact = self.contactList.get_contact() ###Based on the fact that there is currently only one contact selectableat once |
209 if contact: | 213 if contact: |
230 else: | 234 else: |
231 message = _("'%s' is an invalid JID !") % room_jid | 235 message = _("'%s' is an invalid JID !") % room_jid |
232 error (message) | 236 error (message) |
233 custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp) | 237 custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp) |
234 | 238 |
239 def onAddContact(self, button, edit): | |
240 self.removePopUp() | |
241 jid=JID(edit.get_edit_text()) | |
242 if jid.is_valid(): | |
243 self.bridge.addContact(jid.short, profile_key=self.profile) | |
244 else: | |
245 message = _("'%s' is an invalid JID !") % jid | |
246 error (message) | |
247 custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp) | |
248 | |
249 def onRemoveContact(self, button): | |
250 self.removePopUp() | |
251 info(_("Unsubscribing %s presence"),self.contactList.get_contact()) | |
252 self.bridge.delContact(self.contactList.get_contact(), profile_key=self.profile) | |
253 | |
235 #Menu events# | 254 #Menu events# |
236 def onConnectRequest(self, menu): | 255 def onConnectRequest(self, menu): |
237 self.bridge.connect(self.profile) | 256 self.bridge.connect(self.profile) |
238 | 257 |
239 def onDisconnectRequest(self, menu): | 258 def onDisconnectRequest(self, menu): |
245 def onJoinRoomRequest(self, menu): | 264 def onJoinRoomRequest(self, menu): |
246 """User wants to join a MUC room""" | 265 """User wants to join a MUC room""" |
247 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) | 266 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) |
248 self.showPopUp(pop_up_widget) | 267 self.showPopUp(pop_up_widget) |
249 | 268 |
269 def onAddContactRequest(self, menu): | |
270 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) | |
271 self.showPopUp(pop_up_widget) | |
272 | |
273 def onRemoveContactRequest(self, menu): | |
274 contact = self.contactList.get_contact() | |
275 if not contact: | |
276 self.showPopUp(custom_widgets.Alert(_("Error"), _("You have not selected any contact to delete !"), ok_cb=self.removePopUp)) | |
277 else: | |
278 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) | |
279 self.showPopUp(pop_up_widget) | |
280 | |
281 | |
282 | |
283 | |
284 def onAboutRequest(self, menu): | |
285 self.showPopUp(custom_widgets.Alert(_("About"), const_APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp)) | |
286 | |
287 | |
250 sat = PrimitivusApp() | 288 sat = PrimitivusApp() |
251 sat.start() | 289 sat.start() |
252 | 290 |