show image on RecycleView - python

I try to make a table with data from a SQL DB and images not from a DB. I have tried several things but the image don't show up.
I used this code and modified it: Link to Stackoverflow Code
Code snippets that i Changed in Main.py
import sqlite3
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.recycleview.views import RecycleDataViewBehavior
from kivy.uix.button import Button
from kivy.properties import BooleanProperty, ListProperty, StringProperty, ObjectProperty
from kivy.uix.recyclegridlayout import RecycleGridLayout
from kivy.uix.behaviors import FocusBehavior
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
from kivy.uix.popup import Popup
from kivy.uix.image import Image #<<<<<<<<<<<<<<< new
[...]
class RV(BoxLayout):
data_items = ListProperty([])
image = Image(source='image.gif') #<<<<<<<<<<<<<<<<<<< new
def __init__(self, **kwargs):
super(RV, self).__init__(**kwargs)
self.get_users()
def get_users(self):
connection = sqlite3.connect("demo.db")
cursor = connection.cursor()
cursor.execute("SELECT * FROM Users ORDER BY UserID ASC")
rows = cursor.fetchall()
# create data_items
for row in rows:
for col in row:
self.data_items.append(col)
print(type(col))
self.data_items.append(self.image) #<<<<<<<<<<<<<<<<<<< new
[...]
test.kv
#:kivy 1.10.0
<TextInputPopup>:
title: "Popup"
size_hint: None, None
size: 400, 400
auto_dismiss: False
BoxLayout:
orientation: "vertical"
TextInput:
id: txtinput
text: root.obj_text
Button:
size_hint: 1, 0.2
text: "Save Changes"
on_release:
root.obj.update_changes(txtinput.text)
root.dismiss()
Button:
size_hint: 1, 0.2
text: "Cancel Changes"
on_release: root.dismiss()
<SelectableButton>:
# Draw a background to indicate selection
canvas.before:
Color:
rgba: (.0, 0.9, .1, .3) if self.selected else (0, 0, 0, 1)
Rectangle:
pos: self.pos
size: self.size
<RV>:
BoxLayout:
orientation: "vertical"
GridLayout:
size_hint: 1, None
size_hint_y: None
height: 25
cols: 3
Label:
text: "User ID"
Label:
text: "User Name"
Label:
text: "Image To Insert"
BoxLayout:
RecycleView:
viewclass: 'SelectableButton'
data: [{'text': str(x)} for x in root.data_items] #<<<<<<<<<< Problem?
SelectableRecycleGridLayout:
cols: 3
default_size: None, dp(26)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
multiselect: True
touch_multiselect: True
Problem:
Link that shows a Picture of my problem

Related

How Can I Remove BoxLayout?

I want to remove a Boxlayout in my widget, but I cant.
There is a Boxlayout at the begining of the app called "Speca". After my sellections it must be removed.
When you run the app, sellect something in "Home" Spinner and click any of the new Toggle buttons.
Wtih the press of any of the Toggle buttons "Speca" must disappear.
Please help.
Here is main.py:
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.scrollview import ScrollView
from kivy.uix.spinner import Spinner
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.properties import ObjectProperty, StringProperty, BooleanProperty
from kivy.properties import ListProperty
from collections import OrderedDict
from kivy.uix.togglebutton import ToggleButton
data1=["mother","father","son"]
data2=["uncle","aunt","grandfather"]
data3=["jack","mike","simon"]
data4=["1898","1975","1985","1885"]
amd="0dp"
class MainWidget(Widget):
def remove_layout(self, *ignore):
self.remove_widget(self.layout)
global amd
an0=tuple(list(OrderedDict.fromkeys(data1)))
cal5= ObjectProperty()
cal6= ObjectProperty()
def btn10(self,text):
if self.cal5:
self.cal5.parent.remove_widget(self.cal5)
self.cal5 =ModelSpecifications()
a=data2
b=data3
c=data4
mi=[]
n=0
while n < len(a):
aba=n
mi.append(aba)
n+=1
for i in mi:
self.b1=MyTButton(text=str(i),size_hint=(1,None),height="100dp",group="selections")
self.cal5.add_widget(self.b1)
self.ids.scd.add_widget(self.cal5, index=3)
def on_state(self, togglebutton): #<----THIS IS THE TUGGLEBUTTON I WANT USE
global amd
tb = togglebutton
text1=tb.text
if text1=="0":
amd="50dp"
elif text1=="1":
amd="100dp"
else:
amd="200dp"
if self.cal6:
self.cal6.parent.remove_widget(self.cal6)
self.cal6 =Spec()
self.ids.scd.add_widget(self.cal6, index=2)
class SecondPage(ScrollView):
pass
class Speca(BoxLayout): #<------ THIS IS THE BOXLAYOUT I WANT TO REMOVE
pass
class Spec(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.size_hint=(1,None)
self.height=amd
class MyTButton(ToggleButton):
def __init__(self, **kwargs):
super().__init__(**kwargs)
class ModelSpecifications(BoxLayout): #this is the class I want add after my spinner selection
pass
class Calculation(GridLayout):
pass
class MyApp(App):
pass
MyApp().run()
here is my.kv :
MainWidget:
<MainWidget>:
hideable: hideable
ScreenManager:
id: scmanager
size: root.width, root.height
Screen:
id: scndpage
name: "second"
SecondPage:
Calculation:
id:scd
cols:1
height: self.minimum_height
row_default_height: "70dp"
size_hint_y: None
spacing:"10dp"
canvas.before:
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
size_hint: 1, None
height: "50dp"
pading:"10dp"
spacing:"10dp"
orientation: "vertical"
BoxLayout:
orientation: "horizontal"
Label:
text:"Name:"
color: 0,0,0,1
TextInput:
text:"---"
color: 0,0,0,1
Label:
text:"Surname:"
color: 0,0,0,1
TextInput:
text:"-----"
color: 0,0,0,1
BoxLayout:
id:scdd
size_hint: 1, 1
height: "100dp"
orientation: "vertical"
BoxLayout:
size_hint: 1, None
height: "50dp"
orientation: "horizontal"
Label:
text: " Sellection:"
color: 0,0,0,1
Spinner:
text: 'Home'
values: root.an0
on_text: app.root.btn10(self.text)
Speca: #<------ THIS IS THE BOXLAYOUT I WANT TO REMOVE
Button:
text:" Calculate"
Button:
text:"Sellect"
Button:
text:"Back"
<ModelSpecifications>:
id:anss
pading:"10dp"
spacing:"10dp"
size_hint: 1, None
height: "100dp"
orientation: "horizontal"
<MyTButton#ToggleButton>: #<----THIS IS THE TUGGLEBUTTON I WANT USE
on_state:
app.root.on_state(self)
<Speca>: #<------ THIS IS THE BOXLAYOUT I WANT TO REMOVE
orientation:"vertical"
Label:
color: (1,1,0,1)
text:"I WANT TO REMOVE THIS PART WHEN I PRESS ANY OF TOGGLE BUTTONS"
Please run the app and see it.
Looks to me like speca is a child of the calculation widget with ID scd. So give speca an ID and then Remove speca via ids in on_srate python function.
Kv
SecondPage:
Calculation:
id:scd
speca:
id: speca
py
def on_state():
self.root.ids.scd.remove_widget(self.root.ids.speca)
YES.
When I make those changes;
Kv
SecondPage:
Calculation:
id:scd
speca:
id: speca
py
def on_state():
self.ids.scd.remove_widget(self.ids.speca)
It works.

How can I change the height of Boxlayout Dynamically?

I am trying to change Boxlayout height dynamically. There will an empty Boxlayout at the beginning, then with a ToggleButton I will add Buttons on that Boxlayout vertically. But this Boxlayout locates in Gridlayout which has ScrollView. And the number of buttons I will add will change, so the height of the box layout should change too. But it doesn't change. Could you please help.
Here is my main.py:
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.scrollview import ScrollView
from kivy.uix.spinner import Spinner
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.properties import ObjectProperty, StringProperty, BooleanProperty
from kivy.properties import ListProperty
from collections import OrderedDict
data1=["mother","father","son"]
data2=["uncle","aunt","grandfather"]
data3=["jack","mike","simon"]
data4=["1898","1975","1985","1885"]
class MainWidget(Widget):
an0=tuple(list(OrderedDict.fromkeys(data1)))
cal5= ObjectProperty()
def btn10(self,text):
if self.cal5:
self.cal5.parent.remove_widget(self.cal5) #EVERY TIME I NEED TO REMOVE IT BECAUSE MY BUTTON QUANTITIY AND TEXT WILL CHANGE DUE TO TOGGLE BUTTON SELECTION
self.cal5 =ModelSpecifications()
a=data2
b=data3
c=data4
mi=[]
n=0
while n < len(a):
aba=(str(a[n])+"\n"+str(b[n])+"\n"+str(c[n]))
mi.append(aba)
n+=1
for i in mi:
self.b1=Button(text=str(i),size_hint=(1,None),height="10dp")
self.cal5.add_widget(self.b1)
self.ids.scd.add_widget(self.cal5, index=3) #I ADD THE BUTTONS IN HERE
class SecondPage(ScrollView):
pass
some_number=120
calculated_height=(str(some_number)+"dp") #<------I CAN CHANGE THE HEIGHT AT THE BEGINING BUT IT DOSENT CHANGE THE HEIGHT DYNAMICALLY
class ModelSpecifications(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.size_hint=(1,None)
self.height=calculated_height
class Calculation(GridLayout):
pass
class MyApp(App):
pass
MyApp().run()
And here is my my.kv file:
#:import C kivy.utils.get_color_from_hex
MainWidget:
<MainWidget>:
ScreenManager:
id: scmanager
size: root.width, root.height
Screen:
id: scndpage
name: "second"
SecondPage:
Calculation:
id:scd
cols:1
height: self.minimum_height
row_default_height: "70dp" #<---THIS HEIGHT MUST BE SPECIFY BECAUSE OF SCROLLWIEW
size_hint_y: None
spacing:"10dp"
canvas.before:
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
size_hint: 1, None
height: "50dp"
pading:"10dp"
spacing:"10dp"
orientation: "vertical"
BoxLayout:
orientation: "horizontal"
Label:
text:"Name:"
color: 0,0,0,1
TextInput:
text:"---"
color: 0,0,0,1
Label:
text:"Surname:"
color: 0,0,0,1
TextInput:
text:"-----"
color: 0,0,0,1
BoxLayout:
id:scdd
size_hint: 1, 1
height: "100dp"
orientation: "vertical"
BoxLayout:
size_hint: 1, None
height: "50dp"
orientation: "horizontal"
Label:
text: " Sellection:"
color: 0,0,0,1
Spinner:
text: 'Home'
values: root.an0
on_text: app.root.btn10(self.text)
Button:
text:" Calculate"
Button:
text:"Sellect"
Button:
text:"Back"
<ModelSpecifications>: #<---------HOW CAN I DYNAMICALLY CHANGE THE HEIGHT OF THIS WIDGET ?
id:anss
pading:"10dp"
spacing:"10dp"
orientation: "vertical"
canvas.before:
Color:
rgba: (C('EBE4E4'))
RoundedRectangle:
size: self.size
pos: self.pos
radius: [15]
I want to change the height in the python script because I will get the information from another function as variable.
Please run the file. Looking forward to your comments.

I was expect navigation drawer runed as example; however, MDNavigationDrawer perhaps executed twice

from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.uix.boxlayout import MDBoxLayout
class LoginWindow(Screen):
pass
class HomeWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
class ContentNavigationDrawer(MDBoxLayout):
pass
class main(MDApp):
def __init__(self, **kwargs):
self.title = "APP"
super().__init__(**kwargs)
def build(self):
self.theme_cls.theme_style = "Dark"
self.root = Builder.load_file('main.kv')
wm = WindowManager()
wm.add_widget(LoginWindow())
wm.add_widget(HomeWindow())
return wm
if __name__ == '__main__':
main().run()
Here is my ky file.
WindowManager:
LoginWindow:
HomeWindow:
<WindowManager>:
id:window_manager
name:'window_manager'
<LoginWindow>:
id:login_window
name:'login_window'
MDCard:
size_hint:None,None
size:300,500
orientation:"vertical"
halign:"center"
pos_hint:{"center_x":0.5, "center_y":0.5}
padding:15
spacing:20
MDLabel:
text:"Welcome!"
halign:"center"
MDTextFieldRound:
id:user
hint_text:"user"
icon_right:"account"
size_hint:None, None
width:250
pos_hint:{"center_x":0.5, "center_y":0.5}
halign:"center"
MDTextFieldRound:
id:password
hint_text:"password"
icon_right:"eye-off"
size_hint:None, None
width:250
pos_hint:{"center_x":0.5, "center_y":0.5}
halign:"center"
MDRectangleFlatButton:
text:"Log in"
size_hint:None, None
width:150
pos_hint:{"center_x":0.5, "center_y":0.5}
on_press:root.manager.current="home_window"
<HomeWindow>:
id:home_window
name:'home_window'
MDNavigationLayout:
ScreenManager:
MDScreen:
BoxLayout:
orientation:"vertical"
MDToolbar:
type:"top"
title: "Navigation Drawer"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state("open")]]
Widget:
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
<ContentNavigationDrawer>:
id:content_drawer
orientation:"vertical"
I am a beginner.
When I practicing screen switch and navigation drawer, I was expected that navigation drawer would runed as an example, which is https://kivymd.readthedocs.io/en/0.104.0/components/navigation-drawer/index.html.
When I run the code, I was confused with a problem, which was that
lambda x: nav_drawer.set_state("open") perhaps executed twice.
You can remove one MDNavigationDrawer or you can use my code:
try:
from jnius import autoclass
python_activity = autoclass('org.kivy.android.PythonActivity')
python_activity.removeLoadingScreen()
except:
pass
try:
import plyer
except:
pass
try:
import android
except:
pass
from time import sleep
from kivymd.icon_definitions import md_icons
from kivymd.uix.list import OneLineIconListItem
from kivymd.app import MDApp
from kivymd.uix.button import MDIconButton
from kivymd.uix.label import MDLabel
from kivymd.uix.card import MDCard
from kivymd.uix.tab import MDTabsBase
from kivymd.uix.dialog import MDDialog
from kivymd.theming import ThemableBehavior
from kivymd.uix.list import OneLineIconListItem, MDList
from kivymd.toast import toast
from kivymd.uix.behaviors import TouchBehavior
from kivymd.uix.filemanager import MDFileManager
from kivymd.uix.button import MDRaisedButton
from kivymd.uix.button import MDFloatingActionButton
from kivymd.uix.button import MDFlatButton
from kivymd.uix.list import OneLineListItem
from kivymd.uix.list import TwoLineIconListItem
from kivymd.uix.list import ThreeLineAvatarListItem
from kivymd.uix.list import OneLineAvatarIconListItem
from kivymd.uix.list import TwoLineAvatarListItem
from kivymd.uix.list import OneLineAvatarListItem
from kivymd.uix.list import ImageLeftWidget
from kivymd.uix.gridlayout import MDGridLayout
from kivymd.uix.list import IconLeftWidget
from kivymd.uix.list import IconRightWidget
from kivymd.uix.textfield import MDTextField
from kivymd.uix.snackbar import Snackbar
from kivymd.uix.bottomsheet import MDListBottomSheet
from kivymd.uix.bottomsheet import MDGridBottomSheet
from kivymd.uix.filemanager import MDFileManager
from kivymd.uix.imagelist import SmartTileWithLabel
from kivymd.uix.card import MDCardSwipe
#import kivymd.uix.behaviors.MagicBehavior
from kivymd.uix.behaviors.magic_behavior import MagicBehavior
#from kivymd.uix.button import MagicButton
import sys
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.animation import Animation
from kivy.graphics.context_instructions import Color
from kivy.lang import Builder
from kivy.properties import (
NumericProperty,
StringProperty,
BooleanProperty,
OptionProperty,
ListProperty,
ObjectProperty,
)
from kivy.metrics import dp
from kivy.metrics import sp
from kivymd.font_definitions import theme_font_styles
from kivymd.theming import ThemableBehavior
from kivymd.uix.label import MDIcon
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.image import Image
from kivy.factory import Factory
from kivy.uix.scatterlayout import ScatterLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.image import Image
from kivy.uix.scrollview import ScrollView
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
from kivy.uix.screenmanager import ScreenManager,Screen,WipeTransition,FadeTransition,FallOutTransition,RiseInTransition,CardTransition
from kivy.properties import ObjectProperty
from kivy.properties import StringProperty
from kivy.clock import Clock
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.core.audio import SoundLoader
from kivy.metrics import dp
from kivy.uix.bubble import Bubble
from kivy.core.window import Window
from kivy.uix.gridlayout import GridLayout
from kivy.uix.progressbar import ProgressBar
from kivy.setupconfig import USE_SDL2
from kivy.uix.bubble import Bubble
from kivy.uix.recycleview import RecycleView
from kivy.uix.recycleview.views import RecycleDataViewBehavior
from kivy.uix.label import Label
from kivy.properties import BooleanProperty
from kivy.uix.recycleboxlayout import RecycleBoxLayout
from kivy.uix.behaviors import FocusBehavior
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
from kivy.uix.scatter import Scatter
from kivy.properties import StringProperty, ListProperty
import requests
import time
import shutil
from datetime import datetime
from datetime import date, timedelta
import os
worm = os.getcwd()+"/"
Window.softinput_mode = "below_target"
def android_dir(a):
try:
from android.storage import app_storage_path
from android.storage import primary_external_storage_path
from android.storage import secondary_external_storage_path
pt1=app_storage_path()+"/"
if a==1:
pt2=primary_external_storage_path()+"/"
return pt2
if a==2:
pt3=secondary_external_storage_path()+"/"
return pt3
return pt2
except:
return worm
class ContentNavigationDrawer(BoxLayout):
nav_drawer = ObjectProperty()
pass
class DrawerList(ThemableBehavior, MDList):
def set_color_item(self, instance_item):
'''Called when tap on a menu item.'''
# Set the color of the icon and text for the menu item.
for item in self.children:
if item.text_color == self.theme_cls.primary_color:
item.text_color = self.theme_cls.text_color
#self.theme_cls.theme_style="Dark"
break
instance_item.text_color = self.theme_cls.primary_color
Window.softinput_mode = "below_target"
#Window.size=(350,600)
KV = '''
#:import toast kivymd.toast.toast
#:import Snackbar kivymd.uix.snackbar.Snackbar
#:import Clipboard kivy.core.clipboard.Clipboard
#:import MDLabel kivymd.uix.label.MDLabel
#:import MDCard kivymd.uix.card.MDCard
#:import MDTextFieldRound kivymd.uix.textfield.MDTextFieldRound
#:import MDTextButton kivymd.uix.button.MDTextButton
#:import MDIconButton kivymd.uix.button.MDIconButton
#:import MDRaisedButton kivymd.uix.button.MDRaisedButton
#:import Window kivy.core.window.Window
#:import runTouchApp kivy.app.runTouchApp
#:import MDFileManager kivymd.uix.filemanager
#:import Clock kivy.clock.Clock
#:import Button kivy.uix.button.Button
#:import Bubble kivy.uix.bubble.Bubble
#:import * kivy.graphics
#:import ProgressBar kivy.uix.progressbar
#:import OneLineListItem kivymd.uix.list.OneLineListItem
#:import ThreeLineAvatarListItem kivymd.uix.list.ThreeLineAvatarListItem
#:import MagicBehavior kivymd.uix.behaviors.MagicBehavior
####################################################
<On1>:
orientation: "vertical"
border_radius: "-3dp"
ripple_behavior: True
elevation: 20
size: "320dp", "100dp"
size_hint: None, None
pos_hint: {"center_x": .5, "center_y": .5}
#background: app.w+"toolbar.png"
AnchorLayout:
pos_hint: {"center_x": .5, "center_y": .5}
blanks1:
FitImage:
source: app.w + "bbay.png"
size_hint: .5, None
height: text_box.height+100
MDBoxLayout:
id: text_box
orientation: "vertical"
adaptive_height: True
spacing: "40dp"
padding: 0, "90dp", "90dp", "90dp"
#pos_hint: {"center_x": .5, "center_y": .8}
MDLabel:
id: user20
markup: True
text: "\\n\\n[b][color=ffffff] Tarkhan Simarik\\n[/b] [color=ffffff]Cód. de Vendedor: 5555\\n[color=ffffff] Idioma: \\n"
#font_style: "H5"
#halign: "center"
size_hint_y: 20
height: self.texture_size[1]
# Menu item in the DrawerList list.
<ItemDrawer>:
canvas.before:
Color:
rgba: (1,1,1, 1)
Rectangle:
##source: app.w+"toolbar.png"
pos: self.pos
size: self.size
#theme_text_color: "Custom"
on_release: app.action(str(root.icon)) #toast(str(root.icon)) #self.parent.set_color_item(self)
IconLeftWidget:
id: icon
icon: root.icon
#theme_text_color: "Custom"
#text_color: root.text_color
<ContentNavigationDrawer>:
canvas.before:
Color:
rgba: (0,0,0, 0)
Rectangle:
pos: self.pos
size: self.size
orientation: "vertical"
ScrollView:
padding: dp(10)
default_size_hint: None, None
DrawerList:
id: md_list
size_hint_y: None
MDCard:
orientation: "vertical"
border_radius: "-3dp"
ripple_behavior: True
elevation: 20
size: "320dp", "100dp"
size_hint: None, None
pos_hint: {"center_x": .5, "center_y": .5}
#background: "Photos/pro.jpg"
AnchorLayout:
pos_hint: {"center_x": -.1, "center_y": .5}
FitImage:
source: "Photos/pro.jpg"
size_hint: 1, None
height: text_box.height #+100
MDBoxLayout:
id: text_box
orientation: "vertical"
adaptive_height: True
spacing: "40dp"
padding: 0, "90dp", "90dp", "90dp"
#pos_hint: {"center_x": .5, "center_y": .8}
MDLabel:
id: user20
markup: True
text: "\\n\\n[b][color=ffffff] JBSIDIS\\n[/b] [color=ffffff]------\\n[color=ffffff] : \\n"
#font_style: "H5"
#halign: "center"
size_hint_y: 20
height: self.texture_size[1]
Screen:
MDToolbar:
id: mt
pos_hint: {"top": 1}
title: app.t
elevation: 10
#md_bg_color: (.1,.80,.5,.3)
font_stye: "H5"
#source: app.w+"toolbar.png"
hint_animation: True
left_action_items: [['menu', lambda x: nav_drawer.toggle_nav_drawer()]]
NavigationLayout: #kivy.factory.FactoryException: Unknown class <MDNavigationLayout>
ScreenManager:
id: MainActivity
Screen:
id: SecondActivity
name: "main"
BoxLayout:
id: superbody_jbsidis
orientation: 'vertical'
spacing: dp(20)
MDCard:
id: jbsidis_will_be_card
orientation: "vertical"
border_radius: "-3dp"
ripple_behavior: True
padding: dp(10)
size: "320dp", "250dp"
size_hint: .5, None
pos_hint: {"center_x": .5, "center_y": .5}
background: "Photos/pro.jpg"
TextInput:
markup: True
font_size: dp(40)
size_hint: 1.1,1.1
#font_color: (0,0,0,1)
text: "Created by jbsidis " #open("file.txt").read()
id: bx1
background_color: [0,0,0,0]
foreground_color: [1,1,1,1]
halign: "left"
#multiline: True
hint_text: 'Insert Text'
FloatLayout:
BoxLayout:
pos_hint: {"center_x": 1.2, "center_y": .5}
MDIconButton:
canvas.before:
Color:
rgba: (1,1,1,.5)
Rectangle:
pos: self.pos
size: self.size
icon: "pencil"
on_release: app.root.ids.bx1.focus=True
MDIconButton:
canvas.before:
Color:
rgba: (1,1,1,.5)
Rectangle:
pos: self.pos
size: self.size
icon: "delete"
on_release:
app.root.ids.superbody_jbsidis.remove_widget(app.root.ids.jbsidis_will_be_card)
MDCard:
id: jbsidis_will_be_card2
orientation: "vertical"
border_radius: "-3dp"
ripple_behavior: True
padding: dp(10)
size: "320dp", "250dp"
size_hint: .5, None
pos_hint: {"center_x": .5, "center_y": .5}
background: "Photos/pro.jpg"
TextInput:
markup: True
font_size: dp(40)
size_hint: 1.1,1.1
#font_color: (0,0,0,1)
text: "Created by jbsidis " #open("file.txt").read()
id: bx2
background_color: [0,0,0,0]
foreground_color: [1,1,1,1]
halign: "left"
#multiline: True
hint_text: 'Insert Text'
FloatLayout:
BoxLayout:
pos_hint: {"center_x": 1.2, "center_y": .5}
MDIconButton:
canvas.before:
Color:
rgba: (1,1,1,.5)
Rectangle:
pos: self.pos
size: self.size
icon: "pencil"
on_release: app.root.ids.bx2.focus=True
MDIconButton:
canvas.before:
Color:
rgba: (1,1,1,.5)
Rectangle:
pos: self.pos
size: self.size
icon: "delete"
on_release:
app.root.ids.superbody_jbsidis.remove_widget(app.root.ids.jbsidis_will_be_card2)
Widget:
## BoxLayout:
## id: m5
## spacing: dp(10)
## #padding: dp(20)
## pos_hint: {"center_x": .5, "center_y": .43}
## orientation: "vertical"
## BoxLayout:
## id: s_res9
## size_hint_y: None #None
## height: self.minimum_height
## pos_hint: {"center_x": .5, "center_y": .4}
## orientation: "vertical"
## RecycleView:
## id: rvvv9
## key_viewclass: 'viewclass'
## key_size: 'height'
##
## RecycleBoxLayout:
## id: jbsidis
## padding: dp(10)
## spacing: dp(1)
## #default_size: None, dp(75)
## default_size_hint: 1, None
## size_hint_y: None
## height: self.minimum_height
## orientation: 'vertical'
Widget:
MDNavigationDrawer:
opening_time: 0.1
swipe_distance: 2
swipe_edge_width: 40
#scrim_color: [.1,.2,.4,1]
#spacing: dp(5)
id: nav_drawer
ContentNavigationDrawer:
id: content_drawer
<Menu1>:
name: "menu1"
## canvas.before:
## Color:
## rgba: (1,1,1, 1)
## Rectangle:
## source: app.w+"bgx.png"
## pos: self.pos
## size: self.size
## MDToolbar:
## canvas.before:
## Color:
## rgba: (1,1,1, .8)
## Rectangle:
## source: app.w+"toolbar.png"
## pos: self.pos
## size: self.size
## id: mt
## pos_hint: {"top": 1}
## title: app.t
## elevation: 10
## md_bg_color: (.1,.80,.5,.3)
## font_stye: "H5"
## #source: app.w+"toolbar.png"
## hint_animation: True
## MDIconButton:
## icon: "menu"
#left_action_items: [['menu', lambda x: print("")]]
BoxLayout:
id: m51
spacing: dp(10)
#padding: dp(20)
pos_hint: {"center_x": .5, "center_y": .43}
orientation: "vertical"
BoxLayout:
id: s_res91
size_hint_y: None #None
height: self.minimum_height
pos_hint: {"center_x": .5, "center_y": .4}
orientation: "vertical"
RecycleView:
id: rvvv91
key_viewclass: 'viewclass'
key_size: 'height'
RecycleBoxLayout:
id: jbsidis1
padding: dp(10)
spacing: dp(1)
#default_size: None, dp(75)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
#######Class Audio List########
<ItemConfirm0>:
source: app.w+"bbay.png"
<ItemConfirm>:
markup: True
ItemConfirm0:
'''
from kivymd.uix.list import ImageLeftWidget
class ItemConfirm0(ImageLeftWidget):
pass
class ItemConfirm(OneLineIconListItem):
divider = None
source = StringProperty()
text= StringProperty()
us=None
## def on_release(self):
## b=str(self.text)
## us=self.ids['cy_']
## us.text=b
## us.md_bg_color= [.1,.8,1,.9]
## return 0
def set_icon(self, instance_check):
instance_check.active = True
check_list = instance_check.get_widgets(instance_check.group)
for check in check_list:
if check != instance_check:
check.active = False
pass
##################################
#MenuNaibDrawerChooser
class blanks1(BoxLayout):
pass
class ContentNavigationDrawer(BoxLayout):
pass
class On1(MDCard):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def vn1(self):
user20=self.ids['user20']
print(user20.text)
try:
xx=open(app.w+"cookie.dic").read()
f=str(xx).split("]")
z="\n\n[b][color=ffffff] "+str(f[1])+"\n[/b] [color=ffffff]Cód. de Vendedor: "+str(f[2])+"\n[color=ffffff] Idioma: \n"
self.ids.user20.text=z
except Exception as e:
print(str(e))
def vn(self):
Clock.schedule_once(lambda x:self.vn1(),5)
pass
class ItemDrawer(OneLineIconListItem):
divider=None
icon = StringProperty()
text_color = ListProperty((0, 0, 0, 1))
class ExpressBay(MDApp):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.snackbar = None
self.w = worm
self.rr = 10
self.t="jbsidis"
self.sb="15sp" #"15sp"
self.mdc=[0,0,0, .1]
self.tos="hello"
def build(self):
#self.theme_cls.theme_style="Dark"
global app
app=MDApp.get_running_app()
#Clock.schedule_once(lambda x:app.io1(),10)
#Clock.schedule_once(lambda x:app.io2(),10)
return Builder.load_string(KV)
def n1(self,t,m):
try:
plyer.notification.notify(title=t, message=m, app_icon=app.w+"xbay.png")
except Exception as e:
print(str(e))
def n(self, title='', message='', app_name='', app_icon='',timeout=10, ticker='', toast=False):
plyer.notification.notify(title=title, message=message, app_name=app_name, app_icon=app_icon,timeout=timeout, ticker=ticker, toast=toast)
app.v(0.2)
def hilo(self,fx):
import threading
#thread = threading.Thread(target = app.sound_list, args=(types,))
thread = threading.Thread(target = fx)
thread.daemon = True
thread.start()
#app.hilo(app.camx())
def se(self,a):
if os.path.isfile(app.w+"set.dic")==True and a==0:
h=open(app.w+"set.dic").read().split("]")[0]
return str(h)
if os.path.isfile(app.w+"set.dic")==True and a==1:
h=open(app.w+"set.dic").read().split("]")[1]
return str(h)
return ""
def check(self, obj):
rs = "s"
try:
rs = getinfo(obj)
except:
pass
if rs == "Unknown Error":
toast('Unknown Error')
else:
try:
r = json.loads(rs)
version = str(r['version'])
country = str(r['city']) + " " + str(r['region']) + " "+ str(r['country_name'])
lit = str(r['latitude'])
long = str(r['longitude'])
self.root.ids.result.text = "\n" + self.root.ids.target_ip.text + "\n\n" + version + "\n\n" + country + "\n\n" + lit + "\n\n" + long
except Exception as e:
version = str("New version")
country = str("New Country") + " " + str("New City") + " "+ str("New Name")
lit = str("1.232323")
long = str("3437434")
self.root.ids.result.text = "\n" + self.root.ids.target_ip.text + "\n\n" + version + "\n\n" + country + "\n\n" + lit + "\n\n" + long
def tagm(self):
#On1().vn()
try:
xx=open(app.w+"cookie.dic").read()
f=str(xx).split("]")
z="\n\n[b][color=ffffff] "+str(f[1])+"\n[/b] [color=ffffff]Cód. de Vendedor: "+str(f[2])+"\n[color=ffffff] Idioma: \n"
#self.ids.user20.text=z
self.root.ids.content_drawer.ids.user20.text=z
app.root.ids.rvvv9.data=[]
#fffapp.root.ids.rvvv9.data.append({"viewclass": "Operas","markup": True}) #.data.append({"viewclass": "VenderRecargas","markup": True})
## self.root.ids.rvvv9.data.append({"viewclass": "pp1","markup": True})
## self.root.ids.rvvv9.data.append({"viewclass": "Operas","markup": True})
except Exception as e:
print(str(e))
def v(self,s):
try:
plyer.vibrator.vibrate(s)
except Exception as e:
print(str(e))
def action(self,a):
man=['chat-processing', 'shield-airplane-outline', 'history', 'bitcoin', 'bell-ring-outline', 'face-profile', 'credit-card-plus-outline', 'account-circle-outline', 'pencil', 'logout']
if a==man[-1]:
app.root.ids.nav_drawer.toggle_nav_drawer()
app.notti(title="",text="Sesión finalizada")
#app.root.ids.MainActivity.current = "loginpage"
def on_start(self):
#self.theme_cls.theme_style="Dark"
icons_item = {
"chat-processing": "[color=999999]jbsidis1",
"shield-airplane-outline": "[color=999999]jbsidis2",
"history": "[color=999999]jbsidis3",
"bitcoin": "[color=999999]jbsidis4",
"bell-ring-outline": "[color=999999]jbsidis5",
"face-profile": "[color=999999]jbsidis6",
"credit-card-plus-outline": "[color=999999]jbsidis7",
"account-circle-outline": "[color=999999]jbsidis8",
"pencil": "[color=999999]jbsidis9",
"logout": "[color=999999]jbsidis10"
}
#app.root.ids.MainActivity.add_widget(Login())
#app.root.ids.MainActivity.current = "login"
#app.root.ids.MainActivity.add_widget(LoginPage())
#app.root.ids.MainActivity.add_widget(Menu1())
#app.root.ids.MainActivity.add_widget(RegisterPage())
#app.root.ids.MainActivity.add_widget(Camera1())
#app.root.ids.MainActivity.current = "login"
for icon_name in icons_item.keys():
self.root.ids.content_drawer.ids.md_list.add_widget(
ItemDrawer(icon=icon_name, text=icons_item[icon_name])
)
def notti(self,title="",text=""):
self.dialog=MDDialog(
title=title,
text="[color=000000]"+text,
radius=[self.rr,self.rr,self.rr,self.rr],
buttons=[
MDFlatButton(
text="ACEPTAR",
text_color=[0,1,0,1],
on_release=lambda x:(self.dialog.dismiss(force=True))),
],
)
self.dialog.open()
ExpressBay().run()
Here is the image:

Python : How add a datepicker in .kv file

Can anyone tell me how to add a date picker or kivy calendar on date TextBox?
I have two file test.py and test.kv file.
test.py
import kivy
import sqlite3 as lite
from kivy.uix.screenmanager import Screen
from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.label import Label
Window.clearcolor = (0.5, 0.5, 0.5, 1)
Window.size = (400, 125)
class Testing(Screen):
pass
class Testing(App):
def build(self):
self.root = Builder.load_file('test.kv')
return self.root
if __name__ == '__main__':
Testing().run()
test.kv
Testing:
BoxLayout:
orientation: "vertical"
padding : 20, 20
BoxLayout:
orientation: "horizontal"
padding: 10, 10
spacing: 10, 10
size_hint_x: .55
Label:
text: "Date"
text_size: self.size
valign: 'middle'
size_hint_x: .2
TextInput:
size_hint_x: .3
BoxLayout:
orientation: "horizontal"
padding : 10, 0
spacing: 10, 10
size_hint: .5, .7
pos_hint: {'x': .25, 'y':.25}
Button:
text: 'Ok'
on_release:
root.dismiss()
Button:
text: 'Cancel'
on_release: root.dismiss()
.kv file
#:import MDTextField kivymd.uix.textfield.MDTextField
MDTextField:
id: set_date
hint_text: 'Start Date'
write_tab: False
on_focus: root.setDate()
.py file
from kivymd.uix.picker import MDDatePicker
def setDate(self,dobj):
self.ids.set_date.text = str(dobj)
pass
def fromDate(self):
self.foc = self.ids.set_date.focus
if(self.foc==True):
MDDatePicker(self.setFDate).open()
else:
print("not")

Python : How to get value of dynmaic row

I am new to python and kivy.
I am trying to get value of dynamic row.But now i am getting value like this
Column2
Column1
Can someone tell me how to get value like this ?
1,column1,column2
2,column1,column2
Because i have three column in my database table like id,name,value and i want to insert value in database table through loop
I am using this code
def insert_value(self):
values = []
rows = self.ids.rows
for row in reversed(rows.children):
for ch in row.children:
if isinstance(ch, TextInput):
values.append(ch.text)
lenArray = len(values)
for x in range(0, lenArray):
print (values[x])
demo.py
from kivy.uix.screenmanager import Screen
from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import BooleanProperty, ListProperty, StringProperty, ObjectProperty, NumericProperty
from kivy.uix.textinput import TextInput
Window.size = (450, 525)
class display(Screen):
def add_more(self):
self.ids.rows.add_row()
def insert_value(self):
values = []
rows = self.ids.rows
for row in reversed(rows.children):
for ch in row.children:
if isinstance(ch, TextInput):
values.append(ch.text)
lenArray = len(values)
for x in range(0, lenArray):
print (values[x])
class Row(BoxLayout):
button_text = StringProperty("")
id = ObjectProperty(None)
class Rows(BoxLayout):
orientation = "vertical"
row_count = 0
def __init__(self, **kwargs):
super(Rows, self).__init__(**kwargs)
self.add_row()
def add_row(self):
self.row_count += 1
self.add_widget(Row(button_text=str(self.row_count),id=str("test"+str(self.row_count))))
class test(App):
def build(self):
self.root = Builder.load_file('demo.kv')
return self.root
if __name__ == '__main__':
test().run()
demo.kv
<Row>:
orientation: "horizontal"
spacing: 0, 5
Button:
text: root.button_text
size_hint_x: .2
TextInput:
text:"Column1"
size_hint_x: .8
TextInput:
text:"Column2"
size_hint_x: .8
display:
BoxLayout:
orientation: "vertical"
padding : 20, 20
BoxLayout:
orientation: "horizontal"
Button:
size_hint_x: .2
text: "+Add More"
valign: 'bottom'
on_press: root.add_more()
BoxLayout:
orientation: "horizontal"
Label:
size_hint_x: .2
text: "SN"
valign: 'bottom'
Label:
size_hint_x: .8
text: "Value"
valign: 'bottom'
Rows:
id: rows
BoxLayout:
orientation: "horizontal"
padding : 10, 0
spacing: 10, 10
size_hint: .5, .7
pos_hint: {'x': .25, 'y':.25}
Button:
text: 'Ok'
on_release:
root.insert_value()
Button:
text: 'Cancel'
on_release: root.dismiss()
To maintain a structure we must create a list of lists, then in each list the first parameter is the text of the Button that we filter through isinstance(), and the other elements are concatenated.
[...]
from kivy.uix.button import Button
class display(Screen):
def add_more(self):
self.ids.rows.add_row()
def insert_value(self):
values = []
rows = self.ids.rows
for row in reversed(rows.children):
vals = []
for ch in reversed(row.children):
if isinstance(ch, TextInput):
vals.append(ch.text)
if isinstance(ch, Button):
vals.insert(0, ch.text)
values.append(vals)
for val in values:
print("{},{},{}".format(*val))
[...]
One option is to add a ListProperty to your Row class that stores the values of the row in the order you want, which makes it easier to obtain them later.
You can use a ListView to show the rows.
Demo.kv:
<Row>:
values: row_id.text, col1.text, col2.text
orientation: "horizontal"
spacing: 0, 5
size_hint_y: None
height: 30
Button:
id: row_id
text: root.button_text
size_hint_x: .2
TextInput:
id: col1
text:"Column1"
size_hint_x: .8
TextInput:
id: col2
text:"Column2"
size_hint_x: .8
<Rows>:
content: content
BoxLayout:
id: content
orientation: "vertical"
size_hint_y: None
height: self.minimum_height
Display:
rows: rows
BoxLayout:
orientation: "vertical"
padding : 20, 20
BoxLayout:
orientation: "horizontal"
Button:
size_hint_x: .2
text: "+Add More"
valign: 'bottom'
on_press: root.add_more()
BoxLayout:
orientation: "horizontal"
Label:
size_hint_x: .2
text: "SN"
valign: 'bottom'
Label:
size_hint_x: .8
text: "Value"
valign: 'bottom'
Rows:
id: rows
BoxLayout:
orientation: "horizontal"
padding : 10, 10
spacing: 10, 10
size_hint: .5, .7
pos_hint: {'x': .25, 'y':.25}
Button:
text: 'Ok'
on_release:
root.insert_value()
Button:
text: 'Cancel'
on_release: root.dismiss()
Demo.py:
from kivy.uix.screenmanager import Screen
from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ListProperty, StringProperty, ObjectProperty
from kivy.uix.scrollview import ScrollView
from kivy.clock import Clock
Window.size = (450, 525)
class Display(Screen):
rows = ObjectProperty(None)
def __init__(self, **kwargs):
super(Display, self).__init__(**kwargs)
def add_more(self):
self.rows.add_row()
def insert_value(self):
values = [row.values for row in reversed(self.rows.content.children)]
for row in values:
print(row)
class Row(BoxLayout):
button_text = StringProperty("")
id = ObjectProperty(None)
values = ListProperty()
class Rows(ScrollView):
row_count = 0
content = ObjectProperty(None)
def __init__(self, **kwargs):
super(Rows, self).__init__(**kwargs)
Clock.schedule_once(self.add_row)
def add_row(self, *args):
self.row_count += 1
self.content.add_widget(Row(button_text=str(self.row_count),
id="test" + str(self.row_count)))
class Test(App):
def build(self):
self.root = Builder.load_file('Demo.kv')
return self.root
if __name__ == '__main__':
Test().run()

Categories