diff options
-rw-r--r-- | lvc/widgets/osx/tablemodel.py | 71 |
1 files changed, 48 insertions, 23 deletions
diff --git a/lvc/widgets/osx/tablemodel.py b/lvc/widgets/osx/tablemodel.py index d81a8f5..0828fd3 100644 --- a/lvc/widgets/osx/tablemodel.py +++ b/lvc/widgets/osx/tablemodel.py @@ -46,6 +46,7 @@ MIRO_DND_ITEM_LOCAL = 'miro-local-item' # XXX need unsigned but value comes out as signed. NSDragOperationEvery = NSDragOperationAll + def list_from_nsindexset(index_set): rows = list() index = index_set.firstIndex() @@ -54,6 +55,7 @@ def list_from_nsindexset(index_set): index = index_set.indexGreaterThanIndex_(index) return rows + class RowList(object): """RowList is a Linked list that has some optimizations for looking up rows by index number. @@ -112,6 +114,7 @@ class RowList(object): self.iter_cache.append(iter.copy()) return iter + class TableModelBase(signals.SignalEmitter): """Base class for TableModel and TreeTableModel.""" def __init__(self, *column_types): @@ -173,8 +176,10 @@ class TableModelBase(signals.SignalEmitter): def __iter__(self): return iter(self.row_list) + class TableRow(object): - """See https://develop.participatoryculture.org/index.php/WidgetAPITableView for a description of the API for this class.""" + """See https://develop.participatoryculture.org/index.php/WidgetAPITableView + for a description of the API for this class.""" def __init__(self, column_values): self.update_values(column_values) @@ -190,8 +195,10 @@ class TableRow(object): def __iter__(self): return iter(self.values) + class TableModel(TableModelBase): - """See https://develop.participatoryculture.org/index.php/WidgetAPITableView for a description of the API for this class.""" + """See https://develop.participatoryculture.org/index.php/WidgetAPITableView + for a description of the API for this class.""" def __init__(self, *column_types): TableModelBase.__init__(self, column_types) self.row_indexes = {} @@ -259,6 +266,7 @@ class TreeNode(NSObject, TableRow): def iterchildren(self): return iter(self.children) + class TreeTableModel(TableModelBase): """https://develop.participatoryculture.org/index.php/WidgetAPITableView""" def __init__(self, *column_values): @@ -341,7 +349,7 @@ class TreeTableModel(TableModelBase): raise WidgetActionError("no item at row %s" % row) else: raise WidgetActionError("no iter for item %s at row %s" % - (repr(item), row)) + (repr(item), row)) def row_of_iter(self, tableview, iter): item = iter.value() @@ -357,6 +365,7 @@ class TreeTableModel(TableModelBase): """ return NotImplemented + class DataSourceBase(NSObject): def initWithModel_(self, model): self.model = model @@ -401,7 +410,7 @@ class DataSourceBase(NSObject): return None def validateDrop_dragInfo_parentIter_position_(self, view, drag_info, - parent, position): + parent, position): typ = self.calcType_(drag_info) if typ: wrapper = wrappermap.wrapper(view) @@ -421,7 +430,7 @@ class DataSourceBase(NSObject): return NSDragOperationNone def acceptDrop_dragInfo_parentIter_position_(self, view, drag_info, - parent, position): + parent, position): typ = self.calcType_(drag_info) if typ: # XXX using eval sucks. @@ -430,27 +439,29 @@ class DataSourceBase(NSObject): ids = eval(ids) wrapper = wrappermap.wrapper(view) self.drag_dest.accept_drop(wrapper, self.model, typ, - drag_info.draggingSourceOperationMask(), parent, - position, ids) + drag_info.draggingSourceOperationMask(), + parent, position, ids) return YES else: return NO + class MiroTableViewDataSource(DataSourceBase, protocols.NSTableDataSource): def numberOfRowsInTableView_(self, table_view): return len(self.model) - def tableView_objectValueForTableColumn_row_(self, table_view, column, row): + def tableView_objectValueForTableColumn_row_(self, table_view, + column, row): node = self.model.nth_iter(row).value() self.model.remember_row_at_index(node, row) return self.model.get_column_data(node.values, column) - def tableView_writeRowsWithIndexes_toPasteboard_(self, tableview, rowIndexes, - pasteboard): + def tableView_writeRowsWithIndexes_toPasteboard_(self, tableview, + rowIndexes, pasteboard): indexes = list_from_nsindexset(rowIndexes) data = [self.model[self.model.nth_iter(i)] for i in indexes] return self.view_writeColumnData_ToPasteboard_(tableview, data, - pasteboard) + pasteboard) def translateRow_operation_(self, row, operation): if operation == NSTableViewDropOn: @@ -459,10 +470,15 @@ class MiroTableViewDataSource(DataSourceBase, protocols.NSTableDataSource): return None, row def tableView_validateDrop_proposedRow_proposedDropOperation_(self, - tableview, drag_info, row, operation): - parent, position = self.translateRow_operation_(row, operation) - drop_action = self.validateDrop_dragInfo_parentIter_position_(tableview, - drag_info, parent, position) + tableview, + drag_info, + row, + operation): + parent, position = self.translateRow_operation_(row, operation) + drop_action = \ + self.validateDrop_dragInfo_parentIter_position_(tableview, + drag_info, + parent, position) if isinstance(drop_action, (list, tuple)): # XXX nothing uses this yet drop_action, iter = drop_action @@ -472,10 +488,15 @@ class MiroTableViewDataSource(DataSourceBase, protocols.NSTableDataSource): return drop_action def tableView_acceptDrop_row_dropOperation_(self, - tableview, drag_info, row, operation): + tableview, + drag_info, + row, + operation): parent, position = self.translateRow_operation_(row, operation) return self.acceptDrop_dragInfo_parentIter_position_(tableview, - drag_info, parent, position) + drag_info, + parent, + position) class MiroOutlineViewDataSource(DataSourceBase, protocols.NSOutlineViewDataSource): @@ -499,17 +520,20 @@ class MiroOutlineViewDataSource(DataSourceBase, protocols.NSOutlineViewDataSourc return len(self.model) def outlineView_objectValueForTableColumn_byItem_(self, view, column, - item): + item): return self.model.get_column_data(item.values, column) def outlineView_writeItems_toPasteboard_(self, outline_view, items, - pasteboard): + pasteboard): data = [i.values for i in items] return self.view_writeColumnData_ToPasteboard_(outline_view, data, - pasteboard) + pasteboard) def outlineView_validateDrop_proposedItem_proposedChildIndex_(self, - outlineview, drag_info, item, child_index): + outlineview, + drag_info, + item, + child_index): if item is None: iter = None else: @@ -523,10 +547,11 @@ class MiroOutlineViewDataSource(DataSourceBase, protocols.NSOutlineViewDataSourc return drop_action def outlineView_acceptDrop_item_childIndex_(self, outlineview, drag_info, - item, child_index): + item, child_index): if item is None: iter = None else: iter = self.model.iter_for_item[item] return self.acceptDrop_dragInfo_parentIter_position_(outlineview, - drag_info, iter, child_index) + drag_info, + iter, child_index) |