From d85d9877786ee90bae17afa6c99e73087eea6165 Mon Sep 17 00:00:00 2001 From: Linda Karlovska <49241681+lindakladivova@users.noreply.github.com> Date: Wed, 7 Feb 2024 09:58:48 +0100 Subject: [PATCH] wxGUI/history: Move Export History button to history pane (#3402) Export History button moved from the Console pane to the bottom of the History pane --------- Co-authored-by: lindakladivova --- gui/wxpython/gui_core/goutput.py | 45 +-------------------------- gui/wxpython/history/browser.py | 52 +++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 45 deletions(-) diff --git a/gui/wxpython/gui_core/goutput.py b/gui/wxpython/gui_core/goutput.py index 65a8cfd98ad..bb68f13cc22 100644 --- a/gui/wxpython/gui_core/goutput.py +++ b/gui/wxpython/gui_core/goutput.py @@ -29,7 +29,6 @@ from grass.grassdb.history import ( read_history, create_history_file, - copy_history, get_current_mapset_gui_history_path, ) @@ -164,19 +163,10 @@ def __init__( self.btnOutputSave.SetToolTip(_("Save output to a file")) self.btnCmdAbort = Button(parent=self.panelProgress, id=wx.ID_STOP) self.btnCmdAbort.SetToolTip(_("Abort running command")) - self.btnCmdExportHistory = Button(parent=self.panelPrompt, id=wx.ID_ANY) - self.btnCmdExportHistory.SetLabel(_("&Export history")) - self.btnCmdExportHistory.SetToolTip( - _("Export history of executed commands to a file") - ) - - if not self._gcstyle & GC_PROMPT: - self.btnCmdExportHistory.Hide() self.btnClear.Bind(wx.EVT_BUTTON, self.OnClear) self.btnOutputSave.Bind(wx.EVT_BUTTON, self.OnOutputSave) self.btnCmdAbort.Bind(wx.EVT_BUTTON, self._gconsole.OnCmdAbort) - self.btnCmdExportHistory.Bind(wx.EVT_BUTTON, self.OnCmdExportHistory) self._layout() @@ -204,19 +194,13 @@ def _layout(self): promptSizer.Add(helpText, proportion=0, flag=wx.EXPAND | wx.LEFT, border=5) btnSizer = wx.BoxSizer(wx.HORIZONTAL) + btnSizer.AddStretchSpacer() btnSizer.Add( self.btnOutputSave, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5, ) - btnSizer.Add( - self.btnCmdExportHistory, - proportion=0, - flag=wx.EXPAND | wx.LEFT | wx.RIGHT, - border=5, - ) - btnSizer.AddStretchSpacer() btnSizer.Add(self.btnClear, proportion=0, flag=wx.EXPAND, border=5) promptSizer.Add(btnSizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5) @@ -449,33 +433,6 @@ def OnCmdProgress(self, event): self.progressbar.SetValue(event.value) event.Skip() - def OnCmdExportHistory(self, event): - """Export the history of executed commands stored - in a .wxgui_history file to a selected file.""" - dlg = wx.FileDialog( - self, - message=_("Save file as..."), - defaultFile="grass_cmd_log.txt", - wildcard=_("{txt} (*.txt)|*.txt|{files} (*)|*").format( - txt=_("Text files"), files=_("Files") - ), - style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT, - ) - - if dlg.ShowModal() == wx.ID_OK: - path = dlg.GetPath() - history_path = get_current_mapset_gui_history_path() - try: - copy_history(path, history_path) - self.showNotification.emit( - message=_("Command history saved to '{}'".format(path)) - ) - except OSError as e: - GError(str(e)) - - dlg.Destroy() - event.Skip() - def OnCmdRun(self, event): """Run command""" self.outputSizer.Show(self.panelProgress) diff --git a/gui/wxpython/history/browser.py b/gui/wxpython/history/browser.py index 4a94aa9b1c5..b485ca2b092 100644 --- a/gui/wxpython/history/browser.py +++ b/gui/wxpython/history/browser.py @@ -19,10 +19,16 @@ import wx -from gui_core.wrap import SearchCtrl +from gui_core.wrap import SearchCtrl, Button from history.tree import HistoryBrowserTree from grass.pydispatch.signal import Signal +from grass.grassdb.history import ( + copy_history, + get_current_mapset_gui_history_path, +) + +from core.gcmd import GError class HistoryBrowser(wx.Panel): @@ -57,6 +63,14 @@ def __init__( self.search.Bind(wx.EVT_TEXT, lambda evt: self.tree.Filter(evt.GetString())) self.search.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, lambda evt: self.tree.Filter("")) + # buttons + self.btnCmdExportHistory = Button(parent=self, id=wx.ID_ANY) + self.btnCmdExportHistory.SetLabel(_("&Export history")) + self.btnCmdExportHistory.SetToolTip( + _("Export history of executed commands to a file") + ) + self.btnCmdExportHistory.Bind(wx.EVT_BUTTON, self.OnCmdExportHistory) + # tree with layers self.tree = HistoryBrowserTree(self, giface=giface) self.tree.SetToolTip(_("Double-click to run selected tool")) @@ -74,10 +88,46 @@ def _layout(self): flag=wx.ALL | wx.EXPAND, border=5, ) + btnSizer = wx.BoxSizer(wx.HORIZONTAL) + btnSizer.AddStretchSpacer() + btnSizer.Add( + self.btnCmdExportHistory, + proportion=0, + flag=wx.EXPAND | wx.LEFT | wx.RIGHT, + border=5, + ) sizer.Add( self.tree, proportion=1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5 ) + sizer.Add(btnSizer, proportion=0, flag=wx.EXPAND | wx.ALL, border=5) self.SetSizerAndFit(sizer) self.SetAutoLayout(True) self.Layout() + + def OnCmdExportHistory(self, event): + """Export the history of executed commands stored + in a .wxgui_history file to a selected file.""" + dlg = wx.FileDialog( + self, + message=_("Save file as..."), + defaultFile="grass_cmd_log.txt", + wildcard=_("{txt} (*.txt)|*.txt|{files} (*)|*").format( + txt=_("Text files"), files=_("Files") + ), + style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT, + ) + + if dlg.ShowModal() == wx.ID_OK: + path = dlg.GetPath() + history_path = get_current_mapset_gui_history_path() + try: + copy_history(path, history_path) + self.showNotification.emit( + message=_("Command history saved to '{}'".format(path)) + ) + except OSError as e: + GError(str(e)) + + dlg.Destroy() + event.Skip()