def _create_sprites(self, path): ''' Create all of the sprites we'll need ''' self.smiley_graphic = svg_str_to_pixbuf( svg_from_file(os.path.join(path, 'smiley.svg'))) self.frown_graphic = svg_str_to_pixbuf( svg_from_file(os.path.join(path, 'frown.svg'))) self.egg_graphic = svg_str_to_pixbuf( svg_from_file(os.path.join(path, 'Easter_egg.svg'))) self.blank_graphic = svg_str_to_pixbuf( svg_header(REWARD_HEIGHT, REWARD_HEIGHT, 1.0) + \ svg_rect(REWARD_HEIGHT, REWARD_HEIGHT, 5, 5, 0, 0, '#C0C0C0', '#282828') + \ svg_footer()) self.ball = Ball(self.sprites, os.path.join(path, 'basketball.svg')) self.current_frame = 0 self.bar = Bar(self.sprites, self.width, self.height, self.scale, self.ball.width()) self.current_bar = self.bar.get_bar(2) self.ball_y_max = self.bar.bar_y() - self.ball.height() self.ball.move_ball((int( (self.width - self.ball.width()) / 2), self.ball_y_max))
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(self, filename): ''' Create a ball object and Easter Egg animation from an SVG file. ''' self.ball.images[0] = svg_str_to_pixbuf(svg_from_file(filename)) ball = extract_svg_payload(file(filename, 'r')) for i in range(8): self.frames[i].images[0] = svg_str_to_pixbuf( svg_header(SIZE, SIZE, 1.0) + TRANSFORMS[i] + \ ball + PUNCTURE + AIR + '</g>' + svg_footer())
def make_labels(self): ''' Label the bar ''' num = svg_header(BAR_HEIGHT * self.scale, BAR_HEIGHT * self.scale, 1.0) + \ svg_rect(BAR_HEIGHT * self.scale, BAR_HEIGHT * self.scale, 0, 0, 0, 0, 'none', 'none') + \ svg_footer() self.left = Sprite(self.sprites, int(self.ball_size / 4), self.bar_y(), svg_str_to_pixbuf(num)) self.left.set_label(_('0')) self.right = Sprite(self.sprites, self.screen_width - int(self.ball_size / 2), self.bar_y(), svg_str_to_pixbuf(num)) self.right.set_label(_('1'))
def _make_wedge_bar(self, nsegments): ''' Create a wedged-shaped bar with n segments ''' s = 3.5 # add provision for stroke width svg = svg_header(self._width, BAR_HEIGHT * self._scale + s, 1.0) dx = self._width / float(nsegments) dy = (BAR_HEIGHT * self._scale) / float(nsegments) for i in range(int(nsegments) // 2): svg += svg_wedge(dx, BAR_HEIGHT * self._scale + s, i * 2 * dx + s, i * 2 * dy + s, (i * 2 + 1) * dy + s, '#000000', '#FFFFFF') svg += svg_wedge(dx, BAR_HEIGHT * self._scale + s, (i * 2 + 1) * dx + s, (i * 2 + 1) * dy + s, (i * 2 + 2) * dy + s, '#000000', '#FFFFFF') if int(nsegments) % 2 == 1: # odd svg += svg_wedge(dx, BAR_HEIGHT * self._scale + s, (i * 2 + 2) * dx + s, (i * 2 + 2) * dy + s, BAR_HEIGHT * self._scale + s, '#000000', '#FFFFFF') svg += svg_footer() self.bars[nsegments] = Sprite(self._sprites, 0, 0, svg_str_to_pixbuf(svg)) self.bars[nsegments].set_layer(2) self.bars[nsegments].set_label_attributes(18, horiz_align="left", i=0) self.bars[nsegments].set_label_attributes(18, horiz_align="right", i=1) self.bars[nsegments].set_label_color('black', i=0) self.bars[nsegments].set_label_color('white', i=1) self.bars[nsegments].set_label(' 0', i=0) self.bars[nsegments].set_label('1 ', i=1) self.bars[nsegments].move( (0, self._height - BAR_HEIGHT * self._scale))
def _make_wedge_bar(self, nsegments): ''' Create a wedged-shaped bar with n segments ''' s = 3.5 # add provision for stroke width svg = svg_header(self._width, BAR_HEIGHT * self._scale + s, 1.0) dx = self._width / float(nsegments) dy = (BAR_HEIGHT * self._scale) / float(nsegments) for i in range(int(nsegments) / 2): svg += svg_wedge(dx, BAR_HEIGHT * self._scale + s, i * 2 * dx + s, i * 2 * dy + s, (i * 2 + 1) * dy + s, '#000000', '#FFFFFF') svg += svg_wedge(dx, BAR_HEIGHT * self._scale + s, (i * 2 + 1) * dx + s, (i * 2 + 1) * dy + s, (i * 2 + 2) * dy + s, '#000000', '#FFFFFF') if int(nsegments) % 2 == 1: # odd svg += svg_wedge(dx, BAR_HEIGHT * self._scale + s, (i * 2 + 2) * dx + s, (i * 2 + 2) * dy + s, BAR_HEIGHT * self._scale + s, '#000000', '#FFFFFF') svg += svg_footer() self.bars[nsegments] = Sprite(self._sprites, 0, 0, svg_str_to_pixbuf(svg)) self.bars[nsegments].set_layer(2) self.bars[nsegments].set_label_attributes(18, horiz_align="left", i=0) self.bars[nsegments].set_label_attributes(18, horiz_align="right", i=1) self.bars[nsegments].set_label_color('black', i=0) self.bars[nsegments].set_label_color('white', i=1) self.bars[nsegments].set_label(' 0', i=0) self.bars[nsegments].set_label('1 ', i=1) self.bars[nsegments].move( (0, self._height - BAR_HEIGHT * self._scale))
def _append_player(self, nick, colors): ''' Keep a list of players, their colors, and an XO pixbuf ''' if not nick in self.bounce_window.buddies: # _logger.debug('appending %s to the buddy list', nick) self.bounce_window.buddies.append(nick) self._player_colors.append(colors) self._player_pixbuf.append(svg_str_to_pixbuf( generate_xo_svg(scale=0.8, colors=colors)))
def _append_player(self, nick, colors): ''' Keep a list of players, their colors, and an XO pixbuf ''' if not nick in self._bounce_window.buddies: _logger.debug('appending %s to the buddy list', nick) self._bounce_window.buddies.append(nick) self._player_colors.append([str(colors[0]), str(colors[1])]) self._player_pixbufs.append(svg_str_to_pixbuf( generate_xo_svg(scale=0.8, colors=self._player_colors[-1])))
def _append_player(self, nick, colors): ''' Keep a list of players, their colors, and an XO pixbuf ''' if nick not in self._bounce_window.buddies: _logger.debug('appending %s to the buddy list', nick) self._bounce_window.buddies.append(nick) self._player_colors.append([str(colors[0]), str(colors[1])]) self._player_pixbufs.append( svg_str_to_pixbuf( generate_xo_svg(scale=0.8, colors=self._player_colors[-1])))
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_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 _buddy_list(self, payload): '''Sharer sent the updated buddy list, so regenerate internal lists''' if not self.initiating: [buddies, colors] = json_load(payload) self._bounce_window.buddies = buddies[:] self._player_colors = colors[:] self._player_pixbufs = [] for colors in self._player_colors: self._player_pixbufs.append(svg_str_to_pixbuf( generate_xo_svg(scale=0.8, colors=[str(colors[0]), str(colors[1])])))
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(1) self.ball.set_label_attributes(24) 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, SIZE, 1.0) + TRANSFORMS[i] + \ ball + PUNCTURE + AIR + '</g>' + svg_footer()))) for frame in self.frames: frame.set_layer(1) frame.move((0, -SIZE)) # move animation frames off screen
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 _create_sprites(self, path): ''' Create all of the sprites we'll need ''' self.smiley_graphic = svg_str_to_pixbuf(svg_from_file( os.path.join(path, 'images', 'smiley.svg'))) self.frown_graphic = svg_str_to_pixbuf(svg_from_file( os.path.join(path, 'images', 'frown.svg'))) self.blank_graphic = svg_str_to_pixbuf( svg_header(REWARD_HEIGHT, REWARD_HEIGHT, 1.0) + svg_rect(REWARD_HEIGHT, REWARD_HEIGHT, 5, 5, 0, 0, 'none', 'none') + svg_footer()) self.ball = Ball(self._sprites, os.path.join(path, 'images', 'soccerball.svg')) self._current_frame = 0 self.bar = Bar(self._sprites, self.ball.width(), COLORS) self._current_bar = self.bar.get_bar(2) self.ball_y_max = self.bar.bar_y() - self.ball.height() + \ int(BAR_HEIGHT / 2.) self.ball.move_ball((int((self._width - self.ball.width()) / 2), self.ball_y_max)) self._backgrounds = {} width, height = self._calc_background_size() pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size( os.path.join(path, 'images', 'grass_background.png'), width, height) if Gdk.Screen.height() > Gdk.Screen.width(): pixbuf = self._crop_to_portrait(pixbuf) self._backgrounds['grass_background.png'] = pixbuf self._background = Sprite(self._sprites, 0, 0, pixbuf) self._background.set_layer(-100) self._background.type = 'background' self._current_bg = 'grass_background.png'
def _make_mark(self): ''' Make a mark to show the fraction position on the bar. ''' mark = svg_header(self._ball_size / 2., BAR_HEIGHT * self._scale + 4, 1.0) mark += svg_rect(self._ball_size / 2., BAR_HEIGHT * self._scale + 4, 0, 0, 0, 0, '#FF0000', '#FF0000') mark += svg_rect(1, BAR_HEIGHT * self._scale + 4, 0, 0, self._ball_size / 4., 0, '#000000', '#000000') mark += svg_footer() self.mark = Sprite(self._sprites, 0, self._height, # hide off bottom of screen svg_str_to_pixbuf(mark)) self.mark.set_layer(1)
def _setup_presence_service(self): ''' Setup the Presence Service. ''' self.pservice = presenceservice.get_instance() self.initiating = None # sharing (True) or joining (False) owner = self.pservice.get_owner() self.owner = owner self.bounce_window.buddies.append(self.nick) self._player_colors = [self.colors] self._player_pixbuf = [svg_str_to_pixbuf( generate_xo_svg(scale=0.8, colors=self.colors))] self._share = '' self.connect('shared', self._shared_cb) self.connect('joined', self._joined_cb)
def _setup_sharing(self): ''' Setup the Presence Service. ''' self.pservice = presenceservice.get_instance() self.initiating = None # sharing (True) or joining (False) owner = self.pservice.get_owner() self.owner = owner self._bounce_window.buddies.append(self.nick) self._player_colors = [self._colors] self._player_pixbufs = [ svg_str_to_pixbuf(generate_xo_svg(scale=0.8, colors=self._colors)) ] self._share = '' self.connect('shared', self._shared_cb) self.connect('joined', self._joined_cb)
def _load_standard_buttons(self, toolbar): ''' Load buttons onto whichever toolbar we are using ''' self.fraction_button = radio_factory('fraction', toolbar, self._fraction_cb, tooltip=_('fractions'), group=None) self.percent_button = radio_factory('percent', toolbar, self._percent_cb, tooltip=_('percents'), group=self.fraction_button) self.player = image_factory( svg_str_to_pixbuf(generate_xo_svg(scale=0.8, colors=['#282828', '#000000'])), toolbar, tooltip=self.nick) separator_factory(toolbar, expand=False, visible=True) self.challenge = label_factory(toolbar, _("Click the ball to start."))
def _load_standard_buttons(self, toolbar): fraction_button = RadioToolButton(group=None) fraction_button.set_icon_name('fraction') fraction_button.set_tooltip(_('fractions')) fraction_button.connect('clicked', self._fraction_cb) toolbar.insert(fraction_button, -1) fraction_button.show() sector_button = RadioToolButton(group=fraction_button) sector_button.set_icon_name('sector') sector_button.set_tooltip(_('sectors')) sector_button.connect('clicked', self._sector_cb) toolbar.insert(sector_button, -1) sector_button.show() percent_button = RadioToolButton(group=fraction_button) percent_button.set_icon_name('percent') percent_button.set_tooltip(_('percents')) percent_button.connect('clicked', self._percent_cb) toolbar.insert(percent_button, -1) percent_button.show() self._player = Gtk.Image() self._player.set_from_pixbuf( svg_str_to_pixbuf( generate_xo_svg(scale=0.8, colors=['#282828', '#282828']))) self._player.set_tooltip_text(self.nick) toolitem = Gtk.ToolItem() toolitem.add(self._player) self._player.show() toolbar.insert(toolitem, -1) toolitem.show() self._label = Gtk.Label(_("Click the ball to start.")) self._label.set_line_wrap(True) if Gdk.Screen.width() < 1024: self._label.set_size_request(275, -1) else: self._label.set_size_request(500, -1) self.toolitem = Gtk.ToolItem() self.toolitem.add(self._label) self._label.show() toolbar.insert(self.toolitem, -1) self.toolitem.show()
def _load_standard_buttons(self, toolbar): fraction_button = RadioToolButton(group=None) fraction_button.set_icon_name('fraction') fraction_button.set_tooltip(_('fractions')) fraction_button.connect('clicked', self._fraction_cb) toolbar.insert(fraction_button, -1) fraction_button.show() sector_button = RadioToolButton(group=fraction_button) sector_button.set_icon_name('sector') sector_button.set_tooltip(_('sectors')) sector_button.connect('clicked', self._sector_cb) toolbar.insert(sector_button, -1) sector_button.show() percent_button = RadioToolButton(group=fraction_button) percent_button.set_icon_name('percent') percent_button.set_tooltip(_('percents')) percent_button.connect('clicked', self._percent_cb) toolbar.insert(percent_button, -1) percent_button.show() self._player = Gtk.Image() self._player.set_from_pixbuf(svg_str_to_pixbuf( generate_xo_svg(scale=0.8, colors=['#282828', '#282828']))) self._player.set_tooltip_text(self.nick) toolitem = Gtk.ToolItem() toolitem.add(self._player) self._player.show() toolbar.insert(toolitem, -1) toolitem.show() self._label = Gtk.Label(_("Click the ball to start.")) self._label.set_line_wrap(True) if Gdk.Screen.width() < 1024: self._label.set_size_request(275, -1) else: self._label.set_size_request(500, -1) self.toolitem = Gtk.ToolItem() self.toolitem.add(self._label) self._label.show() toolbar.insert(self.toolitem, -1) self.toolitem.show()
def make_bar(self, nsegments): ''' Create a bar with n segments ''' svg = svg_header(self.screen_width - self.ball_size, BAR_HEIGHT, 1.0) dx = (self.screen_width - self.ball_size) / float(nsegments) for i in range(int(nsegments) / 2): svg += svg_rect(dx, BAR_HEIGHT * self.scale, 0, 0, i * 2 * dx, 0, '#FFFFFF', '#FFFFFF') svg += svg_rect(dx, BAR_HEIGHT * self.scale, 0, 0, (i * 2 + 1) * dx, 0, '#AAAAAA', '#AAAAAA') if int(nsegments) % 2 == 1: # odd svg += svg_rect(dx, BAR_HEIGHT * self.scale, 0, 0, (i * 2 + 2) * dx, 0, '#FFFFFF', '#FFFFFF') svg += svg_footer() self.bars[nsegments] = Sprite(self.sprites, 0, 0, svg_str_to_pixbuf(svg)) self.bars[nsegments].move( (int(self.ball_size / 2), self.screen_height - \ int((self.ball_size + self.height()) / 2)))
def _make_wedge_mark(self): ''' Make a mark to show the fraction position on the bar. ''' dx = self._ball_size / 2. n = (self._width - self._ball_size) / dx dy = (BAR_HEIGHT * self._scale) / n s = 3.5 i = int(n / 2) - 1 mark = svg_header(self._ball_size, BAR_HEIGHT * self._scale + s, 1.0) mark += svg_wedge(dx, BAR_HEIGHT * self._scale + s, s, i * 2 * dy + s, (i * 2 + 1) * dy + s, '#FF0000', '#FFFFFF') mark += svg_wedge(dx, BAR_HEIGHT * self._scale + s, dx + s, (i * 2 + 1) * dy + s, (i * 2 + 2) * dy + s, '#FF0000', '#FFFFFF') mark += svg_footer() self.mark = Sprite( self._sprites, 0, self._height, # hide off bottom of screen svg_str_to_pixbuf(mark)) self.mark.set_layer(1)
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_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 _make_rect_bar(self, nsegments): ''' Create a bar with n segments ''' svg = svg_header(self._width - self._ball_size, BAR_HEIGHT * self._scale, 1.0) dx = self._width / float(nsegments) for i in range(int(nsegments) / 2): svg += svg_rect(dx, BAR_HEIGHT * self._scale, 0, 0, i * 2 * dx, 0, self._colors[0], self._colors[0]) svg += svg_rect(dx, BAR_HEIGHT * self._scale, 0, 0, (i * 2 + 1) * dx, 0, self._colors[1], self._colors[1]) if int(nsegments) % 2 == 1: # odd svg += svg_rect(dx, BAR_HEIGHT * self._scale, 0, 0, (i * 2 + 2) * dx, 0, self._colors[0], self._colors[0]) svg += svg_footer() self.bars[nsegments] = Sprite(self._sprites, 0, 0, svg_str_to_pixbuf(svg)) self.bars[nsegments].move((0, self._height - int( (self._ball_size + self._height()) / 2)))
def _make_rect_bar(self, nsegments): ''' Create a bar with n segments ''' svg = svg_header(self._width - self._ball_size, BAR_HEIGHT * self._scale, 1.0) dx = self._width / float(nsegments) for i in range(int(nsegments) / 2): svg += svg_rect(dx, BAR_HEIGHT * self._scale, 0, 0, i * 2 * dx, 0, self._colors[0], self._colors[0]) svg += svg_rect(dx, BAR_HEIGHT * self._scale, 0, 0, (i * 2 + 1) * dx, 0, self._colors[1], self._colors[1]) if int(nsegments) % 2 == 1: # odd svg += svg_rect(dx, BAR_HEIGHT * self._scale, 0, 0, (i * 2 + 2) * dx, 0, self._colors[0], self._colors[0]) svg += svg_footer() self.bars[nsegments] = Sprite(self._sprites, 0, 0, svg_str_to_pixbuf(svg)) self.bars[nsegments].move( (0, self._height - int((self._ball_size + self._height()) / 2)))
def _make_wedge_mark(self): ''' Make a mark to show the fraction position on the bar. ''' dx = self._ball_size / 2. n = (self._width - self._ball_size) / dx dy = (BAR_HEIGHT * self._scale) / n s = 3.5 i = int(n / 2) - 1 mark = svg_header(self._ball_size, BAR_HEIGHT * self._scale + s, 1.0) mark += svg_wedge(dx, BAR_HEIGHT * self._scale + s, s, i * 2 * dy + s, (i * 2 + 1) * dy + s, '#FF0000', '#FFFFFF') mark += svg_wedge(dx, BAR_HEIGHT * self._scale + s, dx + s, (i * 2 + 1) * dy + s, (i * 2 + 2) * dy + s, '#FF0000', '#FFFFFF') mark += svg_footer() self.mark = Sprite(self._sprites, 0, self._height, # hide off bottom of screen svg_str_to_pixbuf(mark)) self.mark.set_layer(1)
def __init__(self, handle): ''' Initiate activity. ''' super(FractionBounceActivity, self).__init__(handle) self.nick = profile.get_nick_name() if profile.get_color() is not None: self._colors = profile.get_color().to_string().split(',') else: self._colors = ['#A0FFA0', '#FF8080'] self.max_participants = 4 # sharing self._playing = True self._setup_toolbars() canvas = self._setup_canvas() # Read any custom fractions from the project metadata if 'custom' in self.metadata: custom = self.metadata['custom'] else: custom = None self._current_ball = 'soccerball' self._toolbar_was_expanded = False # Initialize the canvas self._bounce_window = Bounce(canvas, activity.get_bundle_path(), self) Gdk.Screen.get_default().connect('size-changed', self._configure_cb) # Restore any custom fractions if custom is not None: fractions = custom.split(',') for f in fractions: self._bounce_window.add_fraction(f) self._bounce_window.buddies.append(self.nick) self._player_colors = [self._colors] self._player_pixbufs = [ svg_str_to_pixbuf(generate_xo_svg(scale=0.8, colors=self._colors)) ] def on_activity_joined_cb(me): logging.debug('activity joined') self._player.set_from_pixbuf(self._player_pixbufs[0]) self.connect('joined', on_activity_joined_cb) def on_activity_shared_cb(me): logging.debug('activity shared') self._player.set_from_pixbuf(self._player_pixbufs[0]) self._label.set_label(_('Wait for others to join.')) self.connect('shared', on_activity_shared_cb) self._collab = CollabWrapper(self) if self.shared_activity: # We're joining if not self.get_shared(): self._label.set_label(_('Wait for the sharer to start.')) actions = { 'j': self._new_joiner, 'b': self._buddy_list, 'f': self._receive_a_fraction, 't': self._take_a_turn, 'l': self._buddy_left, } def on_message_cb(collab, buddy, msg): logging.debug('on_message_cb buddy %r msg %r' % (buddy, msg)) if self._playing: actions[msg.get('action')](msg.get('data')) self._collab.connect('message', on_message_cb) def on_joined_cb(collab, msg): logging.debug('joined') self.send_event('j', [self.nick, self._colors]) self._collab.connect('joined', on_joined_cb, 'joined') def on_buddy_joined_cb(collab, buddy, msg): logging.debug('on_buddy_joined_cb buddy %r' % (buddy.props.nick)) self._collab.connect('buddy_joined', on_buddy_joined_cb, 'buddy_joined') def on_buddy_left_cb(collab, buddy, msg): logging.debug('on_buddy_left_cb buddy %r' % (buddy.props.nick)) self._collab.connect('buddy_left', on_buddy_left_cb, 'buddy_left') self._collab.setup()