コード例 #1
0
 def return_text(self):
     s = [o for o in WidgetHandler.selected.sprites() if o.numerable]
     if len(s) == 1 and any([len(line) for line in self.lines]):
         idx = s[0].idx
         text = '\n'.join([''.join(str(line)) for line in self.lines])
         EventHandler.trigger('WriteNode', self, {'idx': idx, 'text': text})
         self.clear()
コード例 #2
0
 def __init__(self):
     super().__init__()
     self.f = font.SysFont('Verdana', 16)
     self.image = Surface((WIDTH, HEIGHT // 5))
     self.image.fill(COLOR_BOX)
     self.rect = self.image.get_rect(bottomleft=(0, HEIGHT))
     EventHandler.register(self.switch, 'ToggleTypeMode')
     WidgetHandler.add_widget(self)
     Renderer.add_widget(self)
コード例 #3
0
 def switch(self, event):
     instance = System.MAIN_TB if event.data[
         'instance'] == 'MainTB' else event.data['instance']
     if instance is self:
         if event.data['value'] is True:
             WidgetHandler.add_widget(self)
             Renderer.add_widget(self)
             EventHandler.register(self.filter, 'Key')
             self.cursor.switch(True)
         else:
             self.return_text()
             self.clear()
             WidgetHandler.del_widget(self)
             Renderer.del_widget(self)
             EventHandler.deregister(self.filter, 'Key')
             self.cursor.switch(False)
コード例 #4
0
    def __init__(self, parent, x, y, w, h, size, name):
        super().__init__(parent)
        self.image = Surface((w, h))
        self.image.fill(COLOR_BOX)
        self.name = name
        if self.name == 'MainTB':
            System.MAIN_TB = self
        self.rect = self.image.get_rect(bottomleft=(x, y))
        self.x, self.y, self.w, self.h = self.rect
        self.right = self.rect.right
        self.left = self.rect.left
        self.char_x = self.x
        self.char_y = self.y
        self.f = font.SysFont('Courier New', size)
        self.altura_del_texto = self.f.get_height()

        self.line_lenghts = []
        self.lines = [[]]
        self.cursor = Cursor(self)
        self.cursor.place(self.char_x + 1, self.char_y)

        EventHandler.register(self.switch, 'ToggleTypeMode')
コード例 #5
0
            ss = 's' if len(s) > 1 else ''
            elos = 'el' if len(s) == 1 else 'los'
            t = 'Hay un locutor y {} nodo{} seleccionado{}.'.format(
                len(s), ss, ss)
            t += ' Presione D para vincular al locutor con {} nodo{}.'.format(
                elos, ss)

        elif len(s) == 2:
            t = 'Dos nodos están seleccionados. Presione C para crear una conexión entre ellos,'
            t += ' o A, si ya hay una conexión, para crear un punto intermedio'
        elif len(s) > 2:
            t = 'Múltiples nodos están selecionados. Elija sólo uno para ver su contenido o bien dos para crear una'
            t += ' conexión entre ellos (tecla C).'
        elif not len(s):
            t = 'No hay nodos seleccionados. Haga click en uno para ver su contenido o bien toque S para crear un nodo.'

        else:
            t = s[0].text

        return t

    def update(self):
        text = self.get_selected()
        r = render_textrect(text, self.f, self.rect.inflate(-3, -3),
                            COLOR_TEXT, COLOR_BOX)
        self.image.fill(COLOR_BOX)
        self.image.blit(r, (3, 3))


EventHandler.register(lambda e: Preview(), 'Init')
コード例 #6
0
    def update(cls):
        events = event.get([
            KEYDOWN, KEYUP, MOUSEBUTTONDOWN, MOUSEBUTTONUP, MOUSEMOTION, QUIT
        ])
        event.clear()

        # esto es para que se pueda reemplazar un locutor sin tener que reseleccionarlo.
        cls.selected.add([
            i for i in cls.widgets.widgets()
            if i.is_selected and (i not in cls.selected)
        ])

        for e in events:
            mods = key.get_mods()
            ctrl = mods & KMOD_CTRL
            shift = mods & KMOD_SHIFT
            if e.type == QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE):
                salir()

            elif e.type == KEYDOWN:
                widgets = cls.selected.widgets()
                if System.type_mode:
                    if e.key == K_F3:
                        System.toggle_typemode('MainTB')
                    else:
                        EventHandler.trigger('Key', cls.name, {
                            'key': e.key,
                            'mod': e.mod
                        })

                elif e.key == K_c:
                    if len(widgets) == 2 and all(
                        [o.numerable for o in widgets]):
                        widgets.sort(
                            key=lambda o: o.idx)  # lower idx's go first
                        if not shift:
                            widgets[0].connect(widgets[1])
                        else:
                            widgets[0].disconnect(widgets[1])

                elif e.key == K_a and len(widgets) == 2:
                    base, other = widgets
                    EventHandler.trigger('AddMidPoint', 'System', {
                        'base': base,
                        'other': other
                    })

                elif e.key == K_RETURN:
                    EventHandler.trigger('CreateDialog', cls.name,
                                         {'nodes': cls.numerable})

                elif e.key == K_F3:
                    if any([o.order == 'b' for o in widgets]):
                        System.toggle_typemode('MainTB')
                    else:
                        for widget in widgets:
                            widget.on_keydown(e)

                elif e.key == K_s:
                    x, y = mouse.get_pos()
                    color, text = None, None
                    if any([o.order == 'a' for o in widgets]):
                        color = [i for i in widgets if i.order == 'a'][0].color
                        text = [i for i in widgets if i.order == 'a'][0].text

                    if System.area_nodos.collidepoint(x,
                                                      y) and text is not None:
                        EventHandler.trigger('AddNode', cls.name, {
                            'text': text,
                            'pos': [x, y],
                            'color': color
                        })

                elif e.key == K_d and any([o.order == 'a' for o in widgets]):
                    widgets.sort(key=lambda o: o.order)
                    color_namer = widgets.pop(0)
                    for other in widgets:
                        other.colorize(color_namer)

                elif len(cls.selected):
                    for widget in cls.selected.widgets():
                        widget.on_keydown(e)

            elif e.type == KEYUP:
                if len(cls.selected):
                    for widget in cls.selected.widgets():
                        widget.on_keyup(e)

            elif e.type == MOUSEBUTTONDOWN:  # pos, button
                widgets = [
                    w for w in cls.widgets.widgets()
                    if w.selectable and w.rect.collidepoint(e.pos)
                ]
                if not len(
                        widgets
                ) and e.button == 1 and cls.active_area.collidepoint(e.pos):
                    if not shift and not System.type_mode:
                        cls.selected.empty()
                    if not ctrl:
                        EventHandler.trigger('AddSelection', cls.name, {
                            "pos": e.pos,
                            'value': True
                        })

                elif len(widgets) and not len(cls.selected):
                    cls.selected.sumar([w for w in widgets if w.selectable])

                elif not cls.selected.has(widgets) and e.button == 1 and len(
                        widgets):
                    order_c = [i for i in widgets if i.order == 'c']
                    if not ctrl and not System.type_mode and not len(order_c):
                        cls.selected.empty()
                    cls.selected.sumar(widgets)

                if len(widgets):
                    for widget in cls.selected.widgets():
                        if widget is not cls.selection:
                            widget.on_mousedown(e)

                elif e.button != 1:
                    widgets = [w for w in cls.widgets.widgets() if w.numerable]
                    if ctrl and not shift:
                        dx, dy = 1, 0
                    elif shift and not ctrl:
                        dx, dy = 0, 5
                    elif ctrl and shift:
                        dx, dy = 5, 0
                    else:
                        dx, dy = 0, 1

                    for widget in widgets:
                        if e.button == 4:
                            dx *= -1
                            dy *= -1
                        elif e.button == 5:
                            dx *= 1
                            dy *= 1

                        widget.rect.move_ip(dx, dy)

            elif e.type == MOUSEBUTTONUP:  # pos, button
                if cls.on_selection and e.button == 1:
                    cls.selection.on_mouseup(e)
                    selected = [
                        i for i in cls.widgets
                        if cls.selection.rect.contains(i.rect)
                    ]
                    cls.selected.sumar(selected)

            elif e.type == MOUSEMOTION:  # pos, rel, buttons
                if e.buttons[0] and len(
                        cls.selected) and not shift and not System.type_mode:
                    for widget in [
                            i for i in cls.selected.widgets()
                            if i.draggable is True
                    ]:
                        widget.on_mousemotion(e)

                elif cls.on_selection and e.buttons[0]:
                    cls.selection.on_mousemotion(e)

                elif ctrl and e.buttons[0]:
                    widgets = [
                        w for w in cls.widgets.widgets()
                        if w.selectable and w.draggable
                    ]
                    for widget in widgets:
                        widget.on_mousemotion(e)

        cls.widgets.update()
コード例 #7
0
            elif e.type == MOUSEMOTION:  # pos, rel, buttons
                if e.buttons[0] and len(
                        cls.selected) and not shift and not System.type_mode:
                    for widget in [
                            i for i in cls.selected.widgets()
                            if i.draggable is True
                    ]:
                        widget.on_mousemotion(e)

                elif cls.on_selection and e.buttons[0]:
                    cls.selection.on_mousemotion(e)

                elif ctrl and e.buttons[0]:
                    widgets = [
                        w for w in cls.widgets.widgets()
                        if w.selectable and w.draggable
                    ]
                    for widget in widgets:
                        widget.on_mousemotion(e)

        cls.widgets.update()

    @classmethod
    def __repr__(cls):
        return cls.name + " ({} widgets)".format(str(len(cls.widgets)))


EventHandler.register(WidgetHandler.toggle_selection, 'AddSelection',
                      'EndSelection')
コード例 #8
0
        return text

    def update(self):
        self.image.fill(COLOR_BOX)
        text = self.get_selected()
        if text and not self.written:
            for char in text:
                self.input_character(char)
            self.written = True

    def __repr__(self):
        return 'TypeBox ' + self.name


EventHandler.register(
    lambda e: TypeBox(None, 0, HEIGHT, WIDTH, HEIGHT // 5, 16, 'MainTB'),
    'Init')


class BaseCharacter(BaseWidget):
    line = None
    x, y = 0, 0

    def place(self, x, y, line):
        self.x, self.y = x, y
        self.rect.move_ip(x, y)
        self.line = line

    def move(self, x, y, line):
        self.x, self.y = x, y
        self.rect.topleft = x, y
コード例 #9
0
        cls.widgets.remove(widget)

    @classmethod
    def update(cls):
        fondo = display.get_surface()
        rect = [fondo.fill(COLOR_BG)]
        if System.type_mode:
            color = (0, 255, 0)
        else:
            color = (255, 0, 0)

        r = fondo.blit(cls.typemode_label, (505, 360))
        cls.typemode_mark.fill(color)
        fondo.blit(cls.typemode_mark, (r.right + 3, r.y))

        rect.extend(cls.widgets.draw(fondo))
        if cls.on_selection:
            corners = [
                cls.selection.rect.topleft, cls.selection.rect.topright,
                cls.selection.rect.bottomright, cls.selection.rect.bottomleft
            ]
            draw.aalines(fondo, cls.selection.color, 1, corners)
        display.update(rect)

    @classmethod
    def toggle_selection(cls, evento):
        cls.on_selection = evento.data['value']


EventHandler.register(Renderer.toggle_selection, 'EndSelection')