Skip to content

Instantly share code, notes, and snippets.

@Zen-CODE
Created July 21, 2016 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zen-CODE/63749afae7faf70a0de419f9e5f76360 to your computer and use it in GitHub Desktop.
Save Zen-CODE/63749afae7faf70a0de419f9e5f76360 to your computer and use it in GitHub Desktop.
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: "name of chosen folder should appear here"
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.content.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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment