diff --git a/qt.py b/qt.py index 711227f..99143a5 100644 --- a/qt.py +++ b/qt.py @@ -1080,7 +1080,7 @@ class BalWindow(Logger): willitems = {} for k,v in data.items(): data[k]['tx']=tx_from_any(v['tx']) - willitems[k]=Will.WillItem(data[k],_id=k) + willitems[k]=WillItem(data[k],_id=k) self.update_will(willitems) except Exception as e: raise e @@ -1587,18 +1587,22 @@ class BalWizardHeirsWidget(BalWizardWidget): self.heirs_list=HeirList(self.bal_window,self.parent) button_add=QPushButton(_("Add")) button_add.clicked.connect(self.add_heir) - button_import=QPushButton(_("Import from file")) + button_import=QPushButton(_("Import")) button_import.clicked.connect(self.import_from_file) + button_export=QPushButton(_("Export")) + button_import.clicked.connect(self.export_to_file) widget=QWidget() vbox=QVBoxLayout(widget) vbox.addWidget(self.heirs_list) - vbox.addLayout(Buttons(button_add,button_import)) + vbox.addLayout(Buttons(button_add,button_import,button_export)) return widget def import_from_file(self): self.bal_window.import_heirs() self.heirs_list.update() + def export_to_file(self): + self.bal_window.export_heirs() def add_heir(self): self.bal_window.new_heir_dialog() self.heirs_list.update() @@ -1623,30 +1627,37 @@ class BalWizardWEDownloadWidget(BalWizardWidget): def validate(self): return True def _on_next(self): + index = self.combo.currentIndex() _logger.debug(f"selected index:{index}") - if index < 2: - def on_success(willexecutors): - self.bal_window.willexecutors=Willexecutors.get_willexecutors(self.bal_window.bal_plugin) - self.bal_window.willexecutors.update(willexecutors) - self.bal_window.ping_willexecutors(self.bal_window.willexecutors) - if index < 1: - for we in self.bal_window.willexecutors: - if self.bal_window.willexecutors[we]['status']==200: - self.bal_window.willexecutors[we]['selected']=True - Willexecutors.save(self.bal_window.bal_plugin,self.bal_window.willexecutors) - def on_failure(fail): - print(f"fail") - pass - - task = partial(Willexecutors.download_list,self.bal_window.bal_plugin) - msg = _("Downloading Will-Executors list") - self.waiting_dialog = BalWaitingDialog(self.bal_window, msg, task, on_success, on_failure,exe=False) - self.waiting_dialog.exe() + if index < 3: + self.bal_window.willexecutors=Willexecutors.get_willexecutors(self.bal_window.bal_plugin) + + if index == 2: + def doNothing(): + self.bal_window.willexecutors.update(self.willexecutors) + Willexecutors.save(self.bal_window.bal_plugin,self.bal_window.willexecutors) + pass + import_meta_gui(self.bal_window.window, _('willexecutors.json'), self.import_json_file, doNothing) + + if index < 2: + def on_success(willexecutors): + self.bal_window.willexecutors.update(willexecutors) + self.bal_window.ping_willexecutors(self.bal_window.willexecutors) + if index < 1: + for we in self.bal_window.willexecutors: + if self.bal_window.willexecutors[we]['status']==200: + self.bal_window.willexecutors[we]['selected']=True + Willexecutors.save(self.bal_window.bal_plugin,self.bal_window.willexecutors) + def on_failure(fail): + print(f"fail") + pass + + task = partial(Willexecutors.download_list,self.bal_window.bal_plugin) + msg = _("Downloading Will-Executors list") + self.waiting_dialog = BalWaitingDialog(self.bal_window, msg, task, on_success, on_failure,exe=False) + self.waiting_dialog.exe() - elif index == 2: - #TODO import from file - pass elif index == 3: #TODO DO NOTHING pass @@ -1654,6 +1665,14 @@ class BalWizardWEDownloadWidget(BalWizardWidget): if self.validate(): return self.on_next() + def import_json_file(self, path): + data = read_json_file(path) + data = self._validate(data) + self.willexecutors=data + + def _validate(self,data): + return data + class BalWizardWEWidget(BalWizardWidget): title=("Bitcoin After Life Will-Executors") message=_("Configure and select your willexecutors") @@ -2532,6 +2551,7 @@ class PreviewList(MyTreeView): menu.addAction(_("Display"), self.bal_window.preview_modal_dialog) menu.addAction(_("Sign"), self.ask_password_and_sign_transactions) menu.addAction(_("Export"), self.export_will) + menu.addAction(_("Import"), self.import_will) menu.addAction(_("Broadcast"), self.broadcast) menu.addAction(_("Check"), self.check) menu.addAction(_("Invalidate"), self.invalidate_will) diff --git a/will.py b/will.py index 430c2c4..1753313 100644 --- a/will.py +++ b/will.py @@ -15,8 +15,8 @@ MIN_LOCKTIME = 1 MIN_BLOCK = 1 _logger = get_logger(__name__) -#return an array with the list of children class Will: + #return an array with the list of children def get_children(will,willid): out = [] for _id in will: @@ -744,10 +744,11 @@ class WillItem(Logger): else: return "#ffffff" - -class WillExpiredException(Exception): +class WillException(Exception): pass -class NotCompleteWillException(Exception): +class WillExpiredException(WillException): + pass +class NotCompleteWillException(WillException): pass class HeirChangeException(NotCompleteWillException): pass @@ -761,9 +762,9 @@ class NoWillExecutorNotPresent(NotCompleteWillException): pass class WillExecutorNotPresent(NotCompleteWillException): pass -class NoHeirsException(Exception): +class NoHeirsException(WillException): pass -class AmountException(Exception): +class AmountException(WillException): pass class PercAmountException(AmountException): pass