0

I'm a French engineering student in water-treatment, and for fun I try to develop an app to show all pipes in a city with some feature, like if you click on a pipe, you have access to all informations about it, but I have a problem! I can't make a zoom where all pipes still clickable, and my drag don't work very well.

can you help me? you can also make propositions to improve my code, I'm a beginner :

master  = Tk()
idlist=[0,0,0,0,0,0]
#position clique souris
Ysouris=0
Xsouris=0


#creation
canvas_width = 1000
canvas_height = 600
w= Canvas(master, width=canvas_width, height=canvas_height)
w.pack()

#base de donnée tuyau
cana=[[200,100,"fonte",100,0.174,2018,0,11,400,11],[187,100,"fonte",100,0.174,2018,402,11,776,11],[210,100,"fonte",100,0.174,2018,401,12,401,432],[281.2,100,"fonte",100,0.174,2018,776,11,402,432]]

#creation des conduites
for i in range (len(cana)):
    w.create_line(cana[i][6],cana[i][7],cana[i][8],cana[i][9],fill="blue",width=int(cana[i][1])*0.01*2)

w.bind("<MouseWheel>", do_zoom)
w.bind('<ButtonPress-1>', lambda event: w.scan_mark(event.x, event.y))
w.bind("<B1-Motion>", lambda event: w.scan_dragto(event.x, event.y, gain=1))

def leplusgrandX(A):
    if A[6]<A[8]:
        return A[8]
    else:
        return A[6]
def lepluspetitX(A):
    if A[6]>A[8]:
        return A[8]
    else:
        return A[6]
#verifiaction si sur une canalisation
def estsur(Xpos,Ypos,A):

    w.delete(idlist[len(idlist)-1])
    w.delete(idlist[len(idlist)-2])
    w.delete(idlist[len(idlist)-3])
    w.delete(idlist[len(idlist)-4])
    w.delete(idlist[len(idlist)-5])
    w.delete(idlist[len(idlist)-6])
    w.delete(idlist[len(idlist)-7])

    for i in range (len(A)):


        print("here")
        if (A[i][6]==A[i][8]):
            if A[i][6]==Xpos or A[i][6]==Xpos+1 or A[i][6]==Xpos+2 or A[i][6]==Xpos-1 or A[i][6]==Xpos-2:
                    idlist.append(w.create_rectangle(Xpos,Ypos,Xpos+150,Ypos+120,fill="yellow"))
                    idlist.append(w.create_text(Xpos+75,Ypos+10,text="longueur "+str(A[i][0]),fill="black"))
                    idlist.append(w.create_text(Xpos+75,Ypos+30,text="materiaux:"+A[i][2],fill="black"))
                    idlist.append(w.create_text(Xpos+75,Ypos+50,text="diametre:"+str(A[i][1]),fill="black"))
                    idlist.append(w.create_text(Xpos+75,Ypos+70,text="integrité:"+str(A[i][3]),fill="black"))
                    idlist.append(w.create_text(Xpos+75,Ypos+90,text="debit:"+str(A[i][4]),fill="black"))
                    idlist.append(w.create_text(Xpos+75,Ypos+110,text="année de pose:"+str(A[i][5]),fill="black"))
                    w.pack()





        else:
            if ((int(Ypos)==int(((A[i][7]-A[i][9])/(A[i][6]-A[i][8]))*(Xpos-A[i][6])+A[i][7])) or (int(Ypos+1)==int(((A[i][7]-A[i][9])/(A[i][6]-A[i][8]))*(Xpos-A[i][6])+A[i][7])) or (int(Ypos+2)==int(((A[i][7]-A[i][9])/(A[i][6]-A[i][8]))*(Xpos-A[i][6])+A[i][7]))or (int(Ypos-1)==int(((A[i][7]-A[i][9])/(A[i][6]-A[i][8]))*(Xpos-A[i][6])+A[i][7]))or (int(Ypos-2)==int(((A[i][7]-A[i][9])/(A[i][6]-A[i][8]))*(Xpos-A[i][6])+A[i][7]))or (int(Ypos)==int(((A[i][7]-A[i][9])/(A[i][6]-A[i][8]))*(Xpos-A[i][6])+A[i][7]))) and (Xpos<leplusgrandX(A[i]) and Xpos>lepluspetitX(A[i])):

                    idlist.append(w.create_rectangle(Xpos,Ypos,Xpos+150,Ypos+120,fill="yellow"))
                    idlist.append(w.create_text(Xpos+75,Ypos+10,text="longueur "+str(A[i][0]),fill="black"))
                    idlist.append(w.create_text(Xpos+75,Ypos+30,text="materiaux:"+A[i][2],fill="black"))
                    idlist.append(w.create_text(Xpos+75,Ypos+50,text="diametre:"+str(A[i][1]),fill="black"))
                    idlist.append(w.create_text(Xpos+75,Ypos+70,text="integrité:"+str(A[i][3]),fill="black"))
                    idlist.append(w.create_text(Xpos+75,Ypos+90,text="debit:"+str(A[i][4]),fill="black"))
                    idlist.append(w.create_text(Xpos+75,Ypos+110,text="année de pose:"+str(A[i][5]),fill="black"))
                    w.pack()




def afficher_position(evt):

    pos_x, pos_y = evt.x, evt.y
    affichage = f"Position : abscisse = {pos_x} ; ordonnées = {pos_y}"

    Xsouris,Ysouris=pos_x,pos_y
    estsur(Xsouris,Ysouris,cana)
    idlist=[0,0,0,0,0,0]

def do_zoom(event):
    x = w.canvasx(event.x)
    y = w.canvasy(event.y)
    factor = 1.001 ** event.delta
    w.scale(ALL, x, y, factor, factor)


w.bind("<Button-1>",afficher_position)

mainloop()
cèdre
  • 1
  • 2
  • the next step is to make a sql data base on a raspberry pi and access all the pipe data from it – cèdre Jul 13 '22 at 14:19
  • I don't understand "I can't make a zoom where all pipes still clickable" since the pipes in the given code are not clickable at the moment. Maybe you can use a unique tag for each pipe and use `w.tag_bind(...)` (see e.g. https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/canvas-methods.html) to display the info. Secondly, what do you mean by "my drag don't work very well"? What do you want to improve? – j_4321 Jul 13 '22 at 14:41

1 Answers1

0

I can't make a zoom where all pipes still clickable, and my drag don't work very well.

Move do_zoom(event) function to top and below w.bind("<MouseWheel>", do_zoom)

Screenshot:

enter image description here

toyota Supra
  • 3,181
  • 4
  • 15
  • 19