简体   繁体   English

如果从xrc加载,wxpython中的自动完成功能

[英]Autocomplete in wxpython if load from xrc

I am trying to work with xrc resource in wxpython. 我正在尝试使用wxpython中的xrc资源。 It is good but where is one big "no" - there is no autocomplete of wxFrame class loadet from xrc. 很好,但是哪里有个大“否”-从xrc没有自动完成wxFrame类加载的完成。 And other loaded from xrc classes too. 其他也从xrc类加载。

Is this right or I'am doing somthing wgong? 这是正确的,还是我在做某事?

here is the part of code for example: 例如,这是代码的一部分:

import wx
from wx import xrc

class MyApp(wx.App):
    def OnInit(self):
        if os.path.exists("phc.xrc"):
            self.res = xrc.XmlResource("phc.xrc")

            self.frame = self.res.LoadFrame(None, 'MyFrame')
            self.list_box = xrc.XRCCTRL(self.frame, "list_box_1")
            self.notebook = xrc.XRCCTRL(self.frame, "Notebook")
            self.StatusBar= xrc.XRCCTRL(self.frame, "MFrame_statusbar")
            self.list_ctrl= xrc.XRCCTRL(self.frame, "list_ctr_1")

Well, how good the autocomplete function is depends entirely on the editor/IDE that you are using. 好吧,自动完成功能的好坏完全取决于您使用的编辑器/ IDE。 You didn't specify what you are using to write python scripts, but from personal experience I would say that it is probably true, that there is no autocomplete. 您没有指定用于编写python脚本的内容,但是根据个人经验,我会说这可能是对的,没有自动完成功能。

I've used Eclipse/PyDev, Spyder, SPE and PyCharm in the past and they all did not show an ability to autocomplete widgets created with XRC. 我过去使用过Eclipse / PyDev,Spyder,SPE和PyCharm,但它们都没有显示自动完成XRC创建的小部件的功能。 You could still try to get the Emacs autocomplete for Python to work and try it there, but I doubt it'll work. 您仍然可以尝试使Emacs自动完成功能可以在Python上运行并在那里进行尝试,但是我怀疑它是否可以正常工作。

I did not find this a particular hindrance, but everyone's different, I guess. 我没有发现这是一个特殊的障碍,但是我想每个人都不一样。 Hopefully, that answers your question. 希望能回答您的问题。

Yes autocomplete wouldn't work here since our code doesn't know what the xrc is going to return. 是的,因为我们的代码不知道xrc将返回什么,所以自动完成功能在这里不起作用。 Your code gets to know about the type of variable (in this case, frame) only during runtime. 您的代码仅在运行时才了解变量的类型(在这种情况下为帧)。

And, unfortunately/fortunately, we cannot assign 'type' to a variable in Python for the autocompletion to work. 而且,不幸的是,我们无法为Python中的变量分配“类型”以使自动补全功能起作用。

But in Eclipse + PyDev plugin 但是在Eclipse + PyDev插件中

you can add this statement for autocomplete to work: 您可以添加以下语句以使自动完成功能起作用:

assert isinstance(self.frame, wx.Frame) 断言isinstance(self.frame,wx.Frame)

autocomplete works after this statement. 此语句之后,自动完成功能将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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