Skip to content

Commit

Permalink
Add diff-between-tabs developer function
Browse files Browse the repository at this point in the history
This is something that never made it from the old UI to the new one,
but it's very handy in some situations.
  • Loading branch information
kk7ds committed Jan 16, 2025
1 parent 5b178d5 commit c338270
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions chirp/wxui/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
CHIRP_DATA_MEMORY = wx.DataFormat('x-chirp/memory-channel')
EditorChanged, EVT_EDITOR_CHANGED = wx.lib.newevent.NewCommandEvent()
StatusMessage, EVT_STATUS_MESSAGE = wx.lib.newevent.NewCommandEvent()
CrossEditorAction, EVT_CROSS_EDITOR_ACTION = wx.lib.newevent.NewCommandEvent()
INDEX_CHAR = settings.BANNED_NAME_CHARACTERS[0]

# This is a lock that can be used to exclude edit-specific operations
Expand Down
11 changes: 10 additions & 1 deletion chirp/wxui/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ def simple_diff(a, b, diffsonly=False):

diff = ""
for i in range(0, len(lines_a)):
if lines_a[i] != lines_b[i]:
try:
line_a = lines_a[i]
except IndexError:
line_a = ''
try:
line_b = lines_b[i]
except IndexError:
line_b = ''
if line_a != line_b:
diff += "-%s%s" % (lines_a[i], os.linesep)
diff += "+%s%s" % (lines_b[i], os.linesep)
blankprinted = False
Expand All @@ -68,6 +76,7 @@ def __init__(self, mem, *a, **k):

self.text = wx.richtext.RichTextCtrl(
self, style=wx.VSCROLL | wx.HSCROLL | wx.NO_BORDER)
self.text.SetEditable(False)
sizer.Add(self.text, 1, wx.EXPAND)

sizer.Add(wx.StaticLine(self), 0)
Expand Down
41 changes: 41 additions & 0 deletions chirp/wxui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ def current_editor(self):
def current_editor_index(self):
return self._editors.GetSelection()

def iter_editors(self, onlycls=None):
for title, editor in self._editor_index.items():
if onlycls is None or isinstance(editor, onlycls):
yield title, editor

def select_editor(self, index=None, name=None):
if index is None and name:
try:
Expand Down Expand Up @@ -461,6 +466,7 @@ def __init__(self, *args, **kwargs):
self._editors.Bind(wx.aui.EVT_AUINOTEBOOK_TAB_RIGHT_DOWN,
self._tab_rclick)
self.Bind(wx.EVT_CLOSE, self._window_close)
self.Bind(common.EVT_CROSS_EDITOR_ACTION, self._editor_cross_action)

self.statusbar = self.CreateStatusBar(2)
self.statusbar.SetStatusWidths([-1, 200])
Expand Down Expand Up @@ -1112,6 +1118,41 @@ def _editor_status(self, event):
# FIXME: Should probably only do this for the current editorset
self.statusbar.SetStatusText(event.message)

def _editor_cross_action(self, event):
tabs = {}
for i in range(self._editors.GetPageCount()):
page = self._editors.GetPage(i)
for title, editor in page.iter_editors(
onlycls=memedit.ChirpMemEdit):
tabs['%s::%s' % (os.path.basename(page.filename), title)] = \
editor

d = wx.Dialog(self, title=_('Choose Diff Target'))
vbox = wx.BoxSizer(wx.VERTICAL)
d.SetSizer(vbox)

label = wx.StaticText(d, label=_('Select a tab and memory to diff'),
style=wx.ALIGN_CENTER_HORIZONTAL)
tab = wx.Choice(d, choices=list(tabs.keys()))
memory = wx.SpinCtrl(d)
memory.SetMin(0)
memory.SetMax(2000)
memory.SetValue(event.memory)
buttons = d.CreateButtonSizer(wx.OK | wx.CANCEL)

vbox.Add(label, proportion=1, flag=wx.EXPAND | wx.ALL, border=10)
vbox.Add(tab, proportion=0, flag=wx.EXPAND | wx.ALL, border=10)
vbox.Add(memory, proportion=0, flag=wx.EXPAND | wx.ALL, border=10)
vbox.Add(buttons, proportion=0, flag=wx.EXPAND)
d.CenterOnParent()
c = d.ShowModal()
if c == wx.ID_OK:
mem_a = event.GetEventObject()._radio.get_raw_memory(event.memory)
editor = tabs[tab.GetStringSelection()]
mem_b = editor._radio.get_raw_memory(memory.GetValue())
with developer.MemoryDialog((mem_a, mem_b), self) as d:
d.ShowModal()

def _editor_close(self, event):
eset = self._editors.GetPage(event.GetSelection())
if self._prompt_to_close_editor(eset):
Expand Down
14 changes: 14 additions & 0 deletions chirp/wxui/memedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,7 @@ def _memory_rclick(self, event):
functools.partial(self._mem_showraw, event.GetRow()),
raw_item)
menu.Append(raw_item)
menu.Enable(raw_item.GetId(), len(selected_rows) == 1)

diff_item = wx.MenuItem(menu, wx.NewId(),
_('Diff Raw Memories'))
Expand All @@ -1909,6 +1910,14 @@ def _memory_rclick(self, event):
menu.Append(diff_item)
menu.Enable(diff_item.GetId(), len(selected_rows) == 2)

diff_across_item = wx.MenuItem(menu, wx.NewId(),
_('Diff against another editor'))
self.Bind(wx.EVT_MENU,
functools.partial(self._mem_diff_across, event.GetRow()),
diff_across_item)
menu.Append(diff_across_item)
menu.Enable(diff_across_item.GetId(), len(selected_rows) == 1)

self.PopupMenu(menu)
menu.Destroy()

Expand Down Expand Up @@ -1973,6 +1982,11 @@ def _mem_diff(self, rows, event):
with developer.MemoryDialog((mem_a, mem_b), self) as d:
d.ShowModal()

def _mem_diff_across(self, row, event):
evt = common.CrossEditorAction(self.GetId(), memory=self.row2mem(row))
evt.SetEventObject(self)
wx.PostEvent(self, evt)

def update_font(self, refresh=True):
fixed = CONF.get_bool('font_fixed', 'state', False)
large = CONF.get_bool('font_large', 'state', False)
Expand Down

0 comments on commit c338270

Please sign in to comment.