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

PyQt Python Discussion :

Structurer un programme


Sujet :

PyQt Python

  1. #1
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2014
    Messages : 16
    Points : 0
    Points
    0
    Par défaut Structurer un programme
    Salut a tous,

    J'ai crée un programme qui fonctionne bien, et qui répond à mon cahier de charge.
    Mais j'aimerai que vous m'aidez a programmer autrement, en structurant mon code. Surtout tout les "if" que je met, à la fin du projet mon programme aura 10 000 ligne de code .
    Montrer moi un exemple, et je construit la suite.

    Voici le code :

    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
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
     
    #!/usr/bin/env python
    # -*- coding: cp1252 -*-
    #SPEC 0.4
     
    import sys
    import time
    import serial
    import binascii
     
    from PyQt4 import QtCore, QtGui
     
    class MyPopup(QtGui.QWidget):
        def __init__(self):
            QtGui.QWidget.__init__(self)
     
            ''' Titre_1  '''
            self.Label_1 = QtGui.QLabel()
            self.Label_1.setText("NUMERO DE PORT")
     
            ''' Titre_11  '''
            self.Label_11 = QtGui.QLabel()
            self.Label_11.setText("VITESSE")
     
            ''' ComboBox_11 '''
            self.ComboBox_11 = QtGui.QComboBox()
            self.ComboBox_11.setGeometry(QtCore.QRect(10,10,10,10))
            self.ComboBox_11.addItem("COM 1")
            self.ComboBox_11.addItem("COM 25")
            self.ComboBox_11.addItem("COM 2")
            self.ComboBox_11.addItem("COM 4")
     
            ''' ComboBox_22 '''
            self.ComboBox_22 = QtGui.QComboBox()
            self.ComboBox_22.setGeometry(QtCore.QRect(10,10,10,10))
            self.ComboBox_22.addItem("4800")
            self.ComboBox_22.addItem("115200")
     
            self.bouton1 = QtGui.QPushButton("Open", self)
            self.bouton1.clicked.connect(self.F_Open)
     
            self.bouton2 = QtGui.QPushButton("Close", self)
            self.bouton2.clicked.connect(self.F_Close)
     
            # positionner les widgets dans la fenêtre
            posit = QtGui.QGridLayout()
            posit.addWidget(self.Label_1,            0, 0)
            posit.addWidget(self.ComboBox_11,        1, 0)
            posit.addWidget(self.Label_11,           2, 0)
            posit.addWidget(self.ComboBox_22,        3, 0)
            posit.addWidget(self.bouton1,            4, 0)
            posit.addWidget(self.bouton2,            5, 0)
            self.setLayout(posit)
     
     
            # SERIAL #
     
        def F_Open(self):
            F_Serial(1,self.ComboBox_11.itemText(self.ComboBox_11.currentIndex()),self.ComboBox_22.itemText(self.ComboBox_22.currentIndex()))
     
     
        def F_Close(self):
            F_Serial(4,"null", "null")
     
     
        def M_Signal(self):
            self.M_Status(3)
            time.sleep(0.2)
            self.M_Status(2)
     
     
    def F_Serial(a,port_ou_msg,vitesse):
        s = "null"   
        if a == 1:
             num_port = int(port_ou_msg[4:6])
             vit = int(vitesse)
             global ser
             ser = serial.Serial(num_port-1,vit,timeout=0,parity='N', rtscts=1)
             print ser.portstr # check which port was really used
        elif a == 2:
             ser.write(port_ou_msg+"\r\n") # Ecriture verticale
        elif a == 3:
             s = ser.readline(120)
        elif a == 4:
             ser.close()
        return s
     
    class essai(QtGui.QMainWindow):
        def __init__(self):
    #--------------------------------------------
            # Main Window #
            QtGui.QMainWindow.__init__(self)
            self.resize(310,310)
            self.setWindowTitle(' Travaille ')
     
            # Menu #
            ''' Menu0 '''
            Action1 = QtGui.QAction('LOAD SGV', self)   
            Action1.setStatusTip('Action 1')  
            Action1.triggered.connect(self.M_Action1)
     
            Action2 = QtGui.QAction('SAVE SGV', self)   
            Action2.setStatusTip('Action 2')  
            Action2.triggered.connect(self.M_Action2)
     
            Action3 = QtGui.QAction('EXPORT TO MOBILE', self)   
            Action3.setStatusTip('Action 3')
            Action3.triggered.connect(self.M_Action3)
     
            menubar = self.menuBar()
     
            ChMenu = menubar.addMenu('&Action')
            ChMenu.addAction(Action1)
            ChMenu.addAction(Action2)
            ChMenu.addAction(Action3)
     
            '''Menu2'''
            PopFen1 = QtGui.QAction('PopUp', self)
            PopFen1.setStatusTip('PopFen1')  
            PopFen1.triggered.connect(self.F_Popup)
     
            menubar = self.menuBar()
     
            PopMenu = menubar.addMenu('&PopFen')
            PopMenu.addAction(PopFen1)
    #--------------------------------------------
            ''' Dock '''
     
            self.Label_0 = QtGui.QLabel()
            self.Label_0.setText("MODE")
     
            self.ComboBox_0 = QtGui.QComboBox()
            self.ComboBox_0.setGeometry(QtCore.QRect(10,10,10,10))
            self.ComboBox_0.addItem("HANDSET")
            self.ComboBox_0.addItem("HANDFREE")
            self.ComboBox_0.addItem("CAR KIT")
            self.ComboBox_0.addItem("RSM")
     
            self.Label_1 = QtGui.QLabel()
            self.Label_1.setText("SIGNAL")
     
            self.ComboBox_1 = QtGui.QComboBox()
            self.ComboBox_1.setGeometry(QtCore.QRect(10,10,10,10))
            self.ComboBox_1.addItem("VOICE")
            self.ComboBox_1.addItem("RING")
            self.ComboBox_1.addItem("BEEP")
     
     
            VBoxLayout_1 = QtGui.QVBoxLayout()
            VBoxLayout_1.addWidget(self.Label_0)
            VBoxLayout_1.addWidget(self.ComboBox_0)
            VBoxLayout_1.addWidget(self.Label_1)
            VBoxLayout_1.addWidget(self.ComboBox_1)
            VBoxLayout_1.setSpacing(100)
     
            Widget_1 = QtGui.QWidget()
            Widget_1.setLayout(VBoxLayout_1)
     
            F_Dock_Wid_Vitesse = QtGui.QDockWidget()
            F_Dock_Wid_Vitesse.setWidget(Widget_1)
            self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, F_Dock_Wid_Vitesse)
     
            self.SpinBox_1 = QtGui.QSpinBox(self)
            self.SpinBox_1.setRange(-12,12)
            self.SpinBox_1.setSingleStep(1)
            self.SpinBox_1.setValue(0)
     
            self.SpinBox_2 = QtGui.QSpinBox(self)
            self.SpinBox_2.setRange(-12,12)
            self.SpinBox_2.setSingleStep(1)
            self.SpinBox_2.setValue(0)
     
            self.SpinBox_3 = QtGui.QSpinBox(self)
            self.SpinBox_3.setRange(-12,12)
            self.SpinBox_3.setSingleStep(1)
            self.SpinBox_3.setValue(0)
     
            GridLayout_1 = QtGui.QGridLayout()
            GridLayout_1.addWidget(self.SpinBox_1,     0,0,1,1)
            GridLayout_1.addWidget(self.SpinBox_2,     0,1,1,1)
            GridLayout_1.addWidget(self.SpinBox_3,     0,2,1,1)
     
            O_GroupBox_1 = QtGui.QGroupBox()
            O_GroupBox_1.setLayout(GridLayout_1)
     
            self.setCentralWidget(O_GroupBox_1)
    #--------------------------------------------
            self.ComboBox_0.currentIndexChanged.connect(self.test_1)
            self.ComboBox_1.currentIndexChanged.connect(self.test_1)
     
        def test_1(self, idx):
            a = [self.SpinBox_1.value()]
            b = [self.SpinBox_2.value()]
            c = [self.SpinBox_3.value()]
            Tab_0 = [a, b, c]
            if str(self.ComboBox_0.currentText()) == "HANDSET" :
                if str(self.ComboBox_1.currentText()) == "VOICE" :
                   Tab = [a, b, c]
                   print "Voici le résultat de Tab_0 :"
                   print Tab_0
     
     
            a_1 = [self.SpinBox_1.value()]
            b_1 = [self.SpinBox_2.value()]
            c_1 = [self.SpinBox_3.value()]
            Tab_1 = [a_1, b_1, c_1]
            if str(self.ComboBox_0.currentText()) == "HANDFREE" :
                if str(self.ComboBox_1.currentText()) == "VOICE" :
                   Tab_1 = [a_1, b_1, c_1]
                   print "Voici le résultat de Tab_1 :"
                   print Tab_1
     
     
            a_2 = [self.SpinBox_1.value()]
            b_2 = [self.SpinBox_2.value()]
            c_2 = [self.SpinBox_3.value()]
            Tab_2 = [a_2, b_2, c_2]
            if str(self.ComboBox_0.currentText()) == "CAR KIT" :
                if str(self.ComboBox_1.currentText()) == "VOICE" :
                   Tab_2 = [a_2, b_2, c_2]
                   print "Voici le résultat de Tab_2 :"
                   print Tab_2
     
            a_3 = [self.SpinBox_1.value()]
            b_3 = [self.SpinBox_2.value()]
            c_3 = [self.SpinBox_3.value()]
            Tab_3 = [a_3, b_3, c_3]
            if str(self.ComboBox_0.currentText()) == "RSM" :
                if str(self.ComboBox_1.currentText()) == "VOICE" :
                   Tab_3 = [a_3, b_3, c_3]
                   print "Voici le résultat de Tab_3 :"
                   print Tab_3
     
            a_4 = [self.SpinBox_1.value()]
            b_4 = [self.SpinBox_2.value()]
            c_4 = [self.SpinBox_3.value()]
            Tab_4 = [a_4, b_4, c_4]
            if str(self.ComboBox_0.currentText()) == "HANDSET" :
                if str(self.ComboBox_1.currentText()) == "RING" :
                   Tab_4 = [a_4, b_4, c_4]
                   print "Voici le résultat de Tab_4 :"
                   print Tab_4
     
            a_5 = [self.SpinBox_1.value()]
            b_5 = [self.SpinBox_2.value()]
            c_5 = [self.SpinBox_3.value()]
            Tab_5 = [a_5, b_5, c_5]
            if str(self.ComboBox_0.currentText()) == "HANDFREE" :
                if str(self.ComboBox_1.currentText()) == "RING" :
                   Tab_5 = [a_5, b_5, c_5]
                   print "Voici le résultat de Tab_5 :" 
                   print Tab_5
     
     
            a_6 = [self.SpinBox_1.value()]
            b_6 = [self.SpinBox_2.value()]
            c_6 = [self.SpinBox_3.value()]
            Tab_6 = [a_6, b_6, c_6]
            if str(self.ComboBox_0.currentText()) == "CAR KIT" :
                if str(self.ComboBox_1.currentText()) == "RING" :
                   Tab_6 = [a_6, b_6, c_6]
                   print "Voici le résultat de Tab_6 :"
                   print Tab_6
     
            a_7 = [self.SpinBox_1.value()]
            b_7 = [self.SpinBox_2.value()]
            c_7 = [self.SpinBox_3.value()]
            Tab_7 = [a_7, b_7, c_7]
            if str(self.ComboBox_0.currentText()) == "RSM" :
                if str(self.ComboBox_1.currentText()) == "RING" :
                   Tab_7 = [a_7, b_7, c_7]
                   print "Voici le résultat de Tab_7 :"
                   print Tab_7
     
     
            a_8 = [self.SpinBox_1.value()]
            b_8 = [self.SpinBox_2.value()]
            c_8 = [self.SpinBox_3.value()]
            Tab_8 = [a_8, b_8, c_8]
            if str(self.ComboBox_0.currentText()) == "HANDSET" :
                if str(self.ComboBox_1.currentText()) == "BEEP" :
                   Tab_8 = [a_8, b_8, c_8]
                   print "Voici le résultat de Tab_8 :"
                   print Tab_8
     
            a_9 = [self.SpinBox_1.value()]
            b_9 = [self.SpinBox_2.value()]
            c_9 = [self.SpinBox_3.value()]
            Tab_9 = [a_9, b_9, c_9]
            if str(self.ComboBox_0.currentText()) == "HANDFREE" :
                if str(self.ComboBox_1.currentText()) == "BEEP" :
                   Tab_9 = [a_9, b_9, c_9]
                   print "Voici le résultat de Tab_9 :"
                   print Tab_9
     
            a_10 = [self.SpinBox_1.value()]
            b_10 = [self.SpinBox_2.value()]
            c_10 = [self.SpinBox_3.value()]
            Tab_10 = [a_10, b_10, c_10]
            if str(self.ComboBox_0.currentText()) == "CAR KIT" :
                if str(self.ComboBox_1.currentText()) == "BEEP" :
                   Tab_10 = [a_10, b_10, c_10]
                   print "Voici le résultat de Tab_10 :"
                   print Tab_10
     
            a_11 = [self.SpinBox_1.value()]
            b_11 = [self.SpinBox_2.value()]
            c_11 = [self.SpinBox_3.value()]
            Tab_11 = [a_11, b_11, c_11]
            if str(self.ComboBox_0.currentText()) == "RSM" :
                if str(self.ComboBox_1.currentText()) == "BEEP" :
                   Tab_11 = [a_11, b_11, c_11]
                   print "Voici le résultat de Tab_11 :"
                   print Tab_11
    #-----------------------------
     
            self.SpinBox_1.valueChanged.connect(self.on_spinbox_changed)
            self.SpinBox_2.valueChanged.connect(self.on_spinbox_changed)
            self.SpinBox_3.valueChanged.connect(self.on_spinbox_changed)
     
        def on_spinbox_changed(self, idx):
     
            a = [self.SpinBox_1.value()]
            b = [self.SpinBox_2.value()]
            c = [self.SpinBox_3.value()]
            Tab_0 = [a, b, c]
            if str(self.ComboBox_0.currentText()) == "HANDSET" :
                if str(self.ComboBox_1.currentText()) == "VOICE" :
                   Tab = [a, b, c]
                   print "Voici le résultat de Tab_0 :"
                   print Tab_0
     
            a_1 = [self.SpinBox_1.value()]
            b_1 = [self.SpinBox_2.value()]
            c_1 = [self.SpinBox_3.value()]
            Tab_1 = [a_1, b_1, c_1]
            if str(self.ComboBox_0.currentText()) == "HANDFREE" :
                if str(self.ComboBox_1.currentText()) == "VOICE" :
                   Tab_1 = [a_1, b_1, c_1]
                   print "Voici le résultat de Tab_1 :"
                   print Tab_1
     
     
            a_2 = [self.SpinBox_1.value()]
            b_2 = [self.SpinBox_2.value()]
            c_2 = [self.SpinBox_3.value()]
            Tab_2 = [a_2, b_2, c_2]
            if str(self.ComboBox_0.currentText()) == "CAR KIT" :
                if str(self.ComboBox_1.currentText()) == "VOICE" :
                   Tab_2 = [a_2, b_2, c_2]
                   print "Voici le résultat de Tab_2 :"
                   print Tab_2
     
            a_3 = [self.SpinBox_1.value()]
            b_3 = [self.SpinBox_2.value()]
            c_3 = [self.SpinBox_3.value()]
            Tab_3 = [a_3, b_3, c_3]
            if str(self.ComboBox_0.currentText()) == "RSM" :
                if str(self.ComboBox_1.currentText()) == "VOICE" :
                   Tab_3 = [a_3, b_3, c_3]
                   print "Voici le résultat de Tab_3 :"
                   print Tab_3
     
            a_4 = [self.SpinBox_1.value()]
            b_4 = [self.SpinBox_2.value()]
            c_4 = [self.SpinBox_3.value()]
            Tab_4 = [a_4, b_4, c_4]
            if str(self.ComboBox_0.currentText()) == "HANDSET" :
                if str(self.ComboBox_1.currentText()) == "RING" :
                   Tab_4 = [a_4, b_4, c_4]
                   print "Voici le résultat de Tab_4 :"
                   print Tab_4
     
            a_5 = [self.SpinBox_1.value()]
            b_5 = [self.SpinBox_2.value()]
            c_5 = [self.SpinBox_3.value()]
            Tab_5 = [a_5, b_5, c_5]
            if str(self.ComboBox_0.currentText()) == "HANDFREE" :
                if str(self.ComboBox_1.currentText()) == "RING" :
                   Tab_5 = [a_5, b_5, c_5]
                   print "Voici le résultat de Tab_5 :" 
                   print Tab_5
     
            a_6 = [self.SpinBox_1.value()]
            b_6 = [self.SpinBox_2.value()]
            c_6 = [self.SpinBox_3.value()]
            Tab_6 = [a_6, b_6, c_6]
            if str(self.ComboBox_0.currentText()) == "CAR KIT" :
                if str(self.ComboBox_1.currentText()) == "RING" :
                   Tab_6 = [a_6, b_6, c_6]
                   print "Voici le résultat de Tab_6 :"
                   print Tab_6
     
            a_7 = [self.SpinBox_1.value()]
            b_7 = [self.SpinBox_2.value()]
            c_7 = [self.SpinBox_3.value()]
            Tab_7 = [a_7, b_7, c_7]
            if str(self.ComboBox_0.currentText()) == "RSM" :
                if str(self.ComboBox_1.currentText()) == "RING" :
                   Tab_7 = [a_7, b_7, c_7]
                   print "Voici le résultat de Tab_7 :"
                   print Tab_7
     
            a_8 = [self.SpinBox_1.value()]
            b_8 = [self.SpinBox_2.value()]
            c_8 = [self.SpinBox_3.value()]
            Tab_8 = [a_8, b_8, c_8]
            if str(self.ComboBox_0.currentText()) == "HANDSET" :
                if str(self.ComboBox_1.currentText()) == "BEEP" :
                   Tab_8 = [a_8, b_8, c_8]
                   print "Voici le résultat de Tab_8 :"
                   print Tab_8
     
            a_9 = [self.SpinBox_1.value()]
            b_9 = [self.SpinBox_2.value()]
            c_9 = [self.SpinBox_3.value()]
            Tab_9 = [a_9, b_9, c_9]
            if str(self.ComboBox_0.currentText()) == "HANDFREE" :
                if str(self.ComboBox_1.currentText()) == "BEEP" :
                   Tab_9 = [a_9, b_9, c_9]
                   print "Voici le résultat de Tab_9 :"
                   print Tab_9
     
            a_10 = [self.SpinBox_1.value()]
            b_10 = [self.SpinBox_2.value()]
            c_10 = [self.SpinBox_3.value()]
            Tab_10 = [a_10, b_10, c_10]
            if str(self.ComboBox_0.currentText()) == "CAR KIT" :
                if str(self.ComboBox_1.currentText()) == "BEEP" :
                   Tab_10 = [a_10, b_10, c_10]
                   print "Voici le résultat de Tab_10 :"
                   print Tab_10
     
            a_11 = [self.SpinBox_1.value()]
            b_11 = [self.SpinBox_2.value()]
            c_11 = [self.SpinBox_3.value()]
            Tab_11 = [a_11, b_11, c_11]
     
            if str(self.ComboBox_0.currentText()) == "RSM" :
                if str(self.ComboBox_1.currentText()) == "BEEP" :
                   Tab_11 = [a_11, b_11, c_11]
                   print "Voici le résultat de Tab_11 :"
                   print Tab_11
    #--------------------------------------------
     
        def M_Action1(self):
     
            with open("C:/Users/ssrinivasa/Desktop/texto.txt") as f:
                x = int(f.readline().rstrip())                     
                self.SpinBox_1.setValue(x)       
                x = int(f.readline().rstrip())
                self.SpinBox_2.setValue(x)
                x = int(f.readline().rstrip())
                self.SpinBox_3.setValue(x)
                x = int(f.readline().rstrip())
     
    #--------------------------------------------
        def M_Action2(self):
     
            reponse = self.SpinBox_1.value()
            fichier = open("C:/Users/ssrinivasa/Desktop/fichier.txt", "a")
            fichier.write(str(reponse) +"\r\n") # ajouter nouvelle ligne après écriture
            reponse = self.SpinBox_2.value()
            fichier.write(str(reponse) +"\r\n")
            reponse = self.SpinBox_3.value()        
            fichier.write(str(reponse) +"\r\n")        
            print reponse
    #-------------------------------------------
        def M_Action3(self):
            self.Serial_Write()
     
        def Serial_Write(self):
            value = str(self.SpinBox_1.value())
            F_Serial(2,value,"null")
            value = str(self.SpinBox_2.value())
            F_Serial(2,value,"null")
            value = str(self.SpinBox_3.value())
            F_Serial(2,value,"null")
     
    #--------------------------------------------
        def F_Popup(self):
            self.w = MyPopup()
            self.w.setGeometry(QtCore.QRect(100, 100, 400, 200))
            self.w.show()
    #--------------------------------------------
     
    def main():
            '''Application'''
            App = QtGui.QApplication(sys.argv)
            App.setStyle("windows")
            MainWin2 = essai()
            MainWin2.show()
            editor = essai()
            sys.exit(App.exec_() )
     
    if __name__=='__main__':
        main()
    Merci d'avance.

  2. #2
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 287
    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 287
    Points : 36 776
    Points
    36 776
    Par défaut
    Salut,

    Vous avez plein de répétitions:
    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
            a = [self.SpinBox_1.value()]
            b = [self.SpinBox_2.value()]
            c = [self.SpinBox_3.value()]
            Tab_0 = [a, b, c]
            if str(self.ComboBox_0.currentText()) == "HANDSET" :
                if str(self.ComboBox_1.currentText()) == "VOICE" :
                   Tab = [a, b, c]
                   print "Voici le résultat de Tab_0 :"
                   print Tab_0
     
     
            a_1 = [self.SpinBox_1.value()]
            b_1 = [self.SpinBox_2.value()]
            c_1 = [self.SpinBox_3.value()]
            Tab_1 = [a_1, b_1, c_1]
            if str(self.ComboBox_0.currentText()) == "HANDFREE" :
                if str(self.ComboBox_1.currentText()) == "VOICE" :
                   Tab_1 = [a_1, b_1, c_1]
                   print "Voici le résultat de Tab_1 :"
                   print Tab_1
    dont l'intérêt "fonctionnel" pose questions:
    1. pourquoi récupérer les self.SpinBox_*.value() et self.ComboBox_*.currentText() à chaque fois?
    2. pourquoi assigner 2 fois (a_X, b_X, c_X) a un tab_X alors que vous vous contentez d'afficher "conditionnellement"?
    3. ...


    Mais j'aimerai que vous m'aidez a programmer autrement, en structurant mon code. Surtout tout les "if" que je met, à la fin du projet mon programme aura 10 000 ligne de code .
    Si vous factorisez aussi peu votre code, effectivement, il sera très long!

    De plus, la correspondance entre les self.ComboBox_*.currentText() et le X du tab semble être une simple fonction de correspondance entre les cases d'un tableau (4, 3) avec un entier dans [0..11].

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

  3. #3
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Salut,

    T'as déjà essayé Pylint ?

    Attention, ça peut dégouter à tout jamais de la programation.

    Extrait (avec ton code):
    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
     
    pylint prog.py > report.txt
    ************* Module prog
    C: 59,0: Line too long (137/80)
    W: 75,0: Bad indentation. Found 9 spaces, expected 8
    W: 76,0: Bad indentation. Found 9 spaces, expected 8
    W: 77,0: Bad indentation. Found 9 spaces, expected 8
    W: 78,0: Bad indentation. Found 9 spaces, expected 8
    W: 79,0: Bad indentation. Found 9 spaces, expected 8
    W: 81,0: Bad indentation. Found 9 spaces, expected 8
    W: 83,0: Bad indentation. Found 9 spaces, expected 8
    W: 85,0: Bad indentation. Found 9 spaces, expected 8
    W:198,0: Bad indentation. Found 15 spaces, expected 16
    W:199,0: Bad indentation. Found 15 spaces, expected 16
    ...
    etc
    Je le met en attachement, il fait 400 lignes.

    Il faut malgré tout relativiser, Pylint est connu comme l'ayatolla de la PEP 8 et celle-ci n'est pas non plus à prendre à la lettre. Il s'agit simplement de conventions de bonne pratique, mais bien pratiques lors de debogage.

    En ce qui me concerne Pylint ne m'a jamais accordé plus de cinq points sur dix, donc ton score n'est pas trop mauvais.
    Fichiers attachés Fichiers attachés

  4. #4
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2014
    Messages : 16
    Points : 0
    Points
    0
    Par défaut
    Salut merci pour votre réponses.

    J'ai rien comprit avec le Pylint, c'est ma faute ?

  5. #5
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Citation Envoyé par NiceLinux123456 Voir le message
    ... c'est ma faute ?

    Pas trop, Pylint fait aussi un peu de paranoïa.

  6. #6
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2014
    Messages : 16
    Points : 0
    Points
    0
    Par défaut
    Alors comment comprendre ce que ta expliqué sur le Pylint, notamment le le code ?

  7. #7
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Dans le rapport Pylint, tu trouveras principalement des remarques ou avertissements basés sur les règles de l'art définies dans la PEP 8 (1)

    Prenons quelques lignes:
    * C: 59,0: Line too long (137/80)
    Le C désigne une violation des conventions standard de programation en général, une ligne physique de code ne devrait pas excéder 80 caractères (on recommande 79), je ne sais s'il existe encore des éditeurs limités à 80 caractères mais c'était la première raison. Lorsque sont apparut les IDE dont la zone d'édition est encadrée d'une foultitude de boites d'outils, l'espace en largeur pour cet éditeur se retrouve limité aussi. Ensuite les écrans modernes ont une tendance à grandir plutôt en largeur et la limitation à 80 caractères offre le plaisir d'afficher côte à côte deux éditeurs, et ça, ça change la vie.

    * W: 75,0: Bad indentation. Found 9 spaces, expected 8
    Le W désigne un avertissement concernant des règles spécifiques à Python, dans ce cas ci les indentations de 4 espaces seront préférées à toutes autres et 9 n'est pas un multiple de 4

    * C: 1,0: Missing docstring
    Tu n'as aucune docstring dans ton code, mais nous sommes tous sûrs qu'il ne s'agit que d'un oubli.

    * E: 11,0: No name 'QtCore' in module 'PyQt4'
    Le E désigne une erreur suite à laquelle ton programme ne devrait pas survivre, ici dans ce cas c'est Pylint lui-même qui se trompe ...

    * C: 34,8:MyPopup.__init__: Invalid name "ComboBox_22" (should match [a-z_][a-z0-9_]{2,30}$)
    La capitalisation et la camel case sont à réserver aux noms des classes, tu devrais écrire "combobox_22". Ce machin "[a-z_][a-z0-9_]{2,30}$" est l'expression régulière utilisée pour tester les noms.

    * C: 27,8:MyPopup.__init__: Comma not followed by a space
    self.ComboBox_11.setGeometry(QtCore.QRect(10,10,10,10))
    ^^
    Virgule non suivie d'une espace >> QtCore.QRect(10, 10, 10, 10))

    * W: 17,8:MyPopup.__init__: String statement has no effect
    Ce sont ces lignes ''' Titre_1 ''' que tu as dispersées dans ton code. Réserve le triple guillemets pour les docstring ou les chaînes de texte longues, dans ce cas ci "Titre_1" est simplement un commentaire donc: # Titre_1

    * C: 72,0:F_Serial: Invalid name "a" (should match [a-z_][a-z0-9_]{2,30}$)
    Minimum deux caractères !

    * E:161,27:essai.__init__: Module 'PyQt4.QtCore' has no 'Qt' member
    Encore Pylint qui se plante ...

    * R: 89,4:essai.__init__: Too many statements (74/50)
    Le R veut dire 'A réécrire, pas beau le code, je cite bad code smell. Ici trop d'instructions. Tu peux ignorer tranquillement.

    * R:191,4:essai.test_1: Too many local variables (51/15)
    Pareil, ignore.

    * W:191,21:essai.test_1: Unused argument 'idx'
    L'argument "idx" (ligne 191) est inutile. Tu ne peux cependant peut-être pas le supprimer, dépend du contexte.

    * W:198,15:essai.test_1: Unused variable 'Tab'
    Enfin Pylint a détecté une erreur dans ton code, ligne 198 "Tab = [a, b, c]" devrait être selon moi "Tab_0 = [a, b, c]".

    * W:482,8:essai.F_Popup: Attribute 'w' defined outside __init__
    Tu ne t'en occupes pas, tu es obligée de garder une référence de ton popup sinon Python le virera aussitôt ouvert.

    * W: 9,0: Unused import binascii
    Un import inutile.


    Voilà, ça ne devrait pas t'oter le sommeil, je pense.


    (1) http://legacy.python.org/dev/peps/pep-0008/

  8. #8
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2014
    Messages : 16
    Points : 0
    Points
    0
    Par défaut
    Super, ta écrit beaucoup pour m'expliquer.

    Merci beaucoup

Discussions similaires

  1. [débutant]Pb de structure du programme
    Par Tymk dans le forum C++
    Réponses: 7
    Dernier message: 03/07/2008, 08h56
  2. Vue structure de programme
    Par nialaz dans le forum Général Python
    Réponses: 2
    Dernier message: 01/02/2007, 16h35
  3. [Debutant] Structure de programme
    Par mpascolo dans le forum Langage
    Réponses: 13
    Dernier message: 23/10/2006, 11h30
  4. Conseils sur structure de programme
    Par RR instinct dans le forum Langage
    Réponses: 6
    Dernier message: 21/09/2006, 14h44
  5. Font , Xml & structure de programme .
    Par Clad3 dans le forum XML
    Réponses: 11
    Dernier message: 30/03/2005, 22h45

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