<commit_before>from PyQt4 import QtCore, QtGui

from vistrails.packages.spreadsheet.basic_widgets import SpreadsheetCell
from vistrails.packages.spreadsheet.spreadsheet_cell import QCellWidget


class TableCell(SpreadsheetCell):
    """Shows a table in a spreadsheet cell.
    """
    _input_ports = [('table', '(org.vistrails.vistrails.tabledata:Table)')]

    def compute(self):
        table = self.get_input('table')
        self.cellWidget = self.displayAndWait(TableCellWidget, (table,))


class TableCellWidget(QCellWidget):
    def __init__(self, parent=None):
        QCellWidget.__init__(self, parent)

        layout = QtGui.QVBoxLayout()
        layout.setContentsMargins(0,0,0,0)

        self.table = QtGui.QTableWidget()

        scrollarea = QtGui.QScrollArea(self)
        scrollarea.setWidgetResizable(True)
        scrollarea.setWidget(self.table)
        layout.addWidget(scrollarea)

        self.setLayout(layout)

    def updateContents(self, inputPorts):
        table, = inputPorts

        self.table.setColumnCount(table.columns)
        self.table.setRowCount(table.rows)

        for col in xrange(table.columns):
            column = table.get_column(col)
            for row in xrange(table.rows):
                elem = column[row]
                if isinstance(elem, bytes):
                    elem = elem.decode('utf-8', 'replace')
                elif not isinstance(elem, unicode):
                    elem = unicode(elem)
                item = QtGui.QTableWidgetItem(elem)
                item.setFlags(QtCore.Qt.ItemIsEnabled |
                              QtCore.Qt.ItemIsSelectable)
                self.table.setItem(row, col, item)

        if table.names is not None:
            self.table.setHorizontalHeaderLabels(table.names)


_modules = [TableCell]<commit_msg>Enable column sorting in tabledata viewer<commit_after>from PyQt4 import QtCore, QtGui

from vistrails.packages.spreadsheet.basic_widgets import SpreadsheetCell
from vistrails.packages.spreadsheet.spreadsheet_cell import QCellWidget


class TableCell(SpreadsheetCell):
    """Shows a table in a spreadsheet cell.
    """
    _input_ports = [('table', '(org.vistrails.vistrails.tabledata:Table)')]

    def compute(self):
        table = self.get_input('table')
        self.cellWidget = self.displayAndWait(TableCellWidget, (table,))


class TableCellWidget(QCellWidget):
    def __init__(self, parent=None):
        QCellWidget.__init__(self, parent)

        layout = QtGui.QVBoxLayout()
        layout.setContentsMargins(0,0,0,0)

        self.table = QtGui.QTableWidget()

        scrollarea = QtGui.QScrollArea(self)
        scrollarea.setWidgetResizable(True)
        scrollarea.setWidget(self.table)
        layout.addWidget(scrollarea)

        self.setLayout(layout)

    def updateContents(self, inputPorts):
        table, = inputPorts

        self.table.setSortingEnabled(False)
        self.table.setColumnCount(table.columns)
        self.table.setRowCount(table.rows)

        for col in xrange(table.columns):
            column = table.get_column(col)
            for row in xrange(table.rows):
                elem = column[row]
                if isinstance(elem, bytes):
                    elem = elem.decode('utf-8', 'replace')
                elif not isinstance(elem, unicode):
                    elem = unicode(elem)
                item = QtGui.QTableWidgetItem(elem)
                item.setFlags(QtCore.Qt.ItemIsEnabled |
                              QtCore.Qt.ItemIsSelectable)
                self.table.setItem(row, col, item)

        if table.names is not None:
            self.table.setHorizontalHeaderLabels(table.names)
        self.table.setSortingEnabled(True)

_modules = [TableCell]
{'fraction_non_alphanumeric': 0.09737827715355805, 'fraction_numerical': 0.0032102728731942215, 'mean_word_length': 2.4588344125809436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3817557', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1054, 'n_words': 198}