IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Tkinter Python Discussion :

PySerial - Tkinter et boucle infinie [Python 3.X]


Sujet :

Tkinter Python

  1. #21
    Membre régulier Avatar de Caxton
    Homme Profil pro
    Sans
    Inscrit en
    Janvier 2005
    Messages
    586
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Sans

    Informations forums :
    Inscription : Janvier 2005
    Messages : 586
    Points : 123
    Points
    123
    Par défaut
    Pour le moment non. Mais on peut effectivement ajouter cette option.

    Dans un premier temps, je n'en ai pas besoin car je ne suis distant que de quelques mètres. Le retour vidéo sera suffisamment clair pour savoir si il y a exécution ou non.

    J'ai avancer un chouilla. Quand-même !

    Déjà, je dispose de 4 fichiers. Idle3 commence à me sortir par les yeux ! Au passage est-ce qu'on peut utilisé autre chose qui sait gérer le multipage ?

    Mon main : POSL-Rover.py
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
     
     
    # -- IMPORTATIONS
    import tkinter as tk
     
    from ihm import IHM
    from rover import ROVER
    from com import COM
     
    # -- MAIN
    root = tk.Tk()
     
    ihm = IHM(root)
    ihm.grid(column=0, row=0, sticky='NS')
     
    rover = ROVER(root)
     
    root.title('POSL Rover')    #Titre de l'application
    root.mainloop()             #Boucler
    Ensuite, mon IHM:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    # -- IMPORTATIONS
    import tkinter as tk
     
    # -- CLASSE Interface graphique
    class IHM(tk.Frame):
     
        #Initialisation
        def __init__(self, parent):
            #Variables
            self.parent = parent
     
            #Les frames
            tk.Frame.__init__(self, self.parent)
            self.boutons = tk.LabelFrame(self, text="Contoles", padx=20, pady=20)
            self.logs = tk.LabelFrame(self, text="Logs", padx=20, pady=20)
     
            #Images
            self.myImgAV = tk.PhotoImage(file="ressources/icones/av.gif")
            self.myImgCO = tk.PhotoImage(file="ressources/icones/co.gif")
     
            #Boutons
            self.btAV = tk.Button(self.boutons, image=self.myImgAV, bg = "grey")
            self.btCO = tk.Button(self.boutons, image=self.myImgCO, bg = "green")
     
            #Textes
            self.textLogs = tk.Text(self.logs, width=50, height=20, wrap=tk.WORD)
     
            #Position des boutons
            self.boutons.grid(column=0, row=0, sticky='NS')
            self.btCO.grid(column=0, row=0)
            self.btAV.grid(column=2, row=1)
     
            #Position du log
            self.logs.grid(column=0, row=1, sticky='NS')
            self.textLogs.grid(column=0, row=0)
    Mon début de classe action que je finirais plus tard
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     
     
    # --CLASSE rover
    class ROVER():
     
        #Initialisation
        def __init__(self, parent):
     
            #Variables
            self.parent = parent
     
        """
            Ici on place toutes les fonctions que feront le rover
            -> Admet des infos de l'IHM
            <- Retourne des datas à envoyer sur le port série
        """
    Et enfin mon fichier connexion:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    # -- IMPORTATIONS
    import serial
     
    # -- CLASSE Communication
    class COM():
     
        #Initialisation
        def __init__(self, parent):
     
            #Variables
            self.parent = parent
     
            self.locations=['/dev/ttyUSB0', '/dev/ttyUSB1', '/dev/ttyUSB2', '/dev/ttyUSB3', '/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2', '/dev/ttyS3']
            self.ser = ''
            self.serialConnection = 0
     
        #Connexion Serie
        def getSerialConnexion(self):
     
            #Tentative de connexion au XBee Usb
            for device in self.locations:
     
                try:
                    information = "Tentative de connecion sur le port" + device + "...\n"
                    self.textInfos.insert(0.0, information)
                    self.ser = serial.Serial(device, 9600)
                    self.serialConnection = 1
                    break
     
                except:
                    information = "Connection échoué sur " + device + "!\n"
                    self.textInfos.insert(0.0, information)
                    self.serialConnection = 0
     
            return self.serialConnection
    Il faut maintenant que je trouve deux choses.
    1/ Comment le bouton connexion ira déclencher la fonction connexion ?
    2/ Comment la méthode getSerialConnexion ira donné des infos dans l'IHM ?

  2. #22
    Membre régulier Avatar de Caxton
    Homme Profil pro
    Sans
    Inscrit en
    Janvier 2005
    Messages
    586
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Sans

    Informations forums :
    Inscription : Janvier 2005
    Messages : 586
    Points : 123
    Points
    123
    Par défaut
    J'essaie quand même !

    Mais
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    Traceback (most recent call last):
      File "POSL-Rover.py", line 12, in <module>
        ihm = IHM(root)
      File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/ihm.py", line 25, in __init__
        self.btCO = tk.Button(self.boutons, image=self.myImgCO, bg = "green", command=COM.getSerialConnexion)
    NameError: global name 'COM' is not defined
    Et pourtant j'ai fait cela :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     
     
    # -- IMPORTATIONS
    import tkinter as tk
     
    from ihm import IHM
    from rover import ROVER
    from com import COM
     
    # -- MAIN
    root = tk.Tk()
     
    ihm = IHM(root)
    ihm.grid(column=0, row=0, sticky='NS')
     
    rover = ROVER(root)
    com = COM(root)
     
    root.title('POSL Rover')    #Titre de l'application
    root.mainloop()             #Boucler
    Et
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    # -- IMPORTATIONS
    import serial
     
    # -- CLASSE Communication
    class COM():
     
    	#Initialisation
    	def __init__(self, parent):
     
    		#Variables
    		self.parent = parent
     
    		self.locations=['/dev/ttyUSB0', '/dev/ttyUSB1', '/dev/ttyUSB2', '/dev/ttyUSB3', '/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2', '/dev/ttyS3']
    		self.ser = ''
    		self.serialConnection = 0
     
    		#Connexion Serie
    		def getSerialConnexion(self):
     
    			#Tentative de connexion au XBee Usb
    			for device in self.locations:
    				try:
    					information = "Tentative de connecion sur le port" + device + "...\n"
    					IHM.setLog(information)
     
    					self.ser = serial.Serial(device, 9600)
    					self.serialConnection = 1
    					break
     
    				except:
    					information = "Connection échoué sur " + device + "!\n"
    					self.textInfos.insert(0.0, information)
    					self.serialConnection = 0
     
    					return self.serialConnection
    Et
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    # -- IMPORTATIONS
    import tkinter as tk
     
    # -- CLASSE Interface graphique
    class IHM(tk.Frame):
     
    	#Initialisation
    	def __init__(self, parent):
     
    		#Variables
    		self.parent = parent
     
    		#Les frames
    		tk.Frame.__init__(self, self.parent)
    		self.boutons = tk.LabelFrame(self, text="Contoles", padx=20, pady=20)
    		self.logs = tk.LabelFrame(self, text="Logs", padx=20, pady=20)
     
    		#Images
    		self.myImgAV = tk.PhotoImage(file="ressources/icones/av.gif")
    		self.myImgCO = tk.PhotoImage(file="ressources/icones/co.gif")
     
    		#Boutons
    		self.btAV = tk.Button(self.boutons, image=self.myImgAV, bg = "grey")
    		self.btCO = tk.Button(self.boutons, image=self.myImgCO, bg = "green", command=COM.getSerialConnexion)
     
    		#Textes
    		self.textLogs = tk.Text(self.logs, width=50, height=20, wrap=tk.WORD)
     
    		#Position des boutons
    		self.boutons.grid(column=0, row=0, sticky='NS')
    		self.btCO.grid(column=0, row=0)
    		self.btAV.grid(column=2, row=1)
     
    		#Position du log
    		self.logs.grid(column=0, row=1, sticky='NS')
    		self.textLogs.grid(column=0, row=0)
     
    		#Afficher des informations
    		def setLog(self, informations):
    			self.textLogs.insert(0.0, informations)
    Et enfin
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     
     
    # --CLASSE rover
    class ROVER():
     
    	#Initialisation
    	def __init__(self, parent):
     
    		#Variables
    		self.parent = parent
     
    	"""
                    Ici on place toutes les fonctions que feront le rover
                    -> Admet des infos de l'IHM
                    <- Retourne des datas à envoyer sur le port série
            """
    Voila, je suis bloqué pour le moment...

  3. #23
    Membre chevronné
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2013
    Messages
    1 608
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2013
    Messages : 1 608
    Points : 2 072
    Points
    2 072
    Par défaut
    Citation Envoyé par Caxton Voir le message

    Déjà, je dispose de 4 fichiers. Idle3 commence à me sortir par les yeux ! Au passage est-ce qu'on peut utilisé autre chose qui sait gérer le multipage ?
    Spyder !
    Pas d'aide par mp.

  4. #24
    Membre régulier Avatar de Caxton
    Homme Profil pro
    Sans
    Inscrit en
    Janvier 2005
    Messages
    586
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Sans

    Informations forums :
    Inscription : Janvier 2005
    Messages : 586
    Points : 123
    Points
    123
    Par défaut
    Ok, vue pour spyder

    Bon, maintenant, reste à résoudre l'erreur que je rencontre ! Là, je demande un peu d'aide pour comprendre cet exemple et ensuite ça devrais pas trop mal se passer je pense.

  5. #25
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 285
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 285
    Points : 36 773
    Points
    36 773
    Par défaut
    Salut,

    Citation Envoyé par Caxton Voir le message
    Déjà, je dispose de 4 fichiers. Idle3 commence à me sortir par les yeux ! Au passage est-ce qu'on peut utilisé autre chose qui sait gérer le multipage ?
    Quelque soit l'éditeur, pas facile de distribuer rôles et responsabilités et répartir les instructions qui vont avec dans plusieurs fichiers à la fois... surtout lorsque les idées ne sont pas encore claires.
    Comme vous encapsulez tout dans des classes, vous pouvez commencer par tout garder dans un même fichier.
    Pour ce qui est d'un IDE Python, vous en avez des tas. Ils sont plus ou moins compliqués à installer, apprendre à utiliser,... et il faut en essayer plusieurs pour voir celui qui vous convient le mieux.

    Citation Envoyé par Caxton Voir le message
    Il faut maintenant que je trouve deux choses.
    1/ Comment le bouton connexion ira déclencher la fonction connexion ?
    2/ Comment la méthode getSerialConnexion ira donné des infos dans l'IHM ?
    Relisez le post d'hier matin. J'y fait le boulot pour "avancer".

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  6. #26
    Membre régulier Avatar de Caxton
    Homme Profil pro
    Sans
    Inscrit en
    Janvier 2005
    Messages
    586
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Sans

    Informations forums :
    Inscription : Janvier 2005
    Messages : 586
    Points : 123
    Points
    123
    Par défaut
    Citation Envoyé par wiztricks Voir le message
    Salut,

    Quelque soit l'éditeur, pas facile de distribuer rôles et responsabilités et répartir les instructions qui vont avec dans plusieurs fichiers à la fois... surtout lorsque les idées ne sont pas encore claires.
    Comme vous encapsulez tout dans des classes, vous pouvez commencer par tout garder dans un même fichier.
    Pour ce qui est d'un IDE Python, vous en avez des tas. Ils sont plus ou moins compliqués à installer, apprendre à utiliser,... et il faut en essayer plusieurs pour voir celui qui vous convient le mieux.
    Geany fait le taff pour moi. Donc sujet clos !

    Citation Envoyé par wiztricks Voir le message
    Salut,

    Relisez le post d'hier matin. J'y fait le boulot pour "avancer".

    - W
    Justement, si je demande d'autres infos, c'est que j'ai pas tout compris. Mes classes ne se voient donc pas ?

  7. #27
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 285
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 285
    Points : 36 773
    Points
    36 773
    Par défaut
    Citation Envoyé par Caxton Voir le message
    Justement, si je demande d'autres infos, c'est que j'ai pas tout compris. Mes classes ne se voient donc pas ?
    C'est pour cela que je vous ai suggéré de remettre vos classes dans un même fichier.
    Cela devrait corriger le "nameerror" et planter un peu plus loin car... vous n'avez rien fait pour instancier votre classe.

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  8. #28
    Membre régulier Avatar de Caxton
    Homme Profil pro
    Sans
    Inscrit en
    Janvier 2005
    Messages
    586
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Sans

    Informations forums :
    Inscription : Janvier 2005
    Messages : 586
    Points : 123
    Points
    123
    Par défaut
    Justement, je ne veux pas que ça reste dans un même fichier (trop laborieux à maintenir).

    Ok pour l'instanciation, je pensait l'avoir fait

    Mais bon, je veux bien essayer ta méthode...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    # -- IMPORTATIONS
    import tkinter as tk
    import serial
     
    # -- CLASSE Interface graphique
    class IHM(tk.Frame):
     
    	#Initialisation
    	def __init__(self, parent):
     
    		#Variables
    		self.parent = parent
     
    		#Les frames
    		tk.Frame.__init__(self, self.parent)
    		self.boutons = tk.LabelFrame(self, text="Contoles", padx=20, pady=20)
    		self.logs = tk.LabelFrame(self, text="Logs", padx=20, pady=20)
     
    		#Images
    		self.myImgAV = tk.PhotoImage(file="ressources/icones/av.gif")
    		self.myImgCO = tk.PhotoImage(file="ressources/icones/co.gif")
     
    		#Boutons
    		self.btAV = tk.Button(self.boutons, image=self.myImgAV, bg = "grey")
    		self.btCO = tk.Button(self.boutons, image=self.myImgCO, bg = "green", command=COM.getSerialConnexion)
     
    		#Textes
    		self.textLogs = tk.Text(self.logs, width=50, height=20, wrap=tk.WORD)
     
    		#Position des boutons
    		self.boutons.grid(column=0, row=0, sticky='NS')
    		self.btCO.grid(column=0, row=0)
    		self.btAV.grid(column=2, row=1)
     
    		#Position du log
    		self.logs.grid(column=0, row=1, sticky='NS')
    		self.textLogs.grid(column=0, row=0)
     
    		#Afficher des informations
    		def setLog(self, informations):
    			self.textLogs.insert(0.0, informations)
     
    # --CLASSE rover
    class ROVER():
     
    	#Initialisation
    	def __init__(self, parent):
     
    		#Variables
    		self.parent = parent
     
    	"""
                    Ici on place toutes les fonctions que feront le rover
                    -> Admet des infos de l'IHM
                    <- Retourne des datas à envoyer sur le port série
            """
     
    # -- CLASSE Communication
    class COM():
     
    	#Initialisation
    	def __init__(self, parent):
     
    		#Variables
    		self.parent = parent
     
    		self.locations=['/dev/ttyUSB0', '/dev/ttyUSB1', '/dev/ttyUSB2', '/dev/ttyUSB3', '/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2', '/dev/ttyS3']
    		self.ser = ''
    		self.serialConnection = 0
     
    		#Connexion Serie
    		def getSerialConnexion(self):
     
    			#Tentative de connexion au XBee Usb
    			for device in self.locations:
    				try:
    					information = "Tentative de connecion sur le port" + device + "...\n"
    					IHM.setLog(information)
     
    					self.ser = serial.Serial(device, 9600)
    					self.serialConnection = 1
    					break
     
    				except:
    					information = "Connection échoué sur " + device + "!\n"
    					self.textInfos.insert(0.0, information)
    					self.serialConnection = 0
     
    					return self.serialConnection 
     
     
    # -- MAIN
    root = tk.Tk()
     
    ihm = IHM(root)
    ihm.grid(column=0, row=0, sticky='NS')
     
    rover = ROVER(root)
    com = COM(root)
     
    root.title('POSL Rover')    #Titre de l'application
    root.mainloop()             #Boucler
    Et du coup, ça bloque plus loin, en effet
    Traceback (most recent call last):
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 100, in <module>
    ihm = IHM(root)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 26, in __init__
    self.btCO = tk.Button(self.boutons, image=self.myImgCO, bg = "green", command=COM.getSerialConnexion)
    AttributeError: type object 'COM' has no attribute 'getSerialConnexion'

  9. #29
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 285
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 285
    Points : 36 773
    Points
    36 773
    Par défaut
    Salut,

    Citation Envoyé par Caxton Voir le message
    Mais bon, je veux bien essayer ta méthode...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Traceback (most recent call last):
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 100, in <module>
    ihm = IHM(root)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 26, in __init__
    self.btCO = tk.Button(self.boutons, image=self.myImgCO, bg = "green", command=COM.getSerialConnexion)
    AttributeError: type object 'COM' has no attribute 'getSerialConnexion'
    Et du coup, ça bloque plus loin, en effet
    Revoyez l'indentation du block qui définit "getSerialConnexion".
    Tel que vous l'avez écrit c'est une fonction déclarée dans __init__ et non une méthode de la classe COM.

    De plus, si "COM" est le nom de la classe, l'instance a été crée dans la variable globale "com".

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  10. #30
    Membre régulier Avatar de Caxton
    Homme Profil pro
    Sans
    Inscrit en
    Janvier 2005
    Messages
    586
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Sans

    Informations forums :
    Inscription : Janvier 2005
    Messages : 586
    Points : 123
    Points
    123
    Par défaut
    Ok ! Exact pour l'indentation. Erreur de recopie de ma part

    Bon, je viens de tomber sur un petit exemple de callback. Faut que j'essaie de comprendre.

    Pour l'histoire de COM / com cela veut-il dire qu'il n'y a pas de respect de la casse ?

    Voilà ou j'en suis actuellement :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    # -- IMPORTATIONS
    import tkinter as tk
    import serial
     
    # -- CLASSE Interface graphique
    class IHM(tk.Frame):
     
        #Initialisation
        def __init__(self, parent):
     
            #Variables
            self.parent = parent
            self.connexion = COM()
     
            #Les frames
            tk.Frame.__init__(self, self.parent)
            self.boutons = tk.LabelFrame(self, text="Contoles", padx=20, pady=20)
            self.logs = tk.LabelFrame(self, text="Logs", padx=20, pady=20)
     
            #Images
            self.myImgAV = tk.PhotoImage(file="ressources/icones/av.gif")
            self.myImgCO = tk.PhotoImage(file="ressources/icones/co.gif")
     
            #Boutons
            self.btAV = tk.Button(self.boutons, image=self.myImgAV, bg = "grey")
            self.btCO = tk.Button(self.boutons, image=self.myImgCO, bg = "green", command=callback_connexion)
     
            #Textes
            self.textLogs = tk.Text(self.logs, width=50, height=20, wrap=tk.WORD)
     
            #Position des boutons
            self.boutons.grid(column=0, row=0, sticky='NS')
            self.btCO.grid(column=0, row=0)
            self.btAV.grid(column=2, row=1)
     
            #Position du log
            self.logs.grid(column=0, row=1, sticky='NS')
            self.textLogs.grid(column=0, row=0)
     
        #Afficher des informations
        def setLog(self, informations):
            self.textLogs.insert(0.0, informations)
     
        #Callback : Connexion
        def callback_connexion(self, parent):
            self.COM.getSerialConnexion()
     
    # --CLASSE rover
    class ROVER():
     
        #Initialisation
        def __init__(self, parent):
     
            #Variables
            self.parent = parent
     
            """
                Ici on place toutes les fonctions que feront le rover
                -> Admet des infos de l'IHM
                <- Retourne des datas à envoyer sur le port série
            """
     
    # -- CLASSE Communication
    class COM():
     
        #Initialisation
        def __init__(self, parent):
            #Variables
            self.parent = parent
            self.locations=['/dev/ttyUSB0', '/dev/ttyUSB1', '/dev/ttyUSB2', '/dev/ttyUSB3', '/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2', '/dev/ttyS3']
            self.ser = ''
            self.serialConnection = 0
     
        #Connexion Serie
        def getSerialConnexion(self):
     
            #Tentative de connexion au XBee Usb
            for device in self.locations:
     
                try:
                    information = "Tentative de connecion sur le port" + device + "...\n"
                    IHM.setLog(information)
     
                    self.ser = serial.Serial(device, 9600)
                    self.serialConnection = 1
                    break
     
                except:
                    information = "Connection échoué sur " + device + "!\n"
                    self.textInfos.insert(0.0, information)
                    self.serialConnection = 0
     
            return self.serialConnection 
     
    # -- MAIN
    root = tk.Tk()
     
    ihm = IHM(root)
    ihm.grid(column=0, row=0, sticky='NS')
     
    rover = ROVER(root)
    com = COM(root)
     
    root.title('POSL Rover')    #Titre de l'application
    root.mainloop()             #Boucler
    Traceback (most recent call last):
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 99, in <module>
    ihm = IHM(root)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM()
    TypeError: __init__() takes exactly 2 arguments (1 given)
    Faut que j'essaie en remplaçant COM par com...

  11. #31
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 285
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 285
    Points : 36 773
    Points
    36 773
    Par défaut
    Citation Envoyé par Caxton Voir le message
    Pour l'histoire de COM / com cela veut-il dire qu'il n'y a pas de respect de la casse ?

    Voilà ou j'en suis actuellement :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    ...
    # -- MAIN
    root = tk.Tk()
     
    ihm = IHM(root)
    ihm.grid(column=0, row=0, sticky='NS')
     
    rover = ROVER(root)
    com = COM(root)
     
    root.title('POSL Rover')    #Titre de l'application
    root.mainloop()             #Boucler
    A quoi sert le "com = COM(root)" si vous ne vous en servez pas?
    Pourquoi "com" aurait besoin de récupérer "root"?
    Éventuellement, "rover" devrait récupérer "com" et ihm" devrait récupérer "rover".
    Dans tous les cas, la connaissance par rover et com de l'interface devrait être limitée.

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  12. #32
    Membre régulier Avatar de Caxton
    Homme Profil pro
    Sans
    Inscrit en
    Janvier 2005
    Messages
    586
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Sans

    Informations forums :
    Inscription : Janvier 2005
    Messages : 586
    Points : 123
    Points
    123
    Par défaut
    Citation Envoyé par wiztricks Voir le message
    A quoi sert le "com = COM(root)" si vous ne vous en servez pas?
    Diable ! Je pensait qu'on était obliger à un moment donné de dire que la classe était accessible

    Citation Envoyé par wiztricks Voir le message
    Pourquoi "com" aurait besoin de récupérer "root"?
    Diable ! Je pensait aussi que c'étais la bonne façon de faire.

    Citation Envoyé par wiztricks Voir le message
    Éventuellement, "rover" devrait récupérer "com" et ihm" devrait récupérer "rover".
    Oui, ça me paraît logique. Comment devrais-je m'y prendre pour que ce soit le cas ?
    Je proposerais bien ceci : rover = ROVER(com, ihm) à codition d'avoir au dessus com = COM() non ?

    Citation Envoyé par wiztricks Voir le message
    Dans tous les cas, la connaissance par rover et com de l'interface devrait être limitée.
    Ah bon ?

    J'ai tester cela....
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    # -- IMPORTATIONS
    import tkinter as tk
    import serial
     
    # -- CLASSE Interface graphique
    class IHM(tk.Frame):
     
        #Initialisation
        def __init__(self, parent):
     
            #Variables
            self.parent = parent
            self.connexion = COM(parent)
     
            #Les frames
            tk.Frame.__init__(self, self.parent)
            self.boutons = tk.LabelFrame(self, text="Contoles", padx=20, pady=20)
            self.logs = tk.LabelFrame(self, text="Logs", padx=20, pady=20)
     
            #Images
            self.myImgAV = tk.PhotoImage(file="ressources/icones/av.gif")
            self.myImgCO = tk.PhotoImage(file="ressources/icones/co.gif")
     
            #Boutons
            self.btAV = tk.Button(self.boutons, image=self.myImgAV, bg = "grey")
            self.btCO = tk.Button(self.boutons, image=self.myImgCO, bg = "green", command=self.callback_connexion)
     
            #Textes
            self.textLogs = tk.Text(self.logs, width=50, height=20, wrap=tk.WORD)
     
            #Position des boutons
            self.boutons.grid(column=0, row=0, sticky='NS')
            self.btCO.grid(column=0, row=0)
            self.btAV.grid(column=2, row=1)
     
            #Position du log
            self.logs.grid(column=0, row=1, sticky='NS')
            self.textLogs.grid(column=0, row=0)
     
        #Afficher des informations
        def setLog(self, informations):
            self.textLogs.insert(0.0, informations)
     
        #Callback : Connexion
        def callback_connexion(self):
            self.connexion.getSerialConnexion()
     
    # --CLASSE rover
    class ROVER():
     
        #Initialisation
        def __init__(self, parent):
     
            #Variables
            self.parent = parent
     
            """
                Ici on place toutes les fonctions que feront le rover
                -> Admet des infos de l'IHM
                <- Retourne des datas à envoyer sur le port série
            """
     
    # -- CLASSE Communication
    class COM():
     
        #Initialisation
        def __init__(self, parent):
            #Variables
            self.parent = parent
            self.log = IHM(parent)
     
            self.locations=['/dev/ttyUSB0', '/dev/ttyUSB1', '/dev/ttyUSB2', '/dev/ttyUSB3', '/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2', '/dev/ttyS3']
            self.ser = ''
            self.serialConnection = 0
     
        #Connexion Serie
        def getSerialConnexion(self):
     
            #Tentative de connexion au XBee Usb
            for device in self.locations:
     
                try:
                    information = "Tentative de connecion sur le port" + device + "...\n"
                    #self.callback_log(information)
     
     
                    self.ser = serial.Serial(device, 9600)
                    self.serialConnection = 1
                    break
     
                except:
                    information = "Connection échoué sur " + device + "!\n"
                    #self.textInfos.insert(0.0, information)
                    self.serialConnection = 0
     
            return self.serialConnection
     
        #Callback : Ihm
        #def callback_log(self, parent, information):
            #self.log.setLog(information)
     
    # -- MAIN
    root = tk.Tk()
     
    ihm = IHM(root)
    ihm.grid(column=0, row=0, sticky='NS')
     
    #rover = ROVER(root)
    #com = COM(root)
     
    root.title('POSL Rover')    #Titre de l'application
    root.mainloop()             #Boucler
    Mais alors ! Banzaï !
    Python 3.2.3 (default, Feb 27 2014, 21:31:18)
    [GCC 4.6.3] on linux2
    Type "copyright", "credits" or "license()" for more information.
    ==== No Subprocess ====
    >>>
    Traceback (most recent call last):
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 106, in <module>
    ihm = IHM(root)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 71, in __init__
    self.log = IHM(parent)
    File "/home/alexandre/Documents/Programmations/Python/POSL-Rover/POSL-Rover.py", line 14, in __init__
    self.connexion = COM(parent)
    RuntimeError: maximum recursion depth exceeded while calling a Python object
    >>>

  13. #33
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 285
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 285
    Points : 36 773
    Points
    36 773
    Par défaut
    Salut,

    Citation Envoyé par Caxton Voir le message
    Diable ! Je pensait qu'on était obliger à un moment donné de dire que la classe était accessible
    ...

    Diable ! Je pensait aussi que c'étais la bonne façon de faire.
    ...

    Oui, ça me paraît logique. Comment devrais-je m'y prendre pour que ce soit le cas ?
    Je proposerais bien ceci : rover = ROVER(com, ihm) à codition d'avoir au dessus com = COM() non ?
    Si vous écrivez:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    def g():
         f()
    def f():
         g()
    C'est sûr que ça va boucler car la machine s'applique à faire ce que vous lui demandez même si c'est n'importe quoi car elle ne lit pas encore vos pensées.
    Bien sûr, dans votre cas, la boucle n'est pas aussi "simple" à voir: elle est indirecte et enfouie dans pleins de lignes de code.
    C'est la raison pour laquelle, programmer est difficile et qu'on a mis à votre disposition plein de tutos pour vous permettre d'apprendre à votre rythme.

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  14. #34
    Membre régulier Avatar de Caxton
    Homme Profil pro
    Sans
    Inscrit en
    Janvier 2005
    Messages
    586
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Sans

    Informations forums :
    Inscription : Janvier 2005
    Messages : 586
    Points : 123
    Points
    123
    Par défaut
    J'ai nettoyé un peu ce que j'avais fait. Mis en commentaire ce qui semblais pas correct car inutilisé.

    Cela fonctionne, le bouton connexion aussi mais maintenant, je cherche à remonter l'info dans l'ihm pour dire si on est connecté ou non.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    # -- IMPORTATIONS
    import tkinter as tk
    import serial
     
    # -- CLASSE Interface graphique
    class IHM(tk.Frame):
     
        #Initialisation
        def __init__(self, parent):
     
            #Variables
            self.parent = parent
            self.connexion = COM(parent)
     
            #Les frames
            tk.Frame.__init__(self, self.parent)
            self.boutons = tk.LabelFrame(self, text="Contoles", padx=20, pady=20)
            self.logs = tk.LabelFrame(self, text="Logs", padx=20, pady=20)
     
            #Images
            self.myImgAV = tk.PhotoImage(file="ressources/icones/av.gif")
            self.myImgCO = tk.PhotoImage(file="ressources/icones/co.gif")
     
            #Boutons
            self.btAV = tk.Button(self.boutons, image=self.myImgAV, bg = "grey")
            self.btCO = tk.Button(self.boutons, image=self.myImgCO, bg = "green", command=self.callback_connexion)
     
            #Textes
            self.textLogs = tk.Text(self.logs, width=50, height=20, wrap=tk.WORD)
     
            #Position des boutons
            self.boutons.grid(column=0, row=0, sticky='NS')
            self.btCO.grid(column=0, row=0)
            self.btAV.grid(column=2, row=1)
     
            #Position du log
            self.logs.grid(column=0, row=1, sticky='NS')
            self.textLogs.grid(column=0, row=0)
     
        #Afficher des informations
        def setLog(self, informations):
            self.textLogs.insert(0.0, informations)
     
        #Callback : Connexion
        def callback_connexion(self):
            self.connexion.getSerialConnexion()
     
    # --CLASSE rover
    class ROVER():
     
        #Initialisation
        def __init__(self, parent):
     
            #Variables
            self.parent = parent
     
            """
                Ici on place toutes les fonctions que feront le rover
                -> Admet des infos de l'IHM
                <- Retourne des datas à envoyer sur le port série
            """
     
    # -- CLASSE Communication
    class COM():
     
        #Initialisation
        def __init__(self, parent):
            #Variables
            self.parent = parent
     
            self.locations=['/dev/ttyUSB0', '/dev/ttyUSB1', '/dev/ttyUSB2', '/dev/ttyUSB3', '/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2', '/dev/ttyS3']
            self.ser = ''
            self.serialConnection = 0
     
        #Connexion Serie
        def getSerialConnexion(self):
     
            #Tentative de connexion au XBee Usb
            for device in self.locations:
     
                try:
                    information = "Tentative de connecion sur le port" + device + "...\n"
     
                    self.ser = serial.Serial(device, 9600)
                    self.serialConnection = 1
                    break
     
                except:
                    information = "Connection échoué sur " + device + "!\n"
                    self.serialConnection = 0
     
            return self.serialConnection
     
    # -- MAIN
    root = tk.Tk()
     
    ihm = IHM(root)
    ihm.grid(column=0, row=0, sticky='NS')
     
    #rover = ROVER(root)
    #com = COM(root)
     
    root.title('POSL Rover')    #Titre de l'application
    root.mainloop()             #Boucler
    Et j'arrive pas encore à comprendre comment faire ceci:

    Root (programme principal)
    Ihm(root) //Ok
    com = COM() //Ici chu pas sûr
    rover = ROVER(ihm, com) //Là non plus chu pas sûr

  15. #35
    Membre régulier Avatar de Caxton
    Homme Profil pro
    Sans
    Inscrit en
    Janvier 2005
    Messages
    586
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Sans

    Informations forums :
    Inscription : Janvier 2005
    Messages : 586
    Points : 123
    Points
    123
    Par défaut
    Petite modification. Dans le but d'avoir accès à l'état de connexion dans les commandes ROVER(), j'ai créer un getter spécifique pour ça. De plus je décharge la fonction de connexion de retourner cette valeur.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    # -- IMPORTATIONS
    import tkinter as tk
    import serial
     
    # -- CLASSE Interface graphique
    class IHM(tk.Frame):
     
        #Initialisation
        def __init__(self, parent):
     
            #Variables
            self.parent = parent
            self.connexion = COM(parent)
     
            #Les frames
            tk.Frame.__init__(self, self.parent)
            self.boutons = tk.LabelFrame(self, text="Contoles", padx=20, pady=20)
            self.logs = tk.LabelFrame(self, text="Logs", padx=20, pady=20)
     
            #Images
            self.myImgAV = tk.PhotoImage(file="ressources/icones/av.gif")
            self.myImgCO = tk.PhotoImage(file="ressources/icones/co.gif")
     
            #Boutons
            self.btAV = tk.Button(self.boutons, image=self.myImgAV, bg = "grey")
            self.btCO = tk.Button(self.boutons, image=self.myImgCO, bg = "green", command=self.callback_connexion)
     
            #Textes
            self.textLogs = tk.Text(self.logs, width=50, height=20, wrap=tk.WORD)
     
            #Position des boutons
            self.boutons.grid(column=0, row=0, sticky='NS')
            self.btCO.grid(column=0, row=0)
            self.btAV.grid(column=2, row=1)
     
            #Position du log
            self.logs.grid(column=0, row=1, sticky='NS')
            self.textLogs.grid(column=0, row=0)
     
        #Afficher des informations
        def setLog(self, informations):
            self.textLogs.insert(0.0, informations)
     
        #Callback : Connexion
        def callback_connexion(self):
            self.connexion.serialConnexion()
            print(self.connexion.getEtatConnexion())
     
    # --CLASSE rover
    class ROVER():
     
        #Initialisation
        def __init__(self, parent):
     
            #Variables
            self.parent = parent
     
            """
                Ici on place toutes les fonctions que feront le rover
                -> Admet des infos de l'IHM
                <- Retourne des datas à envoyer sur le port série
            """
     
    # -- CLASSE Communication
    class COM():
     
        #Initialisation
        def __init__(self, parent):
            #Variables
            self.parent = parent
     
            self.locations=['/dev/ttyUSB0', '/dev/ttyUSB1', '/dev/ttyUSB2', '/dev/ttyUSB3', '/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2', '/dev/ttyS3']
            self.ser = ''
            self.serialConnection = 0
     
        #Connexion Serie
        def serialConnexion(self):
     
            #Tentative de connexion au XBee Usb
            for device in self.locations:
     
                try:
                    information = "Tentative de connecion sur le port" + device + "...\n"
     
                    self.ser = serial.Serial(device, 9600)
                    self.serialConnection = 1
                    break
     
                except:
                    information = "Connection échoué sur " + device + "!\n"
                    self.serialConnection = 0
     
        #Etat de la connexion
        def getEtatConnexion(self):
            return self.serialConnection
     
    # -- MAIN
    root = tk.Tk()
     
    ihm = IHM(root)
    ihm.grid(column=0, row=0, sticky='NS')
     
    #rover = ROVER(root)
    #com = COM(root)
     
    root.title('POSL Rover')    #Titre de l'application
    root.mainloop()             #Boucler
    Voyons maintenant, comment retourner les infos dans le log.

    Merci beaucoup déjà pour toutes ces infos. J'essaie d'avancer pas à pas.

  16. #36
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 285
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 285
    Points : 36 773
    Points
    36 773
    Par défaut
    Salut,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
        #Connexion Serie
        def serialConnexion(self):
     
            #Tentative de connexion au XBee Usb
            for device in self.locations:
     
                try:
                    information = "Tentative de connecion sur le port" + device + "...\n"
     
                    self.ser = serial.Serial(device, 9600)
                    self.serialConnection = 1
                    break
     
                except:
                    information = "Connection échoué sur " + device + "!\n"
                    self.serialConnection = 0
    "serialConnexion" méthode et "serialConnection" attribut ne diffèrent que d'une lettre.
    Pourquoi ne pas choisir des noms composés plus simple à penser avec?
    open_serialport comme nom de méthode et is_connected comme attribut qui devrait être un booléen serait quand même moins fatiguant.

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  17. #37
    Membre régulier Avatar de Caxton
    Homme Profil pro
    Sans
    Inscrit en
    Janvier 2005
    Messages
    586
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Sans

    Informations forums :
    Inscription : Janvier 2005
    Messages : 586
    Points : 123
    Points
    123
    Par défaut
    Ok pour cette modif. Actuellement ça me répond True ou False en fonction de la réussite ou non de la connection. J'ai changer le nom aussi et ça se passe bien.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    # -- CLASSE Communication
    class COM():
     
        #Initialisation
        def __init__(self, parent):
            #Variables
            self.parent = parent
     
            self.locations=['/dev/ttyUSB0', '/dev/ttyUSB1', '/dev/ttyUSB2', '/dev/ttyUSB3', '/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2', '/dev/ttyS3']
            self.ser = ''
            self.is_connected = False
     
        #Connexion Serie
        def serialConnexion(self):
     
            #Tentative de connexion au XBee Usb
            for device in self.locations:
     
                try:
                    information = "Tentative de connecion sur le port" + device + "...\n"
     
                    self.ser = serial.Serial(device, 9600)
                    self.is_connected = True
                    break
     
                except:
                    information = "Connection échoué sur " + device + "!\n"
                    self.is_connected = False
     
        #Etat de la connexion
        def getEtatConnexion(self):
            return self.is_connected
    Et ensuite, je pense que déjà c'est un peu plus clair en effet. Reste le retour d'infos depuis la classe COM.

  18. #38
    Membre régulier Avatar de Caxton
    Homme Profil pro
    Sans
    Inscrit en
    Janvier 2005
    Messages
    586
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Sans

    Informations forums :
    Inscription : Janvier 2005
    Messages : 586
    Points : 123
    Points
    123
    Par défaut
    J'ai fini par trouver une parade qui fonctionne bien :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    # -- IMPORTATIONS
    import tkinter as tk
    import serial
     
    # -- CLASSE Interface graphique
    class IHM(tk.Frame):
     
        #Initialisation
        def __init__(self, parent):
     
            #Variables
            self.parent = parent
            self.connexion = COM(parent)
     
            #Les frames
            tk.Frame.__init__(self, self.parent)
            self.boutons = tk.LabelFrame(self, text="Contoles", padx=20, pady=20)
            self.logs = tk.LabelFrame(self, text="Logs", padx=20, pady=20)
     
            #Images
            self.myImgAV = tk.PhotoImage(file="ressources/icones/av.gif")
            self.myImgCO = tk.PhotoImage(file="ressources/icones/co.gif")
     
            #Boutons
            self.btAV = tk.Button(self.boutons, image=self.myImgAV, bg = "grey")
            self.btCO = tk.Button(self.boutons, image=self.myImgCO, bg = "green", command=self.callback_connexion)
     
            #Textes
            self.textLogs = tk.Text(self.logs, width=50, height=20, wrap=tk.WORD)
     
            #Position des boutons
            self.boutons.grid(column=0, row=0, sticky='NS')
            self.btCO.grid(column=0, row=0)
            self.btAV.grid(column=2, row=1)
     
            #Position du log
            self.logs.grid(column=0, row=1, sticky='NS')
            self.textLogs.grid(column=0, row=0)
     
        #Afficher des informations
        def setLog(self, informations):
            self.textLogs.insert(0.0, informations)
     
        #Callback : Connexion
        def callback_connexion(self):
            self.connexion.serialConnexion()
     
            self.setLog(self.connexion.getEtatConnexion())
            self.setLog("\n" + self.connexion.getInformationsUser())
            self.connexion.resetInformation()
     
    # --CLASSE rover
    class ROVER():
     
        #Initialisation
        def __init__(self, parent):
     
            #Variables
            self.parent = parent
     
            """
                Ici on place toutes les fonctions que feront le rover
                -> Admet des infos de l'IHM
                <- Retourne des datas à envoyer sur le port série
            """
     
    # -- CLASSE Communication
    class COM():
     
        #Initialisation
        def __init__(self, parent):
            #Variables
            self.parent = parent
     
            self.locations=['/dev/ttyUSB0', '/dev/ttyUSB1', '/dev/ttyUSB2', '/dev/ttyUSB3', '/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2', '/dev/ttyS3']
            self.ser = ''
            self.is_connected = False
            self.information = ""
     
        #Connexion Serie
        def serialConnexion(self):
     
            #Tentative de connexion au XBee Usb
            for device in self.locations:
     
                try:
                    self.information += "Tentative de connecion sur le port" + device + "...\n"
     
                    self.ser = serial.Serial(device, 9600)
                    self.is_connected = True
                    break
     
                except:
                    self.information += "Connection échoué sur " + device + "!\n"
                    self.is_connected = False
     
        #Reset de message
        def resetInformation(self):
            self.information = ""
     
        #Etat de la connexion
        def getEtatConnexion(self):
            return self.is_connected
     
        #Informations utilisateur
        def getInformationsUser(self):
            return self.information
     
    # -- MAIN
    root = tk.Tk()
     
    ihm = IHM(root)
    ihm.grid(column=0, row=0, sticky='NS')
     
    #rover = ROVER(root)
    #com = COM(root)
     
    root.title('POSL Rover')    #Titre de l'application
    root.mainloop()             #Boucler
    Bon, maintenant, je m'attaque au retour d'info. C'étais le sujet initial. On a dit que chaque fois que ça avançais il falait recevoir l'info. Comme je désirais au départ avoir le retour de façon asynchrone, je pense qu'il faille passer par un tread.

    Et si c'est le cas, comment procéder ?

  19. #39
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 285
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 285
    Points : 36 773
    Points
    36 773
    Par défaut
    Salut,

    Citation Envoyé par Caxton Voir le message
    Bon, maintenant, je m'attaque au retour d'info. C'étais le sujet initial. On a dit que chaque fois que ça avançais il falait recevoir l'info. Comme je désirais au départ avoir le retour de façon asynchrone, je pense qu'il faille passer par un tread.
    Pour l'instant, rien dans votre code ne mérite la mise en place d'une mécanique plus compliquée que celles données dans les réponses à la question initiale.

    Vous parlez de retour d'information et vous aviez commencé à gratter quelque chose dans ce post sans mentionner ce qui fonctionnait ou pas.

    En attendant d'y voir plus clair...

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  20. #40
    Membre régulier Avatar de Caxton
    Homme Profil pro
    Sans
    Inscrit en
    Janvier 2005
    Messages
    586
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Sans

    Informations forums :
    Inscription : Janvier 2005
    Messages : 586
    Points : 123
    Points
    123
    Par défaut
    Oula, ça date !

    Bon, reprenons. Que faudrait-il mettre en place comme mécanisme pour que les datas reçus (si on en reçois) vue que ce serais asynchrone, aille dans la fenêtre de l'IHM ?

    Niveau data, on peut avoir une confirmation, un tableau de valeurs, des infos régulières sur les capteurs (textes / chiffres avec ou sans virgules...). Le plus souvent, c'est des caractères de la table ASCII.

    Je pense que lancer un thread spécifique est une bonne idée à condition de savoir le killer à la fermeture de l'application. A ce sujet, je n'ai pas encore coder de fermeture de programme.

    Je dirais en 1/ comment faire la fermeture de programme et comment elle pourrait killer un thread d'écoute ?
    Je dirais en 2/ Comment créer un petit thread discret (pas de fenêtre associé quoi) et qui ne ferais qu'écouter les retours de datas. Il s'appuie de toute façon sur COM puisque c'est COM qui établie la connexion.

    A propos de 2/. Je pense que l'on peut faire ceci:
    Si appuie sur le bouton connexion -> callback -> COM -> Connexion + Lancement du thread écoute
    Si appuie sur le bouton fermeture, si la connexion est ouverte, killer le thread écoute + tuer la connunication
    Si appuie sur le bouton déconnexion (à créer) -> callback2 -> COM -> kill thread écoute + tuer la communication

    Si on procède dans cette ordre on devrais certainement éviter les crash programmes.

    Qu'en pensez-vous ?

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 3 PremièrePremière 123 DernièreDernière

Discussions similaires

  1. Tkinter Bind et boucle infinie
    Par lilly74 dans le forum Tkinter
    Réponses: 3
    Dernier message: 12/03/2010, 23h41
  2. symptome de la boucle infinie dans une requete
    Par ouam81 dans le forum Langage SQL
    Réponses: 8
    Dernier message: 27/05/2005, 12h10
  3. Réponses: 15
    Dernier message: 24/05/2005, 08h34
  4. [Socket] Pb de boucle infinie
    Par Myogtha dans le forum Entrée/Sortie
    Réponses: 12
    Dernier message: 10/06/2004, 14h10
  5. [C#] Comment eviter les boucles infinies ?
    Par Thomas Lebrun dans le forum C#
    Réponses: 12
    Dernier message: 09/06/2004, 00h04

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo