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 146 147 148 149 150 151 152
|
# coding:utf-8
#version 3.x python
import sys
from tkinter import *
from tkinter.ttk import *
from tkinter import messagebox # Librairie des fenêtres d'alerte
# ================= Liaison file py =========================
import HV_DB_BackEnd
class Main:
def __init__(self, root):
self.root = root
self.root.title("--------------")
self.root.geometry("620x660+0+0")
self.root.config(bg="cadet blue")
if __name__ =='__main__':
root = Tk()
application = Main(root)
# --- Déclaration Variables - Tableaux
frames = [] # Liste Frames
global Liste_Full
Liste_Full = [] # Liste d'imbrication des L_List (sélection faites depuis Treeview)
global L_SAS_curItem # Liste iid frame
L_SAS_curItem = []
# ======================== Frames Master ====================
MainFrame = LabelFrame(root, text="[TEST]", relief=FLAT)
MainFrame.place(x=5, y=5, width=1300, height=600)
FrameCalc_1 = Frame(name='labels', relief=SOLID, borderwidth=1)
FrameCalc_1.place(x=15, y=220, width=800, height=300)
def removeLabel(var):
global frames
print("\n" + "\n" + "var", var)
z = -1
for frame in frames:
z = z + 1
if frame.winfo_children()[2].var.get() == var: # 6 est le nombre de labels à générer dans une frame - identifie la correspondance de la valeur var (index) de la frame supprimée
print("Frame à supprimer --> ", frame.winfo_children()[2].var.get())
frame.destroy() # Supprime frame dans GUI
frames = frames[:z] + frames[z + 1:] # Mise à jour du nombre de frame
z = -1
# Mise à jour de l'indexation var des frames
r = 0
for frame in frames:
frame.winfo_children()[2].var.set(r)
frame.grid(row=r + 1) # Positionnement de la grille, après suppression d'une frame entre la 1er et la dernière frame GUI.
print("Index frame - removeLabel(var) - ", frame.winfo_children()[2].var.get())
L_SAS_curItem[frame][1] = r
print("r", r)
# Création dynamiquement frame(s) contenant Labels selon la sélection faite depuis TreeView
def selectItem(event):
global frames
var = IntVar()
frame = Frame(FrameCalc_1) # frame généré dans la frame master
L_curItem =[]
# === [Listing Table dans Widget Treeview] ===
curItem = HElist.focus()
Liste = HElist.item(curItem)["values"]
# === [Génére automatiquement de nouveaux widgets Labels] ===
frame.configure(relief=GROOVE)
frame.grid(row=len(frames) + 1, column=5, pady=1) # Nb de Colonne à générer - pady=intervale entre la prochaine
frame.columnconfigure(0, minsize=135) # Largeur de la Colonne
frame.columnconfigure(1, minsize=30)
var.set(len(frames))
L_curItem.append(curItem)
L_curItem.append(var.get())
print("Liste -- L_curItem ", L_curItem)
# Vérification de la redondance de sélection
for u in range(len(L_SAS_curItem)):
print("\n" + "---- L_SAS_curItem[u] ", L_SAS_curItem[u][0], type(L_SAS_curItem[u][0]), curItem, type(curItem))
if curItem == L_SAS_curItem[u][0]:
print("---- L_SAS_curItem[u][1] --> ", L_SAS_curItem[u][0], L_SAS_curItem[u][1], type( L_SAS_curItem[u][1]))
selection = curItem
x = HElist.identify_row(event.y)
if x in selection:
HElist.selection_remove(x)
removeLabel(L_SAS_curItem[u][1])
del L_SAS_curItem[u]
return "break"
if len(frames) < 5:
L_Line = [] # Liste temporaire pour chaque sélection
Champ_Table = [1] # Liste des index de champ cible de la table cible à exploiter
Champ_NomColonne = ["Nom"] # Liste des Noms de champ cible de la table cible correspondant aux index
# -- Génére x Labels "Nom"
for i in range(len(Champ_Table)):
Label(frame, name='%s' % "lb_"+ str(i ), text=Liste[Champ_Table[i]]).grid(row=0, column=i)
ki = '%s' % "lb_"+ str(i) # Nom Label - type str
L_Line.append(Liste[Champ_Table[i]])
# -- Génére widget Button
b = Button(frame, text="Supprimer", width=10, takefocus=False, command=lambda: removeLabel(var))
b.grid(row=0, column=5)
# -- Génère Label - Affiche le N0. de la frame générée
l = Label(frame, textvariable=var)
l.grid(row=0, column=6)
l.var = var
frames.append(frame) # liste des frames générée
Liste_Full.append(L_Line[0:len(L_Line)]) # Imbrique L_Line dans Liste_Full
L_SAS_curItem.append(L_curItem)
print("Liste d'encapsulation -- L_SAS_curItem : ", L_SAS_curItem)
def DisplayData():
a = 0
for i in HV_DB_BackEnd.loadRecord():
HElist.insert('', 'end', text=i[0], values=(i[0], i[1]))
a = a + 1
# ============================== Treeview & Scrollbar Vertical/Horizontal [XY] ========================
HElist = Treeview(MainFrame, selectmode="browse", columns=(1,2), show="headings")
# En-tête
HElist.heading('#1', text="ID")
HElist.heading('#2', text="Nom")
HElist.column('#1', width=0, minwidth=0, stretch=False)
HElist.column('#2', width=160, minwidth=160, stretch=OFF)
HElist.place(x=2, y=2, width=250, height=175)
exclusionlist = ['1'] # Colonne [ID] exclue d'affichage
displaycolumns = ['2'] # Colonne [xxx] affichées
for col in HElist["columns"]:
if not "%s" % col in exclusionlist:
pass
HElist["displaycolumns"] = displaycolumns
HV_DB_BackEnd.loadRecord()
DisplayData()
HElist.bind('<ButtonRelease-1>', selectItem)
root.mainloop() |
Partager