summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--invest-applet/invest/defs.py.in1
-rw-r--r--invest-applet/invest/networkmanager.py24
-rw-r--r--invest-applet/invest/quotes.py34
3 files changed, 39 insertions, 20 deletions
diff --git a/invest-applet/invest/defs.py.in b/invest-applet/invest/defs.py.in
index c674b1b4..769e957c 100644
--- a/invest-applet/invest/defs.py.in
+++ b/invest-applet/invest/defs.py.in
@@ -6,3 +6,4 @@ PYTHONDIR = "@PYTHONDIR@"
GETTEXT_PACKAGE = "@GETTEXT_PACKAGE@"
MATELOCALEDIR = "@MATELOCALEDIR@"
BUILDERDIR = "@BUILDERDIR@"
+NETWORKMANAGER_VERSION = "@NETWORKMANAGER_VERSION@"
diff --git a/invest-applet/invest/networkmanager.py b/invest-applet/invest/networkmanager.py
index 152cd862..f1156115 100644
--- a/invest-applet/invest/networkmanager.py
+++ b/invest-applet/invest/networkmanager.py
@@ -1,14 +1,36 @@
import mate_invest
+from mate_invest.defs import NETWORKMANAGER_VERSION
from dbus.mainloop.glib import DBusGMainLoop
import dbus
-# possible states, see http://projects.mate.org/NetworkManager/developers/spec-08.html#type-NM_STATE
+# possible states, see http://projects.gnome.org/NetworkManager/developers/ -> spec 0.8 -> NM_STATE
STATE_UNKNOWN = dbus.UInt32(0)
STATE_ASLEEP = dbus.UInt32(1)
STATE_CONNECTING = dbus.UInt32(2)
STATE_CONNECTED = dbus.UInt32(3)
STATE_DISCONNEDTED = dbus.UInt32(4)
+# numerical values of these states depend on the network manager version, they changed with 0.8.995
+fields = NETWORKMANAGER_VERSION.split('.')
+if len(fields) >= 2:
+ major = int(fields[0])
+ minor = int(fields[1])
+ if len(fields) > 2:
+ micro = int(fields[2])
+
+ if major > 0 or major == 0 and (minor >= 9 or len(fields) > 2 and minor == 8 and micro >= 995):
+ # see http://projects.gnome.org/NetworkManager/developers/ -> spec 0.9 -> NM_STATE
+ print("Found NetworkManager spec 0.9 (%s)" % NETWORKMANAGER_VERSION)
+ STATE_UNKNOWN = dbus.UInt32(0)
+ STATE_ASLEEP = dbus.UInt32(10)
+ STATE_DISCONNECTED = dbus.UInt32(20)
+ STATE_DISCONNECTING = dbus.UInt32(30)
+ STATE_CONNECTING = dbus.UInt32(40)
+ STATE_CONNECTED_LOCAL = dbus.UInt32(50)
+ STATE_CONNECTED_SITE = dbus.UInt32(60)
+ STATE_CONNECTED_GLOBAL = dbus.UInt32(70)
+ STATE_CONNECTED = STATE_CONNECTED_GLOBAL # backward compatibility with < 0.9
+
class NetworkManager:
def __init__(self):
self.state = STATE_UNKNOWN
diff --git a/invest-applet/invest/quotes.py b/invest-applet/invest/quotes.py
index 0d8e028e..9f916eb1 100644
--- a/invest-applet/invest/quotes.py
+++ b/invest-applet/invest/quotes.py
@@ -148,9 +148,9 @@ class QuoteUpdater(gtk.ListStore):
def update_tooltip(self):
tooltip = []
- if self.simple_quotes_count > 0:
+ if self.quotes_count > 0:
# Translators: This is share-market jargon. It is the average percentage change of all stock prices. The %s gets replaced with the string value of the change (localized), including the percent sign.
- tooltip.append(_('Average change: %s') % self.format_percent(self.avg_simple_quotes_change))
+ tooltip.append(_('Average change: %s') % self.format_percent(self.avg_quotes_change))
for currency, stats in self.statistics.items():
# get the statsitics
balance = stats["balance"]
@@ -231,8 +231,8 @@ class QuoteUpdater(gtk.ListStore):
quote_items = quotes.items ()
quote_items.sort ()
- simple_quotes_change = 0
- self.simple_quotes_count = 0
+ quotes_change = 0
+ self.quotes_count = 0
self.statistics = {}
for ticker, val in quote_items:
@@ -275,9 +275,7 @@ class QuoteUpdater(gtk.ListStore):
break
if is_simple_quote:
- self.simple_quotes_count += 1
row = self.insert(0, [ticker, label, val["currency"], True, 0, 0, val["trade"], val["variation_pct"], pb])
- simple_quotes_change += val['variation_pct']
else:
(balance, change) = self.balance(mate_invest.STOCKS[ticker]["purchases"], val["trade"])
row = self.insert(0, [ticker, label, val["currency"], False, balance, change, val["trade"], val["variation_pct"], pb])
@@ -292,22 +290,20 @@ class QuoteUpdater(gtk.ListStore):
image_retriever.connect("completed", self.set_pb_callback, row)
image_retriever.start()
- if self.simple_quotes_count > 0:
- self.avg_simple_quotes_change = simple_quotes_change/float(self.simple_quotes_count)
- else:
- self.avg_simple_quotes_change = 0
+ quotes_change += val['variation_pct']
+ self.quotes_count += 1
- if self.avg_simple_quotes_change != 0:
- simple_quotes_change_sign = self.avg_simple_quotes_change / abs(self.avg_simple_quotes_change)
- else:
- simple_quotes_change_sign = 0
+ # we can only compute an avg quote if there are quotes
+ if self.quotes_count > 0:
+ self.avg_quotes_change = quotes_change / float(self.quotes_count)
- # change icon
- if self.simple_quotes_count > 0:
- self.change_icon_callback(simple_quotes_change_sign)
+ # change icon
+ quotes_change_sign = 0
+ if self.avg_quotes_change != 0:
+ quotes_change_sign = self.avg_quotes_change / abs(self.avg_quotes_change)
+ self.change_icon_callback(quotes_change_sign)
else:
- positions_balance_sign = self.positions_balance/abs(self.positions_balance)
- self.change_icon_callback(positions_balance_sign)
+ self.avg_quotes_change = 0
# mark quotes to finally be valid
self.quotes_valid = True