Cycling though popup windows in Kivy - python

I created a main windows with 6 toggle buttons in Kivy.
I like to access a popup window with related settings via a long-press event on each of these toggle buttons.
The popup window is defined and has "next" and "previous" buttons to cycle from one settings page to the next one.
How can I avoid to create each of these popup definitions manually in Kivy?
Dummy .kv code:
#:import Factory kivy.factory.Factory
<MyPopup2#Popup>:
auto_dismiss: False
title: "Popup Window No. 2"
Button:
text: 'Close me, too!'
on_release: root.dismiss()
MyPopup1#Popup:
auto_dismiss: False
size_hint: None,None
size: 400,300
title: "Popup Window No. 1"
BoxLayout:
orientation: "vertical"
BoxLayout:
orientation: "vertical"
BoxLayout:
Label:
text: 'Circuit Active:'
Switch:
id: "switch1"
BoxLayout:
Label:
text: 'Default Watering Time: [min]'
TextInput:
text: '30'
BoxLayout:
Label:
text: 'Watering Group'
TextInput:
text: '3'
BoxLayout:
Button:
text: 'Previous'
Button:
text: 'Cancel'
on_release: root.dismiss()
Button:
text: 'Save + Exit'
Button:
text: 'Next'
on_release: root.dismiss()
on_release: Factory.MyPopup2().open()
BoxLayout:
orientation: "vertical"
padding: 5
BoxLayout:
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 1"
# disabled: True
on_release: Factory.MyPopup1().open()
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 2"
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 3"
BoxLayout:
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 4"
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 5"
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 6"
BoxLayout:
BoxLayout:
padding: 5
Label:
text: 'Drei Zeilen\nmit\nStatusmeldungen'
BoxLayout:
size_hint_x: 0.5
padding: 5
ToggleButton:
text: "Automatik-\nBetrieb"
on_press: app.testfunktion()

In the same way, as you extended Popup you can also extend MyPopup you created. I implemented it for the first two Popups. It is straightforward to extend it. If you still have a question ask in the comments.
All the features MyPopup has are also in MyPopup1 because it extends MyPopup. The title should be different and the previous and next are different for each Popup. Therefore you need to specify them.
<MyPopup1#MyPopup>:
title: "Popup Window No. 1"
call_previous:
call_next: "Factory.MyPopup2().open()"
I am using eval in the MyPopup to "evaluate" these statements which are part of the root. See this extract from MyPopup:
on_release: eval(root.call_next)
Alternatively you could also give them just numbers and use maybe sth similar, but I'll leave that up to you.
#:import Factory kivy.factory.Factory
<MyPopup1#MyPopup>:
title: "Popup Window No. 1"
call_previous:
call_next: "Factory.MyPopup2().open()"
<MyPopup2#MyPopup>:
title: "Popup Window No. 2"
call_previous: "Factory.MyPopup1().open()"
call_next: "Factory.MyPopup2().open()"
<MyPopup#Popup>:
auto_dismiss: False
size_hint: None,None
size: 400,300
BoxLayout:
orientation: "vertical"
BoxLayout:
orientation: "vertical"
BoxLayout:
Label:
text: 'Circuit Active:'
Switch:
id: "switch1"
BoxLayout:
Label:
text: 'Default Watering Time: [min]'
TextInput:
text: '30'
BoxLayout:
Label:
text: 'Watering Group'
TextInput:
text: '3'
BoxLayout:
Button:
text: 'Previous'
on_release: root.dismiss()
on_release: eval(root.call_previous)
Button:
text: 'Cancel'
on_release: root.dismiss()
Button:
text: 'Save + Exit'
Button:
text: 'Next'
on_release: root.dismiss()
on_release: eval(root.call_next)
BoxLayout:
orientation: "vertical"
padding: 5
BoxLayout:
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 1"
# disabled: True
on_release: Factory.MyPopup1().open()
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 2"
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 3"
BoxLayout:
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 4"
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 5"
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 6"
BoxLayout:
BoxLayout:
padding: 5
Label:
text: 'Drei Zeilen\nmit\nStatusmeldungen'
BoxLayout:
size_hint_x: 0.5
padding: 5
ToggleButton:
text: "Automatik-\nBetrieb"
on_press: app.testfunktion()

Related

Kivy ScrollView does not fill the entire window

I am trying to write a Kivy file that includes a scrollview below the MDToolBar and above MDBottomNavigation. I cannot get the ScrollView content to fill the entire screen below the ToolBar and above the BottomNav. It only fills have the window vertical span. If I eliminate the toolbar and bottom nave the scrollview fills the entire vertical span without a problem. Any tips on getting the scrollview contents to fill the completely would be appreciated. I tried changing indentation and that did not work. Thanks in advance.
Screenshot
# WINDOW MANAGER
WindowManager:
MainWindow:
AboutWindow:
<MainWindow>:
name: "main"
BoxLayout:
orientation: "vertical"
MDToolbar:
title: "Solar Weather"
MDLabel:
id: sub_title
text: "SUB TITLE"
halign: "center"
size_hint: (1,0.2)
ScrollView:
size: self.size
GridLayout:
size_hint_y: None
height: self.minimum_height
width: self.minimum_width
cols: 2
spacing: "20dp"
padding: "20dp"
# SOLAR FLUX BOX #
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: 1, None
height: "210dp"
elevation: 5
MDLabel:
id: flux
text: "Solar Wind"
halign: "center"
MDLabel:
id: flux_value_id
text: ""
halign: "center"
MDLabel:
id: flux_time_id
text: ""
halign: "center"
MDRaisedButton:
text: "Refresh"
pos_hint: {"x":0}
size_hint: 1,1
md_bg_color: app.theme_cls.primary_color
on_release: root.calc_solar_flux()
MDRaisedButton:
text: "Details"
pos_hint: {"x":0}
size_hint: 1,1
md_bg_color: app.theme_cls.primary_color
on_release: root.calc_solar_flux()
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: 1, None
height: "210dp"
elevation: 5
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: 1, None
height: "210dp"
elevation: 5
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: 1, None
height: "210dp"
elevation: 5
MDLabel:
text: "Solar Wind"
halign: "center"
MDRaisedButton:
text: "Go Back"
md_bg_color: app.theme_cls.primary_color
on_release:
root.manager.current = "main"
root.manager.transition.direction = "right"
MDBottomNavigation:
MDBottomNavigationItem:
name: 'Dark'
text: "Dark Theme"
icon: 'brightness-2'
on_tab_release: root.dark_theme()
MDBottomNavigationItem:
name: 'Light'
text: "Light Theme"
icon: 'brightness-5'
on_tab_release: root.light_theme()
MDBottomNavigationItem:
name: 'info'
text: "About"
icon: 'information'
on_tab_release:
root.manager.current = "about"
root.manager.transition.direction = "left"
MDBottomNavigationItem:
name: 'option 2'
text: "Relaod"
icon: 'reload'
#: include about.kv
I hope this helps someone else. I had to rewrite the kv file fairly extensively but it works.
# WINDOW MANAGER
WindowManager:
MainWindow:
AboutWindow:
<MainWindow>:
name: "main"
BoxLayout:
orientation: "vertical"
MDLabel:
id: title
text: "SOLAR WEATHER"
halign: "left"
size_hint: (1,0.1)
padding_x: 20
pos_hint: {"x":0.0,"y":0.9}
md_bg_color: app.theme_cls.primary_dark
MDLabel:
id: sub_title
text: "SUB TITLE"
halign: "center"
size_hint: (1,0.1)
pos_hint: {"x":0.0,"y":0.8}
ScrollView:
size: self.size
pos_hint: {"x":0,"y":0.1}
GridLayout:
size_hint_y: None
height: self.minimum_height
width: self.minimum_width
cols: 2
spacing: "20dp"
padding: "20dp"
# SOLAR FLUX BOX #
MDCard:
orientation: "vertical"
padding: "8dp"
spacing: "8dp"
size_hint: 1, None
height: "210dp"
elevation: 5
MDLabel:
id: flux
text: "SOLAR FLUX"
halign: "center"
MDLabel:
id: flux_value_id
markup: True
text: ""
halign: "center"
MDLabel:
id: flux_time_id
text: ""
halign: "center"
MDRaisedButton:
text: "Refresh"
pos_hint: {"x":0}
size_hint: 1,1
md_bg_color: app.theme_cls.primary_color
on_release: root.calc_solar_flux()
MDRaisedButton:
text: "Details"
pos_hint: {"x":0}
size_hint: 1,1
md_bg_color: app.theme_cls.primary_color
on_release: root.calc_solar_flux()
# SUN SPOT NUMBER BOX #
MDCard:
orientation: "vertical"
padding: "8dp"
spacing: "8dp"
size_hint: 1, None
height: "210dp"
elevation: 5
MDLabel:
id: ssn
text: "SUN SPOT NUMBER"
halign: "center"
MDLabel:
id: ssn_value_id
markup: True
text: ""
halign: "center"
MDLabel:
id: ssn_date_id
text: ""
halign: "center"
MDRaisedButton:
text: "Refresh"
pos_hint: {"x":0}
size_hint: 1,1
md_bg_color: app.theme_cls.primary_color
on_release: root.calc_sunspot_number()
MDRaisedButton:
text: "Details"
pos_hint: {"x":0}
size_hint: 1,1
md_bg_color: app.theme_cls.primary_color
on_release: root.calc_sunspot_number()
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: 1, None
height: "210dp"
elevation: 5
MDCard:
orientation: "vertical"
padding: "8dp"
spacing: "8dp"
size_hint: 1, None
height: "210dp"
elevation: 5
MDLabel:
text: "Solar Wind"
halign: "center"
MDRaisedButton:
text: "Go Back"
md_bg_color: app.theme_cls.primary_color
on_release:
root.manager.current = "main"
root.manager.transition.direction = "right"
GridLayout:
size_hint_y: None
height: self.minimum_height
width: self.minimum_width
cols: 3
spacing: "80dp"
padding: "20dp"
MDIconButton:
name: "Dark"
text: "Dark Theme"
icon: "brightness-2"
on_release: root.dark_theme()
md_bg_color: app.theme_cls.primary_dark
MDIconButton:
id: light_theme_icon
name: "Light"
text: "Light Theme"
icon: "brightness-5"
on_release: root.light_theme()
md_bg_color: app.theme_cls.primary_dark
MDIconButton:
name: "info"
text: "About"
icon: "information"
on_release:
root.manager.current = "about"
md_bg_color: app.theme_cls.primary_dark
#: include about.kv

PYTHON + KIVYMD / KIVY | Scrollview is only on half the screen but works as normal when used in a navigation drawer

Here is a picture of the problem. As you can see the left side picture has a fully working scrollview, the rightside picture on the other hand is only displaying the scrollview on the bottom half of the screen.
Not sure whats wrong here. Ive tried moving the intendent levels back and forth, for some reason it refuses to put anything above the equator
Snippit of the KV code from the not working part:
Screen:
container: container
BoxLayout:
id: container
orientation: 'vertical'
MDToolbar:
title: "TRYM"
anchor_title: "center"
# right_action_items: [["check", lambda x: app.show_alert_dialog_save(), 'Save']]
left_action_items: [["keyboard-backspace", lambda x: app.show_alert_dialog_back(), 'Back']]
Widget:
ScreenManager:
id: screen_manager
Screen:
name: 'innlogget_trym_alarm'
id: trym
MDBottomNavigation:
MDBottomNavigationItem:
name: 'alarm_trym'
text: 'Alarm'
icon: 'alarm'
on_tab_release: text: 'Alarm'
MDLabel:
text: 'Currently no alarm active'
pos_hint: {"center_x": .5, "center_y": .8}
halign: 'center'
MDFloatingActionButton:
id: trym_time_picker
name: 'trym'
icon: "alarm-plus"
opposite_colors: False
elevation_normal: 8
pos_hint: {"center_x": .9, "center_y": .2}
on_release:
app.show_time_picker('trym')
MDBottomNavigationItem:
name: 'instillinger_trym'
text: 'Instillinger'
icon: 'tools'
# on_tab_release: screen_manager.current = "settings_list_view"
MDLabel:
ScrollView:
MDList:
OneLineIconListItem:
text: "Oppgrader til premium"
on_release:
print("Click!")
IconLeftWidget:
icon: "lock-outline"
TwoLineIconListItem:
text: "Tilkoblingsinnstillinger"
secondary_text: "Endre IP og port for klientsiden"
on_release:
app.show_confirmation_dialog()
IconLeftWidget:
icon: "lan-connect"
TwoLineIconListItem:
text: "Alarminstillinger"
secondary_text: "Konfigurer forsinket eller for tidlig handling"
on_release:
print("Click!")
IconLeftWidget:
icon: "account-clock"
Snippit of the KV code from the working part:
MDNavigationDrawer:
id: nav_draw
orientation: "vertical"
padding: "8dp"
spacing: "8dp"
AnchorLayout:
anchor_x: "center"
size_hint_y: None
height: avatar.height
Image:
id: avatar
size_hint: None, None
size: "56dp", "56dp"
source: "untitled.jpg"
MDLabel:
halign: 'center'
anchor_x: "right"
text: "AnySched"
font_style: "Button"
size_hint_y: None
height: self.texture_size[1]
MDLabel:
text: ""
font_style: "Caption"
size_hint_y: None
height: self.texture_size[1]
ScrollView:
MDList:
OneLineAvatarListItem:
on_press:
nav_draw.set_state("close")
app.next_screen('trym')
text: "Trym"
IconLeftWidget:
icon: "account-box"
OneLineAvatarListItem:
on_press:
nav_draw.set_state("close")
screen_manager.current = "lucas"
So I found the problem (posting incase anyone else gets the same issue).
Screen:
container: container
BoxLayout:
id: container
orientation: 'vertical'
MDToolbar:
title: "TRYM"
anchor_title: "center"
# right_action_items: [["check", lambda x: app.show_alert_dialog_save(), 'Save']]
left_action_items: [["keyboard-backspace", lambda x: app.show_alert_dialog_back(), 'Back']]
Widget: # <----- After removing this the ScrollView fills the whole screen not just half :)
ScreenManager:
id: screen_manager
Screen:
name: 'innlogget_trym_alarm'
id: trym
MDBottomNavigation:

KivyMD Remove a Expansion Panel

I'm having trouble finding the solution in how to remove an expansion panel which inside of it it contains TwoLineAvatarListItem with a IconLeftWidget, and below that is a MDCard with two MDlabels for text. I've tried to use self.root.ids.remove_widget() but it does not do anything. I've tried many ways and have not found the solution. Here is the code please feel free to view. Thanks
kv. file
<Content>:
adaptive_height: True
#size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
TwoLineAvatarListItem:
text: "Message"
secondary_text: 'to: #gmail.com'
IconLeftWidget:
icon: 'email'
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: None, None
size: "280dp", "180dp"
pos_hint: {"center_x": .5, "center_y": .5}
MDLabel:
text: "Title"
theme_text_color: "Secondary"
size_hint_y: None
height: self.texture_size[1]
MDSeparator:
height: "1dp"
MDLabel:
text: "Body"
ScreenManager:
Screen:
id: messages
name: 'messages'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Messages Center"
elevation:8
MDIconButton:
icon: 'arrow-left'
on_press: screen_manager.current = "main_app_screen"
theme_text_color: 'Custom'
md_bg_color: app.theme_cls.primary_color
ScrollView:
GridLayout:
cols: 1
size_hint_y: None
height: self.minimum_height
id: box
.py python file
class DemoApp(MDApp):
def on_start(self):
for i in range(10):
panel = MDExpansionPanel(
icon=f"{images_path}folder.png",
content=Content(),
panel_cls=MDExpansionPanelTwoLine(
text='',
secondary_text=str(i) + ' email: xxxxx#gmail.com',))
self.root.ids.box.add_widget(panel)
DemoApp().run()
<Content>:
[...]
MDCard:
[...]
MDRaisedButton:
text: "REMOVE"
on_release: app.remove(root)
[...]
class DemoApp(MDApp):
[...]
def remove(self, content):
self.root.ids.box.remove_widget(content.parent)

Widgets inside Tabbed Panel in Kivy

I'm new to designing in kivy and I'm trying to display a listview, inputbox and label inside a Tab panel but it's showing empty panel. I'm not sure where is my mistake.
I want to do a simple search of users by just typing the username in the inputbox then the listview will automatically update the records inside the listview.
I'm using kivy 1.10.0 and python 3.6
Here is my code in kivy file:
<AdminMainScreen#Screen>:#===================MAIN SCREEN=========================
txt_search: txt_search
view_user_list: view_user_list
BoxLayout:
size_hint_y: 1
size_hint_x: 1
canvas:
Color:
rgb: .132, .232, .249
Rectangle:
size: self.size
TabbedPanel:
do_default_tab: False
TabbedPanelItem:
text:"1st Tab"
Label:
text: "Content of Admin Panel"
TabbedPanelItem:
text:"2nd Tab"
Label:
text: "Content of Second Panel"
TabbedPanelItem:
text:"Manage Users"
BoxLayout:
size_hint_y: .2
size_hint_x: 1
orientation: 'horizontal'
Label:
text: "Search User"
size_hint_x: .25
spacing: .2, .2
TextInput:
id: txt_search
text: ""
size_hint_x: .3
spacing: .2, .2
Label:
id: lbl_search
size_hint_y:None
height: 10
text: ""
ListView:
color: [0,0,0]
id: view_user_list
size_hint_x: 1
size_hint_y: .8
item_strings: []
adapters:
ListAdapter(data=[], cls = ListItemButton)
I don't think that having multiple widgets in a TabbedPanelItem is allowed, there is only one child - content. So just put an extra Layout and everything you want in the tab inside that one layout:
BoxLayout: # The only child of panel item
size_hint_y: 1
size_hint_x: 1
orientation: 'horizontal'
BoxLayout:
size_hint_y: 0.2
size_hint_x: 1
orientation: 'horizontal'
Label:
text: "Search User"
size_hint_x: .25
spacing: .2, .2
TextInput:
id: txt_searh
text: ""
size_hint_x: .3
spacing: .2, .2
Label:
id: lbl_search
size_hint_y:None
...

ScrollView in a anchorlayout. python. kivy

practice screen
This is from the .py file
The screens are controlled by screen manager as you can see
class Practice_Page(Screen):
pass
class PracticeList(BoxLayout):
def practicelist(ScrollView):
practicelist.bind(minimum_height=layout.setter('height'))
.KV file:
<Practice_page>:
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: 'background1.png'
AnchorLayout:
anchor_x: 'center'
anchor_y: 'center'
PracticeList:
size: 900,30
size_hint: None,None
do_scroll_x: False
BoxLayout:
orientation: 'vertical'
padding: 10
cols: 1
Button:
text: 'The Real Number System'
on_press: root.manager.current = 'open_topics'
Button:
text: 'Absolute Value'
on_press: root.manager.current = 'open_practice'
Button:
text: 'Operations W/ Integers & Fractions'
on_press: root.manager.current = 'open_topics'
Button:
text: 'Operations W/ Zero'
on_press: root.manager.current = 'open_formulas'
I have about 30 more buttons. I have no idea what I'm doing wrong, any help or suggestions will be very helpful.
AnchorLayout:
anchor_x: 'center'
anchor_y: 'center'
ScrollView:
#size: 900,30
size: self.size
#do_scroll_x: False
GridLayout:
# orientation: 'vertical'
#padding: 10
size_hint_y: None
height: self.minimum_height
cols: 1
Button:
size_hint_y: None
text: 'The Real Number System'
on_press: root.manager.current = 'open_topics'
Button:
size_hint_y: None
text: 'Absolute Value'
on_press: root.manager.current = 'open_practice'
Button:
size_hint_y: None
text: 'Operations W/ Integers & Fractions'
on_press: root.manager.current = 'open_topics'
Button:
size_hint_y: None
text: 'Operations W/ Zero'
on_press: root.manager.current = 'open_formulas'
##MORE BTNS
For anyone who needs it.

Categories