Browse Source

qt: fix invoices tab

closes #4941
3.3.3.1
SomberNight 6 years ago
parent
commit
1b7672f70e
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 34
      electrum/gui/qt/invoice_list.py
  2. 3
      electrum/gui/qt/main_window.py

34
electrum/gui/qt/invoice_list.py

@ -33,7 +33,7 @@ class InvoiceList(MyTreeView):
filter_columns = [0, 1, 2, 3] # Date, Requestor, Description, Amount filter_columns = [0, 1, 2, 3] # Date, Requestor, Description, Amount
def __init__(self, parent): def __init__(self, parent):
super().__init__(parent, self.create_menu, 2) super().__init__(parent, self.create_menu, stretch_column=2, editable_columns=[])
self.setSortingEnabled(True) self.setSortingEnabled(True)
self.setColumnWidth(1, 200) self.setColumnWidth(1, 200)
self.setModel(QStandardItemModel(self)) self.setModel(QStandardItemModel(self))
@ -44,19 +44,20 @@ class InvoiceList(MyTreeView):
self.model().clear() self.model().clear()
self.update_headers([_('Expires'), _('Requestor'), _('Description'), _('Amount'), _('Status')]) self.update_headers([_('Expires'), _('Requestor'), _('Description'), _('Amount'), _('Status')])
self.header().setSectionResizeMode(1, QHeaderView.Interactive) self.header().setSectionResizeMode(1, QHeaderView.Interactive)
for pr in inv_list: for idx, pr in enumerate(inv_list):
key = pr.get_id() key = pr.get_id()
status = self.parent.invoices.get_status(key) status = self.parent.invoices.get_status(key)
requestor = pr.get_requestor() requestor = pr.get_requestor()
exp = pr.get_expiration_date() exp = pr.get_expiration_date()
date_str = format_time(exp) if exp else _('Never') date_str = format_time(exp) if exp else _('Never')
labels = [date_str, requestor, pr.memo, self.parent.format_amount(pr.get_amount(), whitespaces=True), pr_tooltips.get(status,'')] labels = [date_str, requestor, pr.memo, self.parent.format_amount(pr.get_amount(), whitespaces=True), pr_tooltips.get(status,'')]
item = [QStandardItem(e) for e in labels] items = [QStandardItem(e) for e in labels]
item[4].setIcon(self.icon_cache.get(pr_icons.get(status))) self.set_editability(items)
item[0].setData(Qt.UserRole, key) items[4].setIcon(self.icon_cache.get(pr_icons.get(status)))
item[1].setFont(QFont(MONOSPACE_FONT)) items[0].setData(key, role=Qt.UserRole)
item[3].setFont(QFont(MONOSPACE_FONT)) items[1].setFont(QFont(MONOSPACE_FONT))
self.addTopLevelItem(item) items[3].setFont(QFont(MONOSPACE_FONT))
self.model().insertRow(idx, items)
self.selectionModel().select(self.model().index(0,0), QItemSelectionModel.SelectCurrent) self.selectionModel().select(self.model().index(0,0), QItemSelectionModel.SelectCurrent)
if self.parent.isVisible(): if self.parent.isVisible():
b = len(inv_list) > 0 b = len(inv_list) > 0
@ -70,16 +71,17 @@ class InvoiceList(MyTreeView):
export_meta_gui(self.parent, _('invoices'), self.parent.invoices.export_file) export_meta_gui(self.parent, _('invoices'), self.parent.invoices.export_file)
def create_menu(self, position): def create_menu(self, position):
menu = QMenu() idx = self.indexAt(position)
item = self.itemAt(position) item = self.model().itemFromIndex(idx)
if not item: item_col0 = self.model().itemFromIndex(idx.sibling(idx.row(), 0))
if not item or not item_col0:
return return
key = item.data(0, Qt.UserRole) key = item_col0.data(Qt.UserRole)
column = self.currentColumn() column = idx.column()
column_title = self.headerItem().text(column) column_title = self.model().horizontalHeaderItem(column).text()
column_data = item.text(column) column_data = item.text()
pr = self.parent.invoices.get(key)
status = self.parent.invoices.get_status(key) status = self.parent.invoices.get_status(key)
menu = QMenu(self)
if column_data: if column_data:
menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(column_data)) menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(column_data))
menu.addAction(_("Details"), lambda: self.parent.show_invoice(key)) menu.addAction(_("Details"), lambda: self.parent.show_invoice(key))

3
electrum/gui/qt/main_window.py

@ -1929,7 +1929,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
grid.addWidget(QLabel(format_time(expires)), 4, 1) grid.addWidget(QLabel(format_time(expires)), 4, 1)
vbox.addLayout(grid) vbox.addLayout(grid)
def do_export(): def do_export():
fn = self.getSaveFileName(_("Save invoice to file"), "*.bip70") name = str(key) + '.bip70'
fn = self.getSaveFileName(_("Save invoice to file"), name, filter="*.bip70")
if not fn: if not fn:
return return
with open(fn, 'wb') as f: with open(fn, 'wb') as f:

Loading…
Cancel
Save