Browse Source

toolbar: use custom MyMenu class with addToggle

master
ThomasV 3 years ago
parent
commit
473c86c395
  1. 5
      electrum/gui/qt/address_list.py
  2. 9
      electrum/gui/qt/contact_list.py
  3. 14
      electrum/gui/qt/history_list.py
  4. 3
      electrum/gui/qt/main_window.py
  5. 11
      electrum/gui/qt/receive_tab.py
  6. 19
      electrum/gui/qt/send_tab.py
  7. 23
      electrum/gui/qt/util.py

5
electrum/gui/qt/address_list.py

@ -109,9 +109,8 @@ class AddressList(MyTreeView):
self.sortByColumn(self.Columns.TYPE, Qt.AscendingOrder) self.sortByColumn(self.Columns.TYPE, Qt.AscendingOrder)
def create_toolbar(self, config): def create_toolbar(self, config):
toolbar = self.create_toolbar_with_menu('', [ toolbar, menu = self.create_toolbar_with_menu('')
(_("&Filter"), lambda: self.toggle_toolbar(self.config)), menu.addToggle(_("Show Filter"), lambda: self.toggle_toolbar(self.config))
])
hbox = self.create_toolbar_buttons() hbox = self.create_toolbar_buttons()
toolbar.insertLayout(1, hbox) toolbar.insertLayout(1, hbox)
return toolbar return toolbar

9
electrum/gui/qt/contact_list.py

@ -129,9 +129,8 @@ class ContactList(MyTreeView):
return self.get_role_data_from_coordinate(row, col, role=self.ROLE_CONTACT_KEY) return self.get_role_data_from_coordinate(row, col, role=self.ROLE_CONTACT_KEY)
def create_toolbar(self, config): def create_toolbar(self, config):
toolbar = self.create_toolbar_with_menu('', [ toolbar, menu = self.create_toolbar_with_menu('')
(_("&New contact"), self.parent.new_contact_dialog), menu.addAction(_("&New contact"), self.parent.new_contact_dialog)
(_("Import"), lambda: self.parent.import_contacts()), menu.addAction(_("Import"), lambda: self.parent.import_contacts())
(_("Export"), lambda: self.parent.export_contacts()), menu.addAction(_("Export"), lambda: self.parent.export_contacts())
])
return toolbar return toolbar

14
electrum/gui/qt/history_list.py

@ -528,19 +528,15 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
self.hide_rows() self.hide_rows()
def create_toolbar(self, config): def create_toolbar(self, config):
toolbar = self.create_toolbar_with_menu('', [ toolbar, menu = self.create_toolbar_with_menu('')
(_("&Filter Period"), lambda: self.toggle_toolbar(self.config)), menu.addToggle(_("&Filter Period"), lambda: self.toggle_toolbar(self.config))
(_("&Summary"), self.show_summary), menu.addAction(_("&Summary"), self.show_summary)
(_("&Plot"), self.plot_history_dialog), menu.addAction(_("&Plot"), self.plot_history_dialog)
(_("&Export"), self.export_history_dialog), menu.addAction(_("&Export"), self.export_history_dialog)
])
hbox = self.create_toolbar_buttons() hbox = self.create_toolbar_buttons()
toolbar.insertLayout(1, hbox) toolbar.insertLayout(1, hbox)
return toolbar return toolbar
def toggle_filter(self):
pass
def get_toolbar_buttons(self): def get_toolbar_buttons(self):
return self.period_combo, self.start_button, self.end_button return self.period_combo, self.start_button, self.end_button

3
electrum/gui/qt/main_window.py

@ -1065,6 +1065,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
def do_copy(self, text: str, *, title: str = None) -> None: def do_copy(self, text: str, *, title: str = None) -> None:
self.app.clipboard().setText(text) self.app.clipboard().setText(text)
message = _("Text copied to Clipboard") if title is None else _("{} copied to Clipboard").format(title) 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 # 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)) self.gui_object.timer.singleShot(200, lambda: QToolTip.showText(QCursor.pos(), message, self))

11
electrum/gui/qt/receive_tab.py

@ -174,13 +174,10 @@ class ReceiveTab(QWidget, MessageBoxMixin, Logger):
self.receive_requests_label.setMaximumWidth(400) self.receive_requests_label.setMaximumWidth(400)
from .request_list import RequestList from .request_list import RequestList
self.request_list = RequestList(self) self.request_list = RequestList(self)
self.toolbar = self.request_list.create_toolbar_with_menu( 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)
(_("Toggle QR code window"), self.window.toggle_qr_window), menu.addAction(_("Export requests"), self.window.export_requests)
(_("Import requests"), self.window.import_requests),
(_("Export requests"), self.window.export_requests),
])
# layout # layout
vbox_g = QVBoxLayout() vbox_g = QVBoxLayout()

19
electrum/gui/qt/send_tab.py

@ -149,13 +149,10 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
self.invoices_label = QLabel(_('Invoices')) self.invoices_label = QLabel(_('Invoices'))
from .invoice_list import InvoiceList from .invoice_list import InvoiceList
self.invoice_list = InvoiceList(self) self.invoice_list = InvoiceList(self)
self.toolbar = self.invoice_list.create_toolbar_with_menu( 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)
(_("&Pay to many"), self.paytomany), menu.addAction(_("Export invoices"), self.window.export_invoices)
(_("Import invoices"), self.window.import_invoices),
(_("Export invoices"), self.window.export_invoices),
])
vbox0 = QVBoxLayout() vbox0 = QVBoxLayout()
vbox0.addLayout(grid) vbox0.addLayout(grid)
@ -754,15 +751,17 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
broadcast_thread, broadcast_done, self.window.on_error) broadcast_thread, broadcast_done, self.window.on_error)
def paytomany(self): def paytomany(self):
self.window.show_send_tab() if self.payto_e.is_multiline():
self.payto_e.do_clear()
return
self.payto_e.paytomany() self.payto_e.paytomany()
msg = '\n'.join([ message = '\n'.join([
_('Enter a list of outputs in the \'Pay to\' field.'), _('Enter a list of outputs in the \'Pay to\' field.'),
_('One output per line.'), _('One output per line.'),
_('Format: address, amount'), _('Format: address, amount'),
_('You may load a CSV file using the file icon.') _('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): def payto_contacts(self, labels):
paytos = [self.window.get_contact_payto(label) for label in labels] paytos = [self.window.get_contact_payto(label) for label in labels]

23
electrum/gui/qt/util.py

@ -569,6 +569,20 @@ class ElectrumItemDelegate(QStyledItemDelegate):
return custom_data.sizeHint(default_size) 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): class MyTreeView(QTreeView):
ROLE_CLIPBOARD_DATA = Qt.UserRole + 100 ROLE_CLIPBOARD_DATA = Qt.UserRole + 100
ROLE_CUSTOM_PAINT = Qt.UserRole + 101 ROLE_CUSTOM_PAINT = Qt.UserRole + 101
@ -754,11 +768,8 @@ class MyTreeView(QTreeView):
self.toolbar_buttons = buttons self.toolbar_buttons = buttons
return hbox return hbox
def create_toolbar_with_menu(self, title, menu_items): def create_toolbar_with_menu(self, title):
menu = QMenu() menu = MyMenu(self.config)
menu.setToolTipsVisible(True)
for k, v in menu_items:
menu.addAction(k, v)
toolbar_button = QToolButton() toolbar_button = QToolButton()
toolbar_button.setIcon(read_QIcon("preferences.png")) toolbar_button.setIcon(read_QIcon("preferences.png"))
toolbar_button.setMenu(menu) toolbar_button.setMenu(menu)
@ -768,7 +779,7 @@ class MyTreeView(QTreeView):
toolbar.addWidget(QLabel(title)) toolbar.addWidget(QLabel(title))
toolbar.addStretch() toolbar.addStretch()
toolbar.addWidget(toolbar_button) toolbar.addWidget(toolbar_button)
return toolbar return toolbar, menu
def show_toolbar(self, state, config=None): def show_toolbar(self, state, config=None):
if state == self.toolbar_shown: if state == self.toolbar_shown:

Loading…
Cancel
Save