Spreadsheet: removed automatic updating and added a compute button
This commit is contained in:
parent
aa5a2e1b3f
commit
2fa481379f
|
@ -325,7 +325,7 @@ class Spreadsheet:
|
||||||
co.Proxy.execute(co)
|
co.Proxy.execute(co)
|
||||||
|
|
||||||
def execute(self,obj):
|
def execute(self,obj):
|
||||||
self.setControlledCells(obj)
|
pass
|
||||||
|
|
||||||
def isFunction(self,key):
|
def isFunction(self,key):
|
||||||
"isFunction(cell): returns True if the given cell or value is a function"
|
"isFunction(cell): returns True if the given cell or value is a function"
|
||||||
|
@ -437,21 +437,23 @@ class Spreadsheet:
|
||||||
raise Exception(msg)
|
raise Exception(msg)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def setControlledCells(self,obj):
|
def recompute(self,obj):
|
||||||
"Fills the cells that are controlled by a controller"
|
"Fills the controlled cells and properties"
|
||||||
if obj:
|
if obj:
|
||||||
if hasattr(obj,"Controllers"):
|
if hasattr(obj,"Controllers"):
|
||||||
|
import Draft
|
||||||
for co in obj.Controllers:
|
for co in obj.Controllers:
|
||||||
import Draft
|
|
||||||
if Draft.getType(co) == "SpreadsheetController":
|
if Draft.getType(co) == "SpreadsheetController":
|
||||||
co.Proxy.setCells(co,obj)
|
co.Proxy.setCells(co,obj)
|
||||||
|
elif Draft.getType(co) == "SpreadsheetPropertyController":
|
||||||
|
co.Proxy.compute(co)
|
||||||
|
|
||||||
def getControlledCells(self,obj):
|
def getControlledCells(self,obj):
|
||||||
"returns a list of cells managed by controllers"
|
"returns a list of cells managed by controllers"
|
||||||
cells = []
|
cells = []
|
||||||
if hasattr(obj,"Controllers"):
|
if hasattr(obj,"Controllers"):
|
||||||
|
import Draft
|
||||||
for co in obj.Controllers:
|
for co in obj.Controllers:
|
||||||
import Draft
|
|
||||||
if Draft.getType(co) == "SpreadsheetController":
|
if Draft.getType(co) == "SpreadsheetController":
|
||||||
cells.extend(co.Proxy.getCells(co,obj))
|
cells.extend(co.Proxy.getCells(co,obj))
|
||||||
return cells
|
return cells
|
||||||
|
@ -460,8 +462,8 @@ class Spreadsheet:
|
||||||
"returns a list of controlling cells managed by controllers"
|
"returns a list of controlling cells managed by controllers"
|
||||||
cells = []
|
cells = []
|
||||||
if hasattr(obj,"Controllers"):
|
if hasattr(obj,"Controllers"):
|
||||||
|
import Draft
|
||||||
for co in obj.Controllers:
|
for co in obj.Controllers:
|
||||||
import Draft
|
|
||||||
if Draft.getType(co) == "SpreadsheetPropertyController":
|
if Draft.getType(co) == "SpreadsheetPropertyController":
|
||||||
if co.Cell:
|
if co.Cell:
|
||||||
cells.append(co.Cell.lower())
|
cells.append(co.Cell.lower())
|
||||||
|
@ -574,6 +576,7 @@ class SpreadsheetController:
|
||||||
# get the correct cell key
|
# get the correct cell key
|
||||||
c,r = spreadsheet.Proxy.splitKey(obj.BaseCell)
|
c,r = spreadsheet.Proxy.splitKey(obj.BaseCell)
|
||||||
if obj.Direction == "Horizontal":
|
if obj.Direction == "Horizontal":
|
||||||
|
c = c.lower()
|
||||||
c = "abcdefghijklmnopqrstuvwxyz".index(c)
|
c = "abcdefghijklmnopqrstuvwxyz".index(c)
|
||||||
c += i
|
c += i
|
||||||
c = "abcdefghijklmnopqrstuvwxyz"[c]
|
c = "abcdefghijklmnopqrstuvwxyz"[c]
|
||||||
|
@ -597,6 +600,7 @@ class SpreadsheetController:
|
||||||
# get the correct cell key
|
# get the correct cell key
|
||||||
c,r = spreadsheet.Proxy.splitKey(obj.BaseCell)
|
c,r = spreadsheet.Proxy.splitKey(obj.BaseCell)
|
||||||
if obj.Direction == "Horizontal":
|
if obj.Direction == "Horizontal":
|
||||||
|
c = c.lower()
|
||||||
c = "abcdefghijklmnopqrstuvwxyz".index(c)
|
c = "abcdefghijklmnopqrstuvwxyz".index(c)
|
||||||
c += i
|
c += i
|
||||||
c = "abcdefghijklmnopqrstuvwxyz"[c]
|
c = "abcdefghijklmnopqrstuvwxyz"[c]
|
||||||
|
@ -641,6 +645,9 @@ class SpreadsheetPropertyController:
|
||||||
obj.TargetType = ["Property","Constraint"]
|
obj.TargetType = ["Property","Constraint"]
|
||||||
|
|
||||||
def execute(self,obj):
|
def execute(self,obj):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def compute(self,obj):
|
||||||
if obj.Cell and obj.TargetObject and obj.TargetProperty and obj.InList:
|
if obj.Cell and obj.TargetObject and obj.TargetProperty and obj.InList:
|
||||||
sp = obj.InList[0]
|
sp = obj.InList[0]
|
||||||
import Draft
|
import Draft
|
||||||
|
@ -713,10 +720,25 @@ class SpreadsheetView(QtGui.QWidget):
|
||||||
self.horizontalLayout = QtGui.QHBoxLayout()
|
self.horizontalLayout = QtGui.QHBoxLayout()
|
||||||
self.label = QtGui.QLabel(self)
|
self.label = QtGui.QLabel(self)
|
||||||
self.label.setMinimumSize(QtCore.QSize(82, 0))
|
self.label.setMinimumSize(QtCore.QSize(82, 0))
|
||||||
self.label.setText(str(translate("Spreadsheet","Cell"))+" A1 :")
|
self.label.setText(translate("Spreadsheet","Cell")+" A1 :")
|
||||||
self.horizontalLayout.addWidget(self.label)
|
|
||||||
self.lineEdit = QtGui.QLineEdit(self)
|
self.lineEdit = QtGui.QLineEdit(self)
|
||||||
|
self.applyButton = QtGui.QPushButton(self)
|
||||||
|
self.applyButton.setText(translate("Spreadsheet","Apply"))
|
||||||
|
self.applyButton.setIcon(QtGui.QIcon(":/icons/edit_OK.svg"))
|
||||||
|
self.applyButton.setToolTip(translate("Spreadsheet","Apply the changes to the current cell"))
|
||||||
|
self.wipeButton = QtGui.QPushButton(self)
|
||||||
|
self.wipeButton.setText(translate("Spreadsheet","Delete"))
|
||||||
|
self.wipeButton.setIcon(QtGui.QIcon(":/icons/process-stop.svg"))
|
||||||
|
self.wipeButton.setToolTip(translate("Spreadsheet","Deletes the contents of the current cell"))
|
||||||
|
self.computeButton = QtGui.QPushButton(self)
|
||||||
|
self.computeButton.setText(translate("Spreadsheet","Compute"))
|
||||||
|
self.computeButton.setIcon(QtGui.QIcon(":/icons/view-refresh.svg"))
|
||||||
|
self.computeButton.setToolTip(translate("Spreadsheet","Updates the values handled by controllers"))
|
||||||
|
self.horizontalLayout.addWidget(self.label)
|
||||||
self.horizontalLayout.addWidget(self.lineEdit)
|
self.horizontalLayout.addWidget(self.lineEdit)
|
||||||
|
self.horizontalLayout.addWidget(self.applyButton)
|
||||||
|
self.horizontalLayout.addWidget(self.wipeButton)
|
||||||
|
self.horizontalLayout.addWidget(self.computeButton)
|
||||||
self.verticalLayout.addLayout(self.horizontalLayout)
|
self.verticalLayout.addLayout(self.horizontalLayout)
|
||||||
|
|
||||||
# add table
|
# add table
|
||||||
|
@ -732,6 +754,9 @@ class SpreadsheetView(QtGui.QWidget):
|
||||||
QtCore.QObject.connect(self.table, QtCore.SIGNAL("cellChanged(int,int)"), self.changeCell)
|
QtCore.QObject.connect(self.table, QtCore.SIGNAL("cellChanged(int,int)"), self.changeCell)
|
||||||
QtCore.QObject.connect(self.table, QtCore.SIGNAL("currentCellChanged(int,int,int,int)"), self.setEditLine)
|
QtCore.QObject.connect(self.table, QtCore.SIGNAL("currentCellChanged(int,int,int,int)"), self.setEditLine)
|
||||||
QtCore.QObject.connect(self.lineEdit, QtCore.SIGNAL("returnPressed()"), self.getEditLine)
|
QtCore.QObject.connect(self.lineEdit, QtCore.SIGNAL("returnPressed()"), self.getEditLine)
|
||||||
|
QtCore.QObject.connect(self.applyButton, QtCore.SIGNAL("clicked()"), self.getEditLine)
|
||||||
|
QtCore.QObject.connect(self.wipeButton, QtCore.SIGNAL("clicked()"), self.wipeCell)
|
||||||
|
QtCore.QObject.connect(self.computeButton, QtCore.SIGNAL("clicked()"), self.recompute)
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
#if DEBUG: print "Closing spreadsheet view"
|
#if DEBUG: print "Closing spreadsheet view"
|
||||||
|
@ -775,6 +800,10 @@ class SpreadsheetView(QtGui.QWidget):
|
||||||
brush.setStyle(QtCore.Qt.Dense6Pattern)
|
brush.setStyle(QtCore.Qt.Dense6Pattern)
|
||||||
if self.table.item(r,c):
|
if self.table.item(r,c):
|
||||||
self.table.item(r,c).setBackground(brush)
|
self.table.item(r,c).setBackground(brush)
|
||||||
|
else:
|
||||||
|
brush = QtGui.QBrush()
|
||||||
|
if self.table.item(r,c):
|
||||||
|
self.table.item(r,c).setBackground(brush)
|
||||||
|
|
||||||
def changeCell(self,r,c,value=None):
|
def changeCell(self,r,c,value=None):
|
||||||
"changes the contens of a cell"
|
"changes the contens of a cell"
|
||||||
|
@ -783,21 +812,28 @@ class SpreadsheetView(QtGui.QWidget):
|
||||||
self.doNotChange = False
|
self.doNotChange = False
|
||||||
elif self.spreadsheet:
|
elif self.spreadsheet:
|
||||||
key = "abcdefghijklmnopqrstuvwxyz"[c]+str(r+1)
|
key = "abcdefghijklmnopqrstuvwxyz"[c]+str(r+1)
|
||||||
if not value:
|
if value == None:
|
||||||
value = self.table.item(r,c).text()
|
value = self.table.item(r,c).text()
|
||||||
if DEBUG: print "Changing "+key+" to "+value
|
if value == "":
|
||||||
# store the entry as best as possible
|
if DEBUG: print "Wiping "+key
|
||||||
try:
|
if self.table.item(r,c):
|
||||||
v = int(value)
|
self.table.item(r,c).setText("")
|
||||||
except:
|
if key in self.spreadsheet.Proxy._cells.keys():
|
||||||
|
del self.spreadsheet.Proxy._cells[key]
|
||||||
|
else:
|
||||||
|
if DEBUG: print "Changing "+key+" to "+value
|
||||||
|
# store the entry as best as possible
|
||||||
try:
|
try:
|
||||||
v = float(value)
|
v = int(value)
|
||||||
except:
|
except:
|
||||||
try:
|
try:
|
||||||
v = v = str(value)
|
v = float(value)
|
||||||
except:
|
except:
|
||||||
v = value
|
try:
|
||||||
setattr(self.spreadsheet.Proxy,key,v)
|
v = v = str(value)
|
||||||
|
except:
|
||||||
|
v = value
|
||||||
|
setattr(self.spreadsheet.Proxy,key,v)
|
||||||
self.update()
|
self.update()
|
||||||
# TODO do not update the whole spreadsheet when only one cell has changed:
|
# TODO do not update the whole spreadsheet when only one cell has changed:
|
||||||
# use the _relations table and recursively update only cells based on this one
|
# use the _relations table and recursively update only cells based on this one
|
||||||
|
@ -820,11 +856,19 @@ class SpreadsheetView(QtGui.QWidget):
|
||||||
"called when something has been entered in the edit line"
|
"called when something has been entered in the edit line"
|
||||||
txt = str(self.lineEdit.text())
|
txt = str(self.lineEdit.text())
|
||||||
if DEBUG: print "Text edited ",txt
|
if DEBUG: print "Text edited ",txt
|
||||||
if txt:
|
r = self.table.currentRow()
|
||||||
r = self.table.currentRow()
|
c = self.table.currentColumn()
|
||||||
c = self.table.currentColumn()
|
self.changeCell(r,c,txt)
|
||||||
self.changeCell(r,c,txt)
|
|
||||||
|
|
||||||
|
def wipeCell(self):
|
||||||
|
if DEBUG: print "Wiping cell"
|
||||||
|
self.lineEdit.setText("")
|
||||||
|
self.getEditLine()
|
||||||
|
|
||||||
|
def recompute(self):
|
||||||
|
if self.spreadsheet:
|
||||||
|
self.spreadsheet.Proxy.recompute(self.spreadsheet)
|
||||||
|
self.update()
|
||||||
|
|
||||||
class _Command_Spreadsheet_Create:
|
class _Command_Spreadsheet_Create:
|
||||||
"the Spreadsheet_Create FreeCAD command"
|
"the Spreadsheet_Create FreeCAD command"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user