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


Python Console.clear方法代码示例

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


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

示例1: __init__

# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import clear [as 别名]

#.........这里部分代码省略.........
        player_data = player_data[player_name]
        if 'abilities' in player_data:
            starting_abilities = player_data['abilities']
            del player_data['abilities']
        else:
            starting_abilities = []
        player_creature = Golem(self,player_name,**player_data)
        player_creature.raw_color = yamlhelp.load_color(player_creature.raw_color)
        for ability in starting_abilities:
            player_creature.add_ability(ability)
        for bp_name in player_creature.body_parts:
            bp = player_creature.body_parts[bp_name]
            bp = BodyPart(player_creature,bp_name,**bp)
            player_creature.body_parts[bp_name] = bp
            starting_trait_ids = bp.traits
            bp.traits = []
            for trait_id in starting_trait_ids:
                bp.add_trait(self.traits[trait_id],force=True)

        self.player = Player(self, self.next_id(),
                             0, 0, 0, False, True,
                             input_handler = InputHandler(),
                             creature = player_creature)
        self.add_entity(self.player)

        for name in self.materials:
            self.player.materials[self.materials[name]] = 0
        for ability in self.abilities.values():
            self.player.add_observer(ability)
            ability.add_observer(self.player.input_handler)
        for word_id in self.words:
            self.player.words.append(self.words[word_id])

    def clear_all(self):
        for entity in self.entities:
            entity.clear(self.player.x,
                        self.player.y,
                        self.map_con)

    def get_entity(self,entity_id):
        for entity in self.entities:
            if entity.entity_id == entity_id:
                return entity

    def get_creature_at(self,x,y):
        return self.cur_level.get_tile(x,y).creature
    def get_item_at(self,x,y):
        return self.cur_level.get_tile(x,y).item

    def render_panel(self):
        self.panel_con.clear()
        self.panel_con.draw_border(True,C_BORDER,C_BORDER_BKGND)

        y = 2
        if SHOW_FPS:
            x=2
            self.panel_con.set_default_foreground(C_MENU)
            self.panel_con.print_string(x,y,'FPS: %i'%self.fps)
            y += 1

        y += 1
        for part_name in ['Head','Torso','L Arm','R Arm','L Leg','R Leg']:
            part = self.player.creature.body_parts[part_name]
            part_name = '%s:'%part.name
            part_health = '%i/%i'%(part.health,part.max_health)
            x = 2
开发者ID:mscottmoore16,项目名称:golemrl,代码行数:70,代码来源:game.py

示例2: MainWindow

# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import clear [as 别名]
class MainWindow(QMainWindow):
    
	def __init__(self, parent=None):
		super(MainWindow, self).__init__(parent)
		#icon = QIcon("logo.png")
		#self.setWindowIcon(icon)
		self.setWindowTitle("LiveHack by nAkoustix v0.1")
		
		#pal = self.palette()
		#pal.setColor(QPalette.Base, Qt.black)
		#pal.setColor(QPalette.Text, Qt.green)
		#self.setPalette(pal)
		#self.setAutoFillBackground(True)
		
		self.console = Console(self)
		self.lay = QGridLayout()
		self.lay.addWidget(self.console, 0,0)
        
		cw = QWidget(self)
		cw.setLayout(self.lay)
		self.setCentralWidget(cw)
		
		self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
		self.socket.setblocking(0)
		self.localAddr = ("localhost", 9001)
		self.socket.bind(self.localAddr)
		
		self.socksend = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
		self.remoteAddr = ("localhost", 9000)
		
		self.buffer = []
		self.indentation = 0
		
		self.readTimer = QTimer(self)
		self.readTimer.timeout.connect(self.readData)
		
		self.console.newLine.connect(self.interpretLine)
		self.console.indentationPlus.connect(self.indentPlus)
		self.console.indentationMinus.connect(self.indentMinus)
		
		self.readTimer.start(50)
		
		self.console.makePrompt()
		
	def indentPlus(self):
		print("indent +")
		self.indentation += 1
		
	def indentMinus(self):
		print("indent -")
		self.indentation -= 1
		
	def interpretLine(self, line):
		if line[:3] != ">>>" and line[:3] != "...":
			self.console.putData("\n")
			self.console.makePrompt()
			return
		line = line[4:]
		if line[:1] == "!":
			line = line[1:]
#-- Escape chars ----------------------
			print("Escape char!")
			if line == "knock":
				print("knock, knock, knocking on Liiives door...")
				self.console.putData("\n\\0/ - Client says:\t\"Knock knock.. Hi Live! may I come in?\"")
				self.socksend.sendto("!knock".encode("utf-8"), self.remoteAddr)
			elif line == "clear":
				self.socksend.sendto("!clear".encode("utf-8"), self.remoteAddr)
				self.clear()
				self.console.clear()
			elif line == "exit":
				print("Bye!!")
				self.exitTimer = QTimer(self)
				self.console.putData("\nBye!!")
				#self.exitTimer.timeout.connect(QCoreApplication.instance.quit)
				self.exitTimer.timeout.connect(self.close)
				self.exitTimer.start(800)
				#QCoreApplication.instance().quit()
			else:
				self.console.putData("\nUnknown escape sequence!")
				self.makePrompt()
			self.clear()
			return
		self.buffer += [line]
		#self.console.addToCmdHistory(line)
#-- Editor behaviour ------------------
		if line[-1:] == ":":
			self.console.putData("\n")
			self.indentation += 1
			self.console.makeExtendedPrompt(self.indentation)
			print(": found")
			print("line")
			#debug("1");
		else:
			self.console.putData("\n")
			if self.indentation == 0:
				self.execute()
				self.console.makePrompt()
				#debug("2");
			else:
#.........这里部分代码省略.........
开发者ID:nakoustix,项目名称:LiveHack,代码行数:103,代码来源:liveterm.py


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