| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 
 | #IMPORT MODULES
from tkinter import filedialog
from tkinter import *
import pandas
import os
import csv
from tkinter.ttk import *
from tkinter import ttk
 
#-------------CHART-------------#
#BT = BUTTONS
#LB = LABELS
 
#GLOBAL VAR
global count
count = 0
 
global filepath
filepath=''
 
global data_frame
data_frame = ''
 
global data_frame_stock
data_frame_stock = ''
 
#WINDOW CONFIGURATION
window = Tk()
window.title('Optimisation coupe')
window.geometry('720x720')
window.grid_rowconfigure(0,weight=1)
window.grid_columnconfigure(0,weight=1)
 
#window.resizable(0,0)
 
#PROCEDURES
def proc_importbtn():
 
    filepath =  filedialog.askopenfilename(initialdir = '/',title = 'Select file',filetypes = [('Csv files','*.csv')])
    count = func_count_rows(filepath)
 
    if filepath != '':
        LB_path.config(text=filepath)
        data_frame = pandas.read_csv(filepath,sep=';')
 
        scrollbar = Scrollbar(tab1,orient='vertical')
        scrollbar.grid(row=5,column=5,sticky='ns',rowspan=count)
 
        if count > 0:
            rows=[]
            for x in range(0,count):
                cols=[]
                col = x + 5
                for y in range(0,4):
                    loc = data_frame.iloc[x,y]
                    e = Entry(tab1)
                    e.grid(row=col, column=y, sticky=NSEW)
                    e.insert(END,loc)
                    cols.append(e)
                    e.config(state='disabled')
            rows.append(cols)
 
            BT_calcul_chute = Button(tab1,text='Calculate',command= lambda: proc_calcul_chute(data_frame,data_frame_stock))
            BT_calcul_chute.grid(sticky=NSEW,row=col+1)
 
#FUNCTIONS
def func_count_rows(filepath):
    line_count=0
    with open(filepath,'r') as csv_file:
        csv_reader = csv.reader(csv_file)
        next(csv_reader)
        for row in csv_reader:
            line_count += 1
    return(line_count)
 
def func_entry_creation(window, caption, posy, posx, **options):
    entry = Entry(window)
    entry.grid(row=posx,column=posy)
    entry.insert(END,caption)
    entry.config(state='disable')
    return(entry)
 
def func_LB_creation(name,window,caption,posy,posx,**options):
    name = Label(window,text=caption)
    name.grid(row=posx,column=posy,**options)
    return(name)
 
def proc_calcul_chute(data_frame,data_frame_stock):
    if data_frame_stock.iloc[0,0] != data_frame.iloc[1,0]:
        print("ok")
    loc2= data_frame_stock.iloc[1,2]
    loc= data_frame.iloc[1,2]
 
 
#MAIN
 
tab_control = ttk.Notebook(window)
tab1 = ttk.Frame(tab_control)
tab2 = ttk.Frame(tab_control)
tab_control.add(tab1, text='Optimisation')
tab_control.add(tab2, text='Stock')
tab_control.grid(column=0,row=0)
 
#WINDOW1
LB_description = func_LB_creation('LB_description',tab1,'Current file in use : ',0,1,sticky=W)
LB_path = func_LB_creation('LB_path',tab1,'No file selected',1,1,sticky=W)
LB_profile = func_LB_creation('LB_profile',tab1,'Profil',0,3,sticky=W)
LB_section = func_LB_creation('LB_section',tab1,'Section',1,3,sticky=W)
LB_quantite = func_LB_creation('LB_quantite',tab1,'Quantité',2,3,sticky=W)
LB_longueur = func_LB_creation('LB_longueur',tab1,'Longueur (mm)',3,3,sticky=W)
 
BT_import = Button(tab1, text='Import .csv file', command=proc_importbtn)
BT_import.grid(column=0, row=2, sticky=W)
 
 
#WINDOW2
data_frame_stock = pandas.read_csv('stock.csv',sep=';')
count = func_count_rows('stock.csv')
 
LB_profile = func_LB_creation('LB_profile',tab2,'Profile',0,0,sticky=W)
LB_section = func_LB_creation('LB_section',tab2,'Section',1,0,sticky=W)
LB_longueur = func_LB_creation('LB_longueur',tab2,'Longueur (mm)',2,0,sticky=W)
 
rows=[]
for x in range(0,count):
    cols=[]
    col = x + 1
    for y in range(0,3):
        loc = data_frame_stock.iloc[x,y]
        e = Entry(tab2)
        e.grid(row=col, column=y, sticky=NSEW)
        e.insert(END,loc)
        cols.append(e)
        e.config(state='disabled')
    rows.append(cols)
 
#WINDOW LOOP
window.mainloop() | 
Partager