Mercurial > libervia-desktop-kivy
comparison cagou/core/menu.py @ 491:203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:44:32 +0200 |
parents | 3693c662fa88 |
children |
comparison
equal
deleted
inserted
replaced
490:962d17c4078c | 491:203755bbe0fe |
---|---|
97 cancel_cb = properties.ObjectProperty() | 97 cancel_cb = properties.ObjectProperty() |
98 | 98 |
99 def __init__(self, **kwargs): | 99 def __init__(self, **kwargs): |
100 super(SideMenu, self).__init__(**kwargs) | 100 super(SideMenu, self).__init__(**kwargs) |
101 if self.cancel_cb is None: | 101 if self.cancel_cb is None: |
102 self.cancel_cb = self.onMenuCancelled | 102 self.cancel_cb = self.on_menu_cancelled |
103 | 103 |
104 def _set_anim_kw(self, kw, size_hint, size): | 104 def _set_anim_kw(self, kw, size_hint, size): |
105 """Set animation keywords | 105 """Set animation keywords |
106 | 106 |
107 for each value of size_hint it is used if not None, | 107 for each value of size_hint it is used if not None, |
126 G.host.app.root.add_widget(self) | 126 G.host.app.root.add_widget(self) |
127 kw = {'d': 0.3, 't': 'out_back'} | 127 kw = {'d': 0.3, 't': 'out_back'} |
128 self._set_anim_kw(kw, self.size_hint_open, self.size_open) | 128 self._set_anim_kw(kw, self.size_hint_open, self.size_open) |
129 Animation(**kw).start(self) | 129 Animation(**kw).start(self) |
130 | 130 |
131 def _removeFromParent(self, anim, menu): | 131 def _remove_from_parent(self, anim, menu): |
132 # self.parent can already be None if the widget has been removed by a callback | 132 # self.parent can already be None if the widget has been removed by a callback |
133 # before the animation started. | 133 # before the animation started. |
134 if self.parent is not None: | 134 if self.parent is not None: |
135 self.parent.remove_widget(self) | 135 self.parent.remove_widget(self) |
136 | 136 |
137 def hide(self): | 137 def hide(self): |
138 Window.unbind(on_keyboard=self.key_input) | 138 Window.unbind(on_keyboard=self.key_input) |
139 kw = {'d': 0.2} | 139 kw = {'d': 0.2} |
140 self._set_anim_kw(kw, self.size_hint_close, self.size_close) | 140 self._set_anim_kw(kw, self.size_hint_close, self.size_close) |
141 anim = Animation(**kw) | 141 anim = Animation(**kw) |
142 anim.bind(on_complete=self._removeFromParent) | 142 anim.bind(on_complete=self._remove_from_parent) |
143 anim.start(self) | 143 anim.start(self) |
144 if self.callback_on_close: | 144 if self.callback_on_close: |
145 self.do_callback() | 145 self.do_callback() |
146 | 146 |
147 def on_touch_down(self, touch): | 147 def on_touch_down(self, touch): |
157 def key_input(self, window, key, scancode, codepoint, modifier): | 157 def key_input(self, window, key, scancode, codepoint, modifier): |
158 if key == 27: | 158 if key == 27: |
159 self.hide() | 159 self.hide() |
160 return True | 160 return True |
161 | 161 |
162 def onMenuCancelled(self, wid, cleaning_cb=None): | 162 def on_menu_cancelled(self, wid, cleaning_cb=None): |
163 self._closeUI(wid) | 163 self._close_ui(wid) |
164 if cleaning_cb is not None: | 164 if cleaning_cb is not None: |
165 cleaning_cb() | 165 cleaning_cb() |
166 | 166 |
167 def _closeUI(self, wid): | 167 def _close_ui(self, wid): |
168 G.host.closeUI() | 168 G.host.close_ui() |
169 | 169 |
170 def do_callback(self, *args, **kwargs): | 170 def do_callback(self, *args, **kwargs): |
171 log.warning("callback not implemented") | 171 log.warning("callback not implemented") |
172 | 172 |
173 | 173 |
180 | 180 |
181 def __init__(self, **kwargs): | 181 def __init__(self, **kwargs): |
182 super().__init__(**kwargs) | 182 super().__init__(**kwargs) |
183 G.local_platform.on_extra_menu_init(self) | 183 G.local_platform.on_extra_menu_init(self) |
184 | 184 |
185 def addItem(self, label, callback): | 185 def add_item(self, label, callback): |
186 self.add_widget( | 186 self.add_widget( |
187 ExtraMenuItem( | 187 ExtraMenuItem( |
188 text=label, | 188 text=label, |
189 on_press=partial(self.onItemPress, callback=callback), | 189 on_press=partial(self.on_item_press, callback=callback), |
190 ), | 190 ), |
191 # we want the new item above "About" and last empty Widget | 191 # we want the new item above "About" and last empty Widget |
192 index=2) | 192 index=2) |
193 | 193 |
194 def onItemPress(self, *args, callback): | 194 def on_item_press(self, *args, callback): |
195 self.hide() | 195 self.hide() |
196 callback() | 196 callback() |
197 | 197 |
198 def onAbout(self): | 198 def on_about(self): |
199 self.hide() | 199 self.hide() |
200 about = AboutPopup() | 200 about = AboutPopup() |
201 about.title = ABOUT_TITLE | 201 about.title = ABOUT_TITLE |
202 about.content = AboutContent( | 202 about.content = AboutContent( |
203 text=ABOUT_CONTENT.format( | 203 text=ABOUT_CONTENT.format( |
226 | 226 |
227 def __init__(self, **kwargs): | 227 def __init__(self, **kwargs): |
228 super(TransferMenu, self).__init__(**kwargs) | 228 super(TransferMenu, self).__init__(**kwargs) |
229 if self.profiles is None: | 229 if self.profiles is None: |
230 self.profiles = iter(G.host.profiles) | 230 self.profiles = iter(G.host.profiles) |
231 for plug_info in G.host.getPluggedWidgets(type_=C.PLUG_TYPE_TRANSFER): | 231 for plug_info in G.host.get_plugged_widgets(type_=C.PLUG_TYPE_TRANSFER): |
232 item = TransferItem( | 232 item = TransferItem( |
233 plug_info = plug_info | 233 plug_info = plug_info |
234 ) | 234 ) |
235 self.items_layout.add_widget(item) | 235 self.items_layout.add_widget(item) |
236 | 236 |
237 def on_kv_post(self, __): | 237 def on_kv_post(self, __): |
238 self.updateTransferInfo() | 238 self.update_transfer_info() |
239 | 239 |
240 def getTransferInfo(self): | 240 def get_transfer_info(self): |
241 if self.upload_btn.state == "down": | 241 if self.upload_btn.state == "down": |
242 # upload | 242 # upload |
243 if self.encrypted: | 243 if self.encrypted: |
244 return _( | 244 return _( |
245 "The file will be [color=00aa00][b]encrypted[/b][/color] and sent to " | 245 "The file will be [color=00aa00][b]encrypted[/b][/color] and sent to " |
268 "The file will be sent [color=ff0000][b]unencrypted[/b][/color] " | 268 "The file will be sent [color=ff0000][b]unencrypted[/b][/color] " |
269 "directly to your contact (it [i]may be[/i] transiting by the " | 269 "directly to your contact (it [i]may be[/i] transiting by the " |
270 "server if direct connection is not possible)." | 270 "server if direct connection is not possible)." |
271 ) | 271 ) |
272 | 272 |
273 def updateTransferInfo(self): | 273 def update_transfer_info(self): |
274 self.transfer_info.text = self.getTransferInfo() | 274 self.transfer_info.text = self.get_transfer_info() |
275 | 275 |
276 def _onTransferCb(self, file_path, cleaning_cb=None, external=False, wid_cont=None): | 276 def _on_transfer_cb(self, file_path, cleaning_cb=None, external=False, wid_cont=None): |
277 if not external: | 277 if not external: |
278 wid = wid_cont[0] | 278 wid = wid_cont[0] |
279 self._closeUI(wid) | 279 self._close_ui(wid) |
280 self.callback( | 280 self.callback( |
281 file_path, | 281 file_path, |
282 transfer_type = (C.TRANSFER_UPLOAD | 282 transfer_type = (C.TRANSFER_UPLOAD |
283 if self.ids['upload_btn'].state == "down" else C.TRANSFER_SEND), | 283 if self.ids['upload_btn'].state == "down" else C.TRANSFER_SEND), |
284 cleaning_cb=cleaning_cb, | 284 cleaning_cb=cleaning_cb, |
287 def _check_plugin_permissions_cb(self, plug_info): | 287 def _check_plugin_permissions_cb(self, plug_info): |
288 external = plug_info.get('external', False) | 288 external = plug_info.get('external', False) |
289 wid_cont = [] | 289 wid_cont = [] |
290 wid_cont.append(plug_info['factory']( | 290 wid_cont.append(plug_info['factory']( |
291 plug_info, | 291 plug_info, |
292 partial(self._onTransferCb, external=external, wid_cont=wid_cont), | 292 partial(self._on_transfer_cb, external=external, wid_cont=wid_cont), |
293 self.cancel_cb, | 293 self.cancel_cb, |
294 self.profiles)) | 294 self.profiles)) |
295 if not external: | 295 if not external: |
296 G.host.showExtraUI(wid_cont[0]) | 296 G.host.show_extra_ui(wid_cont[0]) |
297 | 297 |
298 def do_callback(self, plug_info): | 298 def do_callback(self, plug_info): |
299 self.parent.remove_widget(self) | 299 self.parent.remove_widget(self) |
300 if self.callback is None: | 300 if self.callback is None: |
301 log.warning("TransferMenu callback is not set") | 301 log.warning("TransferMenu callback is not set") |
302 else: | 302 else: |
303 G.local_platform.check_plugin_permissions( | 303 G.local_platform.check_plugin_permissions( |
304 plug_info, | 304 plug_info, |
305 callback=partial(self._check_plugin_permissions_cb, plug_info), | 305 callback=partial(self._check_plugin_permissions_cb, plug_info), |
306 errback=lambda: G.host.addNote( | 306 errback=lambda: G.host.add_note( |
307 _("permission refused"), | 307 _("permission refused"), |
308 _("this transfer menu can't be used if you refuse the requested " | 308 _("this transfer menu can't be used if you refuse the requested " |
309 "permission"), | 309 "permission"), |
310 C.XMLUI_DATA_LVL_WARNING) | 310 C.XMLUI_DATA_LVL_WARNING) |
311 ) | 311 ) |