From fd39b0d6e5e61694fda7273f37499c49a7baac17 Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Wed, 1 Jul 2015 21:55:23 +0200
Subject: [PATCH] Starting work on cleaning UI code

---
 res/ui/currency_tab.ui            |  3 ---
 src/cutecoin/core/net/network.py  |  2 +-
 src/cutecoin/core/wallet.py       |  2 +-
 src/cutecoin/gui/community_tab.py | 11 +++++-----
 src/cutecoin/gui/currency_tab.py  | 34 ++++++++-----------------------
 src/cutecoin/gui/mainwindow.py    | 18 ++++++++--------
 6 files changed, 24 insertions(+), 46 deletions(-)

diff --git a/res/ui/currency_tab.ui b/res/ui/currency_tab.ui
index d56ceb51..96fb8c59 100644
--- a/res/ui/currency_tab.ui
+++ b/res/ui/currency_tab.ui
@@ -29,9 +29,6 @@
      <layout class="QVBoxLayout" name="verticalLayout">
       <item>
        <widget class="QTabWidget" name="tabs_account">
-        <property name="enabled">
-         <bool>false</bool>
-        </property>
         <property name="currentIndex">
          <number>-1</number>
         </property>
diff --git a/src/cutecoin/core/net/network.py b/src/cutecoin/core/net/network.py
index f483db38..f82e083c 100644
--- a/src/cutecoin/core/net/network.py
+++ b/src/cutecoin/core/net/network.py
@@ -197,7 +197,7 @@ class Network(QObject):
             for node in self.nodes:
                 if self.continue_crawling():
                     yield from asyncio.sleep(2)
-                    node.refresh()
+                    node.refresh_identities()
         logging.debug("End of network discovery")
 
     @pyqtSlot(Peer)
diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py
index 3d996bee..cc8aadcc 100644
--- a/src/cutecoin/core/wallet.py
+++ b/src/cutecoin/core/wallet.py
@@ -114,7 +114,7 @@ class Wallet(QObject):
         :param community: The community to refresh its cache
         """
         logging.debug("Refresh transactions for {0}".format(self.pubkey))
-        asyncio.async(self.caches[community.currency].refresh(community, received_list))
+        asyncio.async(self.caches[community.currency].refresh_identities(community, received_list))
 
     def check_password(self, salt, password):
         """
diff --git a/src/cutecoin/gui/community_tab.py b/src/cutecoin/gui/community_tab.py
index 88698485..89717f7d 100644
--- a/src/cutecoin/gui/community_tab.py
+++ b/src/cutecoin/gui/community_tab.py
@@ -43,10 +43,9 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget):
         self.community = community
         self.account = account
         self.password_asker = password_asker
-        self.setup_ui()
 
-    def setup_ui(self):
         self.setupUi(self)
+
         identities_model = IdentitiesTableModel(self.community)
         proxy = IdentitiesFilterProxyModel()
         proxy.setSourceModel(identities_model)
@@ -251,7 +250,7 @@ Revoking your UID can only success if it is not already validated by the network
                 raise
 
         self.edit_textsearch.clear()
-        self.refresh(identities)
+        self.refresh_identities(identities)
 
     def search_text(self):
         """
@@ -297,7 +296,7 @@ Revoking your UID can only success if it is not already validated by the network
                 raise
 
         self.edit_textsearch.clear()
-        self.refresh(identities)
+        self.refresh_identities(identities)
 
     def search_direct_connections(self):
         """
@@ -322,9 +321,9 @@ Revoking your UID can only success if it is not already validated by the network
         certified_by = [p for p in account_connections
                   if p.pubkey not in [i.pubkey for i in certifiers_of]]
         identities = certifiers_of + certified_by
-        self.refresh(identities)
+        self.refresh_identities(identities)
 
-    def refresh(self, identities):
+    def refresh_identities(self, identities):
         """
         Refresh the table with specified identities.
         If no identities is passed, use the account connections.
diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py
index 2809a02e..71af87f5 100644
--- a/src/cutecoin/gui/currency_tab.py
+++ b/src/cutecoin/gui/currency_tab.py
@@ -33,7 +33,6 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
         Constructor
         """
         super().__init__()
-        self.setupUi(self)
         self.app = app
         self.community = community
         self.password_asker = password_asker
@@ -46,13 +45,8 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
                             self.tr("Warning : Your could miss certifications soon.")
                             }
 
-        self.tab_community = None
-        self.tab_wallets = None
-        self.tab_network = None
-        self.tab_history = None
-
-    def setupUi(self):
         super().setupUi(self)
+
         self.tab_community = CommunityTabWidget(self.app,
                                                 self.app.current_account,
                                                     self.community,
@@ -86,6 +80,10 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
                                  QIcon(':/icons/informations_icon'),
                                 self.tr("Informations"))
 
+        self.tabs_account.addTab(self.tab_community,
+                                 QIcon(':/icons/community_icon'),
+                                self.tr("Community"))
+
         self.tabs_account.addTab(self.tab_network,
                                  QIcon(":/icons/network_icon"),
                                  self.tr("Network"))
@@ -93,24 +91,6 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
         self.community.network.new_block_mined.connect(self.refresh_block)
         self.community.network.nodes_changed.connect(self.refresh_status)
 
-    def refresh(self):
-        if self.app.current_account is None:
-            self.tabs_account.setEnabled(False)
-        else:
-            self.tabs_account.setEnabled(True)
-
-            self.tab_wallets.refresh()
-
-            self.tab_history.refresh()
-
-            self.tab_community.refresh()
-
-            self.tab_informations.refresh()
-
-            self.tab_network.refresh()
-
-            self.refresh_status()
-
     @pyqtSlot(str)
     def display_error(self, error):
         QMessageBox.critical(self, ":(",
@@ -153,6 +133,10 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
         self.tab_history.start_progress()
         self.refresh_data()
 
+    def refresh_wallets(self):
+        if self.tab_wallets:
+            self.tab_wallets.refresh()
+
     def refresh_data(self):
         """
         Refresh data when the blockchain watcher finished handling datas
diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py
index 5d1faac5..d6e991b1 100644
--- a/src/cutecoin/gui/mainwindow.py
+++ b/src/cutecoin/gui/mainwindow.py
@@ -44,25 +44,24 @@ class MainWindow(QMainWindow, Ui_MainWindow):
         self.app = app
         self.initialized = False
         self.password_asker = None
-        self.combo_referential = QComboBox(self)
-        self.status_label = QLabel("", self)
-        self.label_time = QLabel("", self)
         self.import_dialog = None
-        self.setupUi()
 
-    def setupUi(self):
         super().setupUi(self)
+
         QApplication.setWindowIcon(QIcon(":/icons/cutecoin_logo"))
 
         self.app.version_requested.connect(self.latest_version_requested)
 
-        self.combo_referential.setEnabled(False)
-        self.combo_referential.currentIndexChanged.connect(self.referential_changed)
-
+        self.status_label = QLabel("", self)
         self.status_label.setTextFormat(Qt.RichText)
-
         self.statusbar.addPermanentWidget(self.status_label, 1)
+
+        self.label_time = QLabel("", self)
         self.statusbar.addPermanentWidget(self.label_time)
+
+        self.combo_referential = QComboBox(self)
+        self.combo_referential.setEnabled(False)
+        self.combo_referential.currentIndexChanged.connect(self.referential_changed)
         self.statusbar.addPermanentWidget(self.combo_referential)
 
         self.homescreen = HomeScreenWidget(self.app)
@@ -242,7 +241,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
                 tab_currency = CurrencyTabWidget(self.app, community,
                                                  self.password_asker,
                                                  self.status_label)
-                tab_currency.refresh()
                 self.currencies_tabwidget.addTab(tab_currency,
                                                  QIcon(":/icons/currency_icon"),
                                                  community.name)
-- 
GitLab