I tried to write the word in the selected text file to the page. Where am I making mistake?
import kivy
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ObjectProperty, ListProperty
from kivy.uix.popup import Popup
from kivy.lang import Builder
import os
Builder.load_string("""
<MainScreen>:
BoxLayout:
orientation: 'vertical'
BoxLayout:
size_hint_y: None
height: 30
Button:
text: 'Choose Source'
on_release: root.load_source()
Label:
id: _selection
text: "Word in selected text file""
size_hint_y: .5
canvas.before:
Color:
rgb: .5,.5,.4
Rectangle:
pos: self.pos
size: self.size
Button:
text: 'GO'
on_release: root.GetFolderName()
<LoadDialog>:
BoxLayout:
size: root.size
pos: root.pos
orientation: "vertical"
FileChooserListView:
path: '/volumes'
dirselect: True
id: filechooser
filter: ['*.mov']
multiselect: True
BoxLayout:
size_hint_y: None
height: 30
Button
text: "Cancel"
on_release: root.close(None)
Button
text: "Select"
on_release: root.close(filechooser.selection)
""")
class LoadDialog(FloatLayout):
selection = None
''' Holds a list of the file items return by the file chooser, None
otherwise.
'''
cancel = ObjectProperty(None)
def close(self, selection):
""" Close the dialog. The selected is boolean indicating acceptance or
cancellation. """
if selection is not None:
self.selection = selection
print "Select {0}".format(self.selection)
self.cancel()
class MainScreen(FloatLayout):
def dismiss_popup(self):
self._popup.dismiss()
if self.content.selection is not None:
self.ids._selection.text = str(self.text_input.text.selection)
def load_source(self):
self.content = LoadDialog(load=self.load, cancel=self.dismiss_popup)
self._popup = Popup(title="Select Source Folder",
content=self.content,
size_hint=(0.9, 0.9))
self._popup.open()
def load(self, path, filename):
with open(os.path.join(path, filename[0])) as stream:
self.text_input.text = stream.read()
self.dismiss_popup()
################## I'd like to do a few python things with this but Can't figure out how to get variables from the dialog in Kivy to bind with this#########################
def GetFolderName(self, *args):
y = "name of chosen folder"
print y
class FootageImport(App):
def build(self):
return MainScreen()
if __name__ == "__main__":
FootageImport().run()