Skip to content

Commit

Permalink
Modernize object inheritance, super() calls, and OSError aliases (OSG…
Browse files Browse the repository at this point in the history
  • Loading branch information
echoix authored Dec 12, 2023
1 parent c8af2ea commit a71b72a
Show file tree
Hide file tree
Showing 121 changed files with 327 additions and 363 deletions.
2 changes: 1 addition & 1 deletion gui/wxpython/animation/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def SetAnimations(self, layerLists):
anim.SetLayerList(layerLists[i])
animationData.append(anim)

except (GException, ValueError, IOError) as e:
except (GException, ValueError, OSError) as e:
GError(
parent=self.frame,
message=str(e),
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/animation/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from core.layerlist import LayerList, Layer


class AnimationData(object):
class AnimationData:
def __init__(self):
self._name = None
self._windowIndex = 0
Expand Down Expand Up @@ -133,7 +133,7 @@ def SetWorkspaceFile(self, fileName):
raise ValueError(_("No workspace file selected."))

if not os.path.exists(fileName):
raise IOError(_("File %s not found") % fileName)
raise OSError(_("File %s not found") % fileName)
self._workspaceFile = fileName

self.nvizTask.Load(self.workspaceFile)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/animation/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ def OnOk(self, event):
self._update()
self.UnInit()
self.EndModal(wx.ID_OK)
except (GException, ValueError, IOError) as e:
except (GException, ValueError, OSError) as e:
GError(message=str(e), showTraceback=False, caption=_("Invalid input"))


Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/animation/temporal_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class GranularityMode:
ORIGINAL = 2


class TemporalManager(object):
class TemporalManager:
"""Class for temporal data processing."""

def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/gconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def RunCmd(
skipInterface = False
break
sfile.close()
except IOError:
except OSError:
pass

if len(command) == 1 and not skipInterface:
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/core/giface.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Notification:
RAISE_WINDOW = 3


class Layer(object):
class Layer:
"""Layer is generally usable layer object.
.. note::
Expand All @@ -52,7 +52,7 @@ class Layer(object):
pass


class LayerList(object):
class LayerList:
def GetSelectedLayers(self, checkedOnly=True):
"""Returns list of selected layers.
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/core/layerlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from grass.script import core as gcore


class LayerList(object):
class LayerList:
"""Non GUI class managing list of layers.
It provides API for handling layers. In the future,
Expand Down Expand Up @@ -162,7 +162,7 @@ def __str__(self):
return text


class Layer(object):
class Layer:
"""Object representing layer.
Properties of the object are checked during setting.
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/core/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_tempfile_name(suffix, create=False):
return name


class Layer(object):
class Layer:
"""Virtual class which stores information about layers (map layers and
overlays) of the map composition.
Expand Down Expand Up @@ -902,7 +902,7 @@ def GetWindow(self):
)
try:
windfile = open(filename, "r")
except IOError as e:
except OSError as e:
sys.exit(
_("Error: Unable to open '%(file)s'. Reason: %(ret)s. wxGUI exited.\n")
% {"file": filename, "ret": e}
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def color(item):
else:
return item

return super(SettingsJSONEncoder, self).iterencode(color(obj))
return super().iterencode(color(obj))


def settings_JSON_decode_hook(obj):
Expand Down Expand Up @@ -933,7 +933,7 @@ def _readLegacyFile(self, settings=None):

try:
fd = open(self.legacyFilePath, "r")
except IOError:
except OSError:
sys.stderr.write(
_("Unable to read settings file <%s>\n") % self.legacyFilePath
)
Expand Down Expand Up @@ -988,7 +988,7 @@ def SaveToFile(self, settings=None):
try:
with open(self.filePath, "w") as f:
json.dump(settings, f, indent=2, cls=SettingsJSONEncoder)
except IOError as e:
except OSError as e:
raise GException(e)
except Exception as e:
raise GException(
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/core/treemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from grass.script.utils import naturally_sort


class TreeModel(object):
class TreeModel:
"""Class represents a tree structure with hidden root.
TreeModel is used together with TreeView class to display results in GUI.
Expand Down Expand Up @@ -192,7 +192,7 @@ def __str__(self):
return "\n".join(text)


class DictNode(object):
class DictNode:
"""Node which has data in a form of dictionary."""

def __init__(self, data=None):
Expand Down Expand Up @@ -243,7 +243,7 @@ class ModuleNode(DictNode):
"""Node representing module."""

def __init__(self, label=None, data=None):
super(ModuleNode, self).__init__(data=data)
super().__init__(data=data)
self._label = label if label else ""
if not data:
self.data = {}
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ def GetSettingsPath():
try:
verFd = open(os.path.join(ETCDIR, "VERSIONNUMBER"))
version = int(verFd.readlines()[0].split(" ")[0].split(".")[0])
except (IOError, ValueError, TypeError, IndexError) as e:
except (OSError, ValueError, TypeError, IndexError) as e:
sys.exit(_("ERROR: Unable to determine GRASS version. Details: %s") % e)

verFd.close()
Expand Down Expand Up @@ -840,7 +840,7 @@ def StoreEnvVariable(key, value=None, envFile=None):
if os.path.exists(envFile):
try:
fd = open(envFile)
except IOError as e:
except OSError as e:
sys.stderr.write(_("Unable to open file '%s'\n") % envFile)
return
for line in fd.readlines():
Expand Down Expand Up @@ -870,7 +870,7 @@ def StoreEnvVariable(key, value=None, envFile=None):
# write update env file
try:
fd = open(envFile, "w")
except IOError as e:
except OSError as e:
sys.stderr.write(_("Unable to create file '%s'\n") % envFile)
return
if windows:
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ def __processNvizState(self, node):
self.nviz_state["constants"] = constants


class WriteWorkspaceFile(object):
class WriteWorkspaceFile:
"""Generic class for writing workspace file"""

def __init__(self, lmgr, file):
Expand Down Expand Up @@ -1721,7 +1721,7 @@ def __writeOverlayParams(self, disp_size, cmd, coord_px):
self.indent -= 4


class ProcessGrcFile(object):
class ProcessGrcFile:
def __init__(self, filename):
"""Process GRC file"""
self.filename = filename
Expand All @@ -1747,7 +1747,7 @@ def read(self, parent):
"""
try:
file = open(self.filename, "r")
except IOError:
except OSError:
wx.MessageBox(
parent=parent,
message=_("Unable to open file <%s> for reading.") % self.filename,
Expand Down
6 changes: 2 additions & 4 deletions gui/wxpython/datacatalog/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class DataCatalogNode(DictNode):
"""Node representing item in datacatalog."""

def __init__(self, data=None):
super(DataCatalogNode, self).__init__(data=data)
super().__init__(data=data)

@property
def label(self):
Expand Down Expand Up @@ -253,9 +253,7 @@ def __init__(
"""Location Map Tree constructor."""
self._model = TreeModel(DataCatalogNode)
self._orig_model = self._model
super(DataCatalogTree, self).__init__(
parent=parent, model=self._model, id=wx.ID_ANY, style=style
)
super().__init__(parent=parent, model=self._model, id=wx.ID_ANY, style=style)

self._giface = giface
self._restricted = True
Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/dbmgr/sqlbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,7 @@ def __init__(self, parent, vectmap, id=wx.ID_ANY, layer=1):
"map": vectmap,
}

super(SQLBuilderWhere, self).__init__(
parent, title, vectmap, id=wx.ID_ANY, layer=layer
)
super().__init__(parent, title, vectmap, id=wx.ID_ANY, layer=layer)

def OnClear(self, event):
self.text_sql.SetValue("")
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/gcp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def getSmallDnArrowImage():
return img


class GCPWizard(object):
class GCPWizard:
"""
Start wizard here and finish wizard here
"""
Expand Down Expand Up @@ -1575,7 +1575,7 @@ def SaveGCPs(self, event):
+ "\n"
)

except IOError as err:
except OSError as err:
GError(
parent=self,
message="%s <%s>. %s%s"
Expand Down Expand Up @@ -1635,7 +1635,7 @@ def ReadGCPs(self):
self.list.CheckItem(index, check)
GCPcnt += 1

except IOError as err:
except OSError as err:
GError(
parent=self,
message="%s <%s>. %s%s"
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/gmodeler/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ def WriteModelFile(self, filename):
tmpfile.seek(0)
for line in tmpfile.readlines():
mfile.write(line)
except IOError:
except OSError:
wx.MessageBox(
parent=self,
message=_("Unable to open file <%s> for writing.") % filename,
Expand Down Expand Up @@ -2173,7 +2173,7 @@ def OnRun(self, event):
try:
fd = open(self.filename, "w")
fd.write(self.body.GetText())
except IOError as e:
except OSError as e:
GError(_("Unable to launch Python script. %s") % e, parent=self)
return
finally:
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/gmodeler/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
from grass.script import task as gtask


class Model(object):
class Model:
"""Class representing the model"""

def __init__(self, canvas=None):
Expand Down Expand Up @@ -890,7 +890,7 @@ def Parameterize(self):
return result


class ModelObject(object):
class ModelObject:
def __init__(self, id=-1, label=""):
self.id = id # internal id, should be not changed
self.label = ""
Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/gui_core/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1809,9 +1809,7 @@ def __init__(
self.parent = parent # GMFrame
self.opacity = opacity # current opacity

super(SetOpacityDialog, self).__init__(
parent, id=id, pos=pos, size=size, style=style, title=title
)
super().__init__(parent, id=id, pos=pos, size=size, style=style, title=title)

self.applyOpacity = Signal("SetOpacityDialog.applyOpacity")
panel = wx.Panel(parent=self, id=wx.ID_ANY)
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/gui_core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ def MakeModal(self, modal=True):
if not modal and hasattr(self, "_disabler"):
del self._disabler
else:
super(TaskFrame, self).MakeModal(modal)
super().MakeModal(modal)

def updateValuesHook(self, event=None):
"""Update status bar data"""
Expand Down Expand Up @@ -2571,7 +2571,7 @@ def OnFileLoad(self, event):
data = ""
try:
f = open(path, "r")
except IOError as e:
except OSError as e:
gcmd.GError(
parent=self,
showTraceback=False,
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/gui_core/ghelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,10 +785,10 @@ def OnLinkClicked(self, linkinfo):
self.historyIdx += 1
self.parent.OnHistory()

super(HelpWindow, self).OnLinkClicked(linkinfo)
super().OnLinkClicked(linkinfo)

def LoadPage(self, path):
super(HelpWindow, self).LoadPage(path)
super().LoadPage(path)
self.loaded = True

def fillContentsFromFile(self, htmlFile, skipDescription=True):
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gui_core/goutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def OnOutputSave(self, event):
try:
output = open(path, "w")
output.write(text)
except IOError as e:
except OSError as e:
GError(
_("Unable to write file '%(path)s'.\n\nDetails: %(error)s")
% {"path": path, "error": e}
Expand Down
Loading

0 comments on commit a71b72a

Please sign in to comment.