不明白wxPython ids [英] Don't understand wxPython ids

查看:91
本文介绍了不明白wxPython ids的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经决定学习wxPython了,而且我害怕我只是没有/ b $ b grok整个id你需要拉出独特的东西

整数出你的,呃,空气,然后用它们来参考物品:


来自w wyPython wiki示例:


self.button = wxButton(self,10," Save",wxPoint(200,325))

EVT_BUTTON(自我,10,自我。单击)


10是否具有除句柄之外的任何功能

允许您引用自己。 EVT *电话中的按钮?


您应该只为对象组成唯一的ID号

当a)他们已经有了唯一的身份证号码[至少id

内置认为如此]和b)他们的名字使得物品更具可读性?


这感觉非常适合。不,它比汇编语言更糟糕,因为即使汇编语言也有标签和

符号。


为什么不是这个:


self.button = wxButton(自我,10,保存,wxPoint(200,325))

EVT_BUTTON(自我,自我) .button,self.OnClick)


或者更好的是:


self.button = wxButton(self,10," Save" ,wxPoint(200,325),action = self.OnClick)


这最后一种方式看起来非常直观......


有人可以提供线索我介绍了

progrmmer为对象生成的整数id号的优点?


-

Grant Edwards grante Yow !现在,KEN和BARBIE

永久性地加上

visi.com MIND-ALTERING DUGING ......

解决方案

格兰特爱德华兹写道:

我已经决定学习wxPython,而且我害怕我只是没有完全理解整个id。你必须从你的,呃,空气中拉出独特的整数,然后用它们来指代对象:

来自wxPython wiki示例:

self.button = wxButton(自我,10,保存,wxPoint(200,325))
EVT_BUTTON(自我,10,自我。单击)

除了作为一个句柄之外,10还有什么功能可以让你在EVT *调用中引用self.button?


AFAIK,是的。但话说回来,我不知道多少。请注意,您可以使用-1

作为ID,该按钮将为您创建自己唯一的ID。然后

所有你需要做的就是调用button.GetId(),只要你需要它。

你应该只为对象组成唯一的id号码/>当a)他们已经有了唯一的身份证号码[至少内部认为是这样的身份]和b)他们的名字会使事情更具可读性吗?

这感觉非常适合。不,它甚至比汇编语言更糟糕,因为即使汇编语言也有标签和
符号。

为什么不这样:

自我.button = wxButton(self,10," Save",wxPoint(200,325))
EVT_BUTTON(self,self.button,self.OnClick)

或者更好的是:

self.button = wxButton(self,10," Save",wxPoint(200,325),action = self.OnClick)

这最后一种方式看起来非常直观...

有人能否告诉我
progrmmer为对象生成的整数id号的优点?




在新的wxPython(2.5.1.5)中,使用widget.Bind可以更轻松地绑定事件

而不使用id。这样​​:


import wx


class MyFrame(wx.Frame):

def __init __(self,* args,** kwargs):

wx.Frame .__ init __(self,* args,** kwargs)


self.button = wx.Button(self,-1," What's's my ID?&q uot;)

self.button.Bind(wx.EVT_BUTTON,self.OnButtonPress)

def OnButtonPress(self,event):

self.button.SetLabel(" My id is:%d" %self.button.GetId())

app = wx.App()

frame = MyFrame(None,-1," Events and ids")

frame.Show(True)

app.MainLoop()

我只能想到一个为什么他们选择使用ID在第一个

的地方。为同一个id分配许多对象允许您对这些对象使用一个EVT_ *

调用。但这真的是一个有用的功能吗?谁知道?


greg


文章< BO ************** **** @ newsread1.news.pas.earthlink .net>,Greg Krohn写道:

AFAIK,是的。但话说回来,我不知道多少。请注意,您可以使用-1
作为ID,按钮将为您创建自己唯一的ID。那么你需要做的就是在需要的时候调用button.GetId()。


我知道,既然你提到了它,我想我几年前就回来了。
$ blockquote class = post_quotes>

有人能否告诉我
progrmmer为对象生成的整数id号的优点?



在新的wxPython中(2.5.1.5)有一种更简单的方法来绑定事件
而不使用任何使用widget的绑定。绑定,如下所示:

import wx

class MyFrame(wx.Frame):
def __init __(self,* args,** kwargs):
wx.Frame .__ init __(self,* args,** kwargs)

self.button = wx.Button(self,-1,我的id是什么?)
self.button.Bind(wx.EVT_BUTTON,self.OnButtonPress)




这绝对越来越接近我期望的

在过去15到20年间设计的东西,尽管通过了

绑定作为wx.Button()的参数肯定似乎是li对于我遇到的90%的案例来说,这是一个明显的解决方案。也许我已经习惯了bk b。

我只能想到为什么他们选择在第一个地方使用id的原因。分配许多具有相同ID的对象允许您对这些对象使用一个EVT_ *
调用。但这真的是一个有用的功能吗?谁知道?




这是我唯一能想到的。在我想要做某些事情的几个

的情况下我会很高兴地在一个对象列表中进行for循环迭代/>
交换能够使用单行代码另外

90%的时间。


-

格兰特爱德华兹格兰特哇!我很年轻......我是健康的... b $ b我可以HIKE

visi.com THRU CAPT GROGAN''LUMBAR

REGIONS!


我只能想到一个为什么他们选择使用ID在第一个
的地方。分配许多具有相同ID的对象允许您对这些对象使用一个EVT_ *
调用。但这真的是一个有用的功能吗?谁知道?



这是我唯一能想到的。在我想要做的事情的几个情况下,我很乐意在
交换中对一个对象列表进行for循环迭代以便能够使用单线代码另一方面90%的时间。




对,设计事件时需要考虑几个特殊情况 gui工具包的
绑定。一个是你想要多个控件的地方

共享同一个事件处理程序(比如一个按钮和一个菜单项,它可以做同样的事情)。另一种情况是允许人们在调用窗口构造函数并设置

窗口后更改事件绑定

动态。


我提出了一些与你类似的变化,请看这个帖子:
http://lists.wxwidgets.org/cgi-bin/e...kojpgmpdpmio#b

但没有任何结果。我为Wax编写了一个实现代码
http ://wiki.wxpython.org/index.cgi/Wax ),但我不知道是否包含了



I''ve decided to learn wxPython, and I''m afraid I just don''t
grok the whole "id" thing where you have to pull unique
integers out of your, er, the air and then use those to refer
to objects:

From whe wxPython wiki examples:

self.button =wxButton(self, 10, "Save", wxPoint(200, 325))
EVT_BUTTON(self, 10, self.OnClick)

Does the 10 have any function other than as a handle that
allows you to refer to self.button in the EVT* call?

You''re supposed to just make up unique id numbers for objects
when a) they''ve already got unique id numbers [at least the id
builtin thinks so] and b) they''ve got names that make things
even more readable?

This feels very assmebly-level. No, it''s even worse than
assembly language, since even assembly language has labels and
symbols.

Why not this:

self.button =wxButton(self, 10, "Save", wxPoint(200, 325))
EVT_BUTTON(self, self.button, self.OnClick)

Or better yet this:

self.button =wxButton(self, 10, "Save", wxPoint(200, 325), action=self.OnClick)

This last way seems pretty intuitive...

Can somebody clue me in on the advantages of the
progrmmer-generated integer id numbers for objects?

--
Grant Edwards grante Yow! Now KEN and BARBIE
at are PERMANENTLY ADDICTED to
visi.com MIND-ALTERING DRUGS...

解决方案

Grant Edwards wrote:

I''ve decided to learn wxPython, and I''m afraid I just don''t
grok the whole "id" thing where you have to pull unique
integers out of your, er, the air and then use those to refer
to objects:

From whe wxPython wiki examples:

self.button =wxButton(self, 10, "Save", wxPoint(200, 325))
EVT_BUTTON(self, 10, self.OnClick)

Does the 10 have any function other than as a handle that
allows you to refer to self.button in the EVT* call?
AFAIK, yes. But then again, I don''t know much. Note that you can use -1
as the id and the button will create it''s own unique id for you. Then
all you have to do is call button.GetId() whenever you need it.
You''re supposed to just make up unique id numbers for objects
when a) they''ve already got unique id numbers [at least the id
builtin thinks so] and b) they''ve got names that make things
even more readable?

This feels very assmebly-level. No, it''s even worse than
assembly language, since even assembly language has labels and
symbols.

Why not this:

self.button =wxButton(self, 10, "Save", wxPoint(200, 325))
EVT_BUTTON(self, self.button, self.OnClick)

Or better yet this:

self.button =wxButton(self, 10, "Save", wxPoint(200, 325), action=self.OnClick)

This last way seems pretty intuitive...

Can somebody clue me in on the advantages of the
progrmmer-generated integer id numbers for objects?



In the new wxPython (2.5.1.5) there''s an easier way to bind events
without using ids at all using widget.Bind, like this:

import wx

class MyFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)

self.button = wx.Button(self, -1, "What''s my id?")
self.button.Bind(wx.EVT_BUTTON, self.OnButtonPress)

def OnButtonPress(self, event):
self.button.SetLabel("My id is: %d" % self.button.GetId())
app = wx.App()
frame = MyFrame(None, -1, "Events and ids")
frame.Show(True)
app.MainLoop()

I can only think of one reasn why they chose to use ids in the first
place. Assigning many objects the same id allows you to use one EVT_*
call for those objects. But is that really a useful feature? Who knows?

greg


In article <BO******************@newsread1.news.pas.earthlink .net>, Greg Krohn wrote:

AFAIK, yes. But then again, I don''t know much. Note that you can use -1
as the id and the button will create it''s own unique id for you. Then
all you have to do is call button.GetId() whenever you need it.
Ya know, now that you mention it, I think I actually new that
once a couple years back.

Can somebody clue me in on the advantages of the
progrmmer-generated integer id numbers for objects?



In the new wxPython (2.5.1.5) there''s an easier way to bind events
without using ids at all using widget.Bind, like this:

import wx

class MyFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)

self.button = wx.Button(self, -1, "What''s my id?")
self.button.Bind(wx.EVT_BUTTON, self.OnButtonPress)



That''s definitely getting closer to what I would expect in
something designed in the last 15-20 years, though passing the
binding as a parameter to wx.Button() sure seems like the
obvious solution for 90% of the cases I run into. Perhaps I''m
too used to Tk.
I can only think of one reasn why they chose to use ids in the first
place. Assigning many objects the same id allows you to use one EVT_*
call for those objects. But is that really a useful feature? Who knows?



That''s about the only thing I could think of. The few
situations where I''d have wanted to do someting like that I''d
gladly put a for-loop iterating over a list of objects in
exchange for being able to use single-line of code the other
90% of the time.

--
Grant Edwards grante Yow! I''m young... I''m
at HEALTHY... I can HIKE
visi.com THRU CAPT GROGAN''S LUMBAR
REGIONS!


I can only think of one reasn why they chose to use ids in the first
place. Assigning many objects the same id allows you to use one EVT_*
call for those objects. But is that really a useful feature? Who knows?


That''s about the only thing I could think of. The few
situations where I''d have wanted to do someting like that I''d
gladly put a for-loop iterating over a list of objects in
exchange for being able to use single-line of code the other
90% of the time.



Right, there a couple of special cases to think of when designing event
bindings for a gui toolkit. One is where you want multiple controls to
share the same event handler (like a button and a menu item that do the
same thing). Another case is allowing people to change event bindings
"on the fly", after a window constructor has already been called and the
window set up.

I proposed some changes similar to you, see this thread:
http://lists.wxwidgets.org/cgi-bin/e...kojpgmpdpmio#b
but nothing came out of it. I did code up an implementation for Wax
(http://wiki.wxpython.org/index.cgi/Wax ), but I don''t know if it was
included.


这篇关于不明白wxPython ids的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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