Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix delete accel and stock config improvements #687

Merged
merged 5 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
263 changes: 135 additions & 128 deletions chirp/locale/de.po

Large diffs are not rendered by default.

260 changes: 135 additions & 125 deletions chirp/locale/el.po

Large diffs are not rendered by default.

259 changes: 134 additions & 125 deletions chirp/locale/en_US.po

Large diffs are not rendered by default.

264 changes: 135 additions & 129 deletions chirp/locale/es.po

Large diffs are not rendered by default.

263 changes: 135 additions & 128 deletions chirp/locale/fr.po

Large diffs are not rendered by default.

263 changes: 135 additions & 128 deletions chirp/locale/hu.po

Large diffs are not rendered by default.

263 changes: 135 additions & 128 deletions chirp/locale/it.po

Large diffs are not rendered by default.

263 changes: 135 additions & 128 deletions chirp/locale/nl.po

Large diffs are not rendered by default.

259 changes: 134 additions & 125 deletions chirp/locale/pl.po

Large diffs are not rendered by default.

263 changes: 135 additions & 128 deletions chirp/locale/pt_BR.po

Large diffs are not rendered by default.

263 changes: 135 additions & 128 deletions chirp/locale/ru.po

Large diffs are not rendered by default.

260 changes: 135 additions & 125 deletions chirp/locale/tr_TR.po

Large diffs are not rendered by default.

263 changes: 135 additions & 128 deletions chirp/locale/uk_UA.po

Large diffs are not rendered by default.

264 changes: 135 additions & 129 deletions chirp/locale/zh_CN.po

Large diffs are not rendered by default.

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)
71 changes: 52 additions & 19 deletions chirp/wxui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
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():
default_dir = chirp_platform.get_platform().config_file(
"stock_configs")
prefs_dir = CONF.get('stock_configs', 'prefs')
return prefs_dir or default_dir


class ChirpDropTarget(wx.DropTarget):
Expand Down Expand Up @@ -566,14 +574,14 @@ def add_stock_menu(self):
stock = wx.Menu()

try:
user_stock_dir = chirp_platform.get_platform().config_file(
"stock_configs")
user_stock_dir = get_stock_configs()
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
(conf.name, hashlib.md5(conf.read_bytes())) for conf
in importlib_resources.files('chirp.stock_configs').iterdir()
if conf.is_file()
]
Expand All @@ -591,12 +599,38 @@ def add_stock(fn):

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)
else:
LOG.info('Ignoring dist stock conf %s because same name found '
'in user dir', os.path.basename(fn))
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, hash in dist_stock_confs:
if os.path.basename(fn) in found:
# Remove old stock configs that were copied to the user's
# directory by legacy chirp.
try:
user_fn = os.path.join(get_stock_configs(),
os.path.basename(fn))
with open(user_fn, 'rb') as f:
user_hash = hashlib.md5(f.read())
if hash.digest() == user_hash.digest():
LOG.info('Removing stale legacy stock config %s',
os.path.basename(fn))
os.remove(user_fn)
# Since we already added it to the user area, just
# don't add it to system this time. At next startup,
# it will move to the system section.
continue
else:
raise FileExistsError('File is changed')
except Exception as e:
LOG.info('Ignoring dist stock conf %s because same name '
'found in user dir: %s',
os.path.basename(fn), e)
continue
add_stock(fn)

return stock

Expand Down Expand Up @@ -716,6 +750,7 @@ def make_menubar(self):
self.Bind(wx.EVT_MENU, self._menu_selall, selall_item)

delete_item = edit_menu.Append(wx.ID_DELETE)
delete_item.SetAccel(wx.AcceleratorEntry(wx.MOD_CONTROL, wx.WXK_BACK))
self.Bind(wx.EVT_MENU, self._menu_delete, delete_item)

edit_menu.Append(wx.MenuItem(edit_menu, wx.ID_SEPARATOR))
Expand Down Expand Up @@ -952,7 +987,7 @@ def adj_menu_open_recent(self, filename):
return

# Don't add stock config files to the recent files list
stock_dir = chirp_platform.get_platform().config_file("stock_configs")
stock_dir = get_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)):
Expand Down Expand Up @@ -1172,12 +1207,16 @@ 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()

user_stock_dir = chirp_platform.get_platform().config_file(
"stock_configs")
user_stock_dir = get_stock_configs()
user_stock_conf = os.path.join(user_stock_dir, fn)
with importlib_resources.as_file(
importlib_resources.files('chirp.stock_configs')
Expand Down Expand Up @@ -1602,13 +1641,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
Loading