0
votes

I am new to the area and trying to write a small app with Kivy. I have a Home Screen and a WaveScreen. The WaveScreen is supposed to plot a RealTime SensorData. WaveScreen.py

import numpy as np
from kivy.lang import Builder
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy_garden.graph import MeshLinePlot
from kivy.clock import Clock
from threading import Thread
from kivy.core.window import Window

Window.size = (320, 600)


def getAttentionLevel():
    global attention
    while True:
        data = np.genfromtxt('../sensorOutput.csv', delimiter=',', dtype=float)
        lines = []
        for line in data:
            lines.append(line)
            if len(lines) > 100:
                lines.pop(0)
        attention = [row[10] for row in lines]


class Logic(BoxLayout):
    def __init__(self, **kwargs):
        super(Logic, self).__init__(**kwargs)
        self.plot = MeshLinePlot(color=[1, 0, 0, 1])

    def start(self):
        self.ids.graph.add_plot(self.plot)
        Clock.schedule_interval(self.get_value, 1 / 60)

    def stop(self):
        Clock.unschedule(self.get_value)

    def get_value(self, dt):
        self.plot.points = [(i, j) for i, j in enumerate(attention)]


class RealTimeMicrophone(App):
    def build(self):
        return Builder.load_file("../KV/wavescreen.kv")

    def runWave(self):
        levels = []  # store levels of microphone
        get_level_thread = Thread(target=getAttentionLevel)
        get_level_thread.daemon = True
        get_level_thread.start()
        RealTimeMicrophone().run()

RealTimeMicrophone().runWave()

wavescreen.kv

#:import MeshLinePlot kivy.garden.graph.MeshLinePlot
Logic:
    BoxLayout:
        orientation: "vertical"
        canvas.before:
            Color:
                rgba: 1, 1, 1, 1
            Rectangle:
                pos: self.pos
                size: self.size
        BoxLayout:
            size_hint: [1, .8]
            Graph:
                canvas.before:
                    Color:
                        rgba: 0, 1, 1, 1
                    Rectangle:
                        pos: self.pos
                        size: self.size
                id: graph
                xlabel: ""
                ylabel: ""
                size_hint: [1, .3]
                pos_hint: {"center_x": .5, "center_y": .848}


        BoxLayout:
            size_hint: [1, .2]
            orientation: "horizontal"
            Button:
                text: "START"
                bold: True
                on_press: root.start()
            Button:
                text: "STOP"
                bold: True
                on_press: root.stop()

My HomeScreen contains BottomNavigation with some screens. I want to display my WaveScreen as one the screens in HomeScreen. HomeScreen.py

from kivy.metrics import dp
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.core.window import Window
from kivymd.uix.menu import MDDropdownMenu
from kivymd.uix.snackbar import Snackbar
from kivymd.icon_definitions import md_icons


colors = {
    "Teal": {
        "50": "e4f8f9",
        "100": "bdedf0",
        "200": "97e2e8",
        "300": "79d5de",
        "400": "6dcbd6",
        "500": "6ac2cf",
        "600": "63b2bc",
        "700": "5b9ca3",
        "800": "54888c",
        "900": "486363",
        "A100": "bdedf0",
        "A200": "97e2e8",
        "A400": "6dcbd6",
        "A700": "5b9ca3",
    },
    "Blue": {
        "50": "e3f3f8",
        "100": "b9e1ee",
        "200": "91cee3",
        "300": "72bad6",
        "400": "62acce",
        "500": "ffffff",
        "600": "5191b8",
        "700": "487fa5",
        "800": "426f91",
        "900": "35506d",
        "A100": "b9e1ee",
        "A200": "91cee3",
        "A400": "62acce",
        "A700": "487fa5",
    },
    "Light": {
        "StatusBar": "E0E0E0",
        "AppBar": "F5F5F5",
        "Background": "FAFAFA",
        "CardsDialogs": "FFFFFF",
        "FlatButtonDown": "cccccc",
    },
    "Dark": {
        "StatusBar": "000000",
        "AppBar": "212121",
        "Background": "303030",
        "CardsDialogs": "424242",
        "FlatButtonDown": "999999",
    }
}

Window.size = (320, 600)


class HomeScreen(MDApp):
    icons = list(md_icons.keys())[15:30]

    def build(self):
        self.theme_cls.theme_style = "Light"
        self.theme_cls.colors = colors
        self.theme_cls.primary_palette = "Blue"
        self.theme_cls.accent_palette = "Teal"

        menu_items = [
            {
                "viewclass": "OneLineListItem",
                "text": f"Item {i}",
                "height": dp(56),
                "on_release": lambda x=f"Item {i}": self.menu_callback(x),
            } for i in range(5)
        ]
        self.menu = MDDropdownMenu(
            items=menu_items,
            width_mult=4,
        )

        return Builder.load_file("KV/homescreen.kv")

    def callback(self, button):
        self.menu.caller = button
        self.menu.open()

    def menu_callback(self, text_item):
        self.menu.dismiss()
        Snackbar(text=text_item).open()

homescreen.kv

MDBoxLayout:
    orientation:'vertical'
    MDToolbar:
        #title: "MDToolbar"
        md_bg_color: 14/255, 154/255, 167/255, 1
        #md_bg_color: 47/255, 47/255, 47/255, 1
        left_action_items: [["menu", lambda x: app.callback(x)]]
        right_action_items: [["dots-vertical", lambda x: app.callback(x)]]
        elevation: 10
    #MDLabel:
        #text: "Content"
        #halign: "center"


    MDBottomNavigation:
        panel_color: 14/255, 154/255, 167/255, 1

        MDBottomNavigationItem:
            name: 'Wave'
            #text: 'Home'
            icon: 'waveform'
            #Here I would like to display my WaveScreen 

How can i do it? I would be very grateful for your help