Skip to content

Commit

Permalink
gtk: Work around wxGTK Ctrl-C bug
Browse files Browse the repository at this point in the history
It seems wxGTK is broken in that wxGrid implements Ctrl-C behavior
itself and only on GTK does that take precedence over the application
menubar:

wxWidgets/wxWidgets#22625 (comment)

This implements the recommended workaround, whereby memedit catches
that EVT_KEY_DOWN event and directs it as appropriate to the memedit
copy handler.

Fixes #10934
  • Loading branch information
kk7ds committed Nov 7, 2023
1 parent ad73f0b commit f8fa755
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion chirp/wxui/memedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

LOG = logging.getLogger(__name__)
CONF = config.get()
WX_GTK = 'gtk' in wx.version().lower()


class ChirpMemoryGrid(wx.grid.Grid, glr.GridWithLabelRenderersMixin):
Expand Down Expand Up @@ -676,6 +677,8 @@ def __init__(self, radio, *a, **k):
self._grid.Bind(wx.grid.EVT_GRID_LABEL_RIGHT_CLICK,
self._memory_rclick)
self._grid.Bind(wx.grid.EVT_GRID_CELL_BEGIN_DRAG, self._memory_drag)
if WX_GTK:
self._grid.Bind(wx.EVT_KEY_DOWN, self._gtk_short_circuit_edit_copy)
row_labels = self._grid.GetGridRowLabelWindow()
row_labels.Bind(wx.EVT_LEFT_DOWN, self._row_click)
row_labels.Bind(wx.EVT_LEFT_UP, self._row_click)
Expand All @@ -685,6 +688,19 @@ def __init__(self, radio, *a, **k):
self._dc = wx.ScreenDC()
self.set_cell_attrs()

def _gtk_short_circuit_edit_copy(self, event):
# wxGTK is broken and does not direct Ctrl-C to the menu items
# because wx.grid.Grid() tries to implement something for it,
# which we don't want. The wxWidgets people say the only way is to
# grab it ourselves and direct it appropriately before wx.grid.Grid()
# can do it.
# https://github.com/wxWidgets/wxWidgets/issues/22625
if (event.GetKeyCode() == ord('C') and
event.GetModifiers() == wx.MOD_CONTROL):
self.cb_copy(cut=False)
else:
event.Skip()

def _row_click(self, event):
# In order to override the drag-to-multi-select behavior of the base
# grid, we need to basically reimplement what happens when a user
Expand Down Expand Up @@ -765,7 +781,7 @@ def comment_col(self):
return self._col_defs.index(self._col_def_by_name('comment'))

def set_cell_attrs(self):
if platform.system() == 'Linux':
if platform.system() == WX_GTK:
minwidth = 100
else:
minwidth = 75
Expand Down

0 comments on commit f8fa755

Please sign in to comment.