Example #1
0
    def scale(self, factor):
        scaled = []
        for w in [self._img, self._hover, self._down]:
            if w.get_animation():
                w = scale_gif(w, factor)
            else:
                w = scale_image(w, factor)
            scaled.append(w)

        self._img, self._hover, self._down = scaled
Example #2
0
    def add_widget(self, widget, p43, p169, clicked_cb=None, key=None,
                   name=None, modal=False):
        placement = p43 if self._screen_ratio == self.RATIO_4_3 else p169

        final_scale = placement.scale * self._scale_factor
        if final_scale != 1 and placement.scale != 0:
            if widget.__class__.__name__ == 'Image':
                if widget.get_animation():
                    widget = scale_gif(widget, final_scale)
                else:
                    widget = scale_image(widget, final_scale)
            elif issubclass(widget.__class__, ActiveImage):
                widget.scale(final_scale)
            else:
                if placement.scale != 1.0:
                    raise RuntimeError('Can\'t scale regular widgets!')

        if issubclass(widget.__class__, ActiveImage):
            root_widget = widget.get_widget()
        else:
            root_widget = widget

        if clicked_cb:
            # ActiveImage already comes in a button wrapper
            if not issubclass(widget.__class__, ActiveImage):
                button_wrapper = Gtk.Button()
                button_wrapper.add(root_widget)
                root_widget = button_wrapper

            attach_cursor_events(root_widget)
            if isinstance(clicked_cb, (list, tuple)):
                root_widget.connect('clicked', self._clicked_cb_wrapper,
                                    clicked_cb[0], *clicked_cb[1:])
            else:
                root_widget.connect('clicked', self._clicked_cb_wrapper,
                                    clicked_cb)

            if key is not None:
                if not hasattr(self, '_keys'):
                    msg = 'Scene must be initialised with main_window to ' + \
                          'be able to receive key events.'
                    raise RuntimeError(msg)
                cbs = {'action': clicked_cb}
                if issubclass(widget.__class__, ActiveImage):
                    cbs['down'] = widget.down
                    cbs['up'] = widget.up
                self._keys[key] = cbs

        align = Gtk.Alignment.new(placement.x, placement.y, 0, 0)
        align.add(root_widget)
        align.set_size_request(self._w, self._h)

        wrapper = align
        if modal:
            wrapper = Gtk.EventBox()
            add_class(wrapper, 'modal')
            wrapper.add(align)

        wrapper.show_all()
        self._fixed.put(wrapper, 0, 0)

        if name is not None:
            self._widgets[name] = wrapper