diff --git a/gui/wxpython/animation/data.py b/gui/wxpython/animation/data.py index f35e85e1e5b..ec33ce082d2 100644 --- a/gui/wxpython/animation/data.py +++ b/gui/wxpython/animation/data.py @@ -240,9 +240,7 @@ def _computeRegions(self, count, startRegion, endRegion=None, zoomValue=None): del region["projection"] if "zone" in region: del region["zone"] - regions = [] - for i in range(self._mapCount): - regions.append(copy.copy(region)) + regions = [copy.copy(region) for i in range(self._mapCount)] self._regions = regions if not (endRegion or zoomValue): return diff --git a/gui/wxpython/animation/nviztask.py b/gui/wxpython/animation/nviztask.py index 26605737ea8..5dbb1d3e982 100644 --- a/gui/wxpython/animation/nviztask.py +++ b/gui/wxpython/animation/nviztask.py @@ -136,9 +136,7 @@ def _processSurface(self, surface, mapName): self._setMultiTaskParam(mode2, value) # position - pos = [] - for coor in ("x", "y", "z"): - pos.append(str(surface["position"][coor])) + pos = [str(surface["position"][coor]) for coor in ("x", "y", "z")] value = ",".join(pos) self._setMultiTaskParam("surface_position", value) diff --git a/gui/wxpython/animation/temporal_manager.py b/gui/wxpython/animation/temporal_manager.py index 0f00cc6e329..814a48fcac1 100644 --- a/gui/wxpython/animation/temporal_manager.py +++ b/gui/wxpython/animation/temporal_manager.py @@ -116,8 +116,7 @@ def _setTemporalState(self): # check for units for relative type if relative: - units = set() - units.update(infoDict["unit"] for infoDict in self.timeseriesInfo.values()) + units = {infoDict["unit"] for infoDict in self.timeseriesInfo.values()} if len(units) > 1: message = _( "It is not allowed to display data with different units (%s)." @@ -162,10 +161,11 @@ def GetGranularity(self): return self._getCommonGranularity() def _getCommonGranularity(self): - allMaps = [] - for dataset in self.timeseriesList: - maps = self.timeseriesInfo[dataset]["maps"] - allMaps.extend(maps) + allMaps = [ + a + for dataset in self.timeseriesList + for a in self.timeseriesInfo[dataset]["maps"] + ] if self.temporalType == TemporalType.ABSOLUTE: gran = tgis.compute_absolute_time_granularity(allMaps) @@ -210,9 +210,9 @@ def GetLabelsAndMaps(self): newMapList[i : i + len(mapList)] = mapList newMapLists.append(newMapList) - mapDict = {} - for i, dataset in enumerate(self.timeseriesList): - mapDict[dataset] = newMapLists[i] + mapDict = { + dataset: newMapLists[i] for i, dataset in enumerate(self.timeseriesList) + } if self.temporalType == TemporalType.ABSOLUTE: # ('1996-01-01 00:00:00', '1997-01-01 00:00:00', 'year'), diff --git a/gui/wxpython/animation/utils.py b/gui/wxpython/animation/utils.py index 7e9b6e54fb3..54aafa3532f 100644 --- a/gui/wxpython/animation/utils.py +++ b/gui/wxpython/animation/utils.py @@ -212,8 +212,7 @@ def checkSeriesCompatibility(mapSeriesList=None, timeseriesList=None): ) if mapSeriesList: - count = set() - count.update(len(mapSeries) for mapSeries in mapSeriesList) + count = {len(mapSeries) for mapSeries in mapSeriesList} if len(count) > 1: raise GException( _( diff --git a/gui/wxpython/core/layerlist.py b/gui/wxpython/core/layerlist.py index b6609b9c2df..c09ea203326 100644 --- a/gui/wxpython/core/layerlist.py +++ b/gui/wxpython/core/layerlist.py @@ -63,11 +63,7 @@ def GetLayersByTypes(self, mapTypes): :param mapTypes: list of types """ - layers = [] - for layer in self._list: - if layer.mapType in mapTypes: - layers.append(layer) - return layers + return [layer for layer in self._list if layer.mapType in mapTypes] def AddNewLayer( self, diff --git a/gui/wxpython/core/render.py b/gui/wxpython/core/render.py index 941d21879cd..26a984990e7 100644 --- a/gui/wxpython/core/render.py +++ b/gui/wxpython/core/render.py @@ -116,9 +116,7 @@ def __init__( self.name = name if self.type == "command": - self.cmd = [] - for c in cmd: - self.cmd.append(cmdlist_to_tuple(c)) + self.cmd = [] + [cmdlist_to_tuple(c) for c in cmd] else: self.cmd = cmdlist_to_tuple(cmd) @@ -326,9 +324,7 @@ def SetOpacity(self, value): def SetCmd(self, cmd): """Set new command for layer""" if self.type == "command": - self.cmd = [] - for c in cmd: - self.cmd.append(cmdlist_to_tuple(c)) + self.cmd = [] + [cmdlist_to_tuple(c) for c in cmd] else: self.cmd = cmdlist_to_tuple(cmd) Debug.msg(3, "Layer.SetCmd(): cmd='%s'" % self.GetCmd(string=True)) @@ -1055,8 +1051,7 @@ def GetRegion( env["GISRC"] = self.gisrc # do not update & shell style output - cmd = {} - cmd["flags"] = "ugpc" + cmd = {"flags": "ugpc"} if default: cmd["flags"] += "d" @@ -1656,10 +1651,7 @@ def GetOverlay(self, id, list=False): :return: overlay (list=False) :return: None (list=False) if no overlay or more overlays found """ - ovl = [] - for overlay in self.overlays: - if overlay.id == id: - ovl.append(overlay) + ovl = [overlay for overlay in self.overlays if overlay.id == id] if not list: if len(ovl) != 1: diff --git a/gui/wxpython/core/settings.py b/gui/wxpython/core/settings.py index 05c6579e636..aa51f8fb207 100644 --- a/gui/wxpython/core/settings.py +++ b/gui/wxpython/core/settings.py @@ -1230,12 +1230,13 @@ def GetDisplayVectSettings(): % UserSettings.Get(group="vectorLayer", key="point", subkey="size"), ) ) - types = [] - for ftype in ["point", "line", "boundary", "centroid", "area", "face"]: + types = [ + ftype + for ftype in ["point", "line", "boundary", "centroid", "area", "face"] if UserSettings.Get( group="vectorLayer", key="showType", subkey=[ftype, "enabled"] - ): - types.append(ftype) + ) + ] settings.append("type=%s" % ",".join(types)) if UserSettings.Get(group="vectorLayer", key="randomColors", subkey="enabled"): diff --git a/gui/wxpython/core/utils.py b/gui/wxpython/core/utils.py index 2a7ac31c36f..47fd14003b3 100644 --- a/gui/wxpython/core/utils.py +++ b/gui/wxpython/core/utils.py @@ -918,9 +918,8 @@ def SetAddOnPath(addonPath=None, key="PATH"): "white": (255, 255, 255), "yellow": (255, 255, 0), } -rgb2str = {} -for s, r in str2rgb.items(): - rgb2str[r] = s + +rgb2str = {r: s for s, r in str2rgb.items()} # ensure that gray value has 'gray' string and not 'grey' rgb2str[str2rgb["gray"]] = "gray" # purple is defined as nickname for violet in lib/gis @@ -974,9 +973,7 @@ def color_resolve(color): "d.polar": "polar", "d.legend.vect": "vectleg", } -ltype2command = {} -for cmd, ltype in command2ltype.items(): - ltype2command[ltype] = cmd +ltype2command = {ltype: cmd for cmd, ltype in command2ltype.items()} def GetGEventAttribsForHandler(method, event): diff --git a/gui/wxpython/dbmgr/vinfo.py b/gui/wxpython/dbmgr/vinfo.py index c32ac5572b4..94dda140406 100644 --- a/gui/wxpython/dbmgr/vinfo.py +++ b/gui/wxpython/dbmgr/vinfo.py @@ -120,9 +120,7 @@ def SelectByPoint(self, queryCoords, qdist): return None # process attributes - ret = {} - for key in ["Category", "Layer", "Table", "Id"]: - ret[key] = [] + ret = {key: [] for key in ["Category", "Layer", "Table", "Id"]} for record in data: if "Table" not in record: diff --git a/gui/wxpython/gcp/manager.py b/gui/wxpython/gcp/manager.py index 2d53bd6f533..43bbfdc1b8e 100644 --- a/gui/wxpython/gcp/manager.py +++ b/gui/wxpython/gcp/manager.py @@ -1000,10 +1000,11 @@ def GetWebServiceLayers(self, ltype=("wms"), name=None): } :return: None when web service map layer name doesn't exist """ - layers = {} - for layer in self.parent._giface.GetLayerList(): - if layer.type in ltype: - layers[str(layer)] = {"type": layer.type, "cmd": layer.cmd} + layers = { + str(layer): {"type": layer.type, "cmd": layer.cmd} + for layer in self.parent._giface.GetLayerList() + if layer.type in ltype + } if name: return layers.get(name) return layers @@ -1407,9 +1408,8 @@ def SetSettings(self): font = self.GetFont() font.SetPointSize(int(spx) + 2) - textProp = {} - textProp["active"] = True - textProp["font"] = font + textProp = {"active": True, "font": font} + self.pointsToDrawSrc.SetPropertyVal("text", textProp) self.pointsToDrawTgt.SetPropertyVal("text", copy(textProp)) diff --git a/gui/wxpython/gmodeler/dialogs.py b/gui/wxpython/gmodeler/dialogs.py index ba966ea6a53..1f8ef0ffc91 100644 --- a/gui/wxpython/gmodeler/dialogs.py +++ b/gui/wxpython/gmodeler/dialogs.py @@ -978,9 +978,7 @@ def Populate(self, data): bId = action.GetBlockId() bId = _("No") if not bId else _("Yes") options = action.GetParameterizedParams() - params = [] - for f in options["flags"]: - params.append("-{0}".format(f["name"])) + params = ["-{0}".format(f["name"]) for f in options["flags"]] for p in options["params"]: params.append(p["name"]) diff --git a/gui/wxpython/gmodeler/model.py b/gui/wxpython/gmodeler/model.py index 930944d6bb1..1f85af66ded 100644 --- a/gui/wxpython/gmodeler/model.py +++ b/gui/wxpython/gmodeler/model.py @@ -100,12 +100,7 @@ def GetItems(self, objType=None): if not objType: return self.items - result = [] - for item in self.items: - if isinstance(item, objType): - result.append(item) - - return result + return [item for item in self.items if isinstance(item, objType)] def GetItem(self, aId, objType=None): """Get item of given id @@ -683,11 +678,12 @@ def Run(self, log, onDone, parent=None): GError(parent=parent, message="\n".join(err)) return - err = [] - for key, item in params.items(): - for p in item["params"]: - if p.get("value", "") == "": - err.append((key, p.get("name", ""), p.get("description", ""))) + err = [ + (key, p.get("name", ""), p.get("description", "")) + for key, item in params.items() + for p in item["params"] + if p.get("value", "") == "" + ] if err: GError( parent=parent, @@ -990,11 +986,7 @@ def GetBlockId(self): :return: list of ids """ - ret = [] - for mo in self.inBlock: - ret.append(mo.GetId()) - - return ret + return [mo.GetId() for mo in self.inBlock] class ModelAction(ModelObject, ogl.DividedShape): @@ -1409,20 +1401,14 @@ def OnDraw(self, dc): def GetLog(self, string=True): """Get logging info""" - name = [] - for rel in self.GetRelations(): - name.append(rel.GetLabel()) + name = [rel.GetLabel() for rel in self.GetRelations()] if name: return "/".join(name) + "=" + self.value + " (" + self.prompt + ")" return self.value + " (" + self.prompt + ")" def GetLabel(self): """Get list of names""" - name = [] - for rel in self.GetRelations(): - name.append(rel.GetLabel()) - - return name + return [rel.GetLabel() for rel in self.GetRelations()] def GetPrompt(self): """Get prompt""" @@ -1528,9 +1514,7 @@ def _setPen(self): def SetLabel(self): """Update text""" self.ClearText() - name = [] - for rel in self.GetRelations(): - name.append(rel.GetLabel()) + name = [rel.GetLabel() for rel in self.GetRelations()] self.AddText("/".join(name)) if self.value: self.AddText(self.value) @@ -1795,12 +1779,7 @@ def Update(self): def GetItems(self, items): """Get sorted items by id""" - result = [] - for item in items: - if item.GetId() in self.itemIds: - result.append(item) - - return result + return [item for item in items if item.GetId() in self.itemIds] def SetItems(self, items): """Set items (id)""" @@ -3731,11 +3710,7 @@ def _createPage(self, name, params): def GetErrors(self): """Check for errors, get list of messages""" - errList = [] - for task in self.tasks: - errList += task.get_cmd_error() - - return errList + return [task.get_cmd_error() for task in self.tasks] def DeleteIntermediateData(self) -> bool: """Check if to delete intermediate data""" diff --git a/gui/wxpython/gui_core/dialogs.py b/gui/wxpython/gui_core/dialogs.py index 19e430d605e..ca412808a57 100644 --- a/gui/wxpython/gui_core/dialogs.py +++ b/gui/wxpython/gui_core/dialogs.py @@ -1114,10 +1114,7 @@ def OnRemoveLayer(self, event): def GetLayers(self): """Get layers""" if self.edit_subg: - layers = [] - for maps, sel in self.subgmaps.items(): - if sel: - layers.append(maps) + layers = [maps for maps, sel in self.subgmaps.items() if sel] else: layers = self.gmaps[:] @@ -1342,8 +1339,7 @@ def GetSelectedGroup(self): def GetGroupLayers(self, group, subgroup=None): """Get layers in group""" - kwargs = {} - kwargs["group"] = group + kwargs = {"group": group} if subgroup: kwargs["subgroup"] = subgroup @@ -2139,9 +2135,10 @@ def _layout(self): mainSizer.Add(btnSizer, proportion=0, flag=wx.EXPAND | wx.ALL, border=5) # show panel with the largest number of images and fit size - count = [] - for folder in os.listdir(self.symbolPath): - count.append(len(os.listdir(os.path.join(self.symbolPath, folder)))) + count = [ + len(os.listdir(os.path.join(self.symbolPath, folder))) + for folder in os.listdir(self.symbolPath) + ] index = count.index(max(count)) self.folderChoice.SetSelection(index) @@ -2196,9 +2193,7 @@ def _createSymbolPanels(self, parent): def _getSymbols(self, path): # we assume that images are in subfolders (1 level only) - imageList = [] - for image in os.listdir(path): - imageList.append(os.path.join(path, image)) + imageList = [os.path.join(path, image) for image in os.listdir(path)] return sorted(imageList) diff --git a/gui/wxpython/gui_core/forms.py b/gui/wxpython/gui_core/forms.py index cadbedce6f9..389ae6f2c30 100644 --- a/gui/wxpython/gui_core/forms.py +++ b/gui/wxpython/gui_core/forms.py @@ -196,11 +196,7 @@ def run(self): map = pMap.get("value", "") if pMap else None # avoid running db.describe several times - cparams = {} - cparams[map] = { - "dbInfo": None, - "layers": None, - } + cparams = {map: {"dbInfo": None, "layers": None}} # update reference widgets for uid in p["wxId-bind"]: @@ -586,8 +582,10 @@ def __init__( self.btn_cancel.Bind(wx.EVT_BUTTON, self.OnCancel) # bind closing to ESC and CTRL+Q self.Bind(wx.EVT_MENU, self.OnCancel, id=wx.ID_CANCEL) - accelTableList = [(wx.ACCEL_NORMAL, wx.WXK_ESCAPE, wx.ID_CANCEL)] - accelTableList.append((wx.ACCEL_CTRL, ord("Q"), wx.ID_CANCEL)) + accelTableList = [ + (wx.ACCEL_NORMAL, wx.WXK_ESCAPE, wx.ID_CANCEL), + (wx.ACCEL_CTRL, ord("Q"), wx.ID_CANCEL), + ] # TODO: bind Ctrl-t for tile windows here (trac #2004) if self.get_dcmd is not None: # A callback has been set up @@ -2411,15 +2409,9 @@ def OnCheckItem(index=None, flag=None, event=None): pSqlWhere.append(p) # collect ids - pColumnIds = [] - for p in pColumn: - pColumnIds += p["wxId"] - pLayerIds = [] - for p in pLayer: - pLayerIds += p["wxId"] - pSqlWhereIds = [] - for p in pSqlWhere: - pSqlWhereIds += p["wxId"] + pColumnIds = [p["wxId"] for p in pColumn] + pLayerIds = [p["wxId"] for p in pLayer] + pSqlWhereIds = [p["wxId"] for p in pSqlWhere] # set wxId-bindings if pMap: @@ -2837,9 +2829,7 @@ def OnCheckBoxMulti(self, event): myIndex = p["wxId"].index(me) # Unpack current value list - currentValues = {} - for isThere in theParam.get("value", "").split(","): - currentValues[isThere] = 1 + currentValues = dict.fromkeys(theParam.get("value", "").split(","), 1) theValue = theParam["values"][myIndex] if event.IsChecked(): @@ -2848,10 +2838,7 @@ def OnCheckBoxMulti(self, event): del currentValues[theValue] # Keep the original order, so that some defaults may be recovered - currentValueList = [] - for v in theParam["values"]: - if v in currentValues: - currentValueList.append(v) + currentValueList = [v for v in theParam["values"] if v in currentValues] # Pack it back theParam["value"] = ",".join(currentValueList) diff --git a/gui/wxpython/gui_core/gselect.py b/gui/wxpython/gui_core/gselect.py index 1fb305395fd..248d40de073 100644 --- a/gui/wxpython/gui_core/gselect.py +++ b/gui/wxpython/gui_core/gselect.py @@ -1395,16 +1395,12 @@ def __init__( ftype = "ogr" if ogr else "gdal" - formats = [] - for f in GetFormats()[ftype][srcType].items(): - formats += f + formats = list(GetFormats()[ftype][srcType].items()) self.SetItems(formats) def GetExtension(self, name): """Get file extension by format name""" - formatToExt = {} - formatToExt.update(rasterFormatExtension) - formatToExt.update(vectorFormatExtension) + formatToExt = {**rasterFormatExtension, **vectorFormatExtension} return formatToExt.get(name, "") @@ -1949,9 +1945,7 @@ def _layout(self): def _getExtension(self, name): """Get file extension by format name""" - formatToExt = {} - formatToExt.update(rasterFormatExtension) - formatToExt.update(vectorFormatExtension) + formatToExt = {**rasterFormatExtension, **vectorFormatExtension} return formatToExt.get(name, "") diff --git a/gui/wxpython/gui_core/query.py b/gui/wxpython/gui_core/query.py index 5e0f734fa6a..bf46df8688e 100644 --- a/gui/wxpython/gui_core/query.py +++ b/gui/wxpython/gui_core/query.py @@ -119,11 +119,10 @@ def ShowContextMenu(self, node): menu = Menu() texts = [] if len(nodes) > 1: - values = [] - for node in nodes: - values.append( - (node.label, node.data[self._colNames[1]] if node.data else "") - ) + values = [ + (node.label, node.data[self._colNames[1]] if node.data else "") + for node in nodes + ] col1 = "\n".join([val[1] for val in values if val[1]]) col2 = "\n".join([val[0] for val in values if val[0]]) table = "\n".join([val[0] + ": " + val[1] for val in values]) @@ -253,8 +252,7 @@ def PrepareQueryResults(coordinates, result): Adds coordinates, improves vector results tree structure. """ - data = [] - data.append({_("east, north"): ", ".join(map(str, coordinates))}) + data = [{_("east, north"): ", ".join(map(str, coordinates))}] for part in result: if "Map" in part: itemText = part["Map"] diff --git a/gui/wxpython/gui_core/toolbars.py b/gui/wxpython/gui_core/toolbars.py index d608994cfce..33ca987e142 100644 --- a/gui/wxpython/gui_core/toolbars.py +++ b/gui/wxpython/gui_core/toolbars.py @@ -18,6 +18,7 @@ import platform import os +from itertools import starmap import wx from wx.lib.agw import aui @@ -243,10 +244,7 @@ def EnableAll(self, enable=True): def _getToolbarData(self, data): """Define tool""" - retData = [] - for args in data: - retData.append(self._defineTool(*args)) - return retData + return list(starmap(self._defineTool, data)) def _defineTool( self, name=None, icon=None, handler=None, item=wx.ITEM_NORMAL, pos=-1 diff --git a/gui/wxpython/history/browser.py b/gui/wxpython/history/browser.py index 03e39a884a3..9589cee3f0d 100644 --- a/gui/wxpython/history/browser.py +++ b/gui/wxpython/history/browser.py @@ -326,11 +326,11 @@ def _get_current_region(self): def _get_history_region(self): """Get computational region settings of executed command.""" - history_region = {} - for key, value in self.region_settings.items(): - if self._region_settings_filter(key): - history_region[key] = value - return history_region + return { + key: value + for key, value in self.region_settings.items() + if self._region_settings_filter(key) + } def OnUpdateRegion(self, event): """Set current region to the region of executed command.""" diff --git a/gui/wxpython/iclass/frame.py b/gui/wxpython/iclass/frame.py index e594d1860fb..4bb9e66b6c4 100644 --- a/gui/wxpython/iclass/frame.py +++ b/gui/wxpython/iclass/frame.py @@ -1502,10 +1502,7 @@ def AddLayerRGB(self, cmd): :param cmd: d.rgb command as a list """ - name = [] - for param in cmd: - if "=" in param: - name.append(param.split("=")[1]) + name = [param.split("=")[1] for param in cmd if "=" in param] name = ",".join(name) self.map.AddLayer( ltype="rgb", diff --git a/gui/wxpython/image2target/ii2t_manager.py b/gui/wxpython/image2target/ii2t_manager.py index 3b5135781e9..56adf91775b 100644 --- a/gui/wxpython/image2target/ii2t_manager.py +++ b/gui/wxpython/image2target/ii2t_manager.py @@ -1391,9 +1391,8 @@ def SetSettings(self): font = self.GetFont() font.SetPointSize(int(spx) + 2) - textProp = {} - textProp["active"] = True - textProp["font"] = font + textProp = {"active": True, "font": font} + self.pointsToDrawSrc.SetPropertyVal("text", textProp) self.pointsToDrawTgt.SetPropertyVal("text", copy(textProp)) diff --git a/gui/wxpython/iscatt/controllers.py b/gui/wxpython/iscatt/controllers.py index 6a5bcb6bb9e..f87569b2698 100644 --- a/gui/wxpython/iscatt/controllers.py +++ b/gui/wxpython/iscatt/controllers.py @@ -1133,11 +1133,9 @@ def DeletAllCategories(self): def SetCategory(self, cat, stats): self.cats_mgr.setCategoryAttrs.disconnect(self.SetStatistics) - cats_attr = {} - - for attr in ["name", "color", "nstd"]: - if attr in stats: - cats_attr[attr] = stats[attr] + cats_attr = { + attr: stats[attr] for attr in ["name", "color", "nstd"] if attr in stats + } if cats_attr: self.cats_mgr.SetCategoryAttrs(cat, cats_attr) diff --git a/gui/wxpython/iscatt/dialogs.py b/gui/wxpython/iscatt/dialogs.py index a2d054b64a4..4dd10aeb832 100644 --- a/gui/wxpython/iscatt/dialogs.py +++ b/gui/wxpython/iscatt/dialogs.py @@ -425,9 +425,7 @@ def __init__( gridSizer = wx.GridBagSizer(vgap=1, hgap=1) row = 0 - setts = {} - setts.update(self.colorsSetts) - setts.update(self.sizeSetts) + setts = {**self.colorsSetts, **self.sizeSetts} settsOrder = [ "sel_pol", diff --git a/gui/wxpython/iscatt/iscatt_core.py b/gui/wxpython/iscatt/iscatt_core.py index 33ba110122b..1d56ffe88c3 100644 --- a/gui/wxpython/iscatt/iscatt_core.py +++ b/gui/wxpython/iscatt/iscatt_core.py @@ -155,12 +155,12 @@ def UpdateCategoryWithPolygons(self, cat_id, scatts_pols, value): b1, b2 = idScattToidBands(scatt_id, len(self.an_data.GetBands())) b = self.scatts_dt.GetBandsInfo(scatt_id) - region = {} - region["s"] = b["b2"]["min"] - 0.5 - region["n"] = b["b2"]["max"] + 0.5 - - region["w"] = b["b1"]["min"] - 0.5 - region["e"] = b["b1"]["max"] + 0.5 + region = { + "s": b["b2"]["min"] - 0.5, + "n": b["b2"]["max"] + 0.5, + "w": b["b1"]["min"] - 0.5, + "e": b["b1"]["max"] + 0.5, + } arr = self.scatt_conds_dt.GetValuesArr(cat_id, scatt_id) arr = Rasterize(polygon=coords, rast=arr, region=region, value=value) @@ -218,11 +218,12 @@ def SyncWithMap(self): region = self.an_data.GetRegion() - bbox = {} - bbox["maxx"] = region["e"] - bbox["minx"] = region["w"] - bbox["maxy"] = region["n"] - bbox["miny"] = region["s"] + bbox = { + "maxx": region["e"], + "minx": region["w"], + "maxy": region["n"], + "miny": region["s"], + } updated_cats = [] diff --git a/gui/wxpython/iscatt/plots.py b/gui/wxpython/iscatt/plots.py index 4e69aa0e975..1c081958fed 100644 --- a/gui/wxpython/iscatt/plots.py +++ b/gui/wxpython/iscatt/plots.py @@ -667,13 +667,14 @@ def __init__(self, ax, pol, empty_pol): self.it = 0 def _getPolygonStyle(self): - style = {} - style["sel_pol"] = UserSettings.Get( - group="scatt", key="selection", subkey="sel_pol" - ) - style["sel_pol_vertex"] = UserSettings.Get( - group="scatt", key="selection", subkey="sel_pol_vertex" - ) + style = { + "sel_pol": UserSettings.Get( + group="scatt", key="selection", subkey="sel_pol" + ), + "sel_pol_vertex": UserSettings.Get( + group="scatt", key="selection", subkey="sel_pol_vertex" + ), + } style["sel_pol"] = [i / 255.0 for i in style["sel_pol"]] style["sel_pol_vertex"] = [i / 255.0 for i in style["sel_pol_vertex"]] diff --git a/gui/wxpython/lmgr/frame.py b/gui/wxpython/lmgr/frame.py index e003a648018..0fe98001674 100644 --- a/gui/wxpython/lmgr/frame.py +++ b/gui/wxpython/lmgr/frame.py @@ -578,8 +578,7 @@ def CanCloseDisplay(askIfSaveWorkspace): map display notebook layers tree page index """ - pgnum_dict = {} - pgnum_dict["layers"] = self.notebookLayers.GetPageIndex(page) + pgnum_dict = {"layers": self.notebookLayers.GetPageIndex(page)} name = self.notebookLayers.GetPageText(pgnum_dict["layers"]) caption = _("Close Map Display {}").format(name) if not askIfSaveWorkspace or ( @@ -1086,11 +1085,10 @@ def GetMapDisplay(self, onlyCurrent=True): return self.GetLayerTree().GetMapDisplay() return None # -> return list of all mapdisplays - mlist = [] - for idx in range(self.notebookLayers.GetPageCount()): - mlist.append(self.notebookLayers.GetPage(idx).maptree.GetMapDisplay()) - - return mlist + return [ + self.notebookLayers.GetPage(idx).maptree.GetMapDisplay() + for idx in range(self.notebookLayers.GetPageCount()) + ] def GetAllMapDisplays(self): """Get all (open) map displays""" @@ -1705,10 +1703,11 @@ def OnAnimationTool(self, event=None, cmd=None): tree = self.GetLayerTree() if tree: - rasters = [] - for layer in tree.GetSelectedLayers(checkedOnly=False): - if tree.GetLayerInfo(layer, key="type") == "raster": - rasters.append(tree.GetLayerInfo(layer, key="maplayer").GetName()) + rasters = [ + tree.GetLayerInfo(layer, key="maplayer").GetName() + for layer in tree.GetSelectedLayers(checkedOnly=False) + if tree.GetLayerInfo(layer, key="type") == "raster" + ] if len(rasters) >= 2: from core.layerlist import LayerList from animation.data import AnimLayer diff --git a/gui/wxpython/lmgr/layertree.py b/gui/wxpython/lmgr/layertree.py index 350320d97a7..afed1cccc6f 100644 --- a/gui/wxpython/lmgr/layertree.py +++ b/gui/wxpython/lmgr/layertree.py @@ -1111,9 +1111,10 @@ def OnCopyMap(self, event): def OnHistogram(self, event): """Plot histogram for given raster map layer""" - rasterList = [] - for layer in self.GetSelectedLayers(): - rasterList.append(self.GetLayerInfo(layer, key="maplayer").GetName()) + rasterList = [ + self.GetLayerInfo(layer, key="maplayer").GetName() + for layer in self.GetSelectedLayers() + ] if not rasterList: GError( @@ -1151,11 +1152,12 @@ def OnUnivariateStats(self, event): def OnReportStats(self, event): """Print 2D statistics""" - rasters = [] # TODO: Implement self.GetSelectedLayers(ltype='raster') - for layer in self.GetSelectedLayers(): - if self.GetLayerInfo(layer, key="type") == "raster": - rasters.append(self.GetLayerInfo(layer, key="maplayer").GetName()) + rasters = [ + self.GetLayerInfo(layer, key="maplayer").GetName() + for layer in self.GetSelectedLayers() + if self.GetLayerInfo(layer, key="type") == "raster" + ] if rasters: self._giface.RunCmd( @@ -2256,9 +2258,7 @@ def ChangeLayer(self, item): win = self.FindWindowById(self.GetLayerInfo(item, key="ctrl")) if win.GetValue() is not None: cmd = win.GetValue().split(";") - cmdlist = [] - for c in cmd: - cmdlist.append(c.split(" ")) + cmdlist = [c.split(" ") for c in cmd] opac = 1.0 chk = self.IsItemChecked(item) hidden = not self.IsVisible(item) diff --git a/gui/wxpython/location_wizard/wizard.py b/gui/wxpython/location_wizard/wizard.py index 274fa8fbab7..c12fb22860f 100644 --- a/gui/wxpython/location_wizard/wizard.py +++ b/gui/wxpython/location_wizard/wizard.py @@ -1063,9 +1063,9 @@ def __init__(self, wizard, parent): self.searchb.ShowCancelButton(True) # create list control for datum/elipsoid list - data = [] - for key in self.parent.datums.keys(): - data.append([key, self.parent.datums[key][0], self.parent.datums[key][1]]) + data = [ + [key, datum[0], datum[1]] for (key, datum) in self.parent.datums.items() + ] self.datumlist = ItemList( self, data=data, columns=[_("Code"), _("Ellipsoid"), _("Description")] ) @@ -1262,10 +1262,10 @@ def __init__(self, wizard, parent): ) # create list control for ellipse list - data = [] # extract code, desc - for key in self.parent.ellipsoids.keys(): - data.append([key, self.parent.ellipsoids[key][0]]) + data = [ + [key, ellipsoid[0]] for (key, ellipsoid) in self.parent.ellipsoids.items() + ] self.ellipselist = ItemList( self, data=data, columns=[_("Code"), _("Description")] @@ -1753,10 +1753,11 @@ def OnBrowseCodes(self, event, search=None): self.epsglist.Populate([], update=True) return - data = [] - for code, val in self.epsgCodeDict.items(): - if code is not None: - data.append((code, val[0], val[1])) + data = [ + (code, val[0], val[1]) + for code, val in self.epsgCodeDict.items() + if code is not None + ] self.epsglist.Populate(data, update=True) @@ -2025,10 +2026,11 @@ def OnBrowseCodes(self, event, search=None): self.epsglist.Populate([], update=True) return - data = [] - for code, val in self.epsgCodeDict.items(): - if code is not None: - data.append((code, val[0], val[1])) + data = [ + (code, val[0], val[1]) + for code, val in self.epsgCodeDict.items() + if code is not None + ] self.epsglist.Populate(data, update=True) @@ -2287,10 +2289,7 @@ def OnEnterPage(self, event: WizardEvent) -> None: # print coordsys,proj4string if coordsys in {"proj", "epsg", "iau", "wkt", "file"}: - extra_opts = {} - extra_opts["project"] = "project" - extra_opts["getErrorMsg"] = True - extra_opts["read"] = True + extra_opts = {"project": "project", "getErrorMsg": True, "read": True} if coordsys == "proj": if len(datum) > 0: diff --git a/gui/wxpython/main_window/frame.py b/gui/wxpython/main_window/frame.py index 1a3ab948f7f..7af480925a4 100644 --- a/gui/wxpython/main_window/frame.py +++ b/gui/wxpython/main_window/frame.py @@ -521,9 +521,11 @@ def CanCloseDisplay(askIfSaveWorkspace): map display notebook page index (single window mode) """ - pgnum_dict = {} - pgnum_dict["layers"] = self.notebookLayers.GetPageIndex(page) - pgnum_dict["mainnotebook"] = self.mainnotebook.GetPageIndex(mapdisplay) + pgnum_dict = { + "layers": self.notebookLayers.GetPageIndex(page), + "mainnotebook": self.mainnotebook.GetPageIndex(mapdisplay), + } + name = self.notebookLayers.GetPageText(pgnum_dict["layers"]) caption = _("Close Map Display {}").format(name) if not askIfSaveWorkspace or ( @@ -1238,11 +1240,10 @@ def GetMapDisplay(self, onlyCurrent=True): return self.GetLayerTree().GetMapDisplay() return None # -> return list of all mapdisplays - mlist = [] - for idx in range(self.notebookLayers.GetPageCount()): - mlist.append(self.notebookLayers.GetPage(idx).maptree.GetMapDisplay()) - - return mlist + return [ + self.notebookLayers.GetPage(idx).maptree.GetMapDisplay() + for idx in range(self.notebookLayers.GetPageCount()) + ] def GetAllMapDisplays(self): """Get all (open) map displays""" @@ -1856,10 +1857,11 @@ def OnAnimationTool(self, event=None, cmd=None): tree = self.GetLayerTree() if tree: - rasters = [] - for layer in tree.GetSelectedLayers(checkedOnly=False): - if tree.GetLayerInfo(layer, key="type") == "raster": - rasters.append(tree.GetLayerInfo(layer, key="maplayer").GetName()) + rasters = [ + tree.GetLayerInfo(layer, key="maplayer").GetName() + for layer in tree.GetSelectedLayers(checkedOnly=False) + if tree.GetLayerInfo(layer, key="type") == "raster" + ] if len(rasters) >= 2: from core.layerlist import LayerList from animation.data import AnimLayer diff --git a/gui/wxpython/mapdisp/frame.py b/gui/wxpython/mapdisp/frame.py index 119a14a8159..0be010f3432 100644 --- a/gui/wxpython/mapdisp/frame.py +++ b/gui/wxpython/mapdisp/frame.py @@ -1148,9 +1148,7 @@ def _queryHighlight(self, vectQuery): self._highlighter_layer.SetMap( vectQuery[0]["Map"] + "@" + vectQuery[0]["Mapset"] ) - tmp = [] - for i in vectQuery: - tmp.append(i["Category"]) + tmp = [i["Category"] for i in vectQuery] self._highlighter_layer.SetCats(tmp) self._highlighter_layer.DrawSelected() @@ -1285,11 +1283,11 @@ def Profile(self, rasters=None): def OnHistogramPyPlot(self, event): """Init PyPlot histogram display canvas and tools""" - raster = [] - - for layer in self._giface.GetLayerList().GetSelectedLayers(): - if layer.maplayer.GetType() == "raster": - raster.append(layer.maplayer.GetName()) + raster = [ + layer.maplayer.GetName() + for layer in self._giface.GetLayerList().GetSelectedLayers() + if layer.maplayer.GetType() == "raster" + ] from wxplot.histogram import HistogramPlotFrame @@ -1299,11 +1297,11 @@ def OnHistogramPyPlot(self, event): def OnScatterplot(self, event): """Init PyPlot scatterplot display canvas and tools""" - raster = [] - - for layer in self._giface.GetLayerList().GetSelectedLayers(): - if layer.maplayer.GetType() == "raster": - raster.append(layer.maplayer.GetName()) + raster = [ + layer.maplayer.GetName() + for layer in self._giface.GetLayerList().GetSelectedLayers() + if layer.maplayer.GetType() == "raster" + ] from wxplot.scatter import ScatterFrame diff --git a/gui/wxpython/mapdisp/statusbar.py b/gui/wxpython/mapdisp/statusbar.py index ca69416af85..7e60e762281 100644 --- a/gui/wxpython/mapdisp/statusbar.py +++ b/gui/wxpython/mapdisp/statusbar.py @@ -223,11 +223,13 @@ def Reposition(self): It should not be necessary to call it manually. """ - widgets = [] - for item in self.statusbarItems.values(): - widgets.append((item.GetPosition(), item.GetWidget())) - - widgets.append((1, self.progressbar.GetWidget())) + widgets = [ + *[ + (item.GetPosition(), item.GetWidget()) + for item in self.statusbarItems.values() + ], + (1, self.progressbar.GetWidget()), + ] for idx, win in widgets: if not win: diff --git a/gui/wxpython/mapdisp/test_mapdisp.py b/gui/wxpython/mapdisp/test_mapdisp.py index 786be1fc85c..d2265e235b7 100755 --- a/gui/wxpython/mapdisp/test_mapdisp.py +++ b/gui/wxpython/mapdisp/test_mapdisp.py @@ -267,10 +267,11 @@ def testMapWindowProfile(self, giface, map_): self.controller = ProfileController(giface, window) self.controller.Start() - rasters = [] - for layer in giface.GetLayerList().GetSelectedLayers(): - if layer.maplayer.GetType() == "raster": - rasters.append(layer.maplayer.GetName()) + rasters = [ + layer.maplayer.GetName() + for layer in giface.GetLayerList().GetSelectedLayers() + if layer.maplayer.GetType() == "raster" + ] from wxplot.profile import ProfileFrame diff --git a/gui/wxpython/mapwin/buffered.py b/gui/wxpython/mapwin/buffered.py index 542c77b6281..7e42ebc57c9 100644 --- a/gui/wxpython/mapwin/buffered.py +++ b/gui/wxpython/mapwin/buffered.py @@ -1062,16 +1062,13 @@ def DrawCompRegionExtent(self): dispReg = self.Map.GetCurrentRegion() reg = dispReg if utils.isInRegion(dispReg, compReg) else compReg - regionCoords = [] - regionCoords.extend( - ( - (reg["w"], reg["n"]), - (reg["e"], reg["n"]), - (reg["e"], reg["s"]), - (reg["w"], reg["s"]), - (reg["w"], reg["n"]), - ) - ) + regionCoords = [ + (reg["w"], reg["n"]), + (reg["e"], reg["n"]), + (reg["e"], reg["s"]), + (reg["w"], reg["s"]), + (reg["w"], reg["n"]), + ] # draw region extent self.polypen = wx.Pen( diff --git a/gui/wxpython/modules/colorrules.py b/gui/wxpython/modules/colorrules.py index dcb34619b57..d5d74eaf08e 100644 --- a/gui/wxpython/modules/colorrules.py +++ b/gui/wxpython/modules/colorrules.py @@ -203,8 +203,7 @@ def OnRuleEnable(self, event): self.mainPanel.FindWindowById(id + 1000).Enable() self.mainPanel.FindWindowById(id + 2000).Enable() if self.mapType == "vector" and not self.parent.GetParent().colorTable: - vals = [] - vals.append(self.mainPanel.FindWindowById(id + 1000).GetValue()) + vals = [self.mainPanel.FindWindowById(id + 1000).GetValue()] try: vals.append(self.mainPanel.FindWindowById(id + 1 + 1000).GetValue()) except AttributeError: @@ -273,8 +272,7 @@ def SetRasterRule(self, num, val): def SetVectorRule(self, num, val): """Set vector rule""" - vals = [] - vals.append(val) + vals = [val] try: vals.append(self.mainPanel.FindWindowById(num + 1).GetValue()) except AttributeError: @@ -725,9 +723,7 @@ def ReadColorTable(self, ctable): self.rulesPanel.ruleslines[count]["value"] = value self.rulesPanel.ruleslines[count]["color"] = color self.rulesPanel.mainPanel.FindWindowById(count + 1000).SetValue(value) - rgb = [] - for c in color.split(":"): - rgb.append(int(c)) + rgb = [int(c) for c in color.split(":")] self.rulesPanel.mainPanel.FindWindowById(count + 2000).SetColour(rgb) # range try: diff --git a/gui/wxpython/nviz/tools.py b/gui/wxpython/nviz/tools.py index 8a3a57a8b42..49cbec8067e 100644 --- a/gui/wxpython/nviz/tools.py +++ b/gui/wxpython/nviz/tools.py @@ -1936,9 +1936,10 @@ def _createVectorPage(self, parent): def GselectOnPopup(self, ltype, exclude=False): """Update gselect.Select() items""" - maps = [] - for layer in self.mapWindow.Map.GetListOfLayers(ltype=ltype, active=True): - maps.append(layer.GetName()) + maps = [ + layer.GetName() + for layer in self.mapWindow.Map.GetListOfLayers(ltype=ltype, active=True) + ] return maps, exclude def _createVolumePage(self, parent): @@ -3833,10 +3834,7 @@ def _get3dRange(self, name): """Gelper func for getting range of 3d map""" ret = RunCommand("r3.info", read=True, flags="r", map=name) if ret: - range = [] - for value in ret.strip("\n").split("\n"): - range.append(float(value.split("=")[1])) - return range + return [float(value.split("=")[1]) for value in ret.strip("\n").split("\n")] return -1e6, 1e6 @@ -5183,11 +5181,9 @@ def UpdatePage(self, pageId): self.EnablePage("constant", True) elif pageId == "cplane": count = self._display.GetCPlanesCount() - choices = [ - _("None"), + choices = [_("None")] + [ + "%s %i" % (_("Plane"), plane + 1) for plane in range(count) ] - for plane in range(count): - choices.append("%s %i" % (_("Plane"), plane + 1)) self.FindWindowById(self.win["cplane"]["planes"]).SetItems(choices) current = 0 for i, cplane in enumerate(self.mapWindow.cplanes): diff --git a/gui/wxpython/nviz/workspace.py b/gui/wxpython/nviz/workspace.py index 378f17aef46..13df2ad981d 100644 --- a/gui/wxpython/nviz/workspace.py +++ b/gui/wxpython/nviz/workspace.py @@ -30,9 +30,7 @@ def __init__(self): def SetConstantDefaultProp(self): """Set default constant data properties""" - data = {} - for key, value in UserSettings.Get(group="nviz", key="constant").items(): - data[key] = value + data = dict(UserSettings.Get(group="nviz", key="constant").items()) color = ( str(data["color"][0]) + ":" @@ -137,10 +135,7 @@ def SetVolumeDefaultProp(self): group="nviz", key="volume", subkey=["draw", "mode"] ) desc = "isosurface" if sel == 0 else "slice" - data["draw"]["mode"] = { - "value": sel, - "desc": desc, - } + data["draw"]["mode"] = {"value": sel, "desc": desc} elif control == "box": box = UserSettings.Get( group="nviz", key="volume", subkey=["draw", "box"] @@ -184,10 +179,11 @@ def SetIsosurfaceDefaultProp(self): def SetSliceDefaultProp(self): """Set default slice properties""" - data = {} - data["position"] = copy.deepcopy( - UserSettings.Get(group="nviz", key="volume", subkey="slice_position") - ) + data = { + "position": copy.deepcopy( + UserSettings.Get(group="nviz", key="volume", subkey="slice_position") + ) + } data["position"]["update"] = None data["transp"] = copy.deepcopy( diff --git a/gui/wxpython/photo2image/ip2i_manager.py b/gui/wxpython/photo2image/ip2i_manager.py index 1adb2abcc8c..dc5713e961a 100644 --- a/gui/wxpython/photo2image/ip2i_manager.py +++ b/gui/wxpython/photo2image/ip2i_manager.py @@ -772,9 +772,8 @@ def SetSettings(self): font = self.GetFont() font.SetPointSize(int(spx) + 2) - textProp = {} - textProp["active"] = True - textProp["font"] = font + textProp = {"active": True, "font": font} + self.pointsToDrawSrc.SetPropertyVal("text", textProp) self.pointsToDrawTgt.SetPropertyVal("text", copy(textProp)) diff --git a/gui/wxpython/psmap/dialogs.py b/gui/wxpython/psmap/dialogs.py index 428ae248c87..25319e21976 100644 --- a/gui/wxpython/psmap/dialogs.py +++ b/gui/wxpython/psmap/dialogs.py @@ -792,11 +792,12 @@ def OnChoice(self, event): currPaper = self.paperTable[self.getCtrl("Format").GetSelection()] currUnit = self.unitConv.findUnit(self.getCtrl("Units").GetStringSelection()) currOrientIdx = self.getCtrl("Orientation").GetSelection() - newSize = {} - for item in self.cat[3:]: - newSize[item] = self.unitConv.convert( + newSize = { + item: self.unitConv.convert( float(currPaper[item]), fromUnit="inch", toUnit=currUnit ) + for item in self.cat[3:] + } enable = True if currPaper["Format"] != _("custom"): @@ -5470,10 +5471,11 @@ def _positionPanel(self, notebook): ) sizerR = wx.StaticBoxSizer(box, wx.VERTICAL) flexSizer = wx.FlexGridSizer(rows=3, cols=3, hgap=5, vgap=5) - ref = [] - for row in ["upper", "center", "lower"]: - for col in ["left", "center", "right"]: - ref.append(row + " " + col) + ref = [ + row + " " + col + for row in ["upper", "center", "lower"] + for col in ["left", "center", "right"] + ] self.radio = [ RadioButton(panel, id=wx.ID_ANY, label="", style=wx.RB_GROUP, name=ref[0]) ] diff --git a/gui/wxpython/psmap/instructions.py b/gui/wxpython/psmap/instructions.py index dcdfb907383..4528e0a0d93 100644 --- a/gui/wxpython/psmap/instructions.py +++ b/gui/wxpython/psmap/instructions.py @@ -140,10 +140,7 @@ def AddInstruction(self, instruction): def FindInstructionByType(self, type, list=False): """Find instruction(s) with the given type""" - inst = [] - for each in self.instruction: - if each.type == type: - inst.append(each) + inst = [each for each in self.instruction if each.type == type] if len(inst) == 1 and not list: return inst[0] return inst @@ -1676,8 +1673,7 @@ def __str__(self): def Read(self, instruction, text, **kwargs): """Read instruction and save information""" - instr = {} - instr["rLegend"] = True + instr = {"rLegend": True} for line in text: try: if line.startswith("where"): @@ -1840,8 +1836,7 @@ def __str__(self): def Read(self, instruction, text, **kwargs): """Read instruction and save information""" - instr = {} - instr["vLegend"] = True + instr = {"vLegend": True} for line in text: try: if line.startswith("where"): @@ -1906,8 +1901,7 @@ def __str__(self): def Read(self, instruction, text): """Read instruction and save information""" - instr = {} - instr["isRaster"] = True + instr = {"isRaster": True} try: map = text.split()[1] except IndexError: diff --git a/gui/wxpython/rlisetup/frame.py b/gui/wxpython/rlisetup/frame.py index 3905fa9b09d..dd93e607cea 100644 --- a/gui/wxpython/rlisetup/frame.py +++ b/gui/wxpython/rlisetup/frame.py @@ -213,12 +213,13 @@ def _layout(self): def ListFiles(self): """Check the configuration files inside the path""" # list of configuration file - listfiles = [] # return all the configuration files in self.rlipath, check if there are # link or directory and doesn't add them - for rli_conf in os.listdir(self.rlipath): - if os.path.isfile(os.path.join(self.rlipath, rli_conf)): - listfiles.append(rli_conf) + listfiles = [ + rli_conf + for rli_conf in os.listdir(self.rlipath) + if os.path.isfile(os.path.join(self.rlipath, rli_conf)) + ] return sorted(listfiles) def OnClose(self, event): diff --git a/gui/wxpython/rlisetup/wizard.py b/gui/wxpython/rlisetup/wizard.py index 8a40142bc68..fb23affbd25 100644 --- a/gui/wxpython/rlisetup/wizard.py +++ b/gui/wxpython/rlisetup/wizard.py @@ -727,9 +727,7 @@ def CheckVector(self, vector): ) return False, [] if links > 0: - layers = [] - for i in range(1, links + 1): - layers.append(str(i)) + layers = [str(i) for i in range(1, links + 1)] return True, layers return False, [] diff --git a/gui/wxpython/startup/locdownload.py b/gui/wxpython/startup/locdownload.py index 7e24724d862..fd2f174df14 100644 --- a/gui/wxpython/startup/locdownload.py +++ b/gui/wxpython/startup/locdownload.py @@ -231,9 +231,7 @@ def __init__(self, parent, database, locations=LOCATIONS): parent=self, label=_("Select sample project to download:") ) - choices = [] - for item in self.locations: - choices.append(item["label"]) + choices = [item["label"] for item in self.locations] self.choice = wx.Choice(parent=self, choices=choices) self.choice.Bind(wx.EVT_CHOICE, self.OnChangeChoice) diff --git a/gui/wxpython/tools/update_menudata.py b/gui/wxpython/tools/update_menudata.py index 08897e6147d..18c542c71f2 100644 --- a/gui/wxpython/tools/update_menudata.py +++ b/gui/wxpython/tools/update_menudata.py @@ -71,9 +71,7 @@ def updateData(data, modules): if node.tag != "menuitem": continue - item = {} - for child in node: - item[child.tag] = child.text + item = {child.tag: child.text for child in node} if "command" not in item: continue diff --git a/gui/wxpython/tplot/frame.py b/gui/wxpython/tplot/frame.py index 977fea94cea..831d06e93a8 100755 --- a/gui/wxpython/tplot/frame.py +++ b/gui/wxpython/tplot/frame.py @@ -760,8 +760,7 @@ def _writeCSV(self, x, y): with open(self.csvpath, "w", newline="") as fi: writer = csv.writer(fi) if self.header: - head = ["Time"] - head.extend(self.yticksNames) + head = ["Time", *self.yticksNames] writer.writerow(head) writer.writerows(zipped) @@ -1337,10 +1336,11 @@ def AddDataset(self, yranges, xranges, datasetName): self.data[datasetName][xranges[i]] = yranges[i] def GetInformation(self, x): - values = {} - for key, value in self.data.items(): - if value[x]: - values[key] = [self.convert(x), value[x]] + values = { + key: [self.convert(x), value[x]] + for key, value in self.data.items() + if value[x] + } if len(values) == 0: return None diff --git a/gui/wxpython/vdigit/dialogs.py b/gui/wxpython/vdigit/dialogs.py index 494f8f66acc..27d34601459 100644 --- a/gui/wxpython/vdigit/dialogs.py +++ b/gui/wxpython/vdigit/dialogs.py @@ -75,9 +75,7 @@ def __init__( for layer in cats[line].keys(): self.cats[line][layer] = list(cats[line][layer]) - layers = [] - for layer in self.digit.GetLayers(): - layers.append(str(layer)) + layers = [str(layer) for layer in self.digit.GetLayers()] # make copy of cats (used for 'reload') self.cats_orig = copy.deepcopy(self.cats) @@ -114,9 +112,7 @@ def __init__( self.fidText.SetLabel(str(self.fid)) else: self.fidText.Show(False) - choices = [] - for fid in self.cats.keys(): - choices.append(str(fid)) + choices = [str(fid) for fid in self.cats.keys()] self.fidMulti.SetItems(choices) self.fidMulti.SetSelection(0) @@ -546,9 +542,7 @@ def UpdateDialog(self, query=None, cats=None): else: self.fidText.Show(False) self.fidMulti.Show(True) - choices = [] - for fid in self.cats.keys(): - choices.append(str(fid)) + choices = [str(fid) for fid in self.cats.keys()] self.fidMulti.SetItems(choices) self.fidMulti.SetSelection(0) diff --git a/gui/wxpython/vdigit/wxdigit.py b/gui/wxpython/vdigit/wxdigit.py index 342996efc3d..b4b7b0dfd7b 100644 --- a/gui/wxpython/vdigit/wxdigit.py +++ b/gui/wxpython/vdigit/wxdigit.py @@ -828,11 +828,7 @@ def _convertGeom(self, poPoints): """ Points = poPoints.contents - pts_geom = [] - for j in range(Points.n_points): - pts_geom.append((Points.x[j], Points.y[j])) - - return pts_geom + return [(Points.x[j], Points.y[j]) for j in range(Points.n_points)] def MoveSelectedLines(self, move): """Move selected features diff --git a/gui/wxpython/vnet/dialogs.py b/gui/wxpython/vnet/dialogs.py index c5f72bc7f07..ca928a6b164 100644 --- a/gui/wxpython/vnet/dialogs.py +++ b/gui/wxpython/vnet/dialogs.py @@ -581,13 +581,10 @@ def _updateResultDbMgrPage(self): def OnPageChanged(self, event): """Tab switched""" if event.GetEventObject() == self.notebook: - dbMgrIndxs = [] - dbMgrIndxs.extend( - ( - self.notebook.GetPageIndexByName("inputDbMgr"), - self.notebook.GetPageIndexByName("resultDbMgr"), - ) - ) + dbMgrIndxs = [ + self.notebook.GetPageIndexByName("inputDbMgr"), + self.notebook.GetPageIndexByName("resultDbMgr"), + ] if self.notebook.GetSelection() in dbMgrIndxs: self.stBar.AddStatusItem( text=_("Loading tables..."), @@ -834,9 +831,7 @@ def OnNLayerSel(self, event): self._setInputData() def _setInputData(self): - params = {} - for k, v in self.inputData.items(): - params[k] = v.GetValue() + params = {k: v.GetValue() for k, v in self.inputData.items()} flags = {} self.vnet_mgr.SetParams(params, flags) @@ -1258,11 +1253,13 @@ def __init__( rules = RunCommand("v.colors", read=True, flags="l") - settsLabels = {} - - settsLabels["color_table"] = StaticText( - parent=self, id=wx.ID_ANY, label=_("Color table style %s:") % "(v.net.flow)" - ) + settsLabels = { + "color_table": StaticText( + parent=self, + id=wx.ID_ANY, + label=_("Color table style %s:") % "(v.net.flow)", + ) + } self.settings["color_table"] = ComboBox( parent=self, id=wx.ID_ANY, @@ -1651,11 +1648,7 @@ def InputSel(self): self._updateInputDbMgrPage(show=True) def GetData(self): - params = {} - for param, sel in self.inputData.items(): - params[param] = sel.GetValue() - - return params + return {param: sel.GetValue() for param, sel in self.inputData.items()} class OutputVectorDialog(wx.Dialog): diff --git a/gui/wxpython/vnet/toolbars.py b/gui/wxpython/vnet/toolbars.py index d31313091fe..4472d718064 100644 --- a/gui/wxpython/vnet/toolbars.py +++ b/gui/wxpython/vnet/toolbars.py @@ -208,10 +208,10 @@ def __init__(self, parent, vnet_mgr): self.vnet_mgr = vnet_mgr self.InitToolbar(self._toolbarData()) - choices = [] - - for moduleName in self.vnet_mgr.GetAnalyses(): - choices.append(self.vnet_mgr.GetAnalysisProperties(moduleName)["label"]) + choices = [ + self.vnet_mgr.GetAnalysisProperties(moduleName)["label"] + for moduleName in self.vnet_mgr.GetAnalyses() + ] self.anChoice = ComboBox( parent=self, diff --git a/gui/wxpython/vnet/vnet_core.py b/gui/wxpython/vnet/vnet_core.py index b0ec072b2af..b019256bb75 100644 --- a/gui/wxpython/vnet/vnet_core.py +++ b/gui/wxpython/vnet/vnet_core.py @@ -419,9 +419,11 @@ def _vnetPathRunAn(self, analysis, output, params, flags, catPts): cats = self.data.GetAnalysisProperties()["cmdParams"]["cats"] # Creates part of cmd fro analysis - cmdParams = [analysis] - cmdParams.extend(self._setInputParams(analysis, params, flags)) - cmdParams.append("output=" + output) + cmdParams = [ + analysis, + *self._setInputParams(analysis, params, flags), + "output=" + output, + ] cmdPts = [] for cat in cats: @@ -513,9 +515,11 @@ def _onDone(self, event): def _runTurnsAn(self, analysis, output, params, flags, catPts): # Creates part of cmd fro analysis - cmdParams = [analysis] - cmdParams.extend(self._setInputParams(analysis, params, flags)) - cmdParams.append("output=" + output) + cmdParams = [ + analysis, + *self._setInputParams(analysis, params, flags), + "output=" + output, + ] cats = {} for cat_name, pts_coor in catPts.items(): @@ -622,9 +626,11 @@ def _runAn(self, analysis, output, params, flags, catPts): """Called for all v.net.* analysis (except v.net.path)""" # Creates part of cmd fro analysis - cmdParams = [analysis] - cmdParams.extend(self._setInputParams(analysis, params, flags)) - cmdParams.append("output=" + output) + cmdParams = [ + analysis, + *self._setInputParams(analysis, params, flags), + "output=" + output, + ] cats = self.data.GetAnalysisProperties()["cmdParams"]["cats"] @@ -765,9 +771,7 @@ def _getPtByCat(self, analysis): anProps = self.data.GetAnalysisProperties() cats = anProps["cmdParams"]["cats"] - ptByCats = {} - for cat in anProps["cmdParams"]["cats"]: - ptByCats[cat[0]] = [] + ptByCats = {cat[0]: [] for cat in anProps["cmdParams"]["cats"]} for i in range(self.pts_data.GetPointsCount()): pt_data = self.pts_data.GetPointData(i) @@ -893,13 +897,13 @@ def _updateHistStepData(self, histStepData): ptDataHist = histStepData["points"]["pt" + str(iPt)] e, n = ptDataHist["coords"] - pt_data = {"e": e, "n": n} - - pt_data["type"] = int(ptDataHist["catIdx"]) - - pt_data["topology"] = ptDataHist["topology"] - - pt_data["use"] = ptDataHist["checked"] + pt_data = { + "e": e, + "n": n, + "type": int(ptDataHist["catIdx"]), + "topology": ptDataHist["topology"], + "use": ptDataHist["checked"], + } pts.append(pt_data) diff --git a/gui/wxpython/vnet/vnet_data.py b/gui/wxpython/vnet/vnet_data.py index 778f4cf50b1..9dd1bff4f66 100644 --- a/gui/wxpython/vnet/vnet_data.py +++ b/gui/wxpython/vnet/vnet_data.py @@ -427,11 +427,7 @@ def _ptDataToList(self, pt_data): return pt_list_data def _ptListDataToPtData(self, pt_list_data): - pt_data = {} - for i, val in enumerate(pt_list_data): - pt_data[self.cols["name"][i]] = val - - return pt_data + return {self.cols["name"][i]: val for i, val in enumerate(pt_list_data)} def _usePoint(self, pt_id, use): """Item is checked/unchecked""" @@ -557,8 +553,7 @@ def OnMapClickHandler(self, event): def GetColumns(self, only_relevant=True): cols_data = deepcopy(self.cols) - hidden_cols = [] - hidden_cols.extend((self.cols["name"].index("e"), self.cols["name"].index("n"))) + hidden_cols = [self.cols["name"].index("e"), self.cols["name"].index("n")] analysis, valid = self.an_params.GetParam("analysis") if only_relevant and len(self.an_data[analysis]["cmdParams"]["cats"]) <= 1: @@ -1347,11 +1342,7 @@ def __init__(self): ] def GetData(self): - data = [] - for ival in self.turn_data: - data.append(ival[1:]) - - return data + return [ival[1:] for ival in self.turn_data] def GetValue(self, line, col): return self.turn_data[line][col] diff --git a/gui/wxpython/web_services/cap_interface.py b/gui/wxpython/web_services/cap_interface.py index 38cc7c3c72f..91b2b396dfd 100644 --- a/gui/wxpython/web_services/cap_interface.py +++ b/gui/wxpython/web_services/cap_interface.py @@ -109,11 +109,7 @@ def GetFormats(self): get_map_node = request_node.find(self.xml_ns.Ns("GetMap")) format_nodes = get_map_node.findall(self.xml_ns.Ns("Format")) - formats = [] - for node in format_nodes: - formats.append(node.text) - - return formats + return [node.text for node in format_nodes] class WMSLayer(LayerBase): @@ -265,10 +261,10 @@ def GetLayerData(self, param): return styles if param == "format": - formats = [] - for frmt in self.layer_node.findall(self.xml_ns.NsWmts("Format")): - formats.append(frmt.text.strip()) - return formats + return [ + frmt.text.strip() + for frmt in self.layer_node.findall(self.xml_ns.NsWmts("Format")) + ] if param == "srs": return self.projs diff --git a/gui/wxpython/web_services/dialogs.py b/gui/wxpython/web_services/dialogs.py index bed4f57c70b..309d4b8387c 100644 --- a/gui/wxpython/web_services/dialogs.py +++ b/gui/wxpython/web_services/dialogs.py @@ -336,11 +336,10 @@ def OnClose(self, event): event.Skip() def _getCapFiles(self): - ws_cap_files = {} - for v in self.ws_panels.values(): - ws_cap_files[v["panel"].GetWebService()] = v["panel"].GetCapFile() - - return ws_cap_files + return { + v["panel"].GetWebService(): v["panel"].GetCapFile() + for v in self.ws_panels.values() + } def OnServer(self, event): """Server settings edited""" @@ -416,12 +415,9 @@ def _getConnectedWS(self): :return: list of found web services on server (identified as keys in self.ws_panels) """ - conn_ws = [] - for ws, data in self.ws_panels.items(): - if data["panel"].IsConnected(): - conn_ws.append(ws) - - return conn_ws + return [ + ws for ws, data in self.ws_panels.items() if data["panel"].IsConnected() + ] def UpdateDialogAfterConnection(self): """Update dialog after all web service panels downloaded and parsed @@ -750,10 +746,7 @@ def LoadCapFiles(self, ws_cap_files, cmd): def _getServerConnFromCmd(self, cmd): """Get url/server/password from cmd tuple""" conn = {"url": "", "username": "", "password": ""} - - for k in conn.keys(): - if k in cmd[1]: - conn[k] = cmd[1][k] + conn |= {k: cmd[1][k] for k in conn.keys() if k in cmd[1]} return conn def _apply(self): diff --git a/gui/wxpython/web_services/widgets.py b/gui/wxpython/web_services/widgets.py index db057313831..29a1c99014a 100644 --- a/gui/wxpython/web_services/widgets.py +++ b/gui/wxpython/web_services/widgets.py @@ -514,10 +514,7 @@ def _prepareForNewConn(self, url, username, password): self.conn = {"url": url, "password": password, "username": username} - conn_cmd = [] - for k, v in self.conn.items(): - if v: - conn_cmd.append("%s=%s" % (k, v)) + conn_cmd = ["%s=%s" % (k, v) for k, v in self.conn.items() if v] self.ws_cmdl = self.ws_drvs[self.ws]["cmd"] + conn_cmd diff --git a/gui/wxpython/wxplot/dialogs.py b/gui/wxpython/wxplot/dialogs.py index bae305a1817..cdb74c64a9e 100755 --- a/gui/wxpython/wxplot/dialogs.py +++ b/gui/wxpython/wxplot/dialogs.py @@ -986,9 +986,7 @@ def _do_layout(self): gridSizer = wx.GridBagSizer(vgap=5, hgap=5) row = 0 - choicelist = [] - for i in self.rasterList: - choicelist.append(str(i)) + choicelist = [str(i) for i in self.rasterList] self.mapchoice = Choice( parent=self, id=wx.ID_ANY, size=(300, -1), choices=choicelist