Bläddra i källkod

wxGUI: Replace getchildren and getiterator from ElementTree (#1120)

Element.getchildren() and getiterator() are deprecated
since Python version 3.2 and removed in version 3.9.

Using simpler replacements list(), in, and iter().

Fixes #1119.
Vaclav Petras 4 år sedan
förälder
incheckning
e162721437

+ 5 - 6
gui/wxpython/core/toolboxes.py

@@ -413,7 +413,7 @@ def _expandToolboxes(node, toolboxes):
             continue
             continue
         for subtoolbox in n.findall('./items/subtoolbox'):
         for subtoolbox in n.findall('./items/subtoolbox'):
             items = n.find('./items')
             items = n.find('./items')
-            idx = items.getchildren().index(subtoolbox)
+            idx = list(items).index(subtoolbox)
 
 
             if has_xpath:
             if has_xpath:
                 toolbox = toolboxes.find(
                 toolbox = toolboxes.find(
@@ -450,7 +450,7 @@ def _expandUserToolboxesItem(node, toolboxes):
 
 
     for n in node.findall('./items/user-toolboxes-list'):
     for n in node.findall('./items/user-toolboxes-list'):
         items = node.find('./items')
         items = node.find('./items')
-        idx = items.getchildren().index(n)
+        idx = list(items).index(n)
         el = etree.Element(
         el = etree.Element(
             'toolbox', attrib={
             'toolbox', attrib={
                 'name': 'GeneratedUserToolboxesList'})
                 'name': 'GeneratedUserToolboxesList'})
@@ -531,7 +531,7 @@ def _expandAddonsItem(node):
     for n in addonsTags:
     for n in addonsTags:
         # find parent is not possible with implementation of etree (in 2.7)
         # find parent is not possible with implementation of etree (in 2.7)
         items = node.find('./menubar')
         items = node.find('./menubar')
-        idx = items.getchildren().index(n)
+        idx = list(items).index(n)
         # do not set name since it is already in menudata file
         # do not set name since it is already in menudata file
         # attib={'name': 'AddonsList'}
         # attib={'name': 'AddonsList'}
         el = etree.Element('menu')
         el = etree.Element('menu')
@@ -570,9 +570,8 @@ def _expandItems(node, items, itemTag):
 
 
         if moduleNode is None:  # module not available in dist
         if moduleNode is None:  # module not available in dist
             continue
             continue
-        mItemChildren = moduleItem.getchildren()
-        tagList = [n.tag for n in mItemChildren]
-        for node in moduleNode.getchildren():
+        tagList = [n.tag for n in moduleItem]
+        for node in moduleNode:
             if node.tag not in tagList:
             if node.tag not in tagList:
                 moduleItem.append(node)
                 moduleItem.append(node)
 
 

+ 1 - 1
gui/wxpython/core/workspace.py

@@ -209,7 +209,7 @@ class ProcessWorkspaceFile:
         :param node: display tree node
         :param node: display tree node
         :param inGroup: in group -> index of group item otherwise -1
         :param inGroup: in group -> index of group item otherwise -1
         """
         """
-        for item in node.getchildren():
+        for item in node:
             if item.tag == 'group':
             if item.tag == 'group':
                 # -> group
                 # -> group
                 self.layers.append({
                 self.layers.append({

+ 2 - 2
gui/wxpython/tools/update_menudata.py

@@ -73,12 +73,12 @@ def updateData(data, modules):
               'vcolors']
               'vcolors']
 
 
     menu_modules = list()
     menu_modules = list()
-    for node in data.tree.getiterator():
+    for node in data.tree.iter():
         if node.tag != 'menuitem':
         if node.tag != 'menuitem':
             continue
             continue
 
 
         item = dict()
         item = dict()
-        for child in node.getchildren():
+        for child in node:
             item[child.tag] = child.text
             item[child.tag] = child.text
 
 
         if 'command' not in item:
         if 'command' not in item: