comparison cagou/plugins/plugin_wid_file_sharing.py @ 194:a68c9baa6694

plugin file sharing: use header hint to show current path, and open new path: - if header is empty, current path is shown as hint - if text is entered, it's used to filter files/dirs in the current path - if text is a path (i.e. if it contains a "/"), current path is changed to specified one when header is validated
author Goffi <goffi@goffi.org>
date Wed, 23 May 2018 18:44:15 +0200
parents 62198e00a2b7
children 519b3a29743c
comparison
equal deleted inserted replaced
193:284cb5c467b0 194:a68c9baa6694
47 "description": _(u"share/transfer files between devices"), 47 "description": _(u"share/transfer files between devices"),
48 "icon_symbol": u"exchange", 48 "icon_symbol": u"exchange",
49 } 49 }
50 MODE_VIEW = u"view" 50 MODE_VIEW = u"view"
51 MODE_LOCAL = u"local" 51 MODE_LOCAL = u"local"
52 SELECT_INSTRUCTIONS = _(u"Please select entities to share with")
52 53
53 54
54 dist = modernmenu.dist 55 dist = modernmenu.dist
55 56
56 57
267 268
268 def on_mode(self, instance, new_mode): 269 def on_mode(self, instance, new_mode):
269 print(instance) 270 print(instance)
270 self.update_view(None, self.local_dir) 271 self.update_view(None, self.local_dir)
271 272
273 def onHeaderInput(self):
274 if u'/' in self.header_input.text or self.header_input.text == u'~':
275 self.current_dir = os.path.expanduser(self.header_input.text)
276
272 def onHeaderInputComplete(self, wid, text): 277 def onHeaderInputComplete(self, wid, text):
273 """we filter items when text is entered in input box""" 278 """we filter items when text is entered in input box"""
274 text = text.strip().lower() 279 text = text.strip().lower()
280 if u'/' in text:
281 return
275 filtering = len(text)>len(self._filter_last) 282 filtering = len(text)>len(self._filter_last)
276 self._filter_last = text 283 self._filter_last = text
277 for child in self.layout.children: 284 for child in self.layout.children:
278 if not isinstance(child, ItemWidget): 285 if not isinstance(child, ItemWidget):
279 continue 286 continue
347 def update_view(self, *args): 354 def update_view(self, *args):
348 """update items according to current mode, entity and dir""" 355 """update items according to current mode, entity and dir"""
349 log.debug(u'updating {}, {}'.format(self.current_dir, args)) 356 log.debug(u'updating {}, {}'.format(self.current_dir, args))
350 self.layout.clear_widgets() 357 self.layout.clear_widgets()
351 self.header_input.text = u'' 358 self.header_input.text = u''
359 self.header_input.hint_text = self.current_dir
360
352 if self.mode == MODE_LOCAL: 361 if self.mode == MODE_LOCAL:
353 filepath = os.path.join(self.local_dir, u'..') 362 filepath = os.path.join(self.local_dir, u'..')
354 self.layout.add_widget(LocalPathWidget(sharing_wid=self, filepath=filepath)) 363 self.layout.add_widget(LocalPathWidget(sharing_wid=self, filepath=filepath))
355 files = sorted(os.listdir(self.local_dir)) 364 files = sorted(os.listdir(self.local_dir))
356 for f in files: 365 for f in files: