本文整理汇总了Python中sprites.Sprite.set_label_attributes方法的典型用法代码示例。如果您正苦于以下问题:Python Sprite.set_label_attributes方法的具体用法?Python Sprite.set_label_attributes怎么用?Python Sprite.set_label_attributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sprites.Sprite
的用法示例。
在下文中一共展示了Sprite.set_label_attributes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from sprites import Sprite [as 别名]
# 或者: from sprites.Sprite import set_label_attributes [as 别名]
class Card:
''' Individual cards '''
def __init__(self, scale=1.0):
''' Create the card and store its attributes '''
self.spr = None
self.index = None # Calculated index
self._scale = scale
def create(self, string, attributes=None, sprites=None, file_path=None):
if attributes is None:
if self.spr is None:
self.spr = Sprite(sprites, 0, 0, svg_str_to_pixbuf(string))
else:
self.spr.set_image(svg_str_to_pixbuf(string))
self.index = None
else:
self.shape = attributes[0]
self.color = attributes[1]
self.num = attributes[2]
self.fill = attributes[3]
self.index = self.shape * COLORS * NUMBER * FILLS + \
self.color * NUMBER * FILLS + \
self.num * FILLS + \
self.fill
if self.spr is None:
self.spr = Sprite(sprites, 0, 0, svg_str_to_pixbuf(string))
else:
self.spr.set_image(svg_str_to_pixbuf(string))
if file_path is not None:
self.spr.set_image(load_image(file_path, self._scale), i=1,
dx=int(self._scale * CARD_WIDTH * .125),
dy=int(self._scale * CARD_HEIGHT * .125))
self.spr.set_label_attributes(self._scale * 24)
self.spr.set_label('')
def show_card(self, layer=2000):
''' Show the card '''
if self.spr is not None:
self.spr.set_layer(layer)
self.spr.draw()
def hide_card(self):
''' Hide a card '''
if self.spr is not None:
self.spr.hide()
示例2: Yupana
# 需要导入模块: from sprites import Sprite [as 别名]
# 或者: from sprites.Sprite import set_label_attributes [as 别名]
class Yupana():
def __init__(self, canvas, parent=None, colors=['#A0FFA0', '#FF8080']):
self._activity = parent
self._colors = ['#FFFFFF']
self._colors.append(colors[0])
self._colors.append(colors[1])
self._colors.append('#000000')
self._canvas = canvas
if parent is not None:
parent.show_all()
self._parent = parent
self._canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self._canvas.connect("draw", self.__draw_cb)
self._canvas.connect("button-press-event", self._button_press_cb)
self._width = Gdk.Screen.width()
self._height = Gdk.Screen.height() - (GRID_CELL_SIZE * 1.5)
self._scale = self._width / (20 * DOT_SIZE * 1.1)
self._dot_size = int(DOT_SIZE * self._scale)
self._space = int(self._dot_size / 5.)
self.we_are_sharing = False
self._sum = 0
self._mode = 'ten'
self.custom = [1, 1, 1, 1, 10]
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
Sprite(self._sprites, 0, 0, self._box(self._width, self._height,
color=colors[1]))
self._number_box = Sprite(self._sprites, 0, 0, self._box(
self._width, 2 * self._dot_size, color=colors[1]))
self._number_box.set_label_attributes(48)
self._dots = []
for p in range(SIX):
y = self._height - self._space
Sprite(self._sprites, 0, y, self._line(vertical=False))
x = int(p * self._width / 6) + self._space
y -= self._dot_size
for d in range(3): # bottom of fives row
self._dots.append(
Sprite(self._sprites, x, y,
self._new_dot(self._colors[0])))
self._dots[-1].type = 0 # not set
# self._dots[-1].set_label_color('white')
x += self._dot_size + self._space
x = int((p * self._width / 6.) + self._dot_size / 2.) + self._space
y -= self._dot_size + self._space
for d in range(2): # top of fives row
self._dots.append(
Sprite(self._sprites, x, y,
self._new_dot(self._colors[0])))
self._dots[-1].type = 0 # not set
# self._dots[-1].set_label_color('white')
x += self._dot_size + self._space
y -= self._dot_size
Sprite(self._sprites, 0, y, self._line(vertical=False))
x = int((p * self._width / 6.) + self._dot_size / 2.) + self._space
y -= self._dot_size
for d in range(2): # bottom of threes row
self._dots.append(
Sprite(self._sprites, x, y,
self._new_dot(self._colors[0])))
self._dots[-1].type = 0 # not set
# self._dots[-1].set_label_color('white')
x += self._dot_size + self._space
x = int((p * self._width / 6.) + self._dot_size) + self._space
y -= self._dot_size + self._space
for d in range(1): # top of threes row
self._dots.append(
Sprite(self._sprites, x, y,
self._new_dot(self._colors[0])))
self._dots[-1].type = 0 # not set
# self._dots[-1].set_label_color('white')
x += self._dot_size + self._space
y -= self._dot_size
Sprite(self._sprites, 0, y, self._line(vertical=False))
x = int((p * self._width / 6.) + self._dot_size / 2.) + self._space
y -= self._dot_size
for d in range(2): # twos row
self._dots.append(
Sprite(self._sprites, x, y,
self._new_dot(self._colors[0])))
self._dots[-1].type = 0 # not set
# self._dots[-1].set_label_color('white')
x += self._dot_size + self._space
y -= self._dot_size
Sprite(self._sprites, 0, y, self._line(vertical=False))
x = int((p * self._width / 6.) + self._dot_size) + self._space
#.........这里部分代码省略.........
示例3: Game
# 需要导入模块: from sprites import Sprite [as 别名]
# 或者: from sprites.Sprite import set_label_attributes [as 别名]
class Game():
def __init__(self, canvas, parent=None, path=None):
self._canvas = canvas
self._parent = parent
self._parent.show_all()
self._path = path
self._canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self._canvas.connect("draw", self.__draw_cb)
self._canvas.connect("button-press-event", self._button_press_cb)
self._width = Gdk.Screen.width()
self._height = Gdk.Screen.height()
self._scale = self._width / 1200.
self._target = 0
self._tries = 0
self.level = 0
self._picture_cards = []
self._small_picture_cards = []
self.food_cards = []
self._group_cards = []
self._quantity_cards = []
self._balance_cards = []
self._last_twenty = []
self._background = None
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self._background = Sprite(
self._sprites, 0, 0, GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images','background.png'),
self._width, self._height))
self._background.set_layer(0)
self._background.type = None
self._background.hide()
self.pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images', 'word-box.png'),
int(350 * self._scale), int(100 * self._scale))
for i in range(len(FOOD_DATA) / 4):
FOOD.append([FOOD_DATA[i * 4 + NAME], FOOD_DATA[i * 4 + CALS],
FOOD_DATA[i * 4 + GROUP], FOOD_DATA[i * 4 + IMAGE]])
self.food_cards.append(None)
self._picture_cards.append(None)
for j in range(6):
self._small_picture_cards.append(None)
self.allocate_food(0)
x = 10
dx, dy = self.food_cards[0].get_dimensions()
y = 10
for i in range(len(MYPLATE)):
self.word_card_append(self._group_cards, self.pixbuf)
self._group_cards[-1].type = i
self._group_cards[-1].set_label(MYPLATE[i][0])
self._group_cards[-1].move((x, y))
y += int(dy * 1.25)
y = 10
for i in range(len(QUANTITIES)):
self.word_card_append(self._quantity_cards, self.pixbuf)
self._quantity_cards[-1].type = i
self._quantity_cards[-1].set_label(QUANTITIES[i])
self._quantity_cards[-1].move((x, y))
y += int(dy * 1.25)
y = 10
for i in range(len(BALANCE)):
self.word_card_append(self._balance_cards, self.pixbuf)
self._balance_cards[-1].type = i
self._balance_cards[-1].set_label(BALANCE[i])
self._balance_cards[-1].move((x, y))
y += int(dy * 1.25)
self._smile = Sprite(self._sprites,
int(self._width / 4),
int(self._height / 4),
GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images', 'correct.png'),
int(self._width / 2),
int(self._height / 2)))
self._smile.set_label_attributes(36)
self._smile.set_margins(10, 0, 10, 0)
self._frown = Sprite(self._sprites,
int(self._width / 4),
int(self._height / 4),
GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images', 'wrong.png'),
int(self._width / 2),
int(self._height / 2)))
self._frown.set_label_attributes(36)
self._frown.set_margins(10, 0, 10, 0)
self.build_food_groups()
#.........这里部分代码省略.........
示例4: Game
# 需要导入模块: from sprites import Sprite [as 别名]
# 或者: from sprites.Sprite import set_label_attributes [as 别名]
class Game():
def __init__(self, canvas, parent=None, path=None):
self._canvas = canvas
self._parent = parent
self._parent.show_all()
self._path = path
self._canvas.connect("draw", self.__draw_cb)
self._canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self._canvas.connect("button-press-event", self._button_press_cb)
self._canvas.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
self._canvas.connect("motion-notify-event", self._mouse_move_cb)
self._canvas.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK)
self._canvas.connect('button-release-event', self._button_release_cb)
self._canvas.add_events(Gdk.EventMask.KEY_PRESS_MASK)
self._canvas.connect('key-press-event', self._keypress_cb)
self._canvas.set_can_focus(True)
self._canvas.grab_focus()
self._width = Gdk.Screen.width()
self._height = Gdk.Screen.height()
self._scale = self._width / 1200.
self._first_time = True
self._loco_pos = (0, 0)
self._loco_dim = (0, 0)
self._loco_quadrant = 3
self._drag_pos = [0, 0]
self._counter = 0
self._correct = 0
self._timeout_id = None
self._pause = 200
self._press = None
self._clicked = False
self._dead_key = None
self._waiting_for_delete = False
self._waiting_for_enter = False
self._seconds = 0
self._timer_id = None
self.level = 0
self.score = 0
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self._BG = ['background0.jpg', 'background0.jpg', 'background0.jpg',
'background1.jpg', 'background2.jpg', 'background2.jpg',
'background2.jpg']
self._backgrounds = []
for bg in self._BG:
self._backgrounds.append(Sprite(
self._sprites, 0, 0, GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images', bg),
self._width, self._height)))
self._backgrounds[-1].type = 'background'
self._backgrounds[-1].hide()
self._panel = Sprite(
self._sprites, int(400 * self._scale), int(400 * self._scale),
GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images', 'ventana.png'),
int(720 * self._scale), int(370 * self._scale)))
self._panel.type = 'panel'
self._panel.set_label(LABELS[0])
self._panel.set_label_attributes(20)
self._panel.hide()
self._LOCOS = glob.glob(
os.path.join(self._path, 'images', 'loco*.png'))
self._loco_cards = []
for loco in self._LOCOS:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
loco, int(150 * self._scale), int(208 * self._scale))
self._loco_cards.append(Sprite(self._sprites, 0, 0, pixbuf))
self._loco_cards[-1].type = 'loco'
self._loco_dim = (int(150 * self._scale), int(208 * self._scale))
self._MEN = glob.glob(
os.path.join(self._path, 'images', 'man*.png'))
self._man_cards = []
for loco in self._MEN:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
loco, int(150 * self._scale), int(208 * self._scale))
self._man_cards.append(Sprite(self._sprites, 0, 0, pixbuf))
self._man_cards[-1].type = 'loco'
self._TAUNTS = glob.glob(
os.path.join(self._path, 'images', 'taunt*.png'))
self._taunt_cards = []
for loco in self._TAUNTS:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
loco, int(150 * self._scale), int(208 * self._scale))
self._taunt_cards.append(Sprite(self._sprites, 0, 0, pixbuf))
self._taunt_cards[-1].type = 'loco'
self._GHOSTS = glob.glob(
os.path.join(self._path, 'images', 'ghost*.png'))
self._ghost_cards = []
for loco in self._GHOSTS:
#.........这里部分代码省略.........
示例5: Ball
# 需要导入模块: from sprites import Sprite [as 别名]
# 或者: from sprites.Sprite import set_label_attributes [as 别名]
class Ball():
''' The Bounce class is used to define the ball and the user
interaction. '''
def __init__(self, sprites, filename):
self._current_frame = 0
self._frames = [] # Easter Egg animation
self._sprites = sprites
self.ball = Sprite(self._sprites, 0, 0, svg_str_to_pixbuf(
svg_from_file(filename)))
self.ball.set_layer(3)
self.ball.set_label_attributes(24, vert_align='top')
ball = extract_svg_payload(file(filename, 'r'))
for i in range(8):
self._frames.append(Sprite(
self._sprites, 0, 0, svg_str_to_pixbuf(
svg_header(SIZE[0], SIZE[1], 1.0) + TRANSFORMS[i] +
ball + PUNCTURE + AIR + '</g>' + svg_footer())))
for frame in self._frames:
frame.set_layer(3)
frame.move((0, -SIZE[1])) # move animation frames off screen
def new_ball(self, filename):
''' Create a ball object and Easter Egg animation from an SVG file. '''
self.ball.set_shape(svg_str_to_pixbuf(svg_from_file(filename)))
ball = extract_svg_payload(file(filename, 'r'))
for i in range(8):
self._frames[i].set_shape(svg_str_to_pixbuf(
svg_header(SIZE[0], SIZE[1], 1.0) + TRANSFORMS[i] +
ball + PUNCTURE + AIR + '</g>' + svg_footer()))
def new_ball_from_image(self, filename, save_path):
''' Just create a ball object from an image file '''
if filename == '':
_logger.debug('Image file not found.')
return
try:
pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename)
if pixbuf.get_width() > pixbuf.get_height():
size = pixbuf.get_height()
x = int((pixbuf.get_width() - size) / 2)
else:
size = pixbuf.get_width()
x = int((pixbuf.get_height() - size) / 2)
crop = GdkPixbuf.Pixbuf.new(0, True, 8, size, size)
pixbuf.copy_area(x, 0, size, size, crop, 0, 0)
scale = crop.scale_simple(85, 85, GdkPixbuf.InterpType.BILINEAR)
scale.savev(save_path, 'png', [], [])
self.ball.set_shape(
svg_str_to_pixbuf(generate_ball_svg(save_path)))
except Exception as e:
_logger.error('Could not load image from %s: %s' % (filename, e))
def new_ball_from_fraction(self, fraction):
''' Create a ball with a section of size fraction. '''
r = SIZE[0] / 2.0
self.ball.set_shape(svg_str_to_pixbuf(
svg_header(SIZE[0], SIZE[1], 1.0) +
svg_sector(r, r + BOX[1], r - 1, 1.999 * pi,
COLORS[0], COLORS[1]) +
svg_sector(r, r + BOX[1], r - 1, fraction * 2 * pi,
COLORS[1], COLORS[0]) +
svg_rect(BOX[0], BOX[1], 4, 4, 0, 0, '#FFFFFF', 'none') +
svg_footer()))
def ball_x(self):
return self.ball.get_xy()[0]
def ball_y(self):
return self.ball.get_xy()[1]
def frame_x(self, i):
return self._frames[i].get_xy()[0]
def frame_y(self, i):
return self._frames[i].get_xy()[1]
def width(self):
return self.ball.rect[2]
def height(self):
return self.ball.rect[3]
def move_ball(self, pos):
self.ball.move(pos)
def move_ball_relative(self, pos):
self.ball.move_relative(pos)
def move_frame(self, i, pos):
self._frames[i].move(pos)
def move_frame_relative(self, i, pos):
self._frames[i].move_relative(pos)
def hide_frames(self):
for frame in self._frames:
#.........这里部分代码省略.........
示例6: BBoardActivity
# 需要导入模块: from sprites import Sprite [as 别名]
# 或者: from sprites.Sprite import set_label_attributes [as 别名]
#.........这里部分代码省略.........
media_object = False
mimetype = None
if 'mime_type' in ds.metadata:
mimetype = ds.metadata['mime_type']
if mimetype[0:5] == 'image':
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
ds.file_path, MAXX, MAXY)
# ds.file_path, 300, 225)
media_object = True
else:
pixbuf = get_pixbuf_from_journal(ds, MAXX, MAXY) # 300, 225)
if 'description' in ds.metadata:
desc = ds.metadata['description']
else:
desc = None
self.slides.append(Slide(True, ds.object_id, self.colors,
title, pixbuf, desc))
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self._help = Sprite(
self._sprites,
int((self._width - int(PREVIEWW * self._scale)) / 2),
int(PREVIEWY * self._scale),
gtk.gdk.pixbuf_new_from_file_at_size(
os.path.join(activity.get_bundle_path(), 'help.png'),
int(PREVIEWW * self._scale), int(PREVIEWH * self._scale)))
self._help.hide()
self._genblanks(self.colors)
self._title = Sprite(self._sprites, 0, 0, self._title_pixbuf)
self._title.set_label_attributes(int(titlef * self._scale),
rescale=False)
self._preview = Sprite(self._sprites,
int((self._width - int(PREVIEWW * self._scale)) / 2),
int(PREVIEWY * self._scale), self._preview_pixbuf)
self._description = Sprite(self._sprites,
int(DESCRIPTIONX * self._scale),
int(DESCRIPTIONY * self._scale),
self._desc_pixbuf)
self._description.set_label_attributes(int(descriptionf * self._scale))
self._my_canvas = Sprite(self._sprites, 0, 0, self._canvas_pixbuf)
self._my_canvas.set_layer(BOTTOM)
self._clear_screen()
self.i = 0
self._show_slide()
self._playing = False
self._rate = 10
def _genblanks(self, colors):
''' Need to cache these '''
self._title_pixbuf = svg_str_to_pixbuf(
genblank(self._width, int(TITLEH * self._scale), colors))
self._preview_pixbuf = svg_str_to_pixbuf(
genblank(int(PREVIEWW * self._scale), int(PREVIEWH * self._scale),
colors))
self._desc_pixbuf = svg_str_to_pixbuf(
genblank(int(self._width - (2 * DESCRIPTIONX * self._scale)),
int(DESCRIPTIONH * self._scale), colors))