Merge lp:~laszlok/decibel-audio-player/status-icon-fix into lp:decibel-audio-player

Proposed by Laszlo Pandy
Status: Needs review
Proposed branch: lp:~laszlok/decibel-audio-player/status-icon-fix
Merge into: lp:decibel-audio-player
Diff against target: 83 lines (+31/-4)
1 file modified
src/modules/StatusIcon.py (+31/-4)
To merge this branch: bzr merge lp:~laszlok/decibel-audio-player/status-icon-fix
Reviewer Review Type Date Requested Status
Anonym25712 Approve
Review via email: mp+26850@code.launchpad.net

Description of the change

Added two features to the status icon:
 - Scrolling up and down changes volume.
 - Middle click toggles pause.

To post a comment you must log in.
Revision history for this message
Anonym25712 (anonym25712) :
review: Approve

Unmerged revisions

65. By Laszlo Pandy

Scroll mouse on status icon to change volume.

64. By Laszlo Pandy

Add middle click to pause on status icon.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/modules/StatusIcon.py'
2--- src/modules/StatusIcon.py 2010-05-16 08:43:26 +0000
3+++ src/modules/StatusIcon.py 2010-06-05 00:18:23 +0000
4@@ -23,6 +23,7 @@
5
6 MOD_INFO = ('Status Icon', _('Status Icon'), _('Add an icon to the notification area'), [], False, False)
7
8+VOLUME_SCROLL_STEP = 0.05
9
10 class StatusIcon(modules.Module):
11
12@@ -30,7 +31,8 @@
13 """ Constructor """
14 modules.Module.__init__(self, (consts.MSG_EVT_MOD_LOADED, consts.MSG_EVT_MOD_UNLOADED, consts.MSG_EVT_APP_STARTED,
15 consts.MSG_EVT_NEW_TRACK, consts.MSG_EVT_PAUSED, consts.MSG_EVT_UNPAUSED,
16- consts.MSG_EVT_STOPPED, consts.MSG_EVT_NEW_TRACKLIST, consts.MSG_EVT_TRACK_MOVED))
17+ consts.MSG_EVT_STOPPED, consts.MSG_EVT_NEW_TRACKLIST, consts.MSG_EVT_TRACK_MOVED,
18+ consts.MSG_EVT_VOLUME_CHANGED))
19
20
21 def install(self):
22@@ -45,15 +47,18 @@
23 self.trackHasPrev = False
24 self.emptyTracklist = True
25 self.isMainWinVisible = True
26+ self.currVolume = 0
27 # The status icon does not support RGBA, so make sure to use the RGB color map when creating it
28 colormap = self.mainWindow.get_screen().get_rgb_colormap()
29 gtk.widget_push_colormap(self.mainWindow.get_screen().get_rgb_colormap())
30 self.statusIcon = gtk.StatusIcon()
31 gtk.widget_pop_colormap()
32 # GTK+ handlers
33- self.statusIcon.connect('activate', self.toggleWinVisibility)
34- self.statusIcon.connect('popup-menu', self.onPopupMenu)
35- self.statusIcon.connect('size-changed', self.renderIcons)
36+ self.statusIcon.connect('activate', self.toggleWinVisibility)
37+ self.statusIcon.connect('popup-menu', self.onPopupMenu)
38+ self.statusIcon.connect('size-changed', self.renderIcons)
39+ self.statusIcon.connect('scroll-event', self.onScroll)
40+ self.statusIcon.connect('button-press-event', self.onButtonPress)
41 # Install everything
42 self.statusIcon.set_tooltip(consts.appName)
43 self.onNewTrack(None)
44@@ -119,6 +124,9 @@
45 self.statusIcon.set_from_pixbuf(self.icoNormal)
46 self.statusIcon.set_tooltip(self.tooltip)
47
48+ def onVolumeChanged(self, volume):
49+ """ The volume has been changed """
50+ self.currVolume = volume
51
52 def toggleWinVisibility(self, statusIcon):
53 """ Show/hide the main window """
54@@ -147,6 +155,7 @@
55 elif msg == consts.MSG_EVT_APP_STARTED: self.install()
56 elif msg == consts.MSG_EVT_MOD_UNLOADED: self.uninstall()
57 elif msg == consts.MSG_EVT_NEW_TRACKLIST: self.emptyTracklist = (len(params['tracks']) == 0)
58+ elif msg == consts.MSG_EVT_VOLUME_CHANGED:self.onVolumeChanged(params['value'])
59
60
61 # --== GTK handlers ==--
62@@ -181,3 +190,21 @@
63 self.menuPlay.set_sensitive((not (self.isPlaying or self.emptyTracklist)) or self.isPaused)
64
65 self.popupMenu.popup(None, None, gtk.status_icon_position_menu, button, time, statusIcon)
66+
67+ def onScroll(self, statusIcon, scrollEvent):
68+ """ The mouse is scrolled on the status icon """
69+ volume = self.currVolume
70+ if scrollEvent.direction == gtk.gdk.SCROLL_UP or scrollEvent.direction == gtk.gdk.SCROLL_RIGHT:
71+ volume = min(1.0, volume + VOLUME_SCROLL_STEP)
72+ else:
73+ volume = max(0.0, volume - VOLUME_SCROLL_STEP)
74+
75+ modules.postMsg(consts.MSG_CMD_SET_VOLUME, {'value': volume})
76+
77+ def onButtonPress(self, statusIcon, buttonEvent):
78+ """ A button is pressed on the status icon """
79+ if buttonEvent.button == 2:
80+ modules.postMsg(consts.MSG_CMD_TOGGLE_PAUSE)
81+
82+
83+

Subscribers

People subscribed via source and target branches

to all changes: