From 08e817bc9efa3da75fb6c1749232107cd156f059 Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Thu, 3 Sep 2015 23:29:41 +0200
Subject: [PATCH] Corrections diverses dans les vues

---
 src/cutecoin/gui/community_view.py   | 20 +++++++++++++-------
 src/cutecoin/gui/mainwindow.py       | 26 ++++++++++++++++++++------
 src/cutecoin/gui/network_tab.py      |  6 +++++-
 src/cutecoin/gui/transactions_tab.py |  5 ++++-
 src/cutecoin/gui/wot_tab.py          |  5 ++++-
 5 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/src/cutecoin/gui/community_view.py b/src/cutecoin/gui/community_view.py
index ffba895d..b76ed016 100644
--- a/src/cutecoin/gui/community_view.py
+++ b/src/cutecoin/gui/community_view.py
@@ -63,11 +63,11 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
                                  QIcon(':/icons/tx_icon'),
                                 self.tr("Transactions"))
 
-        self.tabs.addTab(self.tab_identities,
+        self.tabs.addTab(self.tab_wot,
                          QIcon(':/icons/wot_icon'),
                          self.tr("Web of Trust"))
 
-        self.tabs.addTab(self.tab_wot,
+        self.tabs.addTab(self.tab_identities,
                          QIcon(':/icons/members_icon'),
                          self.tr("Search Identities"))
 
@@ -81,15 +81,21 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
         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)
-        self.community.inner_data_changed.connect(self.refresh_status)
+        if self.community:
+            self.community.network.new_block_mined.disconnect(self.refresh_block)
+            self.community.network.nodes_changed.disconnect(self.refresh_status)
+            self.community.inner_data_changed.disconnect(self.refresh_status)
+        if community:
+            community.network.new_block_mined.connect(self.refresh_block)
+            community.network.nodes_changed.connect(self.refresh_status)
+            community.inner_data_changed.connect(self.refresh_status)
+            self.label_currency.setText(community.currency)
+        self.community = community
 
     @pyqtSlot(str)
     def display_error(self, error):
@@ -188,7 +194,7 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
         self.refresh_status()
 
     def referential_changed(self):
-        if self.tab_history.table_history.model():
+        if self.community and self.tab_history.table_history.model():
             self.tab_history.table_history.model().dataChanged.emit(
                                                      QModelIndex(),
                                                      QModelIndex(),
diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py
index d15d5147..b7fec5a5 100644
--- a/src/cutecoin/gui/mainwindow.py
+++ b/src/cutecoin/gui/mainwindow.py
@@ -71,8 +71,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
         self.homescreen.toolbutton_new_account.addAction(self.action_import)
         self.homescreen.button_disconnect.clicked.connect(lambda :self.action_change_account(""))
         self.centralWidget().layout().addWidget(self.homescreen)
+        self.homescreen.toolbutton_connect.setMenu(self.menu_change_account)
 
         self.community_view = CommunityWidget(self.app, self.status_label)
+        self.community_view.button_home.clicked.connect(lambda: self.change_community(None))
         self.community_view.button_certification.clicked.connect(self.open_certification_dialog)
         self.community_view.button_send_money.clicked.connect(self.open_transfer_money_dialog)
         self.centralWidget().layout().addWidget(self.community_view)
@@ -236,9 +238,16 @@ class MainWindow(QMainWindow, Ui_MainWindow):
 
     @pyqtSlot(Community)
     def change_community(self, community):
-        logging.debug("Change on tile")
-        self.homescreen.hide()
-        self.community_view.show()
+        if self.community_view.community:
+            self.community_view.community.stop_coroutines()
+
+        if community:
+            self.homescreen.hide()
+            self.community_view.show()
+        else:
+            self.homescreen.show()
+            self.community_view.hide()
+
         self.community_view.change_community(community)
 
     def refresh_accounts(self):
@@ -247,7 +256,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
             action = QAction(account_name, self)
             action.triggered.connect(lambda checked, account_name=account_name: self.action_change_account(account_name))
             self.menu_change_account.addAction(action)
-            self.homescreen.toolbutton_connect.addAction(action)
 
     def refresh_contacts(self):
         self.menu_contacts_list.clear()
@@ -275,9 +283,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
 
         if self.app.current_account is None:
             self.setWindowTitle(self.tr("CuteCoin {0}").format(__version__))
-            self.menu_account.setEnabled(False)
+            self.action_add_a_contact.setEnabled(False)
+            self.actionCertification.setEnabled(False)
+            self.actionTransfer_money.setEnabled(False)
             self.action_configure_parameters.setEnabled(False)
             self.action_set_as_default.setEnabled(False)
+            self.menu_contacts_list.setEnabled(False)
             self.combo_referential.setEnabled(False)
             self.status_label.setText(self.tr(""))
             self.password_asker = None
@@ -293,7 +304,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
             self.combo_referential.blockSignals(False)
             logging.debug(self.app.preferences)
             self.combo_referential.setCurrentIndex(self.app.preferences['ref'])
-            self.menu_account.setEnabled(True)
+            self.action_add_a_contact.setEnabled(True)
+            self.actionCertification.setEnabled(True)
+            self.actionTransfer_money.setEnabled(True)
+            self.menu_contacts_list.setEnabled(True)
             self.action_configure_parameters.setEnabled(True)
             self.setWindowTitle(self.tr("CuteCoin {0} - Account : {1}").format(__version__,
                                                                                self.app.current_account.name))
diff --git a/src/cutecoin/gui/network_tab.py b/src/cutecoin/gui/network_tab.py
index 8021fa81..0c0e73c6 100644
--- a/src/cutecoin/gui/network_tab.py
+++ b/src/cutecoin/gui/network_tab.py
@@ -41,9 +41,13 @@ class NetworkTabWidget(QWidget, Ui_NetworkTabWidget):
         self.table_network.resizeColumnsToContents()
 
     def change_community(self, community):
+        if community:
+            community.network.nodes_changed.connect(self.refresh_nodes)
+        if self.community:
+            self.community.network.nodes_changed.disconnect(self.refresh_nodes)
+
         self.community = community
         self.table_network.model().change_community(community)
-        community.network.nodes_changed.connect(self.refresh_nodes)
 
     @pyqtSlot()
     def refresh_nodes(self):
diff --git a/src/cutecoin/gui/transactions_tab.py b/src/cutecoin/gui/transactions_tab.py
index d2778100..5ef5cf9a 100644
--- a/src/cutecoin/gui/transactions_tab.py
+++ b/src/cutecoin/gui/transactions_tab.py
@@ -35,9 +35,12 @@ class TransactionsTabWidget(QWidget, Ui_transactionsTabWidget):
         self.refresh()
 
     def change_community(self, community):
+        if self.community:
+            self.community.inner_data_changed.disconnect(self.refresh_minimum_maximum)
+        if community:
+            community.inner_data_changed.connect(self.refresh_minimum_maximum)
         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)
diff --git a/src/cutecoin/gui/wot_tab.py b/src/cutecoin/gui/wot_tab.py
index c2d43672..16b7f834 100644
--- a/src/cutecoin/gui/wot_tab.py
+++ b/src/cutecoin/gui/wot_tab.py
@@ -52,9 +52,12 @@ class WotTabWidget(QWidget, Ui_WotTabWidget):
         self.account = account
 
     def change_community(self, community):
+        if self.community:
+            self.community.network.new_block_mined.disconnect(self.refresh)
+        if community:
+            community.network.new_block_mined.connect(self.refresh)
         self.community = community
         self.reset()
-        self.community.network.new_block_mined.connect(self.refresh)
 
     def refresh_informations_frame(self):
         parameters = self.community.parameters
-- 
GitLab