Esempio n. 1
0
    def _onAppendItemClicked(self, event):
        """ Called when the user clicks on the option to append an item to an
        array. """

        # Include the parent name in the key text for the child item, since this
        # makes array items more readable.
        parentName = self._tree.GetItemText(self.currentItem)

        lastChild = self._tree.GetLastChild(self.currentItem)
        if lastChild:
            index = self._tree.GetItemPyData(lastChild)['index'] + 1
        else:
            index = 0
        child = self._tree.AppendItem(self.currentItem,\
                "%s[%d]" % (parentName, index+1))
        currentItemSchema = self._tree.GetItemPyData(self.currentItem)['schema']
        childSchema = currentItemSchema['items']
        self._tree.SetItemPyData(child, {'schema': childSchema, 'index': index})

        # Initialize the new item with the default value
        self._setItemValue(child, parameters.getDefault(childSchema))

        self._tree.SortChildren(self.currentItem)
        self._tree.Expand(self.currentItem)

        self._setModified()
Esempio n. 2
0
    def _onAppendItemClicked(self, event):
        """ Called when the user clicks on the option to append an item to an
        array. """

        # Include the parent name in the key text for the child item, since this
        # makes array items more readable.
        parentName = self._tree.GetItemText(self.currentItem)

        lastChild = self._tree.GetLastChild(self.currentItem)
        if lastChild:
            index = self._tree.GetItemPyData(lastChild)['index'] + 1
        else:
            index = 0
        child = self._tree.AppendItem(self.currentItem,\
                "%s[%d]" % (parentName, index+1))
        currentItemSchema = self._tree.GetItemPyData(
            self.currentItem)['schema']
        childSchema = currentItemSchema['items']
        self._tree.SetItemPyData(child, {
            'schema': childSchema,
            'index': index
        })

        # Initialize the new item with the default value
        self._setItemValue(child, parameters.getDefault(childSchema))

        self._tree.SortChildren(self.currentItem)
        self._tree.Expand(self.currentItem)

        self._setModified()
Esempio n. 3
0
    def _setItemValue(self, item, value):
        """ Set the value of the given tree item.  If the value is a dict or a
        list, recursively create subitems and set their values.  Assumes that
        the schema for the item has already been set, and that the value is of
        the type specified in the schema (mapped from JSON Schema type to Python
        type; see parameters.JSONTypeMap). """

        schema = self._tree.GetItemPyData(item)['schema']

        # If the value is a collection, delete the item's existing children,
        # then recursively set values for its elements
        if schema['type'] == 'object':

            # Update the object's properties with default values for any missing
            # properties required by the schema.
            for propName, propSchema in schema.get('properties', {}).items():
                if propSchema.get('required') and not value.has_key(propName):
                    value[propName] = parameters.getDefault(propSchema)

            self._tree.DeleteChildren(item)
            for k, v in sorted(value.items()):
                child = self._tree.AppendItem(item, k)
                childSchema = schema.get('properties', {}).get(k, None)
                self._tree.SetItemPyData(child, {'schema': childSchema})
                self._setItemValue(child, v)
        elif schema['type'] == 'array':
            self._tree.DeleteChildren(item)

            # FIXME: Allow the possibility that 'items' is an array of schemas
            # rather than a single schema

            # Allows showing a more informative label in the Key column than
            # just the element's index.
            thisKey = self._tree.GetItemText(item, 0)

            childSchema = schema.get('items')
            for k, v in enumerate(value):
                child = self._tree.AppendItem(item,
                                              "%s[%d]" % (thisKey, k + 1))
                self._tree.SetItemPyData(child, {'schema': childSchema,\
                        'index': k})
                self._setItemValue(child, v)

        else:
            # The value is not a collection - we've reached a leaf in the tree
            self._tree.SetItemText(item, str(value), 1)

        self._setItemImage(item, schema['type'])
Esempio n. 4
0
    def _setItemValue(self, item, value):
        """ Set the value of the given tree item.  If the value is a dict or a
        list, recursively create subitems and set their values.  Assumes that
        the schema for the item has already been set, and that the value is of
        the type specified in the schema (mapped from JSON Schema type to Python
        type; see parameters.JSONTypeMap). """

        schema = self._tree.GetItemPyData(item)['schema']

        # If the value is a collection, delete the item's existing children,
        # then recursively set values for its elements
        if schema['type'] == 'object':

            # Update the object's properties with default values for any missing
            # properties required by the schema.
            for propName, propSchema in schema.get('properties', {}).items():
                if propSchema.get('required') and not value.has_key(propName):
                    value[propName] = parameters.getDefault(propSchema)

            self._tree.DeleteChildren(item)
            for k, v in sorted(value.items()):
                child = self._tree.AppendItem(item, k)
                childSchema = schema.get('properties', {}).get(k, None)
                self._tree.SetItemPyData(child, {'schema': childSchema})
                self._setItemValue(child, v)
        elif schema['type'] == 'array':
            self._tree.DeleteChildren(item)

            # FIXME: Allow the possibility that 'items' is an array of schemas
            # rather than a single schema

            # Allows showing a more informative label in the Key column than
            # just the element's index.
            thisKey = self._tree.GetItemText(item, 0)

            childSchema = schema.get('items')
            for k, v in enumerate(value):
                child = self._tree.AppendItem(item, "%s[%d]" % (thisKey, k+1))
                self._tree.SetItemPyData(child, {'schema': childSchema,\
                        'index': k})
                self._setItemValue(child, v)

        else:
            # The value is not a collection - we've reached a leaf in the tree
            self._tree.SetItemText(item, str(value), 1)

        self._setItemImage(item, schema['type'])
Esempio n. 5
0
    def _onAddPropertyClicked(self, event):
        """ Called when the user clicks on a property to add from an object's
        popup menu of available properties """

        menu = event.GetEventObject()
        menuItem = menu.FindItemById(event.GetId())
        propName = menuItem.GetItemLabelText()

        child = self._tree.AppendItem(self.currentItem, propName)

        currentItemSchema = self._tree.GetItemPyData(self.currentItem)['schema']
        childSchema = currentItemSchema['properties'][propName]
        self._tree.SetItemPyData(child, {'schema': childSchema})

        # Initialize the new item with the default value
        self._setItemValue(child, parameters.getDefault(childSchema))

        self._tree.SortChildren(self.currentItem)
        self._tree.Expand(self.currentItem)

        self._setModified()
Esempio n. 6
0
    def _onAddPropertyClicked(self, event):
        """ Called when the user clicks on a property to add from an object's
        popup menu of available properties """

        menu = event.GetEventObject()
        menuItem = menu.FindItemById(event.GetId())
        propName = menuItem.GetItemLabelText()

        child = self._tree.AppendItem(self.currentItem, propName)

        currentItemSchema = self._tree.GetItemPyData(
            self.currentItem)['schema']
        childSchema = currentItemSchema['properties'][propName]
        self._tree.SetItemPyData(child, {'schema': childSchema})

        # Initialize the new item with the default value
        self._setItemValue(child, parameters.getDefault(childSchema))

        self._tree.SortChildren(self.currentItem)
        self._tree.Expand(self.currentItem)

        self._setModified()