How to use the RST module in Kivy? - python

I'm creating a fitness/nutrition app in Kivy. The problem is that most of the screens involve text for the viewer to read and I don't want the text to be just plain old text like that of a .txt file. I tried looking for something and I found there is a RST rendering module that will make my text look good but after trying for a couple of days, I can't seem to get it working with my code. Also I want to put the text that I will be using with RST into a seperate file so I can keep my code clean, how would I be able to do that?
Python Code(main.py):
import kivy
kivy.require('1.9.0')
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.stacklayout import StackLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ListProperty, StringProperty, OptionProperty, VariableListProperty
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.graphics import *
from kivy.base import runTouchApp
from kivy.uix.label import Label
class MainScreen(Screen):
pass
class NutritionScreen(Screen):
pass
class FitnessScreen(Screen):
pass
class CalorcalcScreen(Screen):
pass
class BigsixScreen(Screen):
pass
class ProteinScreen(Screen):
pass
class CarbScreen(Screen):
pass
class FatScreen(Screen):
pass
class VitaminScreen(Screen):
pass
class MineralScreen(Screen):
pass
class WaterScreen(Screen):
pass
class SuppleScreen(Screen):
pass
class DietScreen(Screen):
pass
class ExerciseScreen(Screen):
pass
class WorkoutplanScreen(Screen):
pass
class ScreenManagement(ScreenManager):
pass
presentation = Builder.load_file("nutrifit.kv")
class NutrifitApp(App):
def build(self):
return presentation
nfApp = NutrifitApp()
nfApp.run()
Kivy Code(nutrifit.kv):
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
ScreenManagement:
transition: FadeTransition()
MainScreen:
NutritionScreen:
FitnessScreen:
CalorcalcScreen:
BigsixScreen:
SuppleScreen:
DietScreen:
ExerciseScreen:
WorkoutplanScreen:
ProteinScreen:
CarbScreen:
FatScreen:
VitaminScreen:
MineralScreen:
WaterScreen:
<MainScreen>:
name: 'main'
GridLayout:
cols: 1
rows: 3
spacing: 1
padding: 1
Button:
text: "Nutrition"
font_size: 25
on_release: app.root.current = "nutrition"
Button:
text: "Fitness"
font_size: 25
on_release: app.root.current = "fitness"
################################################################################
<NutritionScreen>:
name: 'nutrition'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Home'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "main"
Label:
text: 'Nutrition'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"center": 1, "top": 1}
BoxLayout:
orientation: 'vertical'
size_hint: 1, .9
Button:
text: "Caloric Calculator"
font_size: 25
on_release: app.root.current = "calorcalc"
Button:
text: "The Big Six"
font_size: 25
on_release: app.root.current = "bigsix"
Button:
text: "Supplementation"
font_size: 25
on_release: app.root.current = "supple"
Button:
text: "Diets"
font_size: 25
on_release: app.root.current = "diet"
<CalorcalcScreen>:
name: 'calorcalc'
<BackBar#ButtonBehavior+BoxLayout>:
orientation: 'horizontal'
bgcolor: [1, 0, 0, 1]
on_press: self.bgcolor = [1, 0, 0, .5]
on_release: self.bgcolor = [1, 0, 0, 1]
canvas:
Color:
rgba: root.bgcolor
Rectangle:
pos: self.pos
size: self.size
Label:
text: '<--'
size_hint_x: None
width: root.height
Label:
text: 'Current name'
text_size: self.size
halign: 'left'
valign: 'middle'
RstDocument:
text: root.text
<BigsixScreen>:
name: 'bigsix'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "nutrition"
GridLayout:
cols: 2
rows: 3
size_hint: 1, .9
Button:
text: 'Protein'
on_release: app.root.current = 'protein'
Button:
text: 'Carbohydrates'
on_release: app.root.current = 'carb'
Button:
text: 'Fats'
on_release: app.root.current = 'fat'
Button:
text: 'Vitamins'
on_release: app.root.current = 'vitamin'
Button:
text: 'Minerals'
on_release: app.root.current = 'mineral'
Button:
text: 'Water'
on_release: app.root.current = 'water'
<ProteinScreen>:
name: 'protein'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "bigsix"
Label:
text: 'Protein'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
FloatLayout:
Label:
text: 'this is protein'
pos_hint: {"center_x": .5, "center_y": .5}
<CarbScreen>:
name: 'carb'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "bigsix"
Label:
text: 'Carbohydrates'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
FloatLayout:
Label:
text: 'this is carbs'
pos_hint: {"center_x": .5, "center_y": .5}
<FatScreen>:
name: 'fat'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "bigsix"
Label:
text: 'Fats'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
FloatLayout:
Label:
text: 'this is fats'
pos_hint: {"center_x": .5, "center_y": .5}
<MineralScreen>:
name: 'mineral'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "bigsix"
Label:
text: 'Minerals'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
FloatLayout:
Label:
text: 'this is minerals'
pos_hint: {"center_x": .5, "center_y": .5}
<VitaminScreen>:
name: 'vitamin'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "bigsix"
Label:
text: 'Vitamins'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
FloatLayout:
Label:
text: 'this is vitamins'
pos_hint: {"center_x": .5, "center_y": .5}
<WaterScreen>:
name: 'water'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "bigsix"
Label:
text: 'Water'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
FloatLayout:
Label:
text: 'this is water'
pos_hint: {"center_x": .5, "center_y": .5}
<SuppleScreen>:
name: 'supple'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "nutrition"
Label:
text: 'Supplementation'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
BoxLayout:
orientation: 'vertical'
size_hint: 1, .9
<DietScreen>:
name: 'diet'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "nutrition"
Label:
text: 'Diets'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
BoxLayout:
orientation: 'vertical'
size_hint: 1, .9
################################################################################
<FitnessScreen>:
name: 'fitness'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Home'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "main"
Label:
text: 'Fitness'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
BoxLayout:
orientation: 'vertical'
size_hint: 1, .9
Button:
text: "Exercises"
font_size: 25
on_release: app.root.current = "exercise"
Button:
text: "The Big Six"
font_size: 25
on_release: app.root.current = "workoutplan"
<WorkoutplanScreen>:
name: 'workoutplan'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "fitness"
Label:
text: 'Workout Plans'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
BoxLayout:
orientation: 'vertical'
size_hint: 1, .9
<ExerciseScreen>:
name: 'exercise'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "fitness"
Label:
text: 'Exercises'
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
BoxLayout:
orientation: 'vertical'
size_hint: 1, .9
This is if I set it to vertical:
first example
This is if I enter the parameters:
size_hint: .5, .1
pos_hint: {"x": 0, "top": 1}
second example

How to use RST Document in Kivy?
Rreference: reStructuredText renderer
Reading text from an input File:
1. Create an input File - inFile.txt
Create a file called "inFile.txt" with the following text:
.. _top:
Hello world
===========
This is an **emphased text**, some ``interpreted text``.
And this is a reference to top_::
$ print("Hello world")
2. Edit class CalorcalcScreen
Replaced "pass" with the following code in your class CalorcalcScreen(Screen):
class CalorcalcScreen(Screen):
text = ""
with open("inFile.txt") as fobj:
for line in fobj:
text += line
3. Edit kv Rule file - nutrifit.kv
At <CalcorcalcScreen>, replace "Label" with "RstDocument" and remove "document = RstDocument..."
<CalorcalcScreen>:
name: 'calorcalc'
BoxLayout:
orientation: 'horizontal'
spacing: 1
padding: 1
Button:
text: 'Back'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
on_release: app.root.current = "nutrition"
Label:
text: ''
size_hint_y: .1
size_hint_x: 1
pos_hint: {"right": 1, "top": 1}
BoxLayout:
orientation: 'vertical'
size_hint: 1, .9
RstDocument:
text: root.text
<BigsixScreen>:
New Navigation Bar
Edit kv Rule file
Please update your kv rule file as follow:
<BackBar#ButtonBehavior+BoxLayout>:
orientation: 'horizontal'
bgcolor: [1, 0, 0, 1]
on_press: self.bgcolor = [1, 0, 0, .5]
on_release: self.bgcolor = [1, 0, 0, 1]
canvas:
Color:
rgba: root.bgcolor
Rectangle:
pos: self.pos
size: self.size
Label:
text: '<--'
size_hint: .25, .1
pos_hint: {"x": 0, "top": 1}
Label:
text: 'Current name'
text_size: self.size
halign: 'left'
valign: 'middle'
size_hint: 1, .1
pos_hint: {"right": 1, "top": 1}
<CalorcalcScreen>:
name: 'calorcalc'
BackBar:
BoxLayout:
orientation: 'vertical'
size_hint: 1, .9
RstDocument:
text: root.text
<BigsixScreen>:
Output

Related

Updating labels with user input from MDTextField

I'm trying to print user input from MDTextField to a label, but I keep getting "AttributeError: 'super' object has no attribute 'getattr'".
Here's my python file:
'''
class TodoLayout(MDScreen, MDFloatLayout):
pass
class CatLayout(Screen):
pass
class WindowManager(ScreenManager):
pass
class BullyCat(MDApp, App):
def get_data(self):
user_input = (self.root.get_screen("to_do_view").ids.data.text)
self.root.get_screen("to_do_view").ids.label_id.text = user_input
def build(self):
return Builder.load_file("kivyfile.kv")
def add_todo(self):
global screen_manager
screen_manager = ScreenManager()
screen_manager.get_screen("main").todo_list.add_widget(TodoCard())
if __name__ == "__main__":
BullyCat().run()
'''
Here's my .kv file:
'''
WindowManager:
TodoLayout:
CatLayout:
<TodoLayout>:
name: "to_do_view"
MDScreen:
id: 'main'
name: 'main'
MDFloatLayout:
md_bg_color: 0, 1, 0, .1
MDLabel:
text: "MyTasks"
pos_hint: {"center_x": .9, "center_y": .95}
font_size: "35sp"
MDLabel:
id: date
text: ""
pos_hint: {"center_x": .885, "center_y": .89}
font_size: "18sp"
MDIconButton:
icon: "plus"
pos_hint: {"center_x": .92, "center_y": .925}
user_font_size: "30sp"
md_bg_color: 30/255, 1, 30/255, 0.8
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
on_release: on_release: root.ids.add_input.text = choice(app.my_list)
MDIconButton:
icon: "cat"
pos_hint: {"center_x": .075, "center_y": .925}
user_font_size: "30sp"
md_bg_color: 30/255, 1, 30/255, 0.8
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
on_release:
app.root.current = "cat_view"
root.manager.transition.direction = "left"
MDTextField:
id: data
hint_text: "Write a task"
pos_hint: {"center_x": .5, "center_y": .1}
size_hint: 0.5, None
MDRectangleFlatButton:
text: 'add'
pos_hint: {"center_x": .8, "center_y": .1}
on_release: app.get_data()
MDLabel:
id: 'label_id'
text: 'Task 1'
pos_hint: {"center_x": .9, "center_y": .8}
font_size: 30
<CatLayout>:
name: 'cat_view'
MDScreen:
id: 'second'
name: 'second'
MDFloatLayout:
md_bg_color: 0, 1, 0, .1
MDIconButton:
icon: "pencil"
pos_hint: {"center_x": .075, "center_y": .925}
user_font_size: "30sp"
md_bg_color: 30/255, 1, 30/255, 0.8
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
on_release:
app.root.current = "to_do_view"
root.manager.transition.direction = "right"
MDTextField:
hint_text: "Persistent helper text"
pos_hint: {"center_x": .5, "center_y": .1}
size_hint: 0.5, None
'''
Ultimately i'm trying to build a to-do app with an animated cat that will bully you verbally into doing your tasks.
I suspect the problem lies within here:
def get_data(self):
user_input = (self.root.get_screen("to_do_view").ids.data.text)
self.root.get_screen("to_do_view").ids.label_id.text = user_input
I am very new to coding and i'm a bit lost here. Thanks a lot!
Ids in your kv should not be enclosed in quotes. Just change:
id: 'label_id'
to:
id: label_id

KivyMD Text Field doesn't work, recieve attribute error when pressing clear button and MD Cards arent aligned properly

I completed my code for main window which is the login page and I'm writing my code for the second page. Then, I tried to use the text field on my login screen and I can't type in it. However, before making my second window, the text field worked as expected and I can type in it. What could cause this issue?
Furthermore, I recieve an error (AttributeError: 'super' object has no attribute 'getattr'
) when I tried to press the clear button in main window.
Also, if you tried to run this code and see the second window, you will notice 3 MD cards not aligned properly if you don't expand the window to full size. if you have any idea how to fix it, please let me know.
SUMMARY OF WHAT I'M TRYING TO ACHIEVE HERE:
Figure out what why I can't use the textfield in main window
Fix the error when press the clear button
Align MD Cards properly
.py file
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.screenmanager import ScreenManager, Screen
class MainWindow(Screen):
pass
class SecondWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
class BaseApp(MDApp):
def build(self):
self.theme_cls.theme_style = "Light"
self.theme_cls.primary_palette = "Green"
return Builder.load_file("base.kv")
def clear(self):
self.root.ids.user.text = ""
self.root.ids.passw.text = ""
if __name__ == "__main__":
BaseApp().run()```
.kv file
# Filename: base.kv
#:kivy 2.1.0
#:include main.py
WindowManager:
MainWindow:
SecondWindow:
<MainWindow>:
name: "main"
Screen:
MDCard:
size_hint: None, None
size: 400, 500
pos_hint: {"center_x": 0.5, "center_y": 0.5}
elevation: 10
padding: 25
spacing: 25
orientation: "vertical"
MDLabel:
id: login_label
text: "WELCOME TO JAMES MADISON/n HIGH SCHOOL STUDENTS APP"
font_size: 22
font_name: "Raleway-Regular"
halign: "center"
size_hint_y: None
height: self.texture_size[1]
padding_y: 15
MDBoxLayout:
Image:
source: "jmhs.png"
size_hint_x: 1.15
halign: "center"
size_hint_y: 1.15
height: self.texture_size[1]
padding_y: 10
MDTextFieldRound:
id: user
hint_text: "Username"
icon_right: "account"
size_hint_x: None
width: 200
font_size: 18
font_name: "Roboto-Regular"
pos_hint: {"center_x": 0.5}
MDTextFieldRound:
id: passw
hint_text: "Password"
icon_right: "eye-off"
size_hint_x: None
width: 200
font_size: 18
font_name: "Roboto-Regular"
pos_hint: {"center_x": 0.5}
password: True
MDRoundFlatButton:
text: "LOG IN"
font_size: 12
font_name: "Raleway-Regular"
pos_hint: {"center_x": 0.5}
on_press:
app.root.current = "second"
root.manager.transition.direction = "left"
MDRoundFlatButton:
text: "CLEAR"
font_size: 12
font_name: "Raleway-Regular"
pos_hint: {"center_x": 0.5}
on_press: app.clear()
<SecondWindow>:
name: "second"
MDBoxLayout:
orientation: "horizontal"
MDBoxLayout:
size_hint: .225, 1
canvas.before:
Color:
rgba: 0, 0, 0, 0
Rectangle:
pos: self.pos
size: self.size
MDBoxLayout:
orientation: "vertical"
spacing: "10dp"
size_hint: 1, 1
canvas.before:
Color:
rgba: 227/255, 255/255, 226/255, 0.8
Rectangle:
pos: self.pos
size: self.size
MDBoxLayout:
spacing: "10dp"
size_hint: 1, .1
MDBoxLayout:
spacing: "10dp"
size_hint: 1, .9
canvas.before:
Color:
rgba: 227/255, 255/255, 226/255, 0.8
Rectangle:
pos: self.pos
size: self.size
MDGridLayout:
cols: 3
padding: 18
spacing: "20dp"
MDCard:
padding: 16
elevation: 0
border_radius: 20
radius: [15]
size_hint: None, None
size: "370dp", "140dp"
pos_hint: {"center_x": .5, "center_y": .5}
MDCard:
padding: 16
elevation: 0
border_radius: 20
radius: [15]
size_hint: None, None
size: "370dp", "140dp"
pos_hint: {"center_x": .5, "center_y": .5}
MDCard:
padding: 16
elevation: 0
border_radius: 20
radius: [15]
size_hint: None, None
size: "200dp", "140dp"
pos_hint: {"center_x": .5, "center_y": .5}
MDBoxLayout:
size_hint: .29, 1
canvas.before:
Color:
rgba: 0, 0, 0, 0
Rectangle:
pos: self.pos
size: self.size

Gridlayout height based on Label height in recycleview not aligned

I have managed to get the size of a box layout to change based on the corresponding Label height, however, it doesn't line up perfectly and I cannot figure out why.
I have looked at adding offsets but have had no luck since it ended up making the issue worse
Thank you for any help
MainInterface:
<MainInterface#BoxLayout>:
orientation: "vertical"
Label:
#font_name: "Nunito-Black.ttf"
text: "T R U T H"
size_hint: 1, 0.1
GridLayout:
size_hint: 1, 0.12
cols: 4
Button:
text: "Menu1"
Button:
text: "Menu2"
Button:
text: "Menu3"
Button:
text: "Menu4"
PageLayout:
border: "20dp"
swipe_threshold: 0.2
RecycleView:
viewclass: 'PostGrid'
scroll_y: 1
id: rv
data: app.posts
RecycleBoxLayout:
id: box
default_size: None, None
default_size_hint: 1, None
size_hint_y: None
padding: ["10dp", "16dp"]
spacing: "8dp"
height: self.minimum_height
orientation: 'vertical'
key_size: '_size'
BoxLayout:
orientation: "vertical"
Button:
text: "peni"
Button:
text: "tag # will J"
Button:
text: "Input"
<PostGrid#BoxLayout>:
message_id: -1
orientation: "horizontal"
text: ''
spacing: "10dp"
#size_hint: self.width, None
_size: 0, 74
size: 0, 74
text_size: None, None
BoxLayout:
orientation: "vertical"
spacing: "10dp"
size_hint: .1, 1
size: self.size
Button:
text: "UP"
font_size: "5dp"
size_hint: 1, 0.2
Button:
text: "DOWN"
font_size: "5dp"
size_hint: 1, 0.2
Label:
text: "test"
font_size: "5dp"
size_hint: 1, 0.6
Label:
text: root.text
padding: 5, 5
size_hint: .9, 1
#size: self.texture_size
height: self.texture_size[1]
text_size: self.width, None
color: 0,0,0,1
#text_size: self.width, None
#size_hint: None, 1
#size: self.texture_size
#font_name: "Nunito-Bold.ttf"
#font_size: "12dp"
multiline: True
#size: 1, root.min_height
on_texture_size:
app.update_message_size(
root.message_id,
self.texture_size,
root.width)
pos: self.pos
canvas.before:
Color:
rgba: (0.8, 0.8, 0.8, 1)
RoundedRectangle:
size: self.texture_size
radius: [5, 5, 5, 5]
pos: self.x, self.y
canvas:
Color:
rgba:0,0.9,0.9,1
Line:
width:0.8
rounded_rectangle:(self.x,self.y,self.width,self.height, 5)
from kivy.app import App
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.properties import ListProperty
from kivy.animation import Animation
from kivy.metrics import dp
class TruthApp(App):
posts = ListProperty([{'message_id':0, 'text':"testskjhfjksdhfkjshfjshfjkhskjdfhskjdhfkjshfdkjhsjkdfhskjhdfkjshdfjkhzxczxczxczxcxzczxcxsjkdfhjksdhfkjshkjdfhksjdhfjkshdfjkhsdkjhfkjshdfjkshkjfhskjhfkjshfjkshdkjfhskjhfjshfkjshdfjkshdjkfhskjhfkjshfjksdhjfhsjkdhfjkhsdkjfhskjhfjk\ngdgdgd\ndgdgdg\ndgdgdg\ndggdgd",'_size':[0,0] }, {'message_id':1, 'text':"testskjhfjksdhfkjshfjshfjkhskjdfhskjdhfkjshfdkjhsjkdfhskjhjfhskjhfjk,'_size':[0,0]"}])
def update_message_size(self, message_id, texture_size, max_width):
#print(self.posts)
#print("Here")
self.posts[message_id] = {**self.posts[message_id], '_size':[0, texture_size[1]]}
if __name__ == '__main__':
TruthApp().run()
^ Image showing how the code above runs
The problem is in the viewclass of RecycleView (i.e. PostGrid). You set its heightas such it could not accomodate its children which is supposed to be the minimum height that will place all its children.
Now that's exactly the attr. minimum_height does. With this being applied you also don't need default_size: None, None (especially the height attr.)
With this and other modifications your .kv file should now look like,
MainInterface:
<MainInterface#BoxLayout>:
orientation: "vertical"
Label:
#font_name: "Nunito-Black.ttf"
text: "T R U T H"
size_hint: 1, 0.1
GridLayout:
size_hint: 1, 0.12
cols: 4
Button:
text: "Menu1"
Button:
text: "Menu2"
Button:
text: "Menu3"
Button:
text: "Menu4"
PageLayout:
border: "20dp"
swipe_threshold: 0.2
RecycleView:
viewclass: 'PostGrid'
scroll_y: 1
id: rv
data: app.posts
RecycleBoxLayout:
id: box
default_size_hint: 1, None
size_hint_y: None
padding: ["10dp", "16dp"]
spacing: "8dp"
height: self.minimum_height
orientation: 'vertical'
key_size: '_size'
BoxLayout:
orientation: "vertical"
Button:
text: "peni"
Button:
text: "tag # will J"
Button:
text: "Input"
<PostGrid#BoxLayout>:
message_id: -1
orientation: "horizontal"
text: ''
spacing: "10dp"
size_hint_y: None
#_size: 0, 74
height: self.minimum_height
text_size: None, None
BoxLayout:
orientation: "vertical"
spacing: "10dp"
size_hint: .1, 1
Button:
text: "UP"
font_size: "5dp"
size_hint: 1, 0.2
Button:
text: "DOWN"
font_size: "5dp"
size_hint: 1, 0.2
Label:
text: "test"
font_size: "5dp"
size_hint: 1, 0.6
Label:
text: root.text
padding: 5, 5
#size_hint: .9, 1
#size: self.texture_size
size_hint_y: None
height: self.texture_size[1]
text_size: self.width, None
color: 0,0,0,1
#text_size: self.width, None
#size_hint: None, 1
#size: self.texture_size
#font_name: "Nunito-Bold.ttf"
#font_size: "12dp"
multiline: True
#size: 1, root.min_height
on_texture_size:
app.update_message_size(
root.message_id,
self.texture_size,
root.width)
pos: self.pos
canvas.before:
Color:
rgba: (0.8, 0.8, 0.8, 1)
RoundedRectangle:
size: self.texture_size
radius: [5, 5, 5, 5]
pos: self.x, self.y
canvas:
Color:
rgba:0,0.9,0.9,1
Line:
width:0.8
rounded_rectangle:(self.x,self.y,self.width,self.height, 5)

kivy VideoPlayer: Video does not return to its original size after full screen mode

When I double click on the video, it goes full screen, but if I double click on it again, it doesn't go back to normal. However, the rest of the window elements are partially visible. The part of my .kv code responsible for the VideoPlayer is given below:
<VideosWindow>:
name: 'vids'
FloatLayout:
FileChooserListView:
id:chooser
path: root.get_files_list()
canvas.before:
Color:
rgb: .4, .5, .5
Rectangle:
pos: self.pos
size: self.size
on_selection: root.select(chooser.selection)
size_hint: (.9, .15)
pos_hint: {'x':.05, 'y':.8}
VideoPlayer:
id:vid
options: {'eos':'loop'}
size_hint: (.9, .7)
pos_hint: {'x':.05, 'y':.05}
Button:
size_hint_y: 0.3
height: 48
text: "open"
disabled: not chooser.selection
on_release: root.select(chooser.selection)
size_hint: (.45, .05)
pos_hint: {'x':.05, 'y':.00}
Button:
text: 'Go Back'
color: (1,1,1,1)
background_normal:''
background_color: (0.3,0.6,0.7,1)
on_release:
vid.state = 'pause'
app.root.current = 'saved_files'
size_hint: (.45, .05)
pos_hint: {'x':.50, 'y':.00}
VideosWindow class code:
class VideosWindow(Screen):
def get_files_list(self):
files = os.sep.join([my_folder,'mp4'])
return files
def select(self, filename):
self.ids.vid.source = filename[0]
self.ids.vid.state = 'play'
The screenshots of my program before and after I go fullscreen mode:
before
after
Solved this issue by adding VideoPlayer widget to the GridLayout. Now .kv code looks like this:
<VideosWindow>:
name: 'vids'
FloatLayout:
FileChooserListView:
id:chooser
path: root.get_files_list()
canvas.before:
Color:
rgb: .4, .5, .5
Rectangle:
pos: self.pos
size: self.size
on_selection: root.select(chooser.selection)
size_hint: (.9, .15)
pos_hint: {'x':.05, 'y':.8}
GridLayout:
cols:1
size_hint: (.9, .7)
pos_hint: {'x':.05, 'y':.05}
VideoPlayer:
id:vid
options: {'eos':'loop'}
Button:
size_hint_y: 0.3
height: 48
text: "open"
disabled: not chooser.selection
on_release: root.select(chooser.selection)
size_hint: (.45, .05)
pos_hint: {'x':.05, 'y':.00}
Button:
text: 'Go Back'
color: (1,1,1,1)
background_normal:''
background_color: (0.3,0.6,0.7,1)
on_release:
vid.state = 'pause'
app.root.current = 'saved_files'
size_hint: (.45, .05)
pos_hint: {'x':.50, 'y':.00}
Don't know if it is good decision but it works.

Kivy Label Text doesn't update

I am working on a calendar program with Kivy. My Problem is in the print_appointment_to_label function. I wrote appointment_label.text = appointment_name_file_content at the end of the function ,but the label doesn't update only when I restart the program.
If you wondering label_id_file_content stands for "1jal" which is the label id.
Thank you for your help
Julius
Python:
# diable multitouch
from kivy.config import Config
Config.set('input', 'mouse', 'mouse,multitouch_on_demand')
from kivy.app import App
from kivy.uix.screenmanager import Screen,ScreenManager
from kivy.lang.builder import Builder
from kivy.uix.popup import Popup
from kivy.uix.floatlayout import FloatLayout
from kivy.clock import Clock
class screenmanager(ScreenManager):
pass
class PopupContent(FloatLayout):
def store_appointment_name(self):
appointment_name = self.ids.appointment_name.text
with open("appointment_name_file","w") as appointment_name_file:
appointment_name_file.write(appointment_name)
with open("label_id_file","r") as label_id_file:
label_id_file_content = label_id_file.read()
#check month
if "ja" in label_id_file_content:
Ja = JanuaryWindow()
Ja.__init__()
class MonthWindow(Screen):
pass
class JanuaryWindow(Screen):
def __init__(self, **kwargs):
super(JanuaryWindow, self).__init__(**kwargs)
Clock.schedule_once(self.print_appointment_to_label)
def print_appointment_to_label(self,dt):
with open("appointment_name_file", "r") as appointment_name_file:
appointment_name_file_content = appointment_name_file.read()
with open("label_id_file", "r") as label_id_file:
label_id_file_content = label_id_file.read()
appointment_label = self.ids[label_id_file_content]
appointment_label.text = appointment_name_file_content
# Label Text is not showing up only when restart program
kv = Builder.load_file("Calendar-KIVY.kv")
class Calendar(App):
def create_popup_and_convert_button_id_in_label_id(self,button_id):
with open("button_id_file","w") as button_id_file:
button_id_file.write(button_id)
pcontent = PopupContent()
new_appointment_p = Popup(title="Make new appointment",content=pcontent,size_hint=(None,None),size=(1500,1000))
new_appointment_p.open()
#make label id
with open("button_id_file", "r") as button_id_file:
button_id_file_content = button_id_file.read()
label_id = button_id_file_content.replace("b", "l")
with open("label_id_file", "w") as label_id_file:
label_id_file.write(label_id)
def build(self):
return kv
Calendar().run()
Kv:
screenmanager:
MonthWindow:
JanuaryWindow:
<PopupContent>:
Label:
text: "Enter your appointment name"
size_hint: 0.4,0.1
pos_hint:{"x":0.1,"y":0.6}
TextInput:
id: appointment_name
size_hint: 0.4,0.06
pos_hint: {"x":0.478,"y":0.615}
multiline: False
Button:
text: "Create"
size_hint: 0.8,0.2
pos_hint: {"x":0.1,"y":0.09}
on_release:
root.store_appointment_name()
<MonthWindow>:
name : "MoW"
GridLayout:
cols:4
Button:
text:"January"
on_release:
app.root.current = "JaW"
Button:
text:"February"
on_release:
app.root.current = "FeW"
Button:
text:"March"
Button:
text:"April"
Button:
text:"May"
Button:
text:"June"
Button:
text:"July"
Button:
text:"August"
Button:
text:"September"
Button:
text:"October"
Button:
text:"November"
Button:
text:"December"
<JanuaryWindow>:
name : "JaW"
FloatLayout:
Label:
text:"January"
font_size: "30sp"
pos_hint: {"x":-0.426,"y":0.429}
BoxLayout:
orientation: "vertical"
pos_hint: {"x":-0.4,"y":-0.0015}
size_hint: 0.9,0.89
Label:
text:"1"
Label:
text:"2"
Label:
text:"3"
Label:
text:"4"
Label:
text:"5"
Label:
text:"6"
Label:
text:"7"
Label:
text:"8"
Label:
text:"9"
Label:
text:"10"
Label:
text:"11"
Label:
text:"12"
Label:
text:"13"
Label:
text:"14"
Label:
text:"15"
Label:
text:""
BoxLayout:
orientation: "vertical"
pos_hint: {"x":0,"y":-0.0015}
size_hint: 0.9,0.89
Label:
text:"16"
Label:
text:"17"
Label:
text:"18"
Label:
text:"19"
Label:
text:"20"
Label:
text:"21"
Label:
text:"22"
Label:
text:"23"
Label:
text:"24"
Label:
text:"25"
Label:
text:"26"
Label:
text:"27"
Label:
text:"28"
Label:
text:"29"
Label:
text:"30"
Label:
text:""
BoxLayout:
orientation: "vertical"
pos_hint: {"x":0.32,"y":-0.0015}
size_hint: 0.9,0.89
Label:
text:"31"
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.843}
size_hint: 0.02,0.03
text: "+"
on_release:
app.create_popup_and_convert_button_id_in_label_id("1jab")
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.7885}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.734}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.6795}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.6795}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.625}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.5705}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.516}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.4615}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.4615}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.407}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.3525}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.298}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.2435}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.2435}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.188}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.1235}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.38,"y":0.07}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.843}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.7885}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.734}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.6795}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.6795}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.625}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.5705}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.516}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.4615}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.4615}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.407}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.3525}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.298}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.2435}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.2435}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.188}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.1235}
size_hint: 0.02,0.03
text: "+"
FloatLayout:
Button:
pos_hint: {"x":0.7174,"y":0.07}
size_hint: 0.02,0.03
text: "+"
BoxLayout:
orientation: "vertical"
pos_hint: {"x":-0.36,"y":-0.0015}
size_hint: 0.9,0.89
Label:
id:1jal
text: ""
Label:
id:2jal
text:""
Label:
id:3jal
text:""
Label:
id:4jal
text:""
Label:
id:5jal
text:""
Label:
id:6jal
text:""
Label:
id:7jal
text:""
Label:
id:8jal
text:""
Label:
id:9jal
text:""
Label:
id:10jal
text:""
Label:
id:11jal
text:""
Label:
id:12jal
text:""
Label:
id:13jal
text:""
Label:
id:14jal
text:""
Label:
id:15jal
text:""
Label:
text:""
BoxLayout:
orientation: "vertical"
pos_hint: {"x":0,"y":-0.0015}
size_hint: 0.9,0.89
Label:
id:16jal
text:""
Label:
id:17jal
text:""
Label:
id:18jal
text:""
Label:
id:19jal
text:""
Label:
id:20jal
text:""
Label:
id:21jal
text:""
Label:
id:22jal
text:""
Label:
id:23jal
text:""
Label:
id:24jal
text:""
Label:
id:25jal
text:""
Label:
id:26jal
text:""
Label:
id:27jal
text:""
Label:
id:28jal
text:""
Label:
id:29jal
text:""
Label:
id:30jal
text:""
Label:
text:""
BoxLayout:
orientation: "vertical"
pos_hint: {"x":0.32,"y":-0.0015}
size_hint: 0.9,0.89
Label:
id:31jal
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
Label:
text:""
You are scheduling incorrectly,the following statement:
Clock.schedule_once(self.print_appointment_to_label)
Should be:
Clock.schedule_once(self.print_appointment_to_label, .5)

Categories

Resources