def toggle_connection(a, b, value=True):
    if value:
        Connection(a, b)
    else:
        EventHandler.trigger('DeleteConnection', None, {
            'value': value,
            'parents': [a, b]
        })
 def __init__(self, parent, center):
     super().__init__(parent)
     self.layer = 20
     self.image = Surface((8, 8), SRCALPHA)
     draw.circle(self.image, COLOR_CONNECTION, (3, 3), 4)
     self.rect = self.image.get_rect(center=center)
     Renderer.add_widget(self)
     WidgetHandler.add_widget(self)
     EventHandler.register(self.toggle_selection, 'select', 'deselect')
Ejemplo n.º 3
0
 def button_trigger(self):
     nombre = ''.join(self.input).upper()
     columns = []
     if self.status_precio:
         columns.append('precio')
     if self.status_isbn:
         columns.append('ISBN')
     selection = select_many(nombre, columns) if len(self.input) > 0 else []
     EventHandler.trigger('show_text', 'input', {'text': selection})
Ejemplo n.º 4
0
 def init(cls):
     EventHandler.register(cls.subtotal, 'Subtotal')
     cls.cart = Cart(643, 31, 900 - 640)
     Label('Adquirido', 643, 10, 900 - 640, just=1)
     cls.total_lbl = Label('Total\n$0.00', 643, 400, 900 - 640, just=1)
     b = Button(710, 465, 'Cerrar Compra', action=cls.checkout)
     cls.ultima_chk = Checkbox(b.rect.right + 12, b.rect.centery,
                               'CheckUltimaComra')
     chk = cls.ultima_chk
     Label('Última', chk.rect.right + 3, chk.rect.top - 2, size=12)
Ejemplo n.º 5
0
 def __init__(self, name, text, x, y):
     self.x, self.y = x, y
     self.name = name
     self.f = font.SysFont('Verdana', 16)
     render = self.f.render(text, 1, (0, 0, 0))
     rect = render.get_rect(topleft=(x, y))
     EventHandler.register(self.show, 'show_text')
     super().__init__(render, rect)
     Renderer.add_widget(self, 1)
     WidgetHandler.add_widget(self, 1)
Ejemplo n.º 6
0
    def check(self):
        self.state = not self.state
        if self.state:
            self.image = self.img_true
        else:
            self.image = self.img_false

        EventHandler.trigger('check', self, {
            'name': self.nombre,
            'status': self.state
        })
    def __init__(self, parent_a, parent_b):
        super().__init__()
        self.parent_a = parent_a
        self.parent_b = parent_b
        self.handles = [self.parent_a, self.parent_b]
        self.image = self.create()
        self.rect = self.image.get_rect()
        self.layer = min([self.parent_a.layer, self.parent_b.layer]) - 1
        Renderer.add_widget(self)
        WidgetHandler.add_widget(self)

        EventHandler.register(self.event_handle, 'AddMidPoint')
        EventHandler.register(self.delete, 'DeleteConnection')
Ejemplo n.º 8
0
    def __init__(self, x, y):
        self.f = font.SysFont('Verdana', 16)
        self.empty_f = font.SysFont('Verdana', 16, italic=True)
        self.w, self.h = 310, 23
        self.image = Surface((self.w, self.h))
        self.image.fill(self.color_fondo, (1, 1, self.w - 2, self.h - 2))
        self.rect = self.image.get_rect(topleft=(x, y))
        super().__init__()
        Renderer.add_widget(self)
        WidgetHandler.add_widget(self)
        WidgetHandler.set_active(self)
        EventHandler.register(self.update_status, 'check')

        self.input = []
Ejemplo n.º 9
0
    def __init__(self, data):
        super().__init__()
        self.children = []
        self.fuente = font.SysFont('Verdana', 10)
        self.layer = 1
        self.tipo = data['text'] if data['text'] != '' else 'leaf'
        WidgetHandler.add_widget(self)
        Renderer.add_widget(self)
        self.image = self.create()
        if data['color'] is not None:
            self.colorize(data['color'])
            self.text = data['text']

        self.rect = self.image.get_rect(center=data['pos'])
        EventHandler.register(self.toggle_selection, 'select', 'deselect')
Ejemplo n.º 10
0
 def button_trigger(self):
     nombre = ''.join(self.input).upper()
     txt = costo_por_clave('devir', nombre, 'nombre')
     if txt is None:
         txt = costo_por_clave('sd_dist', nombre, 'titulo')
     try:
         EventHandler.trigger('show_text', 'input', {
             'label': 'precio',
             'text': str(txt[0]),
             "show_price": '$'
         })
     except TypeError:
         text = probar_input(nombre, devolver_todos())
         EventHandler.trigger('show_text', 'input', {
             'label': 'precio',
             'text': str(text),
             "show_price": ''
         })
Ejemplo n.º 11
0
    def __init__(self, x, y, name, initial_state=False):
        super().__init__()
        self.x, self.y = x, y
        self.nombre = name
        self.img_true = self._crear(True)
        self.img_false = self._crear(False)
        self.state = initial_state
        if self.state:
            self.image = self.img_true
        else:
            self.image = self.img_false
        self.rect = self.image.get_rect(center=(self.x, self.y))

        Renderer.add_widget(self)
        WidgetHandler.add_widget(self)
        EventHandler.trigger('check', self, {
            'name': self.nombre,
            'status': self.state
        })
Ejemplo n.º 12
0
    def configure(opcion):
        key, value = None, None
        if opcion == 'Generar una lista de reproducción.':
            import_module('lib.write_and_play')
            # import_module('backend.rate')

        elif opcion == 'Actualizar la cantidad de canciones.':
            key = 'songs'

        elif opcion == 'Cambiar la ruta base de las canciones':
            print('La ruta actual es: {}'.format(config['root']))
            print('\nIngrese la nueva ruta')
            key = 'root'

        elif opcion == 'Cambiar los pesos de las canciones.':
            print('Ésta operación aun no se encuentra disponible')
            print(len(songlist))

        elif opcion == 'Restaurar los pesos de las canciones.':
            key = 'weights'
            import_module('backend.update_songlist')

        elif opcion == 'Actualizar la lista de canciones.':
            if config['weights']:
                print(
                    '\nAlerta: Esta acción restablecerá los pesos de las canciones'
                )
                import_module('backend.update_songlist')

        elif opcion == 'Conservar la lista de reproducción':
            key = 'keeppls'

        elif opcion == 'Cambiar el nombre por defecto de las listas':
            print('\nIngrese el nuevo nombre por defecto')
            key = 'default'

        elif opcion == 'Salir':
            EventHandler.trigger('salir', 'Window', {'texto': 'normal'})

        if key is not None and value is not None:
            config[key] = value
            guardar_json(config, 'config.json')
Ejemplo n.º 13
0
    def update(cls):
        cls.clock.tick(30)
        events = event.get([KEYDOWN, MOUSEBUTTONDOWN, QUIT])
        event.clear()
        for e in events:
            if e.type == QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE):
                EventHandler.trigger('salir', 'engine', {'mensaje': 'normal'})

            elif e.type == KEYDOWN:
                if cls.active is not None:
                    cls.active.on_keydown(e.key)

            elif e.type == KEYUP:
                if cls.active is not None:
                    cls.active.on_keyup(e.key)

            elif e.type == MOUSEBUTTONDOWN:
                for wig in cls.contents:
                    wig.active = False
                widgets = [
                    i for i in cls.contents.sprites()
                    if i.rect.collidepoint(e.pos)
                ]
                for w in widgets:
                    w.on_mousebuttondown(e.button)
                    cls.active = w

            elif e.type == MOUSEBUTTONUP:
                pass

            elif e.tyoe == MOUSEMOTION:
                pass

        x, y = mouse.get_pos()
        for widget in cls.contents.sprites():
            if widget.rect.collidepoint((x, y)):
                widget.on_mouseover()

        cls.contents.update()
Ejemplo n.º 14
0
    def checkout(cls):
        v = 0
        now = datetime.now()
        with cls.open_sales_file(now, 'r') as file:
            for line in file.readlines():
                if 'Venta' in line:
                    v += 1

        with cls.open_sales_file(now, 'a') as file:
            file.write('Venta #' + str(v) + ':' + str(now.hour) + ':' +
                       str(now.minute) + ':' + str(now.second) + '\n')
            for item in cls.cart.items:
                file.write(item.item.name.title() + '.....$' +
                           str(item.item.price) + '\n')
            file.write('Total: $' + str(cls.subtotal_acumulado) + '\n\n')

        cls.cart.clear()
        cls.total_lbl.update_text('Total\n$0.00', just=1)
        cls.subtotal_acumulado = 0

        if cls.ultima_chk.state:
            cls.ultima_compra(now)
            EventHandler.trigger('salir', 'AreaVentas', {})
 def on_mouseup(self, event):
     self.rect.normalize()
     EventHandler.trigger('EndSelection', 'SelectionObject',
                          {'value': False})
     Renderer.del_widget(self)
     WidgetHandler.del_widget(self)
class SelectionBox(BaseWidget):
    layer = 0

    def __init__(self, event):
        x, y = event.data['pos']
        self.rect = Rect(x, y, 1, 1)
        self.color = COLOR_SELECTION
        super().__init__()
        Renderer.enable_selection(self)
        WidgetHandler.enable_selection(self)

    def on_mousemotion(self, event):
        if event.buttons[0]:
            px, py = event.rel
            self.rect.w += px
            self.rect.h += py

    def on_mouseup(self, event):
        self.rect.normalize()
        EventHandler.trigger('EndSelection', 'SelectionObject',
                             {'value': False})
        Renderer.del_widget(self)
        WidgetHandler.del_widget(self)

    def __repr__(self):
        return 'Selection Object @{},{},{},{}'.format(*self.rect)


EventHandler.register(lambda e: SelectionBox(e), 'AddSelection')
Ejemplo n.º 17
0
 def __init__(self, x, y, w, text_h=14):
     super().__init__(x, y, w, text_h)
     EventHandler.register(self.show, 'show_text')
Ejemplo n.º 18
0
 def export(self):
     EventHandler.trigger('AddToCart', self.name, {'item': self.item})
Ejemplo n.º 19
0
 def __init__(self, x, y, w):
     super().__init__(x, y, w, text_h=12)
     EventHandler.register(self.add, 'AddToCart')
Ejemplo n.º 20
0
 def add(self, event):
     item = CartedItem(self, event.data['item'], self.y + self.h, 12)
     self.h += item.h
     self.items.append(item)
     EventHandler.trigger('Subtotal', item.name, {'price': item.item.price})
Ejemplo n.º 21
0
    def __int__(self):
        return self.idx

    def __str__(self):
        return str(self.idx)

    def kill(self):
        WidgetHandler.del_widget(self)
        Renderer.del_widget(self)
        super().kill()

    @property
    def lead(self):
        lenght = len(self.children)
        if lenght > 1:
            return [int(i) for i in self.children]
        elif lenght == 1:
            return int(self.children[0])

    def select(self):
        super().select()
        r = self.rect.copy()
        draw.rect(self.image, self.color_box, [0, 0, r.w, r.h], 1)

    def deselect(self):
        super().deselect()
        self.image.fill(self.color_base)


EventHandler.register(lambda e: Node(e.data), 'AddNode')