From fb204bd839c1d401151dca4bf8315490c1a9b81e Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 15 May 2016 15:39:58 +1000 Subject: [PATCH] Removed Column class and cleaned up ColumnList class --- KiBOM/columns.py | 93 ++++++++++++------------------------------------ 1 file changed, 22 insertions(+), 71 deletions(-) diff --git a/KiBOM/columns.py b/KiBOM/columns.py index bd0ddccb..d45d5ad2 100644 --- a/KiBOM/columns.py +++ b/KiBOM/columns.py @@ -1,9 +1,4 @@ - -class Column: - - COL_TYPE_KICAD = "KiCAD" #Immutable columns defined within KiCAD - COL_TYPE_FIELD = "Field" #Fields defined within KiCAD, by the user - COL_TYPE_EXT = "External" #Fields defined in external BoM, not stored within KiCAD +class ColumnList: #default columns (immutable) COL_REFERENCE = 'Reference' @@ -17,55 +12,32 @@ class Column: #default columns for groups COL_GRP_QUANTITY = 'Quantity' - - def __init__(self, title, vis=True, colType=COL_TYPE_FIELD): - self.title = str(title) - self.visible = vis - - #column comparison - def __eq__(self, other): - #match based on string - if type(other) == str: - return other.lower() == self.title.lower() - #match based on Column - if type(other) == Column: - return other.title.lower() == self.title.lower() - #no match - return False - - def __str__(self): - return self.title - def __repr__(self): - return "'" + self.__str__() + "'" - -class ColumnList: - - #all available columns - _COLUMNS_ALL = [ - Column.COL_DESCRIPTION, - Column.COL_PART, - Column.COL_REFERENCE, - Column.COL_VALUE, - Column.COL_FP, - Column.COL_GRP_QUANTITY, - Column.COL_DATASHEET + #default columns + _COLUMNS_DEFAULT = [ + COL_DESCRIPTION, + COL_PART, + COL_REFERENCE, + COL_VALUE, + COL_FP, + COL_GRP_QUANTITY, + COL_DATASHEET ] #default columns #these columns are 'immutable' _COLUMNS_PROTECTED = [ - Column.COL_DESCRIPTION, - Column.COL_PART, - Column.COL_REFERENCE, - Column.COL_VALUE, - Column.COL_FP + COL_REFERENCE, + COL_GRP_QUANTITY, + COL_VALUE, + COL_PART, + COL_PART_LIB, + COL_DESCRIPTION, + COL_DATASHEET, + COL_FP, + COL_FP_LIB ] - #Columns that only exist for the 'grouped' components - _COLUMNS_GROUPED = [ - Column.COL_GRP_QUANTITY, - ] def __str__(self): return " ".join(map(str,self.columns)) @@ -73,26 +45,17 @@ class ColumnList: def __repr__(self): return self.__str__() - def __init__(self, cols=_COLUMNS_ALL): + def __init__(self, cols=_COLUMNS_DEFAULT): self.columns = [] - + #make a copy of the supplied columns for col in cols: self.AddColumn(col) - - self._checkDefaultColumns() def _hasColumn(self, col): #col can either be or - return col in self.columns - - def _checkDefaultColumns(self): - - #prepend any default columns that don't exist - for c in self._COLUMNS_DEFAULT[::-1]: - if c not in self.columns: - self.columns = [Column(c)] + self.columns + return col.lower() in [c.lower() for c in self.columns] """ Remove a column from the list. Specify either the heading or the index @@ -100,8 +63,6 @@ class ColumnList: def RemoveColumn(self, col): if type(col) is str: self.RemoveColumnByName(col) - if type(col) is Column: - self.RemoveColumnByName(col.title) elif type(col) is int and col >= 0 and col < len(self.columns): self.RemoveColumnByName(self.columns[col]) @@ -124,13 +85,6 @@ class ColumnList: #add a new column (if it doesn't already exist!) def AddColumn(self, col, index=None): - if type(col) == Column: - pass - elif type(col) == str: - col = Column(col) - else: - return - #Already exists? if self._hasColumn(col): return @@ -142,9 +96,6 @@ class ColumnList: else: self.columns = self.columns[0:index] + [col] + self.columns[index:] - def VisibleColumns(self): - return [col for col in self.columns if col.visible] - if __name__ == '__main__': c = ColumnList()