diff --git a/res/ui/community_view.ui b/res/ui/community_view.ui index d5c0078d2188f388ef359f68f470daa4e2a0a814..45b86c534c47c9c4f877f78c6344554a8a402e8d 100644 --- a/res/ui/community_view.ui +++ b/res/ui/community_view.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>532</width> - <height>313</height> + <width>624</width> + <height>429</height> </rect> </property> <property name="windowTitle"> diff --git a/src/cutecoin/gui/certification.py b/src/cutecoin/gui/certification.py index c76f14682aa9f91552e17b74bd69e54d25a2f0e3..ca55ef33781e335ca926c64beb068f5425cc433a 100644 --- a/src/cutecoin/gui/certification.py +++ b/src/cutecoin/gui/certification.py @@ -16,7 +16,7 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): classdocs """ - def __init__(self, certifier, app, password_asker): + def __init__(self, app, certifier, password_asker): """ Constructor """ diff --git a/src/cutecoin/gui/community_view.py b/src/cutecoin/gui/community_view.py index b76ed0161cdf9b1b24b5cbde6c9c5ba326b3ea5a..de3563c1a8c8e1aa1a241d5f05e3065b268076c6 100644 --- a/src/cutecoin/gui/community_view.py +++ b/src/cutecoin/gui/community_view.py @@ -13,14 +13,11 @@ from PyQt5.QtGui import QIcon from ..core.net.api import bma as qtbma from .wot_tab import WotTabWidget from .identities_tab import IdentitiesTabWidget -from .wallets_tab import WalletsTabWidget from .transactions_tab import TransactionsTabWidget from .network_tab import NetworkTabWidget -from .informations_tab import InformationsTabWidget from . import toast import asyncio -from ..tools.exceptions import MembershipNotFoundError, NoPeerAvailable -from ..core.registry import IdentitiesRegistry +from ..tools.exceptions import MembershipNotFoundError, LookupFailureError from ..gen_resources.community_view_uic import Ui_CommunityWidget @@ -53,8 +50,6 @@ class CommunityWidget(QWidget, Ui_CommunityWidget): self.tab_identities = IdentitiesTabWidget(self.app) - self.tab_wallets = WalletsTabWidget(self.app) - self.tab_history = TransactionsTabWidget(self.app) self.tab_network = NetworkTabWidget(self.app) @@ -96,6 +91,7 @@ class CommunityWidget(QWidget, Ui_CommunityWidget): community.inner_data_changed.connect(self.refresh_status) self.label_currency.setText(community.currency) self.community = community + self.refresh_quality_buttons() @pyqtSlot(str) def display_error(self, error): @@ -143,17 +139,13 @@ class CommunityWidget(QWidget, Ui_CommunityWidget): self.tab_history.start_progress() self.refresh_data() - def refresh_wallets(self): - if self.tab_wallets: - self.tab_wallets.refresh() + def refresh_quality_buttons(self): + pass def refresh_data(self): """ Refresh data when the blockchain watcher finished handling datas """ - if self.tab_wallets: - self.tab_wallets.refresh() - self.tab_history.refresh_balance() self.refresh_status() @@ -190,6 +182,28 @@ class CommunityWidget(QWidget, Ui_CommunityWidget): self.status_label.setText(label_text) + def refresh_quality_buttons(self): + if self.account and self.community: + try: + if self.account.identity(self.community).published_uid(self.community): + logging.debug("UID Published") + if self.account.identity(self.community).is_member(self.community): + self.button_membership.setText(self.tr("Renew membership")) + self.button_membership.show() + self.button_certification.show() + else: + logging.debug("Not a member") + self.button_membership.setText(self.tr("Send membership demand")) + self.button_membership.show() + self.button_certification.hide() + else: + logging.debug("UID not published") + self.button_membership.hide() + self.button_certification.hide() + except LookupFailureError: + self.button_membership.hide() + self.button_certification.hide() + def showEvent(self, event): self.refresh_status() @@ -220,6 +234,44 @@ The process to join back the community later will have to be done again.""") asyncio.async(self.account.send_membership(password, self.community, 'OUT')) + def publish_uid(self): + reply = QMessageBox.warning(self, self.tr("Warning"), + self.tr("""Are you sure ? +Publishing your UID can be canceled by Revoke UID.""") +.format(self.account.pubkey), QMessageBox.Ok | QMessageBox.Cancel) + if reply == QMessageBox.Ok: + password = self.password_asker.exec_() + if self.password_asker.result() == QDialog.Rejected: + return + + try: + self.account.send_selfcert(password, self.community) + toast.display(self.tr("UID Publishing"), + self.tr("Success publishing your UID")) + except ValueError as e: + QMessageBox.critical(self, self.tr("Publish UID error"), + str(e)) + except NoPeerAvailable as e: + QMessageBox.critical(self, self.tr("Network error"), + self.tr("Couldn't connect to network : {0}").format(e), + QMessageBox.Ok) + except Exception as e: + QMessageBox.critical(self, self.tr("Error"), + "{0}".format(e), + QMessageBox.Ok) + + def revoke_uid(self): + reply = QMessageBox.warning(self, self.tr("Warning"), + self.tr("""Are you sure ? +Revoking your UID can only success if it is not already validated by the network.""") +.format(self.account.pubkey), QMessageBox.Ok | QMessageBox.Cancel) + if reply == QMessageBox.Ok: + password = self.password_asker.exec_() + if self.password_asker.result() == QDialog.Rejected: + return + + asyncio.async(self.account.revoke(password, self.community)) + def handle_membership_broadcasted(self): if self.app.preferences['notifications']: toast.display(self.tr("Membership"), self.tr("Success sending Membership demand")) diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py index b7fec5a56ccce28460ea8469486ab93d0f0c1ce9..1e23292675857dcb8bca66c45b411bea3fc8e262 100644 --- a/src/cutecoin/gui/mainwindow.py +++ b/src/cutecoin/gui/mainwindow.py @@ -149,7 +149,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.community_view.tab_history.table_history.model().sourceModel().refresh_transfers() def open_certification_dialog(self): - dialog = CertificationDialog(self.app.current_account, + dialog = CertificationDialog(self.app, + self.app.current_account, self.password_asker) dialog.exec_() @@ -231,11 +232,6 @@ class MainWindow(QMainWindow, Ui_MainWindow): version_info=version_info, version_url=version_url)) - def refresh_wallets(self): - currency_tab = self.community_view - if currency_tab: - currency_tab.refresh_wallets() - @pyqtSlot(Community) def change_community(self, community): if self.community_view.community: @@ -312,7 +308,6 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.setWindowTitle(self.tr("CuteCoin {0} - Account : {1}").format(__version__, self.app.current_account.name)) - self.refresh_wallets() self.refresh_contacts() def import_account(self): diff --git a/src/cutecoin/gui/transfer.py b/src/cutecoin/gui/transfer.py index d6ef4c738d22e0fc406cc4d8ba904051a19372be..cbd86f8207649a7582b0f01d931a8046428ac86f 100644 --- a/src/cutecoin/gui/transfer.py +++ b/src/cutecoin/gui/transfer.py @@ -123,16 +123,10 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): self.community = self.account.communities[index] self.dividend = self.community.dividend amount = self.wallet.value(self.community) - ref_amount = self.account.units_to_ref(amount, self.community) - ref_name = self.account.ref_name(self.community.currency) - # if referential type is quantitative... - if self.account.ref_type() == 'q': - # display int values - ref_amount = QLocale().toString(float(ref_amount), 'f', 0) - else: - # display float values - ref_amount = QLocale().toString(float(ref_amount), 'f', 6) - self.label_total.setText("{0} {1}".format(ref_amount, ref_name)) + + ref_text = self.account.current_ref(amount, self.community, self.app)\ + .diff_localized(units=True, international_system=self.app.preferences['international_system_of_units']) + self.label_total.setText("{0}".format(ref_text)) self.spinbox_amount.setSuffix(" " + self.community.currency) self.spinbox_amount.setValue(0) amount = self.wallet.value(self.community) @@ -143,16 +137,9 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): def change_displayed_wallet(self, index): self.wallet = self.account.wallets[index] amount = self.wallet.value(self.community) - ref_amount = self.account.units_to_ref(amount, self.community) - ref_name = self.account.ref_name(self.community.currency) - # if referential type is quantitative... - if self.account.ref_type() == 'q': - # display int values - ref_amount = QLocale().toString(float(ref_amount), 'f', 0) - else: - # display float values - ref_amount = QLocale().toString(float(ref_amount), 'f', 6) - self.label_total.setText("{0} {1}".format(ref_amount, ref_name)) + ref_text = self.account.current_ref(amount, self.community, self.app)\ + .diff_localized(units=True, international_system=self.app.preferences['international_system_of_units']) + self.label_total.setText("{0}".format(ref_text)) self.spinbox_amount.setValue(0) amount = self.wallet.value(self.community) relative = amount / self.dividend diff --git a/src/cutecoin/gui/wallets_tab.py b/src/cutecoin/gui/wallets_tab.py deleted file mode 100644 index ef418735777b5cdedb706cc275b652df011e9b29..0000000000000000000000000000000000000000 --- a/src/cutecoin/gui/wallets_tab.py +++ /dev/null @@ -1,232 +0,0 @@ -""" -Created on 15 févr. 2015 - -@author: inso -""" -import asyncio -import logging - -from PyQt5.QtWidgets import QWidget, QMenu, QAction, QApplication, QDialog, QMessageBox -from PyQt5.QtCore import QDateTime, QModelIndex, Qt, QLocale, QEvent -from PyQt5.QtGui import QCursor - -from ..core.registry import Identity -from ..core.wallet import Wallet -from cutecoin.gui import toast -from ..gui.password_asker import PasswordAskerDialog -from ..models.wallets import WalletsTableModel, WalletsFilterProxyModel -from .transfer import TransferMoneyDialog -from ..tools.exceptions import MembershipNotFoundError, NoPeerAvailable, LookupFailureError -from ..gen_resources.wallets_tab_uic import Ui_WalletsTab - - -class WalletsTabWidget(QWidget, Ui_WalletsTab): - """ - classdocs - """ - - def __init__(self, app): - """ - Init - :param cutecoin.core.app.Application app: Application instance - """ - super().__init__() - self.setupUi(self) - self.app = app - self.account = None - self.community = None - self.password_asker = None - - def change_account(self, account): - self.account = account - - def change_community(self, community): - self.community = community - - def refresh(self): - if self.community: - self.refresh_informations_frame() - self.refresh_wallets() - self.refresh_quality_buttons() - - def refresh_wallets(self): - # TODO: Using reset model instead of destroy/create - wallets_model = WalletsTableModel(self.app, self.community) - proxy_model = WalletsFilterProxyModel() - proxy_model.setSourceModel(wallets_model) - wallets_model.dataChanged.connect(self.wallet_changed) - self.table_wallets.setModel(proxy_model) - self.table_wallets.resizeColumnsToContents() - - def wallet_context_menu(self, point): - index = self.table_wallets.indexAt(point) - model = self.table_wallets.model() - if index.row() < model.rowCount(QModelIndex()): - source_index = model.mapToSource(index) - - name_col = model.sourceModel().columns_types.index('name') - name_index = model.index(index.row(), - name_col) - - pubkey_col = model.sourceModel().columns_types.index('pubkey') - pubkey_index = model.sourceModel().index(source_index.row(), - pubkey_col) - - pubkey = model.sourceModel().data(pubkey_index, Qt.DisplayRole) - menu = QMenu(model.data(index, Qt.DisplayRole), self) - - new_wallet = QAction(self.tr("New Wallet"), self) - new_wallet.triggered.connect(self.new_wallet) - - rename = QAction(self.tr("Rename"), self) - rename.triggered.connect(self.rename_wallet) - rename.setData(name_index) - - copy_pubkey = QAction(self.tr("Copy pubkey to clipboard"), self) - copy_pubkey.triggered.connect(self.copy_pubkey_to_clipboard) - copy_pubkey.setData(pubkey) - - transfer_to = QMenu() - transfer_to.setTitle(self.tr("Transfer to...")) - for w in self.account.wallets: - if w == self.account.wallets[source_index.row()]: - continue - transfer_action = QAction(w.name, self) - transfer_action.triggered.connect(self.transfer_to_wallet) - wallets = (self.account.wallets[source_index.row()], w) - transfer_action.setData(wallets) - transfer_to.addAction(transfer_action) - - menu.addAction(new_wallet) - menu.addAction(rename) - menu.addAction(copy_pubkey) - menu.addMenu(transfer_to) - # Show the context menu. - menu.exec_(QCursor.pos()) - - def new_wallet(self): - """ - Create a new wallet - """ - password_asker = PasswordAskerDialog(self.app.current_account) - password = password_asker.exec_() - if password_asker.result() == QDialog.Rejected: - return None - # create new wallet by increasing wallet pool size - self.account.set_walletpool_size(len(self.account.wallets) + 1, password) - # capture new wallet - wallet = self.account.wallets[len(self.account.wallets) - 1] - # feed cache data of the wallet - wallet.refresh_cache(self.community, list()) - # save wallet cache on disk - self.app.save_wallet(self.account, self.account.wallets[len(self.account.wallets) - 1]) - # save account cache on disk (update number of wallets) - self.app.save(self.account) - # refresh wallet list in gui - self.refresh() - - def rename_wallet(self): - index = self.sender().data() - self.table_wallets.edit(index) - - def wallet_changed(self): - self.table_wallets.resizeColumnsToContents() - self.app.save(self.app.current_account) - - def copy_pubkey_to_clipboard(self): - data = self.sender().data() - clipboard = QApplication.clipboard() - if data.__class__ is Wallet: - clipboard.setText(data.pubkey) - elif data.__class__ is Identity: - clipboard.setText(data.pubkey) - elif data.__class__ is str: - clipboard.setText(data) - - def transfer_to_wallet(self): - wallets = self.sender().data() - dialog = TransferMoneyDialog(self.app, self.account, self.password_asker) - dialog.edit_pubkey.setText(wallets[1].pubkey) - dialog.combo_community.setCurrentText(self.community.name) - dialog.combo_wallets.setCurrentText(wallets[0].name) - dialog.radio_pubkey.setChecked(True) - if dialog.exec_() == QDialog.Accepted: - currency_tab = self.window().currencies_tabwidget.currentWidget() - currency_tab.tab_history.table_history.model().sourceModel().refresh_transfers() - - def publish_uid(self): - reply = QMessageBox.warning(self, self.tr("Warning"), - self.tr("""Are you sure ? -Publishing your UID can be canceled by Revoke UID.""") -.format(self.account.pubkey), QMessageBox.Ok | QMessageBox.Cancel) - if reply == QMessageBox.Ok: - password = self.password_asker.exec_() - if self.password_asker.result() == QDialog.Rejected: - return - - try: - self.account.send_selfcert(password, self.community) - toast.display(self.tr("UID Publishing"), - self.tr("Success publishing your UID")) - except ValueError as e: - QMessageBox.critical(self, self.tr("Publish UID error"), - str(e)) - except NoPeerAvailable as e: - QMessageBox.critical(self, self.tr("Network error"), - self.tr("Couldn't connect to network : {0}").format(e), - QMessageBox.Ok) - # except Exception as e: - # QMessageBox.critical(self, self.tr("Error"), - # "{0}".format(e), - # QMessageBox.Ok) - - def revoke_uid(self): - reply = QMessageBox.warning(self, self.tr("Warning"), - self.tr("""Are you sure ? -Revoking your UID can only success if it is not already validated by the network.""") -.format(self.account.pubkey), QMessageBox.Ok | QMessageBox.Cancel) - if reply == QMessageBox.Ok: - password = self.password_asker.exec_() - if self.password_asker.result() == QDialog.Rejected: - return - - asyncio.async(self.account.revoke(password, self.community)) - - def refresh_quality_buttons(self): - try: - if self.account.identity(self.community).published_uid(self.community): - logging.debug("UID Published") - if self.account.identity(self.community).is_member(self.community): - self.button_membership.setText(self.tr("Renew membership")) - self.button_membership.show() - self.button_publish_uid.hide() - self.button_leaving.show() - self.button_revoke_uid.hide() - else: - logging.debug("Not a member") - self.button_membership.setText(self.tr("Send membership demand")) - self.button_membership.show() - self.button_revoke_uid.show() - self.button_leaving.hide() - self.button_publish_uid.hide() - else: - logging.debug("UID not published") - self.button_membership.hide() - self.button_leaving.hide() - self.button_publish_uid.show() - self.button_revoke_uid.hide() - except LookupFailureError: - self.button_membership.hide() - self.button_leaving.hide() - self.button_publish_uid.show() - - def changeEvent(self, event): - """ - Intercepte LanguageChange event to translate UI - :param QEvent QEvent: Event - :return: - """ - if event.type() == QEvent.LanguageChange: - self.retranslateUi(self) - self.refresh() - return super(WalletsTabWidget, self).changeEvent(event)