comparison frontends/primitivus/primitivus @ 131:6cad483a6d84

Primitivus: menu is now working /!\ tooltips not managed yet, doesn't manage properly menu when it's displayed on several rows /!\ still need to manage other menus (chat menu)
author Goffi <goffi@goffi.org>
date Wed, 14 Jul 2010 19:36:40 +0800
parents 542682d67282
children 227394eb080c
comparison
equal deleted inserted replaced
130:5a88ad24ccc0 131:6cad483a6d84
64 ('alert_focus', 'default,bold,underline', 'default'), 64 ('alert_focus', 'default,bold,underline', 'default'),
65 ('date', 'light gray', 'default'), 65 ('date', 'light gray', 'default'),
66 ('my_nick', 'dark red,bold', 'default'), 66 ('my_nick', 'dark red,bold', 'default'),
67 ('other_nick', 'dark cyan,bold', 'default'), 67 ('other_nick', 'dark cyan,bold', 'default'),
68 ('menubar', 'light gray,bold', 'dark red'), 68 ('menubar', 'light gray,bold', 'dark red'),
69 ('selected_menu', 'light gray,bold', 'dark green'),
70 ('menuitem', 'light gray,bold', 'dark red'),
71 ('menuitem_focus', 'light gray,bold', 'dark green'),
69 ] 72 ]
70 73
71 class ChatList(QuickChatList): 74 class ChatList(QuickChatList):
72 """This class manage the list of chat windows""" 75 """This class manage the list of chat windows"""
73 76
89 92
90 ##misc setup## 93 ##misc setup##
91 self.chat_wins=ChatList(self) 94 self.chat_wins=ChatList(self)
92 95
93 def debug(self): 96 def debug(self):
94 """convenience method to reset screen and launch pdb""" 97 """convenient method to reset screen and launch pdb"""
95 import os 98 import os
96 os.system('reset') 99 os.system('reset')
97 print 'Entered debug mode' 100 print 'Entered debug mode'
98 pdb.set_trace() 101 pdb.set_trace()
99 102
100 def write_log(self, log, file_name='/tmp/primitivus_log'): 103 def write_log(self, log, file_name='/tmp/primitivus_log'):
101 #method to write log in a temporary file, useful for debugging 104 """method to write log in a temporary file, useful for debugging"""
102 f=open(file_name, 'a') 105 f=open(file_name, 'a')
103 f.write(log+"\n") 106 f.write(log+"\n")
104 f.close() 107 f.close()
105 108
106 def redraw(self): 109 def redraw(self):
121 if i[1] == 5: #Mouse wheel down 124 if i[1] == 5: #Mouse wheel down
122 input[input.index(i)] = 'down' 125 input[input.index(i)] = 'down'
123 return input 126 return input
124 127
125 def keyHandler(self, input): 128 def keyHandler(self, input):
126 if input in ('q', 'Q') or input == 'ctrl x': 129 if input == 'meta m':
127 raise urwid.ExitMainLoop()
128 elif input == 'meta m':
129 try: 130 try:
130 if self.main_widget.header == None: 131 if self.main_widget.header == None:
131 self.main_widget.header = self.menu 132 self.main_widget.header = self.menu
132 else: 133 else:
133 self.main_widget.header = None 134 self.main_widget.header = None
134 except AttributeError: 135 except AttributeError:
135 pass 136 pass
136 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
137 self.debug() 138 self.debug()
138 elif input == 'meta j': #user wants to join a room
139 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)
140 self.showPopUp(pop_up_widget)
141 elif input == 'f2': #user wants to (un)hide the contact_list 139 elif input == 'f2': #user wants to (un)hide the contact_list
142 try: 140 try:
143 center_widgets = self.center_part.widget_list 141 center_widgets = self.center_part.widget_list
144 if self.contactList in center_widgets: 142 if self.contactList in center_widgets:
145 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 143 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
164 try: 162 try:
165 return self.menu.checkShortcuts(input) 163 return self.menu.checkShortcuts(input)
166 except AttributeError: 164 except AttributeError:
167 return input 165 return input
168 166
167 def __buildMainMenu(self):
168 menu = custom_widgets.Menu(self.loop)
169 connect = _("Connect")
170 menu.addMenu(connect, connect, self.onConnectRequest)
171 menu.addMenu(connect, _("Disconnect"), self.onDisconnectRequest)
172 menu.addMenu(connect, _("Exit"), self.onExitRequest, 'ctrl x')
173 communication = _("Communication")
174 menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j')
175 return menu
176
169 def __buildMainWidget(self): 177 def __buildMainWidget(self):
170 self.contactList = ContactList(self, self.CM, on_click = self.contactSelected, on_change=lambda w: self.redraw()) 178 self.contactList = ContactList(self, self.CM, on_click = self.contactSelected, on_change=lambda w: self.redraw())
171 #self.center_part = urwid.Columns([('weight',2,self.contactList),('weight',8,Chat('',self))]) 179 #self.center_part = urwid.Columns([('weight',2,self.contactList),('weight',8,Chat('',self))])
172 self.center_part = urwid.Columns([('weight',2,self.contactList), ('weight',8,urwid.Filler(urwid.Text('')))]) 180 self.center_part = urwid.Columns([('weight',2,self.contactList), ('weight',8,urwid.Filler(urwid.Text('')))])
173 editBar = custom_widgets.AdvancedEdit('> ') 181 editBar = custom_widgets.AdvancedEdit('> ')
174 urwid.connect_signal(editBar,'click',self.onTextEntered) 182 urwid.connect_signal(editBar,'click',self.onTextEntered)
175 self.menu = custom_widgets.Menu() 183 self.menu = self.__buildMainMenu()
176 self.main_widget = custom_widgets.FocusFrame(self.center_part, header=self.menu, footer=editBar, focus_part='footer') 184 self.main_widget = custom_widgets.FocusFrame(self.center_part, header=self.menu, footer=editBar, focus_part='footer')
177 return self.main_widget 185 return self.main_widget
178 186
179 def plug_profile(self, profile_key='@DEFAULT@'): 187 def plug_profile(self, profile_key='@DEFAULT@'):
180 self.loop.widget = self.__buildMainWidget() 188 self.loop.widget = self.__buildMainWidget()
222 else: 230 else:
223 message = _("'%s' is an invalid JID !") % room_jid 231 message = _("'%s' is an invalid JID !") % room_jid
224 error (message) 232 error (message)
225 custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp) 233 custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp)
226 234
235 #Menu events#
236 def onConnectRequest(self, menu):
237 self.bridge.connect(self.profile)
238
239 def onDisconnectRequest(self, menu):
240 self.bridge.disconnect(self.profile)
241
242 def onExitRequest(self, menu):
243 raise urwid.ExitMainLoop()
244
245 def onJoinRoomRequest(self, menu):
246 """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)
248 self.showPopUp(pop_up_widget)
249
227 sat = PrimitivusApp() 250 sat = PrimitivusApp()
228 sat.start() 251 sat.start()
229 252