beremiz

Code cleaning and refactoring without side effect.

15 months ago, Edouard Tisserant
f54c32474825
Parents 387bd44f6dd1
Children 97eac383d9af
Code cleaning and refactoring without side effect.
--- a/controls/IDBrowser.py Mon Mar 10 14:45:59 2025 +0100
+++ b/controls/IDBrowser.py Mon Mar 10 14:50:20 2025 +0100
@@ -4,12 +4,11 @@
# See COPYING file for copyrights details.
-from operator import eq
import wx
import wx.dataview as dv
import PSKManagement as PSK
from PSKManagement import *
-from dialogs.IDMergeDialog import IDMergeDialog
+from dialogs.MsgConfirmDialog import MsgConfirmDialog
class IDBrowserModel(dv.DataViewIndexListModel):
@@ -38,16 +37,6 @@
def GetCount(self):
return len(self.data)
- def Compare(self, item1, item2, col, ascending):
- if not ascending: # swap sort order?
- item2, item1 = item1, item2
- row1 = self.GetRow(item1)
- row2 = self.GetRow(item2)
- if col == 0:
- return eq(int(self.data[row1][col]), int(self.data[row2][col]))
- else:
- return eq(self.data[row1][col], self.data[row2][col])
-
def DeleteRows(self, rows):
rows = list(rows)
rows.sort(reverse=True)
@@ -185,7 +174,7 @@
def ShouldIReplaceCallback(self, existing, replacement):
ID, URI, DESC, LAST = existing
_ID, _URI, _DESC, _LAST = replacement
- dlg = IDMergeDialog(
+ dlg = MsgConfirmDialog(
self,
_("Import IDs"),
(_("Replace information for ID {ID} ?") + "\n\n" +
--- a/dialogs/IDMergeDialog.py Mon Mar 10 14:45:59 2025 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-# See COPYING file for copyrights details.
-
-
-import wx
-
-
-# class RichMessageDialog is still not available in wxPython 3.0.2
-class IDMergeDialog(wx.Dialog):
- def __init__(self, parent, title, question, optiontext, button_texts):
- wx.Dialog.__init__(self, parent, title=title)
-
- main_sizer = wx.BoxSizer(wx.VERTICAL)
-
- message = wx.StaticText(self, label=question)
- main_sizer.Add(message, border=20,
- flag=wx.ALIGN_CENTER_HORIZONTAL | wx.TOP | wx.LEFT | wx.RIGHT)
-
- self.check = wx.CheckBox(self, label=optiontext)
- main_sizer.Add(self.check, border=20,
- flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.ALIGN_CENTER_HORIZONTAL)
-
- buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
- for label, wxID in zip(button_texts, [wx.ID_YES, wx.ID_NO, wx.ID_CANCEL]):
- Button = wx.Button(self, label=label)
-
- def OnButtonFactory(_wxID):
- return lambda event: self.EndModal(_wxID)
-
- self.Bind(wx.EVT_BUTTON, OnButtonFactory(wxID), Button)
- buttons_sizer.Add(Button)
-
- main_sizer.Add(buttons_sizer, border=20,
- flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.ALIGN_RIGHT)
-
- self.SetSizer(main_sizer)
- self.Fit()
-
- self.Bind(wx.EVT_CHAR_HOOK, self.OnEscapeKey)
-
- def OnEscapeKey(self, event):
- keycode = event.GetKeyCode()
- if keycode == wx.WXK_ESCAPE:
- self.EndModal(wx.ID_CANCEL)
- else:
- event.Skip()
-
- def OptionChecked(self):
- return self.check.GetValue()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dialogs/MsgConfirmDialog.py Mon Mar 10 14:50:20 2025 +0100
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# See COPYING file for copyrights details.
+
+
+import wx
+
+
+# class RichMessageDialog is still not available in wxPython 3.0.2
+class MsgConfirmDialog(wx.Dialog):
+ def __init__(self, parent, title, question, optiontext, button_texts):
+ wx.Dialog.__init__(self, parent, title=title)
+
+ main_sizer = wx.BoxSizer(wx.VERTICAL)
+
+ message = wx.StaticText(self, label=question)
+ main_sizer.Add(message, border=20,
+ flag=wx.ALIGN_CENTER_HORIZONTAL | wx.TOP | wx.LEFT | wx.RIGHT)
+
+ if optiontext:
+ self.check = wx.CheckBox(self, label=optiontext)
+ main_sizer.Add(self.check, border=20,
+ flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.ALIGN_CENTER_HORIZONTAL)
+ else:
+ self.check = None
+
+ buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
+ for label, wxID in zip(button_texts, [wx.ID_YES, wx.ID_NO, wx.ID_CANCEL]):
+ Button = wx.Button(self, label=label)
+
+ def OnButtonFactory(_wxID):
+ return lambda event: self.EndModal(_wxID)
+
+ self.Bind(wx.EVT_BUTTON, OnButtonFactory(wxID), Button)
+ buttons_sizer.Add(Button)
+
+ main_sizer.Add(buttons_sizer, border=20,
+ flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.ALIGN_RIGHT)
+
+ self.SetSizer(main_sizer)
+ self.Fit()
+
+ self.Bind(wx.EVT_CHAR_HOOK, self.OnEscapeKey)
+
+ def OnEscapeKey(self, event):
+ keycode = event.GetKeyCode()
+ if keycode == wx.WXK_ESCAPE:
+ self.EndModal(wx.ID_CANCEL)
+ else:
+ event.Skip()
+
+ def OptionChecked(self):
+ if self.check:
+ return self.check.GetValue()