summaryrefslogtreecommitdiff
path: root/src/leap/baseapp/systray.py
diff options
context:
space:
mode:
authorkali <kali@leap.se>2012-09-04 06:58:15 +0900
committerkali <kali@leap.se>2012-09-04 06:58:15 +0900
commit8ef9f6f6f155b4acd0a69f1611058c4f0ba07d42 (patch)
treed45fa606da0ef42593d036753fe7a91bf623cac5 /src/leap/baseapp/systray.py
parent1826d9a0d5400c21a3f7af73eda2e843f0639271 (diff)
refactor icon/iconpath dict
closes #331
Diffstat (limited to 'src/leap/baseapp/systray.py')
-rw-r--r--src/leap/baseapp/systray.py61
1 files changed, 27 insertions, 34 deletions
diff --git a/src/leap/baseapp/systray.py b/src/leap/baseapp/systray.py
index 3fb64db1..f3832473 100644
--- a/src/leap/baseapp/systray.py
+++ b/src/leap/baseapp/systray.py
@@ -11,6 +11,24 @@ class StatusAwareTrayIcon(object):
get updated from conductor status
polling.
"""
+ states = {
+ "disconnected": 0,
+ "connecting": 1,
+ "connected": 2}
+
+ iconpath = {
+ "disconnected": ':/images/conn_error.png',
+ "connecting": ':/images/conn_connecting.png',
+ "connected": ':/images/conn_connected.png'}
+
+ Icons = {
+ 'disconnected': lambda self: QtGui.QIcon(
+ self.iconpath['disconnected']),
+ 'connecting': lambda self: QtGui.QIcon(
+ self.iconpath['connecting']),
+ 'connected': lambda self: QtGui.QIcon(
+ self.iconpath['connected'])
+ }
def __init__(self, *args, **kwargs):
self.createIconGroupBox()
@@ -26,31 +44,22 @@ class StatusAwareTrayIcon(object):
dummy icongroupbox
(to be removed from here -- reference only)
"""
- icons = {
- 'disconnected': ':/images/conn_error.png',
- 'connecting': ':/images/conn_connecting.png',
- 'connected': ':/images/conn_connected.png'
- }
con_widgets = {
'disconnected': QtGui.QLabel(),
'connecting': QtGui.QLabel(),
'connected': QtGui.QLabel(),
}
con_widgets['disconnected'].setPixmap(
- QtGui.QPixmap(icons['disconnected']))
+ QtGui.QPixmap(
+ self.iconpath['disconnected']))
con_widgets['connecting'].setPixmap(
- QtGui.QPixmap(icons['connecting']))
+ QtGui.QPixmap(
+ self.iconpath['connecting']))
con_widgets['connected'].setPixmap(
- QtGui.QPixmap(icons['connected'])),
+ QtGui.QPixmap(
+ self.iconpath['connected'])),
self.ConnectionWidgets = con_widgets
- con_icons = {
- 'disconnected': QtGui.QIcon(icons['disconnected']),
- 'connecting': QtGui.QIcon(icons['connecting']),
- 'connected': QtGui.QIcon(icons['connected'])
- }
- self.Icons = con_icons
-
self.statusIconBox = QtGui.QGroupBox("Connection Status")
statusIconLayout = QtGui.QHBoxLayout()
statusIconLayout.addWidget(self.ConnectionWidgets['disconnected'])
@@ -99,31 +108,20 @@ class StatusAwareTrayIcon(object):
triggered=self.cleanupAndQuit)
def setConnWidget(self, icon_name):
- #print 'changing icon to %s' % icon_name
oldlayout = self.statusIconBox.layout()
- # XXX reuse with icons
- # XXX move states to StateWidget
- states = {"disconnected": 0,
- "connecting": 1,
- "connected": 2}
-
for i in range(3):
oldlayout.itemAt(i).widget().hide()
- new = states[icon_name]
+ new = self.states[icon_name]
oldlayout.itemAt(new).widget().show()
def setIcon(self, name):
- icon = self.Icons.get(name)
+ icon = self.Icons.get(name)(self)
self.trayIcon.setIcon(icon)
self.setWindowIcon(icon)
def getIcon(self, icon_name):
- # XXX get from connection dict
- icons = {'disconnected': 0,
- 'connecting': 1,
- 'connected': 2}
- return icons.get(icon_name, None)
+ return self.states.get(icon_name, None)
def setIconToolTip(self):
"""
@@ -154,12 +152,7 @@ class StatusAwareTrayIcon(object):
slot for status changes. triggers new signals for
updating icon, status bar, etc.
"""
-
- #print('STATUS CHANGED! (on Qt-land)')
- #print('%s -> %s' % (status.previous, status.current))
icon_name = self.conductor.get_icon_name()
self.setIcon(icon_name)
- #print 'icon = ', icon_name
-
# change connection pixmap widget
self.setConnWidget(icon_name)