예제 #1
0
    def create_menu(self, position):
        menu = QMenu()
        idx = self.indexAt(position)
        column = idx.column() or self.Columns.NAME
        selected_keys = []
        for s_idx in self.selected_in_column(self.Columns.NAME):
            sel_key = self.model().itemFromIndex(s_idx).data(Qt.UserRole)
            selected_keys.append(sel_key)
        if not selected_keys or not idx.isValid():
            menu.addAction(_("New contact"), lambda: self.parent.new_contact_dialog())
            menu.addAction(_("Import file"), lambda: self.import_contacts())
            menu.addAction(_("Export file"), lambda: self.export_contacts())
        else:
            column_title = self.model().horizontalHeaderItem(column).text()
            column_data = '\n'.join(self.model().itemFromIndex(s_idx).text()
                                    for s_idx in self.selected_in_column(column))
            menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(column_data))
            if column in self.editable_columns:
                item = self.model().itemFromIndex(idx)
                if item.isEditable():
                    # would not be editable if openalias
                    persistent = QPersistentModelIndex(idx)
                    menu.addAction(_("Edit {}").format(column_title), lambda p=persistent: self.edit(QModelIndex(p)))
            menu.addAction(_("Pay to"), lambda: self.parent.payto_contacts(selected_keys))
            menu.addAction(_("Delete"), lambda: self.parent.delete_contacts(selected_keys))
            URLs = [block_explorer_URL(self.config, 'addr', key) for key in filter(is_address, selected_keys)]
            if URLs:
                menu.addAction(_("View on block explorer"), lambda: [webbrowser.open(u) for u in URLs])

        run_hook('create_contact_menu', menu, selected_keys)
        menu.exec_(self.viewport().mapToGlobal(position))
예제 #2
0
    def create_menu(self, position):
        from electrum_nmc.wallet import Multisig_Wallet
        is_multisig = isinstance(self.wallet, Multisig_Wallet)
        can_delete = self.wallet.can_delete_address()
        selected = self.selectedItems()
        multi_select = len(selected) > 1
        addrs = [item.text(1) for item in selected]
        if not addrs:
            return
        if not multi_select:
            item = self.itemAt(position)
            col = self.currentColumn()
            if not item:
                return
            addr = addrs[0]
            if not is_address(addr):
                item.setExpanded(not item.isExpanded())
                return

        menu = QMenu()
        if not multi_select:
            column_title = self.headerItem().text(col)
            copy_text = item.text(col)
            menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(copy_text))
            menu.addAction(_('Details'), lambda: self.parent.show_address(addr))
            if col in self.editable_columns:
                menu.addAction(_("Edit {}").format(column_title), lambda: self.editItem(item, col))
            menu.addAction(_("Request payment"), lambda: self.parent.receive_at(addr))
            if self.wallet.can_export():
                menu.addAction(_("Private key"), lambda: self.parent.show_private_key(addr))
            if not is_multisig and not self.wallet.is_watching_only():
                menu.addAction(_("Sign/verify message"), lambda: self.parent.sign_verify_message(addr))
                menu.addAction(_("Encrypt/decrypt message"), lambda: self.parent.encrypt_message(addr))
            if can_delete:
                menu.addAction(_("Remove from wallet"), lambda: self.parent.remove_address(addr))
            addr_URL = block_explorer_URL(self.config, 'addr', addr)
            if addr_URL:
                menu.addAction(_("View on block explorer"), lambda: webbrowser.open(addr_URL))

            if not self.wallet.is_frozen(addr):
                menu.addAction(_("Freeze"), lambda: self.parent.set_frozen_state([addr], True))
            else:
                menu.addAction(_("Unfreeze"), lambda: self.parent.set_frozen_state([addr], False))

        coins = self.wallet.get_utxos(addrs)
        if coins:
            menu.addAction(_("Spend from"), lambda: self.parent.spend_coins(coins))

        run_hook('receive_menu', menu, addrs, self.wallet)
        menu.exec_(self.viewport().mapToGlobal(position))
예제 #3
0
 def create_menu(self, position: QPoint):
     org_idx: QModelIndex = self.indexAt(position)
     idx = self.proxy.mapToSource(org_idx)
     if not idx.isValid():
         # can happen e.g. before list is populated for the first time
         return
     tx_item = self.hm.transactions.value_from_pos(idx.row())
     column = idx.column()
     if column == HistoryColumns.STATUS_ICON:
         column_title = _('Transaction ID')
         column_data = tx_item['txid']
     else:
         column_title = self.hm.headerData(column, Qt.Horizontal, Qt.DisplayRole)
         column_data = self.hm.data(idx, Qt.DisplayRole).value()
     tx_hash = tx_item['txid']
     tx = self.wallet.db.get_transaction(tx_hash)
     if not tx:
         return
     tx_URL = block_explorer_URL(self.config, 'tx', tx_hash)
     height = self.wallet.get_tx_height(tx_hash).height
     is_relevant, is_mine, v, fee = self.wallet.get_wallet_delta(tx)
     is_unconfirmed = height <= 0
     pr_key = self.wallet.invoices.paid.get(tx_hash)
     menu = QMenu()
     if height == TX_HEIGHT_LOCAL:
         menu.addAction(_("Remove"), lambda: self.remove_local_tx(tx_hash))
     menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(column_data))
     for c in self.editable_columns:
         if self.isColumnHidden(c): continue
         label = self.hm.headerData(c, Qt.Horizontal, Qt.DisplayRole)
         # TODO use siblingAtColumn when min Qt version is >=5.11
         persistent = QPersistentModelIndex(org_idx.sibling(org_idx.row(), c))
         menu.addAction(_("Edit {}").format(label), lambda p=persistent: self.edit(QModelIndex(p)))
     menu.addAction(_("Details"), lambda: self.show_transaction(tx_hash))
     if is_unconfirmed and tx:
         # note: the current implementation of RBF *needs* the old tx fee
         rbf = is_mine and not tx.is_final() and fee is not None
         if rbf:
             menu.addAction(_("Increase fee"), lambda: self.parent.bump_fee_dialog(tx))
         else:
             child_tx = self.wallet.cpfp(tx, 0)
             if child_tx:
                 menu.addAction(_("Child pays for parent"), lambda: self.parent.cpfp(tx, child_tx))
     if pr_key:
         menu.addAction(read_QIcon("seal"), _("View invoice"), lambda: self.parent.show_invoice(pr_key))
     if tx_URL:
         menu.addAction(_("View on block explorer"), lambda: webbrowser.open(tx_URL))
     menu.exec_(self.viewport().mapToGlobal(position))
예제 #4
0
 def create_menu(self, position):
     self.selectedIndexes()
     item = self.currentItem()
     if not item:
         return
     column = self.currentColumn()
     tx_hash = item.data(0, Qt.UserRole)
     if not tx_hash:
         return
     tx = self.wallet.transactions.get(tx_hash)
     if not tx:
         return
     if column is 0:
         column_title = "ID"
         column_data = tx_hash
     else:
         column_title = self.headerItem().text(column)
         column_data = item.text(column)
     tx_URL = block_explorer_URL(self.config, 'tx', tx_hash)
     height = self.wallet.get_tx_height(tx_hash).height
     is_relevant, is_mine, v, fee = self.wallet.get_wallet_delta(tx)
     is_unconfirmed = height <= 0
     pr_key = self.wallet.invoices.paid.get(tx_hash)
     menu = QMenu()
     if height == TX_HEIGHT_LOCAL:
         menu.addAction(_("Remove"), lambda: self.remove_local_tx(tx_hash))
     menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(column_data))
     for c in self.editable_columns:
         menu.addAction(_("Edit {}").format(self.headerItem().text(c)),
                        lambda bound_c=c: self.editItem(item, bound_c))
     menu.addAction(_("Details"), lambda: self.parent.show_transaction(tx))
     if is_unconfirmed and tx:
         # note: the current implementation of RBF *needs* the old tx fee
         rbf = is_mine and not tx.is_final() and fee is not None
         if rbf:
             menu.addAction(_("Increase fee"), lambda: self.parent.bump_fee_dialog(tx))
         else:
             child_tx = self.wallet.cpfp(tx, 0)
             if child_tx:
                 menu.addAction(_("Child pays for parent"), lambda: self.parent.cpfp(tx, child_tx))
     if pr_key:
         menu.addAction(self.icon_cache.get(":icons/seal"), _("View invoice"), lambda: self.parent.show_invoice(pr_key))
     if tx_URL:
         menu.addAction(_("View on block explorer"), lambda: webbrowser.open(tx_URL))
     menu.exec_(self.viewport().mapToGlobal(position))
예제 #5
0
    def create_menu(self, position):
        menu = QMenu()
        selected = self.selectedItems()
        if not selected:
            menu.addAction(_("New contact"),
                           lambda: self.parent.new_contact_dialog())
            menu.addAction(_("Import file"), lambda: self.import_contacts())
            menu.addAction(_("Export file"), lambda: self.export_contacts())
        else:
            names = [item.text(0) for item in selected]
            keys = [item.text(1) for item in selected]
            column = self.currentColumn()
            column_title = self.headerItem().text(column)
            column_data = '\n'.join([item.text(column) for item in selected])
            menu.addAction(
                _("Copy {}").format(column_title),
                lambda: self.parent.app.clipboard().setText(column_data))
            if column in self.editable_columns:
                item = self.currentItem()
                menu.addAction(
                    _("Edit {}").format(column_title),
                    lambda: self.editItem(item, column))
            menu.addAction(_("Pay to"),
                           lambda: self.parent.payto_contacts(keys))
            menu.addAction(_("Delete"),
                           lambda: self.parent.delete_contacts(keys))
            URLs = [
                block_explorer_URL(self.config, 'addr', key)
                for key in filter(is_address, keys)
            ]
            if URLs:
                menu.addAction(_("View on block explorer"),
                               lambda: map(webbrowser.open, URLs))

        run_hook('create_contact_menu', menu, selected)
        menu.exec_(self.viewport().mapToGlobal(position))
예제 #6
0
    def create_menu(self, position):
        from electrum_nmc.wallet import Multisig_Wallet
        is_multisig = isinstance(self.wallet, Multisig_Wallet)
        can_delete = self.wallet.can_delete_address()
        selected = self.selected_in_column(self.Columns.ADDRESS)
        if not selected:
            return
        multi_select = len(selected) > 1
        addrs = [self.model().itemFromIndex(item).text() for item in selected]
        menu = QMenu()
        if not multi_select:
            idx = self.indexAt(position)
            col = idx.column()
            item = self.model().itemFromIndex(idx)
            if not item:
                return
            addr = addrs[0]

            addr_column_title = self.model().horizontalHeaderItem(
                self.Columns.LABEL).text()
            addr_idx = idx.sibling(idx.row(), self.Columns.LABEL)

            column_title = self.model().horizontalHeaderItem(col).text()
            copy_text = self.model().itemFromIndex(idx).text()
            menu.addAction(
                _("Copy {}").format(column_title),
                lambda: self.place_text_on_clipboard(copy_text))
            menu.addAction(_('Details'),
                           lambda: self.parent.show_address(addr))
            persistent = QPersistentModelIndex(addr_idx)
            menu.addAction(_("Edit {}").format(addr_column_title),
                           lambda p=persistent: self.edit(QModelIndex(p)))
            menu.addAction(_("Request payment"),
                           lambda: self.parent.receive_at(addr))
            if self.wallet.can_export():
                menu.addAction(_("Private key"),
                               lambda: self.parent.show_private_key(addr))
            if not is_multisig and not self.wallet.is_watching_only():
                menu.addAction(_("Sign/verify message"),
                               lambda: self.parent.sign_verify_message(addr))
                menu.addAction(_("Encrypt/decrypt message"),
                               lambda: self.parent.encrypt_message(addr))
            if can_delete:
                menu.addAction(_("Remove from wallet"),
                               lambda: self.parent.remove_address(addr))
            addr_URL = block_explorer_URL(self.config, 'addr', addr)
            if addr_URL:
                menu.addAction(_("View on block explorer"),
                               lambda: webbrowser.open(addr_URL))

            if not self.wallet.is_frozen_address(addr):
                menu.addAction(
                    _("Freeze"), lambda: self.parent.
                    set_frozen_state_of_addresses([addr], True))
            else:
                menu.addAction(
                    _("Unfreeze"), lambda: self.parent.
                    set_frozen_state_of_addresses([addr], False))

        coins = self.wallet.get_spendable_coins(addrs, config=self.config)
        if coins:
            menu.addAction(_("Spend from"),
                           lambda: self.parent.spend_coins(coins))

        run_hook('receive_menu', menu, addrs, self.wallet)
        menu.exec_(self.viewport().mapToGlobal(position))