Skip to content

Commit

Permalink
wxGUI/history: Move Export History button to history pane (#3402)
Browse files Browse the repository at this point in the history
Export History button moved from the Console pane to the bottom of the History pane

---------

Co-authored-by: lindakladivova <l.kladivova@seznam.cz>
  • Loading branch information
lindakarlovska and lindakladivova committed Feb 7, 2024
1 parent ae869f5 commit d85d987
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 45 deletions.
45 changes: 1 addition & 44 deletions gui/wxpython/gui_core/goutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from grass.grassdb.history import (
read_history,
create_history_file,
copy_history,
get_current_mapset_gui_history_path,
)

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
52 changes: 51 additions & 1 deletion gui/wxpython/history/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"))
Expand All @@ -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()

0 comments on commit d85d987

Please sign in to comment.