Finished rework of attachments methods for wall posts
This commit is contained in:
parent
fb06df8578
commit
abcbbe9ae2
@ -9,7 +9,7 @@
|
|||||||
* Adding and removing an audio file to your library works.
|
* Adding and removing an audio file to your library works.
|
||||||
* Unread messages will play a sound when focused.
|
* Unread messages will play a sound when focused.
|
||||||
* Unread messages will be marked as read when user focuses them.
|
* Unread messages will be marked as read when user focuses them.
|
||||||
* Socializer will skip restricted audio tracks. Restricted songs are not allowed to be played in the user's country. Before, playing a restricted track was generating an exception and playback could not resume.
|
* Socializer will handle restricted audio tracks. Restricted songs are not allowed to be played in the user's country. Before, playing a restricted track was generating an exception and playback could not resume. Now, playing an audio track will display an error notification.
|
||||||
* Fixed an error when people was trying to open a post in an empty buffer, or accessing the menu when there are no posts in the buffer.
|
* Fixed an error when people was trying to open a post in an empty buffer, or accessing the menu when there are no posts in the buffer.
|
||||||
* Now Socializer will not send a notification every 5 minutes.
|
* Now Socializer will not send a notification every 5 minutes.
|
||||||
* the chat widget now is a multiline text control. It means it is possible to add a new line by pressing shift+Enter, and send the message by pressing enter.
|
* the chat widget now is a multiline text control. It means it is possible to add a new line by pressing shift+Enter, and send the message by pressing enter.
|
||||||
@ -17,6 +17,7 @@
|
|||||||
* When trying to add an audio or video to an album, if the current user does not have any album, it will display an error instead of a traceback.
|
* When trying to add an audio or video to an album, if the current user does not have any album, it will display an error instead of a traceback.
|
||||||
* Added popular and suggested songs. This will not work when using alternative tokens.
|
* Added popular and suggested songs. This will not work when using alternative tokens.
|
||||||
* Now it is possible to update the status message, located in your profile.
|
* Now it is possible to update the status message, located in your profile.
|
||||||
|
* Now it is possible to upload an audio from your computer when adding attachments in a wall post.
|
||||||
* Updated Russian translation: thanks to Дарья Ратникова.
|
* Updated Russian translation: thanks to Дарья Ратникова.
|
||||||
* new versions will include documentation and changelog.
|
* new versions will include documentation and changelog.
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
""" Attachment upload methods for different kind of posts in VK. This should become the framework for posting attachment files to the social network."""
|
""" Attachment controller for different kind of posts in VK. This should become the framework for posting attachment files to the social network.
|
||||||
|
this controller will take care of preparing data structures to be uploaded later, when the user decides to start the upload process by sending the post.
|
||||||
|
"""
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import widgetUtils
|
import widgetUtils
|
||||||
@ -8,38 +10,46 @@ from wxUI.dialogs import selector
|
|||||||
from wxUI.menus import attachMenu
|
from wxUI.menus import attachMenu
|
||||||
log = logging.getLogger(__file__)
|
log = logging.getLogger(__file__)
|
||||||
|
|
||||||
class attachFromLocal(object):
|
class attach(object):
|
||||||
""" Controller used in some sections of the application, mainly for uploading photos from the local computer to VK.
|
""" Controller used in some sections of the application, it can do the following:
|
||||||
This controller will not upload the contents by itself, but will generate the data structures for being sent over the VK API.
|
|
||||||
At the current time, only photo uploading is supported."""
|
|
||||||
|
|
||||||
def __init__(self, voice_messages=False):
|
* Handle all user input related to adding local or online files (online files are those already uploaded in vk).
|
||||||
|
* Prepare local files to be uploaded once a post will be sent (no uploading work is done here, but structured dicts will be generated).
|
||||||
|
* Parse online files and allow addition of them as attachment, so this controller will add both local and online files in the same dialog.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, session, voice_messages=False):
|
||||||
""" Constructor.
|
""" Constructor.
|
||||||
|
@ session sessionmanager.session object: an object capable of calling all VK methods.
|
||||||
@voice_messages bool: If True, will add a button for sending voice messages. Functionality for this button has not been added yet.
|
@voice_messages bool: If True, will add a button for sending voice messages. Functionality for this button has not been added yet.
|
||||||
"""
|
"""
|
||||||
|
self.session = session
|
||||||
# Self.attachments will hold a reference to all attachments added to the dialog.
|
# Self.attachments will hold a reference to all attachments added to the dialog.
|
||||||
self.attachments = list()
|
self.attachments = list()
|
||||||
# Type is just a reference, as there will be local and online based attachments.
|
|
||||||
self.type = "local"
|
|
||||||
self.dialog = gui.attachDialog(voice_messages)
|
self.dialog = gui.attachDialog(voice_messages)
|
||||||
widgetUtils.connect_event(self.dialog.photo, widgetUtils.BUTTON_PRESSED, self.on_image)
|
widgetUtils.connect_event(self.dialog.photo, widgetUtils.BUTTON_PRESSED, self.on_image)
|
||||||
widgetUtils.connect_event(self.dialog.audio, widgetUtils.BUTTON_PRESSED, self.on_audio)
|
widgetUtils.connect_event(self.dialog.audio, widgetUtils.BUTTON_PRESSED, self.on_audio)
|
||||||
widgetUtils.connect_event(self.dialog.remove, widgetUtils.BUTTON_PRESSED, self.remove_attachment)
|
widgetUtils.connect_event(self.dialog.remove, widgetUtils.BUTTON_PRESSED, self.remove_attachment)
|
||||||
self.dialog.get_response()
|
|
||||||
log.debug("Attachments controller started.")
|
log.debug("Attachments controller started.")
|
||||||
|
self.dialog.get_response()
|
||||||
|
|
||||||
def on_image(self, *args, **kwargs):
|
def on_image(self, *args, **kwargs):
|
||||||
|
""" display menu for adding image attachments. """
|
||||||
m = attachMenu()
|
m = attachMenu()
|
||||||
|
# disable add from VK as it is not supported in images, yet.
|
||||||
|
m.add.Enable(False)
|
||||||
widgetUtils.connect_event(m, widgetUtils.MENU, self.upload_image, menuitem=m.upload)
|
widgetUtils.connect_event(m, widgetUtils.MENU, self.upload_image, menuitem=m.upload)
|
||||||
self.dialog.PopupMenu(m, self.dialog.photo.GetPosition())
|
self.dialog.PopupMenu(m, self.dialog.photo.GetPosition())
|
||||||
|
|
||||||
def on_audio(self, *args, **kwargs):
|
def on_audio(self, *args, **kwargs):
|
||||||
|
""" display menu to add audio attachments."""
|
||||||
m = attachMenu()
|
m = attachMenu()
|
||||||
widgetUtils.connect_event(m, widgetUtils.MENU, self.upload_audio, menuitem=m.upload)
|
widgetUtils.connect_event(m, widgetUtils.MENU, self.upload_audio, menuitem=m.upload)
|
||||||
self.dialog.PopupMenu(m, self.dialog.photo.GetPosition())
|
widgetUtils.connect_event(m, widgetUtils.MENU, self.add_audio, menuitem=m.add)
|
||||||
|
self.dialog.PopupMenu(m, self.dialog.audio.GetPosition())
|
||||||
|
|
||||||
def upload_image(self, *args, **kwargs):
|
def upload_image(self, *args, **kwargs):
|
||||||
""" allows uploading an image from the computer. In theory
|
""" allows uploading an image from the computer.
|
||||||
"""
|
"""
|
||||||
image, description = self.dialog.get_image()
|
image, description = self.dialog.get_image()
|
||||||
if image != None:
|
if image != None:
|
||||||
@ -53,17 +63,37 @@ class attachFromLocal(object):
|
|||||||
self.dialog.remove.Enable(True)
|
self.dialog.remove.Enable(True)
|
||||||
|
|
||||||
def upload_audio(self, *args, **kwargs):
|
def upload_audio(self, *args, **kwargs):
|
||||||
|
""" Allows uploading an audio file from the computer. Only mp3 files are supported. ID3 tags are not extracted automatically, yet."""
|
||||||
audio = self.dialog.get_audio()
|
audio = self.dialog.get_audio()
|
||||||
if audio != None:
|
if audio != None:
|
||||||
# Define data structure for this attachment, as will be required by VK API later.
|
# Define data structure for this attachment, as will be required by VK API later.
|
||||||
audioInfo = {"type": "audio", "file": audio, "from": "local"}
|
audioInfo = {"type": "audio", "file": audio, "from": "local"}
|
||||||
log.debug("Audio data to upload: %r" % (audioInfo,))
|
log.debug("Audio data to upload: %r" % (audioInfo,))
|
||||||
self.attachments.append(audioInfo)
|
self.attachments.append(audioInfo)
|
||||||
# Translators: This is the text displayed in the attachments dialog, when the user adds a photo.
|
# Translators: This is the text displayed in the attachments dialog, when the user adds an audio file.
|
||||||
info = [_(u"Audio file"), os.path.basename(audio)]
|
info = [_(u"Audio file"), os.path.basename(audio)]
|
||||||
self.dialog.attachments.insert_item(False, *info)
|
self.dialog.attachments.insert_item(False, *info)
|
||||||
self.dialog.remove.Enable(True)
|
self.dialog.remove.Enable(True)
|
||||||
|
|
||||||
|
def add_audio(self, *args, **kwargs):
|
||||||
|
""" Allow adding an audio directly from the user's audio library."""
|
||||||
|
# Let's reuse the already downloaded audios.
|
||||||
|
list_of_audios = self.session.db["me_audio"]["items"]
|
||||||
|
audios = []
|
||||||
|
for i in list_of_audios:
|
||||||
|
audios.append(u"{0}, {1}".format(i["title"], i["artist"]))
|
||||||
|
select = selector.selectAttachment(_(u"Select the audio files you want to send"), audios)
|
||||||
|
if select.get_response() == widgetUtils.OK and select.attachments.GetCount() > 0:
|
||||||
|
attachments = select.get_all_attachments()
|
||||||
|
for i in attachments:
|
||||||
|
info = dict(type="audio", id=list_of_audios[i]["id"], owner_id=list_of_audios[i]["owner_id"])
|
||||||
|
info["from"] = "online"
|
||||||
|
self.attachments.append(info)
|
||||||
|
# Translators: This is the text displayed in the attachments dialog, when the user adds an audio file.
|
||||||
|
info2 = [_(u"Audio file"), u"{0} - {1}".format(list_of_audios[i]["title"], list_of_audios[i]["artist"])]
|
||||||
|
self.dialog.attachments.insert_item(False, *info2)
|
||||||
|
self.check_remove_status()
|
||||||
|
|
||||||
def remove_attachment(self, *args, **kwargs):
|
def remove_attachment(self, *args, **kwargs):
|
||||||
""" Remove the currently focused item from the attachments list."""
|
""" Remove the currently focused item from the attachments list."""
|
||||||
current_item = self.dialog.attachments.get_selected()
|
current_item = self.dialog.attachments.get_selected()
|
||||||
@ -111,6 +141,7 @@ class attachFromOnline(object):
|
|||||||
attachments = select.get_all_attachments()
|
attachments = select.get_all_attachments()
|
||||||
for i in attachments:
|
for i in attachments:
|
||||||
list_of_audios[i]["type"] = "audio"
|
list_of_audios[i]["type"] = "audio"
|
||||||
|
list_of_audios[i]["from"] = "online"
|
||||||
self.attachments.append(list_of_audios[i])
|
self.attachments.append(list_of_audios[i])
|
||||||
|
|
||||||
def parse_attachments(self):
|
def parse_attachments(self):
|
||||||
|
@ -139,15 +139,16 @@ class baseBuffer(object):
|
|||||||
local_attachments = ""
|
local_attachments = ""
|
||||||
uploader = upload.VkUpload(self.session.vk.session_object)
|
uploader = upload.VkUpload(self.session.vk.session_object)
|
||||||
for i in attachments:
|
for i in attachments:
|
||||||
if i["type"] == "photo":
|
if i["from"] == "online":
|
||||||
|
local_attachments += "{0}{1}_{2},".format(i["type"], i["owner_id"], i["id"])
|
||||||
|
elif i["from"] == "local" and i["type"] == "photo":
|
||||||
photos = i["file"]
|
photos = i["file"]
|
||||||
description = i["description"]
|
description = i["description"]
|
||||||
r = uploader.photo_wall(photos, caption=description)
|
r = uploader.photo_wall(photos, caption=description)
|
||||||
id = r[0]["id"]
|
id = r[0]["id"]
|
||||||
owner_id = r[0]["owner_id"]
|
owner_id = r[0]["owner_id"]
|
||||||
local_attachments += "photo{0}_{1},".format(owner_id, id)
|
local_attachments += "photo{0}_{1},".format(owner_id, id)
|
||||||
|
elif i["from"] == "local" and i["type"] == "audio":
|
||||||
elif i["type"] == "audio":
|
|
||||||
audio = i["file"]
|
audio = i["file"]
|
||||||
r = uploader.audio(audio, "untitled", "untitled")
|
r = uploader.audio(audio, "untitled", "untitled")
|
||||||
id = r["id"]
|
id = r["id"]
|
||||||
|
@ -70,7 +70,7 @@ class post(object):
|
|||||||
checker.clean()
|
checker.clean()
|
||||||
|
|
||||||
def show_attach_dialog(self, *args, **kwargs):
|
def show_attach_dialog(self, *args, **kwargs):
|
||||||
a = attach.attachFromLocal()
|
a = attach.attach(self.session)
|
||||||
if len(a.attachments) != 0:
|
if len(a.attachments) != 0:
|
||||||
self.attachments = a.attachments
|
self.attachments = a.attachments
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user