def send_chosen_letter(self):
        """
        Send's the chosen letter
        :return: void
        """
        choice = str(self.comboBox.currentText())
        choice = 0x0000 + ord(choice)

        controller.connect()
        res = controller.set_drive_letter(choice)
        if res == "0x0":
            driveoptions.save_letter_option(choice)
            self.close()
        else:
            self.label.setText("The drive program was not tracebale. Sorry but you\
             could consider reinstalling your ZelDrive.\nThanks")
def del_image(path):
    """
    Borra la imagen de un animal
    """
    success = False
    con = controller.connect()
    c = con.cursor()
    pos = 0
    name = ""
    if path != "":
        while path[pos] != ".":
            name = name + path[pos]
            pos += 1
        query = """DELETE FROM imagen WHERE ubicacion=?"""
        try:
            c.execute(query,[name])
            con.commit()
            success = True
        except sqlite3.Error as e:
            success = False
            print "Error:", e.args[0]
        con.close()
        return success
    else:
        return success
def get_image(id_animal):
    """
    Obtiene la imagen de un animal especifico
    """
    con = controller.connect()
    c = con.cursor()
    query = """SELECT ubicacion, formato FROM imagen WHERE fk_id_animal=?"""
    c.execute(query,[id_animal])
    image = c.fetchone()
    return image
def get_id_animal(animal):
    """
    Obtiene el id del animal
    """
    con = controller.connect()
    c = con.cursor()
    query = """SELECT id_animal FROM animal WHERE nombre_comun=?"""
    c.execute(query, [animal])
    id_animal = c.fetchone()
    result = id_animal[0]
    con.close()
    return result
def get_id_type(tipo):
    """
    Obtiene el id del tipo
    """
    con = controller.connect()
    c = con.cursor()
    query = """SELECT id_tipo FROM tipo WHERE nombre=?"""
    c.execute(query, [tipo])
    id_tipo = c.fetchone()
    result = id_tipo[0]
    con.close()
    return result
def get_image_pix(id_animal):
    """
    Carga la imagen ya almacenada en la base de datos
    """
    con = controller.connect()
    c = con.cursor()
    query = """SELECT ubicacion, formato FROM imagen WHERE fk_id_animal=?"""
    c.execute(query,[id_animal])
    result = c.fetchone()
    if result:
        path = result[0]
        format = result[1]
        image = QDir.currentPath()+"/images/"+path+format
        pixMap = QPixmap(image)
        return pixMap
def search_image(id_animal, Ifile):
    """
    Busca imagen de un animal
    """
    success = False
    con = controller.connect()
    c = con.cursor()
    query = """SELECT ubicacion, formato FROM imagen WHERE fk_id_animal =?"""
    c.execute(query,[id_animal])
    result = c.fetchone()
    try:
        if not result:
            success = True
    except:
        print "asdfasdf"
        success = False
    return success
def add_animal(common,cientific,data,id_type):
    """
    Agrega un nuevo animal a la base de datos
    """
    success = False
    con = controller.connect()
    c = con.cursor()
    values = [common,cientific,data,id_type]
    query = """INSERT INTO animal (nombre_comun, nombre_cientifico, datos, fk_id_tipo) VALUES(?,?,?,?)"""
    try:
        result = c.execute(query, values)
        success = True
        con.commit()
    except sqlite3.Error as e:
        success = False
        print "Error: ", e.args[0]
    con.close()
    return success
def add_image_dir(animal,path):
    """
    Agrega la imagen a la base de datos
    """
    con = controller.connect()
    c = con.cursor()
    pos = 0
    name = ""
    while path[pos] != ".":
        name = name + path[pos]
        pos += 1
    format = ""
    while pos <= len(path)-1:
        format = format + path[pos]
        pos += 1
    query = """INSERT INTO imagen (ubicacion,formato,fk_id_animal) VALUES(?,?,?)"""
    c.execute(query,[name,format,animal])
    con.commit()
    con.close
def edit_animal(id_animal,common,cientific,data,id_type):
    """
    Actualiza el animal en la base de datos
    """
    success = False
    con = controller.connect()
    c = con.cursor()
    values = [common,cientific,data,id_type,id_animal]
    query = """UPDATE animal SET nombre_comun=?, nombre_cientifico =?,
            datos=?, fk_id_tipo=? WHERE id_animal=?"""
    try:
        result = c.execute(query, values)
        success = True
        con.commit()
    except sqlite3.Error as e:
        success = False
        print "Error: ", e.args[0]
    con.close()
    return success
import controller
import data

if __name__ == '__main__':
    log = open('log.txt', 'a+')  #defining a file with logs
    data._DEV, data._COMM_LIB = controller.connect()
    while 1:
        data._TIME, data._CARD = controller.get_event(data._DEV,
                                                      data._COMM_LIB)
        code = controller.hash_query(data._TIME, data._CARD, data.API_KEY)
        controller.perform_query(code)
        controller.contorl_device(data._RESP)
        log.write('\n' + repr(data._LOG.value))
Exemple #12
0
import argparse
import controller
from controller import LED_SIZE, LED_COUNT


def colorize(val, max_val):
    return int(1.0 * val / max_val * 255)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Test that blinkenbox maan!')
    parser.add_argument('dev', help='The device to send commands to')
    args = parser.parse_args()

    with controller.connect(args.dev) as con:
        for x in range(LED_SIZE.w):
            for y in range(LED_SIZE.h):
                controller.set_pixel(con, (x, y), colorize(x, LED_SIZE.h),
                                     colorize(y, LED_SIZE.w),
                                     colorize(x * y, LED_COUNT))
        controller.end_frame(con)
Exemple #13
0
	def DBSession(): 
		session = connect('drinking.db')
		return session()