本文整理汇总了Python中kivy.uix.relativelayout.RelativeLayout.remove_widget方法的典型用法代码示例。如果您正苦于以下问题:Python RelativeLayout.remove_widget方法的具体用法?Python RelativeLayout.remove_widget怎么用?Python RelativeLayout.remove_widget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.uix.relativelayout.RelativeLayout
的用法示例。
在下文中一共展示了RelativeLayout.remove_widget方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import remove_widget [as 别名]
class Region:
def __init__(self, loader, region_config):
self.loader = loader
self.widget = RelativeLayout()
self.objects = set()
for tile in region_config.tiles:
self.widget.add_widget(tile.image)
for ID in region_config.object_IDs:
self.load_object(ID)
self._to_cleanup = []
def update(self, dt):
for obj in self.objects:
obj.signals.update.send(dt)
while self._to_cleanup:
obj = self._to_cleanup.pop()
self.objects.remove(obj)
# TODO consider using weakref.finalize
try:
self.widget.remove_widget(obj.widget._kivy_widget)
except AttributeError:
pass
def load_object(self, ID):
obj = self.loader.load(ID)
obj.signals.destroy.connect(self.cleanup)
self.objects.add(obj)
try:
# TODO clean up this widget stuff
self.widget.add_widget(obj.widget._kivy_widget)
except AttributeError:
pass
def cleanup(self, obj):
self._to_cleanup.append(obj)
示例2: BiscuitsApp
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import remove_widget [as 别名]
class BiscuitsApp(App):
def __init__(self):
super().__init__()
self.widget = RelativeLayout()
self._scene = None
self.input = Input()
self.game = BiscuitsGame(self)
@property
def scene(self):
return self._scene
@scene.setter
def scene(self, scene):
if self._scene:
self._scene.unload()
self.widget.remove_widget(self._scene.widget)
self._scene = scene
self.widget.add_widget(scene.widget)
def load_scene(self, loadpoint_ID):
loadpoint = loadpoints[loadpoint_ID]
if loadpoint.type == 'dead':
self.scene = DeadScene(self)
elif loadpoint.type == 'start':
self.scene = StartScene(self)
elif loadpoint.type == 'comic':
self.scene = ComicScene(self, loadpoint)
else:
self.scene = self.game.load(loadpoint)
def update(self, dt):
self.input.update(dt)
self.scene.update(dt)
def build(self):
EventLoop.ensure_window()
self.load_scene('Loadpoint 1a')
Clock.schedule_interval(self.update, 1.0 / 60.0)
return self.widget
示例3: KYRScreen
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import remove_widget [as 别名]
class KYRScreen(Screen):
spriteList = ListProperty()
locationEvent = DictProperty() # all location-based events for the room, including room changes
player = ObjectProperty()
isCurrent = BooleanProperty(False)
playerLocation = ListProperty((200,200))
bg = StringProperty()
music = ObjectProperty()
startLocations = DictProperty()
direction = StringProperty('top')
def __init__(self, **kwargs):
super(KYRScreen, self).__init__(**kwargs)
self.field = RelativeLayout()
#sprites = self.loadSprites()
#self.buildSprites(sprites)
def on_isCurrent(self, instance, value):
if value:
self.turnOn()
else:
self.turnOff()
def turnOn(self):
print 'turning on {}'.format(self)
self.getStartLocation()
self.buildPlayer(self.playerLocation)
self.loadBackground()
self.loadWidgets()
self.toggleMusic('on')
def turnOff(self):
print 'turning off {}'.format(self)
self.parent.playerLocation = self.playerLocation
self.unloadWidgets()
self.toggleMusic('off')
def getStartLocation(self):
self.playerLocation = self.startLocations[self.direction]
def loadBackground(self):
print 'loading bg', self.bg
tex = CImage.load(self.bg, keep_data=True).texture
self.buildBackground(tex)
def buildBackground(self, tex):
with self.field.canvas.before:
Rectangle(texture = tex, pos=(0,0), size=(1024,512))
def loadWidgets(self):
self.add_widget(self.field)
def unloadWidgets(self):
self.field.remove_widget(self.player)
self.remove_widget(self.field)
def toggleMusic(self, value):
if value == 'on':
if self.music:
print("Sound found at %s" % self.music.source)
print("Sound is %.3f seconds" % self.music.length)
self.music.loop = True
self.music.play()
elif value == 'off':
if self.music:
self.music.stop()
def changePlayerImage(self, direction):
if direction == 'up':
self.player.source = 'assets/art/Clyde_up.zip'
elif direction == 'down':
self.player.source = 'assets/art/Clyde_down.zip'
elif direction == 'left':
self.player.source = 'assets/art/Clyde_left.zip'
elif direction == 'right':
self.player.source = 'assets/art/Clyde_right.zip'
def on_transition_state(self, instance, value):
pass
def buildPlayer(self, playerLocation):
self.player = AGSprite(source = 'assets/art/brandon-right.zip', size=(96,192))
#self.player.anim_delay = (-1)
self.player.pos = playerLocation
self.field.add_widget(self.player)
def loadSprites(self):
# look in sprite list for sprite in specific room, return sprite list for room
directory = {'room number': 'sprite list'}
sprites = directory['room number']
return sprites
def buildSprites(self, sprites):
for sprite in sprites:
self.field.add_widget(sprite)
self.spriteList.append(sprite)
def checkCollision(self):
#.........这里部分代码省略.........
示例4: MapLayout
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import remove_widget [as 别名]
class MapLayout(RelativeLayout):
currentSize = 0
sizeOption = (1, 2, 4)
def __init__(self, **kwargs):
super(MapLayout, self).__init__(**kwargs)
self.mainContainer = RelativeLayout(size_hint=(None, None), size=mainWindowSize)
self.mainContainer.currentSize = self.currentSize
self.mainContainer.sizeOption = self.sizeOption
self.filterContainer = RelativeLayout(size_hint=(None, None), size=mainWindowSize)
self.mapBound = ScrollView(size_hint=(None, None), size=mainWindowSize)
self.MapArray = []
self.MapArray.append(Image(source="peta/content/Base Map 1.png", allow_stretch=True))
self.MapArray.append(Image(source="peta/content/Base Map 2.png", allow_stretch=True))
self.MapArray.append(Image(source="peta/content/Base Map 3.png", allow_stretch=True))
self.FilterArray = []
self.FilterArray.append(Image(source="peta/content/peta-batas-wilayah.png", allow_stretch=True, opacity=0.5))
self.FilterArray.append(Image(source="peta/content/peta-jalan.png", allow_stretch=True, opacity=0.5))
self.FilterArray.append(Image(source="peta/content/peta-air-bersih.png", allow_stretch=True, opacity=0.6))
self.FilterArray.append(Image(source="peta/content/peta-gorong-gorong.png", allow_stretch=True, opacity=0.5))
self.FilterArray.append(Image(source="peta/content/peta-sarana-publik.png", allow_stretch=True, opacity=0.9))
self.filterContainer.add_widget(self.FilterArray[0])
self.mainContainer.add_widget(self.MapArray[0])
self.mainContainer.add_widget(self.filterContainer)
self.mapBound.add_widget(self.mainContainer)
def addJalan(self):
# self.mainContainer.add_widget(self.FilterArray[1])
self.filterContainer.add_widget(self.FilterArray[1])
def removeJalan(self):
# self.mainContainer.remove_widget(self.FilterArray[1])
self.filterContainer.remove_widget(self.FilterArray[1])
def addAir(self):
# self.mainContainer.add_widget(self.FilterArray[2])
self.filterContainer.add_widget(self.FilterArray[2])
def removeAir(self):
# self.mainContainer.remove_widget(self.FilterArray[2])
self.filterContainer.remove_widget(self.FilterArray[2])
def addGorong(self):
# self.mainContainer.add_widget(self.FilterArray[3])
self.filterContainer.add_widget(self.FilterArray[3])
def removeGorong(self):
# self.mainContainer.remove_widget(self.FilterArray[3])
self.filterContainer.remove_widget(self.FilterArray[3])
def addSarana(self):
# self.mainContainer.add_widget(self.FilterArray[4])
self.filterContainer.add_widget(self.FilterArray[4])
def removeSarana(self):
# self.mainContainer.remove_widget(self.FilterArray[4])
self.filterContainer.remove_widget(self.FilterArray[4])
def resetMap(self):
self.filterContainer.clear_widgets()
self.mainContainer.clear_widgets()
self.filterContainer.add_widget(self.FilterArray[0])
self.mainContainer.add_widget(self.MapArray[0])
self.mainContainer.add_widget(self.filterContainer)
self.mainContainer.currentSize = 0
anim = Animation(width=mainWindowSize[0], height=mainWindowSize[1], duration=0.01, t="in_out_sine")
anim.start(self.mainContainer)
anim.start(self.filterContainer)
def zoomingIn(self):
if self.mainContainer.currentSize + 1 < len(self.mainContainer.sizeOption):
self.mainContainer.currentSize += 1
anim = Animation(
width=mainWindowSize[0] * self.mainContainer.sizeOption[self.mainContainer.currentSize],
height=mainWindowSize[1] * self.mainContainer.sizeOption[self.mainContainer.currentSize],
duration=0.4,
t="in_out_sine",
)
anim.start(self.mainContainer)
anim.start(self.filterContainer)
if self.mainContainer.currentSize == 1:
self.mainContainer.clear_widgets()
self.mainContainer.add_widget(self.MapArray[1])
self.mainContainer.add_widget(self.filterContainer)
elif self.mainContainer.currentSize == 2:
self.mainContainer.clear_widgets()
self.mainContainer.add_widget(self.MapArray[2])
self.mainContainer.add_widget(self.filterContainer)
# log
gv.logger.log_button("zoom in to :" + str(self.mainContainer.currentSize))
#.........这里部分代码省略.........
示例5: __init__
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import remove_widget [as 别名]
class BiscuitsGame:
def __init__(self, app):
# TODO pretty sure this causes circular references that prevent
# garbage collection of the whole scene
self.app = app
self.world = World()
self.widget = RelativeLayout()
self.objects_layer = RelativeLayout()
object_configs = dict(map.objects)
object_configs['player'] = Config(type='Player',
body=Config(x=0, y=0, w=1, h=1))
scene = WorldScene(object_configs, self.world, app)
self.scene = scene
# TODO figure out a nice way to get rid of this
self.tilewidth = map.tilewidth
self.tileheight = map.tileheight
self.region = None
self.region_cache = {}
player = scene.objects.load('player')
self.player = player
self.world.add(player)
self.hud = HUDWidget(size_hint=(1, .05), pos_hint={'top': 1})
# TODO move debug to app
debug = DebugWidget(player, size_hint=(1, .05))
self.widget.add_widget(self.objects_layer)
self.widget.add_widget(player.widget._kivy_widget)
self.widget.add_widget(self.hud)
self.widget.add_widget(debug)
def load(self, loadpoint):
# Unload the current region
# TODO would be stellar if weak references could account
# for all of this
if self.region:
self.objects_layer.remove_widget(self.region.widget)
for obj in self.region.objects:
# TODO use weakref
self.world.remove(obj)
region_config = loadpoint.region
try:
self.region = self.region_cache[region_config.ID]
except KeyError:
self.region = Region(self.scene.objects, region_config)
self.region_cache[region_config.ID] = self.region
# TODO can use weakref to pass reference to add_widget()?
# would be awesome for maintaining ownership!
self.objects_layer.add_widget(self.region.widget)
self.player.set_position(loadpoint.x, loadpoint.y, loadpoint.direction)
for obj in self.region.objects:
# TODO use weakref
obj.signals.destroy.connect(self.world.remove)
self.world.add(obj)
return self
def update(self, dt):
if self.region:
self.region.update(dt)
self.player.signals.update.send(dt)
self.hud.coins = self.player.coins.balance
self.hud.keys = self.player.keys.balance
self.hud.health = self.player.life.amount
self.track_player()
def unload(self):
pass
def track_player(self):
x = math.floor((self.player.body.bb.x + 0.5) * self.tilewidth)
y = math.floor((self.player.body.bb.y + 0.5) * self.tileheight)
self.objects_layer.x = self.widget.center_x - x
self.objects_layer.y = self.widget.center_y - y
示例6: KivyCardList
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import remove_widget [as 别名]
class KivyCardList(CardList):
def __init__(self, name, player):
super(KivyCardList,self).__init__(name, player)
self.displayed=False
self.lock = threading.Lock()
def initDisplay(self,xpos,ypos,scale,parentlayout,orientation):
self.displayed=True
self.xpos=xpos
self.ypos=ypos
self.scale=scale
self.orientation=orientation
self.layout= RelativeLayout()
parentlayout.add_widget(self.layout)
#self.ipos=(card.image.width*card.scatter.scale)
self.updateDisplay()
def updateDisplay(self):
self.layout.clear_widgets()
offsetx=0
offsety=0
for card in self:
card.scatter.scale=self.scale
card.scatter.pos=(self.xpos+offsetx,self.ypos+offsety)
self.layout.add_widget(card.scatter)
offsetx,offsety=self.getOffset(offsetx,offsety,card,card.scatter.scale)
def moveFrom(self,index,newCardList,newState):
if self.displayed:
card=self[index]
self.layout.remove_widget(card.scatter)
super(KivyCardList,self).moveFrom(index,newCardList,newState)
if self.displayed:
#update remaining cards
offsetx=0
offsety=0
for card in self:
card.scatter.pos=(self.xpos+offsetx,self.ypos+offsety)
offsetx,offsety=self.getOffset(offsetx,offsety,card,card.scatter.scale)
def append(self,card):
#self.lock.acquire()
print card
super(KivyCardList,self).append(card)
if self.displayed:
offsetx,offsety=self.getOffset(0,0,card,self.scale)
offsetx=offsetx*(len(self)-1)
offsety=offsety*(len(self)-1)
card.setDest(self.xpos+offsetx,self.ypos+offsety,self.scale,self,True)
def bringToFront(self):
parent = self.layout.parent
parent.remove_widget(self.layout)
parent.add_widget(self.layout)
def getOffset(self,currentx,currenty,card,scale):
if self.orientation == eLayouts.vertical:
return currentx,currenty-int(card.image.height*scale*0.3)
return currentx+int(card.image.width*scale*0.6),currenty