开发者

xul menulist bug with pydom

i know pydom is deprecated .but my application already used this,this is so easy

my xul is like this.

<menulist name="mailencode" id="mailencode">
     <menupopup id="mailencodepop">
      <menuitem label="UTF-8" value="UTF-8" selected="true"/>
      <menuitem label="ISO-8859-1" value="ISO-8859-1" />
     </menupopup>
    </menulist>

in my python script

ecd=document.getElementById("mailencode")
print  ecd.selectedIndex

there is a exception,show me XPCOM component '' has no attribute selectedIndex

i want get the use开发者_如何学JAVA select value in the menulist

i also tired this,but the same exception

ecd=document.getElementById("mailencodepop")
print  ecd.selectedIndex

any idea? thanks


Your first problem is that the tag name you're after is "menulist". I used xml.dom.minidom to parse this just as a basic example to illustrate because I have never used PyDOM:

>>> ecd = document.getElementsByTagName('menulist')
[<DOM Element: menulist at 0x1006e2710>]
>>> ecd[0].tagName
u'menulist'
>>> ecd[0].attributes.items()
[(u'name', u'mailencode'), (u'id', u'mailencode')]

Then pull out the menulist tag on its own and then inspect its child nodes:

>>> menulist = ecd[0]
>>> menulist.childNodes
[<DOM Text node "u'\n     '">, <DOM Element: menupopup at 0x1006e29e0>, <DOM Text node "u'\n    '">]

And then inspect the menupop tag's child nodes:

>>> menulist.childNodes[1]
<DOM Element: menupopup at 0x1006e29e0>
>>> menulist.childNodes[1].childNodes
[<DOM Text node "u'\n      '">, <DOM Element: menuitem at 0x1006e2b90>, <DOM Text node "u'\n      '">, <DOM Element: menuitem at 0x1006e2ef0>, <DOM Text node "u'\n     '">]

There might be a better way, especially one using PyDOM. I just wanted to illustrate you need to be careful about the tag names you're after.


The selectedIndex attribute is implemented through XBL, and I don't know whether pydom can talk to XBL. Can you call QueryInterface to expose the nsIDOMXULMenuListElement interface?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜