Mercurial > libervia-backend
annotate frontends/src/quick_frontend/quick_menus.py @ 2535:a19b2c43e719
plugin XEP-0234: fixed regex import
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 25 Mar 2018 20:51:02 +0200 |
parents | 0046283a285d |
children |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
1364
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 |
2483 | 5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org) |
1364
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): |
2070
58f0c96d60e5
quick frontend (menus): minor docstring fixes
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
138 """A MenuItem with a local callback""" |
1364
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 |
2070
58f0c96d60e5
quick frontend (menus): minor docstring fixes
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
146 @param callback(callable): local callback. |
58f0c96d60e5
quick frontend (menus): minor docstring fixes
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
147 Will be called with no argument if data_collector is None |
58f0c96d60e5
quick frontend (menus): minor docstring fixes
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
148 and with caller, profile, and requested data otherwise |
1364
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 @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
|
150 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 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
|
152 self.callback = callback |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 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
|
155 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
|
156 if data_collector is None: |
2070
58f0c96d60e5
quick frontend (menus): minor docstring fixes
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
157 # FIXME: would not it be better if caller and profile where used as arguments? |
1364
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 self.callback() |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 else: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 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
|
161 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 class MenuHook(MenuItemLocal): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 """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
|
165 pass |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 class MenuPlaceHolder(MenuItem): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 """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
|
170 ACTIVE=False |
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 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
|
173 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
|
174 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 class MenuSeparator(MenuItem): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 """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
|
178 SEP_IDX=0 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 def __init__(self): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 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
|
182 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
|
183 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
|
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 ## containers ## |
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 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 class MenuContainer(MenuBase): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 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
|
192 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
|
193 self._items = OrderedDict() |
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 __len__(self): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 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
|
197 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 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
|
199 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
|
200 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 def __iter__(self): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 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
|
203 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 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
|
205 try: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 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
|
207 except KeyError: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 raise KeyError(item) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 def getOrCreate(self, item): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
211 log.debug(u"MenuContainer getOrCreate: item=%s name=%s\nlist=%s" % (item, item.canonical, self._items.keys())) |
1364
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 try: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 return self[item] |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 except KeyError: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 self.append(item) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 return item |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 def getActiveMenus(self): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 """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
|
220 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
|
221 if child.ACTIVE: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 yield child |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 def append(self, item): |
1366
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
225 """add an item at the end of current ones |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
226 |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
227 @param item: instance of MenuBase (must be unique in container) |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
228 """ |
1364
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 assert isinstance(item, MenuItem) or isinstance(item, MenuContainer) |
1366
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
230 assert item.canonical not in self._items |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
231 self._items[item.canonical] = item |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
232 |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
233 def replace(self, item): |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
234 """add an item at the end of current ones or replace an existing one""" |
1364
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 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
|
236 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 class MenuCategory(MenuContainer): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 """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
|
240 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 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
|
242 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 @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
|
244 @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
|
245 @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
|
246 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 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
|
248 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
|
249 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
|
250 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 @property |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 def name(self): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 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
|
254 |
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 class MenuType(MenuContainer): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 """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
|
258 pass |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 ## manager ## |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 class QuickMenusManager(object): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 """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
|
266 _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
|
267 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 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
|
269 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 @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
|
271 @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
|
272 @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
|
273 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 self.host = host |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 MenuBase.host = host |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
276 self.language = language |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
277 self.menus = {} |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
278 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
|
279 self.addMenus(menus) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 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
|
282 """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
|
283 languageSwitch(self.language) |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
284 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
|
285 languageSwitch() |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
286 return path_i18n |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
288 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
|
289 """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
|
290 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
291 @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
|
292 @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
|
293 @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
|
294 @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
|
295 @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
|
296 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 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
|
298 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
|
299 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
|
300 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
|
301 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 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
|
303 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
|
304 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
|
305 top_extra = None |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 return menu_container |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 @staticmethod |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 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
|
311 """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
|
312 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
313 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
|
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 @param data_collector(dict[unicode,unicode], callable, None): can be: |
2070
58f0c96d60e5
quick frontend (menus): minor docstring fixes
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
316 - a dict which map data name to local name. |
58f0c96d60e5
quick frontend (menus): minor docstring fixes
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
317 The attribute named after the dict values will be getted from caller, and put in data. |
58f0c96d60e5
quick frontend (menus): minor docstring fixes
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
318 e.g.: if data_collector={'room_jid':'target'}, then the "room_jid" data will be the value of the "target" attribute of the caller. |
1364
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 - 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
|
320 - 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
|
321 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 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
|
323 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 @staticmethod |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
325 def getDataCollector(type_): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 """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
|
327 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 @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
|
329 @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
|
330 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
331 try: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
332 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
|
333 except KeyError: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 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
|
335 return None |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 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
|
338 """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
|
339 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 @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
|
341 @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
|
342 @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
|
343 @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
|
344 @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
|
345 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 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
|
347 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
|
348 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
|
349 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 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
|
351 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
352 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
|
353 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
|
354 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
|
355 else: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 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
|
357 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
|
358 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
|
359 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
|
360 # 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
|
361 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
|
362 else: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
363 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
|
364 else: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 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
|
366 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
|
367 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
|
368 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
369 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
|
370 """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
|
371 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 @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
|
373 @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
|
374 @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
|
375 @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
|
376 @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
|
377 @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
|
378 @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
|
379 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 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
|
381 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
|
382 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
|
383 if id_: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 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
|
385 else: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 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
|
387 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
|
388 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
389 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
|
390 """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
|
391 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 @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
|
393 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
|
394 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
|
395 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
|
396 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
|
397 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
|
398 - "icon": icon name |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
399 @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
|
400 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
401 # TODO: manage icons |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
402 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
|
403 if callable(id_): |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
404 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
|
405 else: |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
406 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
|
407 |
1366
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
408 def addMenuHook(self, type_, path, path_i18n=None, extra=None, top_extra=None, callback=None): |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
409 """Helper method to add a menu hook |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
410 |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
411 Menu hooks are local menus which override menu given by backend |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
412 @param type_(unicode): same as in [sat.core.sat_main.SAT.importMenu] |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
413 @param path(list[unicode]): same as in [sat.core.sat_main.SAT.importMenu] |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
414 @param path_i18n(list[unicode], None): translated menu path (same lenght as path), or None to get deferred translation |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
415 @param extra(dict[unicode, unicode], None): same as in [addMenus] |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
416 @param top_extra: same as in [_createCategories] |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
417 @param callback(callable): local callback (mutually exclusive with id_) |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
418 """ |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
419 if path_i18n is None: |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
420 path_i18n = self._getPathI18n(path) |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
421 menu_item = MenuHook(type_, path[-1], path_i18n[-1], callback=callback, extra=extra) |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
422 self.addMenuItem(type_, path[:-1], menu_item, path_i18n[:-1], top_extra) |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
423 log.info(u"Menu hook set on {path} ({type_})".format(path=path, type_=type_)) |
584d45bb36d9
quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
Goffi <goffi@goffi.org>
parents:
1364
diff
changeset
|
424 |
1364
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
425 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
|
426 """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
|
427 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
428 @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
|
429 @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
|
430 @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
|
431 @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
|
432 @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
|
433 @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
|
434 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
435 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
|
436 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
|
437 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
|
438 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
|
439 return last_container |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
440 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
441 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
|
442 """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
|
443 |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
444 @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
|
445 @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
|
446 """ |
28f0b33ca17c
quick_frontend (menus): added a quick_menus module to manage easily menus logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
447 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
|
448 return menu_container |