commit bf12bac1f23b92e53ddd783e8231d16d8c5d5b12
parent 0ab69e260642a986dbfb1565c1112a140add8f5b
Author: Maran <maran.hidskes@gmail.com>
Date: Sat, 1 Jun 2013 11:06:51 +0200
DRYed the backup wallet
Diffstat:
3 files changed, 17 insertions(+), 27 deletions(-)
diff --git a/gui/gui_classic.py b/gui/gui_classic.py
@@ -320,17 +320,6 @@ class ElectrumWindow(QMainWindow):
else:
self.load_wallet(file_name)
- # TODO: I rather import this from the lite gui, is that possible?
- def backup_wallet(self):
- try:
- folderName = QFileDialog.getExistingDirectory(QWidget(), _('Select folder to save a copy of your wallet to'), os.path.expanduser('~/'))
- if folderName:
- # TODO: Can we get the current wallet file instead of bruteforcing the default one?
- sourceFile = self.wallet.config.path
- shutil.copy2(sourceFile, str(folderName))
- QMessageBox.information(None,"Wallet backup created", _("A copy of your wallet file was created in")+" '%s'" % str(folderName))
- 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 init_menubar(self):
menubar = QMenuBar()
@@ -361,7 +350,7 @@ class ElectrumWindow(QMainWindow):
wallet_menu = menubar.addMenu(_("&Wallet"))
wallet_backup = wallet_menu.addAction(_("&Create backup"))
- wallet_backup.triggered.connect(self.backup_wallet)
+ wallet_backup.triggered.connect(backup_wallet)
show_menu = wallet_menu.addMenu(_("Show"))
diff --git a/gui/gui_lite.py b/gui/gui_lite.py
@@ -35,6 +35,8 @@ from electrum.util import format_satoshis, age
import gui_classic
import shutil
+from qt_util import *
+
bitcoin = lambda v: v * 100000000
def IconButton(filename, parent=None):
@@ -367,8 +369,8 @@ class MiniWindow(QDialog):
view_menu = menubar.addMenu(_("&View"))
extra_menu = menubar.addMenu(_("&Extra"))
- backup_wallet = extra_menu.addAction( _("&Create wallet backup"))
- backup_wallet.triggered.connect(self.backup_wallet)
+ backup_wallet_menu = extra_menu.addAction( _("&Create wallet backup"))
+ backup_wallet_menu.triggered.connect(backup_wallet)
export_csv = extra_menu.addAction( _("&Export transactions to CSV") )
export_csv.triggered.connect(lambda: csv_transaction(self.actuator.wallet))
@@ -625,19 +627,6 @@ class MiniWindow(QDialog):
self.main_layout.setRowMinimumHeight(3,0)
self.history_list.hide()
- def backup_wallet(self):
- try:
- folderName = QFileDialog.getExistingDirectory(QWidget(), _('Select folder to save a copy of your wallet to'), os.path.expanduser('~/'))
- if folderName:
- sourceFile = util.user_dir() + '/electrum.dat'
- shutil.copy2(sourceFile, str(folderName))
- QMessageBox.information(None,"Wallet backup created", _("A copy of your wallet file was created in")+" '%s'" % str(folderName))
- 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))
-
-
-
-
class BalanceLabel(QLabel):
SHOW_CONNECTING = 1
diff --git a/gui/qt_util.py b/gui/qt_util.py
@@ -1,6 +1,18 @@
from i18n import _
from PyQt4.QtGui import *
from PyQt4.QtCore import *
+import os.path
+
+def backup_wallet():
+ try:
+ folderName = QFileDialog.getExistingDirectory(QWidget(), _('Select folder to save a copy of your wallet to'), os.path.expanduser('~/'))
+ if folderName:
+ # TODO: Can we get the current wallet file instead of bruteforcing the default one?
+ sourceFile = self.wallet.config.path
+ shutil.copy2(sourceFile, str(folderName))
+ QMessageBox.information(None,"Wallet backup created", _("A copy of your wallet file was created in")+" '%s'" % str(folderName))
+ 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()