From ac26fb385f864ca0e0b621b668b2cb7cc8c53507 Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Sat, 12 Sep 2015 17:42:03 +0200
Subject: [PATCH] Fix display of referentials in tiles

---
 src/cutecoin/core/money/relative.py |  4 ++--
 src/cutecoin/gui/community_view.py  |  5 +----
 src/cutecoin/gui/homescreen.py      | 15 ++++++++++++---
 src/cutecoin/gui/mainwindow.py      |  1 +
 4 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/cutecoin/core/money/relative.py b/src/cutecoin/core/money/relative.py
index 5cf9d8a7..15cde10e 100644
--- a/src/cutecoin/core/money/relative.py
+++ b/src/cutecoin/core/money/relative.py
@@ -35,7 +35,7 @@ class Relative():
         if dividend > 0:
             return self.amount / float(dividend)
         else:
-            return 0
+            return self.amount
 
     @asyncio.coroutine
     def differential(self):
@@ -48,7 +48,7 @@ class Relative():
         prefix_index = 0
         prefix = ""
 
-        while int(scientific_value) == 0:
+        while int(scientific_value) == 0 and scientific_value > 0.0:
             if prefix_index > 3:
                 scientific_value *= 1000
             else:
diff --git a/src/cutecoin/gui/community_view.py b/src/cutecoin/gui/community_view.py
index b012c3ab..12964200 100644
--- a/src/cutecoin/gui/community_view.py
+++ b/src/cutecoin/gui/community_view.py
@@ -236,10 +236,7 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
 
     def referential_changed(self):
         if self.community and self.tab_history.table_history.model():
-            self.tab_history.table_history.model().dataChanged.emit(
-                                                     QModelIndex(),
-                                                     QModelIndex(),
-                                                     [])
+            self.tab_history.table_history.model().sourceModel().refresh_transfers()
             self.tab_history.refresh_balance()
 
     def send_membership_demand(self):
diff --git a/src/cutecoin/gui/homescreen.py b/src/cutecoin/gui/homescreen.py
index d20dff14..85f21a16 100644
--- a/src/cutecoin/gui/homescreen.py
+++ b/src/cutecoin/gui/homescreen.py
@@ -22,19 +22,25 @@ class FrameCommunities(QFrame):
         self.grid_layout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
         self.setFrameShape(QFrame.StyledPanel)
         self.setFrameShadow(QFrame.Raised)
+        self.tiles = []
 
     def sizeHint(self):
         return self.parentWidget().size()
 
     def refresh(self, app):
-        for i in reversed(range(self.grid_layout.count())):
-            self.grid_layout.itemAt(i).widget().setParent(None)
-
+        for t in self.tiles:
+            t.setParent(None)
+        self.tiles = []
         if app.current_account:
             for c in app.current_account.communities:
                 community_tile = CommunityTile(self, app, c)
                 community_tile.clicked.connect(self.click_on_tile)
                 self.layout().addWidget(community_tile)
+                self.tiles.append(community_tile)
+
+    def refresh_content(self):
+        for t in self.tiles:
+            t.refresh()
 
     @pyqtSlot()
     def click_on_tile(self):
@@ -69,6 +75,9 @@ class HomeScreenWidget(QWidget, Ui_HomescreenWidget):
             self.frame_disconnected.show()
             self.frame_connected.hide()
 
+    def referential_changed(self):
+        self.frame_communities.refresh_content()
+
     def showEvent(self, QShowEvent):
         """
 
diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py
index de83ba5a..9a716c16 100644
--- a/src/cutecoin/gui/mainwindow.py
+++ b/src/cutecoin/gui/mainwindow.py
@@ -127,6 +127,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
             self.app.current_account.set_display_referential(index)
             if self.community_view:
                 self.community_view.referential_changed()
+                self.homescreen.referential_changed()
 
     @pyqtSlot()
     def update_time(self):
-- 
GitLab