forked from albertz/music-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Search.py
32 lines (26 loc) · 889 Bytes
/
Search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
import utils, math
from utils import UserAttrib, initBy, Event, formatTime
import Traits
import songdb
class Search:
Keys = ("artist", "title", "duration", "rating")
_searchText = ""
_searchResults = []
@UserAttrib(type=Traits.EditableText, searchLook=True)
def searchText(self, updateText=None):
if updateText is not None and self._searchText != updateText:
self._searchText = updateText
self._searchResults = songdb.search(updateText)
self.searchResults_updateEvent.push()
return self._searchText
@UserAttrib(type=Traits.Table(keys=Keys,
format_duration=lambda d: formatTime(d) if d > 0 else "",
format_rating=lambda r: "★" * int(round(r * 5))))
@property
def searchResults(self):
return list(self._searchResults)
@searchResults.setUpdateEvent
@initBy
def searchResults_updateEvent(self): return Event()
search = Search()