[ui] Camera Response Function display: make it safer

More checks on file content and catch exception.
Check nbColumns using a slot instead of using the property.
Use a workaround on the CVS loader to avoid a crash (do not set active
to False).
This commit is contained in:
Fabien Castan 2020-08-24 11:33:26 +02:00
parent 04c21fffe4
commit b295242576
4 changed files with 38 additions and 22 deletions

View file

@ -1,10 +1,12 @@
from meshroom.common.qt import QObjectListModel
from PySide2.QtCore import QObject, Slot, Signal, Property
from PySide2.QtCore import QObject, Slot, Signal, Property, Qt
from PySide2.QtCharts import QtCharts
import csv
import os
import logging
class CsvData(QObject):
"""Store data from a CSV file."""
@ -20,13 +22,18 @@ class CsvData(QObject):
def getColumn(self, index):
return self._data.at(index)
@Slot(result=str)
def getFilepath(self):
return self._filepath
@Slot(result=int)
def getNbColumns(self):
return len(self._data) if self._ready else 0
if self._ready:
return len(self._data)
else:
return 0
@Slot(str)
def setFilepath(self, filepath):
if self._filepath == filepath:
return
@ -40,6 +47,7 @@ class CsvData(QObject):
self._ready = ready
self.readyChanged.emit()
@Slot()
def updateData(self):
self.setReady(False)
self._data.clear()
@ -53,23 +61,23 @@ class CsvData(QObject):
if not self._filepath or not self._filepath.lower().endswith(".csv") or not os.path.isfile(self._filepath):
return []
csvRows = []
with open(self._filepath, "r") as fp:
reader = csv.reader(fp)
for row in reader:
csvRows.append(row)
dataList = []
# Create the objects in dataList
# with the first line elements as objects' title
for elt in csvRows[0]:
dataList.append(CsvColumn(elt, parent=self._data))
# Populate the content attribute
for elt in csvRows[1:]:
for idx, value in enumerate(elt):
dataList[idx].appendValue(value)
try:
csvRows = []
with open(self._filepath, "r") as fp:
reader = csv.reader(fp)
for row in reader:
csvRows.append(row)
# Create the objects in dataList
# with the first line elements as objects' title
for elt in csvRows[0]:
dataList.append(CsvColumn(elt)) # , parent=self._data
# Populate the content attribute
for elt in csvRows[1:]:
for idx, value in enumerate(elt):
dataList[idx].appendValue(value)
except:
logging.error("CsvData: Failed to load file: {}".format(self._filepath))
return dataList