Exemple #1
0
def update_reaction(net_index: int,
                    reaction_index: int,
                    id_: str = None,
                    fill_color: wx.Colour = None,
                    thickness: float = None,
                    ratelaw: str = None):
    """
    Update one or multiple properties of a reaction.

    Args:
        net_index (int): The network index.
        reaction_index (int): The reaction index of the reaction to modify.
        id_ (str): If specified, the new ID of the reaction.
        fill_color (wx.Colour): If specified, the new fill color of the reaction.
        thickness (float): If specified, the thickness of the reaction.
        ratelaw (str): If specified, the rate law of the equation.

    Raises:
        ValueError: If ID is empty, thickness is out of range, or the rate law is set to zero.

    """
    # TODO get old reaction
    # Validate
    # Check ID not empty
    if id_ is not None and len(id_) == 0:
        raise ValueError('id_ cannot be empty')

    if thickness is not None and thickness < 0:
        raise ValueError('thickness must be at least 0')

    if ratelaw is not None and len(ratelaw) == 0:
        raise ValueError('ratelaw cannot be empty')

    with group_action():
        if id_ is not None:
            _controller.rename_reaction(net_index, reaction_index, id_)
        if fill_color is not None:
            _controller.set_reaction_fill_rgb(net_index, reaction_index,
                                              fill_color)
            _controller.set_reaction_fill_alpha(net_index, reaction_index,
                                                fill_color.Alpha())
        if thickness is not None:
            _controller.set_reaction_line_thickness(net_index, reaction_index,
                                                    thickness)
        if ratelaw is not None:
            _controller.set_reaction_ratelaw(net_index, reaction_index,
                                             ratelaw)
Exemple #2
0
def opacity_mul(color: wx.Colour, fraction: float) -> wx.Colour:
    return wx.Colour(color.Red(), color.Green(), color.Blue(),
                     color.Alpha() * fraction)
Exemple #3
0
 def wx_to_tcolor(self, color: wx.Colour) -> Color:
     return Color(color.Red(), color.Green(), color.Blue(), color.Alpha())
Exemple #4
0
def _to_color(color: wx.Colour) -> Color:
    return Color(color.Red(), color.Green(), color.Blue(), color.Alpha())
Exemple #5
0
def update_node(net_index: int,
                node_index: int,
                id_: str = None,
                fill_color: wx.Colour = None,
                border_color: wx.Colour = None,
                border_width: float = None,
                position: Vec2 = None,
                size: Vec2 = None):
    """
    Update one or multiple properties of a node.

    Args:
        net_index (int): The network index.
        node_index (int): The node index of the node to modify.
        id_ (str): If specified, the new ID of the node.
        fill_color (wx.Colour): If specified, the new fill color of the node.
        border_color (wx.Colour): If specified, the new border color of the node.
        border_width (float): If specified, the new border width of the node.
        position (Vec2): If specified, the new position of the node.
        size (Vec2): If specified, the new size of the node.

    Raises:
        ValueError: If ID is empty or if at least one of border_width, position, and size is out of
                    range.
    """
    # Make sure this node exists
    old_node = get_node_by_index(net_index, node_index)
    # Validate
    # Check ID not empty
    if id_ is not None and len(id_) == 0:
        raise ValueError('id_ cannot be empty')

    # Check border at least 0
    if border_width is not None and border_width < 0:
        raise ValueError("border_width must be at least 0")

    # Check position at least 0
    if position is not None and (position.x < 0 or position.y < 0):
        raise ValueError(
            "position cannot have negative coordinates, but got '{}'".format(
                position))

    # Check size at least 0
    if size is not None and (size.x < 0 or size.y < 0):
        raise ValueError(
            "size cannot have negative coordinates, but got '{}'".format(size))

    # Check within bounds
    if position is not None or size is not None:
        pos = position if position is not None else old_node.position
        sz = size if size is not None else old_node.size
        botright = pos + sz
        if botright.x > _canvas.realsize.x or botright.y > _canvas.realsize.y:
            raise ValueError(
                'Invalid position and size combination ({} and {}): bottom right '
                'corner exceed canvas boundary {}', pos, sz, _canvas.realsize)

    with group_action():
        if id_ is not None:
            _controller.rename_node(net_index, node_index, id_)
        if fill_color is not None:
            _controller.set_node_fill_rgb(net_index, node_index, fill_color)
            _controller.set_node_fill_alpha(net_index, node_index,
                                            fill_color.Alpha())
        if border_color is not None:
            _controller.set_node_border_rgb(net_index, node_index,
                                            border_color)
            _controller.set_node_border_alpha(net_index, node_index,
                                              border_color.Alpha())
        if border_width is not None:
            _controller.set_node_border_width(net_index, node_index,
                                              border_width)
        if position is not None:
            _controller.move_node(net_index, node_index, position)
        if size is not None:
            _controller.set_node_size(net_index, node_index, size)