[chirp_devel] [PATCH] [wxui] Add "Open Stock Config" submenu to "File" menu #9403
Joseph.P.Scanlan at n7xsd.us
Wed Sep 29 13:06:30 PDT 2021
# HG changeset patch
# User <Joseph.P.Scanlan at n7xsd.us>
# Date 1632944620 25200
# Wed Sep 29 12:43:40 2021 -0700
# Branch py3
# Node ID 065286ef952577c1e629c745b58a0d3798dbee4b
# Parent 9fb5b8995942e5d2d19090967aa2d591c37eb796
[wxui] Add "Open Stock Config" submenu to "File" menu #9403
The "Open Stock Config" submenu lists the CSV files in
~/.chirp/stock_configs. Selecting a file opens it.
This patch does not create the stock_configs directory or
any files in it.
Stock configs are not added to the "Open Recent"
submenu when opened.
diff -r 9fb5b8995942 -r 065286ef9525 chirp/wxui/main.py
--- a/chirp/wxui/main.py Sun Sep 26 16:30:23 2021 -0700
+++ b/chirp/wxui/main.py Wed Sep 29 12:43:40 2021 -0700
@@ -18,6 +18,8 @@
from chirp.wxui import settingsedit
from chirp import CHIRP_VERSION
+from fnmatch import fnmatch
+
EditorSetChanged, EVT_EDITORSET_CHANGED = wx.lib.newevent.NewCommandEvent()
CONF = config.get()
LOG = logging.getLogger(__name__)
@@ -25,6 +27,7 @@
EMPTY_MENU_LABEL = '(none)'
KEEP_RECENT = 8
OPEN_RECENT_MENU = None
+OPEN_STOCK_CONFIG_MENU = None
class ChirpEditorSet(wx.Panel):
def __init__(self, radio, filename, *a, **k):
@@ -194,6 +197,24 @@
open_item = file_menu.Append(wx.ID_OPEN)
self.Bind(wx.EVT_MENU, self._menu_open, open_item)
+ stock_dir = platform.get_platform().config_file("stock_configs")
+ sconfigs = []
+ if os.path.isdir(stock_dir):
+ for fn in os.listdir(stock_dir):
+ if fnmatch(fn, "*.csv"):
+ config, ext = os.path.splitext(fn)
+ sconfigs.append(config)
+ sconfigs.sort()
+ if len(sconfigs):
+ self.OPEN_STOCK_CONFIG_MENU = wx.Menu()
+ for fn in sconfigs:
+ submenu_item = self.OPEN_STOCK_CONFIG_MENU.Append(
+ wx.ID_ANY, fn)
+ self.Bind(wx.EVT_MENU,
+ self._menu_open_stock_config, submenu_item)
+ file_menu.AppendSubMenu(self.OPEN_STOCK_CONFIG_MENU,
+ "Open Stock Config")
+
self.OPEN_RECENT_MENU = wx.Menu()
i = 0
fn = CONF.get("recent%i" % i, "state")
@@ -326,6 +347,13 @@
tb.Realize()
def adj_menu_open_recent(self, filename):
+ ### Don't add stock config files to the recent files list
+ stock_dir = platform.get_platform().config_file("stock_configs")
+ this_dir = os.path.dirname(filename)
+ if (stock_dir and os.path.exists(stock_dir) and
+ this_dir and os.path.samefile(stock_dir, this_dir)):
+ return
+
### Travel the Open Recent menu looking for filename
found_mi = None
empty_mi = None
@@ -451,6 +479,13 @@
config._CONFIG.save()
self.open_file(str(filename))
+ def _menu_open_stock_config(self, event):
+ stock_dir = platform.get_platform().config_file("stock_configs")
+ fn = self.OPEN_STOCK_CONFIG_MENU.FindItemById(event.GetId()).GetLabel()
+ fn += ".csv"
+ filename = os.path.join(stock_dir, fn)
+ self.open_file(filename)
+
def _menu_open_recent(self, event):
filename = self.OPEN_RECENT_MENU.FindItemById(event.GetId()).GetLabel()
self.open_file(filename)
More information about the chirp_devel
mailing list