I wanna display the Excel data with splitting on their null value rows and display them on new screen each until it reach the end of the excel row but in my code it ask me to create screen for all another screen to be displayed.
I wanna display the Excel data with splitting on their null value rows and display them on new screen each until it reach the end of the excel row
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.filechooser import FileChooserIconView
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView
import pandas as pd
# import numpy as np
class FileChooserScreen(Screen):
def __init__(self, **kwargs):
super(FileChooserScreen, self).__init__(**kwargs)
self.layout = BoxLayout(orientation='vertical')
self.filechooser = FileChooserIconView(filters=['*.xlsx'])
self.read_button = Button(text="Read", on_release=self.read_file)
self.next_button = Button(text="Next", on_release=self.go_next)
self.scrollview = ScrollView()
self.label = Label(size_hint_y=None)
self.scrollview.add_widget(self.label)
self.layout.add_widget(self.filechooser)
self.layout.add_widget(self.read_button)
self.layout.add_widget(self.next_button)
self.layout.add_widget(self.scrollview)
self.add_widget(self.layout)
def read_file(self, *args):
try:
selected_file = self.filechooser.selection[0]
df = pd.read_excel(selected_file)
# Find the first null value in the dataframe
first_null_index = df.isnull().any(axis=1).idxmax()
second_null_index = df.iloc[first_null_index + 1:].isnull().any(axis=1).idxmax() + first_null_index + 1
third_null_index = df.iloc[second_null_index + 1:].isnull().any(axis=1).idxmax() + second_null_index + 1
fourth_null_index = df.iloc[third_null_index + 1:].isnull().any(axis=1).idxmax() + third_null_index + 1
# Display only the rows until the first null value
#df_string = self.df.iloc[:first_null_index].to_string()
df_string = df.iloc[:first_null_index].to_string()
self.label.text = df_string
self.label.height = self.label.texture_size[1]
self.scrollview.scroll_y = 1
# Pass the remaining rows to the next screen
# df_string = df.iloc[first_null_index:second_null_index].to_string()
# self.label.text = df_string
# self.label.height = self.label.texture_size[1]
# self.scrollview.scroll_y = 1
#
# df_string = df.iloc[second_null_index:third_null_index].to_string()
# self.label.text = df_string
# self.label.height = self.label.texture_size[1]
# self.scrollview.scroll_y = 1
# self.manager.get_screen('display').update_label(next_df_string)
next_df_string = df.iloc[first_null_index + 1:second_null_index].dropna().to_string(header=False)
self.manager.get_screen('display').update_label(next_df_string)
second_df_string = df.iloc[second_null_index + 1 :third_null_index].dropna().to_string(header=False)
self.manager.get_screen('lala').update_label(second_df_string)
third_df_string = df.iloc[third_null_index + 1:fourth_null_index].dropna().to_string(header=False)
self.manager.get_screen('lala1').update_label(third_df_string)
fourth_df_string = df.iloc[third_null_index+ 2:fourth_null_index].dropna().to_string(header=False)
self.manager.get_screen('lala2').update_label(fourth_df_string)
except IndexError:
pass
def go_next(self, *args):
# Go to the next screen here
self.manager.current = 'display'
class DisplayScreen(Screen):
def __init__(self, **kwargs):
super(DisplayScreen, self).__init__(**kwargs)
self.layout = BoxLayout(orientation='vertical')
self.scrollview = ScrollView()
self.label = Label(size_hint_y=None)
self.scrollview.add_widget(self.label)
self.layout.add_widget(self.scrollview)
self.add_widget(self.layout)
self.next_button = Button(text="Next", on_release=self.go_next)
self.layout.add_widget(self.next_button)
def update_label(self, text):
self.label.text = text
self.label.height = self.label.texture_size[1]
self.scrollview.scroll_y = 1
def go_next(self, *args):
# Go to the next screen here
self.manager.current = 'lala'
class Second(Screen):
def __init__(self, **kwargs):
super(Second, self).__init__(**kwargs)
self.layout = BoxLayout(orientation='vertical')
self.scrollview = ScrollView()
self.label = Label(size_hint_y=None)
self.scrollview.add_widget(self.label)
self.layout.add_widget(self.scrollview)
self.add_widget(self.layout)
self.next_button = Button(text="Next", on_release=self.go_next)
self.layout.add_widget(self.next_button)
def update_label(self, text):
self.label.text = text
self.label.height = self.label.texture_size[1]
self.scrollview.scroll_y = 1
def go_next(self, *args):
# Go to the next screen here
self.manager.current = 'lala1'
class Third(Screen):
def __init__(self, **kwargs):
super(Third, self).__init__(**kwargs)
self.layout = BoxLayout(orientation='vertical')
self.scrollview = ScrollView()
self.label = Label(size_hint_y=None)
self.scrollview.add_widget(self.label)
self.layout.add_widget(self.scrollview)
self.add_widget(self.layout)
self.next_button = Button(text="Next", on_release=self.go_next)
self.layout.add_widget(self.next_button)
def update_label(self, text):
self.label.text = text
self.label.height = self.label.texture_size[1]
self.scrollview.scroll_y = 1
def go_next(self, *args):
# Go to the next screen here
self.manager.current = 'lala2'
class Fourth(Screen):
def __init__(self, **kwargs):
super(Fourth, self).__init__(**kwargs)
self.layout = BoxLayout(orientation='vertical')
self.scrollview = ScrollView()
self.label = Label(size_hint_y=None)
self.scrollview.add_widget(self.label)
self.layout.add_widget(self.scrollview)
self.add_widget(self.layout)
self.next_button = Button(text="Next", on_release=self.go_next)
self.layout.add_widget(self.next_button)
def update_label(self, text):
self.label.text = text
self.label.height = self.label.texture_size[1]
self.scrollview.scroll_y = 1
def go_next(self, *args):
# Go to the next screen here
self.manager.current = 'lala2'
class MyScreenManager(ScreenManager):
def __init__(self, **kwargs):
super(MyScreenManager, self).__init__(**kwargs)
class MyApp(App):
def build(self):
sm = MyScreenManager()
sm.add_widget(FileChooserScreen(name='choose'))
sm.add_widget(DisplayScreen(name='display'))
sm.add_widget(Second(name='lala'))
sm.add_widget(Third(name='lala1'))
sm.add_widget(Fourth(name='lala2'))
return sm
if __name__ == '__main__':
MyApp().run()