Using QGIS 2.6 and Python 2.7 on Windows 7, I am trying to programmatically insert key value pairs into a ValueMap widget via a csv file. Issue is that some of the values are properly inserted and formatted, while some are not.
This csv value is formatted like so:
;
20 ; 20
25 ; 25
32 ; 32
40 ; 40
50 ; 50
60 ; 60
63 ; 63
75 ; 75
80 ; 80
90 ; 90
100 ; 100
110 ; 110
125 ; 125
140 ; 140
150 ; 150
160 ; 160
200 ; 200
225 ; 225
250 ; 250
300 ; 300
315 ; 315
350 ; 350
400 ; 400
500 ; 500
1/4'' ; 1/4''
3/8'' ; 3/8''
1/2'' ; 1/2''
3/4'' ; 3/4''
1'' ; 1''
1'' 1/4 ; 1'' 1/4
1'' 1/2 ; 1'' 1/2
2'' ; 2''
2'' 1/4 ; 2'' 1/4
2'' 1/2 ; 2'' 1/2
3'' ; 3''
3'' 1/2 ; 3'' 1/2
4'' ; 4''
5'' ; 5''
6'' ; 6''
I then created a dictionary from these values, programmatically set the widget, and configured the widget using this code:
resLayer = qgis.utils.iface.activeLayer()
with open('mycsv.csv') as f:
f.readline()
diamResDict = dict(csv.reader(f, delimiter=';'))
diamidx = resLayer.fieldNameIndex('Diametre')
resLayer.setEditorWidgetV2(diamidx, 'ValueMap')
resLayer.setEditorWidgetV2Config(diamidx, diamResDict)
The dictionary prints this:
{'140\t': '\t140', '250\t': '\t250', '50\t': '\t50', '\t': '\t\t\t\t', "1'' 1/4\t": "\t1'' 1/4", '150\t': '\t150', '40\t': '\t40', '125\t': '\t125', '400\t': '\t400', "3/4''\t": "\t3/4''", "1'' 1/2\t": "\t1'' 1/2", "3'' 1/2\t": "\t3'' 1/2", '25\t': '\t25', '100\t': '\t100', "1/2''\t": "\t1/2''", '300\t': '\t300', "4''\t": "\t4''", "6''\t": "\t6''", '60\t': '\t60', "5''\t": "\t5''", '80\t': '\t80', '32\t': '\t32', '225\t': '\t225', '200\t': '\t200', '110\t': '\t110', '160\t': '\t160', '350\t': '\t350', "1/4''\t": "\t1/4''", "3''\t": "\t3''", '90\t': '\t90', '500\t': '\t500', "2''\t": "\t2''", "1''\t": "\t1''", '315\t': '\t315', "3/8''\t": "\t3/8''", "2'' 1/2\t": "\t2'' 1/2", '20\t': '\t20', '63\t': '\t63', '75\t': '\t75', "2'' 1/4\t": "\t2'' 1/4"}
The result is this:
It's the apostrophes instead of keys that is causing me trouble.
Aucun commentaire:
Enregistrer un commentaire