electrum-bitcoinprivate/gui/qt_util.py

43 lines
1.4 KiB
Python
Raw Normal View History

from i18n import _
from PyQt4.QtGui import *
from PyQt4.QtCore import *
2013-06-01 02:06:51 -07:00
import os.path
2013-08-01 05:58:30 -07:00
def backup_wallet(path):
import shutil
directory, fileName = os.path.split(path)
2013-06-01 02:06:51 -07:00
try:
2013-08-01 05:58:30 -07:00
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))
2013-06-01 02:06:51 -07:00
except (IOError, os.error), reason:
2013-08-01 05:58:30 -07:00
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()
hbox.addStretch(1)
b = QPushButton(_("Cancel"))
hbox.addWidget(b)
b.clicked.connect(dialog.reject)
b = QPushButton(ok_label)
hbox.addWidget(b)
b.clicked.connect(dialog.accept)
b.setDefault(True)
return hbox
def text_dialog(parent, title, label, ok_label):
dialog = QDialog(parent)
dialog.setMinimumWidth(500)
dialog.setWindowTitle(title)
dialog.setModal(1)
l = QVBoxLayout()
dialog.setLayout(l)
l.addWidget(QLabel(label))
txt = QTextEdit()
l.addWidget(txt)
l.addLayout(ok_cancel_buttons(dialog, ok_label))
if dialog.exec_():
return unicode(txt.toPlainText())