Ejemplo n.º 1
0
    def tableView_objectValueForTableColumn_row_(self, table, column,
                                                 row: int):
        value = self.interface.data[row]
        try:
            data = value._impl
        except AttributeError:
            data = TogaData.alloc().init()
            value._impl = data

        data.attrs = {
            attr: attr_impl(value, attr, self.interface.factory)
            for attr in value._attrs
        }

        return data
Ejemplo n.º 2
0
    def outlineView_child_ofItem_(self, tree, child: int, item):
        # Get the object representing the row
        if item is None:
            node = self.interface.data[child]
        else:
            node = item.attrs['node'][child]

        # Get the Cocoa implementation for the row. If an _impl
        # doesn't exist, create a data object for it, and
        # populate it with initial values for each column.
        try:
            node_impl = node._impl
        except AttributeError:
            node_impl = TogaData.alloc().init()
            node_impl.attrs = {'node': node}
            node._impl = node_impl

        return node_impl
Ejemplo n.º 3
0
    def outlineView_objectValueForTableColumn_byItem_(self, tree, column,
                                                      item):
        col_identifier = self._impl.column_identifiers[id(column.identifier)]

        try:
            value = getattr(item.attrs['node'], col_identifier)

            # Allow for an (icon, value) tuple as the simple case
            # for encoding an icon in a table cell. Otherwise, look
            # for an icon attribute.
            if isinstance(value, tuple):
                icon_iface, value = value
            else:
                # If the value has an icon attribute, get the _impl.
                # Icons are deferred resources, so we bind to the factory.
                try:
                    icon = value.icon.bind(self.interface.factory)
                except AttributeError:
                    icon_iface = None
        except AttributeError:
            # If the node doesn't have a property with the
            # accessor name, assume an empty string value.
            value = ''
            icon_iface = None

        # If the value has an icon, get the _impl.
        # Icons are deferred resources, so we provide the factory.
        if icon_iface:
            icon = icon_iface.bind(self.interface.factory)
        else:
            icon = None

        # Now construct the data object for the cell.
        # If the datum already exists, reuse and update it.
        # If an icon is present, create a TogaData object.
        # Otherwise, just use the string (because a Python string)
        # is transparently an ObjC object, so it works as a value.
        obj = item.attrs['values'][col_identifier]
        if obj is None or isinstance(obj, str):
            if icon:
                # Create a TogaData value
                obj = TogaData.alloc().init()
                obj.attrs = {
                    'label': str(value),
                    'icon': icon,
                }
            else:
                # Create/Update the string value
                obj = str(value)
            item.attrs['values'][col_identifier] = obj
        else:
            # Datum exists, and is currently an icon.
            if icon:
                # Update TogaData values
                obj.attrs = {
                    'label': str(value),
                    'icon': icon,
                }
            else:
                # Convert to a simple string.
                obj = str(value)
                item.attrs['values'][col_identifier] = obj

        return obj