Ejemplo n.º 1
0
 def create_menu(self, position: QPoint):
     idx: QModelIndex = self.indexAt(position)
     if not idx.isValid():
         # can happen e.g. before list is populated for the first time
         return
     tx_item = idx.internalPointer()
     tx_hash = tx_item['txid']
     group_txid = tx_item.get('group_txid')
     is_parent = ('group_label' in tx_item)
     if is_parent and tx_hash in self.hm.expanded_groups:
         expanded = True
     else:
         expanded = False
     tx = self.wallet.db.get_transaction(tx_hash)
     if not tx:
         return
     tx_URL = block_explorer_URL(self.config, 'tx', tx_hash)
     tx_details = self.wallet.get_tx_info(tx)
     menu = QMenu()
     if group_txid:
         collapse_m = lambda: self.collapse_tx_group(group_txid)
         menu.addAction(_("Collapse Tx Group"), collapse_m)
     if is_parent:
         if expanded:
             collapse_m = lambda: self.collapse_tx_group(tx_hash)
             menu.addAction(_("Collapse Tx Group"), collapse_m)
         else:
             expand_m = lambda: self.expand_tx_group(tx_hash)
             menu.addAction(_("Expand Tx Group"), expand_m)
     if tx_details.can_remove and (not is_parent or expanded):
         menu.addAction(_("Remove"), lambda: self.remove_local_tx(tx_hash))
     cc = self.add_copy_menu(menu, idx)
     cc.addAction(
         _("Transaction ID"),
         lambda: self.place_text_on_clipboard(tx_hash, title="TXID"))
     for c in self.editable_columns:
         if is_parent and not expanded: continue
         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(idx.sibling(idx.row(), c))
         menu.addAction(_("Edit {}").format(label),
                        lambda p=persistent: self.edit(QModelIndex(p)))
     menu.addAction(_("View Transaction"),
                    lambda: self.show_transaction(tx_hash))
     invoices = self.wallet.get_relevant_invoices_for_tx(tx)
     if len(invoices) == 1:
         menu.addAction(
             _("View invoice"),
             lambda inv=invoices[0]: self.parent.show_onchain_invoice(inv))
     elif len(invoices) > 1:
         menu_invs = menu.addMenu(_("Related invoices"))
         for inv in invoices:
             menu_invs.addAction(
                 _("View invoice"),
                 lambda inv=inv: self.parent.show_onchain_invoice(inv))
     if tx_URL:
         menu.addAction(_("View on block explorer"),
                        lambda: webopen(tx_URL))
     menu.exec_(self.viewport().mapToGlobal(position))
Ejemplo n.º 2
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(
                self.ROLE_CONTACT_KEY)
            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.parent.import_contacts())
            menu.addAction(_("Export file"),
                           lambda: self.parent.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.place_text_on_clipboard(column_data,
                                                     title=column_title))
            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: [webopen(u) for u in URLs])

        run_hook('create_contact_menu', menu, selected_keys)
        menu.exec_(self.viewport().mapToGlobal(position))
Ejemplo n.º 3
0
    def create_menu(self, position):
        from electrum_firo.wallet import Multisig_Wallet
        is_multisig = isinstance(self.wallet, Multisig_Wallet)
        can_delete = self.wallet.can_delete_address()
        selected = self.selectionModel().selectedRows()
        if not selected:
            return
        multi_select = len(selected) > 1
        addr_items = []
        for idx in selected:
            if not idx.isValid():
                return
            addr_items.append(idx.internalPointer())
        addrs = [addr_item['addr'] for addr_item in addr_items]
        menu = QMenu()
        if not multi_select:
            idx = self.indexAt(position)
            if not idx.isValid():
                return
            item = addr_items[0]
            if not item:
                return
            addr = item['addr']
            is_ps = item['is_ps']
            is_ps_ks = item['is_ps_ks']

            hd = self.am.headerData
            addr_title = hd(AddrColumns.LABEL, None, Qt.DisplayRole)
            label_idx = idx.sibling(idx.row(), AddrColumns.LABEL)

            self.add_copy_menu(menu, idx)
            menu.addAction(_('Details'),
                           lambda: self.parent.show_address(addr))

            persistent = QPersistentModelIndex(label_idx)
            menu.addAction(_("Edit {}").format(addr_title),
                           lambda p=persistent: self.edit(QModelIndex(p)))

            #if not is_ps and not is_ps_ks:
            #    menu.addAction(_("Request payment"),
            #                   lambda: self.parent.receive_at(addr))
            if self.wallet.can_export() or self.wallet.psman.is_ps_ks(addr):
                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: webopen(addr_URL))

            if not is_ps:

                def set_frozen_state(addrs, state):
                    self.parent.set_frozen_state_of_addresses(addrs, state)

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

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

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