@@ -1548,8 +1548,13 @@ def LoadRulesFromColumn(self):
1548
1548
columns += "," + self .properties ["loadColumn" ]
1549
1549
1550
1550
sep = ";"
1551
- if self .inmap :
1552
- outFile = tempfile .NamedTemporaryFile (mode = "w+" )
1551
+ if not self .inmap :
1552
+ self .preview .EraseMap ()
1553
+ del busy
1554
+ return
1555
+
1556
+ # Use a context manager for the file
1557
+ with tempfile .NamedTemporaryFile (mode = "w+" ) as outFile :
1553
1558
ret = RunCommand (
1554
1559
"v.db.select" ,
1555
1560
quiet = True ,
@@ -1560,65 +1565,61 @@ def LoadRulesFromColumn(self):
1560
1565
sep = sep ,
1561
1566
stdout = outFile ,
1562
1567
)
1563
- else :
1564
- self .preview .EraseMap ()
1565
- del busy
1566
- return
1567
1568
1568
- outFile .seek (0 )
1569
- i = 0
1570
- minim = maxim = 0.0
1571
- limit = 1000
1569
+ outFile .seek (0 )
1570
+ i = 0
1571
+ minim = maxim = 0.0
1572
+ limit = 1000
1572
1573
1573
- colvallist = []
1574
- readvals = False
1574
+ colvallist = []
1575
+ readvals = False
1575
1576
1576
- while True :
1577
- # os.linesep doesn't work here (MSYS)
1578
- record = outFile .readline ().replace ("\n " , "" )
1579
- if not record :
1580
- break
1581
- self .rulesPanel .ruleslines [i ] = {}
1577
+ while True :
1578
+ # os.linesep doesn't work here (MSYS)
1579
+ record = outFile .readline ().replace ("\n " , "" )
1580
+ if not record :
1581
+ break
1582
+ self .rulesPanel .ruleslines [i ] = {}
1582
1583
1583
- if not self .properties ["loadColumn" ]:
1584
- col1 = record
1585
- col2 = None
1586
- else :
1587
- col1 , col2 = record .split (sep )
1588
-
1589
- minim = min (float (col1 ), minim )
1590
- maxim = max (float (col1 ), maxim )
1591
-
1592
- # color rules list should only have unique values of col1, not all
1593
- # records
1594
- if col1 not in colvallist :
1595
- self .rulesPanel .ruleslines [i ]["value" ] = col1
1596
- self .rulesPanel .ruleslines [i ][self .attributeType ] = col2
1597
-
1598
- colvallist .append (col1 )
1599
- i += 1
1600
-
1601
- if i > limit and readvals is False :
1602
- dlg = wx .MessageDialog (
1603
- parent = self ,
1604
- message = _ (
1605
- "Number of loaded records reached %d, "
1606
- "displaying all the records will be time-consuming "
1607
- "and may lead to computer freezing, "
1608
- "do you still want to continue?"
1609
- )
1610
- % i ,
1611
- caption = _ ("Too many records" ),
1612
- style = wx .YES_NO | wx .NO_DEFAULT | wx .ICON_QUESTION ,
1613
- )
1614
- if dlg .ShowModal () == wx .ID_YES :
1615
- readvals = True
1616
- dlg .Destroy ()
1584
+ if not self .properties ["loadColumn" ]:
1585
+ col1 = record
1586
+ col2 = None
1617
1587
else :
1618
- del busy
1619
- dlg .Destroy ()
1620
- self .updateColumn = False
1621
- return
1588
+ col1 , col2 = record .split (sep )
1589
+
1590
+ minim = min (float (col1 ), minim )
1591
+ maxim = max (float (col1 ), maxim )
1592
+
1593
+ # color rules list should only have unique values of col1, not all
1594
+ # records
1595
+ if col1 not in colvallist :
1596
+ self .rulesPanel .ruleslines [i ]["value" ] = col1
1597
+ self .rulesPanel .ruleslines [i ][self .attributeType ] = col2
1598
+
1599
+ colvallist .append (col1 )
1600
+ i += 1
1601
+
1602
+ if i > limit and readvals is False :
1603
+ dlg = wx .MessageDialog (
1604
+ parent = self ,
1605
+ message = _ (
1606
+ "Number of loaded records reached %d, "
1607
+ "displaying all the records will be time-consuming "
1608
+ "and may lead to computer freezing, "
1609
+ "do you still want to continue?"
1610
+ )
1611
+ % i ,
1612
+ caption = _ ("Too many records" ),
1613
+ style = wx .YES_NO | wx .NO_DEFAULT | wx .ICON_QUESTION ,
1614
+ )
1615
+ if dlg .ShowModal () == wx .ID_YES :
1616
+ readvals = True
1617
+ dlg .Destroy ()
1618
+ else :
1619
+ del busy
1620
+ dlg .Destroy ()
1621
+ self .updateColumn = False
1622
+ return
1622
1623
1623
1624
self .rulesPanel .AddRules (i , start = True )
1624
1625
ret = self .rulesPanel .LoadRules ()
0 commit comments