示例#1
0
class WorldTest(TestCase):

    def setUp(self):
        ev.events
        self.world = World()
        self.world.register_listener(ev)

    def tearDown(self):
        self.world.unregister_listener(ev)
        ev.events
        del self.world

    def test_world_objects(self):
        wo = WorldObject(name='o', data=1)
        assert wo.name == 'o'
        assert wo.data == 1

    def test_world(self):
        obj = self.world.add(1, 'a')
        events = ev.events
        self.check_events(events,
                          names=['world_object_changed'],
                          values={0: {0: self.world, 1: None, 2: obj}}
                          )
        attribute_dict = dict(name='attr1', value=1, interface='IInt', alias="Attribute 1")
        final_dict = dict(name='attr1', value=1, interface='IInt', alias="Attribute 1", constraints=None)
        obj.set_attribute(**attribute_dict)
        events = ev.events
        self.check_events(events,
                          names=['world_object_item_changed'],
                          values={0: {0: self.world, 1: obj, 2: "attribute", 3: None, 4: final_dict}}
                          )
        assert obj['attr1'] == attribute_dict['value']
示例#2
0
 def clear_namespace(self, interpreter, project):
     if project is None:
         return
     sys.path = self.old_syspath
     for k in project.ns.keys() + ['world', 'data', 'project']:
         if k in interpreter.user_ns:
             del interpreter.user_ns[k]
     from openalea.oalab.world import World
     world = World()
     world.clear()
示例#3
0
class WorldTest(TestCase):
    def setUp(self):
        ev.events
        self.world = World()
        self.world.register_listener(ev)

    def tearDown(self):
        self.world.unregister_listener(ev)
        ev.events
        del self.world

    def test_world_objects(self):
        wo = WorldObject(name='o', data=1)
        assert wo.name == 'o'
        assert wo.data == 1

    def test_world(self):
        obj = self.world.add(1, 'a')
        events = ev.events
        self.check_events(events,
                          names=['world_object_changed'],
                          values={0: {
                              0: self.world,
                              1: None,
                              2: obj
                          }})
        attribute_dict = dict(name='attr1',
                              value=1,
                              interface='IInt',
                              alias="Attribute 1")
        final_dict = dict(name='attr1',
                          value=1,
                          interface='IInt',
                          alias="Attribute 1",
                          constraints=None)
        obj.set_attribute(**attribute_dict)
        events = ev.events
        self.check_events(events,
                          names=['world_object_item_changed'],
                          values={
                              0: {
                                  0: self.world,
                                  1: obj,
                                  2: "attribute",
                                  3: None,
                                  4: final_dict
                              }
                          })
        assert obj['attr1'] == attribute_dict['value']
示例#4
0
 def update_namespace(self, interpreter):
     """
     Definition: Update namespace
     """
     if self._cproject:
         if self._cproject.path.exists():
             os.chdir(self._cproject.path)
             sys.path.insert(0, str(self._cproject.path / 'lib'))
         else:
             os.chdir(self.tmpdir)
             sys.path.insert(0, str(self.tmpdir / 'lib'))
         interpreter.user_ns.update(self._cproject.ns)
         interpreter.user_ns['project'] = self._cproject
         interpreter.user_ns['data'] = self._cproject.path / 'data'
         from openalea.oalab.world import World
         world = World()
         world.update_namespace(interpreter)
示例#5
0
 def setUp(self):
     ev.events
     self.world = World()
     self.world.register_listener(ev)
示例#6
0
文件: view3d.py 项目: pradal/plantlab
    def __init__(self, parent=None):
        #         super(Viewer, self).__init__()
        AbstractListener.__init__(self)
        view3D.__init__(self, parent=parent)

        self.setAccessibleName("3DViewer")
        self.setMinimumSize(100, 100)

        self.autofocus = True
        self._fps = False
        self.axis = False
        self.grid = True

        actionResetZoom = QtGui.QAction(
            QtGui.QIcon(":/images/resources/resetzoom.png"), "Home", self)
        self.actionAutoFocus = QtGui.QAction(
            QtGui.QIcon(":/images/resources/resetzoom.png"), "Auto Focus",
            self)
        self.actionAutoFocus.setCheckable(True)
        self.actionAutoFocus.setChecked(self.autofocus)
        self.actionAutoFocus.changed.connect(self._on_autofocus_changed)
        actionZoomOut = QtGui.QAction(
            QtGui.QIcon(":/images/resources/zoomout.png"), "Zoom Out", self)
        actionZoomIn = QtGui.QAction(
            QtGui.QIcon(":/images/resources/zoomin.png"), "Zoom In", self)
        actionShowAxis = QtGui.QAction(
            QtGui.QIcon(":/images/resources/axis.png"), "Show Axis", self)
        actionShowGrid = QtGui.QAction(
            QtGui.QIcon(":/images/resources/grid.png"), "Show Grid", self)
        actionRadius = QtGui.QAction(
            QtGui.QIcon(":/images/resources/growth2.png"), "Focus", self)
        actionShowFps = QtGui.QAction(
            QtGui.QIcon(":/images/resources/fps.png"), "Show FPS", self)

        actionBlack = QtGui.QAction(QtGui.QIcon(""), "Bg Black", self)
        actionWhite = QtGui.QAction(QtGui.QIcon(""), "Bg White", self)

        actionShowAxis.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+A", None,
                                         QtGui.QApplication.UnicodeUTF8))
        actionShowGrid.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+I", None,
                                         QtGui.QApplication.UnicodeUTF8))
        actionRadius.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+M", None,
                                         QtGui.QApplication.UnicodeUTF8))
        actionResetZoom.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+0", None,
                                         QtGui.QApplication.UnicodeUTF8))
        actionZoomOut.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+-", None,
                                         QtGui.QApplication.UnicodeUTF8))
        actionZoomIn.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl++", None,
                                         QtGui.QApplication.UnicodeUTF8))

        QtCore.QObject.connect(actionResetZoom,
                               QtCore.SIGNAL('triggered(bool)'),
                               self.resetzoom)
        QtCore.QObject.connect(actionZoomOut, QtCore.SIGNAL('triggered(bool)'),
                               self.zoomout)
        QtCore.QObject.connect(actionZoomIn, QtCore.SIGNAL('triggered(bool)'),
                               self.zoomin)

        QtCore.QObject.connect(actionShowAxis,
                               QtCore.SIGNAL('triggered(bool)'),
                               self.show_hide_axis)
        QtCore.QObject.connect(actionShowGrid,
                               QtCore.SIGNAL('triggered(bool)'),
                               self.show_hide_grid)
        QtCore.QObject.connect(actionRadius, QtCore.SIGNAL('triggered(bool)'),
                               self.update_radius)

        QtCore.QObject.connect(actionShowFps, QtCore.SIGNAL('triggered(bool)'),
                               self.show_fps)

        QtCore.QObject.connect(actionBlack, QtCore.SIGNAL('triggered(bool)'),
                               self.set_bg_black)
        QtCore.QObject.connect(actionWhite, QtCore.SIGNAL('triggered(bool)'),
                               self.set_bg_white)

        world = World()
        world.register_listener(self)

        self._actions = [
            ["Viewer", "Zoom", actionResetZoom, 0],
            ["Viewer", "Zoom", actionZoomOut, 0],
            ["Viewer", "Zoom", actionZoomIn, 0],
            ["Viewer", "Zoom", self.actionAutoFocus, 0],
            ["Viewer", "Camera", actionShowAxis, 0],
            ["Viewer", "Camera", actionShowGrid, 0],
            ["Viewer", "Camera", actionRadius, 0],
            ["Viewer", "Camera", actionBlack, 0],
            ["Viewer", "Camera", actionWhite, 0],
            #["Viewer", "Informations", actionShowFps, 1]
        ]
示例#7
0
 def setUp(self):
     ev.events
     self.world = World()
     self.world.register_listener(ev)
示例#8
0
    def __init__(self, parent=None):
        #         super(Viewer, self).__init__()
        AbstractListener.__init__(self)
        view3D.__init__(self, parent=parent)

        self.setAccessibleName("3DViewer")
        self.setMinimumSize(100, 100)

        self.autofocus = True
        self._fps = False
        self.axis = False
        self.grid = True

        actionResetZoom = QtGui.QAction(QtGui.QIcon(":/images/resources/resetzoom.png"), "Home", self)
        self.actionAutoFocus = QtGui.QAction(QtGui.QIcon(":/images/resources/resetzoom.png"), "Auto Focus", self)
        self.actionAutoFocus.setCheckable(True)
        self.actionAutoFocus.setChecked(self.autofocus)
        self.actionAutoFocus.changed.connect(self._on_autofocus_changed)
        actionZoomOut = QtGui.QAction(QtGui.QIcon(":/images/resources/zoomout.png"), "Zoom Out", self)
        actionZoomIn = QtGui.QAction(QtGui.QIcon(":/images/resources/zoomin.png"), "Zoom In", self)
        actionShowAxis = QtGui.QAction(QtGui.QIcon(":/images/resources/axis.png"), "Show Axis", self)
        actionShowGrid = QtGui.QAction(QtGui.QIcon(":/images/resources/grid.png"), "Show Grid", self)
        actionRadius = QtGui.QAction(QtGui.QIcon(":/images/resources/growth2.png"), "Focus", self)
        actionShowFps = QtGui.QAction(QtGui.QIcon(":/images/resources/fps.png"), "Show FPS", self)

        actionBlack = QtGui.QAction(QtGui.QIcon(""), "Bg Black", self)
        actionWhite = QtGui.QAction(QtGui.QIcon(""), "Bg White", self)

        actionShowAxis.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+A", None, QtGui.QApplication.UnicodeUTF8))
        actionShowGrid.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+I", None, QtGui.QApplication.UnicodeUTF8))
        actionRadius.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+M", None, QtGui.QApplication.UnicodeUTF8))
        actionResetZoom.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+0", None, QtGui.QApplication.UnicodeUTF8))
        actionZoomOut.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl+-", None, QtGui.QApplication.UnicodeUTF8))
        actionZoomIn.setShortcut(
            QtGui.QApplication.translate("MainWindow", "Ctrl++", None, QtGui.QApplication.UnicodeUTF8))

        QtCore.QObject.connect(actionResetZoom, QtCore.SIGNAL('triggered(bool)'), self.resetzoom)
        QtCore.QObject.connect(actionZoomOut, QtCore.SIGNAL('triggered(bool)'), self.zoomout)
        QtCore.QObject.connect(actionZoomIn, QtCore.SIGNAL('triggered(bool)'), self.zoomin)

        QtCore.QObject.connect(actionShowAxis, QtCore.SIGNAL('triggered(bool)'), self.show_hide_axis)
        QtCore.QObject.connect(actionShowGrid, QtCore.SIGNAL('triggered(bool)'), self.show_hide_grid)
        QtCore.QObject.connect(actionRadius, QtCore.SIGNAL('triggered(bool)'), self.update_radius)

        QtCore.QObject.connect(actionShowFps, QtCore.SIGNAL('triggered(bool)'), self.show_fps)

        QtCore.QObject.connect(actionBlack, QtCore.SIGNAL('triggered(bool)'), self.set_bg_black)
        QtCore.QObject.connect(actionWhite, QtCore.SIGNAL('triggered(bool)'), self.set_bg_white)

        world = World()
        world.register_listener(self)

        self._actions = [["Viewer", "Zoom", actionResetZoom, 0],
                         ["Viewer", "Zoom", actionZoomOut, 0],
                         ["Viewer", "Zoom", actionZoomIn, 0],
                         ["Viewer", "Zoom", self.actionAutoFocus, 0],
                         ["Viewer", "Camera", actionShowAxis, 0],
                         ["Viewer", "Camera", actionShowGrid, 0],
                         ["Viewer", "Camera", actionRadius, 0],
                         ["Viewer", "Camera", actionBlack, 0],
                         ["Viewer", "Camera", actionWhite, 0],
                         #["Viewer", "Informations", actionShowFps, 1]
                         ]