예제 #1
0
    def test_separate_props(self):
        '''Test modifying the properties of node and alias that are separate, i.e. not shared.
        
        As in, if the position of an alias is changed, that of the node should remain the same,
        and vice versa.
        '''
        alias_pos = Vec2(100, 100)
        alias_size = Vec2(50, 50)
        nodei = api.add_node(self.neti, id='Hookie')
        aliasi = api.add_alias(self.neti,
                               nodei,
                               position=alias_pos,
                               size=alias_size)

        new_pos = Vec2(33, 33)
        new_size = Vec2(66, 66)
        new_lockNode = True
        api.update_node(self.neti,
                        nodei,
                        position=Vec2(33, 33),
                        size=Vec2(66, 66),
                        lockNode=True)
        node = api.get_node_by_index(self.neti, nodei)
        alias = api.get_node_by_index(self.neti, aliasi)

        # alias remains the same
        self.assertEqual(alias_pos, alias.position)
        self.assertEqual(alias_size, alias.size)
        self.assertEqual(False, alias.lockNode)

        # node is updated
        self.assertEqual(new_pos, node.position)
        self.assertEqual(new_size, node.size)
        self.assertEqual(new_lockNode, node.lockNode)
예제 #2
0
 def test_update_nodes(self):
     with run_app():
         node = Node('Charles',
                     pos=Vec2(50, 50),
                     size=Vec2(40, 12),
                     fill_color=wx.RED,
                     border_color=wx.GREEN,
                     border_width=4)
         api.add_node(self.neti, node)
         api.update_node(self.neti, 0, 'James')
         nodes = api.all_nodes()
         self.assertEqual(len(nodes), 1)
         self.assertTrue(nodes[0].id_, 'James')
예제 #3
0
    def unhighlight(self, evt):
        """
        Callback for the color picker control; sets the color of every node/reaction selected.
        """

        # start group action context for undo purposes
        with api.group_action():
            # color selected nodes
            #for index in api.selected_node_indices():
            try:
                for index in self.index_list:
                    api.update_node(api.cur_net_index(),
                                    index,
                                    fill_color=self.default_color,
                                    border_color=self.default_color)
            except:
                wx.MessageBox("There is no highlighted nodes", "Message",
                              wx.OK | wx.ICON_INFORMATION)
예제 #4
0
    def color_callback(self, evt):
        """
        Get whatever cells are currently selected
        """

        cells = self.tab2.grid_moi.GetSelectedCells()
        if not cells:
            if self.tab2.grid_moi.GetSelectionBlockTopLeft():
                top_left = self.tab2.grid_moi.GetSelectionBlockTopLeft()[0]
                bottom_right = self.tab2.grid_moi.GetSelectionBlockBottomRight(
                )[0]
                self.printSelectedCells(top_left, bottom_right)
            #else:
            #    print (self.currentlySelectedCell)
        else:
            print("no cells are selected")
        """
        Callback for the color picker control; sets the color of every node/reaction selected.
        """

        wxcolor = evt.GetColour()
        color = Color.from_rgb(wxcolor.GetRGB())

        # start group action context for undo purposes
        with api.group_action():
            # color selected nodes
            #for index in api.selected_node_indices():

            if len(self.index_list) == 0:
                wx.MessageBox("Please select a row and pick a color again",
                              "Message", wx.OK | wx.ICON_INFORMATION)
            try:
                for index in self.index_list:
                    api.update_node(api.cur_net_index(),
                                    index,
                                    fill_color=color,
                                    border_color=color)
            except:
                wx.MessageBox("Please select a row and pick a color again",
                              "Message", wx.OK | wx.ICON_INFORMATION)
예제 #5
0
    def color_callback(self, evt):
        """
        Change the colors.
        Set up a tracking of changes made to allow possibility to undo them.
        
        Args:
            self
            evt

        """
        color = evt.GetColour()

        # start group action context for undo purposes
        with api.group_action():
            # color selected nodes
            for index in api.selected_node_indices():
                api.update_node(api.cur_net_index(),
                                index,
                                fill_color=color,
                                border_color=color)

            # color selected reactions
            for index in api.selected_reaction_indices():
                api.set_reaction_color(api.cur_net_index(), index, color)
예제 #6
0
    def test_update_failure(self):
        api.add_node(self.neti, id='Zulu')
        # empty ID
        with self.assertRaises(ValueError):
            api.update_node(self.neti, 0, id='')

        # nodes don't exist
        with self.assertRaises(NetIndexError):
            api.update_node(-1, 0, size=Vec2(50, 60))
        with self.assertRaises(NodeIndexError):
            api.update_node(0, 2, size=Vec2(50, 60))

        # out of bounds
        with self.assertRaises(ValueError):
            api.update_node(self.neti, 0, position=Vec2(-1, 0))
        with self.assertRaises(ValueError):
            api.update_node(self.neti, 0, position=Vec2(0, -1))

        csize = api.canvas_size()
        # in bounds
        api.update_node(self.neti, 0, position=csize - Vec2(100, 100))

        # out of bounds
        with self.assertRaises(ValueError):
            api.update_node(self.neti, 0, position=csize - Vec2(1, 1))
예제 #7
0
 def test_update_basic(self):
     api.add_node(self.neti, id="Eric")
     api.update_node(self.neti, 0, 'James')
     nodes = api.get_nodes(self.neti)
     self.assertEqual(len(nodes), 1)
     self.assertEqual(nodes[0].id, 'James')