summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2013-07-25 17:38:28 +0200
committerKali Kaneko <kali@leap.se>2013-07-25 18:12:09 +0200
commitb9c3fcd9ea6469185f7e7f483eeffb7b346e9dad (patch)
treef88f96806306760966f4b73c98697a8dd8e4b239
parentdb18ad67d4149b5f5a6f68db1f52abd91f6f9373 (diff)
Make the rates clickable to alternate between rates and totals.
Closes: #3249, #3232
-rw-r--r--changes/bug_fix_rate_displays3
-rw-r--r--src/leap/gui/statuspanel.py99
-rw-r--r--src/leap/gui/ui/statuspanel.ui63
3 files changed, 138 insertions, 27 deletions
diff --git a/changes/bug_fix_rate_displays b/changes/bug_fix_rate_displays
new file mode 100644
index 00000000..b4b42fcb
--- /dev/null
+++ b/changes/bug_fix_rate_displays
@@ -0,0 +1,3 @@
+ o Allow to alternate between rates and total throughput for the virtual interface. Closes: #3232
+ o Reset rates/totals when terminating connection. Closes #3249
+ o Fix a bug in the displayed magnitude for the up/down traffic rates and totals.
diff --git a/src/leap/gui/statuspanel.py b/src/leap/gui/statuspanel.py
index 3e0377f9..7c824e01 100644
--- a/src/leap/gui/statuspanel.py
+++ b/src/leap/gui/statuspanel.py
@@ -75,8 +75,12 @@ class RateMovingAverage(object):
traff = [traffic for (ts, traffic) in data]
times = [ts for (ts, traffic) in data]
- deltatraffic = traff[-1] - first(traff)
- deltat = (times[-1] - first(times)).seconds
+ try:
+ deltatraffic = traff[-1] - first(traff)
+ deltat = (times[-1] - first(times)).seconds
+ except IndexError:
+ deltatraffic = 0
+ deltat = 0
try:
rate = float(deltatraffic) / float(deltat) / 1024
@@ -84,6 +88,15 @@ class RateMovingAverage(object):
rate = 0
return rate
+ def get_total(self):
+ """
+ Gets the total accumulated throughput.
+ """
+ try:
+ return self._data[-1][1] / 1024
+ except TypeError:
+ return 0
+
class StatusPanelWidget(QtGui.QWidget):
"""
@@ -93,6 +106,10 @@ class StatusPanelWidget(QtGui.QWidget):
start_eip = QtCore.Signal()
stop_eip = QtCore.Signal()
+ DISPLAY_TRAFFIC_RATES = True
+ RATE_STR = "%14.2f KB/s"
+ TOTAL_STR = "%14.2f Kb"
+
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
@@ -118,6 +135,27 @@ class StatusPanelWidget(QtGui.QWidget):
self._set_eip_icons()
self._set_traffic_rates()
+ self._make_status_clickable()
+
+ def _make_status_clickable(self):
+ """
+ Makes upload and download figures clickable.
+ """
+ onclicked = self._on_VPN_status_clicked
+ self.ui.btnUpload.clicked.connect(onclicked)
+ self.ui.btnDownload.clicked.connect(onclicked)
+
+ def _on_VPN_status_clicked(self):
+ """
+ SLOT
+ TRIGGER: self.ui.btnUpload.clicked
+ self.ui.btnDownload.clicked
+
+ Toggles between rate and total throughput display for vpn
+ status figures.
+ """
+ self.DISPLAY_TRAFFIC_RATES = not self.DISPLAY_TRAFFIC_RATES
+ self.update_vpn_status(None) # refresh
def _set_traffic_rates(self):
"""
@@ -126,15 +164,16 @@ class StatusPanelWidget(QtGui.QWidget):
self._up_rate = RateMovingAverage()
self._down_rate = RateMovingAverage()
+ self.ui.btnUpload.setText(self.RATE_STR % (0,))
+ self.ui.btnDownload.setText(self.RATE_STR % (0,))
+
def _reset_traffic_rates(self):
"""
Resets up and download rates, and cleans up the labels.
"""
self._up_rate.reset()
self._down_rate.reset()
- zeroed = {VPNManager.TUNTAP_WRITE_KEY: 0,
- VPNManager.TUNTAP_READ_KEY: 0}
- self.update_vpn_status(zeroed)
+ self.update_vpn_status(None)
def _update_traffic_rates(self, up, down):
"""
@@ -151,7 +190,7 @@ class StatusPanelWidget(QtGui.QWidget):
def _get_traffic_rates(self):
"""
- Gets the traffic rates.
+ Gets the traffic rates (in KB/s).
:returns: a tuple with the (up, down) rates
:rtype: tuple
@@ -161,6 +200,18 @@ class StatusPanelWidget(QtGui.QWidget):
return (up.get_average(), down.get_average())
+ def _get_traffic_totals(self):
+ """
+ Gets the traffic total throughput (in Kb).
+
+ :returns: a tuple with the (up, down) totals
+ :rtype: tuple
+ """
+ up = self._up_rate
+ down = self._down_rate
+
+ return (up.get_total(), down.get_total())
+
def _set_eip_icons(self):
"""
Sets the EIP status icons for the main window and for the tray
@@ -317,18 +368,30 @@ class StatusPanelWidget(QtGui.QWidget):
TRIGGER: VPN.status_changed
Updates the download/upload labels based on the data provided
- by the VPN thread
- """
- upload = float(data[VPNManager.TUNTAP_WRITE_KEY] or "0")
- download = float(data[VPNManager.TUNTAP_READ_KEY] or "0")
- self._update_traffic_rates(upload, download)
- uprate, downrate = self._get_traffic_rates()
-
- upload_str = "%14.2f KB/s" % (uprate,)
- self.ui.lblUpload.setText(upload_str)
-
- download_str = "%14.2f KB/s" % (downrate,)
- self.ui.lblDownload.setText(download_str)
+ by the VPN thread.
+
+ :param data: a dictionary with the tcp/udp write and read totals.
+ If data is None, we just will refresh the display based
+ on the previous data.
+ :type data: dict
+ """
+ if data:
+ upload = float(data[VPNManager.TCPUDP_WRITE_KEY] or "0")
+ download = float(data[VPNManager.TCPUDP_READ_KEY] or "0")
+ self._update_traffic_rates(upload, download)
+
+ if self.DISPLAY_TRAFFIC_RATES:
+ uprate, downrate = self._get_traffic_rates()
+ upload_str = self.RATE_STR % (uprate,)
+ download_str = self.RATE_STR % (downrate,)
+
+ else: # display total throughput
+ uptotal, downtotal = self._get_traffic_totals()
+ upload_str = self.TOTAL_STR % (uptotal,)
+ download_str = self.TOTAL_STR % (downtotal,)
+
+ self.ui.btnUpload.setText(upload_str)
+ self.ui.btnDownload.setText(download_str)
def update_vpn_state(self, data):
"""
diff --git a/src/leap/gui/ui/statuspanel.ui b/src/leap/gui/ui/statuspanel.ui
index fd675d35..3482ac7c 100644
--- a/src/leap/gui/ui/statuspanel.ui
+++ b/src/leap/gui/ui/statuspanel.ui
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>542</width>
+ <width>384</width>
<height>477</height>
</rect>
</property>
@@ -140,9 +140,33 @@
</widget>
</item>
<item>
- <widget class="QLabel" name="lblUpload">
+ <widget class="QPushButton" name="btnDownload">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>100</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>120</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="cursor">
+ <cursorShape>PointingHandCursor</cursorShape>
+ </property>
<property name="text">
- <string>0.0 KB/s</string>
+ <string>0.0 KB/s</string>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
</property>
</widget>
</item>
@@ -172,10 +196,34 @@
</property>
</widget>
</item>
- <item>
- <widget class="QLabel" name="lblDownload">
+ <item alignment="Qt::AlignLeft">
+ <widget class="QPushButton" name="btnUpload">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>100</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>120</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="cursor">
+ <cursorShape>PointingHandCursor</cursorShape>
+ </property>
<property name="text">
- <string>0.0 KB/s</string>
+ <string>0.0 KB/s</string>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
</property>
</widget>
</item>
@@ -233,9 +281,6 @@
</spacer>
</item>
</layout>
- <zorder>lblProvider</zorder>
- <zorder>status_rows</zorder>
- <zorder>globalStatusBox</zorder>
</widget>
<resources>
<include location="../../../../data/resources/icons.qrc"/>