def increase_score(self): new_score = Icon(icon_name='score', pixel_size=style.SMALL_ICON_SIZE) new_score.set_fill_color(self.fill_color) new_score.set_stroke_color(self.stroke_color) self.scores.append(new_score) new_score.show() self.score_table.attach(new_score, self.current_x, self.current_x + 1, self.current_y, self.current_y + 1, Gtk.AttachOptions.SHRINK, Gtk.AttachOptions.SHRINK) self.current_x += 1 if self.current_x == self._score_cols: self.current_x = 0 self.current_y += 1 self.queue_draw()
def increase_score(self): new_score = Icon(icon_name='score', pixel_size=style.SMALL_ICON_SIZE) new_score.set_fill_color(self.fill_color) new_score.set_stroke_color(self.stroke_color) self.scores.append(new_score) new_score.show() self.score_table.attach( new_score, self.current_x, self.current_x + 1, self.current_y, self.current_y + 1, Gtk.AttachOptions.SHRINK, Gtk.AttachOptions.SHRINK) self.current_x += 1 if self.current_x == self._score_cols: self.current_x = 0 self.current_y += 1 self.queue_draw()
class SlideView(Gtk.EventBox): def __init__(self, activity): Gtk.EventBox.__init__(self) self._area = Gtk.DrawingArea() self._area.connect('draw', self._area_draw_cb) self._boxes = [] self._current_box = None self._timeout_id = None prev_btn = Gtk.EventBox() prev_btn.connect('button-press-event', self._prev_slide) self._prev_icon = Icon(pixel_size=100) self._prev_icon.props.icon_name = 'go-previous' prev_btn.add(self._prev_icon) next_btn = Gtk.EventBox() next_btn.connect('button-press-event', self._next_slide) self._next_icon = Icon(pixel_size=100) self._next_icon.props.icon_name = 'go-next' next_btn.add(self._next_icon) hbox = Gtk.Box() hbox.set_border_width(10) hbox.pack_start(prev_btn, True, False, 0) hbox.pack_start(self._area, False, False, 0) hbox.pack_end(next_btn, True, False, 0) self.add(hbox) self.show_all() def _area_draw_cb(self, widget, context): if self._current_box is None: return box = self._boxes[self._current_box] self._area.set_size_request(box.width + 1, box.height + 1) context.move_to(box.width - style.zoom(40), box.height + style.zoom(25)) context.set_font_size(style.zoom(20)) context.show_text('%s/%s' % (self._current_box + 1, str(len(self._boxes)))) if self._current_box == len(self._boxes) - 1: self._next_icon.set_fill_color(style.COLOR_BUTTON_GREY.get_html()) else: self._next_icon.set_fill_color(None) if self._current_box == 0: self._prev_icon.set_fill_color(style.COLOR_BUTTON_GREY.get_html()) else: self._prev_icon.set_fill_color(None) box.draw_in_context(context) def set_boxes(self, boxes): # Discard the title box self._boxes = boxes[1:] def set_current_box(self, box): self._current_box = box self._area.queue_draw() def start(self, use_timings): if not use_timings: self._prev_icon.show() self._next_icon.show() return self._prev_icon.hide() self._next_icon.hide() box = self._boxes[self._current_box] duration = box.slideshow_duration self._timeout_id = \ GObject.timeout_add_seconds(duration, self.__slideshow_timeout_cb) def stop(self): if self._timeout_id: GObject.source_remove(self._timeout_id) def __slideshow_timeout_cb(self, *args): if self._current_box + 1 > len(self._boxes) - 1: return False self._current_box += 1 self._area.queue_draw() box = self._boxes[self._current_box] duration = box.slideshow_duration self._timeout_id = \ GObject.timeout_add_seconds(duration, self.__slideshow_timeout_cb) return False def _next_slide(self, widget, event): self._current_box += 1 if self._current_box > len(self._boxes) - 1: self._current_box -= 1 self._area.queue_draw() def _prev_slide(self, widget, event): self._current_box -= 1 if self._current_box < 0: self._current_box += 1 self._area.queue_draw() def key_press_cb(self, widget, event): if event.keyval == 65361: self._prev_slide(None, None) elif event.keyval == 65363: self._next_slide(None, None)
class PlayerScoreboard(Gtk.EventBox): def __init__(self, nick, fill_color, stroke_color, score=0): Gtk.EventBox.__init__(self) self.default_color = '#666666' self.selected_color = '#818286' self.current_color = '#666666' self.status = False self._score_width = 0 self._score_cols = 0 self._game_size = 16 self.fill_color = fill_color self.stroke_color = stroke_color self.connect('size-allocate', self._allocate_cb) # Set table self.table = Gtk.Table(2, 2, False) self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(self.current_color)) self.table.set_row_spacings(0) self.table.set_col_spacings(0) self.table.set_border_width(style.DEFAULT_SPACING / 2) # Score table self.score_table = Gtk.Table() self.score_table.set_row_spacings(style.DEFAULT_SPACING / 2) self.score_table.set_col_spacings(style.DEFAULT_SPACING / 2) self.scores = [] self.current_x = 0 self.current_y = 0 # Set buddy icon self.icon = Icon(icon_name='computer-xo', pixel_size=style.STANDARD_ICON_SIZE) self.icon.set_fill_color(fill_color) self.icon.set_stroke_color(stroke_color) # Set nick label self.nick = Gtk.Label(label=nick) self.nick.modify_fg(Gtk.StateType.NORMAL, Gdk.color_parse('#ffffff')) self.nick.set_alignment(0, 0.5) # Set message label self.msg = Gtk.Label(label='Waiting for next game...') self.msg.modify_fg(Gtk.StateType.NORMAL, Gdk.color_parse('#ffffff')) self.msg.set_alignment(0, 0.5) self.add(self.table) self.table.attach(self.icon, 0, 1, 0, 3, Gtk.AttachOptions.SHRINK, Gtk.AttachOptions.SHRINK) self.table.attach(self.nick, 1, 2, 0, 1) self.table.attach(self.score_table, 1, 2, 1, 2) if score != 0: for i_ in range(score): self.increase_score() def _allocate_cb(self, widget, allocation): self._score_width = allocation.width - style.STANDARD_ICON_SIZE \ - style.DEFAULT_SPACING * 2 - style.DEFAULT_SPACING / 2 self._score_cols = self._score_width / \ (style.SMALL_ICON_SIZE + style.DEFAULT_SPACING / 2) self.change_game(self._game_size) def change_game(self, size): self._game_size = size if self._score_cols == 0: return rows = int(math.ceil(float(size / 2) / self._score_cols)) self.score_table.resize(rows, self._score_cols) self.score_table.set_size_request( -1, (style.SMALL_ICON_SIZE + style.DEFAULT_SPACING / 2) * rows - style.DEFAULT_SPACING / 2) def increase_score(self): new_score = Icon(icon_name='score', pixel_size=style.SMALL_ICON_SIZE) new_score.set_fill_color(self.fill_color) new_score.set_stroke_color(self.stroke_color) self.scores.append(new_score) new_score.show() self.score_table.attach(new_score, self.current_x, self.current_x + 1, self.current_y, self.current_y + 1, Gtk.AttachOptions.SHRINK, Gtk.AttachOptions.SHRINK) self.current_x += 1 if self.current_x == self._score_cols: self.current_x = 0 self.current_y += 1 self.queue_draw() def set_selected(self, sel): self.status = sel if sel: self.current_color = self.selected_color else: self.current_color = self.default_color self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(self.current_color)) self.icon.set_fill_color(self.fill_color) for score in self.scores: score.set_fill_color(self.fill_color) self.queue_draw() def reset(self): for score in self.scores: self.score_table.remove(score) self.current_x = 0 self.current_y = 0 del self.scores self.scores = [] self.queue_draw() def set_wait_mode(self, status): if status: self.icon.set_fill_color('#ffffff') if len(self.scores) == 0: self.table.attach(self.msg, 1, 2, 1, 2) else: self.icon.set_fill_color(self.fill_color) if len(self.scores) == 0: self.table.remove(self.msg) self.queue_draw() def set_message(self, msg): self.msg.set_text(msg)
class SlideView(Gtk.EventBox): def __init__(self, activity): Gtk.EventBox.__init__(self) self._area = Gtk.DrawingArea() self._area.connect('draw', self._area_draw_cb) self._boxes = [] self._current_box = None prev_btn = Gtk.EventBox() prev_btn.connect('button-press-event', self._prev_slide) self._prev_icon = Icon(pixel_size=100) self._prev_icon.props.icon_name = 'go-previous' prev_btn.add(self._prev_icon) next_btn = Gtk.EventBox() next_btn.connect('button-press-event', self._next_slide) self._next_icon = Icon(pixel_size=100) self._next_icon.props.icon_name = 'go-next' next_btn.add(self._next_icon) hbox = Gtk.Box() hbox.set_border_width(10) hbox.pack_start(prev_btn, True, False, 0) hbox.pack_start(self._area, False, False, 0) hbox.pack_end(next_btn, True, False, 0) self.add(hbox) self.show_all() def _area_draw_cb(self, widget, context): if self._current_box is None: return box = self._boxes[self._current_box] self._area.set_size_request(box.width + 1, box.height + 1) context.move_to(box.width - style.zoom(40), box.height + style.zoom(25)) context.set_font_size(style.zoom(20)) context.show_text('%s/%s' % (self._current_box + 1, str(len(self._boxes)))) if self._current_box == len(self._boxes) - 1: self._next_icon.set_fill_color(style.COLOR_BUTTON_GREY.get_html()) else: self._next_icon.set_fill_color(None) if self._current_box == 0: self._prev_icon.set_fill_color(style.COLOR_BUTTON_GREY.get_html()) else: self._prev_icon.set_fill_color(None) box.draw_in_context(context) def set_boxes(self, boxes): # Discard the title box self._boxes = boxes[1:] def set_current_box(self, box): self._current_box = box self._area.queue_draw() def _next_slide(self, widget, event): self._current_box += 1 if self._current_box > len(self._boxes) - 1: self._current_box -= 1 self._area.queue_draw() def _prev_slide(self, widget, event): self._current_box -= 1 if self._current_box < 0: self._current_box += 1 self._area.queue_draw() def key_press_cb(self, widget, event): if event.keyval == 65361: self._prev_slide(None, None) elif event.keyval == 65363: self._next_slide(None, None)
class PlayerScoreboard(Gtk.EventBox): def __init__(self, nick, fill_color, stroke_color, score=0): Gtk.EventBox.__init__(self) self.default_color = '#666666' self.selected_color = '#818286' self.current_color = '#666666' self.status = False self._score_width = 0 self._score_cols = 0 self._game_size = 16 self.fill_color = fill_color self.stroke_color = stroke_color self.connect('size-allocate', self._allocate_cb) # Set table self.table = Gtk.Table(2, 2, False) self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(self.current_color)) self.table.set_row_spacings(0) self.table.set_col_spacings(0) self.table.set_border_width(style.DEFAULT_SPACING / 2) # Score table self.score_table = Gtk.Table() self.score_table.set_row_spacings(style.DEFAULT_SPACING / 2) self.score_table.set_col_spacings(style.DEFAULT_SPACING / 2) self.scores = [] self.current_x = 0 self.current_y = 0 # Set buddy icon self.icon = Icon(icon_name='computer-xo', pixel_size=style.STANDARD_ICON_SIZE) self.icon.set_fill_color(fill_color) self.icon.set_stroke_color(stroke_color) # Set nick label self.nick = Gtk.Label(label=nick) self.nick.modify_fg(Gtk.StateType.NORMAL, Gdk.color_parse('#ffffff')) self.nick.set_alignment(0, 0.5) # Set message label self.msg = Gtk.Label(label='Waiting for next game...') self.msg.modify_fg(Gtk.StateType.NORMAL, Gdk.color_parse('#ffffff')) self.msg.set_alignment(0, 0.5) self.add(self.table) self.table.attach(self.icon, 0, 1, 0, 3, Gtk.AttachOptions.SHRINK, Gtk.AttachOptions.SHRINK) self.table.attach(self.nick, 1, 2, 0, 1) self.table.attach(self.score_table, 1, 2, 1, 2) if score != 0: for i_ in range(score): self.increase_score() def _allocate_cb(self, widget, allocation): self._score_width = allocation.width - style.STANDARD_ICON_SIZE \ - style.DEFAULT_SPACING * 2 - style.DEFAULT_SPACING / 2 self._score_cols = self._score_width / \ (style.SMALL_ICON_SIZE + style.DEFAULT_SPACING / 2) self.change_game(self._game_size) def change_game(self, size): self._game_size = size if self._score_cols == 0: return rows = int(math.ceil(float(size / 2) / self._score_cols)) self.score_table.resize(rows, self._score_cols) self.score_table.set_size_request( -1, (style.SMALL_ICON_SIZE + style.DEFAULT_SPACING / 2) * rows - style.DEFAULT_SPACING / 2) def increase_score(self): new_score = Icon(icon_name='score', pixel_size=style.SMALL_ICON_SIZE) new_score.set_fill_color(self.fill_color) new_score.set_stroke_color(self.stroke_color) self.scores.append(new_score) new_score.show() self.score_table.attach( new_score, self.current_x, self.current_x + 1, self.current_y, self.current_y + 1, Gtk.AttachOptions.SHRINK, Gtk.AttachOptions.SHRINK) self.current_x += 1 if self.current_x == self._score_cols: self.current_x = 0 self.current_y += 1 self.queue_draw() def set_selected(self, sel): self.status = sel if sel: self.current_color = self.selected_color else: self.current_color = self.default_color self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(self.current_color)) self.icon.set_fill_color(self.fill_color) for score in self.scores: score.set_fill_color(self.fill_color) self.queue_draw() def reset(self): for score in self.scores: self.score_table.remove(score) self.current_x = 0 self.current_y = 0 del self.scores self.scores = [] self.queue_draw() def set_wait_mode(self, status): if status: self.icon.set_fill_color('#ffffff') if len(self.scores) == 0: self.table.attach(self.msg, 1, 2, 1, 2) else: self.icon.set_fill_color(self.fill_color) if len(self.scores) == 0: self.table.remove(self.msg) self.queue_draw() def set_message(self, msg): self.msg.set_text(msg)