具有自定义功能的Python + Kivy接口

时间:2018-04-13 14:20:13

标签: python python-3.x kivy

我正在尝试为我编写的脚本构建一个接口,该脚本根据用户提交的票据处理对用户的自动回复。

当我尝试将我的函数转换为在应用程序中使用时,我遇到了错误。

无效的代码如下,

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

我收到以下错误:

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

我原始代码的功能,预界面如下

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

非常感谢任何帮助......我很失落。

****在建议回答后编辑****

我实现了这个更改,当我尝试使用该函数时,我收到错误声明

 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

我尝试以这种方式使用该功能:

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

1 个答案:

答案 0 :(得分:0)

以下代码由eyllanesc提供,有助于发现问题。而不是尝试使用self.config.get(get_folderMatch())我意识到我不需要显示此配置。所以,我刚刚创建了label的属性,并像这样分配了label.unhandled_requests = self.get_folderMatch(label.main_inbox),一切都很好。

@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