comparison frontends/src/wix/main_window.py @ 1093:11e2bb20e896

core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
author Goffi <goffi@goffi.org>
date Thu, 26 Jun 2014 00:05:20 +0200
parents 6ec513ad92c2
children a096b8579a3c
comparison
equal deleted inserted replaced
1092:0eefc74c346b 1093:11e2bb20e896
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 20
21 from sat.core.i18n import _ 21 from sat.core.i18n import _
22 from sat_frontends.wix.constants import Const as C
22 from sat_frontends.quick_frontend.quick_chat_list import QuickChatList 23 from sat_frontends.quick_frontend.quick_chat_list import QuickChatList
23 from sat_frontends.quick_frontend.quick_app import QuickApp 24 from sat_frontends.quick_frontend.quick_app import QuickApp
24 import wx 25 import wx
25 from sat_frontends.wix.contact_list import ContactList 26 from sat_frontends.wix.contact_list import ContactList
26 from sat_frontends.wix.chat import Chat 27 from sat_frontends.wix.chat import Chat
88 89
89 90
90 #events 91 #events
91 self.Bind(wx.EVT_CLOSE, self.onClose, self) 92 self.Bind(wx.EVT_CLOSE, self.onClose, self)
92 93
93 #menus
94 self.createMenus()
95 for i in range(self.menuBar.GetMenuCount()):
96 self.menuBar.EnableTop(i, False)
97 94
98 #profile panel 95 #profile panel
99 self.profile_pan = ProfileManager(self) 96 self.profile_pan = ProfileManager(self)
100 self.sizer.Add(self.profile_pan, 1, flag=wx.EXPAND) 97 self.sizer.Add(self.profile_pan, 1, flag=wx.EXPAND)
101 98
107 """Hide profile panel then plug profile""" 104 """Hide profile panel then plug profile"""
108 log.debug (_('plugin profile %s' % profile_key)) 105 log.debug (_('plugin profile %s' % profile_key))
109 self.profile_pan.Hide() 106 self.profile_pan.Hide()
110 self.contact_list.Show() 107 self.contact_list.Show()
111 self.sizer.Layout() 108 self.sizer.Layout()
112 for i in range(self.menuBar.GetMenuCount()):
113 self.menuBar.EnableTop(i, True)
114 super(MainWindow, self).plug_profile_1(profile_key) 109 super(MainWindow, self).plug_profile_1(profile_key)
110 #menus
111 self.createMenus()
112
113 def addMenus(self, menubar, type_, menu_data=None):
114 """Add cached menus to instance
115 @param menu: wx.MenuBar instance
116 @param type_: menu type like is sat.core.sat_main.importMenu
117 @param menu_data: data to send with these menus
118
119 """
120 menus = self.profiles[self.profile]['menus'].get(type_,[])
121 for id_, path, path_i18n in menus:
122 if len(path) != 2:
123 raise NotImplementedError("Menu with a path != 2 are not implemented yet")
124 category = path_i18n[0] # TODO: manage path with more than 2 levels
125 name = path_i18n[1]
126 menu_idx = menubar.FindMenu(category)
127 current_menu = None
128 if menu_idx == wx.NOT_FOUND:
129 #the menu is new, we create it
130 current_menu = wx.Menu()
131 menubar.Append(current_menu, category)
132 else:
133 current_menu = menubar.GetMenu(menu_idx)
134 assert(current_menu != None)
135 item_id = wx.NewId()
136 help_string = self.bridge.getMenuHelp(id_, '')
137 current_menu.Append(item_id, name, help=help_string)
138 #now we register the event
139 def event_answer(e, id_=id_):
140 self.launchAction(id_, menu_data, profile_key = self.profile)
141
142 wx.EVT_MENU(menubar.Parent, item_id, event_answer)
115 143
116 def createMenus(self): 144 def createMenus(self):
117 log.info(_("Creating menus")) 145 log.info(_("Creating menus"))
118 connectMenu = wx.Menu() 146 connectMenu = wx.Menu()
119 connectMenu.Append(idCONNECT, _("&Connect CTRL-c"),_(" Connect to the server")) 147 connectMenu.Append(idCONNECT, _("&Connect CTRL-c"),_(" Connect to the server"))
131 self.menuBar.Append(communicationMenu,_("&Communication")) 159 self.menuBar.Append(communicationMenu,_("&Communication"))
132 self.SetMenuBar(self.menuBar) 160 self.SetMenuBar(self.menuBar)
133 161
134 #additionals menus 162 #additionals menus
135 #FIXME: do this in a more generic way (in quickapp) 163 #FIXME: do this in a more generic way (in quickapp)
136 add_menus = self.bridge.getMenus('', Const.NO_SECURITY_LIMIT) 164 self.addMenus(self.menuBar, C.MENU_GLOBAL)
137 for id_, type_, path, path_i18n in add_menus:
138 assert(type_=="NORMAL") #TODO: manage other types
139 if len(path) != 2:
140 raise NotImplementedError("Menu with a path != 2 are not implemented yet")
141 category = path_i18n[0] # TODO: manage path with more than 2 levels
142 name = path_i18n[1]
143 menu_idx = self.menuBar.FindMenu(category)
144 current_menu = None
145 if menu_idx == wx.NOT_FOUND:
146 #the menu is new, we create it
147 current_menu = wx.Menu()
148 self.menuBar.Append(current_menu, category)
149 else:
150 current_menu = self.menuBar.GetMenu(menu_idx)
151 assert(current_menu != None)
152 item_id = wx.NewId()
153 help_string = self.bridge.getMenuHelp(id_, '')
154 current_menu.Append(item_id, name, help=help_string)
155 #now we register the event
156 def event_answer(e, id_=id_):
157 self.launchAction(id_, None, profile_key = self.profile)
158
159 wx.EVT_MENU(self, item_id, event_answer)
160 165
161 # menu items that should be displayed after the automatically added ones 166 # menu items that should be displayed after the automatically added ones
162 contactMenu.AppendSeparator() 167 contactMenu.AppendSeparator()
163 contactMenu.Append(idSHOW_PROFILE, _("&Show profile"), _(" Show contact's profile")) 168 contactMenu.Append(idSHOW_PROFILE, _("&Show profile"), _(" Show contact's profile"))
164 169