1 2 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 139 140 141 142 143 144 145
| from configparser import ConfigParser
from tkinter import *
from tkinter import ttk
from tkinter.ttk import *
from tkinter import font
from tkinter import Listbox
import ftplib
import os
#Application parameters
#FTP parametrers
CFG_FILE = ConfigParser()
CFG_FILE.optionxform = str
CFG_FILE.read('ini/application.ini')
print(os.getlogin()+' connected')
APPLICATION_NAME = CFG_FILE.get('APPLICATION_PARAMETERS', 'APPLICATION_NAME')
global FTP_USER, FTP_PASSWORD
FTP_USER = CFG_FILE.get('SECRET', 'USER')
FTP_PASSWORD = CFG_FILE.get('SECRET', 'PASSWORD')
#END FTP
LINE_NAME = CFG_FILE.options('NETWORK_PARAMETERS')
NUMBER_OF_LINE = len(LINE_NAME)
#global hidden_ext =
#Functions
def FTP_GET_folder():
global SELECTED_LINE
print(ComboBox_linechoice.get()+' selected')
SELECTED_LINE=ComboBox_linechoice.get()
#Cell_listbox.delete(0, END)
#ftp connexion
FTP_PARAMETERS = CFG_FILE.get('NETWORK_PARAMETERS', SELECTED_LINE)
SERVER_NAME, PORT, FTP_PATH = FTP_PARAMETERS.split(";")
ftp = ftplib.FTP()
ftp.connect(SERVER_NAME, int(PORT))
ftp.login(FTP_USER, FTP_PASSWORD)
Names = ftp.nlst(FTP_PATH)
CurrentDir = ftp.pwd()
SubDirs = []
for name in Names:
chemin = name
okdir = GET_Only_directories(ftp, chemin)
if okdir:
SubDirs.append(name)
Cell_listbox.delete(0, END)
for SubDir in SubDirs:
SubDirSplit = SubDir.split("/")
LenOfSubDirSplit = len(SubDirSplit)
Cell_listbox.insert(END, SubDirSplit[LenOfSubDirSplit-1])
ftp.close()
def FTP_GET_filesinfolder():
try:
index = Cell_listbox.curselection()[0]
CELL_folder = Cell_listbox.get(index)
print(CELL_folder)
FTP_PARAMETERS = CFG_FILE.get('NETWORK_PARAMETERS', SELECTED_LINE)
SERVER_NAME, PORT, FTP_PATH = FTP_PARAMETERS.split(";")
ftp = ftplib.FTP()
ftp.connect(SERVER_NAME, int(PORT))
ftp.login(FTP_USER, FTP_PASSWORD)
print('Get files in '+FTP_PATH+CELL_folder)
MyList = ftp.nlst(FTP_PATH+CELL_folder)
iFile=0
FilteredFiles=[]
for file in MyList:
if file.split('.')[-1]=='txt':
continue
elif file.split('.')[-1]=='io':
continue
else:
FilteredFiles.append(file)
print(file)
iFile+=1
if iFile==1:
print('One file found')
elif iFile>1:
print(iFile, 'files found')
else:
print('No file found')
#print(FilteredFiles)
except IndexError:
return None
def FTP_READ_file():
print('FTP_READ_file')
def GET_Only_directories(ftp, chemin):
CurrentDir = ftp.pwd()
try:
ftp.cwd(chemin)
ftp.cwd(CurrentDir)
return True
except Exception:
return False
#End of functions
#################################################################################################
#################################################################################################
#MainGUI
MainGUI = Tk()
MainGUI.title(APPLICATION_NAME)
MainGUI.iconbitmap(r'ini/graph_icon.ico')
MainGUI.geometry('1200x600')
Mainfont = font.Font(MainGUI, family='Courier new', size='10')
#LabelFrame for curve selection
labelframe = LabelFrame(MainGUI, text="SELECTION", width='20')
labelframe.grid(padx=5, pady=5)
#Label for ComboBox line choice
Label_linechoice = Label(MainGUI, text="Select a line:", font=Mainfont).grid(row=0, padx=5, pady=5, sticky=W)
#ComboBox line selection
ComboBox_linechoice = ttk.Combobox(values=LINE_NAME, state="readonly", font=Mainfont)
#ComboBox_linechoice.set('Select a line')
ComboBox_linechoice.bind('<<ComboboxSelected>>', lambda e: FTP_GET_folder()) #print(ComboBox_linechoice.get()))
ComboBox_linechoice.grid(row=1, padx=5)
#Label for ListView cell choice
Label_cellchoice = Label(MainGUI, text="Select a cell:", font=Mainfont).grid(row=2, padx=5, pady=5, sticky=W)
Cell_listbox = Listbox(MainGUI, font=Mainfont, height=16, width=22)
Cell_listbox.bind('<<ListboxSelect>>', lambda e: FTP_GET_filesinfolder())
Cell_listbox.grid(padx=5, column=0, sticky='w')
MainGUI.mainloop() |
Partager