Hello.
I'm making a desktop application and have decided to create a markup layout in the main py file importing all the required widgets in the respective sections in order to make logic cleaner. I stumbled upon some issues:
1. What is the best practice to do it? Supposedly, I'm inventing a bicycle...
2. Why do I get a black screen If i write such a KV text (see below)? tree_widget and textable_widget are imported classes (see the whole code onwards).
<main_window>:
BoxLayout:
orientation: 'horizontal'
tree_widget:
textable_widget:
I can see my imported modules If I add a "standard" widget before:
<main_window>:
BoxLayout:
orientation: 'horizontal'
Label:
text: "Widget that I don't need"
tree_widget:
textable_widget:
2. How can I create interactions between two imported modules in the main application? I want to show, for example, an internal ID of each TreeView element ("num" NumericProperty in tree_class.py) in the right section (textable_widget). Roughly speaking, how to rewrite on_touch_down() method, that is initially used in tree_class.py, - in main.py? I inherit tree_widget class in main.py from tree_window class in tree_class.py but don't know how to get access to on_touch_down() method in tree_class.CustomLabel
main.py
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.lang.builder import Builder
import textable_class
import tree_class
Builder.load_string('''
<main_window>:
BoxLayout:
orientation: 'horizontal'
padding: 10
spacing: 10
Label:
text: "Widget that I don't need"
tree_widget:
textable_widget:
''')
class tree_widget(tree_class.tree_window):
pass
class textable_widget(textable_class.textable_widget):
pass
class main_window(FloatLayout):
pass
class mainApp(App):
title = "Sandbox"
def build(self):
return main_window()
if __name__ == '__main__':
mainApp().run()
tree_class.py
from kivy.app import App
from kivy.uix.treeview import TreeView
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.treeview import TreeViewLabel
from kivy.properties import NumericProperty
class CustomLabel(TreeViewLabel):
num = NumericProperty()
def on_touch_down(self, touch):
#do something
pass
class tree_window(BoxLayout):
def __init__(self, **kwargs):
super(tree_window, self).__init__(**kwargs)
tree = TreeView(root_options=dict(text='Tree Widget'))
for counter in range(1,11):
name = 'Label ' + str(counter)
tree.add_node(CustomLabel(text=name, num=counter))
self.add_widget(tree)
class tree_classApp(App):
def build(self):
return tree_window()
if __name__ == '__main__':
tree_classApp().run()
textable_class.py
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang.builder import Builder
from kivy.properties import ObjectProperty
Builder.load_string('''
<textable_widget>:
orientation: 'vertical'
Label:
id: var_label
text: 'Variable text'
''')
class textable_widget(BoxLayout):
pass
class textable_classApp(App):
def build(self):
return textable_widget()
if __name__ == '__main__':
textable_classApp().run()
Thank you in advance