Qt tx dialog: fix file extension when exporting (on MacOS...)
closes #5954 We are now giving every(?) hint possible to the MacOS file dialog... The extension is put in the filename as before (which turned out not to be enough). It is also set using QFileDialog.setDefaultSuffix, which again, turns out not to be enough. In desperation, the file extension filter-list now contains *.psbt and *.txn as separate filters, and the one with the expected extension is pre-selected. This seems enough...
This commit is contained in:
@@ -45,7 +45,7 @@ from PyQt5.QtWidgets import (QMessageBox, QComboBox, QSystemTrayIcon, QTabWidget
|
|||||||
QVBoxLayout, QGridLayout, QLineEdit,
|
QVBoxLayout, QGridLayout, QLineEdit,
|
||||||
QHBoxLayout, QPushButton, QScrollArea, QTextEdit,
|
QHBoxLayout, QPushButton, QScrollArea, QTextEdit,
|
||||||
QShortcut, QMainWindow, QCompleter, QInputDialog,
|
QShortcut, QMainWindow, QCompleter, QInputDialog,
|
||||||
QWidget, QSizePolicy, QStatusBar, QToolTip)
|
QWidget, QSizePolicy, QStatusBar, QToolTip, QDialog)
|
||||||
|
|
||||||
import electrum
|
import electrum
|
||||||
from electrum import (keystore, ecc, constants, util, bitcoin, commands,
|
from electrum import (keystore, ecc, constants, util, bitcoin, commands,
|
||||||
@@ -89,7 +89,7 @@ from .util import (read_QIcon, ColorScheme, text_dialog, icon_path, WaitingDialo
|
|||||||
CloseButton, HelpButton, MessageBoxMixin, EnterButton,
|
CloseButton, HelpButton, MessageBoxMixin, EnterButton,
|
||||||
import_meta_gui, export_meta_gui,
|
import_meta_gui, export_meta_gui,
|
||||||
filename_field, address_field, char_width_in_lineedit, webopen,
|
filename_field, address_field, char_width_in_lineedit, webopen,
|
||||||
TRANSACTION_FILE_EXTENSION_FILTER, MONOSPACE_FONT)
|
TRANSACTION_FILE_EXTENSION_FILTER_ANY, MONOSPACE_FONT)
|
||||||
from .util import ButtonsTextEdit
|
from .util import ButtonsTextEdit
|
||||||
from .installwizard import WIF_HELP_TEXT
|
from .installwizard import WIF_HELP_TEXT
|
||||||
from .history_list import HistoryList, HistoryModel
|
from .history_list import HistoryList, HistoryModel
|
||||||
@@ -780,13 +780,27 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
self.config.set_key('io_dir', os.path.dirname(fileName), True)
|
self.config.set_key('io_dir', os.path.dirname(fileName), True)
|
||||||
return fileName
|
return fileName
|
||||||
|
|
||||||
def getSaveFileName(self, title, filename, filter = ""):
|
def getSaveFileName(self, title, filename, filter="",
|
||||||
|
*, default_extension: str = None,
|
||||||
|
default_filter: str = None) -> Optional[str]:
|
||||||
directory = self.config.get('io_dir', os.path.expanduser('~'))
|
directory = self.config.get('io_dir', os.path.expanduser('~'))
|
||||||
path = os.path.join( directory, filename )
|
path = os.path.join(directory, filename)
|
||||||
fileName, __ = QFileDialog.getSaveFileName(self, title, path, filter)
|
|
||||||
if fileName and directory != os.path.dirname(fileName):
|
file_dialog = QFileDialog(self, title, path, filter)
|
||||||
self.config.set_key('io_dir', os.path.dirname(fileName), True)
|
file_dialog.setAcceptMode(QFileDialog.AcceptSave)
|
||||||
return fileName
|
if default_extension:
|
||||||
|
# note: on MacOS, the selected filter's first extension seems to have priority over this...
|
||||||
|
file_dialog.setDefaultSuffix(default_extension)
|
||||||
|
if default_filter:
|
||||||
|
assert default_filter in filter, f"default_filter={default_filter!r} does not appear in filter={filter!r}"
|
||||||
|
file_dialog.selectNameFilter(default_filter)
|
||||||
|
if file_dialog.exec() != QDialog.Accepted:
|
||||||
|
return None
|
||||||
|
|
||||||
|
selected_path = file_dialog.selectedFiles()[0]
|
||||||
|
if selected_path and directory != os.path.dirname(selected_path):
|
||||||
|
self.config.set_key('io_dir', os.path.dirname(selected_path), True)
|
||||||
|
return selected_path
|
||||||
|
|
||||||
def timer_actions(self):
|
def timer_actions(self):
|
||||||
self.request_list.refresh_status()
|
self.request_list.refresh_status()
|
||||||
@@ -2509,7 +2523,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
|
|
||||||
def read_tx_from_file(self) -> Optional[Transaction]:
|
def read_tx_from_file(self) -> Optional[Transaction]:
|
||||||
fileName = self.getOpenFileName(_("Select your transaction file"),
|
fileName = self.getOpenFileName(_("Select your transaction file"),
|
||||||
TRANSACTION_FILE_EXTENSION_FILTER)
|
TRANSACTION_FILE_EXTENSION_FILTER_ANY)
|
||||||
if not fileName:
|
if not fileName:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -50,7 +50,9 @@ from electrum.logging import get_logger
|
|||||||
|
|
||||||
from .util import (MessageBoxMixin, read_QIcon, Buttons, icon_path,
|
from .util import (MessageBoxMixin, read_QIcon, Buttons, icon_path,
|
||||||
MONOSPACE_FONT, ColorScheme, ButtonsLineEdit, text_dialog,
|
MONOSPACE_FONT, ColorScheme, ButtonsLineEdit, text_dialog,
|
||||||
char_width_in_lineedit, TRANSACTION_FILE_EXTENSION_FILTER,
|
char_width_in_lineedit, TRANSACTION_FILE_EXTENSION_FILTER_SEPARATE,
|
||||||
|
TRANSACTION_FILE_EXTENSION_FILTER_ONLY_COMPLETE_TX,
|
||||||
|
TRANSACTION_FILE_EXTENSION_FILTER_ONLY_PARTIAL_TX,
|
||||||
BlockingWaitingDialog)
|
BlockingWaitingDialog)
|
||||||
|
|
||||||
from .fee_slider import FeeSlider
|
from .fee_slider import FeeSlider
|
||||||
@@ -323,12 +325,19 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
|
|||||||
if isinstance(tx, PartialTransaction):
|
if isinstance(tx, PartialTransaction):
|
||||||
tx.finalize_psbt()
|
tx.finalize_psbt()
|
||||||
if tx.is_complete():
|
if tx.is_complete():
|
||||||
name = 'signed_%s.txn' % (tx.txid()[0:8])
|
name = 'signed_%s' % (tx.txid()[0:8])
|
||||||
|
extension = 'txn'
|
||||||
|
default_filter = TRANSACTION_FILE_EXTENSION_FILTER_ONLY_COMPLETE_TX
|
||||||
else:
|
else:
|
||||||
name = self.wallet.basename() + time.strftime('-%Y%m%d-%H%M.psbt')
|
name = self.wallet.basename() + time.strftime('-%Y%m%d-%H%M')
|
||||||
|
extension = 'psbt'
|
||||||
|
default_filter = TRANSACTION_FILE_EXTENSION_FILTER_ONLY_PARTIAL_TX
|
||||||
|
name = f'{name}.{extension}'
|
||||||
fileName = self.main_window.getSaveFileName(_("Select where to save your transaction"),
|
fileName = self.main_window.getSaveFileName(_("Select where to save your transaction"),
|
||||||
name,
|
name,
|
||||||
TRANSACTION_FILE_EXTENSION_FILTER)
|
TRANSACTION_FILE_EXTENSION_FILTER_SEPARATE,
|
||||||
|
default_extension=extension,
|
||||||
|
default_filter=default_filter)
|
||||||
if not fileName:
|
if not fileName:
|
||||||
return
|
return
|
||||||
if tx.is_complete(): # network tx hex
|
if tx.is_complete(): # network tx hex
|
||||||
|
|||||||
@@ -51,7 +51,12 @@ pr_icons = {
|
|||||||
|
|
||||||
|
|
||||||
# filter tx files in QFileDialog:
|
# filter tx files in QFileDialog:
|
||||||
TRANSACTION_FILE_EXTENSION_FILTER = "Transaction (*.txn *.psbt);;All files (*)"
|
TRANSACTION_FILE_EXTENSION_FILTER_ANY = "Transaction (*.txn *.psbt);;All files (*)"
|
||||||
|
TRANSACTION_FILE_EXTENSION_FILTER_ONLY_PARTIAL_TX = "Partial Transaction (*.psbt)"
|
||||||
|
TRANSACTION_FILE_EXTENSION_FILTER_ONLY_COMPLETE_TX = "Complete Transaction (*.txn)"
|
||||||
|
TRANSACTION_FILE_EXTENSION_FILTER_SEPARATE = (f"{TRANSACTION_FILE_EXTENSION_FILTER_ONLY_PARTIAL_TX};;"
|
||||||
|
f"{TRANSACTION_FILE_EXTENSION_FILTER_ONLY_COMPLETE_TX};;"
|
||||||
|
f"All files (*)")
|
||||||
|
|
||||||
|
|
||||||
class EnterButton(QPushButton):
|
class EnterButton(QPushButton):
|
||||||
|
|||||||
Reference in New Issue
Block a user