Skip to content

Commit 40b6032

Browse files
committed
filechooser: enhance filechooser to include entry_released. we have now a feedback before the item is used, because down is updating selection, up will submit it. + add it in showcase.
1 parent 119c595 commit 40b6032

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

examples/demo/showcase/main.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from kivy.uix.label import Label
1717
from kivy.uix.popup import Popup
1818
from kivy.uix.accordion import Accordion, AccordionItem
19+
from kivy.uix.filechooser import FileChooserIconView, FileChooserListView
1920

2021

2122
class Showcase(FloatLayout):
@@ -60,22 +61,20 @@ def attach_node(text, n):
6061
n = create_tree('Buttons')
6162
attach_node('Standard buttons', n)
6263
attach_node('Options buttons', n)
63-
n = create_tree('Sliders')
6464
attach_node('Horizontal sliders', n)
6565
attach_node('Vertical sliders', n)
66-
n = create_tree('Scatter')
6766
attach_node('Scatter with image', n)
6867
attach_node('Scatter with buttons', n)
69-
n = create_tree('Textinput')
7068
attach_node('Monoline textinput', n)
7169
attach_node('Multiline textinput', n)
72-
n = create_tree('TreeView')
7370
attach_node('Standard treeview', n)
7471
attach_node('Treeview without root', n)
75-
n = create_tree('Others')
7672
attach_node('Accordion', n)
7773
attach_node('Popup', n)
7874
attach_node('Switch', n)
75+
n = create_tree('Experimentals')
76+
attach_node('Filechooser icon', n)
77+
attach_node('Filechooser list', n)
7978
root.add_widget(tree)
8079
self.content = content = BoxLayout()
8180
root.add_widget(content)
@@ -192,6 +191,12 @@ def show_accordion(self):
192191
col.add_widget(root)
193192
return col
194193

194+
def show_filechooser_icon(self):
195+
return FileChooserIconView()
196+
197+
def show_filechooser_list(self):
198+
return FileChooserListView()
199+
195200

196201
if __name__ in ('__main__', '__android__'):
197202
ShowcaseApp().run()

kivy/data/style.kv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
# Don't allow expansion of the ../ node
202202
is_leaf: not ctx.isdir or ctx.name.endswith('..' + ctx.sep) or self.locked
203203
on_touch_down: self.collide_point(*args[1].pos) and ctx.controller.entry_touched(self, args[1])
204+
on_touch_up: self.collide_point(*args[1].pos) and ctx.controller.entry_released(self, args[1])
204205
BoxLayout:
205206
pos: root.pos
206207
Label:
@@ -244,6 +245,7 @@
244245
size_hint: None, None
245246

246247
on_touch_down: self.collide_point(*args[1].pos) and ctx.controller.entry_touched(self, args[1])
248+
on_touch_up: self.collide_point(*args[1].pos) and ctx.controller.entry_released(self, args[1])
247249

248250
canvas:
249251
Color:

kivy/uix/filechooser.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ def __init__(self, **kwargs):
140140
self.register_event_type('on_submit')
141141
super(FileChooserController, self).__init__(**kwargs)
142142

143+
self._items = []
144+
self.bind(selection=self._update_item_selection)
145+
143146
if platform in ('darwin', 'linux2'):
144147
self.is_hidden = is_hidden_unix
145148
elif platform == 'win32':
@@ -151,6 +154,10 @@ def __init__(self, **kwargs):
151154
filters=self._trigger_update)
152155
self._trigger_update()
153156

157+
def _update_item_selection(self, *args):
158+
for item in self._items:
159+
item.selected = item.path in self.selection
160+
154161
def _trigger_update(self, *args):
155162
Clock.unschedule(self._update_files)
156163
Clock.schedule_once(self._update_files)
@@ -168,9 +175,12 @@ def on_remove_subentry(self, subentry, entry):
168175
pass
169176

170177
def on_submit(self, selected, touch=None):
171-
self.selection = []
178+
pass
172179

173180
def entry_touched(self, entry, touch):
181+
'''(internal) This method must be called by the template when an entry
182+
is touched by the user.
183+
'''
174184
if self.multiselect:
175185
if isdir(entry.path) and touch.is_double_tap:
176186
self.open_entry(entry)
@@ -181,10 +191,23 @@ def entry_touched(self, entry, touch):
181191
self.selection.append(entry.path)
182192
else:
183193
if isdir(entry.path):
184-
self.open_entry(entry)
194+
pass
185195
else:
186196
self.selection = [entry.path, ]
187-
self.dispatch('on_submit', [entry.path], touch)
197+
198+
def entry_released(self, entry, touch):
199+
'''(internal) This method must be called by the template when an entry
200+
is touched by the user.
201+
202+
.. versionadded:: 1.0.10
203+
'''
204+
if self.multiselect:
205+
pass
206+
else:
207+
if isdir(entry.path):
208+
self.open_entry(entry)
209+
elif touch.is_double_tap:
210+
self.dispatch('on_submit', self.selection, touch)
188211

189212
def open_entry(self, entry):
190213
try:
@@ -232,6 +255,7 @@ def get_nice_size(self, fn):
232255
def _update_files(self, *args):
233256
# Clear current files
234257
self.dispatch('on_entries_cleared')
258+
self._items = []
235259

236260
# Add the components that are always needed
237261
if platform == 'win32':
@@ -247,6 +271,7 @@ def _update_files(self, *args):
247271
pardir = Builder.template(self._ENTRY_TEMPLATE, **dict(name=back,
248272
size='', path=back, controller=self, isdir=True, parent=None,
249273
sep=sep, get_nice_size=lambda: ''))
274+
self._items.append(pardir)
250275
self.dispatch('on_entry_added', pardir)
251276
try:
252277
self._add_files(self.path)

0 commit comments

Comments
 (0)