Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

No pointless refreshing after some commands.

  • Loading branch information...
commit 58ea5236461fe187b3d80073e20fac45e725cde0 1 parent 95af541
@tsufeki authored
View
14 qygmy/connection.py
@@ -95,10 +95,11 @@ def normalize(self, value):
return v.strip('/')
-def mpd_cmd(method=None, ignore_conn=False, fallback=None):
+def mpd_cmd(method=None, *, ignore_conn=False, fallback=None, refresh=True):
if method is None:
def decorator(method):
- return mpd_cmd(method, ignore_conn, fallback)
+ return mpd_cmd(method, ignore_conn=ignore_conn, fallback=fallback,
+ refresh=refresh)
return decorator
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
@@ -108,7 +109,8 @@ def wrapper(self, *args, **kwargs):
ret = method(self, *args, **kwargs)
except (mpd.MPDError, OSError) as e:
self.handle_error(e)
- self.update_state()
+ if refresh:
+ self.refresh()
return ret
return wrapper
@@ -176,7 +178,7 @@ def __init__(self, main):
self.mpd_cmdlist = mpd_cmdlist_context_manager(self.conn)
State.create(self, 'state', 'disconnect', not_callable)
- def update_state(self):
+ def refresh(self):
pass
@@ -201,6 +203,6 @@ def mpd_cmdlist(self):
def state(self):
return self.parent.state
- def update_state(self):
- self.parent.update_state()
+ def refresh(self):
+ self.parent.refresh()
View
60 qygmy/lists.py
@@ -38,9 +38,6 @@ def __getitem__(self, index):
def __iter__(self):
return iter(self.items)
- def refresh(self):
- self.current.update(self.current.value, force=True)
-
def refresh_format(self):
self.beginResetModel()
self.endResetModel()
@@ -169,7 +166,6 @@ def add(self, items, pos=None, **kwargs):
for i in a:
self.add_one(i, pos, last, **kwargs)
last += 1
- self.refresh()
return True
@abstractmethod
@@ -200,7 +196,6 @@ def remove(self, positions):
with self.mpd_cmdlist():
for i in reversed(sorted(items, key=lambda x: int(x['pos']))):
self.remove_one(i)
- self.refresh()
@abstractmethod
def remove_one(self, item):
@@ -231,7 +226,6 @@ def move(self, items, pos):
if bpos != i['pos']:
self.move_one(i, bpos)
bpos += 1
- self.refresh()
@abstractmethod
def move_one(self, item, pos):
@@ -270,14 +264,14 @@ def __init__(self, parent):
self.current_pos.changed2.connect(self._update_current_pos)
def refresh(self):
- self.update_state()
+ super().refresh()
self.refresh_format()
- @mpd_cmd(fallback=[])
+ @mpd_cmd(fallback=[], refresh=False)
def ls(self, _=None):
return self.conn.playlistinfo()
- @mpd_cmd(fallback=False)
+ @mpd_cmd(fallback=False, refresh=False)
def add(self, items, pos=None, play=False, replace=False, priority=0):
if replace:
self.conn.clear()
@@ -352,6 +346,9 @@ def _updating_db_changed(self, new, old):
if old and not new:
self.refresh()
+ def refresh(self):
+ self.current.update(self.current.value, force=True)
+
def can_add_to_queue(self, positions):
return len(positions) > 0
@@ -378,7 +375,7 @@ def item_chosen(self, pos):
else:
super().item_chosen(pos)
- @mpd_cmd(fallback=[])
+ @mpd_cmd(fallback=[], refresh=False)
def ls(self, path, recursive=False):
l = self.conn.lsinfo(path)
r = []
@@ -396,7 +393,7 @@ def __init__(self, parent):
super().__init__(parent, '')
self.NEW_PLAYLIST_NAME = self.tr('New playlist')
- @mpd_cmd(fallback=[])
+ @mpd_cmd(fallback=[], refresh=False)
def ls(self, name):
if name != '':
return self.conn.listplaylistinfo(name)
@@ -453,7 +450,7 @@ def move_one(self, item, pos):
if self.current.value != '':
self.conn.playlistmove(self.current.value, item['pos'], pos)
- @mpd_cmd
+ @mpd_cmd(refresh=False)
def save_queue(self, name, replace=False):
try:
self.conn.save(name)
@@ -475,7 +472,7 @@ def data(self, index, role=Qt.DisplayRole):
else:
return super().data(index, role)
- @mpd_cmd(fallback=False)
+ @mpd_cmd(fallback=False, refresh=False)
def setData(self, index, value, role=Qt.EditRole):
r, c = index.row(), index.column()
if role == Qt.EditRole and c == 0:
@@ -513,27 +510,30 @@ def retranslate(self):
('file', self.tr('File name')),
]
- @mpd_cmd(fallback=[])
+ def refresh(self):
+ self.beginResetModel()
+ self.tags = []
+ tags = set(self._tag_types())
+ for t in self.special_tags:
+ tags.discard(t[0])
+ self.tags.append(self.special_tags[0])
+ for t in self.standard_tags:
+ if t[0] in tags:
+ self.tags.append(t)
+ tags.discard(t[0])
+ self.tags.append(self.special_tags[1])
+ for t in sorted(tags):
+ if not t.startswith('musicbrainz_'):
+ self.tags.append((t, t))
+ self.endResetModel()
+
+ @mpd_cmd(fallback=[], refresh=False)
def _tag_types(self):
return (t.lower() for t in self.conn.tagtypes())
def _update(self, newstate, oldstate):
if newstate != 'disconnect' and oldstate == 'disconnect':
- self.beginResetModel()
- self.tags = []
- tags = set(self._tag_types())
- for t in self.special_tags:
- tags.discard(t[0])
- self.tags.append(self.special_tags[0])
- for t in self.standard_tags:
- if t[0] in tags:
- self.tags.append(t)
- tags.discard(t[0])
- self.tags.append(self.special_tags[1])
- for t in sorted(tags):
- if not t.startswith('musicbrainz_'):
- self.tags.append((t, t))
- self.endResetModel()
+ self.refresh()
def rowCount(self, parent=None):
return len(self.tags)
@@ -553,7 +553,7 @@ def __init__(self, parent):
super().__init__(parent, ('', ''))
self.search_tags = SearchTags(self)
- @mpd_cmd(fallback=[])
+ @mpd_cmd(fallback=[], refresh=False)
def ls(self, query):
if query[0] in ('', None) or query[1] in ('', None):
return []
View
25 qygmy/server.py
@@ -26,7 +26,7 @@ def __init__(self, main):
self.search = Search(self)
self.timer = QTimer(self)
- self.timer.timeout.connect(self.update_state)
+ self.timer.timeout.connect(self.refresh)
def _seek(self, time):
if self.state.value != 'stop':
@@ -37,16 +37,15 @@ def start_timer(self, interval=500):
self.timer.stop()
self.timer.start(interval)
- def update_state(self):
- s, c = {'state': 'disconnect'}, {}
- try:
- if self.state.value != 'disconnect':
- with self.mpd_cmdlist() as cl:
- self.conn.status()
- self.conn.currentsong()
- s, c = cl.retval
- except (mpd.MPDError, OSError) as e:
- self.handle_error(e)
+ @mpd_cmd(fallback=({'state': 'disconnect'}, {}), refresh=False)
+ def retrieve_state(self):
+ with self.mpd_cmdlist() as cl:
+ self.conn.status()
+ self.conn.currentsong()
+ return cl.retval
+
+ def refresh(self):
+ s, c = self.retrieve_state()
self.state.update(s['state'])
self.times.update(s.get('time', ':').split(':'))
@@ -95,13 +94,13 @@ def updatedb(self):
self.conn.update()
self.updating_db.update(True) # so we don't miss even super-short updates
- @mpd_cmd(fallback={})
+ @mpd_cmd(fallback={}, refresh=False)
def statistics(self):
stats = self.conn.stats()
stats['mpdversion'] = self.conn.mpd_version
return stats
- @mpd_cmd(fallback=[])
+ @mpd_cmd(fallback=[], refresh=False)
def outputs(self):
return sorted((
i.get('outputname', i['outputid']),
View
28 qygmy/translations/qygmy_pl.ts
@@ -229,7 +229,7 @@
<context>
<name>Playlists</name>
<message>
- <location filename="../lists.py" line="398"/>
+ <location filename="../lists.py" line="395"/>
<source>New playlist</source>
<translation>Nowa lista</translation>
</message>
@@ -270,67 +270,67 @@
<context>
<name>SearchTags</name>
<message>
- <location filename="../lists.py" line="498"/>
+ <location filename="../lists.py" line="495"/>
<source>Title</source>
<translation>Tytuł</translation>
</message>
<message>
- <location filename="../lists.py" line="499"/>
+ <location filename="../lists.py" line="496"/>
<source>Artist</source>
<translation>Artysta</translation>
</message>
<message>
- <location filename="../lists.py" line="500"/>
+ <location filename="../lists.py" line="497"/>
<source>Album</source>
<translation>Album</translation>
</message>
<message>
- <location filename="../lists.py" line="501"/>
+ <location filename="../lists.py" line="498"/>
<source>Genre</source>
<translation>Gatunek</translation>
</message>
<message>
- <location filename="../lists.py" line="502"/>
+ <location filename="../lists.py" line="499"/>
<source>Comment</source>
<translation>Komentarz</translation>
</message>
<message>
- <location filename="../lists.py" line="503"/>
+ <location filename="../lists.py" line="500"/>
<source>Composer</source>
<translation>Kompozytor</translation>
</message>
<message>
- <location filename="../lists.py" line="504"/>
+ <location filename="../lists.py" line="501"/>
<source>Performer</source>
<translation>Wykonawca</translation>
</message>
<message>
- <location filename="../lists.py" line="505"/>
+ <location filename="../lists.py" line="502"/>
<source>Date</source>
<translation>Data</translation>
</message>
<message>
- <location filename="../lists.py" line="506"/>
+ <location filename="../lists.py" line="503"/>
<source>Track</source>
<translation>Ścieżka</translation>
</message>
<message>
- <location filename="../lists.py" line="507"/>
+ <location filename="../lists.py" line="504"/>
<source>Disc</source>
<translation>Dysk</translation>
</message>
<message>
- <location filename="../lists.py" line="511"/>
+ <location filename="../lists.py" line="508"/>
<source>Any</source>
<translation>Wszystko</translation>
</message>
<message>
- <location filename="../lists.py" line="512"/>
+ <location filename="../lists.py" line="509"/>
<source>File name</source>
<translation>Nazwa pliku</translation>
</message>
<message>
- <location filename="../lists.py" line="508"/>
+ <location filename="../lists.py" line="505"/>
<source>Name</source>
<translation>Nazwa</translation>
</message>
Please sign in to comment.
Something went wrong with that request. Please try again.