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


Python ScrolledText.scan_mark方法代码示例

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


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

示例1: skulltagBotWindow

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import scan_mark [as 别名]
class skulltagBotWindow(Frame):
	def __init__(self, args='', parent=None):
		Frame.__init__(self, parent)
		
		self.args = args
		self.flags = [0,0,0,0,0]
		self.history = []
		self.players = {'amount': 0}
		self.historyMarker = 0
		self.playerinfoRE = re.compile("([0-9]+)\. ([^%]+?) - IP \(([0-9\.]+:[0-9]+)\)")
		
		for flag, index in (('+dmflags', 0), ('+dmflags2', 1), ('+dmflags3', 2), ('+compatflags', 3), ('+compatflags2', 4)):
			if flag in self.args:
				try:
					self.flags[index] = int(self.args[self.args.index(flag)+1])
				except:
					pass
		
		self.outputText = ScrolledText()
		self.outputText.config(state=DISABLED)
		self.outputText.pack(expand=1, fill='both', anchor='n')
		self.inputTextText = StringVar()
		self.inputText = Entry(textvariable=self.inputTextText)
		self.inputText.bind('<Return>', self.writeLine)
		self.inputText.bind('<Up>', self.upOneHist)
		self.inputText.bind('<Down>', self.downOneHist)
		self.inputText.pack(fill='x', anchor='s')
		self.outputText.tk.call('tk', 'scaling', 1)
		
		self.outputQueue = Queue.Queue()		# just to be orderly
		self.inputQueue = Queue.Queue()			# same
		self.inQLock = thread.allocate_lock()	# well durrrrrr
		self.outQLock = thread.allocate_lock()
		
		thread.start_new(self.startSkulltag, (None,))
		
		self.pack()
	
	def startSkulltag(self, deadArg):
		self.skulltag = subprocess.Popen(['/usr/games/skulltag/skulltag-server', '+sv_markchatlines 1']+self.args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=0)
		self.stdinPoll = select.poll()
		self.stdinPoll.register(self.skulltag.stdout, select.POLLIN)
		self.stdoutPoll = select.poll()
		self.stdoutPoll.register(self.skulltag.stdout, select.POLLOUT)
		thread.start_new(self.rwLoop, (None,))
	
	def rwLoop(self, deadArg):
		self.readLine()
		try:										#check for input
			output = self.inputQueue.get(block=0)
		except Queue.Empty:
			pass
		else:
			self.inQLock.acquire()
			self.outputText.config(state=NORMAL)
			self.outputText.insert(END, output)		#put it in the main window
			self.outputText.scan_mark(100000, 1)
			self.outputText.scan_dragto(10, 1)
			try:
				lscbot = stbehaviour.LSCParserBot(output, copy.deepcopy(self.players), *self.flags[:])
				chatText = lscbot.get()
						
				if chatText[0]:
					self.skulltag.stdin.flush()
					self.skulltag.stdin.write("say " + chatText[0] + '\n')
				
				self.flags = chatText[2:]
			except:
				import traceback
				print "%s\n%s" % (sys.exc_info()[0], sys.exc_info()[1])
				print traceback.print_tb(sys.exc_info()[2])
				self.cquit()
			self.outputText.config(state=DISABLED)
			self.inQLock.release()
		
		try:										#now for output
			output = self.outputQueue.get(block=0)
		except Queue.Empty:
			pass
		else:
			self.outQLock.acquire()
			self.skulltag.stdin.write(output)
			self.skulltag.stdin.flush()
			self.outQLock.release()
		self.after(5, self.rwLoop, (None,))
	
	def readLine(self):
		output = ''
		scrollAmount = 0
		if self.skulltag.poll():
			output = '\n\n - Terminated - '
			sys.exit()
		else:
			pollin = self.stdinPoll.poll(1)
			while pollin:
				pollin = pollin[0]
				if pollin[1] == 1:
					self.skulltag.stdout.flush()
					output += self.skulltag.stdout.readline()
					scrollAmount += 1
#.........这里部分代码省略.........
开发者ID:IjonTichy,项目名称:PythonTidbits,代码行数:103,代码来源:sttest.py


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