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


Python Scene.key_pressed方法代码示例

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


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

示例1: App

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import key_pressed [as 别名]
class App(object):
    """Application main class"""

    def __init__(self):

        self._init_keyboard()

        self.near = 1
        self.fov = 60

        builder = gtk.Builder()
        builder.add_from_file(ui_file)

        glconfig = self.init_glext()

        self.drawing_area = GLDrawingArea(glconfig)
        self.drawing_area.set_events(
            gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.BUTTON1_MOTION_MASK
        )
        self.drawing_area.set_size_request(800, 800)

        self.box3d = builder.get_object("hbox_3d")

        builder.get_object("vbox4").pack_start(self.drawing_area)

        win_main = builder.get_object("win_main")

        win_main.set_events(gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK)

        win_main.connect("key-press-event", self._on_key_pressed)
        win_main.connect("key-release-event", self._on_key_released)

        win_main.show_all()
        self.box3d.hide()

        width = self.drawing_area.allocation.width
        height = self.drawing_area.allocation.height
        ratio = float(width) / float(height)

        self.scene = Scene(self.fov, ratio, self.near)
        self.drawing_area.add(self.scene)

        builder.connect_signals(self)

        self.statbar = builder.get_object("statbar")

        self.drawing_area.connect("motion_notify_event", self._on_mouse_motion)
        self.drawing_area.connect("button_press_event", self._on_button_pressed)
        self.drawing_area.connect("configure_event", self._on_reshape)
        self.drawing_area.connect_after("expose_event", self._after_draw)

        self.rbut_trans = builder.get_object("rbut_trans")
        self.rbut_isoscale = builder.get_object("rbut_isoscale")
        self.rbut_scale = builder.get_object("rbut_scale")
        self.rbut_rotate = builder.get_object("rbut_rotate")

        self.rbut_xy = builder.get_object("rbut_xy")
        self.rbut_xz = builder.get_object("rbut_xz")
        self.rbut_yz = builder.get_object("rbut_yz")

        self.sp_fov = builder.get_object("sp_fov")
        self.sp_fov.set_value(self.fov)

        self.sp_near = builder.get_object("sp_near")
        self.sp_near.set_value(self.near)

        self.sp_pos_x = builder.get_object("sp_pos_x")
        self.sp_pos_y = builder.get_object("sp_pos_y")
        self.sp_pos_z = builder.get_object("sp_pos_z")
        self.sp_look_x = builder.get_object("sp_look_x")
        self.sp_look_y = builder.get_object("sp_look_y")
        self.sp_look_z = builder.get_object("sp_look_z")

        self.on_but_pos_appyly_clicked(None)

        self.tbut_add_c0 = builder.get_object("tbut_add_c0")
        self.tbut_add_c2 = builder.get_object("tbut_add_c2")
        self.tbut_add_inter = builder.get_object("tbut_add_interpolation")
        self.tbut_del_curve = builder.get_object("tbut_del_curve")
        self.tbut_sel_curve = builder.get_object("tbut_sel_curve")

        self.tbut_add_surf_c0 = builder.get_object("tbut_add_surf_c0")
        self.tbut_add_surf_c2 = builder.get_object("tbut_add_surf_c2")
        self.tbut_add_pipe = builder.get_object("tbut_add_pipe")
        self.tbut_add_gregory = builder.get_object("tbut_add_gregory")

        self.tbut_cut = builder.get_object("tbut_cut_choose")
        self.cbox_first = builder.get_object("cbox_first")
        self.cbox_second = builder.get_object("cbox_second")
        self.sp_delta = builder.get_object("sp_cut_delta")
        self.sp_cut_u1 = builder.get_object("sp_cut_u1")
        self.sp_cut_v1 = builder.get_object("sp_cut_v1")
        self.sp_cut_u2 = builder.get_object("sp_cut_u2")
        self.sp_cut_v2 = builder.get_object("sp_cut_v2")

        cell = gtk.CellRendererText()
        self.cbox_first.pack_start(cell, True)
        self.cbox_first.add_attribute(cell, "text", 0)
        cell = gtk.CellRendererText()
        self.cbox_second.pack_start(cell, True)
#.........这里部分代码省略.........
开发者ID:jkotur,项目名称:Torrusador,代码行数:103,代码来源:torrusador.py

示例2: App

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import key_pressed [as 别名]
class App(object):
	"""Application main class"""

	def __init__(self):

		self.move = [0,0,0]

		self.dirskeys = ( ( ['w'] , ['s'] ) , ( ['a'] , ['d'] ) , ( ['e'] , ['q'] ) )

		for d in self.dirskeys :
			for e in d :
				for i in range(len(e)) : e[i] = ( gtk.gdk.unicode_to_keyval(ord(e[i])) , False )

		self.near = 1
		self.far = 1000
		self.fov  = 60

		builder = gtk.Builder()
		builder.add_from_file(ui_file)

		glconfig = self.init_glext()

		self.drawing_area = GLDrawingArea(glconfig)
		self.drawing_area.set_events( gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.BUTTON3_MOTION_MASK )
		self.drawing_area.set_size_request(640,480)

		builder.get_object("vbox1").pack_start(self.drawing_area)
		self.tb_run = builder.get_object("tb_run")
		self.sp_xb = builder.get_object("sp_xb")
		self.sp_xe = builder.get_object("sp_xe")
		self.sp_yb = builder.get_object("sp_yb")
		self.sp_ye = builder.get_object("sp_ye")
		self.sp_zb = builder.get_object("sp_zb")
		self.sp_ze = builder.get_object("sp_ze")

		self.sp_ms = builder.get_object("sp_miller_size")
		self.cb_m  = builder.get_object("cb_miller")

		self.pbar  = builder.get_object("pbar")

		win_main = builder.get_object("win_main")

		win_main.set_events( gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK )

		self.nosetdrill = False

		win_main.connect('key-press-event'  , self._on_key_pressed  )
		win_main.connect('key-release-event', self._on_key_released )

		win_main.show_all()

		width = self.drawing_area.allocation.width
		height = self.drawing_area.allocation.height
		ratio = float(width)/float(height)

		self.scene = Scene( self.fov , ratio , self.near , self.far , meshes )
		self.scene.set_speed( builder.get_object("sp_spd").get_value() )

		self.drawing_area.add( self.scene )

		builder.connect_signals(self)

		self.drawing_area.connect('motion_notify_event',self._on_mouse_motion)
		self.drawing_area.connect('button_press_event',self._on_button_pressed)
		self.drawing_area.connect('configure_event',self._on_reshape)
		self.drawing_area.connect_after('expose_event',self._after_draw)

		gtk.timeout_add( 1 , self._refresh )

		self.pbar.set_visible(False)

	def _refresh( self ) :
		self.drawing_area.queue_draw()
		return True

	def _after_draw( self , widget , data=None ) :
		self.update_statusbar()

	def update_statusbar( self ) :
		pass

	def _on_reshape( self , widget , data=None ) :
		width = self.drawing_area.allocation.width
		height = self.drawing_area.allocation.height

		ratio = float(width)/float(height)

		self.scene.set_screen_size( width , height )

	def _on_button_pressed( self , widget , data=None ) :
		if data.button == 3 :
			self.mouse_pos = data.x , data.y
		self.drawing_area.queue_draw()

	def _on_mouse_motion( self , widget , data=None ) :
		diff = map( op.sub , self.mouse_pos , (data.x , data.y) )

		self.scene.mouse_move( diff )

		self.mouse_pos = data.x , data.y
#.........这里部分代码省略.........
开发者ID:jkotur,项目名称:miller_simulator,代码行数:103,代码来源:c3sim.py

示例3: App

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import key_pressed [as 别名]
class App(object):
	"""Application main class"""

	def __init__(self):

		self.move = [0,0,0]

		self.dirskeys = ( ( ['w'] , ['s'] ) , ( ['a'] , ['d'] ) , ( ['e'] , ['q'] ) )

		for d in self.dirskeys :
			for e in d :
				for i in range(len(e)) : e[i] = ( gtk.gdk.unicode_to_keyval(ord(e[i])) , False )

		self.near = 1
		self.far = 1000
		self.fov  = 60

		builder = gtk.Builder()
		builder.add_from_file(ui_file)

		glconfig = self.init_glext()

		self.drawing_area = GLDrawingArea(glconfig)
		self.drawing_area.set_events( gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.MOTION_NOTIFY | gtk.gdk.BUTTON1_MOTION_MASK | gtk.gdk.BUTTON3_MOTION_MASK )
		self.drawing_area.set_size_request(320,240)

		builder.get_object("vbox1").pack_start(self.drawing_area)

		win_main = builder.get_object("win_main")
		self.sp_l1 = builder.get_object("sp_l1")
		self.sp_l2 = builder.get_object("sp_l2")

		win_main.set_events( gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK )

		win_main.connect('key-press-event'  , self._on_key_pressed  )
		win_main.connect('key-release-event', self._on_key_released )

		self.scene = Scene( )

		self.scene.set_robot_params( self.sp_l1.get_value() , self.sp_l2.get_value() )

		self.drawing_area.add( self.scene , ( 0,0,1,1) )
#        self.drawing_area.add( self.scene , (.5,0,.5,1) )

		print 'Scene added'

		win_main.show_all()

		width = self.drawing_area.allocation.width
		height = self.drawing_area.allocation.height

		self.scene.set_screen_size( width , height )

		builder.connect_signals(self)

#        self.statbar = builder.get_object('statbar')

		self.drawing_area.connect('motion_notify_event',self._on_mouse_motion)
		self.drawing_area.connect('button_press_event',self._on_button_pressed)
		self.drawing_area.connect('button_release_event',self._on_button_released)
		self.drawing_area.connect('configure_event',self._on_reshape)
		self.drawing_area.connect_after('expose_event',self._after_draw)

		gtk.timeout_add( 1 , self._refresh )

	def _refresh( self ) :
		self.drawing_area.queue_draw()
		return True

	def _after_draw( self , widget , data=None ) :
		self.update_statusbar()

	def update_statusbar( self ) :
		pass

	def _on_reshape( self , widget , data=None ) :
		width = self.drawing_area.allocation.width
		height = self.drawing_area.allocation.height

		ratio = float(width)/float(height)

		self.scene.set_screen_size( width , height )

	def _on_button_pressed( self , widget , data=None ) :
		if data.button in (1,3) :
			self.mouse_pos = data.x , data.y
		self.scene.mouse_but_pressed( data.button , (data.x,data.y) )
		self.drawing_area.queue_draw()

	def _on_button_released( self , widget , data=None ) :
		self.scene.mouse_but_released( data.button , (data.x,data.y) )
		self.drawing_area.queue_draw()

	def _on_mouse_motion( self , widget , data=None ) :
		diff = map( op.sub , self.mouse_pos , (data.x , data.y) )

		self.scene.mouse_move( diff , (data.x,data.y) )

		self.mouse_pos = data.x , data.y
		self.drawing_area.queue_draw()
#.........这里部分代码省略.........
开发者ID:jkotur,项目名称:pathfinder,代码行数:103,代码来源:pathfinder.py

示例4: App

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import key_pressed [as 别名]
class App(object):
	"""Application main class"""

	def __init__(self):

		self._init_keyboard()

		self.near = .01 
		self.far  = 10
		self.fov  = 60

		builder = gtk.Builder()
		builder.add_from_file(ui_file)

		glconfig = self.init_glext()

		self.drawing_area = GLDrawingArea(glconfig)
		self.drawing_area.set_events( gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.BUTTON3_MOTION_MASK )
		self.drawing_area.set_size_request(800, 800)

		builder.get_object("vbox1").pack_start(self.drawing_area)

		self.scene = Scene( self.fov , 1 , self.near , self.far , self._load_cube_img(skybox_files) , self._load_img(duck_file) )
		self.drawing_area.add( self.scene )

		win_main = builder.get_object("win_main")

		win_main.connect('key-press-event'  , self._on_key_pressed  )
		win_main.connect('key-release-event', self._on_key_released )

		win_main.show_all()

		width = self.drawing_area.allocation.width
		height = self.drawing_area.allocation.height
		ratio = float(width)/float(height)

		self.scene.set_ratio( ratio )

		builder.connect_signals(self)

		self.statbar = builder.get_object('statbar')

		self.drawing_area.connect('motion_notify_event',self._on_mouse_motion)
		self.drawing_area.connect('button_press_event',self._on_button_pressed)
		self.drawing_area.connect('configure_event',self._on_reshape)
		self.drawing_area.connect_after('expose_event',self._after_draw)

		gtk.timeout_add( 1 , self._refresh )

	def _init_keyboard( self ) :
		self.move = [0,0,0]
		self.dirskeys = ( ( ['w'] , ['s'] ) , ( ['a'] , ['d'] ) , ( ['e'] , ['q'] ) )

		for d in self.dirskeys :
			for e in d : 
				for i in range(len(e)) : e[i] = ( gtk.gdk.unicode_to_keyval(ord(e[i])) , False )

	def _on_key_pressed( self , widget , data=None ) :
		if not any(self.move) :
			gtk.timeout_add( 20 , self._move_callback )
						  
		for i in range(len(self.dirskeys)) :
			if (data.keyval,False) in self.dirskeys[i][0] :
				self.dirskeys[i][0][ self.dirskeys[i][0].index( (data.keyval,False) ) ] = (data.keyval,True)
				self.move[i]+= 1
			elif (data.keyval,False) in self.dirskeys[i][1] :
				self.dirskeys[i][1][ self.dirskeys[i][1].index( (data.keyval,False) ) ] = (data.keyval,True)
				self.move[i]-= 1

	def _on_key_released( self , widget , data=None ) :
		for i in range(len(self.dirskeys)) :
			if (data.keyval,True) in self.dirskeys[i][0] :
				self.dirskeys[i][0][ self.dirskeys[i][0].index( (data.keyval,True) ) ] = (data.keyval,False)
				self.move[i]-= 1
			elif (data.keyval,True) in self.dirskeys[i][1] :
				self.dirskeys[i][1][ self.dirskeys[i][1].index( (data.keyval,True) ) ] = (data.keyval,False)
				self.move[i]+= 1

	def _move_callback( self ) :
		self.scene.key_pressed( self.move )
		self.drawing_area.queue_draw()
		return any(self.move)

	def _refresh( self ) :            
		self.drawing_area.queue_draw()
		return True    

	def _after_draw( self , widget , data=None ) :
		self.update_statusbar()

	def update_statusbar( self ) :
		pass

	def _on_reshape( self , widget , data=None ) :
		width = self.drawing_area.allocation.width
		height = self.drawing_area.allocation.height

		ratio = float(width)/float(height)

		self.scene.set_screen_size( width , height )
#.........这里部分代码省略.........
开发者ID:jkotur,项目名称:duck,代码行数:103,代码来源:duck.py


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