Longpress to change next/previous track

This commit is contained in:
9and3r
2015-05-24 16:08:06 +02:00
parent 4e2c548f35
commit 1ea6ba11b2
4 changed files with 36 additions and 13 deletions

View File

@@ -91,8 +91,12 @@ class InputManager():
else: else:
return None return None
if direction is not None: if direction is not None:
if time.time() - self.down_time > InputManager.long_click_min_time:
longpress = True
else:
longpress = False
return InputEvent(InputManager.key, None, None, None, return InputEvent(InputManager.key, None, None, None,
direction, self.last_key) direction, self.last_key, longpress=longpress)
def mouse_down(self, event): def mouse_down(self, event):
self.down_pos = event.pos self.down_pos = event.pos
@@ -125,13 +129,14 @@ class InputManager():
self.up_pos, False, None) self.up_pos, False, None)
class InputEvent(): class InputEvent:
def __init__(self, event_type, down_pos, current_pos, vertical, def __init__(self, event_type, down_pos, current_pos, vertical,
direction, unicode=None): direction, unicode=None, longpress=False):
self.type = event_type self.type = event_type
self.down_pos = down_pos self.down_pos = down_pos
self.current_pos = current_pos self.current_pos = current_pos
self.unicode = unicode self.unicode = unicode
self.longpress = longpress
if event_type is InputManager.swipe and direction is None: if event_type is InputManager.swipe and direction is None:
if vertical: if vertical:
if self.down_pos[1] < self.current_pos[1]: if self.down_pos[1] < self.current_pos[1]:

View File

@@ -198,7 +198,7 @@ class ScreenManager():
event.current_pos) event.current_pos)
return self.click_on_objects(objects, event) return self.click_on_objects(objects, event)
else: else:
if event.type == InputManager.key: if event.type == InputManager.key and not event.longpress:
dir = event.direction dir = event.direction
if dir == InputManager.right or dir == InputManager.left: if dir == InputManager.right or dir == InputManager.left:
if not self.screens[self.current_screen]\ if not self.screens[self.current_screen]\

View File

@@ -339,14 +339,32 @@ class MainScreen(BaseScreen):
volume = self.core.playback.volume.get() + 10 volume = self.core.playback.volume.get() + 10
if volume > 100: if volume > 100:
volume = 100 volume = 100
self.core.playback.volume = volume self.core.mixer.set_volume(volume)
self.manager.volume_changed(volume)
elif event.direction == InputManager.down: elif event.direction == InputManager.down:
volume = self.core.playback.volume.get() - 10 volume = self.core.playback.volume.get() - 10
if volume < 0: if volume < 0:
volume = 0 volume = 0
self.core.playback.volume = volume self.core.mixer.set_volume(volume)
self.manager.volume_changed(volume) elif event.type == InputManager.key:
if event.direction == InputManager.enter:
self.click_on_objects(["pause_play"], None)
elif event.direction == InputManager.up:
vol = self.core.mixer.get_volume().get()
vol += 3
if vol > 100:
vol = 100
self.core.mixer.set_volume(vol)
elif event.direction == InputManager.down:
vol = self.core.mixer.get_volume().get()
vol -= 3
if vol < 0:
vol = 0
self.core.mixer.set_volume(vol)
elif event.longpress:
if event.direction == InputManager.left:
self.click_on_objects(["previous"], None)
elif event.direction == InputManager.right:
self.click_on_objects(["next"], None)
def click_on_objects(self, objects, event): def click_on_objects(self, objects, event):
if objects is not None: if objects is not None:
@@ -379,7 +397,7 @@ class MainScreen(BaseScreen):
volume = manager.get_touch_object("volume") volume = manager.get_touch_object("volume")
pos = event.current_pos pos = event.current_pos
value = volume.get_pos_value(pos) value = volume.get_pos_value(pos)
self.core.playback.volume = value self.core.mixer.set_volume(value)
def playback_state_changed(self, old_state, new_state): def playback_state_changed(self, old_state, new_state):
if new_state == mopidy.core.PlaybackState.PLAYING: if new_state == mopidy.core.PlaybackState.PLAYING:

View File

@@ -29,16 +29,16 @@ class MenuScreen(BaseScreen):
clicked = self.list.touch_event(event) clicked = self.list.touch_event(event)
if clicked is not None: if clicked is not None:
if clicked == 0: if clicked == 0:
random = not self.core.tracklist.random.get() random = not self.core.tracklist.get_random().get()
self.core.tracklist.set_random(random) self.core.tracklist.set_random(random)
elif clicked == 1: elif clicked == 1:
repeat = not self.core.tracklist.repeat.get() repeat = not self.core.tracklist.get_repeat().get()
self.core.tracklist.set_repeat(repeat) self.core.tracklist.set_repeat(repeat)
elif clicked == 2: elif clicked == 2:
single = not self.core.tracklist.single.get() single = not self.core.tracklist.get_single().get()
self.core.tracklist.set_single(single) self.core.tracklist.set_single(single)
elif clicked == 3: elif clicked == 3:
consume = not self.core.tracklist.consume.get() consume = not self.core.tracklist.get_consume().get()
self.core.tracklist.set_consume(consume) self.core.tracklist.set_consume(consume)
elif clicked == 4: elif clicked == 4:
os.system("pkill mopidy") os.system("pkill mopidy")