Refactored use of iteritems into function to deal with python 2.7 and 3 compatibility.

This commit is contained in:
Markus Lampert
2017-10-22 18:18:10 -07:00
parent bba9499f48
commit d52fc9ef84
6 changed files with 15 additions and 7 deletions

View File

@@ -29,8 +29,9 @@ import math
import Part
import Path
import PathScripts.PathLog as PathLog
import PathScripts.PathUtil as PathUtil
import PathScripts.PathUtils as PathUtils
from PathScripts import PathUtils
from PathScripts.PathGeom import PathGeom
from PySide import QtCore, QtGui
@@ -852,7 +853,7 @@ class TaskPanel:
def updateBoneList(self):
itemList = []
for loc, (enabled, inaccessible, ids) in self.obj.Proxy.boneStateList(self.obj).iteritems():
for loc, (enabled, inaccessible, ids) in PathUtil.keyValueIter(self.obj.Proxy.boneStateList(self.obj)):
lbl = '(%.2f, %.2f): %s' % (loc[0], loc[1], ','.join(str(id) for id in ids))
item = QtGui.QListWidgetItem(lbl)
if enabled:

View File

@@ -28,6 +28,7 @@ import Path
import PathScripts
import PathScripts.PathLog as PathLog
import PathScripts.PathPreferencesPathDressup as PathPreferencesPathDressup
import PathScripts.PathUtil as PathUtil
import PathScripts.PathUtils as PathUtils
import copy
import math
@@ -585,7 +586,7 @@ class PathData:
tags = []
for (i, count) in edgeDict.iteritems():
for (i, count) in PathUtil.keyValueIter(edgeDict):
edge = self.baseWire.Edges[i]
PathLog.debug(" %d: %d" % (i, count))
#debugMarker(edge.Vertexes[0].Point, 'base', (1.0, 0.0, 0.0), 0.2)

View File

@@ -61,7 +61,7 @@ class Template:
def _traverseTemplateAttributes(attrs, codec):
coded = {}
for key,value in attrs.iteritems():
for key,value in PathUtil.keyValueIter(attrs):
if type(value) == dict:
PathLog.debug("%s is a dict" % key)
coded[key] = _traverseTemplateAttributes(value, codec)

View File

@@ -165,7 +165,7 @@ class ToolLibraryManager():
def tooltableFromAttrs(self, stringattrs):
if stringattrs.get('Version') and 1 == int(stringattrs['Version']):
attrs = {}
for key, val in stringattrs['Tools'].iteritems():
for key, val in PathUtil.keyValueIter(stringattrs['Tools']):
attrs[int(key)] = val
return Path.Tooltable(attrs)
else:
@@ -235,7 +235,7 @@ class ToolLibraryManager():
if tt:
if len(tt.Tools) == 0:
tooldata.append([])
for number, t in tt.Tools.iteritems():
for number, t in PathUtil.keyValueIter(tt.Tools):
itemcheck = QtGui.QStandardItem()
itemcheck.setCheckable(True)

View File

@@ -112,3 +112,8 @@ def isString(string):
return True
return False
def keyValueIter(dictionary):
'''keyValueIter(dict) ... return iterable object over dictionary's (key,value) tuples.'''
if sys.version_info.major < 3:
return dictionary.iteritems()
return dictionary.items()

View File

@@ -48,6 +48,7 @@ Many other OpenSBP commands not handled
'''
from __future__ import print_function
import FreeCAD
import PathScripts.PathUtil as PathUtil
import os, Path
AXIS = 'X','Y','Z','A','B' #OpenSBP always puts multiaxis move parameters in this order
@@ -145,7 +146,7 @@ def parse(inputstring):
last[words[0][1]] = words[1]
output += s
for key, val in last.iteritems():
for key, val in PathUtil.keyValueIter(last):
if val is not None:
output += key + str(val) + " F" + speed + "\n"