From e18575cc8fe6448e70800b850ca69a9e7e9db970 Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Fri, 21 Aug 2015 16:34:22 +0200
Subject: [PATCH] Display something when no longer a member ( #181 ) + start
 coroutines

---
 src/cutecoin/core/account.py     |  4 +++
 src/cutecoin/core/app.py         |  1 +
 src/cutecoin/core/community.py   |  3 ++
 src/cutecoin/core/net/network.py |  7 +++++
 src/cutecoin/gui/currency_tab.py |  1 -
 src/cutecoin/gui/wallets_tab.py  | 52 ++++++++++++++++++++++----------
 6 files changed, 51 insertions(+), 17 deletions(-)

diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py
index 1cfa5fb2..4efdaf9a 100644
--- a/src/cutecoin/core/account.py
+++ b/src/cutecoin/core/account.py
@@ -597,6 +597,10 @@ class Account(QObject):
                     return
             self.broadcast_error.emit(r.error(), strdata)
 
+    def start_coroutines(self):
+        for c in self.communities:
+            c.start_coroutines()
+
     def stop_coroutines(self):
         for c in self.communities:
             c.stop_coroutines()
diff --git a/src/cutecoin/core/app.py b/src/cutecoin/core/app.py
index 6e8344f1..4cb7c3ca 100644
--- a/src/cutecoin/core/app.py
+++ b/src/cutecoin/core/app.py
@@ -178,6 +178,7 @@ class Application(QObject):
             self.stop_current_account()
 
         self.current_account = account
+        self.current_account.start_coroutines()
 
     def stop_current_account(self):
         """
diff --git a/src/cutecoin/core/community.py b/src/cutecoin/core/community.py
index 6d4eb5dc..c0a6903f 100644
--- a/src/cutecoin/core/community.py
+++ b/src/cutecoin/core/community.py
@@ -292,6 +292,9 @@ class Community(QObject):
         memberships = self.bma_access.get(self, qtbma.wot.Members)
         return [m['pubkey'] for m in memberships["results"]]
 
+    def start_coroutines(self):
+        self.network.start_coroutines()
+
     def stop_coroutines(self):
         self.network.stop_coroutines()
 
diff --git a/src/cutecoin/core/net/network.py b/src/cutecoin/core/net/network.py
index f0c9a7e7..ffac7223 100644
--- a/src/cutecoin/core/net/network.py
+++ b/src/cutecoin/core/net/network.py
@@ -112,6 +112,13 @@ class Network(QObject):
         ratio_synced = synced / total
         return ratio_synced
 
+    def start_coroutines(self):
+        """
+        Start network nodes crawling
+        :return:
+        """
+        asyncio.async(self.discover_network())
+
     def stop_coroutines(self):
         """
         Stop network nodes crawling.
diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py
index 9073c101..5d488307 100644
--- a/src/cutecoin/gui/currency_tab.py
+++ b/src/cutecoin/gui/currency_tab.py
@@ -184,7 +184,6 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
         self.status_label.setText(label_text)
 
     def showEvent(self, event):
-        asyncio.async(self.community.network.discover_network())
         self.refresh_status()
 
     def referential_changed(self):
diff --git a/src/cutecoin/gui/wallets_tab.py b/src/cutecoin/gui/wallets_tab.py
index 0010e49e..881c18ee 100644
--- a/src/cutecoin/gui/wallets_tab.py
+++ b/src/cutecoin/gui/wallets_tab.py
@@ -82,23 +82,43 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab):
                 QLocale(),
                 QDateTime.fromTime_t(expiration).date(), QLocale.dateFormat(QLocale(), QLocale.LongFormat)
             )
-            # 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))
+
+            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(
-- 
GitLab