Skip to content

Commit

Permalink
python: Spreadsheet: *.py: Fix python3 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
plaes authored and wwmayer committed Feb 18, 2017
1 parent b115d79 commit f9cb89a
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions src/Mod/Spreadsheet/App/Spreadsheet_legacy.py
Expand Up @@ -232,7 +232,7 @@ def __repr__(self):
def __setattr__(self, key, value):
if self.isKey(key):
key = key.lower()
if DEBUG: print "Setting key ",key," to value ",value
if DEBUG: print("Setting key ",key," to value ",value)
if (value == "") or (value == None):
# remove cell
if key in self._cells.keys():
Expand Down Expand Up @@ -261,7 +261,7 @@ def __getattr__(self, key):
try:
e = self.evaluate(key)
except:
print "Spreadsheet: Error evaluating formula"
print("Spreadsheet: Error evaluating formula")
return None
else:
return e
Expand Down Expand Up @@ -432,17 +432,17 @@ def evaluate(self,key):
if self.isNumeric(e):
result += str(self.evaluate(e))
else:
print "Spreadsheet: Error evaluating formula"
print("Spreadsheet: Error evaluating formula")
return
elif self.isNumeric(e):
result += str(self._cells[e.lower()])
else:
result += e
if DEBUG: print "Evaluating ",result
if DEBUG: print("Evaluating ",result)
try:
p = MathParser(result)
result = p.getValue()
except Exception as (ex):
except Exception as ex:
raise #
#msg = ex.message
#raise Exception(msg) #would discard the type
Expand Down Expand Up @@ -605,7 +605,7 @@ def setCells(self,obj,spreadsheet):
try:
setattr(spreadsheet.Proxy,obj.BaseCell,len(dataset))
except:
print "Spreadsheet: Error counting objects"
print("Spreadsheet: Error counting objects")
elif obj.Data:
for i in range(len(dataset)):
# get the correct cell key
Expand All @@ -618,13 +618,13 @@ def setCells(self,obj,spreadsheet):
else:
r = int(r) + i
cell = c+str(r)
if DEBUG: print "auto setting cell ",cell
if DEBUG: print("auto setting cell ",cell)
if spreadsheet.Proxy.isKey(cell):
# get the contents
args = obj.Data.split(".")
value = dataset[i]
for arg in args:
print arg
print(arg)
if hasattr(value,arg):
value = getattr(value,arg)
try:
Expand All @@ -634,9 +634,9 @@ def setCells(self,obj,spreadsheet):
value = str(value)
value = ''.join([ c for c in value if c not in ('<','>',':')])
setattr(spreadsheet.Proxy,cell,value)
if DEBUG: print "setting cell ",cell," to value ",value
if DEBUG: print("setting cell ",cell," to value ",value)
except:
print "Spreadsheet: Error retrieving property "+obj.Data+" from object "+dataset[i].Name
print("Spreadsheet: Error retrieving property "+obj.Data+" from object "+dataset[i].Name)


class ViewProviderSpreadsheetController:
Expand Down Expand Up @@ -671,7 +671,7 @@ def compute(self,obj):
try:
value = getattr(sp.Proxy,obj.Cell)
except:
if DEBUG: print "No value for cell ",obj.Cell," in spreadsheet."
if DEBUG: print("No value for cell ",obj.Cell," in spreadsheet.")
return
if obj.TargetType == "Property":
b = obj.TargetObject
Expand All @@ -685,9 +685,9 @@ def compute(self,obj):
try:
setattr(b,p,value)
FreeCAD.ActiveDocument.recompute()
if DEBUG: print "setting property ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value
if DEBUG: print("setting property ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value)
except:
if DEBUG: print "unable to set property ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value
if DEBUG: print("unable to set property ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value)
else:
if Draft.getType(obj.TargetObject) == "Sketch":
if obj.TargetProperty.isdigit():
Expand All @@ -696,17 +696,17 @@ def compute(self,obj):
c = int(obj.TargetProperty)
obj.TargetObject.setDatum(c,float(value))
FreeCAD.ActiveDocument.recompute()
if DEBUG: print "setting constraint ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value
if DEBUG: print("setting constraint ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value)
except:
if DEBUG: print "unable to set constraint ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value
if DEBUG: print("unable to set constraint ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value)
else:
# try setting by constraint name
try:
obj.TargetObject.setDatum(obj.TargetProperty,float(value))
FreeCAD.ActiveDocument.recompute()
if DEBUG: print "setting constraint ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value
if DEBUG: print("setting constraint ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value)
except:
if DEBUG: print "unable to set constraint ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value
if DEBUG: print("unable to set constraint ",obj.TargetProperty, " of object ",obj.TargetObject.Name, " to ",value)


def __getstate__(self):
Expand Down Expand Up @@ -785,7 +785,7 @@ def __init__(self,spreadsheet=None):
QtCore.QObject.connect(self.computeButton, QtCore.SIGNAL("clicked()"), self.recompute)

def closeEvent(self, event):
#if DEBUG: print "Closing spreadsheet view"
#if DEBUG: print("Closing spreadsheet view")
if self.spreadsheet:
# before deleting this view, we remove the reference to it in the object
if hasattr(self.spreadsheet,"ViewObject"):
Expand All @@ -811,7 +811,7 @@ def update(self):
self.doNotChange = True
if content == None:
content = ""
if DEBUG: print "Updating ",cell," to ",content
if DEBUG: print("Updating ",cell," to ",content)
if self.table.item(r,c):
self.table.item(r,c).setText(str(content))
else:
Expand All @@ -834,20 +834,20 @@ def update(self):
def changeCell(self,r,c,value=None):
"changes the contens of a cell"
if self.doNotChange:
if DEBUG: print "DoNotChange flag is set"
if DEBUG: print("DoNotChange flag is set")
self.doNotChange = False
elif self.spreadsheet:
key = "abcdefghijklmnopqrstuvwxyz"[c]+str(r+1)
if value == None:
value = self.table.item(r,c).text()
if value == "":
if DEBUG: print "Wiping "+key
if DEBUG: print("Wiping "+key)
if self.table.item(r,c):
self.table.item(r,c).setText("")
if key in self.spreadsheet.Proxy._cells.keys():
del self.spreadsheet.Proxy._cells[key]
else:
if DEBUG: print "Changing "+key+" to "+value
if DEBUG: print("Changing "+key+" to "+value)
# store the entry as best as possible
try:
v = int(value)
Expand All @@ -870,7 +870,7 @@ def setEditLine(self,r,c,orr=None,orc=None):
if self.spreadsheet:
c = "abcdefghijklmnopqrstuvwxyz"[c]
r = r+1
if DEBUG: print "Active cell "+c+str(r)
if DEBUG: print("Active cell "+c+str(r))
from DraftTools import translate
self.label.setText(str(translate("Spreadsheet","Cell"))+" "+c.upper()+str(r)+" :")
content = self.spreadsheet.Proxy.getFunction(c+str(r))
Expand All @@ -881,13 +881,13 @@ def setEditLine(self,r,c,orr=None,orc=None):
def getEditLine(self):
"called when something has been entered in the edit line"
txt = str(self.lineEdit.text())
if DEBUG: print "Text edited ",txt
if DEBUG: print("Text edited ",txt)
r = self.table.currentRow()
c = self.table.currentColumn()
self.changeCell(r,c,txt)

def wipeCell(self):
if DEBUG: print "Wiping cell"
if DEBUG: print("Wiping cell")
self.lineEdit.setText("")
self.getEditLine()

Expand Down Expand Up @@ -1070,7 +1070,7 @@ def read(filename):
cn = 0
for c in row[:26]:
cl = "abcdefghijklmnopqrstuvwxyz"[cn]
#print "setting ",cl+str(rn)," ",c
#print("setting ",cl+str(rn)," ",c)
try:
c = int(c)
except ValueError:
Expand All @@ -1081,21 +1081,21 @@ def read(filename):
setattr(sp.Proxy,cl+str(rn),c)
cn += 1
rn += 1
print "successfully imported ",filename
print("successfully imported ",filename)


def export(exportList,filename):
"called when freecad exports a csv file"
import csv, Draft
if not exportList:
print "Spreadsheet: Nothing to export"
print("Spreadsheet: Nothing to export")
return
obj = exportList[0]
if Draft.getType(obj) != "Spreadsheet":
print "Spreadhseet: The selected object is not a spreadsheet"
print("Spreadhseet: The selected object is not a spreadsheet")
return
if not obj.Proxy._cells:
print "Spreadsheet: The selected spreadsheet contains no cell"
print("Spreadsheet: The selected spreadsheet contains no cell")
return
numcols = ("abcdefghijklmnopqrstuvwxyz".index(str(obj.Proxy.cols[-1])))+1
numrows = int(obj.Proxy.rows[-1])
Expand All @@ -1110,7 +1110,7 @@ def export(exportList,filename):
else:
r.append("")
csvfile.writerow(r)
print "successfully exported ",filename
print("successfully exported ",filename)


#FreeCADGui.addCommand('Spreadsheet_Create',_Command_Spreadsheet_Create())
Expand Down

0 comments on commit f9cb89a

Please sign in to comment.