Skip to content

Commit

Permalink
Fix #463 Add the right click on account name in account list menu to …
Browse files Browse the repository at this point in the history
…the window menu as well under 'Account'.
  • Loading branch information
rt121212121 committed Aug 14, 2020
1 parent 733aaf0 commit 0429ce0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
26 changes: 16 additions & 10 deletions electrumsv/gui/qt/accounts_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,18 @@ def _show_account_menu(self, position) -> None:
account = self._wallet.get_account(account_id)

menu = QMenu()
self.add_menu_items(menu, account, self._main_window.reference())
menu.exec_(self._selection_list.viewport().mapToGlobal(position))

def add_menu_items(self, menu: QMenu, account: AbstractAccount, main_window: ElectrumWindow) \
-> None:
# This expects a reference to the main window, not the weakref.
account_id = account.get_id()

menu.addAction(_("&Information"),
partial(self._show_account_information, account_id))
seed_menu = menu.addAction(_("View &Secured Data"),
partial(self._view_secured_data, main_window=self._main_window, account_id=account_id))
partial(self._view_secured_data, main_window=main_window, account_id=account_id))
seed_menu.setEnabled(
not account.is_watching_only() and not isinstance(account, MultisigAccount) \
and not account.is_hardware_wallet() \
Expand All @@ -188,10 +196,10 @@ def _show_account_menu(self, position) -> None:

private_keys_menu = menu.addMenu(_("&Private keys"))
import_menu = private_keys_menu.addAction(_("&Import"), partial(self._import_privkey,
main_window=self._main_window, account_id=account_id))
main_window=main_window, account_id=account_id))
import_menu.setEnabled(account.can_import_privkey())
export_menu = private_keys_menu.addAction(_("&Export"), partial(self._export_privkeys,
main_window=self._main_window, account_id=account_id))
main_window=main_window, account_id=account_id))
export_menu.setEnabled(account.can_export())
if account.can_import_address():
menu.addAction(_("Import addresses"), partial(self._import_addresses, account_id))
Expand All @@ -200,8 +208,8 @@ def _show_account_menu(self, position) -> None:

labels_menu = menu.addMenu(_("&Labels"))
action = labels_menu.addAction(_("&Import"),
partial(self._main_window.do_import_labels, account_id))
labels_menu.addAction(_("&Export"), partial(self._main_window.do_export_labels, account_id))
partial(main_window.do_import_labels, account_id))
labels_menu.addAction(_("&Export"), partial(main_window.do_export_labels, account_id))

invoices_menu = menu.addMenu(_("Invoices"))
invoices_menu.addAction(_("Import"), partial(self._on_menu_import_invoices, account_id))
Expand All @@ -213,8 +221,6 @@ def _show_account_menu(self, position) -> None:
ed_action.setEnabled(keystore is not None and
keystore.type() != KeystoreType.IMPORTED_PRIVATE_KEY)

menu.exec_(self._selection_list.viewport().mapToGlobal(position))

def _on_menu_import_invoices(self, account_id: int) -> None:
send_view = self._main_window.get_send_view(account_id)
send_view.import_invoices()
Expand Down Expand Up @@ -312,7 +318,7 @@ def _export_privkeys(self, main_window: ElectrumWindow, account_id: int=-1,

defaultname = 'electrumsv-private-keys.csv'
select_msg = _('Select file to export your private keys to')
hbox, filename_e, csv_button = filename_field(self._main_window.config, defaultname,
hbox, filename_e, csv_button = filename_field(main_window.config, defaultname,
select_msg)
vbox.addLayout(hbox)

Expand Down Expand Up @@ -378,10 +384,10 @@ def on_dialog_closed(*args):
])
MessageBox.show_error(txt, title=_("Unable to create csv"))
except Exception as e:
MessageBox.show_message(str(e), self._main_window)
MessageBox.show_message(str(e), main_window)
return

MessageBox.show_message(_('Private keys exported'), self._main_window)
MessageBox.show_message(_('Private keys exported'), main_window)

def _do_export_privkeys(self, fileName: str, pklist, is_csv):
with open(fileName, "w+") as f:
Expand Down
11 changes: 9 additions & 2 deletions electrumsv/gui/qt/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,14 +620,21 @@ def init_menubar(self) -> None:
self.password_menu = wallet_menu.addAction(_("&Password"), self.change_password_dialog)
wallet_menu.addSeparator()

contacts_menu = wallet_menu.addMenu(_("Contacts"))
contacts_menu.addAction(_("&New"), partial(edit_contact_dialog, self._api))
# NOTE(rt12): Contacts menu is disabled as tab is disabled.
if False:
contacts_menu = wallet_menu.addMenu(_("Contacts"))
contacts_menu.addAction(_("&New"), partial(edit_contact_dialog, self._api))

hist_menu = wallet_menu.addMenu(_("&History"))
hist_menu.addAction("Export", self.export_history_dialog)

wallet_menu.addSeparator()
wallet_menu.addAction(_("Find"), self._toggle_search).setShortcut(QKeySequence("Ctrl+F"))

if self._account_id is not None:
account_menu = menubar.addMenu(_("&Account"))
self._accounts_view.add_menu_items(account_menu, self._account, self)

# Make sure the lambda reference does not prevent garbage collection.
weakself = weakref.proxy(self)
def add_toggle_action(view_menu, tab) -> None:
Expand Down

0 comments on commit 0429ce0

Please sign in to comment.