What is the problem you having? I changed the dir in the listdir call, and the code seems to be working.
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/2190a105-ef8e-42d3-a44e-0879b15652a1n%40googlegroups.com.
There are a few things here to fix. I’m surprised that this code works. The class OpenWindow should be on the far left, not nested under the MainWIndow.
When the file is selected, you can use that to set a property on the other screen.
I would recommend using kv to setup your screens it would simplify things greatly.
Give it a try – I’d be happy to help.
import os
from re import template
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.clock import Clock
from kivy.core.window import Window
class MainWindow(Screen):
def build(self):
self.name = 'Main'
self.Box1 = BoxLayout(orientation='horizontal', padding=10)
self.Box1.Gauche_Layout = GridLayout(cols=1, size_hint=(0.85, 1))
self.Box1.Gauche_Layout.add_widget(Label(text="Fichiers déjà existants : ", size_hint=(1, 0.1)))
self.Box1.Gauche_Layout.Fichier_Layout = GridLayout(cols=2)
self.Mes_Boutons_fichier()
self.Box1.Gauche_Layout.add_widget(self.Box1.Gauche_Layout.Fichier_Layout)
self.Box1.add_widget(self.Box1.Gauche_Layout)
self.add_widget(self.Box1)
sm.add_widget(self)
def Mes_Boutons_fichier(self):
self.Liste_Boutons_fichier = []
i = 0
fichiers = os.listdir(".") # finding files in folder
for elt in fichiers: # creating buttons for every files
self.Liste_Boutons_fichier.append(Button(text=str(elt)))
self.Liste_Boutons_fichier[i].bind(on_press=self.p)
self.Box1.Gauche_Layout.Fichier_Layout.add_widget(self.Liste_Boutons_fichier[i])
i += 1
def p(self, instance):
print(instance.text)
r = instance.text # r = name of the file chosen
class OpenWindow(Screen):
def build(self):
self.name = 'Open' # Name of the window
self.box = BoxLayout(orientation='horizontal')
self.box.side = BoxLayout(orientation='vertical')
self.box.side.add_widget(Label(text=r))
self.box.add_widget(self.box.side)
self.box.box_dp = BoxLayout(orientation='horizontal')
self.box.box_dp.btn = Button()
self.box.box_dp.btn.bind(on_press=self.btn_f)
self.box.box_dp.add_widget(self.box.box_dp.btn)
self.box.add_widget(self.box.box_dp)
self.add_widget(self.box)
sm.add_widget(self)
def btn_f(self, instance):
sm.current = 'Main'
Open = OpenWindow()
Open.build()
sm.current = 'Open'
sm = ScreenManager()
class MainFDRApp(App):
def build(self):
Main = MainWindow()
Main.build()
sm.current = 'Main'
return sm
if __name__ == '__main__':
MainFDRApp().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/674ba8a1-90ea-47f3-b0b2-9e8a74592cccn%40googlegroups.com.
Here is an alternative implementation using kv:
import os
from kivy.app import App
from kivy.uix.button import Button
from kivy.lang import Builder
from kivy.uix.screenmanager import
Screen
kv = """
ScreenManager:
id: sm
MainWindow:
name: 'Main'
OpenWindow:
name: 'Open'
<MainWindow>:
BoxLayout:
orientation: 'vertical'
padding: 10
Label:
text: 'Fichiers déjà existants : '
size_hint_y: None
height: 24
GridLayout:
id: grid
cols: 2
<OpenWindow>:
BoxLayout:
Label:
id: filename
Button:
text: 'Home'
on_release: root.manager.current = 'Main'
<FileButton>:
on_release:
app.root.current = 'Open'
app.root.get_screen('Open').ids.filename.text = self.text
"""
class FileButton(Button):
pass
class MainWindow(Screen):
def on_kv_post(self, base_widget):
self.add_buttons()
def add_buttons(self):
for file in os.listdir('.'):
self.ids.grid.add_widget(FileButton(text=file))
class OpenWindow(Screen):
pass
class MainFDRApp(App):
def build(self):
return Builder.load_string(kv)
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/60a7beac.1c69fb81.2612c.be3cSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Thanks a lot ! I'll carefully read it and I'll get back in a few days (or maybe a week). For the moment, I stay without using kv but I think I'll begin to use it a bit (so thanks for the help proposition).
The indented class was the technic I used to replace the update of the page (it is a homemade, so it is maybe why it's wobbly).