Mercurial > libervia-backend
annotate frontends/src/quick_frontend/quick_menus.py @ 1364:28f0b33ca17c frontends_multi_profiles
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
- there are 2 mains types of menu: MenuItem which can be launched, and MenuCategory which contains other menus
- local menus (from frontend only) and distant menus (from backend and its plugins) are managed
- there is a menu manager which, in a similar ways as for widgets, manages the menus logic and should be instantiated by host
- when a context is necessary (this is the case for most of menus), a data collector is used: it collects data from the caller (the instance linked to the menu) and construct data which is then sent throught bridge
- to have implementation specific to a frontend which override the backend one, there is a MenuHook class
- it is possible to place an expected menu in the desired position with MenuPlaceHolder class
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 17 Mar 2015 19:33:05 +0100 |
parents | |
children | 584d45bb36d9 |
rev | line source |
---|---|
1364
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # helper class for making a SAT frontend |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 try: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 # FIXME: to be removed when an acceptable solution is here |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 unicode('') # XXX: unicode doesn't exist in pyjamas |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 unicode = str |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from sat.core.log import getLogger |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from sat.core.i18n import _, languageSwitch |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 log = getLogger(__name__) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from sat_frontends.quick_frontend.constants import Const as C |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from collections import OrderedDict |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 ## items ## |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 class MenuBase(object): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 ACTIVE=True |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 def __init__(self, name, extra=None): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 @param name(unicode): canonical name of the item |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 @param extra(dict[unicode, unicode], None): same as in [addMenus] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 self._name = name |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 self.setExtra(extra) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 @property |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 def canonical(self): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 """Return the canonical name of the container, used to identify it""" |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 return self._name |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 @property |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 def name(self): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 """Return the name of the container, can be translated""" |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 return self._name |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 def setExtra(self, extra): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 if extra is None: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 extra = {} |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 self.icon = extra.get("icon") |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 class MenuItem(MenuBase): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 """A callable item in the menu""" |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 CALLABLE=False |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 def __init__(self, name, name_i18n, extra=None, type_=None): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 @param name(unicode): canonical name of the item |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 @param name_i18n(unicode): translated name of the item |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 @param extra(dict[unicode, unicode], None): same as in [addMenus] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 @param type_(unicode): same as in [sat.core.sat_main.SAT.importMenu] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 MenuBase.__init__(self, name, extra) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 self._name_i18n = name_i18n if name_i18n else name |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 self.type = type_ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 @property |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 def name(self): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 return self._name_i18n |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 def collectData(self, caller): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 """Get data according to data_collector |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 @param caller: Menu caller |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 assert self.type is not None # if data collector are used, type must be set |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 data_collector = QuickMenusManager.getDataCollector(self.type) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 if data_collector is None: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 return {} |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 elif callable(data_collector): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 return data_collector(caller, self.name) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 else: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 if caller is None: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 log.error(u"Caller can't be None with a dictionary as data_collector") |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 return {} |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 data = {} |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 for data_key, caller_attr in data_collector.iteritems(): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 data[data_key] = unicode(getattr(caller, caller_attr)) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 return data |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 def call(self, caller, profile=C.PROF_KEY_NONE): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 """Execute the menu item |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 @param caller: instance linked to the menu |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 @param profile: %(doc_profile)s |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 raise NotImplementedError |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 class MenuItemDistant(MenuItem): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 """A MenuItem with a distant callback""" |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 CALLABLE=True |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 def __init__(self, host, type_, name, name_i18n, id_, extra=None): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 @param host: %(doc_host)s |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 @param type_(unicode): same as in [sat.core.sat_main.SAT.importMenu] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 @param name(unicode): canonical name of the item |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 @param name_i18n(unicode): translated name of the item |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 @param id_(unicode): id of the distant callback |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 @param extra(dict[unicode, unicode], None): same as in [addMenus] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 MenuItem.__init__(self, name, name_i18n, extra, type_) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 self.host = host |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 self.id = id_ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 def call(self, caller, profile=C.PROF_KEY_NONE): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 data = self.collectData(caller) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 log.debug("data collected: %s" % data) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 self.host.launchAction(self.id, data, profile=profile) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 class MenuItemLocal(MenuItem): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 """A MenuItem with a distant callback""" |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 CALLABLE=True |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 def __init__(self, type_, name, name_i18n, callback, extra=None): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 @param type_(unicode): same as in [sat.core.sat_main.SAT.importMenu] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 @param name(unicode): canonical name of the item |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 @param name_i18n(unicode): translated name of the item |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 @param callback(callable): local callback. Will be called with the caller as only argument if data_collector is None, else with the caller + requested data + profile. |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 @param extra(dict[unicode, unicode], None): same as in [addMenus] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 MenuItem.__init__(self, name, name_i18n, extra, type_) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 self.callback = callback |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 def call(self, caller, profile=C.PROF_KEY_NONE): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 data_collector = QuickMenusManager.getDataCollector(self.type) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 if data_collector is None: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 self.callback() |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 else: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 self.callback(caller, self.collectData(caller), profile) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 class MenuHook(MenuItemLocal): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 """A MenuItem which replace an expected item from backend""" |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 pass |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 class MenuPlaceHolder(MenuItem): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 """A non existant menu which is used to keep a position""" |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 ACTIVE=False |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 def __init__(self, name): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 MenuItem.__init__(self, name, name) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 class MenuSeparator(MenuItem): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 """A separation between items/categories""" |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 SEP_IDX=0 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 def __init__(self): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 MenuSeparator.SEP_IDX +=1 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 name = u"___separator_{}".format(MenuSeparator.SEP_IDX) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 MenuItem.__init__(self, name, name) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 ## containers ## |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 class MenuContainer(MenuBase): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 def __init__(self, name, extra=None): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 MenuBase.__init__(self, name, extra) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 self._items = OrderedDict() |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 def __len__(self): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 return len(self._items) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 def __contains__(self, item): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 return item.canonical in self._items |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 def __iter__(self): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 return self._items.itervalues() |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 def __getitem__(self, item): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 try: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 return self._items[item.canonical] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 except KeyError: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 raise KeyError(item) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 def getOrCreate(self, item): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 log.debug("MenuContainer getOrCreate: item=%s name=%s\nlist=%s" % (item, item.canonical, self._items.keys())) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 try: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 return self[item] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 except KeyError: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 self.append(item) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 return item |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 def getActiveMenus(self): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 """Return an iterator on active children""" |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 for child in self._items.itervalues(): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 if child.ACTIVE: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 yield child |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 def append(self, item): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 assert isinstance(item, MenuItem) or isinstance(item, MenuContainer) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 self._items[item.canonical] = item |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 class MenuCategory(MenuContainer): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 """A category which can hold other menus or categories""" |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 def __init__(self, name, name_i18n=None, extra=None): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 @param name(unicode): canonical name |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 @param name_i18n(unicode, None): translated name |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 @param icon(unicode, None): same as in MenuBase.__init__ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 log.debug("creating menuCategory %s with extra %s" % (name, extra)) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 MenuContainer.__init__(self, name, extra) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 self._name_i18n = name_i18n or name |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 @property |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 def name(self): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 return self._name_i18n |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 class MenuType(MenuContainer): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 """A type which can hold other menus or categories""" |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 pass |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 ## manager ## |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 class QuickMenusManager(object): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 """Manage all the menus""" |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 _data_collectors={C.MENU_GLOBAL: None} # No data is associated with C.MENU_GLOBAL items |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 def __init__(self, host, menus=None, language=None): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 @param host: %(doc_host)s |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 @param menus(iterable): menus as in [addMenus] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 @param language: same as in [i18n.languageSwitch] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 self.host = host |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 MenuBase.host = host |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 self.language = language |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 self.menus = {} |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 if menus is not None: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 self.addMenus(menus) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 def _getPathI18n(self, path): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 """Return translated version of path""" |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 languageSwitch(self.language) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
272 path_i18n = [_(elt) for elt in path] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 languageSwitch() |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 return path_i18n |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
276 def _createCategories(self, type_, path, path_i18n=None, top_extra=None): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
277 """Create catogories of the path |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
278 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
279 @param type_(unicode): same as in [sat.core.sat_main.SAT.importMenu] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 @param path(list[unicode]): same as in [sat.core.sat_main.SAT.importMenu] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 @param path_i18n(list[unicode], None): translated menu path (same lenght as path) or None to get deferred translation of path |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 @param top_extra: extra data to use on the first element of path only. If the first element already exists and is reused, top_extra will be ignored (you'll have to manually change it if you really want to). |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
283 @return (MenuContainer): last category created, or MenuType if path is empty |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
284 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
285 if path_i18n is None: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
286 path_i18n = self._getPathI18n(path) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 assert len(path) == len(path_i18n) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
288 menu_container = self.menus.setdefault(type_, MenuType(type_)) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
289 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
290 for idx, category in enumerate(path): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
291 menu_category = MenuCategory(category, path_i18n[idx], extra=top_extra) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
292 menu_container = menu_container.getOrCreate(menu_category) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 top_extra = None |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 return menu_container |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 @staticmethod |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 def addDataCollector(type_, data_collector): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
299 """Associate a data collector to a menu type |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 A data collector is a method or a map which allow to collect context data to construct the dictionnary which will be sent to the bridge method managing the menu item. |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 @param type_(unicode): same as in [sat.core.sat_main.SAT.importMenu] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 @param data_collector(dict[unicode,unicode], callable, None): can be: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 - a dict which map data name to local name. The attribute named after the dict values will be getted from caller, and put in data. e.g.: if data_collector={'room_jid':'target'}, then the "room_jid" data will be the value of the "target" attribute of the caller. |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 - a callable which must return the data dictionnary. callable will have caller and item name as argument |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 - None: an empty dict will be used |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 QuickMenusManager._data_collectors[type_] = data_collector |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 @staticmethod |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 def getDataCollector(type_): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 """Get data_collector associated to type_ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
313 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 @param type_(unicode): same as in [sat.core.sat_main.SAT.importMenu] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 @return (callable, dict, None): data_collector |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 try: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 return QuickMenusManager._data_collectors[type_] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 except KeyError: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 log.error(u"No data collector registered for {}".format(type_)) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 return None |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 def addMenuItem(self, type_, path, item, path_i18n=None, top_extra=None): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 """Add a MenuItemBase instance |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
325 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 @param type_(unicode): same as in [sat.core.sat_main.SAT.importMenu] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
327 @param path(list[unicode]): same as in [sat.core.sat_main.SAT.importMenu], stop at the last parent category |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 @param item(MenuItem): a instancied item |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 @param path_i18n(list[unicode],None): translated menu path (same lenght as path) or None to use deferred translation of path |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
330 @param top_extra: same as in [_createCategories] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
331 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
332 if path_i18n is None: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 path_i18n = self._getPathI18n(path) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 assert path and len(path) == len(path_i18n) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
335 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 menu_container = self._createCategories(type_, path, path_i18n, top_extra) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
338 if item in menu_container: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
339 if isinstance(item, MenuHook): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 menu_container.replace(item) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
341 else: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 container_item = menu_container[item] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
343 if isinstance(container_item, MenuPlaceHolder): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
344 menu_container.replace(item) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
345 elif isinstance(container_item, MenuHook): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 # MenuHook must not be replaced |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 log.debug(u"ignoring menu at path [{}] because a hook is already in place".format(path)) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
348 else: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 log.error(u"Conflicting menus at path [{}]".format(path)) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 else: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 log.debug(u"Adding menu [{type_}] {path}".format(type_=type_, path=path)) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
352 menu_container.append(item) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 self.host.callListeners('menu', type_, path, path_i18n, item) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
354 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
355 def addMenu(self, type_, path, path_i18n=None, extra=None, top_extra=None, id_=None, callback=None): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 """Add a menu item |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
357 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
358 @param type_(unicode): same as in [sat.core.sat_main.SAT.importMenu] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 @param path(list[unicode]): same as in [sat.core.sat_main.SAT.importMenu] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 @param path_i18n(list[unicode], None): translated menu path (same lenght as path), or None to get deferred translation |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
361 @param extra(dict[unicode, unicode], None): same as in [addMenus] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 @param top_extra: same as in [_createCategories] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
363 @param id_(unicode): callback id (mutually exclusive with callback) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 @param callback(callable): local callback (mutually exclusive with id_) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 if path_i18n is None: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
367 path_i18n = self._getPathI18n(path) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
368 assert bool(id_) ^ bool(callback) # we must have id_ xor callback defined |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
369 if id_: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
370 menu_item = MenuItemDistant(self.host, type_, path[-1], path_i18n[-1], id_=id_, extra=extra) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 else: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 menu_item = MenuItemLocal(type_, path[-1], path_i18n[-1], callback=callback, extra=extra) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
373 self.addMenuItem(type_, path[:-1], menu_item, path_i18n[:-1], top_extra) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
374 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 def addMenus(self, menus, top_extra=None): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
376 """Add several menus at once |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
377 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 @param menus(iterable): iterable with: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
379 id_(unicode,callable): id of distant callback or local callback |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 type_(unicode): same as in [sat.core.sat_main.SAT.importMenu] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 path(iterable[unicode]): same as in [sat.core.sat_main.SAT.importMenu] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
382 path_i18n(iterable[unicode]): translated menu path (same lenght as path) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
383 extra(dict[unicode,unicode]): dictionary of extra data (used on the leaf menu), can be: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 - "icon": icon name |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 @param top_extra: same as in [_createCategories] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 # TODO: manage icons |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 for id_, type_, path, path_i18n, extra in menus: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
389 if callable(id_): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
390 self.addMenu(type_, path, path_i18n, callback=id_, extra=extra, top_extra=top_extra) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
391 else: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 self.addMenu(type_, path, path_i18n, id_=id_, extra=extra, top_extra=top_extra) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
393 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
394 def addCategory(self, type_, path, path_i18n=None, extra=None, top_extra=None): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
395 """Create a category with all parents, and set extra on the last one |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
396 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
397 @param type_(unicode): same as in [sat.core.sat_main.SAT.importMenu] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
398 @param path(list[unicode]): same as in [sat.core.sat_main.SAT.importMenu] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
399 @param path_i18n(list[unicode], None): translated menu path (same lenght as path), or None to get deferred translation of path |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
400 @param extra(dict[unicode, unicode], None): same as in [addMenus] (added on the leaf category only) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
401 @param top_extra: same as in [_createCategories] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
402 @return (MenuCategory): last category add |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
403 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
404 if path_i18n is None: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
405 path_i18n = self._getPathI18n(path) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
406 last_container = self._createCategories(type_, path, path_i18n, top_extra=top_extra) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
407 last_container.setExtra(extra) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
408 return last_container |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
409 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
410 def getMainContainer(self, type_): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
411 """Get a main MenuType container |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
412 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
413 @param type_: a C.MENU_* constant |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
414 @return(MenuContainer): the main container |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
415 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
416 menu_container = self.menus.setdefault(type_, MenuType(type_)) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
417 return menu_container |