import kivy
from kivy.app import Appfrom kivy.uix.floatlayout import FloatLayoutfrom kivy.uix.label import Labelfrom kivy.uix.button import Buttonfrom kivy.uix.pagelayout import PageLayoutfrom kivy.properties import ObjectPropertyfrom kivy.uix.popup import Popupfrom kivy.factory import Factoryfrom kivy.uix.textinput import TextInputfrom kivy.uix.boxlayout import BoxLayoutfrom kivy.lang import Builderimport 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 on_selection: root.selected(filechooser.selection)
BoxLayout: size_hint_y: None height: 30
Button text: "Cancel" on_release: root.cancel()
Button text: "Select" on_release: print str(filechooser.selection[0])
###########################################The following line clearly does not work################################## #on_release: MainScreen._selection.text = str(filechooser.selection[0]) on_release: root.cancel()""")
class LoadDialog(FloatLayout):
cancel = ObjectProperty(None) def selected(self, filename): print "new folder selected"
class MainScreen(FloatLayout): def dismiss_popup(self): self._popup.dismiss() def load_source(self): content = LoadDialog(load=self.load, cancel=self.dismiss_popup) self._popup = Popup(title="Select Source Folder", content=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()
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Labelfrom kivy.uix.button import Buttonfrom kivy.uix.pagelayout import PageLayoutfrom kivy.properties import ObjectPropertyfrom kivy.uix.popup import Popupfrom kivy.factory import Factory
from kivy.lang import Builderimport os
Builder.load_string("""
<MainScreen>:
id:Mainscreen FloatLayout: id:Float1
BoxLayout: orientation: 'vertical' BoxLayout: size_hint_y: None
spacing: 0
Button: text: 'Choose Source' on_release: root.load_source()
size_hint_y: 1 Label: id: _selection
size_hint_y: .5 canvas.before: Color: rgb: .5,.5,.4 Rectangle: pos: self.pos size: self.size
Label: #<<<<<---------------------------------------------------HERE! id: _Log text: "I'D LIKE THE POPUP TEXT TO BE BOUND TO THIS (ID:_Log2)"
<LoadDialog>:##Works
BoxLayout: size: root.size pos: root.pos orientation: "vertical" FileChooserListView:
id: filechooser
BoxLayout: size_hint_y: None height: 30
Label: id: _Log2 #<<<<<-------------------------------------------------HERE! text: "I'D LIKE THIS TO BE BOUND TO THE MAIN WINDOW TEXT (ID:_Log)"
""")
##########################################################This defines the python code of the above widget.class LoadDialog(FloatLayout): selection = None cancel = ObjectProperty(None)
class MainScreen(FloatLayout):
def dismissSource_popup(self): self._popup.dismiss() if self.content.selection is not None: self.ids._selection.text = str(self.content.selection[0]) def load_source(self): self.content = LoadDialog(load=self.load, cancel=self.dismissSource_popup) self._popup = Popup(title="Select a Source Folder or file:", 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()
class SimpleBind(App):
def build(self): return MainScreen()
if __name__ == "__main__":
SimpleBind().run()