toolbar: use custom MyMenu class with addToggle
This commit is contained in:
@@ -109,9 +109,8 @@ class AddressList(MyTreeView):
|
||||
self.sortByColumn(self.Columns.TYPE, Qt.AscendingOrder)
|
||||
|
||||
def create_toolbar(self, config):
|
||||
toolbar = self.create_toolbar_with_menu('', [
|
||||
(_("&Filter"), lambda: self.toggle_toolbar(self.config)),
|
||||
])
|
||||
toolbar, menu = self.create_toolbar_with_menu('')
|
||||
menu.addToggle(_("Show Filter"), lambda: self.toggle_toolbar(self.config))
|
||||
hbox = self.create_toolbar_buttons()
|
||||
toolbar.insertLayout(1, hbox)
|
||||
return toolbar
|
||||
|
||||
@@ -129,9 +129,8 @@ class ContactList(MyTreeView):
|
||||
return self.get_role_data_from_coordinate(row, col, role=self.ROLE_CONTACT_KEY)
|
||||
|
||||
def create_toolbar(self, config):
|
||||
toolbar = self.create_toolbar_with_menu('', [
|
||||
(_("&New contact"), self.parent.new_contact_dialog),
|
||||
(_("Import"), lambda: self.parent.import_contacts()),
|
||||
(_("Export"), lambda: self.parent.export_contacts()),
|
||||
])
|
||||
toolbar, menu = self.create_toolbar_with_menu('')
|
||||
menu.addAction(_("&New contact"), self.parent.new_contact_dialog)
|
||||
menu.addAction(_("Import"), lambda: self.parent.import_contacts())
|
||||
menu.addAction(_("Export"), lambda: self.parent.export_contacts())
|
||||
return toolbar
|
||||
|
||||
@@ -528,19 +528,15 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
|
||||
self.hide_rows()
|
||||
|
||||
def create_toolbar(self, config):
|
||||
toolbar = self.create_toolbar_with_menu('', [
|
||||
(_("&Filter Period"), lambda: self.toggle_toolbar(self.config)),
|
||||
(_("&Summary"), self.show_summary),
|
||||
(_("&Plot"), self.plot_history_dialog),
|
||||
(_("&Export"), self.export_history_dialog),
|
||||
])
|
||||
toolbar, menu = self.create_toolbar_with_menu('')
|
||||
menu.addToggle(_("&Filter Period"), lambda: self.toggle_toolbar(self.config))
|
||||
menu.addAction(_("&Summary"), self.show_summary)
|
||||
menu.addAction(_("&Plot"), self.plot_history_dialog)
|
||||
menu.addAction(_("&Export"), self.export_history_dialog)
|
||||
hbox = self.create_toolbar_buttons()
|
||||
toolbar.insertLayout(1, hbox)
|
||||
return toolbar
|
||||
|
||||
def toggle_filter(self):
|
||||
pass
|
||||
|
||||
def get_toolbar_buttons(self):
|
||||
return self.period_combo, self.start_button, self.end_button
|
||||
|
||||
|
||||
@@ -1065,6 +1065,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
||||
def do_copy(self, text: str, *, title: str = None) -> None:
|
||||
self.app.clipboard().setText(text)
|
||||
message = _("Text copied to Clipboard") if title is None else _("{} copied to Clipboard").format(title)
|
||||
self.show_tooltip_after_delay(message)
|
||||
|
||||
def show_tooltip_after_delay(self, message):
|
||||
# tooltip cannot be displayed immediately when called from a menu; wait 200ms
|
||||
self.gui_object.timer.singleShot(200, lambda: QToolTip.showText(QCursor.pos(), message, self))
|
||||
|
||||
|
||||
@@ -174,13 +174,10 @@ class ReceiveTab(QWidget, MessageBoxMixin, Logger):
|
||||
self.receive_requests_label.setMaximumWidth(400)
|
||||
from .request_list import RequestList
|
||||
self.request_list = RequestList(self)
|
||||
self.toolbar = self.request_list.create_toolbar_with_menu(
|
||||
'',
|
||||
[
|
||||
(_("Toggle QR code window"), self.window.toggle_qr_window),
|
||||
(_("Import requests"), self.window.import_requests),
|
||||
(_("Export requests"), self.window.export_requests),
|
||||
])
|
||||
self.toolbar, menu = self.request_list.create_toolbar_with_menu('')
|
||||
menu.addToggle(_("Show QR code window"), self.window.toggle_qr_window)
|
||||
menu.addAction(_("Import requests"), self.window.import_requests)
|
||||
menu.addAction(_("Export requests"), self.window.export_requests)
|
||||
|
||||
# layout
|
||||
vbox_g = QVBoxLayout()
|
||||
|
||||
@@ -149,13 +149,10 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
self.invoices_label = QLabel(_('Invoices'))
|
||||
from .invoice_list import InvoiceList
|
||||
self.invoice_list = InvoiceList(self)
|
||||
self.toolbar = self.invoice_list.create_toolbar_with_menu(
|
||||
'',
|
||||
[
|
||||
(_("&Pay to many"), self.paytomany),
|
||||
(_("Import invoices"), self.window.import_invoices),
|
||||
(_("Export invoices"), self.window.export_invoices),
|
||||
])
|
||||
self.toolbar, menu = self.invoice_list.create_toolbar_with_menu('')
|
||||
menu.addToggle(_("&Pay to many"), self.paytomany)
|
||||
menu.addAction(_("Import invoices"), self.window.import_invoices)
|
||||
menu.addAction(_("Export invoices"), self.window.export_invoices)
|
||||
|
||||
vbox0 = QVBoxLayout()
|
||||
vbox0.addLayout(grid)
|
||||
@@ -754,15 +751,17 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
broadcast_thread, broadcast_done, self.window.on_error)
|
||||
|
||||
def paytomany(self):
|
||||
self.window.show_send_tab()
|
||||
if self.payto_e.is_multiline():
|
||||
self.payto_e.do_clear()
|
||||
return
|
||||
self.payto_e.paytomany()
|
||||
msg = '\n'.join([
|
||||
message = '\n'.join([
|
||||
_('Enter a list of outputs in the \'Pay to\' field.'),
|
||||
_('One output per line.'),
|
||||
_('Format: address, amount'),
|
||||
_('You may load a CSV file using the file icon.')
|
||||
])
|
||||
self.show_message(msg, title=_('Pay to many'))
|
||||
self.window.show_tooltip_after_delay(message)
|
||||
|
||||
def payto_contacts(self, labels):
|
||||
paytos = [self.window.get_contact_payto(label) for label in labels]
|
||||
|
||||
@@ -569,6 +569,20 @@ class ElectrumItemDelegate(QStyledItemDelegate):
|
||||
return custom_data.sizeHint(default_size)
|
||||
|
||||
|
||||
class MyMenu(QMenu):
|
||||
|
||||
def __init__(self, config):
|
||||
QMenu.__init__(self)
|
||||
self.setToolTipsVisible(True)
|
||||
self.config = config
|
||||
|
||||
def addToggle(self, text: str, callback, *, tooltip=''):
|
||||
m = self.addAction(text, callback)
|
||||
m.setCheckable(True)
|
||||
m.setToolTip(tooltip)
|
||||
return m
|
||||
|
||||
|
||||
class MyTreeView(QTreeView):
|
||||
ROLE_CLIPBOARD_DATA = Qt.UserRole + 100
|
||||
ROLE_CUSTOM_PAINT = Qt.UserRole + 101
|
||||
@@ -754,11 +768,8 @@ class MyTreeView(QTreeView):
|
||||
self.toolbar_buttons = buttons
|
||||
return hbox
|
||||
|
||||
def create_toolbar_with_menu(self, title, menu_items):
|
||||
menu = QMenu()
|
||||
menu.setToolTipsVisible(True)
|
||||
for k, v in menu_items:
|
||||
menu.addAction(k, v)
|
||||
def create_toolbar_with_menu(self, title):
|
||||
menu = MyMenu(self.config)
|
||||
toolbar_button = QToolButton()
|
||||
toolbar_button.setIcon(read_QIcon("preferences.png"))
|
||||
toolbar_button.setMenu(menu)
|
||||
@@ -768,7 +779,7 @@ class MyTreeView(QTreeView):
|
||||
toolbar.addWidget(QLabel(title))
|
||||
toolbar.addStretch()
|
||||
toolbar.addWidget(toolbar_button)
|
||||
return toolbar
|
||||
return toolbar, menu
|
||||
|
||||
def show_toolbar(self, state, config=None):
|
||||
if state == self.toolbar_shown:
|
||||
|
||||
Reference in New Issue
Block a user