Beispiel #1
0
def ui(act: Activity):
    act.text('Entrada', x=act.px(1), y=act.py(0.3), height=act.py(5))
    act.entry('x',
              1,
              int,
              x=act.px(5),
              width=act.px(5),
              height=act.py(5),
              justify=tk.CENTER)
    act.entry('y',
              1,
              int,
              x=act.px(10),
              width=act.px(5),
              height=act.py(5),
              justify=tk.CENTER)
    act.entry('z',
              1,
              int,
              x=act.px(15),
              width=act.px(5),
              height=act.py(5),
              justify=tk.CENTER)
    fArch = act.Frame(act.frame, width=act.px(30), height=act.py(84))
    fEdit = act.Frame(act.frame, width=act.px(68), height=act.py(90))
    fSet = act.Frame(fEdit, width=fEdit.px(50), height=act.py(90))
    fAdd = act.Frame(act.frame, width=fEdit.w, height=act.py(89))

    lista = act.Listbox(x=20,
                        frame=fArch,
                        width=fArch.w - 20,
                        height=fArch.h,
                        font=Font.Font(size=14))
    act.ScroolbarY(lista, frame=fArch, width=20, height=fArch.h)

    params = act.Listbox(frame=fEdit,
                         x=21,
                         y=act.py(6),
                         width=fEdit.px(50),
                         height=fEdit.py(94),
                         font=Font.Font(size=16))
    act.ScroolbarY(params,
                   frame=fEdit,
                   y=act.py(6),
                   width=20,
                   height=fEdit.py(94))

    possibleLayers = act.Listbox(frame=fAdd,
                                 x=21,
                                 y=act.py(6),
                                 width=fAdd.px(50),
                                 height=fAdd.py(94),
                                 font=Font.Font(size=16))
    act.ScroolbarY(possibleLayers,
                   frame=fAdd,
                   y=act.py(6),
                   width=20,
                   height=fAdd.py(94))

    act.label('nomeCamada',
              "NULL",
              frame=fEdit,
              x=fEdit.px(1),
              y=act.py(0.3),
              height=act.py(5))

    def load(*args, **kw):
        fileName = act.askLoad()
        if fileName == '': return
        err, msg = act.extras['arch'].load(fileName)
        if err < 0:
            messagebox.showerror(title="Falha ao carregar Arquitetura",
                                 message=msg)
        else:
            act.setVar('x', act.extras['arch'].entrada[0], True)
            act.setVar('y', act.extras['arch'].entrada[1], True)
            act.setVar('z', act.extras['arch'].entrada[2], True)
            updateArq()

    def compile(*args, **kw):
        fileName = act.askSaveAs()
        if fileName == '': return
        with open(fileName, 'w') as file:
            act.extras['arch'].compile(file)

    menubar = tk.Menu(act.frame)
    filemenu = tk.Menu(menubar, tearoff=0)
    filemenu.add_command(label="Open", command=load)
    filemenu.add_command(label="Save", command=compile)
    filemenu.add_separator()
    filemenu.add_command(label="Exit", command=act.finishprogram)
    menubar.add_cascade(label="File", menu=filemenu)
    act.root.config(menu=menubar)
    act.button('make',
               'Compilar',
               frame=fAdd,
               x=fAdd.px(25),
               y=act.py(0.3),
               width=fAdd.px(23),
               height=act.py(5),
               command=compile)

    act.extras['arch'] = Arquitetura()

    def updateArq(*args, **kw):
        try:
            entrada = [act.getValue('x'), act.getValue('y'), act.getValue('z')]
        except Exception:
            return
        act.extras['arch'].update(entrada)
        lista.delete(0, tk.END)
        for camada in act.extras['arch'].camadas:
            lista.insert(tk.END, camada['name'])
            if not camada['ok']:
                lista.itemconfig(tk.END, {'fg': '#f00'})

    act.getEntry('x').bind('<KeyRelease>', updateArq)
    act.getEntry('y').bind('<KeyRelease>', updateArq)
    act.getEntry('z').bind('<KeyRelease>', updateArq)
    for layer in LAYERS:
        possibleLayers.insert(tk.END, layer['name'])
    possibleLayers.selection_set(0)
    fArch.actplace(y=act.py(6))

    def putParam(*args, **kw):
        if params.size() <= 0:
            return
        if params.size() == 0:
            selc = 0
        else:
            selc = params.curselection()
            if len(selc) >= 1:
                selc = selc[0]
            else:
                return
        putArgs(act.extras['layer_select']['args'][selc])

    def addLayer(*args, **kw):
        if possibleLayers.size() <= 0:
            return
        if possibleLayers.size() == 0:
            select = 0
        else:
            select = possibleLayers.curselection()
            if len(select) >= 1:
                select = select[0]
            else:
                return
        act.extras['arch'].add(LAYERS[select])

        def updefault(layer):
            LAYERS[select] = copy.deepcopy(layer)

        act.extras['upDefault'] = updefault
        # fAdd.place_forget()
        updateArq()
        # editLayer(act.extras['arch'].camadas[-1], -1)

    def editLayer(layer, index):
        act.setVar('nomeCamada', layer['name'] + f' {layer["saida"]}')
        act.extras['layer_select'] = layer
        params.bind('<<ListboxSelect>>', None)
        params.delete(0, tk.END)
        for arg in layer['args']:
            params.insert(tk.END, arg[0])
        fEdit.actplace(x=act.px(32))
        params.selection_set(0, 0)
        params.bind('<<ListboxSelect>>', putParam)
        act.extras['lastplace_set_or_edit'] = fEdit
        act.extras['index_edit_layer'] = index
        putParam()

    act.button('addLayer',
               'Nova camada',
               frame=fAdd,
               x=fAdd.px(1),
               y=act.py(0.3),
               width=fAdd.px(23),
               height=act.py(5),
               command=addLayer)

    def confirm(*args, **kw):
        if act.extras['last_arg_frame'] != None:
            act.extras['last_arg_frame'].place_forget()
            act.extras['last_arg_frame'] = None
        updateArq()
        fEdit.place_forget()
        act.extras['lastplace_set_or_edit'] = fAdd
        fAdd.actplace(x=act.px(32))

    def RemoveLayer(*a, **kw):
        if act.extras['last_arg_frame'] != None:
            act.extras['last_arg_frame'].place_forget()
            act.extras['last_arg_frame'] = None
        act.extras['arch'].remove(act.extras['index_edit_layer'])
        updateArq()
        fEdit.place_forget()
        fAdd.actplace(x=act.px(32))
        act.extras['lastplace_set_or_edit'] = fAdd

    act.extras['last_arg_frame'] = None
    act.button('oklayer',
               'confirm',
               frame=fEdit,
               x=fEdit.px(85),
               y=act.py(0.3),
               width=fEdit.px(9),
               height=act.py(5),
               command=confirm)
    act.button('removeLayer',
               'Remove',
               frame=fEdit,
               x=fEdit.px(75),
               y=act.py(0.3),
               width=fEdit.px(9),
               height=act.py(5),
               command=RemoveLayer)
    # fEdit.actplace(x=act.px(32))
    fSet.actplace(x=fEdit.px(50) + 20)
    #### continuar
    putArgs = makeOptions(act, fSet)
    fAdd.actplace(x=act.px(32))

    def listaChange(*args, **kw):
        if lista.size() <= 0:
            return
        if lista.size() == 0:
            selc = 0
        else:
            selc = lista.curselection()
            if len(selc) >= 1:
                selc = selc[0]
            else:
                return
        fAdd.place_forget()
        act.extras['upDefault'] = None
        editLayer(act.extras['arch'].camadas[selc], selc)

    lista.bind('<<ListboxSelect>>', listaChange)
Beispiel #2
0
def ui(act: Activity):
    treino = act.Frame(act.frame, width=act.px(39), height=act.py(100))
    fitnes = act.Frame(act.frame, width=act.px(39), height=act.py(100))
    grafico = act.Frame(treino, width=treino.px(100), height=treino.py(50))

    act.label("epoca",
              "Epoca ",
              frame=treino,
              x=treino.px(1),
              width=treino.px(30),
              y=10)
    act.ProgressBar('pg_epoca',
                    frame=treino,
                    x=treino.px(32),
                    width=treino.px(50),
                    y=10)
    act.label("tepoca",
              '0 s',
              frame=treino,
              x=treino.px(83),
              width=treino.px(16),
              y=10)

    act.label("imagem",
              "Imagem ",
              frame=treino,
              x=treino.px(1),
              width=treino.px(30),
              y=40)
    act.ProgressBar('pg_imagem',
                    frame=treino,
                    x=treino.px(32),
                    width=treino.px(50),
                    y=40)
    act.label("timagem",
              '0 s',
              frame=treino,
              x=treino.px(83),
              width=treino.px(16),
              y=40)

    act.label("imagem_ft",
              "Imagem ",
              frame=fitnes,
              x=fitnes.px(1),
              width=fitnes.px(30),
              y=40)
    act.ProgressBar('pg_imagem_ft',
                    frame=fitnes,
                    x=fitnes.px(32),
                    width=fitnes.px(50),
                    y=40)
    act.label("timagem_ft",
              '0 s',
              frame=fitnes,
              x=fitnes.px(83),
              width=fitnes.px(16),
              y=40)

    act.text('MSE ', frame=treino, x=treino.px(1), width=treino.px(30), y=70)
    act.label('mse',
              '1',
              frame=treino,
              x=treino.px(32),
              width=treino.px(66),
              y=70)

    act.text('MSE ', frame=fitnes, x=fitnes.px(1), width=fitnes.px(30), y=70)
    act.label('mse_ft',
              '1',
              frame=fitnes,
              x=fitnes.px(32),
              width=fitnes.px(66),
              y=70)

    act.text('Acertos ',
             frame=treino,
             x=treino.px(1),
             width=treino.px(30),
             y=100)
    act.label('rate',
              '0%',
              frame=treino,
              x=treino.px(32),
              width=treino.px(66),
              y=100)

    act.text('Acertos ',
             frame=fitnes,
             x=fitnes.px(1),
             width=fitnes.px(30),
             y=100)
    act.label('rate_ft',
              '0%',
              frame=fitnes,
              x=fitnes.px(32),
              width=fitnes.px(66),
              y=100)

    act.button('stop',
               'Cancelar',
               frame=treino,
               x=treino.px(25),
               width=treino.px(50),
               y=130)
    act.button('stop_ft',
               'Cancelar',
               frame=fitnes,
               x=fitnes.px(25),
               width=fitnes.px(50),
               y=130)

    act.putGraphics(grafico,
                    width=grafico.w,
                    height=grafico.h,
                    title='Info train',
                    data=2,
                    legend=['MSE', 'Acerto'],
                    xlabel='epoca')

    act.setVar('pg_epoca', 0.5)
    # act.setVar('pg_imagem',0.5)

    grafico.actplace(y=treino.px(40))
    treino.actplace(x=act.px(10))
    fitnes.actplace(x=act.px(51))
Beispiel #3
0
def makeOptions(act: Activity, frame: tk.Frame):
    # 2dim
    def update2dim(*args, **kw):
        try:
            x = act.getValue('arg_value_2dim_x')
            y = act.getValue('arg_value_2dim_y')

            act.extras['arg_value'][2][0] = x
            act.extras['arg_value'][2][1] = y
            if act.extras['upDefault'] != None:
                act.extras['upDefault'](act.extras['layer_select'])
        except Exception as e:
            print(e)

    def updatefloat(*args, **kw):
        try:
            floatvalue = act.getValue('arg_value_float')
            act.extras['arg_value'][2] = floatvalue
            if act.extras['upDefault'] != None:
                act.extras['upDefault'](act.extras['layer_select'])
        except Exception:
            return

    def updateint(*args, **kw):
        try:
            intvalue = act.getValue('arg_value_int')
            act.extras['arg_value'][2] = intvalue
            if act.extras['upDefault'] != None:
                act.extras['upDefault'](act.extras['layer_select'])
        except Exception:
            return

    f2dim = act.Frame(frame, width=frame.w, height=frame.py(50))
    act.label('arg_name',
              'null',
              frame=frame,
              x=frame.px(25),
              width=frame.px(50),
              y=frame.py(25) - 30)
    act.entry('arg_value_2dim_x',
              1,
              int,
              frame=f2dim,
              y=30,
              x=f2dim.px(25),
              width=f2dim.px(50),
              justify=tk.CENTER).bind('<KeyRelease>', update2dim)
    act.entry('arg_value_2dim_y',
              1,
              int,
              frame=f2dim,
              y=60,
              x=f2dim.px(25),
              width=f2dim.px(50),
              justify=tk.CENTER).bind('<KeyRelease>', update2dim)

    ffloat = act.Frame(frame, width=frame.w, height=frame.py(50))
    act.entry('arg_value_float',
              1,
              float,
              frame=ffloat,
              y=30,
              x=ffloat.px(25),
              width=ffloat.px(50),
              justify=tk.CENTER).bind('<KeyRelease>', updatefloat)
    fint = act.Frame(frame, width=frame.w, height=frame.py(50))
    act.entry('arg_value_int',
              1,
              int,
              frame=fint,
              y=30,
              x=fint.px(25),
              width=fint.px(50),
              justify=tk.CENTER).bind('<KeyRelease>', updateint)

    foptions = act.Frame(frame, width=frame.w, height=frame.py(50))

    lista = act.Listbox(x=foptions.px(25),
                        width=foptions.px(50),
                        height=foptions.w,
                        frame=foptions)
    act.ScroolbarY(lista,
                   x=foptions.px(25) - 20,
                   width=20,
                   height=foptions.w,
                   frame=foptions)

    def putArgs(arg):
        if act.extras['last_arg_frame'] != None:
            act.extras['last_arg_frame'].place_forget()
        act.setVar('arg_name', arg[0])
        act.extras['arg_value'] = arg
        if arg[1] == 'float':
            act.setVar('arg_value_float', arg[2])
            ffloat.actplace(y=frame.py(25))
            act.extras['last_arg_frame'] = ffloat
        elif arg[1] == 'int':
            act.setVar('arg_value_int', arg[2])
            fint.actplace(y=frame.py(25))
            act.extras['last_arg_frame'] = fint
        elif arg[1] == '2dim':
            act.setVar('arg_value_2dim_x', arg[2][0])
            act.setVar('arg_value_2dim_y', arg[2][1])
            f2dim.actplace(y=frame.py(25))
            act.extras['last_arg_frame'] = f2dim
        elif arg[1] == 'options':
            lista.delete(0, tk.END)
            for op in arg[3]:
                lista.insert(tk.END, op)
            lista.selection_set(arg[2])
            foptions.actplace(y=frame.py(25))
            act.extras['last_arg_frame'] = foptions

    def listaChange(*args, **kw):
        if lista.size() <= 0:
            return
        if lista.size() == 0:
            selc = 0
        else:
            selc = lista.curselection()
            if len(selc) >= 1:
                selc = selc[0]
            else:
                return
        act.extras['arg_value'][2] = act.extras['arg_value'][4][selc]

    lista.bind('<<ListboxSelect>>', listaChange)

    return putArgs