use QInputDialog for new filenames

This commit is contained in:
thomasv 2013-09-13 15:08:40 +02:00
parent a96a7c8db2
commit f12760829f
2 changed files with 28 additions and 16 deletions

View File

@ -290,12 +290,34 @@ class ElectrumWindow(QMainWindow):
self.load_wallet(wallet)
def backup_wallet(self):
import shutil
path = self.wallet.storage.path
wallet_folder = os.path.dirname(path)
new_filename, ok = QInputDialog.getText(self, _('Filename'), _('Current directory') + ': ' + wallet_folder + '\n' + _('Enter a filename for the copy of your wallet') + ':')
new_filename = unicode(new_filename)
if not ok or not new_filename:
return
new_path = os.path.join(wallet_folder, new_filename)
if new_path != path:
try:
shutil.copy2(path, new_path)
QMessageBox.information(None,"Wallet backup created", _("A copy of your wallet file was created in")+" '%s'" % str(new_path))
except (IOError, os.error), reason:
QMessageBox.critical(None,"Unable to create backup", _("Electrum was unable to copy your wallet file to the specified location.")+"\n" + str(reason))
def new_wallet(self):
import installwizard
wallet_folder = self.wallet.storage.path
re.sub("(\/\w*.dat)$", "", wallet_folder)
filename = self.getSaveFileName("Select your wallet file", wallet_folder)
wallet_folder = os.path.dirname(self.wallet.storage.path)
filename, ok = QInputDialog.getText(self, _('Filename'), _('Current directory') + ': ' + wallet_folder + '\n'+_('Enter a new file name') + ':')
filename = unicode(filename)
if not ok or not filename:
return
filename = os.path.join(wallet_folder, filename)
storage = WalletStorage({'wallet_path': filename})
assert not storage.file_exists
@ -318,7 +340,7 @@ class ElectrumWindow(QMainWindow):
new_wallet_action.triggered.connect(self.new_wallet)
wallet_backup = file_menu.addAction(_("&Copy"))
wallet_backup.triggered.connect(lambda: backup_wallet(self.wallet.storage.path))
wallet_backup.triggered.connect(self.backup_wallet)
quit_item = file_menu.addAction(_("&Close"))
quit_item.triggered.connect(self.close)
@ -491,14 +513,14 @@ class ElectrumWindow(QMainWindow):
# custom wrappers for getOpenFileName and getSaveFileName, that remember the path selected by the user
def getOpenFileName(self, title, filter = None):
def getOpenFileName(self, title, filter = ""):
directory = self.config.get('io_dir', os.path.expanduser('~'))
fileName = unicode( QFileDialog.getOpenFileName(self, title, directory, filter) )
if fileName and directory != os.path.dirname(fileName):
self.config.set_key('io_dir', os.path.dirname(fileName), True)
return fileName
def getSaveFileName(self, title, filename, filter = None):
def getSaveFileName(self, title, filename, filter = ""):
directory = self.config.get('io_dir', os.path.expanduser('~'))
path = os.path.join( directory, filename )
fileName = unicode( QFileDialog.getSaveFileName(self, title, path, filter) )

View File

@ -56,16 +56,6 @@ class HelpButton(QPushButton):
def backup_wallet(path):
import shutil
directory, fileName = os.path.split(path)
try:
otherpath = unicode( QFileDialog.getOpenFileName(QWidget(), _('Enter a filename for the copy of your wallet'), directory) )
if otherpath and path!=otherpath:
shutil.copy2(path, otherpath)
QMessageBox.information(None,"Wallet backup created", _("A copy of your wallet file was created in")+" '%s'" % str(otherpath))
except (IOError, os.error), reason:
QMessageBox.critical(None,"Unable to create backup", _("Electrum was unable to copy your wallet file to the specified location.")+"\n" + str(reason))
def ok_cancel_buttons(dialog, ok_label=_("OK") ):
hbox = QHBoxLayout()