Skip to content

Commit

Permalink
Add menu option to open stock configs directory
Browse files Browse the repository at this point in the history
This makes it easier to find the directory, since it is hiddenish
on all platforms, and can now be overridden.

Related to #10688
  • Loading branch information
kk7ds committed Jun 28, 2023
1 parent 110e33c commit a6b3e2d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
14 changes: 14 additions & 0 deletions chirp/wxui/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import functools
import logging
import os
import platform
import threading

import wx
Expand Down Expand Up @@ -555,3 +557,15 @@ def __exit__(self, exc_type, exc_val, traceback):
LOG.exception('Context raised unexpected_exception',
exc_info=(exc_type, exc_val, traceback))
self.show_error(exc_val)


def reveal_location(path):
if not os.path.isdir(path):
raise FileNotFoundError(_('Path %s does not exist') % path)
system = platform.system()
if system == 'Windows':
wx.Execute('explorer /select, %s' % path)
elif system == 'Darwin':
wx.Execute('open -R %s' % path)
else:
raise Exception(_('Unable to reveal %s on this system') % path)
22 changes: 15 additions & 7 deletions chirp/wxui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
OPEN_STOCK_CONFIG_MENU = None
CHIRP_TAB_DF = wx.DataFormat('x-chirp/file-tab')
ALL_MAIN_WINDOWS = []
REVEAL_STOCK_DIR = wx.NewId()


def get_stock_configs():
Expand Down Expand Up @@ -577,6 +578,7 @@ def add_stock_menu(self):
user_stock_confs = sorted(os.listdir(user_stock_dir))
except FileNotFoundError:
user_stock_confs = []
os.makedirs(user_stock_dir, exist_ok=True)
dist_stock_confs = sorted(
[
conf.name for conf
Expand All @@ -597,6 +599,13 @@ def add_stock(fn):

stock.Append(wx.MenuItem(stock, wx.ID_SEPARATOR))

if sys.platform in ('darwin', 'win32'):
reveal = stock.Append(REVEAL_STOCK_DIR,
_('Open stock config directory'))
self.Bind(wx.EVT_MENU, self._menu_open_stock_config, reveal)

stock.Append(wx.MenuItem(stock, wx.ID_SEPARATOR))

for fn in dist_stock_confs:
if os.path.basename(fn) not in found:
add_stock(fn)
Expand Down Expand Up @@ -1179,7 +1188,12 @@ def _menu_open(self, event):
if filename is not None:
self.open_file(filename)

@common.error_proof(FileNotFoundError)
def _menu_open_stock_config(self, event):
if event.GetId() == REVEAL_STOCK_DIR:
common.reveal_location(get_stock_configs())
return

fn = self.OPEN_STOCK_CONFIG_MENU.FindItemById(
event.GetId()).GetItemLabelText()

Expand Down Expand Up @@ -1608,13 +1622,7 @@ def _menu_debug_loc(self, event):
prefix='chirp_debug-',
suffix='.txt').name
shutil.copy(src, dst)
system = platform.system()
if system == 'Windows':
wx.Execute('explorer /select, %s' % dst)
elif system == 'Darwin':
wx.Execute('open -R %s' % dst)
else:
raise Exception(_('Unable to reveal %s on this system') % dst)
common.reveal_location(dst)

@common.error_proof()
def _menu_load_from_issue(self, event):
Expand Down

0 comments on commit a6b3e2d

Please sign in to comment.