diff --git a/res/ui/importAccountDialog.ui b/res/ui/importAccountDialog.ui new file mode 100644 index 0000000000000000000000000000000000000000..f552d72c84737aab8e548b8f6d7a48d9434946f3 --- /dev/null +++ b/res/ui/importAccountDialog.ui @@ -0,0 +1,135 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ImportAccountDialog</class> + <widget class="QDialog" name="ImportAccountDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>124</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLineEdit" name="edit_file"/> + </item> + <item> + <widget class="QPushButton" name="button_import"> + <property name="text"> + <string>Import a file</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Name of the account :</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="edit_name"/> + </item> + </layout> + </item> + <item> + <widget class="QLabel" name="label_errors"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="button_box"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>button_box</sender> + <signal>accepted()</signal> + <receiver>ImportAccountDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>button_box</sender> + <signal>rejected()</signal> + <receiver>ImportAccountDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>button_import</sender> + <signal>clicked()</signal> + <receiver>ImportAccountDialog</receiver> + <slot>import_account()</slot> + <hints> + <hint type="sourcelabel"> + <x>349</x> + <y>21</y> + </hint> + <hint type="destinationlabel"> + <x>199</x> + <y>51</y> + </hint> + </hints> + </connection> + <connection> + <sender>edit_name</sender> + <signal>textEdited(QString)</signal> + <receiver>ImportAccountDialog</receiver> + <slot>name_changed()</slot> + <hints> + <hint type="sourcelabel"> + <x>259</x> + <y>52</y> + </hint> + <hint type="destinationlabel"> + <x>199</x> + <y>51</y> + </hint> + </hints> + </connection> + </connections> + <slots> + <slot>import_account()</slot> + <slot>name_changed()</slot> + </slots> +</ui> diff --git a/src/cutecoin/gui/importAccountDialog.py b/src/cutecoin/gui/importAccountDialog.py new file mode 100644 index 0000000000000000000000000000000000000000..af4f6b601b40ee8941aa22d514170014e086a58f --- /dev/null +++ b/src/cutecoin/gui/importAccountDialog.py @@ -0,0 +1,69 @@ +''' +Created on 22 mai 2014 + +@author: inso +''' +import re +from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QMessageBox, QErrorMessage, QFileDialog + +from cutecoin.tools.exceptions import Error +from cutecoin.gen_resources.importAccountDialog_uic import Ui_ImportAccountDialog + + +class ImportAccountDialog(QDialog, Ui_ImportAccountDialog): + + ''' + classdocs + ''' + + def __init__(self, core, parent=None): + ''' + Constructor + ''' + super(ImportAccountDialog, self).__init__() + self.setupUi(self) + self.core = core + self.main_window = parent + self.button_box.button(QDialogButtonBox.Ok).setEnabled(False) + + def accept(self): + account_name = self.edit_name.text() + try: + self.core.import_account(self.selected_file, account_name) + except Error as e: + QErrorMessage(self).showMessage(e.message) + return + QMessageBox.information(self, "Account import", + "Account imported succefully !") + self.accepted.emit() + self.close() + + def import_account(self): + self.selected_file = QFileDialog.getOpenFileName(self, + "Import an account file", + "", + "All account files (*.acc)") + self.selected_file = self.selected_file[0] + self.edit_file.setText(self.selected_file) + self.check() + + def name_changed(self): + self.check() + + def check(self): + name = self.edit_name.text() + if name == "": + self.button_box.button(QDialogButtonBox.Ok).setEnabled(False) + self.label_errors.setText("Please enter a name") + return + for account in self.core.accounts: + if name == account.name: + self.button_box.button(QDialogButtonBox.Ok).setEnabled(False) + self.label_errors.setText("Name already exists") + return + if self.selected_file[-4:] != ".acc": + self.button_box.button(QDialogButtonBox.Ok).setEnabled(False) + self.label_errors.setText("File is not an account format") + return + self.label_errors.setText("") + self.button_box.button(QDialogButtonBox.Ok).setEnabled(True)