前提・実現したいこと
"Kivyプログラミング Pythonでつくるマルチタッチアプリ"という本を読みながらはじめてアプリを作る初心者です。
kvファイルで、あるクラスにStringPropertyのプロパティDialogMsgを定義しました。
on_DialogMsgでモーダルビューが開くようにバインドしました。
DialogMsgを定義したクラスの下流にActionButtonを定義し、これをクリックすると、DialogMsgの値を変更するようにバインドし、on_DialogMsgが呼ばれるように書いたつもりですが、
実行すると、"Invalid data after declaration"とエラーが返ってきます。
なかなか治らず、行き詰っております。ご助言いただけましたら幸いです。
発生している問題・エラーメッセージ
41:<MainLayout>: >> 42: DialogMsg: 'None' 43: on_DialogMsg: self.view.open() 44: orientation: 'vertical' ... Invalid data after declaration
該当のソースコード
test.py
1from kivy.app import App 2from kivy.uix.boxlayout import BoxLayout 3from kivy.factory import Factory 4from kivy.uix.screenmanager import Screen 5from kivy.uix.modalview import ModalView 6import os, tkinter, tkinter.filedialog, tkinter.messagebox 7from kivy.core.text import LabelBase, DEFAULT_FONT 8from kivy.properties import StringProperty 9LabelBase.register(DEFAULT_FONT, 'mplus-1p-regular.ttf') 10 11 12class MyScreen(Screen): 13 def gotoTitle(self): 14 self.parent.current 15 self.add_widget(Factory.Title()) 16 17 def gotoMain(self): 18 self.clear_widgets() 19 self.add_widget(Factory.Main()) 20 21class MainLayout(BoxLayout): 22 23 #DialogMsg = StringProperty('None') 24 25 def __init__(self, **kwargs): 26 super(MainLayout, self).__init__(**kwargs) 27 self.view = Factory.DialogLayout() 28 29 def Filechoose(self): 30 root = tkinter.Tk() 31 root.withdraw() 32 fTyp = [("","*.csv")] 33 iDir = os.path.abspath(os.path.dirname(__file__)) 34 tkinter.messagebox.showinfo('お試し', '処理ファイルを選択してください!') 35 file = tkinter.filedialog.askopenfilename(filetype = fTyp, initialdir=iDir) 36 tkinter.messagebox.showinfo('お試し', file) 37 self.ids.filepath.text = file 38 39class testApp(App): 40 pass 41 42testApp().run() 43
test.kv
1#:import FadeTransition kivy.uix.screenmanager.FadeTransition 2#:set Str_ActionTextInput1 'Input file path here.' 3#:set Str_Dialog1 'File open' 4#:set Str_Dialog2 'DataFrame format?' 5 6Root: 7 8<Root@ScreenManager>: 9 transition: FadeTransition(duration=0.8) 10 TitleScreen: 11 MainScreen: 12 13<TitleScreen@MyScreen> 14 name: 'Title' 15 TitleLayout: 16 17<MainScreen@MyScreen> 18 name: 'Main' 19 MainLayout: 20 21<TitleLayout@BoxLayout>: 22 orientation: 'vertical' 23 Label: 24 size_hint_y: 0.75 25 text: 'Welcome to Fujit' 26 font_size: 64 27 BoxLayout: 28 orientation: 'horizontal' 29 size_hint_y: 0.25 30 padding: [0, 0, 30, 30] 31 Label: 32 size_hint_x: 0.6 33 text: '' 34 Button: 35 size_hint_x: 0.4 36 text: 'Go' 37 font_size: 32 38 on_release: 39 app.root.current = 'Main' 40# ↓このクラスが怪しいです 41<MainLayout>: 42 DialogMsg: 'None' 43 on_DialogMsg: self.view.open() 44 orientation: 'vertical' 45 canvas.before: 46 Color: 47 rgb: 0, 0, 0 48 Rectangle: 49 pos: self.pos 50 size: self.size 51 ActionBar: 52 padding: 5 53 ActionView: 54 ActionPrevious: 55 title: 'Fujit02' 56 id: actionPrevious 57 ActionButton: 58 text: 'File:' 59 on_release: root.Filechoose() 60 ActionTextInput: 61 id: filepath 62 on_text: 63 text: Str_ActionTextInput1 64 if self.text!=Str_ActionTextInput1: self.foreground_color=[0,0,0,1] 65 ActionButton: 66 text: 'go' 67 on_release: root.DialogMsg = Str_Dialog2 68 BoxLayout: 69 orientation:'horizontal' 70 Accordion: 71 size_hint_x: 0.3 72 orientation: 'vertical' 73 AccordionItem: 74 text: 'Task1' 75 AccordionItem: 76 text: 'Task2' 77 AccordionItem: 78 text: 'Task3' 79 Button: 80 size_hint_x: 0.7 81 text: 'OK' 82 id: button 83 on_press: self.view.open() 84 85<ActionTextInput@ActionItem+TextInput>: 86 background_normal: '<ATLAS>/textinput_active' 87 foreground_color: [0.7,0.7,0.7,1] 88 multiline: False 89 90<DialogLayout@ModalView>: 91 size_hint: 0.5, 0.5 92 BoxLayout: 93 orientation: 'vertical' 94 padding: self.width/10 95 Label: 96 text: root.parent.DialogMsg 97 Button: 98 text: 'Yes' 99 on_release: 100 root.dismiss() 101 Button: 102 text: 'No' 103 on_release: 104 root.dismiss(); app.root.current = 'Title'
試したこと
on_DialogMsgのインデントを一つ下げました。
pythonコードでDialogMsgの定義をコメントアウトしました。
on_press: self.view.open()の行をコメントアウトしました。
しかし、すべてダメでした。。。
補足情報(FW/ツールのバージョンなど)
特にございません。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。