本文整理汇总了Python中loader.Loader.loadObjects方法的典型用法代码示例。如果您正苦于以下问题:Python Loader.loadObjects方法的具体用法?Python Loader.loadObjects怎么用?Python Loader.loadObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类loader.Loader
的用法示例。
在下文中一共展示了Loader.loadObjects方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test
# 需要导入模块: from loader import Loader [as 别名]
# 或者: from loader.Loader import loadObjects [as 别名]
class Test(unittest.TestCase):
def setUp(self):
self.loader = Loader()
def test_correctly_formatted_input(self):
# use the reload object functionality to load the simulation
# this way the user doesn't have to select the correct file for each simulation
self.loader.filename = 'ballformation.sim'
# the visual library causes tracebacks on exit (on IDLE)
scene.visible = 0
objects, errors = self.loader.loadObjects(True)
self.assertEqual(Loader.OBJECTS_LOADED, errors)
test_value = False
if 'Ball1' in objects.keys():
test_value = True
self.assertEqual(True, test_value)
if 'Ball2' in objects.keys():
test_value = True
self.assertEqual(True, test_value)
if 'Ball3' in objects.keys():
test_value = True
self.assertEqual(True, test_value)
if 'Ball4' in objects.keys():
test_value = True
self.assertEqual(True, test_value)
if 'Ball5' in objects.keys():
test_value = True
self.assertEqual(True, test_value)
if 'Ball6' in objects.keys():
test_value = True
self.assertEqual(True, test_value)
def test_empty_file(self):
scene.visible = 0
self.loader.filename = 'empty_file.sim'
objects, errors = self.loader.loadObjects(True)
self.assertEqual(0, errors)
self.assertEqual(0, len(objects))
def test_invalid_input(self):
# use the reload object functionality to load the simulation
# this way the user doesn't have to select the correct file for each simulation
self.loader.filename = 'broken_file.sim'
# the visual library causes tracebacks on exit
scene.visible = 0
objects, errors = self.loader.loadObjects(True)
self.assertEqual(Loader.ERRORS_OCCURRED, errors)
# check the errors from the errorlog-file
def test_nonexistent_filename(self):
# possible if someone loads a file, then removes the file from the
# computer and hits reload simulation
scene.visible = 0
self.loader.filename = 'nonexistent_file.sim'
objects, errors = self.loader.loadObjects(True)
self.assertEqual(Loader.FILE_NOT_OPENED, errors)
self.assertEqual(None, objects)
示例2: World
# 需要导入模块: from loader import Loader [as 别名]
# 或者: from loader.Loader import loadObjects [as 别名]
#.........这里部分代码省略.........
self.t=clock()
if self.reference is not None:
scene.center = self.reference.position
def setReference(self, reference):
if reference is not None:
self.reference = self.objects[reference]
scene.center = self.reference.position
else:
self.reference = None
scene.center = vector(0,0,0)
def close(self):
self.paused = False
self.end = True
with self.condition:
self.condition.notify()
def addObject(self, astronomical_object, name):
self.lock.acquire()
if name in self.objects:
del self.objects[name]
self.objects[name] = astronomical_object
self.solver.setObjects(self.objects)
self.lock.release()
def getTimeStep(self):
return self.solver.dt
def setTimeStep(self, dt):
self.solver.dt = float(dt)
#def getObject(self, name):
# return self.objects[name]
def clearObjects(self):
self.lock.acquire()
self.objects.clear()
self.lock.release()
def deleteObject(self, name):
self.lock.acquire()
return_value = False
if name in self.objects.keys():
del self.objects[name]
return_value = True
self.lock.release()
return return_value
def showTrails(self, make_trail):
self.make_trail = make_trail
for key in self.objects:
self.objects[key].setTrail(make_trail)
def showVectors(self, show_vectors):
self.show_vectors = show_vectors
for key in self.objects:
self.objects[key].setVectors(show_vectors)
def setVelocityVectorScale(self, scale):
self.velocity_scale = scale*scale*scale
for key in self.objects:
self.objects[key].setVelocityVectorScale(self.velocity_scale)
def setAccelerationGain(self, gain):
self.acceleration_gain = gain*100
if gain==1:
self.acceleration_gain = 1
temp = self.acceleration_scale*self.acceleration_gain
for key in self.objects:
self.objects[key].setAccelerationVectorScale(temp)
def setAccelerationVectorScale(self, scale):
self.acceleration_scale = scale*scale*scale
temp = self.acceleration_scale*self.acceleration_gain
for key in self.objects:
self.objects[key].setAccelerationVectorScale(temp)
def loadSimulation(self, reload_simulation=False):
self.lock.acquire()
self.loader.velocity_factor = self.velocity_scale
self.loader.acceleration_factor = self.acceleration_scale*self.acceleration_gain
temp, self.errors = self.loader.loadObjects(reload_simulation)
if temp:
for key in self.objects:
self.objects[key].setVisible(False)
self.objects.clear()
self.objects = temp
self.solver.setObjects(self.objects)
if self.show_vectors is True:
self.showVectors(True)
if self.make_trail is True:
self.showTrails(True)
self.time_elapsed = 0
self.lock.release()
def reloadSimulation(self):
self.loadSimulation(True)