def _add_data_to_gwy(self, gwycontainer, channel_id):
        """ Add datafield from the channel to GwyContainer

        Args:
            gwycontainer (<GwyfileObject*>):
                Gwyddion container
            channel_id (int): id of the channel in GwyContainer

        Returns:
            True if the item was actually added.
        """
        if isinstance(self.data, GwyDataField):
            key = "/{:d}/data".format(channel_id)
            gwydf = self.data.to_gwy()
            gwyitem = new_gwyitem_object(key, gwydf)
            is_added = add_gwyitem_to_gwycontainer(gwyitem, gwycontainer)
            return is_added
        else:
            raise TypeError("Datafield is of wrong type")
Beispiel #2
0
    def _add_graphs_to_gwycontainer(self, gwycontainer):
        """ Convert graphs to gwygraphmodels and them to gwycontainer

        Args:
            gwycontainer (<GwyfileObject*>)

        """
        for graph_id, graph in enumerate(self.graphs):
            gwygraph = graph.to_gwy()

            # graph enumeration in gwyddion starts with 1
            key = "/0/graph/graph/{:d}".format(graph_id + 1)
            gwyitem = new_gwyitem_object(key, gwygraph)

            if add_gwyitem_to_gwycontainer(gwyitem, gwycontainer):
                # gwycontainer object keeps alive gwygraph objects
                _container_graphs_dic[gwycontainer].append(gwygraph)

                self._add_graph_visibility_to_gwycontainer(
                    graph, gwycontainer, key)
    def _add_show_to_gwy(self, gwycontainer, channel_id):
        """ Add presentation datafield from the channel to GwyContainer

        Args:
            gwycontainer (<GwyfileObject*>):
                Gwyddion container
            channel_id (int): id of the channel in GwyContainer

        Returns:
            True if the item was actually added.
        """
        if self.show is None:
            return False
        elif isinstance(self.show, GwyDataField):
            key = "/{:d}/show".format(channel_id)
            gwydf = self.show.to_gwy()
            gwyitem = new_gwyitem_object(key, gwydf)
            is_added = add_gwyitem_to_gwycontainer(gwyitem, gwycontainer)
            return is_added
        else:
            raise TypeError("Presentation must be a GwyDataField or None")
    def _add_ellipse_sel_to_gwy(self, gwycontainer, channel_id):
        """ Add ellipse selections from the channel to GwyContainer

        Args:
            gwycontainer (<GwyfileObject*>):
                Gwyddion container
            channel_id (int): id of the channel in GwyContainer

        Returns:
            True if the item was actually added.
        """
        if self.ellipse_selections is None:
            return False
        elif isinstance(self.ellipse_selections, GwyEllipseSelection):
            key = "/{:d}/select/ellipse".format(channel_id)
            gwysel = self.ellipse_selections.to_gwy()
            gwyitem = new_gwyitem_object(key, gwysel)
            is_added = add_gwyitem_to_gwycontainer(gwyitem, gwycontainer)
            return is_added
        else:
            raise TypeError("ellipse_selections must be"
                            "a GwyEllipseSelection instance or None")
 def test_return_value(self):
     """Test return value"""
     self.mock_new_gwyitem.side_effect = self._side_effect
     actual_return = new_gwyitem_object(self.item_key, self.value)
     self.assertEqual(actual_return, self.gwyitem)