From fb06df8578992d00bcd66ffb677fb0bafe4dc56d Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Thu, 20 Dec 2018 17:46:54 -0600 Subject: [PATCH] Started an effort to merge the attachment dialogs in socializer. It will be possible to add both local files and files already present in VK --- src/controller/attach.py | 23 +++++++++++++++++------ src/wxUI/menus.py | 8 ++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/controller/attach.py b/src/controller/attach.py index 6458257..e594e87 100644 --- a/src/controller/attach.py +++ b/src/controller/attach.py @@ -5,6 +5,7 @@ import logging import widgetUtils from wxUI.dialogs import attach as gui from wxUI.dialogs import selector +from wxUI.menus import attachMenu log = logging.getLogger(__file__) class attachFromLocal(object): @@ -21,23 +22,33 @@ class attachFromLocal(object): # Type is just a reference, as there will be local and online based attachments. self.type = "local" self.dialog = gui.attachDialog(voice_messages) - widgetUtils.connect_event(self.dialog.photo, widgetUtils.BUTTON_PRESSED, self.upload_image) - widgetUtils.connect_event(self.dialog.audio, widgetUtils.BUTTON_PRESSED, self.upload_audio) + 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.remove, widgetUtils.BUTTON_PRESSED, self.remove_attachment) self.dialog.get_response() log.debug("Attachments controller started.") + def on_image(self, *args, **kwargs): + m = attachMenu() + widgetUtils.connect_event(m, widgetUtils.MENU, self.upload_image, menuitem=m.upload) + self.dialog.PopupMenu(m, self.dialog.photo.GetPosition()) + + def on_audio(self, *args, **kwargs): + m = attachMenu() + widgetUtils.connect_event(m, widgetUtils.MENU, self.upload_audio, menuitem=m.upload) + self.dialog.PopupMenu(m, self.dialog.photo.GetPosition()) + def upload_image(self, *args, **kwargs): """ allows uploading an image from the computer. In theory """ image, description = self.dialog.get_image() if image != None: # Define data structure for this attachment, as will be required by VK API later. - imageInfo = {"type": "photo", "file": image, "description": description} + imageInfo = {"type": "photo", "file": image, "description": description, "from": "local"} log.debug("Image data to upload: %r" % (imageInfo,)) self.attachments.append(imageInfo) # Translators: This is the text displayed in the attachments dialog, when the user adds a photo. - info = [_(u"Photo"), os.path.basename(image)] + info = [_(u"Photo"), description] self.dialog.attachments.insert_item(False, *info) self.dialog.remove.Enable(True) @@ -45,7 +56,7 @@ class attachFromLocal(object): audio = self.dialog.get_audio() if audio != None: # Define data structure for this attachment, as will be required by VK API later. - audioInfo = {"type": "audio", "file": audio} + audioInfo = {"type": "audio", "file": audio, "from": "local"} log.debug("Audio data to upload: %r" % (audioInfo,)) self.attachments.append(audioInfo) # Translators: This is the text displayed in the attachments dialog, when the user adds a photo. @@ -109,4 +120,4 @@ class attachFromOnline(object): # Define data structures required by VK API. preresult = "{0}{1}_{2}".format(i["type"], i["owner_id"], i["id"]) result = preresult+"," - return result \ No newline at end of file + return result diff --git a/src/wxUI/menus.py b/src/wxUI/menus.py index d3e8ad3..a7844a3 100644 --- a/src/wxUI/menus.py +++ b/src/wxUI/menus.py @@ -79,3 +79,11 @@ class notificationsMenu(wx.Menu): super(notificationsMenu, self).__init__() self.mark_as_read = wx.MenuItem(self, wx.NewId(), _(u"Mark as read")) self.Append(self.mark_as_read) + +class attachMenu(wx.Menu): + def __init__(self): + super(attachMenu, self).__init__() + self.upload = wx.MenuItem(self, wx.NewId(), _(u"Upload from computer")) + self.Append(self.upload) + self.add = wx.MenuItem(self, wx.NewId(), _(u"Add from VK")) + self.Append(self.add) \ No newline at end of file