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 :

[QComboBox] SetCurrentText() donne une attributerror


Sujet :

PyQt Python

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    465
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 465
    Par défaut [QComboBox] SetCurrentText() donne une attributerror
    Bonjour,

    Dans une fenêtre GUI, j'ai plusieurs listes déroulantes.
    Sur elles, j'ai testé les méthodes: [maliste].CurrentItem() ainsi que [maliste].setCurrentText()
    mais un message m'indique que l'attribut sélectionné n'est pas valide (attributeerror)

    Quelqu'un peut-il m'orienter?

    Voici les lignes où j'ai ce problème:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    self.lst_path.setCurrentText("DEFAULTPATH")
                    self.lst_layername.setCurrentText("DEFAULTLAYER")
    Voici mon fichier ui:
    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
    # -*- coding: utf-8 -*-
     
    # Form implementation generated from reading ui file 'C:\Program Files\Quantum GIS\python\plugins\Tiload_Plugin\configtiload.ui'
    #
    # Created: Tue Mar 24 18:06:12 2009
    #      by: PyQt4 UI code generator 4.4.3
    #
    # WARNING! All changes made in this file will be lost!
     
    from PyQt4 import QtCore, QtGui
     
    class Ui_Dialog(object):
        def setupUi(self, Dialog):
            Dialog.setObjectName("Dialog")
            Dialog.resize(311, 437)
            self.groupBox = QtGui.QGroupBox(Dialog)
            self.groupBox.setGeometry(QtCore.QRect(10, 130, 291, 131))
            self.groupBox.setObjectName("groupBox")
            self.ckb_samepath = QtGui.QCheckBox(self.groupBox)
            self.ckb_samepath.setGeometry(QtCore.QRect(20, 30, 131, 31))
            self.ckb_samepath.setObjectName("ckb_samepath")
            self.label_2 = QtGui.QLabel(self.groupBox)
            self.label_2.setGeometry(QtCore.QRect(20, 80, 111, 16))
            self.label_2.setObjectName("label_2")
            self.lst_path = QtGui.QComboBox(self.groupBox)
            self.lst_path.setGeometry(QtCore.QRect(20, 100, 101, 20))
            self.lst_path.setObjectName("lst_path")
            self.label_3 = QtGui.QLabel(self.groupBox)
            self.label_3.setGeometry(QtCore.QRect(180, 80, 101, 16))
            self.label_3.setObjectName("label_3")
            self.lst_layername = QtGui.QComboBox(self.groupBox)
            self.lst_layername.setGeometry(QtCore.QRect(180, 100, 101, 20))
            self.lst_layername.setObjectName("lst_layername")
            self.lst_samecolumn = QtGui.QComboBox(self.groupBox)
            self.lst_samecolumn.setGeometry(QtCore.QRect(160, 40, 121, 22))
            self.lst_samecolumn.setObjectName("lst_samecolumn")
            self.label_7 = QtGui.QLabel(self.groupBox)
            self.label_7.setGeometry(QtCore.QRect(190, 20, 61, 16))
            self.label_7.setObjectName("label_7")
            self.line = QtGui.QFrame(self.groupBox)
            self.line.setGeometry(QtCore.QRect(10, 60, 271, 16))
            self.line.setFrameShape(QtGui.QFrame.HLine)
            self.line.setFrameShadow(QtGui.QFrame.Sunken)
            self.line.setObjectName("line")
            self.groupBox_2 = QtGui.QGroupBox(Dialog)
            self.groupBox_2.setGeometry(QtCore.QRect(10, 270, 291, 111))
            self.groupBox_2.setObjectName("groupBox_2")
            self.horizontalLayoutWidget_2 = QtGui.QWidget(self.groupBox_2)
            self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(10, 70, 241, 31))
            self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2")
            self.horizontalLayout_2 = QtGui.QHBoxLayout(self.horizontalLayoutWidget_2)
            self.horizontalLayout_2.setObjectName("horizontalLayout_2")
            self.lst_loadingmode = QtGui.QComboBox(self.horizontalLayoutWidget_2)
            self.lst_loadingmode.setObjectName("lst_loadingmode")
            self.lst_loadingmode.addItem(QtCore.QString())
            self.lst_loadingmode.addItem(QtCore.QString())
            self.horizontalLayout_2.addWidget(self.lst_loadingmode)
            spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
            self.horizontalLayout_2.addItem(spacerItem)
            self.spb_tilesnblimit = QtGui.QSpinBox(self.horizontalLayoutWidget_2)
            self.spb_tilesnblimit.setObjectName("spb_tilesnblimit")
            self.horizontalLayout_2.addWidget(self.spb_tilesnblimit)
            self.horizontalLayoutWidget = QtGui.QWidget(self.groupBox_2)
            self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 40, 261, 31))
            self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
            self.horizontalLayout = QtGui.QHBoxLayout(self.horizontalLayoutWidget)
            self.horizontalLayout.setObjectName("horizontalLayout")
            self.label_5 = QtGui.QLabel(self.horizontalLayoutWidget)
            self.label_5.setObjectName("label_5")
            self.horizontalLayout.addWidget(self.label_5)
            spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
            self.horizontalLayout.addItem(spacerItem1)
            self.label_6 = QtGui.QLabel(self.horizontalLayoutWidget)
            self.label_6.setObjectName("label_6")
            self.horizontalLayout.addWidget(self.label_6)
            self.groupBox_3 = QtGui.QGroupBox(Dialog)
            self.groupBox_3.setGeometry(QtCore.QRect(10, 10, 291, 111))
            self.groupBox_3.setObjectName("groupBox_3")
            self.label = QtGui.QLabel(self.groupBox_3)
            self.label.setGeometry(QtCore.QRect(20, 20, 141, 16))
            self.label.setObjectName("label")
            self.line_path = QtGui.QLineEdit(self.groupBox_3)
            self.line_path.setGeometry(QtCore.QRect(20, 40, 231, 20))
            self.line_path.setObjectName("line_path")
            self.line_label = QtGui.QLineEdit(self.groupBox_3)
            self.line_label.setGeometry(QtCore.QRect(20, 80, 231, 20))
            self.line_label.setObjectName("line_label")
            self.label_4 = QtGui.QLabel(self.groupBox_3)
            self.label_4.setGeometry(QtCore.QRect(20, 60, 121, 16))
            self.label_4.setObjectName("label_4")
            self.pushButton = QtGui.QPushButton(self.groupBox_3)
            self.pushButton.setGeometry(QtCore.QRect(260, 40, 21, 20))
            self.pushButton.setObjectName("pushButton")
            self.bt_OK = QtGui.QPushButton(Dialog)
            self.bt_OK.setGeometry(QtCore.QRect(140, 390, 75, 23))
            self.bt_OK.setObjectName("bt_OK")
            self.bt_cancel = QtGui.QPushButton(Dialog)
            self.bt_cancel.setGeometry(QtCore.QRect(220, 390, 75, 23))
            self.bt_cancel.setObjectName("bt_cancel")
     
            self.retranslateUi(Dialog)
            QtCore.QMetaObject.connectSlotsByName(Dialog)
     
        def retranslateUi(self, Dialog):
            Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
            self.groupBox.setTitle(QtGui.QApplication.translate("Dialog", "Tile Grid Layer Fields", None, QtGui.QApplication.UnicodeUTF8))
            self.ckb_samepath.setText(QtGui.QApplication.translate("Dialog", "Layer Name and path \n"
    "in same column", None, QtGui.QApplication.UnicodeUTF8))
            self.label_2.setText(QtGui.QApplication.translate("Dialog", "Path Column", None, QtGui.QApplication.UnicodeUTF8))
            self.label_3.setText(QtGui.QApplication.translate("Dialog", "Name Column", None, QtGui.QApplication.UnicodeUTF8))
            self.label_7.setText(QtGui.QApplication.translate("Dialog", "Field Name", None, QtGui.QApplication.UnicodeUTF8))
            self.groupBox_2.setTitle(QtGui.QApplication.translate("Dialog", "Tile Loading parameters", None, QtGui.QApplication.UnicodeUTF8))
            self.lst_loadingmode.setItemText(0, QtGui.QApplication.translate("Dialog", "extent", None, QtGui.QApplication.UnicodeUTF8))
            self.lst_loadingmode.setItemText(1, QtGui.QApplication.translate("Dialog", "selected tiles", None, QtGui.QApplication.UnicodeUTF8))
            self.label_5.setText(QtGui.QApplication.translate("Dialog", "Representation Mode", None, QtGui.QApplication.UnicodeUTF8))
            self.label_6.setText(QtGui.QApplication.translate("Dialog", "Tiles number limit", None, QtGui.QApplication.UnicodeUTF8))
            self.groupBox_3.setTitle(QtGui.QApplication.translate("Dialog", "Grid Layer ", None, QtGui.QApplication.UnicodeUTF8))
            self.label.setText(QtGui.QApplication.translate("Dialog", "Path", None, QtGui.QApplication.UnicodeUTF8))
            self.label_4.setText(QtGui.QApplication.translate("Dialog", "Label ", None, QtGui.QApplication.UnicodeUTF8))
            self.pushButton.setText(QtGui.QApplication.translate("Dialog", "...", None, QtGui.QApplication.UnicodeUTF8))
            self.bt_OK.setText(QtGui.QApplication.translate("Dialog", "OK", None, QtGui.QApplication.UnicodeUTF8))
            self.bt_cancel.setText(QtGui.QApplication.translate("Dialog", "Cancel", None, QtGui.QApplication.UnicodeUTF8))
    Voici le code entier de ma classe contrôlant l'interface dans le fichier TiloadPlugin.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
    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
    #-*- coding: utf-8 -*-
     
    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    #from qgis import *
    from qgis.core import *
    from qgis.gui import *
    import os
    import string
    import ConfigParser
     
    # initialize Qt resources 
    import TiloadPlugin_rc
    from configtiload_ui import Ui_Dialog
     
    class TiloadConfigWindow(QDialog, Ui_Dialog):
            def __init__(self,iface,fl,plugin,config=""):
     
                    QDialog.__init__(self,iface.getMainWindow(),fl)
                    self.setupUi(self)
                    self.iface = iface
                    self.plugin = plugin
                    self.config=config
     
                    self.initGui()
     
            def initGui(self):
     
                    self.connect(self.ckb_samepath,SIGNAL("stateChanged(int)"), self.enable_fieldchoice)
                    self.connect(self.bt_OK,SIGNAL("clicked()"), self.applychanges)
                    self.connect(self.bt_cancel,SIGNAL("clicked()"), self.cancel)
                    self.lst_samecolumn.addItem("")
                    self.lst_path.addItem("")
                    self.lst_layername.addItem("")
     
            def ConfigGUI_init(self,fields=""):
     
                    self.fields=fields
                    #QMessageBox.information(None,"config",self.config['selecting_mode'])
                    #paths to the grid layer
                    self.line_path.setText(self.config['pathtolayer'])
                    self.line_label.setText(self.config['layer_label'])
     
     
    		#we fill the fields
                    #self.lst_path.insertStrList(self.fields, 1)
                    #QMessageBox.information(None,"type",str(type(self.lst_path)))
                    for f in self.fields:
                            self.lst_samecolumn.addItem(f)
                            self.lst_path.addItem(f)
                            self.lst_layername.addItem(f)
     
                    self.lst_path.setCurrentText("DEFAULTPATH")
                    self.lst_layername.setCurrentText("DEFAULTLAYER")
     
                    #parameters
                    loadingmode={"extent":0,"selectedtiles":1}
                    index_loadingmode=loadingmode[self.config['selecting_mode']]
                    #QMessageBox.information(None,"index_loadingmode",str(index_loadingmode))
                    self.lst_loadingmode.setCurrentIndex(index_loadingmode)	
                    self.spb_tilesnblimit.setValue(int(self.config['nbtileslimit']))
     
            def applychanges(self):
     
                    newconfig={"pathtolayer":self.line_path.text(),
                            "layer_label":self.line_label.text(),
                            "tileprefix":"",   
                            "columnwithfolderandfile":self.lst_samecolumn.currentText(),
                            "index_folderpathcolumn":self.lst_path.currentText(),
                            "index_tilenamecolumn":self.lst_layername.currentText(),
                            "autoselectingmode":1,
                            "selecting_mode":self.lst_loadingmode.currentText(),
                            "nbtileslimit":self.spb_tilesnblimit.text(),
                            }
                    QMessageBox.information(None,"config",str(newconfig))
     
    		cp = ConfigParser.ConfigParser()		
    		fileconfig=str(QgsApplication.prefixPath())+"\python\plugins\Tiload_Plugin\TiLoad.cfg"
    		fileconfig=fileconfig.replace('/','\\')
     
                    cp.read(fileconfig)               
                    for sec in cp.sections():
                            name = string.lower(sec)
                            for opt in cp.options(sec):
                                cp.set(sec,opt,newconfig[opt])                                             
     
                    #ini file writing
                    QMessageBox.information(None,"ini file writing","")
                    f=open(fileconfig,'w')
                    cp.write(f)
                    f.close()
     
                    QMessageBox.information(None,"Parameters saved successfully","The parameters have just been saved. /n They'll be applied at the next Tiload execution.")
     
            def cancel(self):
                    #QMessageBox.information(None,"quit",str(index_loadingmode))
                    print "quit"
     
            def enable_fieldchoice(self,index):
                    if index==0:                    
                            self.lst_path.setEnabled(True)
                            self.lst_layername.setEnabled(True)
                            self.lst_samecolumn.setEnabled(False)
                    else:
                            self.lst_path.setEnabled(False)
                            self.lst_layername.setEnabled(False)
                            self.lst_samecolumn.setEnabled(True)
    Merci!

  2. #2
    Membre chevronné
    Homme Profil pro
    Responsable du parc et des réseaux de télécommunication
    Inscrit en
    Mai 2003
    Messages
    290
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Responsable du parc et des réseaux de télécommunication
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2003
    Messages : 290
    Par défaut
    Bonjour,
    Un QComboBox n'a pas de méthode "setCurrentText"
    Tu peux utiliser "setItemText" :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    self.lst_path.setItemText(0,"DEFAULTPATH")

Discussions similaires

  1. passage de données à une popup
    Par loukili81 dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 31/03/2006, 10h56
  2. copie de string donne une chaine vide
    Par zmatz dans le forum SL & STL
    Réponses: 5
    Dernier message: 15/10/2005, 15h31
  3. Comment donne une couleur a une ligne dans un DBGrid
    Par samy84s dans le forum Composants VCL
    Réponses: 5
    Dernier message: 14/09/2005, 23h22
  4. [HTML] Donné une largeur en caractere à une liste.
    Par castaka dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 12/05/2005, 10h31
  5. Réponses: 6
    Dernier message: 30/09/2004, 12h21

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