Jatin Kaushal
Jatin Kaushal

Reputation: 33

kivymd - [Critical] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration

Here is my main.py:

#!/usr/bin/env python3
from kivy.app import App
from kivy.lang import Builder
from kivy.metrics import dp
from kivy.properties import ObjectProperty
from kivy.uix.image import Image
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivymd.bottomsheet import MDListBottomSheet, MDGridBottomSheet
from kivymd.button import MDIconButton
from kivymd.date_picker import MDDatePicker
from kivymd.dialog import MDDialog
from kivymd.label import MDLabel
from kivymd.list import ILeftBody, ILeftBodyTouch, IRightBodyTouch, BaseListItem
from kivymd.material_resources import DEVICE_TYPE
from kivymd.navigationdrawer import MDNavigationDrawer, NavigationDrawerHeaderBase
from kivymd.selectioncontrols import MDCheckbox
from kivymd.snackbar import Snackbar
from kivymd.theming import ThemeManager
from kivymd.time_picker import MDTimePicker

Builder.load_file('main.kv')

class BoxTopLevel(BoxLayout):
    def on_release_next_button(self):
        # self.ids['sm'].current="mainscreen"
        if not self.ids['username'].text:
            Snackbar(text="Please enter a username first").show()
            return 1
        elif ' ' in self.ids['username'].text:
            Snackbar(text="Invalid username").show()
            return 1
        elif '\\' in self.ids['username'].text:
            Snackbar(text="Invalid username").show()
            return 1
        # elif '\\' in self.ids['username'].text:
        #   Snackbar(text="No slashes please").show()
        if self.check_if_user_exists():
            Snackbar(text="Welcome %s!" % (self.ids['username'].text)).show()
            self.ids['sm'].current='mainscreen'
            return 0

    def check_if_user_exists(self):
        return True

    def set_previous_date(self, date_obj):
        self.previous_date = date_obj
        # self.root.ids.date_picker_label.text = str(date_obj)

    def show_date_picker(self):
        self.date_dialog = MDDatePicker(self.set_previous_date)
        self.date_dialog.open()

    def show_time_picker(self):
        self.time_dialog = MDTimePicker()
        self.time_dialog.open()

    def show_send_error_dialog(self):
        content = MDLabel(font_style='Body1', theme_text_color='Secondary', text="This is a dialog with a title and some text. That's pretty awesome right!", size_hint_y=None, valign='top')
        content.bind(texture_size=content.setter('size'))
        self.dialog = MDDialog(title="This is a test dialog",
                               content=content,
                               size_hint=(.8, None),
                               height=dp(200),
                               auto_dismiss=False)

        self.dialog.add_action_button("Dismiss",
                                      action=lambda *x: self.dialog.dismiss())
        self.dialog.open()

    def stop_record(self):
        print("[INFO] Recording Stopped")
        Snackbar(text="Recording stopped").show()
        self.stop_record_button = self.ids['stop_record_button']
        self.stop_record_button.disabled = True
        self.ids['record_button'].disabled = False
        rec_file_path = ''

    def record(self):
        print("[INFO] Recording")
        Snackbar(text="Recording started").show()
        self.record_button = self.ids['record_button']
        self.record_button.disabled = True
        self.ids['stop_record_button'].disabled = False

    def export(self, username, date, time, *args, **kwargs):
        username, date, time = str(username), str(date), str(time)
        file_path = '/home/cocoa/KES/'
        file_name = username+'_'+date+'_'+time+'.csv'
        csv_string = username+','+date+','+time
        for arg in args:
            if type(arg) == str:
                csv_string += ','+arg
        f = open(file_path+file_name, 'w')
        f.write(csv_string+'\n')
        f.close
        return True, file_path+file_name

    def upload(self, csv_file_path, recording_file_path):
        print(csv_file_path, recording_file_path)

    def submit(self):
        try:
            date = str(self.date_dialog.day)+'-'+str(self.date_dialog.month)+'-'+str(self.date_dialog.year)
            print(date)
            if self.export(self.ids['username'].text, date, self.time_dialog.time, 'answer1', 'answer2')[0]:
                Snackbar(text="Woo hoo! It worked!").show()
            else:
                self.show_send_error_dialog()
        except:
            Snackbar(text="Please enter the date and time and try again").show()

class SamplerApp(App):
    theme_cls = ThemeManager()
    def build(self, *args, **kwargs):
        return BoxTopLevel()


SamplerApp().run()

And here is my main.kv:

#:import Toolbar kivymd.toolbar.Toolbar
#:import ThemeManager kivymd.theming.ThemeManager
#:import MDNavigationDrawer kivymd.navigationdrawer.MDNavigationDrawer
#:import NavigationLayout kivymd.navigationdrawer.NavigationLayout
#:import NavigationDrawerDivider kivymd.navigationdrawer.NavigationDrawerDivider
#:import NavigationDrawerToolbar kivymd.navigationdrawer.NavigationDrawerToolbar
#:import NavigationDrawerSubheader kivymd.navigationdrawer.NavigationDrawerSubheader
#:import MDCheckbox kivymd.selectioncontrols.MDCheckbox
#:import MDSwitch kivymd.selectioncontrols.MDSwitch
#:import MDList kivymd.list.MDList
#:import OneLineListItem kivymd.list.OneLineListItem
#:import TwoLineListItem kivymd.list.TwoLineListItem
#:import ThreeLineListItem kivymd.list.ThreeLineListItem
#:import OneLineAvatarListItem kivymd.list.OneLineAvatarListItem
#:import OneLineIconListItem kivymd.list.OneLineIconListItem
#:import OneLineAvatarIconListItem kivymd.list.OneLineAvatarIconListItem
#:import MDTextField kivymd.textfields.MDTextField
#:import MDSpinner kivymd.spinner.MDSpinner
#:import MDCard kivymd.card.MDCard
#:import MDSeparator kivymd.card.MDSeparator
#:import MDDropdownMenu kivymd.menu.MDDropdownMenu
#:import get_color_from_hex kivy.utils.get_color_from_hex
#:import colors kivymd.color_definitions.colors
#:import SmartTile kivymd.grid.SmartTile
#:import MDSlider kivymd.slider.MDSlider
#:import MDTabbedPanel kivymd.tabs.MDTabbedPanel
#:import MDTab kivymd.tabs.MDTab
#:import MDProgressBar kivymd.progressbar.MDProgressBar
#:import MDAccordion kivymd.accordion.MDAccordion
#:import MDAccordionItem kivymd.accordion.MDAccordionItem
#:import MDAccordionSubItem kivymd.accordion.MDAccordionSubItem
#:import MDThemePicker kivymd.theme_picker.MDThemePicker
#:import MDBottomNavigation kivymd.tabs.MDBottomNavigation
#:import MDBottomNavigationItem kivymd.tabs.MDBottomNavigationItem
<BoxTopLevel>:
    orientation: 'vertical'
    Toolbar:
        id: toolbar
        title: 'Sampler'
        md_bg_color: app.theme_cls.primary_color
        background_palette: 'Primary'
        background_hue: '500'
        #left_action_items: [['menu', lambda x: app.root.toggle_nav_drawer()]]
        #right_action_items: [['dots-vertical', lambda x: app.root.toggle_nav_drawer()]]
    ScreenManager:
        id: sm
        Screen:
            name: "loginscreen"
            BoxLayout:
                spacing: 20
                padding: 20
                orientation: 'vertical'
                Widget:
                BoxLayout:
                    orientation: 'vertical'
                    padding: 10
                    spacing: 10
                    MDTextField:
                        id: username
                        hint_text: "Please enter your unique username"
                    MDCard:
                        size_hint_x: 1
                        BoxLayout:
                            padding: 10
                            spacing: 10
                            orientation: 'vertical'
                            MDLabel:
                                text: 'Please don\'t share this username'
                                theme_text_color: 'Secondary'
                                font_style: "Title"
                                size_hint_y: None
                                height: dp(36)
                            MDSeparator:
                                height: dp(1)
                            MDLabel:
                                text: "This application was developed in a hurry, So I didn't have the time to implement a proper login system. This system is temporary And I will impliment proper logins at later stages of development"
                                theme_text_color: "Primary"
                    MDRaisedButton:
                        size_hint_x: 1
                        text: "Next ->"
                        on_release: root.on_release_next_button()
        Screen:
            name: "mainscreen"
            MDBottomNavigation:
                id: bottom_navigation_demo
                MDBottomNavigationItem:
                    name: 'record_page'
                    text: "Record"
                    icon: "microphone"
                    BoxLayout:
                        orientation: 'vertical'
                        padding: 10
                        spacing: 10
                        MDCard:
                            size_hint: 1, 0.2
                            BoxLayout:
                                padding: 10
                                spacing: 10
                                orientation: 'vertical'
                                MDLabel:
                                    text: 'Hello!'
                                    theme_text_color: 'Secondary'
                                    font_style: "Title"
                                    size_hint_y: None
                                    height: dp(36)
                                MDSeparator:
                                    height: dp(1)
                                MDLabel:
                                    text: "Since the buzzer went off, now is the time when you freely record your thought through this app. I want you to be as free as possible, without having to worry about whether or not anyone else will find any meaning in what you're saying. You can go on for as long as you like, but please try and go on for three minutes. You don't have to be talking throughout, it's okay to fill the time with silence if you can't freely associate in that moment. There isn't any right or wrong here, it's not possible for there to be any right or wrong here. Do log in your stats before you start here:"
                                    theme_text_color: "Primary"
                        Widget:
                            size_hint_y: 0.02
                            BoxLayout:
                                padding: 10
                                spacing: 10
                                MDRaisedButton:
                                    id: record_button
                                    text: "Start Recording"
                                    on_press: root.record()
                                MDRaisedButton:
                                    id: stop_record_button
                                    text: "Stop Recording"
                                    on_press: root.stop_record()
                                    disabled: True
                MDBottomNavigationItem:
                    name: 'questions'
                    text: "Questions"
                    icon: "help"
                    GridLayout:
                        rows: 7
                        cols: 1
                        padding: dp(48)
                        spacing: 10
                        MDTextField:
                            id: location
                            multiline: True
                            hint_text: "Where are you?"
                        MDTextField:
                            id: task
                            multiline: True
                            hint_text: "What were you doing?"
                        MDTextField:
                            id: person_with
                            multiline: True
                            hint_text: "Who are you with"
                        MDTextField:
                            id: special_circumstances
                            multiline: True
                            hint_text: "Are there any special circumstances? (Inebriated, very sad, something big happened)"
                        MDRaisedButton:
                            id: date
                            size_hint: None, None
                            size: 3 * dp(48), dp(48)
                            on_press: root.show_date_picker()
                            text: "What date is it?"
                        MDRaisedButton:
                            text: "What time is it?"
                            size_hint: None, None
                            size: 3 * dp(48), dp(48)
                            on_press: root.show_time_picker()
                        MDRaisedButton:
                            id: submit_button
                            disabled: False
                            text: "Submit!"
                            size_hint: None, None
                            size: 3 * dp(48), dp(48)
                            on_press: root.submit()
                MDBottomNavigationItem:
                    name: 'info'
                    text: "Info"
                    icon: "information"
                    GridLayout:
                        spacing: 20
                        padding: 20
                        rows: 4
                        cols: 1
                        MDRaisedButton:
                            size_hint_x: 1
                        MDRaisedButton:
                            size_hint_x: 1
                        MDRaisedButton:
                            size_hint_x: 1
                        MDRaisedButton:
                            size_hint_x: 1

I copied a lot of the kv code from the kitchen sink that kivymd provides. I found another answer on Stack Overflow but didn't quite understand what was causing the error. And since my code seems worse, I'd really appreciate it if someone could explain what exactly is causing the error and why. In my python file, I've just use iteration once in the export function.

Also, here is the output of the code:

[Command: /usr/bin/env -u /home/cocoa/KES/main.py]
[INFO   ] [Logger      ] Record log in /home/cocoa/.kivy/logs/kivy_17-09-22_83.txt
[INFO   ] [Kivy        ] v1.10.0
[INFO   ] [Python      ] v3.6.2 (default, Jul 20 2017, 03:52:27) 
[GCC 7.1.1 20170630]
[INFO   ] [Factory     ] 194 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[INFO   ] [KivyMD      ] KivyMD version: 0.1.2
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [OSC         ] using <multiprocessing> for socket
[INFO   ] [Window      ] Provider: sdl2(['window_egl_rpi'] ignored)
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] Backend used <gl>
[INFO   ] [GL          ] OpenGL version <b'4.5.0 NVIDIA 384.69'>
[INFO   ] [GL          ] OpenGL vendor <b'NVIDIA Corporation'>
[INFO   ] [GL          ] OpenGL renderer <b'GeForce GT 705/PCIe/SSE2'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 5
[INFO   ] [GL          ] Shading version <b'4.50 NVIDIA'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [GL          ] NPOT texture support is available
[INFO   ] [Clipboard   ] Provider: sdl2(['clipboard_dbusklipper', 'clipboard_gtk3', 'clipboard_xclip', 'clipboard_xsel'] ignored)
[CRITICAL] [Cutbuffer   ] Unable to find any valuable Cutbuffer provider.
xclip - FileNotFoundError: [Errno 2] No such file or directory: 'xclip'
  File "/usr/lib/python3.6/site-packages/kivy/core/__init__.py", line 59, in core_select_lib
    fromlist=[modulename], level=0)
  File "/usr/lib/python3.6/site-packages/kivy/core/clipboard/clipboard_xclip.py", line 17, in <module>
    p = subprocess.Popen(['xclip', '-version'], stdout=subprocess.PIPE)
  File "/usr/lib/python3.6/subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1333, in _execute_child
    raise child_exception_type(errno_num, err_msg)

xsel - FileNotFoundError: [Errno 2] No such file or directory: 'xsel'
  File "/usr/lib/python3.6/site-packages/kivy/core/__init__.py", line 59, in core_select_lib
    fromlist=[modulename], level=0)
  File "/usr/lib/python3.6/site-packages/kivy/core/clipboard/clipboard_xsel.py", line 16, in <module>
    p = subprocess.Popen(['xsel'], stdout=subprocess.PIPE)
  File "/usr/lib/python3.6/subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1333, in _execute_child
    raise child_exception_type(errno_num, err_msg)

[WARNING] [MDBottomNavigation] 50.0dp is less than the minimum size of 80dp for a MDBottomNavigationItem. We must now expand to 168dp.
[WARNING] [MDBottomNavigation] 33.333333333333336dp is less than the minimum size of 80dp for a MDBottomNavigationItem. We must now expand to 168dp.
[INFO   ] [Base        ] Start application main loop
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[INFO   ] [Base        ] Leaving application in progress...
[Finished in 7.724s]

Upvotes: 0

Views: 3041

Answers (2)

biendltb
biendltb

Reputation: 1249

This bug still persists in MDRaisedButton of KivyMD. A simple workaround to solve it is using size_hint instead of size_hint_x.

For example in your case, replace

MDRaisedButton:
    size_hint_x: 1

by

MDRaisedButton:
    size_hint: 1., None

Upvotes: 1

Rahul
Rahul

Reputation: 31

This works for me Try not to change MDRaisedButton size_hint to 1 it raised this clock error , my suggestion is not to change any kivymd button size_hint it is by default None rather you can change size in dp

Upvotes: 3

Related Questions