ここで、ScreenMangerを復活させよう。

filelist.py……①


import os

from kivy.app import App

from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.popup import Popup
from kivy.uix.treeview import TreeViewLabel
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty

from pprint import pprint


from kivy.core.text import LabelBase, DEFAULT_FONT
from kivy.resources import resource_add_path

# 日本語フォント設定
resource_add_path('./fonts')
LabelBase.register(DEFAULT_FONT, 'ipaexg.ttf')

sm = ScreenManager()

class SetSCN(Screen):
    pass





class LoadDialog(FloatLayout):
    load = ObjectProperty(None)
    cancel = ObjectProperty(None)



class AllSCN(Screen):
    tv = ObjectProperty(None)
    file_name = ObjectProperty(None)
    loadfile = ObjectProperty(None)
    text_input = ObjectProperty(None)

    def __init__(self, **kwargs):
         super(AllSCN, self).__init__(**kwargs)
         self.tv.add_node(TreeViewLabel(text ='シンカリオン E1 とき'))
         self.tv.add_node(TreeViewLabel(text ='シンカリオン 0 ひかり'))
         self.tv.add_node(TreeViewLabel(text ='シンカリオン キハ32 鉄道ホビートレイン'))

    def setupButtonClicked(self):
        sm.current = 'set'


    def show_load(self):
        content = LoadDialog(load = self.load, cancel = self.dismiss_popup)
        self._popup = Popup( title="読み込み中", content=content, size_hint=(0.9,0.9))
        self._popup.open()

    def load (self, path, filename):
        pprint(filename)
        self.file_name.text = filename[0]
        #with open (os.path.join(path, filename[0])) as stream:
        #    self.text_input.text = stream.read()
        self.dismiss_popup()

    def dismiss_popup(self):
        self._popup.dismiss()


class FilelistApp(App):
    def build(self):
        sm.add_widget(AllSCN(name='all'))
        sm.add_widget(AllSCN(name='set'))
        return AllSCN()


if __name__ == '__main__':
    FilelistApp().run()

filelist.kv


<SetSCN>:
    Label:
        text: 'おほほ'






<AllSCN>:
    BoxLayout:
        tv: tv
        file_name: file_name
        orientation: 'vertical'

        BoxLayout: #OpnSCN
            size_hint_y: 0.1
            Button:
                size_hint_x: 0.1
                text: '設定'
                on_release: root.setupButtonClicked()
            TextInput:
                id: file_name
                size_hint_x: 0.7
                text: 'ファイルパス'
            Button:
                size_hint_x: 0.1
                text: '…'
                on_release: root.show_load()
            Button:
                size_hint_x: 0.1
                text: '実行'

    BoxLayout: #ResultSCN
        size_hint_y: 0.9

        TreeView:
            id: tv

<LoadDialog>:
    BoxLayout:
        size: root.size
        pos: root.pos
        orientation: 'vertical'
        FileChooserListView:
            id: filechooser

        BoxLayout:
            size_hint_y : None
            height : 30
            Button:
                text: 'キャンセル'
                on_release: root.cancel()

            Button:
                text: '読み込み'
                on_release: root.load(filechooser.path, filechooser.selection)


AllSCN:

これで実行してみたら、

 

でた。

ObjectProperty(None)が、入っていない。

 

実験的に、

filelist.py……②


import os

from kivy.app import App

from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.popup import Popup
from kivy.uix.treeview import TreeViewLabel
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty

from pprint import pprint


from kivy.core.text import LabelBase, DEFAULT_FONT
from kivy.resources import resource_add_path

# 日本語フォント設定
resource_add_path('./fonts')
LabelBase.register(DEFAULT_FONT, 'ipaexg.ttf')

sm = ScreenManager()

load = ObjectProperty(None)
cancel = ObjectProperty(None)
tv = ObjectProperty(None)
file_name = ObjectProperty(None)
loadfile = ObjectProperty(None)
text_input = ObjectProperty(None)

class SetSCN(Screen):
    pass




class LoadDialog(FloatLayout):
    pass



class AllSCN(Screen):

    def __init__(self, **kwargs):
         super(AllSCN, self).__init__(**kwargs)
         self.tv.add_node(TreeViewLabel(text ='シンカリオン E1 とき'))
         self.tv.add_node(TreeViewLabel(text ='シンカリオン 0 ひかり'))
         self.tv.add_node(TreeViewLabel(text ='シンカリオン キハ32 鉄道ホビートレイン'))

    def setupButtonClicked(self):
        sm.current = 'set'


    def show_load(self):
        content = LoadDialog(load = self.load, cancel = self.dismiss_popup)
        self._popup = Popup( title="読み込み中", content=content, size_hint=(0.9,0.9))
        self._popup.open()

    def load (self, path, filename):
        pprint(filename)
        self.file_name.text = filename[0]
        #with open (os.path.join(path, filename[0])) as stream:
        #    self.text_input.text = stream.read()
        self.dismiss_popup()

    def dismiss_popup(self):
        self._popup.dismiss()


class FilelistApp(App):
    def build(self):
        sm.add_widget(AllSCN(name='all'))
        sm.add_widget(AllSCN(name='set'))
        return AllSCN()


if __name__ == '__main__':
    FilelistApp().run()

としても、

同じである。困った。

明らかに、ScreenManager関係のロジックを入れたらおかしくなったのだが、何故おかしくなったのだろうか?

(続く)