当前位置: 首页>>代码示例>>Python>>正文


Python Gui.stop方法代码示例

本文整理汇总了Python中gui.Gui.stop方法的典型用法代码示例。如果您正苦于以下问题:Python Gui.stop方法的具体用法?Python Gui.stop怎么用?Python Gui.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gui.Gui的用法示例。


在下文中一共展示了Gui.stop方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: App

# 需要导入模块: from gui import Gui [as 别名]
# 或者: from gui.Gui import stop [as 别名]

#.........这里部分代码省略.........
		settings.update(kwargs)
		trialDir = "{0}_{1}_{2}".format(time.strftime("%y%m%d%H%M%S"),
				settings['experimentName'], settings['stimulator']['activeProtocolName'])
		settings['outputDataDir'] = os.path.join(settings['outputRootDir'], trialDir)
		self.keyBindings = settings['keyBindings']
		self.keycodeBindings = {k: getattr(opencvgui.keycodes, v)
				for k,v in self.keyBindings.items() }
		os.makedirs(os.path.join(settings['outputDataDir'], 'audio'))
		self.writeExperimentData(settings)
		for x in ['audio', 'videoOut', 'writer']:
			kwargs[x] = {} if not kwargs.has_key(x) else kwargs[x]
			kwargs[x]['outputDataDir'] = settings['outputDataDir']

		# gui and writer both need a reference to the app instance because they
		# draw on the state of so many other controllers
		self.audio = Audio(**settings['audio'])
		self.gui = Gui(self, **settings['gui'])
		self.stimulator = Stimulator(**settings['stimulator'])
		self.tracker = Tracker(**settings['tracker'])
		self.videoIn = VideoIn(**settings['videoIn'])
		self.videoOut = VideoOut(**settings['videoOut'])
		self.writer = Writer(self, **settings['writer'])

	def run(self):
		"""Respond to user input and run the master application loop.

		This method has three basic sections. Before the loop starts, the start()
		method is called on all controllers. The central loop calls update() on
		each controller until it is terminated by a user-issued quit keystroke.
		Keystrokes are listened for at the start of each loop iteration.
		"""
		self.printKeybindings()
		self.startTime = self.lastTime = time.clock()
		self.audio.start()
		self.gui.start()
		self.stimulator.start()
		self.tracker.start()
		self.videoIn.start()
		self.videoOut.start()
		self.writer.start()

		while True:

			# respond to user input
			lastKeyStroke = cv2.waitKey(20)  # 20 is the number of ms to wait for key
			if lastKeyStroke != -1: # -1 means there was no keystroke
				if lastKeyStroke == self.keycodeBindings['quit']:
					break
				if lastKeyStroke == self.keycodeBindings['triggerStimulator']:
					self.stimulator.trigger()
				if lastKeyStroke == self.keycodeBindings['toggleStimulator']:
					self.stimulator.toggle()

			# update state
			self.currTime = time.clock()
			self.totalTimeElapsed = self.currTime - self.startTime
			self.audio.update()
			self.videoIn.update()
			self.tracker.update(self.videoIn, self.currTime)
			self.stimulator.update(self.currTime, self.tracker)
			self.videoOut.update(self.videoIn, self.tracker, self.stimulator)
			self.gui.update()
			self.lastTime = self.currTime
			self.writer.update()

		# closing
		self.audio.stop()
		self.videoIn.stop()
		self.videoOut.stop()
		self.gui.stop()
		self.stimulator.stop()
		self.tracker.stop()
		self.writer.stop()

	def writeExperimentData(self, settings, console=True):
		"""Write experiment metadata to a file in the output directory.
		
		Args:
			settings: The full settings dictionary passed to the App's __init__
			console: Optional. Boolean. Also print experiment data to console.
		"""
		with open(os.path.join(settings['outputDataDir'], 'experiment.txt'), 'w') as f:
			lines = [
					"name: " + settings['experimentName'],
					"date: " + time.strftime("%m/%y/%d"),
					"time: " + time.strftime("%H:%M"),
					"protocol: "  + settings['stimulator']['activeProtocolName'],
					str(settings['stimulator']['protocols'][settings['stimulator']['activeProtocolName']])
					]
			f.write("\n".join(lines))
			f.close()
		if console:
			print "\n".join(lines)
	
	def printKeybindings(self):
		"""Print the available keyboard commands to the terminal."""
		print "Key Bindings:"
		for k,v in self.keyBindings.items():
			print "{0}: {1}".format(k,v)
		print ""
开发者ID:smackesey,项目名称:kaufer_prosocial,代码行数:104,代码来源:app.py


注:本文中的gui.Gui.stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。