简体   繁体   中英

Python + Kivy Interface with custom functions

I'm trying to build an interface for an script that I wrote which handles automatic replies to users based on a ticket they submit.

I'm encountering errors when I try to convert my functions for use in the app.

The code that isn't working properly is as follows,

class MyApp(App):

    o = win32.gencache.EnsureDispatch("Outlook.Application").GetNamespace("MAPI")
    ol = win32.Dispatch('outlook.application')

    def sf(self):

        folders = self.o.Folders
        tardir = self.root.ids.label.main_inbox

        for folder in folders:
            if folder.Name == tardir:
                return folder
            folderMatch = self.sf()
            if folderMatch:
                return folderMatch

I get the following error:

Traceback (most recent call last):
   File "_ctypes/callbacks.c", line 234, in 'calling callback function'
   File "C:\Python\Python36-32\lib\site-packages\kivy\input\providers\wm_touch.py", line 127, in _touch_wndProc
     lParam)
 ctypes.ArgumentError: argument 3: <class 'RecursionError'>: maximum recursion depth exceeded while calling a Python object

The function from my original code, pre-interface is as follows

def sf(folders, tardir):    
    for folder in folders:  # if `folder` follows python convention, it should be iterable.
        if folder.Name == tardir: # is it the correct folder?
            return folder 
        folderMatch = sf(folder.Folders, tardir)  # recurse into child folders
        if folderMatch: 
            # return result from recursive call of sf() if successful
            return folderMatch

Any help would be greatly appreciated... I'm rather lost.

****EDIT AFTER SUGGESTED ANSWER****

I implemented this change, and when trying to use the function I get the error stating that

 Traceback (most recent call last):
   File "C:\Python\Python36\emailBotInterface.py", line 175, in <module>
     MyApp().run()
   File "C:\Python\Python36\lib\site-packages\kivy\app.py", line 802, in run
     root = self.build()
   File "C:\Python\Python36\emailBotInterface.py", line 108, in build
     label.unhandled_requests = self.config.get(get_folderMatch())
 NameError: name 'get_folderMatch' is not defined

I tried using the function in this manner:

def build(self):
        """
        Build and return the root widget.
        """

        # The line below is optional. You could leave it out or use one of the
        # standard options, such as SettingsWithSidebar, SettingsWithSpinner
        # etc.
        self.settings_cls = MySettingsWithTabbedPanel

        # We apply the saved configuration settings or the defaults
        root = Builder.load_string(kv)
        label = root.ids.label
        label.main_inbox = self.config.get('Mail Config', 'main_inbox')
        label.comments_folder = self.config.get('Mail Config', 'comments_folder')
        label.excess_folder = self.config.get('Mail Config', 'excess_folder')
        label.search_string = self.config.get('Mail Config', 'search_string')
        label.unhandled_requests = self.config.get(MyApp.get_folderMatch())

        return root

The below code was provided by eyllanesc which helped in finding the issue. Instead of trying to use self.config.get(get_folderMatch()) I realized that I don't need to display this configuration. So, I just created the attribute for label and assigned like so, label.unhandled_requests = self.get_folderMatch(label.main_inbox) and everything works great.

@staticmethod
def sf(folders, tardir):    
    for folder in folders:  # if `folder` follows python convention, it should be iterable.
        if folder.Name == tardir: # is it the correct folder?
            return folder 
        folderMatch = MyApp.sf(folder.Folders, tardir)  # recurse into child folders
        if folderMatch: 
            # return result from recursive call of sf() if successful
            return folderMatch

def get_folderMatch(self, tardir):
    folderMatch = MyApp.sf(MyApp.o.Folders, self.root.ids.label.main_inbox)
    return folderMatch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM