Can not get widgets positioned in combi of GridLayout and BoxLayout using Kivy - kivy

I am trying to implement a fixed size UI consisting of 4 columns according to the structure below (see link "Wired frame"). At column 3 I got lost after hours of studying, looking at examples and a lot of trial and error. Who can help me? Below the kv content as well.
Thanks in advance.
Wired frame
<IeditHome>:
GridLayout:
cols: 4
# 1st Column
BoxLayout:
orientation: 'vertical'
Label:
canvas.before:
Color:
rgb: .7,.7,.7
Rectangle:
pos: self.pos
size: self.size
BorderImage:
source: 'C:/images/border.png'
border: (2,2,2,2)
size: self.size
pos: self.pos
text: '1'
size_hint: None, None
height: 120
width: 25
halign: 'right'
valign: 'middle'
color: .4,.4,.4,1
# Add 4 Label bloks of the same.
# Re-engineer duplicated stuff later...
# 2nd Column
BoxLayout:
orientation: 'vertical'
Image:
canvas.before:
Color:
rgb: .7,.7,.7
Rectangle:
pos: self.pos
size: self.size
BorderImage:
source: 'C:/images/border.png'
border: (2,1,1,2)
size: self.size
pos: self.pos
size_hint_x: None
size_hint_y: None
size: 240, 120
source: 'C:/temp/Object1.png'
# Add 4 image bloks of the same.
# Re-engineer duplicated stuff later...
# 3rd Column
BoxLayout:
orientation: 'vertical'
Label:
canvas.before:
Color:
rgb: .7,.7,.7
Rectangle:
pos: self.pos
size: self.size
text: 'This is the titel'
Image:
canvas.before:
Color:
rgb: .7,.7,.7
Rectangle:
pos: self.pos
size: self.size
BorderImage:
source: 'C:/images/border.png'
border: (2,1,1,2)
size: self.size
pos: self.pos
size_hint_x: None
size_hint_y: None
size: 300, 200
source: 'C:/temp/MediumImage.png'
Image:
canvas.before:
Color:
rgb: .7,.7,.7
Rectangle:
pos: self.pos
size: self.size
BorderImage:
source: 'C:/images/border.png'
border: (2,1,1,2)
size: self.size
pos: self.pos
size_hint_x: None
size_hint_y: None
size: 500, 300
source: 'C:/temp/LargeImage.png'
ActionBar:
pos: 0, 600
font_size: 16
size: 1200, 40
# background color in Kivy acts as a tint and not just a solid color.
# set a pure white background image first.
background_image: 'C:/images/white-bg.png'
background_color: .2,.6,.7,1
ActionView:
ActionPrevious:
size: 1200, 40
font_size: 16
title: 'Ieditor'
with_previous: False
ActionOverflow:
ActionButton:
icon: 'C:/images/butt_prev.png'
ActionButton:
icon: 'C:/images/butt_next.png'

Here is a small working example of the 3rd column should look like (The A class)
Builder.load_string("""
<InputBar#BoxLayout>:
orientation: 'horizontal'
Label:
text: 'some text'
TextInput:
text: 'input?'
Label:
text: 'some text2'
TextInput:
text: 'input2?'
<A>:
orientation: 'vertical'
Label:
text: 'some title'
InputBar:
id: input1
InputBar:
id: input2
InputBar:
id: input3
InputBar:
id: input4
Label:
text: 'some title2'
InputBar:
id: input5
InputBar:
id: input6
InputBar:
id: input7
InputBar:
id: input8
InputBar:
id: input9
""")
class A(BoxLayout):
pass
class VApp(App):
def build(self):
return A()
if __name__ == '__main__':
VApp().run()
Just place it inside your big example I guess.

Related

How to show loading screen at start of functionin Kivy

I am a beginner on Kivy and need some help.
I have a basic mathematical application that, when i press a button it also takes 2-3 secs to be completed the function and then app shows us the result. During this process i want my app to show a loading screen
I found this solution but could not compile for my code
https://stackoverflow.com/a/66154747/19925544
Could you please help me to fix this
Thanks.
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.metrics import dp
import requests
class WrappedLabel(Label):
pass
class Math(BoxLayout):
def __init__(self, **kwargs):
super(Predictor, self).__init__(**kwargs)
self.status = True
self.data = self.datas()
self.Today = self.today()
def underOver(self, s_image, screenmanager):
if(screenmanager.current == 'homepage_screen' or screenmanager.current == 'side_screen' or screenmanager.current == 'privacy_policy_screen'):
screenmanager.transition.direction = 'left'
screenmanager.current = 'result_screen'
print("""
Below the calculate codes which are inside underOver function
""")
KV File
Math:
<Math>:
ScreenManager:
id: sm
size: root.width, root.height
Screen:
name: 'result_screen'
Image:
source: 'images/result_background.png'
allow_stretch: True
keep_ratio: False
BoxLayout:
spacing: 20
orientation: 'vertical'
BoxLayout:
size_hint: 1, 0.10
Label:
text: '#'
font_name: 'fonts/Lcd.ttf'
font_size: '30dp'
color: 1, 0.4, 0.769, 1
Label:
text: 'T1'
font_name: 'fonts/Lcd.ttf'
font_size: '30dp'
color: 1, 0.4, 0.769, 1
Label:
text: 'T2'
font_name: 'fonts/Lcd.ttf'
font_size: '30dp'
color: 1, 0.4, 0.769, 1
Label:
text: 'G.A'
font_name: 'fonts/Lcd.ttf'
font_size: '30dp'
color: 1, 0.4, 0.769, 1
Label:
text: '2.5'
font_name: 'fonts/Lcd.ttf'
font_size: '30dp'
color: 1, 0.4, 0.769, 1
Label:
text: '3.5'
font_name: 'fonts/Lcd.ttf'
font_size: '30dp'
color: 1, 0.4, 0.769, 1
BoxLayout:
size_hint: 1, 0.80
ScrollView:
bar_margin: 5
bar_color: 1, 0.4, 0.769, 1
bar_width: 10
bar_inactive_color: 1, 0.4, 0.769, 1
GridLayout:
id: gridsonuc
cols: 1
spacing: 15
size_hint_y: None
height: self.minimum_height
BoxLayout:
size_hint: 1, 0.10
Button:
id: home_button_result
on_press: root.homepage(img_home, sm)
background_color: 0, 0, 0, 0
Image:
id: img_home
source: 'images/home_button.png'
allow_stretch: True
keep_ratio: False
size: self.parent.size
pos: home_button_result.pos
Button:
id: side_button_result
on_press: root.side(img_side, sm)
background_color: 0, 0, 0, 0
Image:
id: img_side
source: 'images/side_button.png'
allow_stretch: True
keep_ratio: False
size: self.parent.size
pos: side_button_result.pos

Python-Kivy app - popup keyboard covers input fields

Within my kivy app, I have a screen that contains several text input fields. I am using gridlayout. When I click on an input field in the lower half of the screen the popup keyboard covers the field making it difficult to see what is being entered. I have looked at scrollview for that screen but still having problems.
------------ kv file. Start of kv file':'
<FourthWindow>:
name: "fourth"
GridLayout:
orientation: "vertical"
cols: 2
padding: 10
spacing: 10
Label:
text: "Title"
width:120
height: 50
font_size: 32
background_color: (0.0/255, 0.0/255, 230.0/255, 1)
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
Button:
text: "Main"
font_size: 32
background_normal: ''
background_color: utils.get_color_from_hex('#34a1eb')
width: 240
height: 90
on_release:
app.root.current = "first"
root.manager.transition.direction = "right"
Label:
text: "Label 1"
width:70
height: 30
font_size: 24
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
TextInput:
id: spid
multiline:False
width:70
height: 50
font_size: 24
Label:
text: "Label 2"
width:70
height: 50
font_size: 24
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
TextInput:
id: spfhgt
multiline:False
width: 70
height: 50
font_size: 24
Label:
text: "Label 3"
width:70
height: 50
font_size: 24
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
TextInput:
id: sptrv
multiline:False
width:70
height: 50
font_size: 24
Label:
text: "Label 4"
width:50
height: 50
font_size: 24
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
TextInput:
id: sptrv
multiline:False
width:70
height: 50
font_size: 24
Label:
text: "Label 5"
width:70
height: 50
font_size: 24
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
TextInput:
id: spwgt
multiline:False
width:70
height: 50
font_size: 24
Label:
text: "Label 6"
width:70
height: 50
font_size: 24
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
TextInput:
id: spod
multiline:False
width:270
height: 50
font_size: 24
Label:
text: "Label 7 "
width:270
height: 50
font_size: 24
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
TextInput:
id: spsrr
multiline:False
width:270
height: 50
font_size: 24
Label:
text: "Label 8 "
width:70
height: 50
font_size: 24
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
TextInput:
id: spsrgs
multiline:False
width:70
height: 50
font_size: 24
Label:
text: "Label 9 "
width:70
height: 50
font_size: 24
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
TextInput:
id: spmat
multiline:False
width:70
height: 50
font_size: 24
Label:
text: "Label 10"
width:70
height: 50
font_size: 24
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
TextInput:
id: spseta
multiline:False
width:270
height: 50
font_size: 24
Label:
text: "Label 11"
width:270
height: 50
font_size: 24
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
TextInput:
id: spsetb
multiline:False
width:270
height: 50
font_size: 24
Label:
text: "Label 12"
width:270
height: 50
font_size: 24
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
TextInput:
id: sprubsz
multiline:False
width:270
height: 50
font_size: 24
Label:
text: "Label 13 "
width:270
height: 50
font_size: 24
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
TextInput:
id: sprubgrv
multiline:False
width:270
height: 50
font_size: 24
Label:
text: "Label 14 "
width:270
height: 50
font_size: 24
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
TextInput:
id: sprubdurm
multiline:False
width:270
height: 50
font_size: 24
Label:
text: "Label 15 "
width:270
height: 50
font_size: 24
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
TextInput:
id: sprubmat
multiline:False
#pos_hint: {"x":0.57, "top":0.10}
width:270
height: 50
font_size: 24
Label:
text: "Label 16 "
width:270
height: 50
font_size: 24
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
color: utils.get_color_from_hex('#f2f5f7')
bold: True
italic: True
TextInput:
id: sprubnm
multiline:False
width:270
height: 50
font_size: 24
You can use Window.softinput_mode to control where the keyboard shows. I have found the following to be best for my uses:
Window.softinput_mode = ‘below_target’

How do I remove extra unwanted space in kivy BoxLayout?

<BoxExample#BoxLayout>:
orientation: "vertical"
BoxLayout:
orientation: "horizontal"
size_hint_y: None
Button:
text: "Logo"
size_hint: None, None
width: "80dp"
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Menu"
size_hint: 1, None
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Body"
Button:
text: "Footer"
size_hint: 1, None
height: "40dp"
That black space in the picture above, which I want to get rid of.
However after adding size_hint_y: None the gap has been narrowed as in the picture.
It is due to BoxLayout which provides each of its child widgets equal space but here you have changed the size of buttons which are inside of BoxLayout.You also need to change the size of BoxLayout Otherwise it will show black.
<BoxExample#BoxLayout>:
orientation: "vertical"
BoxLayout:
orientation: "horizontal"
size_hint: None,None
size:root.size[0],"40dp"
Button:
text: "Logo"
size_hint: None, None
width: "80dp"
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Menu"
size_hint: 1, None
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Body"
Button:
text: "Footer"
size_hint: 1, None
height: "40dp"
Just add:
height: self.minimum_height
to the BoxLayout:
<BoxExample#BoxLayout>:
orientation: "vertical"
BoxLayout:
orientation: "horizontal"
size_hint_y: None
height: self.minimum_height
Button:
text: "Logo"
size_hint: None, None
width: "80dp"
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Menu"
size_hint: 1, None
height: "40dp"
pos_hint: {'top': 1}
Button:
text: "Body"
Button:
text: "Footer"
size_hint: 1, None
height: "40dp"

kivy KeyError in an ids dictionary

I have the following code snippet:
def on_articles(self, *args):
#self.parent.ids['recommendations'].update_recommendations(self.articles)
self.parent.children[0].update_recommendations(self.articles)
The commented line does not work, because self.parent.ids is an empty dictionary ({})
The uncommented line does work. Why? How to best refer to Recommendations widget?
Here is the UI.
Builder.load_string('''
<SearchItem>:
canvas.before:
Color:
rgba: [0.8, 0.8, 0.8, 1] if self.state == 'normal' else [30/255, 139/255, 195/255, 1]
Rectangle:
size: self.size
pos: self.pos
Color:
rgba: 0, 0, 0, 1
Line:
rectangle: self.x, self.y, self.width, self.height
color: 0, 0, 0, 1
<Urlpopup>:
size_hint: .7, .7
auto_dismiss: False
title: ''
BoxLayout:
canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
size: self.size
pos: self.pos
orientation: 'vertical'
padding: self.width * 0.1
spacing: self.height * 0.1
Spinner:
id: spinner
size_hint: None, None
size: 100, 44
text: 'en'
values: 'en', 'fr', 'de', 'it'
SearchBar:
id: searchbar
size_hint: 1, 0.4
multiline: False
font_size: self.height*0.8
Recommendations:
id: recommendations
orientation: 'vertical'
SearchItem
''')

Kivy ScrollView with two Labels and simultaneously scrolling?

I have created a UI that displays two labels with long text in the lower area. Both labels are in a separate scrollview and therefore scrollable. How can I combine both labels into a single scrollview so that both labels are scrollable at the same time? Do I need to create another Layout around a Scrollview?
Here is my kv:
<Button>:
font_size: 20
color: 0.1,0.5,0.6,1
size_hint: 0.3,0.1
<Label>:
size_hint: 0.1,0.1
<TextInput>:
size_hint: 1,0.1
<PopupBox>:
size_hint: .2, .15
auto_dismiss: True
title: 'Please wait'
Label:
pos_hint: {"x":0.5, "top":0.7}
text: 'Creating the data...'
<FloatLayout>:
canvas:
Color:
rgba: 0.15, 0.15, 0.15, 0.15
Rectangle:
size: self.size
pos: self.pos
Label:
text: "Label 1"
size_hint: 0.1,0.1
pos_hint: {"x":0.0, "top":1}
TextInput:
id: input1
pos_hint: {"x":0.11, "top":1}
multiline: True
Label:
text: "Label 2"
size_hint: 0.1,0.1
pos_hint: {"x":0.0, "top":0.9}
TextInput:
id: input2
pos_hint: {"x":0.11, "top":0.9}
multiline: True
Label:
text: "Label 3"
size_hint: 0.11, None
pos_hint: {"x":0, "top":0.8}
height: 30
TextInput:
id: input3
text: "|"
pos_hint: {"x":0.11, "top":0.8}
size_hint: 0.03, None
height: 30
Button:
text: "Clear"
on_press: app.clear_inputs()
pos_hint: {"x":0.15, "top":0.8}
size_hint: 0.1, None
height: 30
Label:
id: dd_label
text: "dd"
pos_hint: {"x":0.7, "top":0.8}
size_hint: 0.1, None
height: 30
Button:
text: "Comp"
on_press: app.start_second_thread()
pos_hint: {"x":0, "top":0.76}
size_hint: 1, None
height: 50
Button:
text: "So"
on_press: app.show_popup()
pos_hint: {"x":0, "top":0.69}
size_hint: 0.1, None
height: 25
GridLayout:
cols: 2
size_hint: 1, 0.67
ScrollView:
size_hint: (1, 1)
bar_width: 10
bar_color: 0.1, 0.1, 0.1, 0.1
bar_inactive_color: 0.15, 0.15, 0.15, 0.15
effect_cls: "ScrollEffect"
scroll_type: ['bars']
Label:
id: f_output1
text: "long text1 \n" * 100
size_hint_y: None
size_hint_x: 0.7
size: self.texture_size
pos_hint: {"x":0.6, "top":0.7}
markup: True
text_size: 700, None
valign: "middle"
halign: 'right'
padding_x: 5
ScrollView:
size_hint: (1, 1)
bar_width: 10
bar_color: 0.1, 0.1, 0.1, 0.1
bar_inactive_color: 0.15, 0.15, 0.15, 0.15
effect_cls: "ScrollEffect"
scroll_type: ['bars']
Label:
id: f_output2
text: "long text2 \n" * 100
size_hint_y: None
size_hint_x: 1
size: self.texture_size
pos_hint: {"x":0.6, "top":0.7}
text_size: 600, None
markup: True
You can make a single ScrollView and make create a GridLayout with cols:2 for 2 labels
ScrollView:
size_hint: (1, 1)
bar_width: 10
bar_color: 0.1, 0.1, 0.1, 0.1
bar_inactive_color: 0.15, 0.15, 0.15, 0.15
effect_cls: "ScrollEffect"
scroll_type: ['bars']
GridLayout:
cols: 2
size_hint_y:None
height:self.minimum_height
Label:
id: f_output1
text: "long text1 \n" * 100
size_hint_y: None
size_hint_x: 0.7
size: self.texture_size
pos_hint: {"x":0.6, "top":0.7}
markup: True
text_size: 700, None
valign: "middle"
halign: 'right'
padding_x: 5
Label:
id: f_output2
text: "long text2 \n" * 100
size_hint_y: None
size_hint_x: 1
size: self.texture_size
pos_hint: {"x":0.6, "top":0.7}
text_size: 600, None
markup: True

Resources