diff --git a/examples/demo/showcase/main.py b/examples/demo/showcase/main.py index 3cc76888c..3540c20f2 100644 --- a/examples/demo/showcase/main.py +++ b/examples/demo/showcase/main.py @@ -16,6 +16,7 @@ from kivy.uix.switch import Switch from kivy.uix.label import Label from kivy.uix.popup import Popup from kivy.uix.accordion import Accordion, AccordionItem +from kivy.uix.filechooser import FileChooserIconView, FileChooserListView class Showcase(FloatLayout): @@ -60,22 +61,20 @@ class ShowcaseApp(App): n = create_tree('Buttons') attach_node('Standard buttons', n) attach_node('Options buttons', n) - n = create_tree('Sliders') attach_node('Horizontal sliders', n) attach_node('Vertical sliders', n) - n = create_tree('Scatter') attach_node('Scatter with image', n) attach_node('Scatter with buttons', n) - n = create_tree('Textinput') attach_node('Monoline textinput', n) attach_node('Multiline textinput', n) - n = create_tree('TreeView') attach_node('Standard treeview', n) attach_node('Treeview without root', n) - n = create_tree('Others') attach_node('Accordion', n) attach_node('Popup', n) attach_node('Switch', n) + n = create_tree('Experimentals') + attach_node('Filechooser icon', n) + attach_node('Filechooser list', n) root.add_widget(tree) self.content = content = BoxLayout() root.add_widget(content) @@ -192,6 +191,12 @@ class ShowcaseApp(App): col.add_widget(root) return col + def show_filechooser_icon(self): + return FileChooserIconView() + + def show_filechooser_list(self): + return FileChooserListView() + if __name__ in ('__main__', '__android__'): ShowcaseApp().run() diff --git a/kivy/data/style.kv b/kivy/data/style.kv index c7c8a13c9..6be0f89a9 100644 --- a/kivy/data/style.kv +++ b/kivy/data/style.kv @@ -201,6 +201,7 @@ # Don't allow expansion of the ../ node is_leaf: not ctx.isdir or ctx.name.endswith('..' + ctx.sep) or self.locked on_touch_down: self.collide_point(*args[1].pos) and ctx.controller.entry_touched(self, args[1]) + on_touch_up: self.collide_point(*args[1].pos) and ctx.controller.entry_released(self, args[1]) BoxLayout: pos: root.pos Label: @@ -244,6 +245,7 @@ size_hint: None, None on_touch_down: self.collide_point(*args[1].pos) and ctx.controller.entry_touched(self, args[1]) + on_touch_up: self.collide_point(*args[1].pos) and ctx.controller.entry_released(self, args[1]) canvas: Color: diff --git a/kivy/uix/filechooser.py b/kivy/uix/filechooser.py index b11f54ebe..7a1ea164c 100644 --- a/kivy/uix/filechooser.py +++ b/kivy/uix/filechooser.py @@ -140,6 +140,9 @@ class FileChooserController(FloatLayout): self.register_event_type('on_submit') super(FileChooserController, self).__init__(**kwargs) + self._items = [] + self.bind(selection=self._update_item_selection) + if platform in ('darwin', 'linux2'): self.is_hidden = is_hidden_unix elif platform == 'win32': @@ -151,6 +154,10 @@ class FileChooserController(FloatLayout): filters=self._trigger_update) self._trigger_update() + def _update_item_selection(self, *args): + for item in self._items: + item.selected = item.path in self.selection + def _trigger_update(self, *args): Clock.unschedule(self._update_files) Clock.schedule_once(self._update_files) @@ -168,9 +175,12 @@ class FileChooserController(FloatLayout): pass def on_submit(self, selected, touch=None): - self.selection = [] + pass def entry_touched(self, entry, touch): + '''(internal) This method must be called by the template when an entry + is touched by the user. + ''' if self.multiselect: if isdir(entry.path) and touch.is_double_tap: self.open_entry(entry) @@ -181,10 +191,23 @@ class FileChooserController(FloatLayout): self.selection.append(entry.path) else: if isdir(entry.path): - self.open_entry(entry) + pass else: self.selection = [entry.path, ] - self.dispatch('on_submit', [entry.path], touch) + + def entry_released(self, entry, touch): + '''(internal) This method must be called by the template when an entry + is touched by the user. + + .. versionadded:: 1.0.10 + ''' + if self.multiselect: + pass + else: + if isdir(entry.path): + self.open_entry(entry) + elif touch.is_double_tap: + self.dispatch('on_submit', self.selection, touch) def open_entry(self, entry): try: @@ -232,6 +255,7 @@ class FileChooserController(FloatLayout): def _update_files(self, *args): # Clear current files self.dispatch('on_entries_cleared') + self._items = [] # Add the components that are always needed if platform == 'win32': @@ -247,6 +271,7 @@ class FileChooserController(FloatLayout): pardir = Builder.template(self._ENTRY_TEMPLATE, **dict(name=back, size='', path=back, controller=self, isdir=True, parent=None, sep=sep, get_nice_size=lambda: '')) + self._items.append(pardir) self.dispatch('on_entry_added', pardir) try: self._add_files(self.path)