Exemplo n.º 1
0
    def __init__(self, text=None, buttons=None, source=BOTTOM,
                 source_align=0.5, scale=1.0):
        self._source = source
        self._source_align = source_align
        self._button_box = None
        self._scale = scale
        if buttons:
            for button in buttons:
                self.add_button(button[0], button[1])

        super(SpeechBubble, self).__init__()
        self.set_row_spacing(0)
        self.set_column_spacing(0)

        # The speech bubble triangle
        img_path = common_media_path("sb-{}.png".format(self._source))
        img = Gtk.Image.new_from_file(img_path)
        img = scale_image(img, scale)
        img.set_hexpand(False)
        img.set_vexpand(False)

        img_align = Gtk.Alignment()
        img_align.add(img)

        if self._source in [self.TOP, self.BOTTOM]:
            img_align.set(self._source_align, 0, 0, 0)
        else:
            img_align.set(0, self._source_align, 0, 0)

        # The background of the bubble
        self._bubble = Gtk.EventBox()
        self._bubble.get_style_context().add_class('speech-bubble')

        self.attach(self._bubble, 0, 0, 1, 1)

        if self._source == self.TOP:
            self.attach_next_to(img_align, self._bubble,
                                Gtk.PositionType.TOP, 1, 1)
        elif self._source == self.BOTTOM:
            self.attach_next_to(img_align, self._bubble,
                                Gtk.PositionType.BOTTOM, 1, 1)
        elif self._source == self.LEFT:
            self.attach_next_to(img_align, self._bubble,
                                Gtk.PositionType.LEFT, 1, 1)
        elif self._source == self.RIGHT:
            self.attach_next_to(img_align, self._bubble,
                                Gtk.PositionType.RIGHT, 1, 1)

        # Padding in of the bubble
        self._padded_bubble = Gtk.Alignment(hexpand=True, vexpand=True)
        self._padded_bubble.set(0.5, 0.5, 0, 0)
        vert = int(self._scale*25)
        horz = int(self._scale*35)
        self._padded_bubble.set_padding(vert, vert, horz, horz)
        self._bubble.add(self._padded_bubble)

        self._init_content(text)

        self.show_all()
Exemplo n.º 2
0
    def __init__(self, stage, image_path, image_scale, image_align, title,
                 copy, buttons):
        super(Notebook, self).__init__()

        self.add(
            Gtk.Image.new_from_file(stage.media_path('lonely-notebook.png')))

        fixed = Gtk.Fixed()
        self.add_overlay(fixed)

        self._eb = Gtk.EventBox()
        add_class(self._eb, 'notebook-content-area')
        self._eb.set_size_request(415, 460)

        fixed.put(self._eb, 20, 70)

        vbox = Gtk.VBox(False, 0)
        vbox.set_vexpand(True)
        vbox.set_hexpand(True)
        vbox.set_margin_left(10)
        vbox.set_margin_right(10)

        img = scale_image(Gtk.Image.new_from_file(image_path), image_scale)
        img_align = Gtk.Alignment.new(image_align, 0.5, 0, 0)
        img_align.add(img)
        img_align.set_vexpand(True)
        img_align.set_hexpand(True)
        vbox.pack_start(img_align, False, False, 0)

        heading = Gtk.Label(title)
        add_class(heading, 'notebook-heading')

        copy_widgets = []
        for line in copy:
            l = Gtk.Label(line)
            l.set_line_wrap(False)
            l.set_justify(Gtk.Justification.CENTER)
            add_class(l, 'notebook-text')
            l.set_halign(Gtk.Align.CENTER)
            copy_widgets.append(l)

        # Pack heading
        vbox.pack_start(heading, False, False, 0)
        heading.set_margin_top(15)
        heading.set_margin_bottom(15)

        for w in copy_widgets:
            vbox.pack_start(w, False, False, 3)

        hbox = Gtk.HBox(False, 10)
        hbox.set_margin_top(15)
        hbox.set_halign(Gtk.Align.CENTER)
        for b in buttons:
            button = KanoButton(b['label'], color=b['color'])
            button.connect('clicked', cb_wrapper, b['callback'])
            hbox.pack_start(button, False, False, 0)
        vbox.pack_start(hbox, False, False, 0)

        self._eb.add(vbox)
Exemplo n.º 3
0
    def __init__(self, stage, image_path, image_scale, image_align,
                 title, copy, buttons):
        super(Notebook, self).__init__()

        self.add(Gtk.Image.new_from_file(stage.media_path('lonely-notebook.png')))

        fixed = Gtk.Fixed()
        self.add_overlay(fixed)

        self._eb = Gtk.EventBox()
        add_class(self._eb, 'notebook-content-area')
        self._eb.set_size_request(415, 460)

        fixed.put(self._eb, 20, 70)

        vbox = Gtk.VBox(False, 0)
        vbox.set_vexpand(True)
        vbox.set_hexpand(True)
        vbox.set_margin_left(10)
        vbox.set_margin_right(10)

        img = scale_image(Gtk.Image.new_from_file(image_path), image_scale)
        img_align = Gtk.Alignment.new(image_align, 0.5, 0, 0)
        img_align.add(img)
        img_align.set_vexpand(True)
        img_align.set_hexpand(True)
        vbox.pack_start(img_align, False, False, 0)

        heading = Gtk.Label(title)
        add_class(heading, 'notebook-heading')

        copy_widgets = []
        for line in copy:
            l = Gtk.Label(line)
            l.set_line_wrap(False)
            l.set_justify(Gtk.Justification.CENTER)
            add_class(l, 'notebook-text')
            l.set_halign(Gtk.Align.CENTER)
            copy_widgets.append(l)

        # Pack heading
        vbox.pack_start(heading, False, False, 0)
        heading.set_margin_top(15)
        heading.set_margin_bottom(15)

        for w in copy_widgets:
            vbox.pack_start(w, False, False, 3)

        hbox = Gtk.HBox(False, 10)
        hbox.set_margin_top(15)
        hbox.set_halign(Gtk.Align.CENTER)
        for b in buttons:
            button = KanoButton(b['label'], color=b['color'])
            button.connect('clicked', cb_wrapper, b['callback'])
            hbox.pack_start(button, False, False, 0)
        vbox.pack_start(hbox, False, False, 0)

        self._eb.add(vbox)
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
0
    def __init__(self,
                 text=None,
                 buttons=None,
                 source=BOTTOM,
                 source_align=0.5,
                 scale=1.0):
        self._source = source
        self._source_align = source_align
        self._button_box = None
        self._scale = scale
        if buttons:
            for button in buttons:
                self.add_button(button[0], button[1])

        super(SpeechBubble, self).__init__()
        self.set_row_spacing(0)
        self.set_column_spacing(0)

        # The speech bubble triangle
        img_path = common_media_path("sb-{}.png".format(self._source))
        img = Gtk.Image.new_from_file(img_path)
        img = scale_image(img, scale)
        img.set_hexpand(False)
        img.set_vexpand(False)

        img_align = Gtk.Alignment()
        img_align.add(img)

        if self._source in [self.TOP, self.BOTTOM]:
            img_align.set(self._source_align, 0, 0, 0)
        else:
            img_align.set(0, self._source_align, 0, 0)

        # The background of the bubble
        self._bubble = Gtk.EventBox()
        self._bubble.get_style_context().add_class('speech-bubble')

        self.attach(self._bubble, 0, 0, 1, 1)

        if self._source == self.TOP:
            self.attach_next_to(img_align, self._bubble, Gtk.PositionType.TOP,
                                1, 1)
        elif self._source == self.BOTTOM:
            self.attach_next_to(img_align, self._bubble,
                                Gtk.PositionType.BOTTOM, 1, 1)
        elif self._source == self.LEFT:
            self.attach_next_to(img_align, self._bubble, Gtk.PositionType.LEFT,
                                1, 1)
        elif self._source == self.RIGHT:
            self.attach_next_to(img_align, self._bubble,
                                Gtk.PositionType.RIGHT, 1, 1)

        # Padding in of the bubble
        self._padded_bubble = Gtk.Alignment(hexpand=True, vexpand=True)
        self._padded_bubble.set(0.5, 0.5, 0, 0)
        vert = int(self._scale * 25)
        horz = int(self._scale * 35)
        self._padded_bubble.set_padding(vert, vert, horz, horz)
        self._bubble.add(self._padded_bubble)

        self._init_content(text)

        self.show_all()