Skip to content

Commit

Permalink
better naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
lindakladivova committed Jan 18, 2024
1 parent 4d11666 commit 441d357
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
16 changes: 8 additions & 8 deletions gui/wxpython/history/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ def _popupMenuLayer(self):
"""Create popup menu for commands"""
menu = Menu()

item = wx.MenuItem(menu, wx.ID_ANY, _("&Delete"))
item = wx.MenuItem(menu, wx.ID_ANY, _("&Remove"))
menu.AppendItem(item)
self.Bind(wx.EVT_MENU, self.OnDeleteCmd, item)
self.Bind(wx.EVT_MENU, self.OnRemoveCmd, item)

self.PopupMenu(menu)
menu.Destroy()
Expand Down Expand Up @@ -188,19 +188,19 @@ def RemoveEntryFromHistory(self, del_line_number):
except OSError as e:
GError(str(e))

def OnDeleteCmd(self, event):
"""Delete cmd from the history file"""
def OnRemoveCmd(self, event):
"""Remove cmd from the history file"""
tree_node = self._getSelectedNode()
cmd = tree_node.data["command"]
question = _("Do you really want to delete <{}> command?").format(cmd)
if self._confirmDialog(question, title=_("Delete command")) == wx.ID_YES:
self.showNotification.emit(message=_("Deleting <{}>").format(cmd))
question = _("Do you really want to remove <{}> command?").format(cmd)
if self._confirmDialog(question, title=_("Remove command")) == wx.ID_YES:
self.showNotification.emit(message=_("Removing <{}>").format(cmd))
tree_index = self._model.GetIndexOfNode(tree_node)[0]
self.RemoveEntryFromHistory(tree_index)
self._giface.entryFromHistoryRemoved.emit(index=tree_index)
self._model.RemoveNode(tree_node)
self._refreshTree()
self.showNotification.emit(message=_("<{}> deleted").format(cmd))
self.showNotification.emit(message=_("<{}> removed").format(cmd))

def OnItemSelected(self, node):
"""Item selected"""
Expand Down
42 changes: 21 additions & 21 deletions python/grass/grassdb/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ def get_current_mapset_gui_history_path():
def create_history_file(history_path):
"""Set up a new GUI history file."""
try:
fileHistory = open(
file_history = open(
history_path,
encoding="utf-8",
mode="w",
)
except OSError as e:
raise OSError(_("Unable to create history file {}").format(history_path)) from e
finally:
fileHistory.close()
file_history.close()


def read_history(history_path):
"""Get list of commands from history file."""
hist = list()
try:
fileHistory = open(
file_history = open(
history_path,
encoding="utf-8",
mode="r",
Expand All @@ -52,10 +52,10 @@ def read_history(history_path):
_("Unable to read commands from history file {}").format(history_path)
) from e
try:
for line in fileHistory.readlines():
for line in file_history.readlines():
hist.append(line.replace("\n", ""))
finally:
fileHistory.close()
file_history.close()
return hist


Expand All @@ -65,48 +65,48 @@ def add_entry_to_history(command, history_path=None):
:param str command: the command given as a string
:param str|None history_path: history file path string
"""
fileHistory = None
file_history = None
if not history_path:
history_path = get_current_mapset_gui_history_path()
try:
if os.path.exists(history_path):
fileHistory = open(history_path, encoding="utf-8", mode="a")
file_history = open(history_path, encoding="utf-8", mode="a")
else:
fileHistory = open(history_path, encoding="utf-8", mode="w")
fileHistory.write(command + "\n")
file_history = open(history_path, encoding="utf-8", mode="w")
file_history.write(command + "\n")
except OSError as e:
raise OSError(
_("Unable to add entry to history file {}").format(history_path)
) from e
finally:
if fileHistory:
fileHistory.close()
if file_history:
file_history.close()


def remove_entry_from_history(del_line_number, history_path=None):
"""Remove entry from history file.
:param int del_line_number: line number of deleted command
:param int del_line_number: line number of the command to be removed
:param str|None history_path: history file path string
"""
fileHistory = None
file_history = None
if not history_path:
history_path = get_current_mapset_gui_history_path()
try:
fileHistory = open(history_path, encoding="utf-8", mode="r+")
lines = fileHistory.readlines()
fileHistory.seek(0)
fileHistory.truncate()
file_history = open(history_path, encoding="utf-8", mode="r+")
lines = file_history.readlines()
file_history.seek(0)
file_history.truncate()
for number, line in enumerate(lines):
if number not in [del_line_number]:
fileHistory.write(line)
file_history.write(line)
except OSError as e:
raise OSError(
_("Unable to delete entry from history file {}").format(history_path)
_("Unable to remove entry from history file {}").format(history_path)
) from e
finally:
if fileHistory:
fileHistory.close()
if file_history:
file_history.close()


def copy_history(target_path, history_path):
Expand Down

0 comments on commit 441d357

Please sign in to comment.