Skip to content

Commit

Permalink
Add connection status (#132)
Browse files Browse the repository at this point in the history
* Added icon to show connection status

* Updated changelog
  • Loading branch information
ilcardella committed Feb 3, 2020
1 parent d18d16c commit 497d3cf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated Pipfile unifying packages and adding custom scripts

### Added
- Icon in status bar that shows internet connection status
- Show application version in About dialog

## [2.1.1] - 2020-01-13
Expand Down
7 changes: 3 additions & 4 deletions src/UI/DataInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ class DataInterface(TaskThread):

def __init__(self, client, data_callback):
TaskThread.__init__(self)
self.client = client
self._client = client
self._data_callback = data_callback
# This interval determines how often the UI is updated
self._interval = 10

def task(self):
# Get the portfolios and for each of them update their UI
for pf in self.client.get_portfolios():
self._data_callback(pf)
# Get the portfolios and call the callback to update the UI
self._data_callback(self._client.get_portfolios())
25 changes: 20 additions & 5 deletions src/UI/assets/gtk/main_window_layout.glade
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ Author: Alberto Cardellini
<property name="can_focus">False</property>
<property name="stock">gtk-preferences</property>
</object>
<object class="GtkImage" id="log_button_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-file</property>
</object>
<object class="GtkWindow" id="main_window">
<property name="can_focus">False</property>
<property name="default_width">1024</property>
Expand Down Expand Up @@ -165,6 +170,21 @@ Author: Alberto Cardellini
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkImage" id="connection_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="hexpand">True</property>
<property name="xpad">5</property>
<property name="stock">gtk-connect</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="index">-1</property>
Expand All @@ -179,9 +199,4 @@ Author: Alberto Cardellini
</object>
</child>
</object>
<object class="GtkImage" id="log_button_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-file</property>
</object>
</interface>
20 changes: 18 additions & 2 deletions src/UI/gtk/UIHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
ABOUT_BUTTON = "about_button"
PORTFOLIO_PATH_LABEL = "portfolio_path_label"
SHOW_LOG_BUTTON = "show_log_button"
CONNECTION_IMAGE = "connection_image"


class UIHandler:
Expand All @@ -54,6 +55,7 @@ def _create_UI(self):
about_button = builder.get_object(ABOUT_BUTTON)
show_log_button = builder.get_object(SHOW_LOG_BUTTON)
self._portfolio_path_label = builder.get_object(PORTFOLIO_PATH_LABEL)
self._connection_status_image = builder.get_object(CONNECTION_IMAGE)
# and link their callbacks
self._main_window.connect("destroy", self._on_close_main_window_event)
open_button.connect("clicked", self._on_open_portfolio_event)
Expand Down Expand Up @@ -93,8 +95,22 @@ def _on_show_about_event(self, widget):
def _on_show_log_event(self, widget):
self._log_window.show()

def _on_data_worker_timeout(self, portfolio):
GLib.idle_add(self._create_update_portfolio_tab, portfolio)
def _on_data_worker_timeout(self, portfolios):
# Update the connection status image based on portfolio data
offline_portfolios = len([p for p in portfolios if p.get_total_value() is None])
GLib.idle_add(
self._update_connection_status, False if offline_portfolios else True
)
for pf in portfolios:
GLib.idle_add(self._create_update_portfolio_tab, pf)

def _update_connection_status(self, connected):
self._connection_status_image.set_from_icon_name(
"gtk-connect" if connected else "gtk-disconnect", gtk.IconSize.BUTTON
)
self._connection_status_image.set_tooltip_text(
"Online" if connected else "Offline"
)

def _create_update_portfolio_tab(self, portfolio):
if portfolio.get_id() not in self._portfolio_tabs.keys():
Expand Down

0 comments on commit 497d3cf

Please sign in to comment.