Skip to content
Snippets Groups Projects
Commit bc20b773 authored by inso's avatar inso
Browse files

Finally, UI refactoring

parent 08e817bc
No related branches found
No related tags found
No related merge requests found
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>532</width> <width>624</width>
<height>313</height> <height>429</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
......
...@@ -16,7 +16,7 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): ...@@ -16,7 +16,7 @@ class CertificationDialog(QDialog, Ui_CertificationDialog):
classdocs classdocs
""" """
def __init__(self, certifier, app, password_asker): def __init__(self, app, certifier, password_asker):
""" """
Constructor Constructor
""" """
......
...@@ -13,14 +13,11 @@ from PyQt5.QtGui import QIcon ...@@ -13,14 +13,11 @@ from PyQt5.QtGui import QIcon
from ..core.net.api import bma as qtbma from ..core.net.api import bma as qtbma
from .wot_tab import WotTabWidget from .wot_tab import WotTabWidget
from .identities_tab import IdentitiesTabWidget from .identities_tab import IdentitiesTabWidget
from .wallets_tab import WalletsTabWidget
from .transactions_tab import TransactionsTabWidget from .transactions_tab import TransactionsTabWidget
from .network_tab import NetworkTabWidget from .network_tab import NetworkTabWidget
from .informations_tab import InformationsTabWidget
from . import toast from . import toast
import asyncio import asyncio
from ..tools.exceptions import MembershipNotFoundError, NoPeerAvailable from ..tools.exceptions import MembershipNotFoundError, LookupFailureError
from ..core.registry import IdentitiesRegistry
from ..gen_resources.community_view_uic import Ui_CommunityWidget from ..gen_resources.community_view_uic import Ui_CommunityWidget
...@@ -53,8 +50,6 @@ class CommunityWidget(QWidget, Ui_CommunityWidget): ...@@ -53,8 +50,6 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
self.tab_identities = IdentitiesTabWidget(self.app) self.tab_identities = IdentitiesTabWidget(self.app)
self.tab_wallets = WalletsTabWidget(self.app)
self.tab_history = TransactionsTabWidget(self.app) self.tab_history = TransactionsTabWidget(self.app)
self.tab_network = NetworkTabWidget(self.app) self.tab_network = NetworkTabWidget(self.app)
...@@ -96,6 +91,7 @@ class CommunityWidget(QWidget, Ui_CommunityWidget): ...@@ -96,6 +91,7 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
community.inner_data_changed.connect(self.refresh_status) community.inner_data_changed.connect(self.refresh_status)
self.label_currency.setText(community.currency) self.label_currency.setText(community.currency)
self.community = community self.community = community
self.refresh_quality_buttons()
@pyqtSlot(str) @pyqtSlot(str)
def display_error(self, error): def display_error(self, error):
...@@ -143,17 +139,13 @@ class CommunityWidget(QWidget, Ui_CommunityWidget): ...@@ -143,17 +139,13 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
self.tab_history.start_progress() self.tab_history.start_progress()
self.refresh_data() self.refresh_data()
def refresh_wallets(self): def refresh_quality_buttons(self):
if self.tab_wallets: pass
self.tab_wallets.refresh()
def refresh_data(self): def refresh_data(self):
""" """
Refresh data when the blockchain watcher finished handling datas Refresh data when the blockchain watcher finished handling datas
""" """
if self.tab_wallets:
self.tab_wallets.refresh()
self.tab_history.refresh_balance() self.tab_history.refresh_balance()
self.refresh_status() self.refresh_status()
...@@ -190,6 +182,28 @@ class CommunityWidget(QWidget, Ui_CommunityWidget): ...@@ -190,6 +182,28 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
self.status_label.setText(label_text) 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): def showEvent(self, event):
self.refresh_status() self.refresh_status()
...@@ -220,6 +234,44 @@ The process to join back the community later will have to be done again.""") ...@@ -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')) 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): def handle_membership_broadcasted(self):
if self.app.preferences['notifications']: if self.app.preferences['notifications']:
toast.display(self.tr("Membership"), self.tr("Success sending Membership demand")) toast.display(self.tr("Membership"), self.tr("Success sending Membership demand"))
......
...@@ -149,7 +149,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -149,7 +149,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.community_view.tab_history.table_history.model().sourceModel().refresh_transfers() self.community_view.tab_history.table_history.model().sourceModel().refresh_transfers()
def open_certification_dialog(self): def open_certification_dialog(self):
dialog = CertificationDialog(self.app.current_account, dialog = CertificationDialog(self.app,
self.app.current_account,
self.password_asker) self.password_asker)
dialog.exec_() dialog.exec_()
...@@ -231,11 +232,6 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -231,11 +232,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
version_info=version_info, version_info=version_info,
version_url=version_url)) version_url=version_url))
def refresh_wallets(self):
currency_tab = self.community_view
if currency_tab:
currency_tab.refresh_wallets()
@pyqtSlot(Community) @pyqtSlot(Community)
def change_community(self, community): def change_community(self, community):
if self.community_view.community: if self.community_view.community:
...@@ -312,7 +308,6 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -312,7 +308,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.setWindowTitle(self.tr("CuteCoin {0} - Account : {1}").format(__version__, self.setWindowTitle(self.tr("CuteCoin {0} - Account : {1}").format(__version__,
self.app.current_account.name)) self.app.current_account.name))
self.refresh_wallets()
self.refresh_contacts() self.refresh_contacts()
def import_account(self): def import_account(self):
......
...@@ -123,16 +123,10 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): ...@@ -123,16 +123,10 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
self.community = self.account.communities[index] self.community = self.account.communities[index]
self.dividend = self.community.dividend self.dividend = self.community.dividend
amount = self.wallet.value(self.community) 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) ref_text = self.account.current_ref(amount, self.community, self.app)\
# if referential type is quantitative... .diff_localized(units=True, international_system=self.app.preferences['international_system_of_units'])
if self.account.ref_type() == 'q': self.label_total.setText("{0}".format(ref_text))
# 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))
self.spinbox_amount.setSuffix(" " + self.community.currency) self.spinbox_amount.setSuffix(" " + self.community.currency)
self.spinbox_amount.setValue(0) self.spinbox_amount.setValue(0)
amount = self.wallet.value(self.community) amount = self.wallet.value(self.community)
...@@ -143,16 +137,9 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): ...@@ -143,16 +137,9 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
def change_displayed_wallet(self, index): def change_displayed_wallet(self, index):
self.wallet = self.account.wallets[index] self.wallet = self.account.wallets[index]
amount = self.wallet.value(self.community) amount = self.wallet.value(self.community)
ref_amount = self.account.units_to_ref(amount, self.community) ref_text = self.account.current_ref(amount, self.community, self.app)\
ref_name = self.account.ref_name(self.community.currency) .diff_localized(units=True, international_system=self.app.preferences['international_system_of_units'])
# if referential type is quantitative... self.label_total.setText("{0}".format(ref_text))
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))
self.spinbox_amount.setValue(0) self.spinbox_amount.setValue(0)
amount = self.wallet.value(self.community) amount = self.wallet.value(self.community)
relative = amount / self.dividend relative = amount / self.dividend
......
"""
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment