diff --git a/res/ui/community_tab.ui b/res/ui/community_tab.ui deleted file mode 100644 index 43eb5750042ac2493427e536b2e9837890c72624..0000000000000000000000000000000000000000 --- a/res/ui/community_tab.ui +++ /dev/null @@ -1,147 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>CommunityTabWidget</class> - <widget class="QWidget" name="CommunityTabWidget"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>636</width> - <height>404</height> - </rect> - </property> - <property name="contextMenuPolicy"> - <enum>Qt::DefaultContextMenu</enum> - </property> - <property name="windowTitle"> - <string>communityTabWidget</string> - </property> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QTabWidget" name="tabs_information"> - <property name="currentIndex"> - <number>0</number> - </property> - <property name="iconSize"> - <size> - <width>20</width> - <height>20</height> - </size> - </property> - <property name="elideMode"> - <enum>Qt::ElideNone</enum> - </property> - <widget class="QWidget" name="tab_members"> - <attribute name="icon"> - <iconset resource="../icons/icons.qrc"> - <normaloff>:/icons/members_icon</normaloff>:/icons/members_icon</iconset> - </attribute> - <attribute name="title"> - <string>Identities</string> - </attribute> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <layout class="QVBoxLayout" name="verticalLayout_6"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <property name="topMargin"> - <number>0</number> - </property> - <item> - <widget class="QLineEdit" name="edit_textsearch"> - <property name="placeholderText"> - <string>Research a pubkey, an uid...</string> - </property> - </widget> - </item> - <item> - <widget class="QToolButton" name="button_search"> - <property name="text"> - <string>Search</string> - </property> - <property name="popupMode"> - <enum>QToolButton::MenuButtonPopup</enum> - </property> - <property name="toolButtonStyle"> - <enum>Qt::ToolButtonTextBesideIcon</enum> - </property> - </widget> - </item> - </layout> - </item> - <item> - <widget class="QTableView" name="table_identities"> - <property name="contextMenuPolicy"> - <enum>Qt::CustomContextMenu</enum> - </property> - <property name="alternatingRowColors"> - <bool>true</bool> - </property> - <property name="sortingEnabled"> - <bool>true</bool> - </property> - <attribute name="horizontalHeaderShowSortIndicator" stdset="0"> - <bool>true</bool> - </attribute> - <attribute name="horizontalHeaderStretchLastSection"> - <bool>true</bool> - </attribute> - <attribute name="verticalHeaderVisible"> - <bool>false</bool> - </attribute> - </widget> - </item> - </layout> - </item> - </layout> - </widget> - </widget> - </item> - </layout> - </widget> - <resources> - <include location="../icons/icons.qrc"/> - </resources> - <connections> - <connection> - <sender>edit_textsearch</sender> - <signal>returnPressed()</signal> - <receiver>CommunityTabWidget</receiver> - <slot>search_text()</slot> - <hints> - <hint type="sourcelabel"> - <x>170</x> - <y>62</y> - </hint> - <hint type="destinationlabel"> - <x>215</x> - <y>184</y> - </hint> - </hints> - </connection> - <connection> - <sender>button_search</sender> - <signal>clicked()</signal> - <receiver>CommunityTabWidget</receiver> - <slot>search_text()</slot> - <hints> - <hint type="sourcelabel"> - <x>371</x> - <y>62</y> - </hint> - <hint type="destinationlabel"> - <x>215</x> - <y>184</y> - </hint> - </hints> - </connection> - </connections> - <slots> - <slot>identity_context_menu(QPoint)</slot> - <slot>send_membership_demand()</slot> - <slot>send_membership_leaving()</slot> - <slot>search_text()</slot> - <slot>publish_uid()</slot> - <slot>revoke_uid()</slot> - </slots> -</ui> diff --git a/res/ui/community_view.ui b/res/ui/community_view.ui new file mode 100644 index 0000000000000000000000000000000000000000..18889b02c27f5dd4435566e75454ea189633adb8 --- /dev/null +++ b/res/ui/community_view.ui @@ -0,0 +1,81 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>CommunityWidget</class> + <widget class="QWidget" name="CommunityWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QFrame" name="frame"> + <property name="frameShape"> + <enum>QFrame::StyledPanel</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Raised</enum> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QPushButton" name="button_home"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset> + <normaloff>../icons/iconmonstr-home-icon.svg</normaloff>../icons/iconmonstr-home-icon.svg</iconset> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_currency"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="button_send_money"> + <property name="text"> + <string>Send money</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="button_certification"> + <property name="text"> + <string>Certification</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="button_membership"> + <property name="text"> + <string>Renew membership</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QTabWidget" name="tabs"/> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/res/ui/identities_tab.ui b/res/ui/identities_tab.ui new file mode 100644 index 0000000000000000000000000000000000000000..5f3f2e072c5778a32cbea7c6f2bfc1b77a0750c5 --- /dev/null +++ b/res/ui/identities_tab.ui @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>IdentitiesTab</class> + <widget class="QWidget" name="IdentitiesTab"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <property name="topMargin"> + <number>0</number> + </property> + <item> + <widget class="QLineEdit" name="edit_textsearch"> + <property name="placeholderText"> + <string>Research a pubkey, an uid...</string> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="button_search"> + <property name="text"> + <string>Search</string> + </property> + <property name="popupMode"> + <enum>QToolButton::MenuButtonPopup</enum> + </property> + <property name="toolButtonStyle"> + <enum>Qt::ToolButtonTextBesideIcon</enum> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QTableView" name="table_identities"> + <property name="contextMenuPolicy"> + <enum>Qt::CustomContextMenu</enum> + </property> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> + <property name="sortingEnabled"> + <bool>true</bool> + </property> + <attribute name="horizontalHeaderShowSortIndicator" stdset="0"> + <bool>true</bool> + </attribute> + <attribute name="horizontalHeaderStretchLastSection"> + <bool>true</bool> + </attribute> + <attribute name="verticalHeaderVisible"> + <bool>false</bool> + </attribute> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/res/ui/mainwindow.ui b/res/ui/mainwindow.ui index 10a981179bce626465efa75b0e808ce99f8672bb..f30bd087938b923932b71797e41fda4dc494a2ec 100644 --- a/res/ui/mainwindow.ui +++ b/res/ui/mainwindow.ui @@ -14,18 +14,7 @@ <string notr="true">CuteCoin</string> </property> <widget class="QWidget" name="centralwidget"> - <layout class="QVBoxLayout" name="verticalLayout_6"> - <item> - <widget class="QTabWidget" name="currencies_tabwidget"> - <property name="iconSize"> - <size> - <width>24</width> - <height>24</height> - </size> - </property> - </widget> - </item> - </layout> + <layout class="QVBoxLayout" name="verticalLayout_6"/> </widget> <widget class="QMenuBar" name="menubar"> <property name="geometry"> @@ -33,7 +22,7 @@ <x>0</x> <y>0</y> <width>681</width> - <height>25</height> + <height>29</height> </rect> </property> <widget class="QMenu" name="menu_file"> @@ -48,11 +37,11 @@ </widget> <widget class="QMenu" name="menu_account"> <property name="title"> - <string>Account</string> + <string>Acco&unt</string> </property> <widget class="QMenu" name="menu_contacts_list"> <property name="title"> - <string>&Contacts</string> + <string>Co&ntacts</string> </property> <addaction name="separator"/> </widget> @@ -94,7 +83,7 @@ </action> <action name="action_add_a_contact"> <property name="text"> - <string>&Add a contact</string> + <string>A&dd a contact</string> </property> </action> <action name="actionSend_a_message"> @@ -164,7 +153,7 @@ </action> <action name="actionCertification"> <property name="text"> - <string>&Certification</string> + <string>C&ertification</string> </property> </action> <action name="action_set_as_default"> diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/community_view.py similarity index 58% rename from src/cutecoin/gui/currency_tab.py rename to src/cutecoin/gui/community_view.py index 7394d39b7cb35cfc30bdf28bb27aef33978a4003..61ab15dc5ff1ed6f1cd42c7e1941e4f511a9739e 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/community_view.py @@ -9,10 +9,10 @@ import logging from PyQt5.QtWidgets import QWidget, QMessageBox from PyQt5.QtCore import QModelIndex, pyqtSlot, QDateTime, QLocale, QEvent from PyQt5.QtGui import QIcon -from ..gen_resources.currency_tab_uic import Ui_CurrencyTabWidget from ..core.net.api import bma as qtbma -from .community_tab import CommunityTabWidget +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 @@ -21,22 +21,22 @@ from . import toast import asyncio from ..tools.exceptions import MembershipNotFoundError, NoPeerAvailable from ..core.registry import IdentitiesRegistry +from ..gen_resources.community_view_uic import Ui_CommunityWidget - -class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): +class CommunityWidget(QWidget, Ui_CommunityWidget): """ classdocs """ - def __init__(self, app, community, password_asker, status_label): + def __init__(self, app, status_label): """ Constructor """ super().__init__() self.app = app - self.community = community - self.password_asker = password_asker + self.community = None + self.password_asker = None self.status_label = status_label self.status_info = [] @@ -48,47 +48,43 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): super().setupUi(self) - self.tab_community = CommunityTabWidget(self.app, - self.app.current_account, - self.community, - self.password_asker, - self) - - self.tab_wallets = WalletsTabWidget(self.app, - self.app.current_account, - self.community, - self.password_asker) + self.tab_wot = WotTabWidget(self.app) - self.tab_history = TransactionsTabWidget(self.app, - self.community, - self.password_asker, - self) + self.tab_identities = IdentitiesTabWidget(self.app) - self.tab_informations = InformationsTabWidget(self.app, - self.community) + self.tab_wallets = WalletsTabWidget(self.app) - self.tab_network = NetworkTabWidget(self.app, - self.community) + self.tab_history = TransactionsTabWidget(self.app) - self.tabs_account.addTab(self.tab_wallets, - QIcon(':/icons/wallet_icon'), - self.tr("Wallets")) + self.tab_network = NetworkTabWidget(self.app) - self.tabs_account.addTab(self.tab_history, + self.tabs.addTab(self.tab_history, QIcon(':/icons/tx_icon'), self.tr("Transactions")) - self.tabs_account.addTab(self.tab_community, - QIcon(':/icons/community_icon'), - self.tr("Community")) + self.tabs.addTab(self.tab_identities, + QIcon(':/icons/wot_icon'), + self.tr("Web of Trust")) - self.tabs_account.addTab(self.tab_network, + self.tabs.addTab(self.tab_wot, + QIcon(':/icons/members_icon'), + self.tr("Search Identities")) + + self.tabs.addTab(self.tab_network, QIcon(":/icons/network_icon"), self.tr("Network")) - self.tabs_account.addTab(self.tab_informations, - QIcon(':/icons/informations_icon'), - self.tr("Informations")) + def change_account(self, account): + self.account = account + self.tab_wot.change_account(account) + self.tab_identities.change_account(account) + + def change_community(self, community): + self.community = community + self.tab_network.change_community(community) + self.tab_wot.change_community(community) + self.tab_history.change_community(community) + self.tab_identities.change_community(community) self.community.network.new_block_mined.connect(self.refresh_block) self.community.network.nodes_changed.connect(self.refresh_status) @@ -160,31 +156,32 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): Refresh status bar """ logging.debug("Refresh status") - text = self.tr(" Block {0}").format(self.community.network.latest_block_number) - - block = self.community.get_block(self.community.network.latest_block_number) - if block != qtbma.blockchain.Block.null_value: - text += " ( {0} )".format(QLocale.toString( - QLocale(), - QDateTime.fromTime_t(block['medianTime']), - QLocale.dateTimeFormat(QLocale(), QLocale.NarrowFormat) - )) - - if self.community.network.quality > 0.66: - icon = '<img src=":/icons/connected" width="12" height="12"/>' - elif self.community.network.quality > 0.33: - icon = '<img src=":/icons/weak_connect" width="12" height="12"/>' - else: - icon = '<img src=":/icons/disconnected" width="12" height="12"/>' - status_infotext = " - ".join([self.status_infotext[info] for info in self.status_info]) - label_text = "{0}{1}".format(icon, text) - if status_infotext != "": - label_text += " - {0}".format(status_infotext) - - if self.app.preferences['expert_mode']: - label_text += self.tr(" - Median fork window : {0}").format(self.community.network.fork_window(self.community.members_pubkeys())) - - self.status_label.setText(label_text) + if self.community: + text = self.tr(" Block {0}").format(self.community.network.latest_block_number) + + block = self.community.get_block(self.community.network.latest_block_number) + if block != qtbma.blockchain.Block.null_value: + text += " ( {0} )".format(QLocale.toString( + QLocale(), + QDateTime.fromTime_t(block['medianTime']), + QLocale.dateTimeFormat(QLocale(), QLocale.NarrowFormat) + )) + + if self.community.network.quality > 0.66: + icon = '<img src=":/icons/connected" width="12" height="12"/>' + elif self.community.network.quality > 0.33: + icon = '<img src=":/icons/weak_connect" width="12" height="12"/>' + else: + icon = '<img src=":/icons/disconnected" width="12" height="12"/>' + status_infotext = " - ".join([self.status_infotext[info] for info in self.status_info]) + label_text = "{0}{1}".format(icon, text) + if status_infotext != "": + label_text += " - {0}".format(status_infotext) + + if self.app.preferences['expert_mode']: + label_text += self.tr(" - Median fork window : {0}").format(self.community.network.fork_window(self.community.members_pubkeys())) + + self.status_label.setText(label_text) def showEvent(self, event): self.refresh_status() @@ -197,12 +194,6 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): []) self.tab_history.refresh_balance() - if self.tab_wallets: - self.tab_wallets.refresh() - - if self.tab_informations: - self.tab_informations.refresh() - def changeEvent(self, event): """ Intercepte LanguageChange event to translate UI @@ -212,4 +203,4 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): if event.type() == QEvent.LanguageChange: self.retranslateUi(self) self.refresh_status() - return super(CurrencyTabWidget, self).changeEvent(event) + return super(CommunityWidget, self).changeEvent(event) diff --git a/src/cutecoin/gui/homescreen.py b/src/cutecoin/gui/homescreen.py index bc76177f3051ede15baff4d81518198d8f439c10..864e7f199857ed773e8a02781d899df2e54cd247 100644 --- a/src/cutecoin/gui/homescreen.py +++ b/src/cutecoin/gui/homescreen.py @@ -5,12 +5,16 @@ Created on 31 janv. 2015 """ from PyQt5.QtWidgets import QWidget, QFrame, QGridLayout, QLayout -from PyQt5.QtCore import QEvent, Qt +from PyQt5.QtCore import QEvent, Qt, pyqtSlot, pyqtSignal from ..gen_resources.homescreen_uic import Ui_HomescreenWidget from .community_tile import CommunityTile +from ..core.community import Community +import logging class FrameCommunities(QFrame): + community_tile_clicked = pyqtSignal(Community) + def __init__(self, parent): super().__init__(parent) self.grid_layout = QGridLayout() @@ -27,7 +31,15 @@ class FrameCommunities(QFrame): self.grid_layout.itemAt(i).widget().setParent(None) for c in app.current_account.communities: - self.layout().addWidget(CommunityTile(self, app, c)) + community_tile = CommunityTile(self, app, c) + community_tile.clicked.connect(self.click_on_tile) + self.layout().addWidget(community_tile) + + @pyqtSlot() + def click_on_tile(self): + tile = self.sender() + logging.debug("Click on tile") + self.community_tile_clicked.emit(tile.community) class HomeScreenWidget(QWidget, Ui_HomescreenWidget): diff --git a/src/cutecoin/gui/community_tab.py b/src/cutecoin/gui/identities_tab.py similarity index 93% rename from src/cutecoin/gui/community_tab.py rename to src/cutecoin/gui/identities_tab.py index 6d733008d442f0be45285d0bb49db3d491e35146..a5e5e41298baac07140ee665d44fb4606e523b02 100644 --- a/src/cutecoin/gui/community_tab.py +++ b/src/cutecoin/gui/identities_tab.py @@ -10,7 +10,7 @@ from PyQt5.QtGui import QIcon, QCursor from PyQt5.QtWidgets import QWidget, QMessageBox, QAction, QMenu, QDialog, \ QAbstractItemView from cutecoin.models.identities import IdentitiesFilterProxyModel, IdentitiesTableModel -from ..gen_resources.community_tab_uic import Ui_CommunityTabWidget +from ..gen_resources.identities_tab_uic import Ui_IdentitiesTab from cutecoin.gui.contact import ConfigureContactDialog from cutecoin.gui.member import MemberDialog from .wot_tab import WotTabWidget @@ -21,27 +21,25 @@ import asyncio from ..core.net.api import bma as qtbma -class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): +class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab): """ classdocs """ - def __init__(self, app, account, community, password_asker, parent): + def __init__(self, app): """ Init :param cutecoin.core.account.Account account: Account instance :param cutecoin.core.community.Community community: Community instance :param cutecoin.gui.password_asker.PasswordAskerDialog password_asker: Password asker dialog - :param cutecoin.gui.currency_tab.CurrencyTabWidget parent: TabWidget instance :return: """ super().__init__() - self.parent = parent self.app = app - self.community = community - self.account = account - self.password_asker = password_asker + self.community = None + self.account = None + self.password_asker = None self.setupUi(self) @@ -54,8 +52,6 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): self.table_identities.sortByColumn(0, Qt.AscendingOrder) self.table_identities.resizeColumnsToContents() - self.wot_tab = WotTabWidget(self.app, self.account, self.community, self.password_asker, self) - self.tabs_information.addTab(self.wot_tab, QIcon(':/icons/wot_icon'), self.tr("Web of Trust")) members_action = QAction(self.tr("Members"), self) members_action.triggered.connect(self.search_members) self.button_search.addAction(members_action) @@ -63,12 +59,17 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): direct_connections.triggered.connect(self.search_direct_connections) self.button_search.addAction(direct_connections) - self.account.identity(self.community).inner_data_changed.connect(self.handle_account_identity_change) - self.search_direct_connections() + def change_account(self, account): + self.account = account self.account.membership_broadcasted.connect(self.handle_membership_broadcasted) self.account.revoke_broadcasted.connect(self.handle_revoke_broadcasted) self.account.selfcert_broadcasted.connect(self.handle_selfcert_broadcasted) + def change_community(self, community): + self.community = community + self.table_identities.model().change_community(community) + self.account.identity(self.community).inner_data_changed.connect(self.handle_account_identity_change) + def handle_membership_broadcasted(self): if self.app.preferences['notifications']: toast.display(self.tr("Membership"), self.tr("Success sending Membership demand")) @@ -179,8 +180,6 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): # redraw WoT with this identity selected self.wot_tab.draw_graph({'text': person.uid, 'id': person.pubkey}) # change page to WoT - index_community_tab = self.parent.tabs_account.indexOf(self) - self.parent.tabs_account.setCurrentIndex(index_community_tab) index_wot_tab = self.tabs_information.indexOf(self.wot_tab) self.tabs_information.setCurrentIndex(index_wot_tab) @@ -292,5 +291,5 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): """ if event.type() == QEvent.LanguageChange: self.retranslateUi(self) - return super(CommunityTabWidget, self).changeEvent(event) + return super(IdentitiesTabWidget, self).changeEvent(event) diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py index fa463cb8221161de190430153097eb5df822d68f..d53e4e391c6425b86ffac7ca71d8c0ff0a59e922 100644 --- a/src/cutecoin/gui/mainwindow.py +++ b/src/cutecoin/gui/mainwindow.py @@ -14,7 +14,7 @@ from PyQt5.QtGui import QIcon, QDesktopServices from .process_cfg_account import ProcessConfigureAccount from .transfer import TransferMoneyDialog -from .currency_tab import CurrencyTabWidget +from .community_view import CommunityWidget from .contact import ConfigureContactDialog from .import_account import ImportAccountDialog from .certification import CertificationDialog @@ -22,6 +22,7 @@ from .password_asker import PasswordAskerDialog from .preferences import PreferencesDialog from .homescreen import HomeScreenWidget from ..core import money +from ..core.community import Community from ..__init__ import __version__ from . import toast @@ -65,8 +66,12 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.statusbar.addPermanentWidget(self.combo_referential) self.homescreen = HomeScreenWidget(self.app) + self.homescreen.frame_communities.community_tile_clicked.connect(self.change_community) self.centralWidget().layout().addWidget(self.homescreen) + self.community_view = CommunityWidget(self.app, self.status_label) + self.centralWidget().layout().addWidget(self.community_view) + def startup(self): self.update_time() self.app.get_last_version() @@ -74,6 +79,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.showMaximized() else: self.show() + if self.app.current_account: + self.community_view.change_account(self.app.current_account) self.refresh() def open_add_account_dialog(self): @@ -92,8 +99,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): def referential_changed(self, index): if self.app.current_account: self.app.current_account.set_display_referential(index) - if self.currencies_tabwidget.currentWidget(): - self.currencies_tabwidget.currentWidget().referential_changed() + if self.community_view: + self.community_view.referential_changed() @pyqtSlot() def update_time(self): @@ -123,27 +130,15 @@ class MainWindow(QMainWindow, Ui_MainWindow): def action_change_account(self, account_name): self.app.change_current_account(self.app.get_account(account_name)) + self.community_view.change_account(self.app.current_account) self.refresh() - @pyqtSlot() - def loader_finished(self): - logging.debug("Finished loading") - self.refresh() - self.busybar.hide() - QApplication.setOverrideCursor(Qt.ArrowCursor) - try: - self.app.disconnect() - except: - logging.debug("Disconnect of app failed") - - QApplication.processEvents() - def open_transfer_money_dialog(self): dialog = TransferMoneyDialog(self.app, self.app.current_account, self.password_asker) dialog.accepted.connect(self.refresh_wallets) if dialog.exec_() == QDialog.Accepted: - currency_tab = self.currencies_tabwidget.currentWidget() + currency_tab = self.community_view currency_tab.tab_history.table_history.model().sourceModel().refresh_transfers() def open_certification_dialog(self): @@ -230,21 +225,16 @@ class MainWindow(QMainWindow, Ui_MainWindow): version_url=version_url)) def refresh_wallets(self): - currency_tab = self.currencies_tabwidget.currentWidget() + currency_tab = self.community_view if currency_tab: currency_tab.refresh_wallets() - def refresh_communities(self): - logging.debug("CLEAR") - self.currencies_tabwidget.clear() - if self.app.current_account: - for community in self.app.current_account.communities: - tab_currency = CurrencyTabWidget(self.app, community, - self.password_asker, - self.status_label) - self.currencies_tabwidget.addTab(tab_currency, - QIcon(":/icons/currency_icon"), - community.name) + @pyqtSlot(Community) + def change_community(self, community): + logging.debug("Change on tile") + self.homescreen.hide() + self.community_view.show() + self.community_view.change_community(community) def refresh_accounts(self): self.menu_change_account.clear() @@ -278,7 +268,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): logging.debug("Refresh started") self.refresh_accounts() self.homescreen.show() - self.currencies_tabwidget.hide() + self.community_view.hide() self.homescreen.refresh() if self.app.current_account is None: @@ -306,7 +296,6 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.setWindowTitle(self.tr("CuteCoin {0} - Account : {1}").format(__version__, self.app.current_account.name)) - self.refresh_communities() self.refresh_wallets() self.refresh_contacts() diff --git a/src/cutecoin/gui/network_tab.py b/src/cutecoin/gui/network_tab.py index efdd76241b36ecf1c0ea98b97738de9d41b9f1a8..8021fa81a7c33d738d715fd575d772f820a25df0 100644 --- a/src/cutecoin/gui/network_tab.py +++ b/src/cutecoin/gui/network_tab.py @@ -20,26 +20,29 @@ class NetworkTabWidget(QWidget, Ui_NetworkTabWidget): classdocs """ - def __init__(self, app, community): + def __init__(self, app): """ Constructore of a network tab. :param cutecoin.core.Application app: The application - :param cutecoin.core.Community community: The community :return: A new network tab. :rtype: NetworkTabWidget """ super().__init__() self.app = app - self.community = community + self.community = None self.setupUi(self) - model = NetworkTableModel(community) + model = NetworkTableModel(self.community) proxy = NetworkFilterProxyModel(self) proxy.setSourceModel(model) self.table_network.setModel(proxy) self.table_network.sortByColumn(0, Qt.DescendingOrder) self.table_network.resizeColumnsToContents() + + def change_community(self, community): + self.community = community + self.table_network.model().change_community(community) community.network.nodes_changed.connect(self.refresh_nodes) @pyqtSlot() diff --git a/src/cutecoin/gui/transactions_tab.py b/src/cutecoin/gui/transactions_tab.py index 50eaa7deb36d77fb3bef5986899db15ef05b2c31..d277810023e316f810b2b6f7edc84c143f5d9c79 100644 --- a/src/cutecoin/gui/transactions_tab.py +++ b/src/cutecoin/gui/transactions_tab.py @@ -18,27 +18,27 @@ class TransactionsTabWidget(QWidget, Ui_transactionsTabWidget): classdocs """ - def __init__(self, app, community, password_asker, currency_tab): + def __init__(self, app): """ Init :param cutecoin.core.app.Application app: Application instance - :param cutecoin.core.community.Community community: Community instance - :param cutecoin.gui.password_asker.PasswordAskerDialog password_asker: Password dialog instance - :param cutecoin.gui.currency_tab.CurrencyTabWidget currency_tab: Currency tab widget :return: """ super().__init__() self.setupUi(self) self.app = app - self.community = community - self.password_asker = password_asker - self.currency_tab = currency_tab + self.community = None + self.password_asker = None self.progressbar.hide() - self.community.inner_data_changed.connect(self.refresh_minimum_maximum) self.refresh() + def change_community(self, community): + self.community = community + self.refresh() + self.community.inner_data_changed.connect(self.refresh_minimum_maximum) + def refresh_minimum_maximum(self): block = self.community.get_block(1) minimum_datetime = QDateTime() @@ -56,23 +56,24 @@ class TransactionsTabWidget(QWidget, Ui_transactionsTabWidget): def refresh(self): #TODO: Use resetmodel instead of destroy/create - self.refresh_minimum_maximum() - ts_from = self.date_from.dateTime().toTime_t() - ts_to = self.date_to.dateTime().toTime_t() - - model = HistoryTableModel(self.app, self.community) - proxy = TxFilterProxyModel(ts_from, ts_to) - proxy.setSourceModel(model) - proxy.setDynamicSortFilter(True) - proxy.setSortRole(Qt.DisplayRole) - - self.table_history.setModel(proxy) - self.table_history.setSelectionBehavior(QAbstractItemView.SelectRows) - self.table_history.setSortingEnabled(True) - self.table_history.horizontalHeader().setSectionResizeMode(QHeaderView.Interactive) - self.table_history.resizeColumnsToContents() + if self.community: + self.refresh_minimum_maximum() + ts_from = self.date_from.dateTime().toTime_t() + ts_to = self.date_to.dateTime().toTime_t() + + model = HistoryTableModel(self.app, self.community) + proxy = TxFilterProxyModel(ts_from, ts_to) + proxy.setSourceModel(model) + proxy.setDynamicSortFilter(True) + proxy.setSortRole(Qt.DisplayRole) + + self.table_history.setModel(proxy) + self.table_history.setSelectionBehavior(QAbstractItemView.SelectRows) + self.table_history.setSortingEnabled(True) + self.table_history.horizontalHeader().setSectionResizeMode(QHeaderView.Interactive) + self.table_history.resizeColumnsToContents() - self.refresh_balance() + self.refresh_balance() def start_progress(self): def progressing(value, maximum): @@ -100,34 +101,59 @@ class TransactionsTabWidget(QWidget, Ui_transactionsTabWidget): self.table_history.resizeColumnsToContents() def refresh_balance(self): - # if referential is "units" - if self.app.current_account._current_ref == 0: - self.label_balance.show() - self.label_deposit.show() - self.label_payment.show() + if self.app.preferences['expert_mode']: + # if referential is "units" + if self.app.current_account._current_ref == 0: + self.label_balance.show() + self.label_deposit.show() + self.label_payment.show() + else: + self.label_balance.hide() + self.label_deposit.hide() + self.label_payment.hide() + + proxy = self.table_history.model() + balance = proxy.deposits - proxy.payments + localized_deposits = self.app.current_account.current_ref(proxy.deposits, self.community, self.app).diff_localized() + localized_payments = self.app.current_account.current_ref(proxy.payments, self.community, self.app).diff_localized() + localized_balance = self.app.current_account.current_ref(balance, self.community, self.app).diff_localized() + + self.label_deposit.setText(QCoreApplication.translate("TransactionsTabWidget", "<b>Deposits</b> {:} {:}").format( + localized_deposits, + self.app.current_account.current_ref.units(self.community.short_currency) + )) + self.label_payment.setText(QCoreApplication.translate("TransactionsTabWidget", "<b>Payments</b> {:} {:}").format( + localized_payments, + self.app.current_account.current_ref.units(self.community.short_currency) + )) + self.label_balance.setText(QCoreApplication.translate("TransactionsTabWidget", "<b>Balance</b> {:} {:}").format( + localized_balance, + self.app.current_account.current_ref.units(self.community.short_currency) + )) + else: - self.label_balance.hide() - self.label_deposit.hide() - self.label_payment.hide() - - proxy = self.table_history.model() - balance = proxy.deposits - proxy.payments - localized_deposits = self.app.current_account.current_ref(proxy.deposits, self.community, self.app).diff_localized() - localized_payments = self.app.current_account.current_ref(proxy.payments, self.community, self.app).diff_localized() - localized_balance = self.app.current_account.current_ref(balance, self.community, self.app).diff_localized() - - self.label_deposit.setText(QCoreApplication.translate("TransactionsTabWidget", "<b>Deposits</b> {:} {:}").format( - localized_deposits, - self.app.current_account.current_ref.units(self.community.short_currency) - )) - self.label_payment.setText(QCoreApplication.translate("TransactionsTabWidget", "<b>Payments</b> {:} {:}").format( - localized_payments, - self.app.current_account.current_ref.units(self.community.short_currency) - )) - self.label_balance.setText(QCoreApplication.translate("TransactionsTabWidget", "<b>Balance</b> {:} {:}").format( - localized_balance, - self.app.current_account.current_ref.units(self.community.short_currency) - )) + amount = self.account.amount(self.community) + maximum = self.community.monetary_mass + # if referential type is quantitative... + # display int values + localized_amount = self.account.current_ref(amount, self.community, self.app).localized(units=True) + localized_minimum = self.account.current_ref(0, self.community, self.app).localized(units=True) + localized_maximum = self.account.current_ref(maximum, self.community, self.app).localized(units=True) + + # set infos in label + self.label_balance.setText( + self.tr("{:}") + .format( + localized_amount + ) + ) + self.label_balance_range.setText( + self.tr("in [{:} ; {:}]") + .format( + localized_minimum, + localized_maximum + ) + ) def history_context_menu(self, point): index = self.table_history.indexAt(point) diff --git a/src/cutecoin/gui/wallets_tab.py b/src/cutecoin/gui/wallets_tab.py index 245cab78ece53388137e30e254738c540288c56d..425e1c22228c17b0856cd7a9e2e25e4a17ec2260 100644 --- a/src/cutecoin/gui/wallets_tab.py +++ b/src/cutecoin/gui/wallets_tab.py @@ -25,30 +25,31 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): classdocs """ - def __init__(self, app, account, community, password_asker): + def __init__(self, app): """ Init :param cutecoin.core.app.Application app: Application instance - :param cutecoin.core.account.Account account: Account instance - :param cutecoin.core.community.Community community: Community instance - :param cutecoin.gui.password_asker.PasswordAskerDialog password_asker: PasswordAskerDialog instance """ super().__init__() self.setupUi(self) self.app = app - self.account = account - self.community = community - self.password_asker = password_asker - self.setup_connections() + self.account = None + self.community = None + self.password_asker = None - def setup_connections(self): + def change_account(self, account): + self.account = account self.account.inner_data_changed.connect(self.refresh_informations_frame) + + def change_community(self, community): + self.community = community self.community.inner_data_changed.connect(self.refresh_informations_frame) def refresh(self): - self.refresh_informations_frame() - self.refresh_wallets() - self.refresh_quality_buttons() + 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 @@ -59,107 +60,6 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): self.table_wallets.setModel(proxy_model) self.table_wallets.resizeColumnsToContents() - def refresh_informations_frame(self): - parameters = self.community.parameters - try: - identity = self.account.identity(self.community) - membership = identity.membership(self.community) - renew_block = membership['blockNumber'] - last_renewal = self.community.get_block(renew_block)['medianTime'] - expiration = last_renewal + parameters['sigValidity'] - except MembershipNotFoundError: - last_renewal = None - expiration = None - - certified = identity.unique_valid_certified_by(self.app.identities_registry, self.community) - certifiers = identity.unique_valid_certifiers_of(self.app.identities_registry, self.community) - if last_renewal and expiration: - date_renewal = QLocale.toString( - QLocale(), - QDateTime.fromTime_t(last_renewal).date(), QLocale.dateFormat(QLocale(), QLocale.LongFormat) - ) - date_expiration = QLocale.toString( - QLocale(), - QDateTime.fromTime_t(expiration).date(), QLocale.dateFormat(QLocale(), QLocale.LongFormat) - ) - - if self.account.pubkey in self.community.members_pubkeys(): - # set infos in label - self.label_general.setText( - self.tr(""" - <table cellpadding="5"> - <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> - <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> - <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> - </table> - """).format( - self.account.name, self.account.pubkey, - self.tr("Membership"), - self.tr("Last renewal on {:}, expiration on {:}").format(date_renewal, date_expiration), - self.tr("Your web of trust"), - self.tr("Certified by {:} members; Certifier of {:} members").format(len(certifiers), - len(certified)) - ) - ) - else: - # set infos in label - self.label_general.setText( - self.tr(""" - <table cellpadding="5"> - <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> - <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> - <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> - </table> - """).format( - self.account.name, self.account.pubkey, - self.tr("Not a member"), - self.tr("Last renewal on {:}, expiration on {:}").format(date_renewal, date_expiration), - self.tr("Your web of trust"), - self.tr("Certified by {:} members; Certifier of {:} members").format(len(certifiers), - len(certified)) - ) - ) - else: - # set infos in label - self.label_general.setText( - self.tr(""" - <table cellpadding="5"> - <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> - <tr><td align="right"><b>{:}</b></td></tr> - <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> - </table> - """).format( - self.account.name, self.account.pubkey, - self.tr("Not a member"), - self.tr("Your web of trust"), - self.tr("Certified by {:} members; Certifier of {:} members").format(len(certifiers), - len(certified)) - ) - ) - - amount = self.account.amount(self.community) - maximum = self.community.monetary_mass - # if referential type is quantitative... - # display int values - localized_amount = self.account.current_ref(amount, self.community, self.app).localized(units=True) - localized_minimum = self.account.current_ref(0, self.community, self.app).localized(units=True) - localized_maximum = self.account.current_ref(maximum, self.community, self.app).localized(units=True) - - # set infos in label - self.label_balance.setText( - self.tr("{:}") - .format( - localized_amount - ) - ) - self.label_balance_range.setText( - self.tr("in [{:} ; {:}]") - .format( - localized_minimum, - localized_maximum - ) - ) - def wallet_context_menu(self, point): index = self.table_wallets.indexAt(point) model = self.table_wallets.model() diff --git a/src/cutecoin/gui/wot_tab.py b/src/cutecoin/gui/wot_tab.py index c7e8572e094d9135f4b5b5332b534a30b55f586c..c2d436721a00f2f7157d745da98593989bc5e711 100644 --- a/src/cutecoin/gui/wot_tab.py +++ b/src/cutecoin/gui/wot_tab.py @@ -2,8 +2,9 @@ import logging from cutecoin.core.graph import Graph +from ..tools.exceptions import MembershipNotFoundError from PyQt5.QtWidgets import QWidget, QComboBox, QLineEdit -from PyQt5.QtCore import pyqtSlot, QEvent +from PyQt5.QtCore import pyqtSlot, QEvent, QLocale, QDateTime from cutecoin.core.net.api import bma from cutecoin.core.registry import BlockchainState from ..gen_resources.wot_tab_uic import Ui_WotTabWidget @@ -12,17 +13,12 @@ from cutecoin.gui.views.wot import NODE_STATUS_HIGHLIGHTED, NODE_STATUS_SELECTED class WotTabWidget(QWidget, Ui_WotTabWidget): - def __init__(self, app, account, community, password_asker, parent=None): + def __init__(self, app): """ :param cutecoin.core.app.Application app: Application instance - :param cutecoin.core.account.Account account: Account instance - :param cutecoin.core.community.Community community: Community instance - :param QWidget parent: Parent :return: """ - super().__init__(parent) - self.parent = parent - + super().__init__() # construct from qtDesigner self.setupUi(self) @@ -41,9 +37,9 @@ class WotTabWidget(QWidget, Ui_WotTabWidget): self.graphicsView.scene().node_contact.connect(self.add_node_as_contact) self.graphicsView.scene().node_member.connect(self.identity_informations) - self.account = account - self.community = community - self.password_asker = password_asker + self.account = None + self.community = None + self.password_asker = None self.app = app #Â nodes list for menu from search @@ -51,9 +47,93 @@ class WotTabWidget(QWidget, Ui_WotTabWidget): # create node metadata from account self._current_identity = None - self.draw_graph(self.account.identity(self.community)) + + def change_account(self, account): + self.account = account + + def change_community(self, community): + self.community = community + self.reset() self.community.network.new_block_mined.connect(self.refresh) + def refresh_informations_frame(self): + parameters = self.community.parameters + try: + identity = self.account.identity(self.community) + membership = identity.membership(self.community) + renew_block = membership['blockNumber'] + last_renewal = self.community.get_block(renew_block)['medianTime'] + expiration = last_renewal + parameters['sigValidity'] + except MembershipNotFoundError: + last_renewal = None + expiration = None + + certified = identity.unique_valid_certified_by(self.app.identities_registry, self.community) + certifiers = identity.unique_valid_certifiers_of(self.app.identities_registry, self.community) + if last_renewal and expiration: + date_renewal = QLocale.toString( + QLocale(), + QDateTime.fromTime_t(last_renewal).date(), QLocale.dateFormat(QLocale(), QLocale.LongFormat) + ) + date_expiration = QLocale.toString( + QLocale(), + QDateTime.fromTime_t(expiration).date(), QLocale.dateFormat(QLocale(), QLocale.LongFormat) + ) + + if self.account.pubkey in self.community.members_pubkeys(): + # set infos in label + self.label_general.setText( + self.tr(""" + <table cellpadding="5"> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + </table> + """).format( + self.account.name, self.account.pubkey, + self.tr("Membership"), + self.tr("Last renewal on {:}, expiration on {:}").format(date_renewal, date_expiration), + self.tr("Your web of trust"), + self.tr("Certified by {:} members; Certifier of {:} members").format(len(certifiers), + len(certified)) + ) + ) + else: + # set infos in label + self.label_general.setText( + self.tr(""" + <table cellpadding="5"> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + </table> + """).format( + self.account.name, self.account.pubkey, + self.tr("Not a member"), + self.tr("Last renewal on {:}, expiration on {:}").format(date_renewal, date_expiration), + self.tr("Your web of trust"), + self.tr("Certified by {:} members; Certifier of {:} members").format(len(certifiers), + len(certified)) + ) + ) + else: + # set infos in label + self.label_general.setText( + self.tr(""" + <table cellpadding="5"> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + </table> + """).format( + self.account.name, self.account.pubkey, + self.tr("Not a member"), + self.tr("Your web of trust"), + self.tr("Certified by {:} members; Certifier of {:} members").format(len(certifiers), + len(certified)) + ) + ) + @pyqtSlot(dict) def handle_node_click(self, metadata): self.draw_graph( @@ -72,51 +152,52 @@ class WotTabWidget(QWidget, Ui_WotTabWidget): """ logging.debug("Draw graph - " + identity.uid) - identity_account = self.account.identity(self.community) - - # Disconnect old identity - try: - if self._current_identity and self._current_identity != identity: - self._current_identity.inner_data_changed.disconnect(self.handle_identity_change) - except TypeError as e: - if "disconnect()" in str(e): - logging.debug("Disconnect of old identity failed.") - - #Connect new identity - if self._current_identity != identity: - self._current_identity = identity - identity.inner_data_changed.connect(self.handle_identity_change) - - # create Identity from node metadata - certifier_list = identity.unique_valid_certifiers_of(self.app.identities_registry, self.community) - certified_list = identity.unique_valid_certified_by(self.app.identities_registry, self.community) - - # create empty graph instance - graph = Graph(self.app, self.community) - - #Â add wallet node - node_status = 0 - if identity == identity_account: - node_status += NODE_STATUS_HIGHLIGHTED - if identity.is_member(self.community) is False: - node_status += NODE_STATUS_OUT - node_status += NODE_STATUS_SELECTED - graph.add_identity(identity, node_status) - - # populate graph with certifiers-of - graph.add_certifier_list(certifier_list, identity, identity_account) - # populate graph with certified-by - graph.add_certified_list(certified_list, identity, identity_account) - - # draw graph in qt scene - self.graphicsView.scene().update_wot(graph.get()) - - # if selected member is not the account member... - if identity.pubkey != identity_account.pubkey: - # add path from selected member to account member - path = graph.get_shortest_path_between_members(identity, identity_account) - if path: - self.graphicsView.scene().update_path(path) + if self.community: + identity_account = self.account.identity(self.community) + + # Disconnect old identity + try: + if self._current_identity and self._current_identity != identity: + self._current_identity.inner_data_changed.disconnect(self.handle_identity_change) + except TypeError as e: + if "disconnect()" in str(e): + logging.debug("Disconnect of old identity failed.") + + #Connect new identity + if self._current_identity != identity: + self._current_identity = identity + identity.inner_data_changed.connect(self.handle_identity_change) + + # create Identity from node metadata + certifier_list = identity.unique_valid_certifiers_of(self.app.identities_registry, self.community) + certified_list = identity.unique_valid_certified_by(self.app.identities_registry, self.community) + + # create empty graph instance + graph = Graph(self.app, self.community) + + #Â add wallet node + node_status = 0 + if identity == identity_account: + node_status += NODE_STATUS_HIGHLIGHTED + if identity.is_member(self.community) is False: + node_status += NODE_STATUS_OUT + node_status += NODE_STATUS_SELECTED + graph.add_identity(identity, node_status) + + # populate graph with certifiers-of + graph.add_certifier_list(certifier_list, identity, identity_account) + # populate graph with certified-by + graph.add_certified_list(certified_list, identity, identity_account) + + # draw graph in qt scene + self.graphicsView.scene().update_wot(graph.get()) + + # if selected member is not the account member... + if identity.pubkey != identity_account.pubkey: + # add path from selected member to account member + path = graph.get_shortest_path_between_members(identity, identity_account) + if path: + self.graphicsView.scene().update_path(path) def reset(self): """ diff --git a/src/cutecoin/models/identities.py b/src/cutecoin/models/identities.py index 1a66f0f92b18518a5cb59bc0066a6992cbf0a690..33f3032e5f657d2a417a7890952508abe0524ffc 100644 --- a/src/cutecoin/models/identities.py +++ b/src/cutecoin/models/identities.py @@ -21,6 +21,10 @@ class IdentitiesFilterProxyModel(QSortFilterProxyModel): self.community = sourceModel.community super().setSourceModel(sourceModel) + def change_community(self, community): + self.community = community + self.sourceModel().change_community(community) + def lessThan(self, left, right): """ Sort table by given column number. @@ -73,12 +77,12 @@ class IdentitiesTableModel(QAbstractTableModel): A Qt abstract item model to display communities in a tree """ - def __init__(self, community, parent=None): + def __init__(self, parent=None): """ Constructor """ super().__init__(parent) - self.community = community + self.community = None self.columns_titles = {'uid': self.tr('UID'), 'pubkey': self.tr('Pubkey'), 'renewed': self.tr('Renewed'), @@ -89,6 +93,9 @@ class IdentitiesTableModel(QAbstractTableModel): self._identities = [] self._refresh_slots = [] + def change_community(self, community): + self.community = community + @property def pubkeys(self): """ diff --git a/src/cutecoin/models/network.py b/src/cutecoin/models/network.py index ed957576a890dc5ffdb9ca099334028a099ee774..6ba11e5703f79bc91cc8fac8e02468b04ac085eb 100644 --- a/src/cutecoin/models/network.py +++ b/src/cutecoin/models/network.py @@ -21,6 +21,10 @@ class NetworkFilterProxyModel(QSortFilterProxyModel): def columnCount(self, parent): return self.sourceModel().columnCount(None) - 1 + def change_community(self, community): + self.community = community + self.sourceModel().change_community(community) + def setSourceModel(self, sourceModel): self.community = sourceModel.community super().setSourceModel(sourceModel) @@ -123,9 +127,15 @@ class NetworkTableModel(QAbstractTableModel): Node.CORRUPTED: self.tr('Corrupted') } + def change_community(self, community): + self.community = community + @property def nodes(self): - return self.community.network.nodes + if self.community: + return self.community.network.nodes + else: + return [] def rowCount(self, parent): return len(self.nodes)