Skip to content

Commit

Permalink
wxGUI/console: Adding hint to command prompt (#2728)
Browse files Browse the repository at this point in the history
  • Loading branch information
lindakarlovska committed Jan 10, 2023
1 parent 83da642 commit d657c9a
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion gui/wxpython/gui_core/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ def __init__(self, parent, giface, menuModel, margin=False):
self.SetSelBackground(True, selection_color)
self.StyleClearAll()

# show hint
self._showHint()

#
# bindings
#
Expand All @@ -228,6 +231,7 @@ def __init__(self, parent, giface, menuModel, margin=False):
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemChanged)
if sys.platform != "darwin": # unstable on Mac with wxPython 3
self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)

# signal which requests showing of a notification
self.showNotification = Signal("GPromptSTC.showNotification")
Expand Down Expand Up @@ -322,11 +326,34 @@ def OnItemSelected(self, event):
except IOError:
self.cmdDesc = None

def _showHint(self):
"""Shows usability hint"""
self.StyleSetForeground(0, wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
self.WriteText(_("Type command here and press Enter"))
self._hint_shown = True

def _hideHint(self):
"""Hides usability hint"""
if self._hint_shown:
self.ClearAll()
self.StyleSetForeground(
0, wx.SystemSettings().GetColour(wx.SYS_COLOUR_WINDOWTEXT)
)
self._hint_shown = False

def OnKillFocus(self, event):
"""Hides autocomplete"""
"""Hides autocomplete and shows hint"""
# hide autocomplete
if self.AutoCompActive():
self.AutoCompCancel()
# show hint
if self.IsEmpty():
self._showHint()
event.Skip()

def OnSetFocus(self, event):
"""Prepares prompt for entering commands."""
self._hideHint()
event.Skip()

def SetTextAndFocus(self, text):
Expand Down

0 comments on commit d657c9a

Please sign in to comment.