邪恶,邪恶的wxPython(和一线希望) [英] Evil, evil wxPython (and a glimmer of hope)

查看:72
本文介绍了邪恶,邪恶的wxPython(和一线希望)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很少做GUI,今天提醒自己为什么会这样呢

(简单来说,这不好玩)。


我实施了一个简单的TreeCtrl,并且必须实现我自己的''孩子''

方法,所有的东西!


这是:
< br $>
def children(self,node):

c = []

nc,cookie = self.GetFirstChild(node)

而1:

info = self.GetItemText(nc)

c.append((info,nc))


nc,cookie = self.GetNextChild(节点,cookie)

如果不是nc.IsOk():

休息


返回c

甚至零孩子都失败了。这就像它得到的那样是unpythonic。


但是,在

wxPython api上编写小包装应该很容易。我正在考虑用Treectrl包装或注入额外的方法

,以小写字母开头,并用合理的方法返回一些合理的东西。类似的东西:


root = self.AddRoot(" root dir")#root是普通的wx TreeCtrl root

tree = EasyWx(root)#now树是我们的包裹,更有趣 root

for tree in tree.children():

print c.name


#等等。


这有点像Brian Orendorff的路径。模块可以将某些东西变成你可以轻松使用的东西,而不会让你陷入框架,工具包和诸如此类的世界。我可以看到有些东西像Bax或PythonCard一样,但是它们仍然太框架化了,而且你没有使用它们来扩展wxPython,你使用*他们*他们使用

wxPython。我基本上喜欢依赖

长途的东西(普通的wxPython API),但只在我的

自己的主动*上使用便利包装*,因为它看起来很方便。就像我会使用路径

模块一样。


wxPython很棒(因为它是一个C ++工具包的简单包装器)和

基本设计还可以。事实证明,我只是懒得以现在的

形式使用它。

I rarely do GUIs, and reminded myself today why that is the case
(simply, it''s not fun).

I implemented a simple TreeCtrl, and had to implement my own ''children''
method, of all things!

Here it is:

def children(self,node):
c = []
nc,cookie = self.GetFirstChild(node)
while 1:
info = self.GetItemText(nc)
c.append((info,nc))

nc, cookie= self.GetNextChild(node,cookie)
if not nc.IsOk():
break

return c
And it even fails with zero children. This is as unpythonic as it gets.

However, it should be pretty easy to write small wrapper over the
wxPython api. I''m thinking of wrapping or injecting additional methods
to TreeCtrl that start with lowercase letters and return something
sensible, with reasonable methods. Something like:

root = self.AddRoot("root dir") # root is normal wx TreeCtrl root
tree = EasyWx(root) # now tree is our wrapped, more "fun" root
for c in tree.children():
print c.name

# etc. etc.

This is a bit like Brian Orendorff''s "path" module that turns something
low level to something you can use easily, without throwing you into a
world of "frameworks", toolkits and whatnot. I can see there are things
like Wax or PythonCard, but they are still too "frameworky", and you
don''t use them to extend wxPython, you use *them* and they use
wxPython. I''d basically like to rely on something that is there for the
long haul (plain wxPython API) but only use convenience wrappers *on my
own initiative*, as it seems convenient. Just like I''d use the "path"
module.

wxPython is great as it is (a simple wrapper for a C++ toolkit) and the
basic design is ok & proven, I''m just too lazy to use it in its current
form.

推荐答案

正如你刚才所说,wxPython是...(一个C ++

工具包的简单包装器):它是面向C ++风格/思维模式的



As you just said, wxPython is "...(a simple wrapper for a C++
toolkit)": it is
oriented toward the C++ style/mindset.



vi ****** @ gmail.com 写道:
我很少做GUI,今天提醒自己为什么会这样呢
(简单来说,这不好玩)。

我实现了一个简单的TreeCtrl,并且必须实现我自己的''children''方法,所有的东西!

这里是:

def儿童(自我,节点):
c = []
nc,cookie = self.GetFirstChild(节点)
而1:
info = self.GetItemText(nc )
c.append((info,nc))

nc,cookie = self.GetNextChild(node,cookie)
如果不是nc.IsOk ():
打破

返回c

它甚至在零孩子的情况下也失败了。这就像它所获得的一样。但是,在
wxPython api上编写小包装应该很容易。我正在考虑用TreeCtrl包装或注入其他方法,这些方法以小写字母开头,并以合理的方法返回合理的东西。类似的东西:

root = self.AddRoot(" root dir")#root是普通的wx TreeCtrl root
tree = EasyWx(root)#the now tree is our wrapped,more有趣" root用于树中的c(。):
打印c.name

等等

这有点像Brian Orendorff 's路径模块可以将低级别的东西变成你可以轻松使用的东西,而不会让你陷入框架,工具包等诸如此类的世界。我可以看到有像Wax或PythonCard这样的东西,但它们仍然太框架化,而且你不使用它们来扩展wxPython,你使用*它们*它们使用< wxPython。我基本上喜欢依赖长期存在的东西(普通的wxPython API),但只在我自己的主动*上使用便利包装*,因为它看起来很方便。就像我使用路径模块一样。

wxPython非常棒(C ++工具包的简单包装)和
基本设计是好的&事实证明,我只是懒得以现在的形式使用它。
I rarely do GUIs, and reminded myself today why that is the case
(simply, it''s not fun).

I implemented a simple TreeCtrl, and had to implement my own ''children''
method, of all things!

Here it is:

def children(self,node):
c = []
nc,cookie = self.GetFirstChild(node)
while 1:
info = self.GetItemText(nc)
c.append((info,nc))

nc, cookie= self.GetNextChild(node,cookie)
if not nc.IsOk():
break

return c
And it even fails with zero children. This is as unpythonic as it gets.

However, it should be pretty easy to write small wrapper over the
wxPython api. I''m thinking of wrapping or injecting additional methods
to TreeCtrl that start with lowercase letters and return something
sensible, with reasonable methods. Something like:

root = self.AddRoot("root dir") # root is normal wx TreeCtrl root
tree = EasyWx(root) # now tree is our wrapped, more "fun" root
for c in tree.children():
print c.name

# etc. etc.

This is a bit like Brian Orendorff''s "path" module that turns something
low level to something you can use easily, without throwing you into a
world of "frameworks", toolkits and whatnot. I can see there are things
like Wax or PythonCard, but they are still too "frameworky", and you
don''t use them to extend wxPython, you use *them* and they use
wxPython. I''d basically like to rely on something that is there for the
long haul (plain wxPython API) but only use convenience wrappers *on my
own initiative*, as it seems convenient. Just like I''d use the "path"
module.

wxPython is great as it is (a simple wrapper for a C++ toolkit) and the
basic design is ok & proven, I''m just too lazy to use it in its current
form.




看看dabo,我想他们正在做正如你所描述的那样。
http:/ /blog.dabodev.com/



Take a look at dabo, II think they''re doing exactly what you''re
describing.
http://blog.dabodev.com/


snoe写道:
snoe wrote:
看看dabo ,我认为他们正在做的正是你所描述的。
http://blog.dabodev.com/
Take a look at dabo, II think they''re doing exactly what you''re
describing.
http://blog.dabodev.com/




Dabo似乎比我想要的方式更多,有数据库访问权限




我的理想模块在实现时会非常小,因为代码的大小是多少。我正在使用path.py作为例子:

http://www.jorendorff.com/articles/python/path/path.py

def dirs(self,pattern = None) :

""" D.dirs() - >此目录的子目录列表。

"""

如果p.isdir()]返回[p表示自我列表中的p(模式)



Dabo appear to be doing way more than what I want, with database access
etc.

My ideal module, when implemented, would be extremely small as far as
the size of code goes. I''m using path.py as an example:

http://www.jorendorff.com/articles/python/path/path.py

def dirs(self, pattern=None):
""" D.dirs() -> List of this directory''s subdirectories.
"""
return [p for p in self.listdir(pattern) if p.isdir()]


这篇关于邪恶,邪恶的wxPython(和一线希望)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆