From 00eebf92607e9d1f36a385b6c0cadb2fd93c8065 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Tue, 9 Apr 2019 16:08:14 -0500 Subject: [PATCH 1/7] Added support for loading more items in conversation buffers --- src/controller/buffers.py | 32 +++++++++++++++++++++++++++----- src/controller/mainController.py | 4 ++-- src/sessionmanager/session.py | 7 +++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/controller/buffers.py b/src/controller/buffers.py index 61401a8..b8b5e9b 100644 --- a/src/controller/buffers.py +++ b/src/controller/buffers.py @@ -914,7 +914,10 @@ class chatBuffer(baseBuffer): item_ = getattr(renderers, self.compose_function)(item, self.session) # the self.chat dictionary will have (first_line, last_line) as keys and message ID as a value for looking into it when needed. # Here we will get first and last line of a chat message appended to the history. - values = self.tab.add_message(item_[0]) + lines = self.tab.history.GetNumberOfLines() + values = self.tab.add_message(item_[0], reverse=reversed) + if reversed: + values = (values[0]-lines, values[1]-lines) self.chats[values] = item["id"] def get_focused_post(self): @@ -985,10 +988,11 @@ class chatBuffer(baseBuffer): event.Skip() def get_items(self, show_nextpage=False): + """ Update buffer with newest items or get older items in the buffer.""" if self.can_get_items == False: return - retrieved = True # Control variable for handling unauthorised/connection errors. + retrieved = True try: - num = getattr(self.session, "get_messages")(name=self.name, *self.args, **self.kwargs) + num = getattr(self.session, "get_page")(show_nextpage=show_nextpage, name=self.name, *self.args, **self.kwargs) except VkApiError as err: log.error("Error {0}: {1}".format(err.code, err.error)) retrieved = err.code @@ -1001,20 +1005,38 @@ class chatBuffer(baseBuffer): self.create_tab(self.parent) # Add name to the new control so we could look for it when needed. self.tab.name = self.name + if show_nextpage == False: if self.tab.history.GetValue() != "" and num > 0: v = [i for i in self.session.db[self.name]["items"][:num]] -# v.reverse() [self.insert(i, False) for i in v] else: [self.insert(i) for i in self.session.db[self.name]["items"][:num]] else: if num > 0: - [self.insert(i, False) for i in self.session.db[self.name]["items"][:num]] + # At this point we save more CPU and mathematical work if we just delete everything in the chat history and readd all messages. + # Otherwise we'd have to insert new lines at the top and recalculate positions everywhere else. + # Firstly, we'd have to save the current focused object so we will place the user in the right part of the text after loading everything again. + focused_post = self.get_post() + self.chats = dict() + self.tab.history.SetValue("") + v = [i for i in self.session.db[self.name]["items"]] + [self.insert(i) for i in v] + # Now it's time to set back the focus in the post. + for i in self.chats.keys(): + if self.chats[i] == focused_post["id"]: + line = i[0] + self.tab.history.SetInsertionPoint(self.tab.history.XYToPosition(0, line)) + output.speak(_("Items loaded")) + break if self.unread == True and num > 0: self.session.db[self.name]["items"][-1].update(read_state=0) return retrieved + def get_more_items(self): + output.speak(_("Getting more items...")) + call_threaded(self.get_items, show_nextpage=True) + def add_attachment(self, *args, **kwargs): a = presenters.attachPresenter(session=self.session, view=views.attachDialog(voice_messages=True), interactor=interactors.attachInteractor()) if len(a.attachments) != 0: diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 87cdbd2..c75bb38 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -392,7 +392,7 @@ class Controller(object): elif user_id > 2000000000: chat = self.session.vk.client.messages.getChat(chat_id=user_id-2000000000) name = chat["title"] - wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="chatBuffer", buffer_title=name, parent_tab="chats", get_items=True, kwargs=dict(parent=self.window.tb, name="{0}_messages".format(user_id,), composefunc="render_message", session=self.session, unread=unread, count=200, peer_id=user_id, rev=0, extended=True, fields="id, user_id, date, read_state, out, body, attachments, deleted")) + wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="chatBuffer", buffer_title=name, parent_tab="chats", get_items=True, kwargs=dict(parent=self.window.tb, name="{0}_messages".format(user_id,), composefunc="render_message", parent_endpoint="messages", endpoint="getHistory", session=self.session, unread=unread, count=200, peer_id=user_id, rev=0, extended=True, fields="id, user_id, date, read_state, out, body, attachments, deleted")) # if setfocus: # pos = self.window.search(buffer.name) # self.window.change_buffer(pos) @@ -538,7 +538,7 @@ class Controller(object): data = [message] # Let's add this to the buffer. # ToDo: Clean this code and test how is the database working with this set to True. - num = self.session.order_buffer(buffer.name, data, True) + buffer.session.db[buffer.name]["items"].append(message) buffer.insert(self.session.db[buffer.name]["items"][-1], False) self.session.soundplayer.play("message_received.ogg") wx.CallAfter(self.reorder_buffer, buffer) diff --git a/src/sessionmanager/session.py b/src/sessionmanager/session.py index f2f5304..03088df 100644 --- a/src/sessionmanager/session.py +++ b/src/sessionmanager/session.py @@ -66,6 +66,9 @@ class vkSession(object): self.db[name] = {} self.db[name]["items"] = [] first_addition = True + # Handles chat messages case, as the buffer is inverted + if name.endswith("_messages") and show_nextpage == True: + show_nextpage = False for i in data: if "type" in i and not isinstance(i["type"], int) and (i["type"] == "wall_photo" or i["type"] == "photo_tag" or i["type"] == "photo"): log.debug("Skipping unsupported item... %r" % (i,)) @@ -192,6 +195,10 @@ class vkSession(object): if data != None: if "count" not in kwargs: kwargs["count"] = 100 + # Let's handle a little exception when dealing with conversation buffers. + # the first results of the query should be reversed before being sent to order_buffer. + if type(data) == dict and "items" in data and endpoint == "getHistory" and kwargs["offset"] == 0: + data["items"].reverse() if type(data) == dict: num = self.order_buffer(name, data["items"], show_nextpage) self.db[name]["offset"] = kwargs["offset"]+kwargs["count"] From fea57a4034469c924a3460d3de69b053a843b090 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Tue, 9 Apr 2019 16:09:33 -0500 Subject: [PATCH 2/7] Updated changelog with getting more items to conversation buffers --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 39a9526..66e613f 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,7 @@ * Improvements in the audio player module: * When modifying volume of the playing audio, it will decrease or increase the volume by 2% instead of 5%. * For users with multiple soundcards, there is a new tab in the preferences dialogue of Socializer, called sound. From there, you can define what soundcard will be used for input and output. +* it is possible to retrieve more items for conversation buffers. Due to API limitations, it is possible to load up to the last 600 messages for every conversation. Take into account that the process of loading more items takes some time. You will hear a message when the process is done. ## Changes in version 0.19 (13.03.2019) From 05c001067ea80839643a65322e340237a7e4c551 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Tue, 9 Apr 2019 16:15:38 -0500 Subject: [PATCH 3/7] Removed old alpha version built with Python 2 --- .gitlab-ci.yml | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index edbc68c..c64a86f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,33 +21,6 @@ test_py3: - '%PYTHON3% -m coverage report --omit="test*"' coverage: '/TOTAL.+ ([0-9]{1,3}%)/' -.alpha: - type: deploy - tags: - - windows - script: - - pip install --upgrade pip - - pip install --upgrade -r requirements.txt - - copy changelog.md doc\changelog.md - - cd doc - - python documentation_importer.py - - cd ..\src - - python ..\doc\generator.py - - python write_version_data.py - - python setup.py py2exe - - cd .. - - cd scripts - - python prepare_zipversion.py - - cd .. - - move src\socializer.zip socializer.zip - only: - - schedules - artifacts: - paths: - - socializer.zip - name: socializer - expire_in: 1 day - alpha_python3: type: deploy tags: From 6f245d9b7fcfac5105786c10d4052edcb331a3aa Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Tue, 9 Apr 2019 17:55:05 -0500 Subject: [PATCH 4/7] Added support to delete conversations --- changelog.md | 4 +++- src/controller/mainController.py | 15 ++++++++++++++- src/wxUI/commonMessages.py | 5 ++++- src/wxUI/menus.py | 7 ++++++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index 66e613f..c7265f7 100644 --- a/changelog.md +++ b/changelog.md @@ -6,7 +6,9 @@ * Improvements in the audio player module: * When modifying volume of the playing audio, it will decrease or increase the volume by 2% instead of 5%. * For users with multiple soundcards, there is a new tab in the preferences dialogue of Socializer, called sound. From there, you can define what soundcard will be used for input and output. -* it is possible to retrieve more items for conversation buffers. Due to API limitations, it is possible to load up to the last 600 messages for every conversation. Take into account that the process of loading more items takes some time. You will hear a message when the process is done. +* Improvements in conversation buffers: + * it is possible to retrieve more items for conversation buffers. Due to API limitations, it is possible to load up to the last 600 messages for every conversation. Take into account that the process of loading more items takes some time. You will hear a message when the process is done. + * It is possible to delete entire conversations from the tree of buffers, by using the menu key and selecting "delete conversation". The conversation will be removed from VK. ## Changes in version 0.19 (13.03.2019) diff --git a/src/controller/mainController.py b/src/controller/mainController.py index c75bb38..ebdee22 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -883,6 +883,7 @@ class Controller(object): else: option = menu.Append(wx.NewId(), _("Discard groups")) widgetUtils.connect_event(menu, widgetUtils.MENU, self.unload_community_buffers, menuitem=option) + # Deal with video and audio albums' sections. elif current_buffer.name == "audio_albums": menu = wx.Menu() if self.session.settings["load_at_startup"]["audio_albums"] == False and not hasattr(self.session, "audio_albums"): @@ -899,6 +900,9 @@ class Controller(object): else: option = menu.Append(wx.NewId(), _("Discard video albums")) widgetUtils.connect_event(menu, widgetUtils.MENU, self.unload_video_album_buffers, menuitem=option) + elif current_buffer.name.endswith("_messages"): + menu = menus.conversationBufferMenu() + widgetUtils.connect_event(menu, widgetUtils.MENU, self.delete_conversation, menuitem=menu.delete) if menu != None: self.window.PopupMenu(menu, self.window.FindFocus().GetPosition()) @@ -1000,4 +1004,13 @@ class Controller(object): buff = self.window.search(buffer.name) self.window.remove_buffer(buff) self.buffers.remove(buffer) - del self.session.video_albums \ No newline at end of file + del self.session.video_albums + + def delete_conversation(self, *args, **kwargs): + current_buffer = self.get_current_buffer() + d = commonMessages.delete_conversation() + if d == widgetUtils.YES: + results = self.session.vk.client.messages.deleteConversation(peer_id=current_buffer.kwargs["peer_id"]) + buff = self.window.search(current_buffer.name) + self.window.remove_buffer(buff) + self.buffers.remove(current_buffer) \ No newline at end of file diff --git a/src/wxUI/commonMessages.py b/src/wxUI/commonMessages.py index 321d078..f603385 100644 --- a/src/wxUI/commonMessages.py +++ b/src/wxUI/commonMessages.py @@ -63,4 +63,7 @@ def restart_program(): return wx.MessageDialog(None, _("In order to apply the changes you requested, you must restart the program. Do you want to restart Socializer now?"), _("Attention"), style=wx.ICON_QUESTION|wx.YES_NO).ShowModal() def community_no_items(): - return wx.MessageDialog(None, _("There are 0 items for this community."), _("Error"), wx.ICON_ERROR).ShowModal() \ No newline at end of file + return wx.MessageDialog(None, _("There are 0 items for this community."), _("Error"), wx.ICON_ERROR).ShowModal() + +def delete_conversation(): + return wx.MessageDialog(None, _("do you really want to delete all messages of this conversation in VK?"), _("Attention"), style=wx.ICON_QUESTION|wx.YES_NO).ShowModal() diff --git a/src/wxUI/menus.py b/src/wxUI/menus.py index f185965..36c1ed9 100644 --- a/src/wxUI/menus.py +++ b/src/wxUI/menus.py @@ -124,4 +124,9 @@ class communityBufferMenu(wx.Menu): self.load_audios = load.Append(wx.NewId(), _("Load audios")) self.load_videos = load.Append(wx.NewId(), _("Load videos")) self.load_documents = load.Append(wx.NewId(), _("Load documents")) - self.Append(wx.NewId(), _("Load"), load) \ No newline at end of file + self.Append(wx.NewId(), _("Load"), load) + +class conversationBufferMenu(wx.Menu): + def __init__(self): + super(conversationBufferMenu, self).__init__() + self.delete = self.Append(wx.NewId(), _("Delete conversation")) \ No newline at end of file From 81a454c29c004905443f3fcc6d82f383831c705b Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Wed, 10 Apr 2019 15:18:46 -0500 Subject: [PATCH 5/7] Read confirmations will be sent in real time in conversations --- changelog.md | 3 ++- src/controller/buffers.py | 11 ++++------- src/controller/mainController.py | 10 ---------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/changelog.md b/changelog.md index c7265f7..068ec1b 100644 --- a/changelog.md +++ b/changelog.md @@ -8,7 +8,8 @@ * For users with multiple soundcards, there is a new tab in the preferences dialogue of Socializer, called sound. From there, you can define what soundcard will be used for input and output. * Improvements in conversation buffers: * it is possible to retrieve more items for conversation buffers. Due to API limitations, it is possible to load up to the last 600 messages for every conversation. Take into account that the process of loading more items takes some time. You will hear a message when the process is done. - * It is possible to delete entire conversations from the tree of buffers, by using the menu key and selecting "delete conversation". The conversation will be removed from VK. + * It is possible to delete entire conversations from the buffer's tree, by using the menu key and selecting "delete conversation". The conversation will be removed from VK. + * Read confirmations will be sent to VK as soon as you read the message. Before, read confirmations were being sent every 3 minutes to the social network. ## Changes in version 0.19 (13.03.2019) diff --git a/src/controller/buffers.py b/src/controller/buffers.py index b8b5e9b..4921892 100644 --- a/src/controller/buffers.py +++ b/src/controller/buffers.py @@ -911,13 +911,11 @@ class chatBuffer(baseBuffer): def insert(self, item, reversed=False): """ Add a new item to the list. Uses session.composefunc for parsing the dictionary and create a valid result for putting it in the list.""" + # as this tab is based in a text control, we have to overwrite the defaults. item_ = getattr(renderers, self.compose_function)(item, self.session) # the self.chat dictionary will have (first_line, last_line) as keys and message ID as a value for looking into it when needed. # Here we will get first and last line of a chat message appended to the history. - lines = self.tab.history.GetNumberOfLines() values = self.tab.add_message(item_[0], reverse=reversed) - if reversed: - values = (values[0]-lines, values[1]-lines) self.chats[values] = item["id"] def get_focused_post(self): @@ -933,7 +931,6 @@ class chatBuffer(baseBuffer): # position[2]+1 is added because line may start with 0, while in wx.TextCtrl.GetNumberLines() that is not possible. if position[2]+1 >= i[0] and position[2]+1 < i[1]: id_ = self.chats[i] -# print i break # Retrieve here the object based in id_ if id_ != None: @@ -949,9 +946,10 @@ class chatBuffer(baseBuffer): msg = self.get_focused_post() if msg == False: # Handle the case where the last line of the control cannot be matched to anything. return - if "read_state" in msg and msg["read_state"] == 0 and msg["id"] not in self.reads and "out" in msg and msg["out"] == 0: + # Mark unread conversations as read. + if "read_state" in msg and msg["read_state"] == 0 and "out" in msg and msg["out"] == 0: self.session.soundplayer.play("message_unread.ogg") - self.reads.append(msg["id"]) + call_threaded(self.session.vk.client.messages.markAsRead, peer_id=self.kwargs["peer_id"]) self.session.db[self.name]["items"][-1]["read_state"] = 1 if "attachments" in msg and len(msg["attachments"]) > 0: self.tab.attachments.list.Enable(True) @@ -1115,7 +1113,6 @@ class chatBuffer(baseBuffer): def __init__(self, unread=False, *args, **kwargs): super(chatBuffer, self).__init__(*args, **kwargs) self.unread = unread - self.reads = [] self.chats = dict() self.peer_typing = 0 self.last_keypress = time.time() diff --git a/src/controller/mainController.py b/src/controller/mainController.py index ebdee22..9660e4e 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -114,8 +114,6 @@ class Controller(object): self.window.realize() self.repeatedUpdate = RepeatingTimer(120, self.update_all_buffers) self.repeatedUpdate.start() - self.readMarker = RepeatingTimer(60, self.mark_as_read) - self.readMarker.start() def complete_buffer_creation(self, buffer, name_, position): answer = buffer.get_items() @@ -158,14 +156,6 @@ class Controller(object): call_threaded(self.chat_from_id, i["last_message"]["peer_id"], setfocus=False, unread=False) time.sleep(0.6) - def mark_as_read(self): - for i in self.buffers: - if hasattr(i, "reads") and len(i.reads) != 0: - response = self.session.vk.client.messages.markAsRead(peer_id=i.kwargs["peer_id"]) - i.clear_reads() - i.reads = [] - time.sleep(1) - def get_audio_albums(self, user_id=None, create_buffers=True, force_action=False): if self.session.settings["load_at_startup"]["audio_albums"] == False and force_action == False: return From 6d6daa60b6b69848539e333973d433340ea59cfa Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Wed, 10 Apr 2019 17:36:02 -0500 Subject: [PATCH 6/7] Added comments to the player module --- src/presenters/player.py | 47 +++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/presenters/player.py b/src/presenters/player.py index e0a67fc..344320e 100644 --- a/src/presenters/player.py +++ b/src/presenters/player.py @@ -1,40 +1,56 @@ # -*- coding: utf-8 -*- +""" Audio player module for socializer. +As this player does not have (still) an associated GUI, I have decided to place here the code for the interactor, which connects a bunch of pubsub events, and the presenter itself. +""" import sys import random -import output -import sound_lib import logging +import sound_lib +import output import config from sound_lib.config import BassConfig from sound_lib.stream import URLStream from sound_lib.main import BassError -from mysc.repeating_timer import RepeatingTimer from pubsub import pub +from mysc.repeating_timer import RepeatingTimer player = None log = logging.getLogger("player") +# This function will be deprecated when the player works with pubsub events, as will no longer be needed to instantiate and import the player directly. def setup(): global player if player == None: player = audioPlayer() class audioPlayer(object): + """ A media player which will play all passed URLS.""" def __init__(self): + # control variable for checking if another file has been sent to the player before, + # thus avoiding double file playback and other oddities happening in sound_lib from time to time. self.is_playing = False + # This will be the URLStream handler self.stream = None self.vol = config.app["sound"]["volume"] + # this variable is set to true when the URLPlayer is decoding something, thus it will block other calls to the play method. self.is_working = False + # Playback queue. self.queue = [] + # Index of the currently playing track. self.playing_track = 0 + # Status of the player. self.stopped = True # Modify some default settings present in Bass so it will increase timeout connection, thus causing less "connection timed out" errors when playing. bassconfig = BassConfig() # Set timeout connection to 30 seconds. bassconfig["net_timeout"] = 30000 - def play(self, url, set_info=True, fresh=False): + def play(self, object, set_info=True, fresh=False): + """ Play an URl Stream. + @object dict: typically an audio object as returned by VK, with a "url" component which must be a valid URL to a media file. + @set_info bool: If true, will set information about the currently playing audio in the application status bar. + @fresh bool: If True, will remove everything playing in the queue and start this file only. otherwise it will play the new file but not remove the current queue.""" if self.stream != None and self.stream.is_playing == True: try: self.stream.stop() @@ -50,19 +66,15 @@ class audioPlayer(object): if self.is_working == False: self.is_working = True # Let's encode the URL as bytes if on Python 3 - if sys.version[0] == "3": - url_ = bytes(url["url"], "utf-8") - else: - url_ = url["url"] + url_ = bytes(object["url"], "utf-8") try: self.stream = URLStream(url=url_) except IndexError: - log.error("Unable to play URL") - log.error(url_) + log.error("Unable to play URL %s" % (url_)) return # Translators: {0} will be replaced with a song's title and {1} with the artist. if set_info: - msg = _("Playing {0} by {1}").format(url["title"], url["artist"]) + msg = _("Playing {0} by {1}").format(object["title"], object["artist"]) pub.sendMessage("update-status-bar", status=msg) self.stream.volume = self.vol/100.0 self.stream.play() @@ -70,6 +82,7 @@ class audioPlayer(object): self.is_working = False def stop(self): + """ Stop audio playback. """ if self.stream != None and self.stream.is_playing == True: self.stream.stop() self.stopped = True @@ -79,6 +92,7 @@ class audioPlayer(object): self.queue = [] def pause(self): + """ pause the current playback, without destroying the queue or the current stream. If the stream is already paused this function will resume the playback. """ if self.stream != None: if self.stream.is_playing == True: self.stream.pause() @@ -105,11 +119,14 @@ class audioPlayer(object): if self.stream != None: self.stream.volume = self.vol/100.0 - def play_all(self, list_of_urls, shuffle=False): + def play_all(self, list_of_songs, shuffle=False): + """ Play all passed songs and adds all of those to the queue. + @list_of_songs list: A list of audio objects returned by VK. + @shuffle bool: If True, the files will be played randomly.""" self.playing_track = 0 self.stop() # Skip all country restricted tracks as they are not playable here. - self.queue = [i for i in list_of_urls if i["url"] != ""] + self.queue = [i for i in list_of_songs if i["url"] != ""] if shuffle: random.shuffle(self.queue) self.play(self.queue[self.playing_track]) @@ -117,6 +134,7 @@ class audioPlayer(object): self.worker.start() def player_function(self): + """ Check if the stream has reached the end of the file so it will play the next song. """ if self.stream != None and self.stream.is_playing == False and self.stopped == False and len(self.stream) == self.stream.position: if len(self.queue) == 0 or self.playing_track >= len(self.queue): self.worker.cancel() @@ -126,6 +144,7 @@ class audioPlayer(object): self.play(self.queue[self.playing_track]) def play_next(self): + """ Play the next song in the queue. """ if len(self.queue) == 0: return if self.playing_track < len(self.queue)-1: @@ -135,6 +154,7 @@ class audioPlayer(object): self.play(self.queue[self.playing_track]) def play_previous(self): + """ Play the previous song in the queue. """ if len(self.queue) == 0: return if self.playing_track <= 0: @@ -144,6 +164,7 @@ class audioPlayer(object): self.play(self.queue[self.playing_track]) def check_is_playing(self): + """ check if the player is already playing a stream. """ if self.stream == None: return False if self.stream != None and self.stream.is_playing == False: From 9cb1f9647c780991decb195a66f3f9ea727632b5 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Wed, 10 Apr 2019 17:49:23 -0500 Subject: [PATCH 7/7] Started pubsub implementation in all player related functions --- src/controller/mainController.py | 4 ++-- src/presenters/player.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 9660e4e..f511279 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -340,13 +340,13 @@ class Controller(object): if "url" in audio_object and audio_object["url"] =="": self.notify(message=_("This file could not be played because it is not allowed in your country")) return - call_threaded(player.player.play, audio_object, fresh=True) + pub.sendMessage("play", object=audio_object, fresh=True) def play_audios(self, audios): """ Play all audios passed in alist, putting the audio in a queue of the media player. @audios list: A list of Vk audio objects. """ - player.player.play_all(audios, shuffle=self.window.player_shuffle.IsChecked()) + pub.sendMessage("play_all", list_of_songs=audios, shuffle=self.window.player_shuffle.IsChecked()) def view_post(self, post_object, controller_): """ Display the passed post in the passed post presenter. diff --git a/src/presenters/player.py b/src/presenters/player.py index 344320e..8a4c332 100644 --- a/src/presenters/player.py +++ b/src/presenters/player.py @@ -45,6 +45,12 @@ class audioPlayer(object): bassconfig = BassConfig() # Set timeout connection to 30 seconds. bassconfig["net_timeout"] = 30000 + pub.subscribe(self.play, "play") + pub.subscribe(self.play_all, "play_all") + pub.subscribe(self.pause, "pause") + pub.subscribe(self.stop, "stop") + pub.subscribe(self.play_next, "play_next") + pub.subscribe(self.play_previous, "play_previous") def play(self, object, set_info=True, fresh=False): """ Play an URl Stream.