Basic update profile function, some minor bugfixes, sound playback improvements

This commit is contained in:
Manuel Cortez 2015-03-06 21:37:08 -06:00
parent 373ca24a96
commit e65c8ec4a6
8 changed files with 128 additions and 29 deletions

View File

@ -7,6 +7,7 @@ import output
import config
import sound
import messages
import updateProfile
import languageHandler
import logging
from twitter import compose, utils
@ -370,12 +371,12 @@ class baseBufferController(bufferController):
if tweet == None: return
urls = utils.find_urls(tweet)
if len(urls) == 1:
sound.URLPlayer.play(urls[0])
sound.URLPlayer.play(urls[0], self.session.settings["sound"]["volume"])
else:
urls_list = dialogs.urlList.urlList()
urls_list.populate_list(urls)
if urls_list.get_response() == widgetUtils.OK:
sound.URLPlayer.play(urls_list.get_string())
sound.URLPlayer.play(urls_list.get_string(), self.session.settings["sound"]["volume"])
@_tweets_exist
def url(self):
@ -543,6 +544,9 @@ class peopleBufferController(baseBufferController):
self.session.db[self.name]["cursor"] = -1
self.buffer.list.clear()
def url(self):
updateProfile.updateProfileController(self.session, user=self.get_right_tweet()["screen_name"])
class searchBufferController(baseBufferController):
def start_stream(self):
log.debug("Starting stream for %s buffer, %s account and %s type" % (self.name, self.account, self.type))

View File

@ -28,6 +28,7 @@ if platform.system() == "Windows":
from keyboard_handler.wx_handler import WXKeyboardHandler
import userActionsController
import trendingTopics
import updateProfile
import webbrowser
log = logging.getLogger("mainController")
@ -149,6 +150,7 @@ class Controller(object):
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.visit_website, menuitem=self.view.visit_website)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.edit_keystrokes, menuitem=self.view.keystroke_editor)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.manage_accounts, self.view.manage_accounts)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.update_profile, menuitem=self.view.updateProfile)
widgetUtils.connect_event(self.view.nb, widgetUtils.NOTEBOOK_PAGE_CHANGED, self.buffer_changed)
def __init__(self):
@ -1068,5 +1070,8 @@ class Controller(object):
self.accounts.remove(session_.sessions[i].settings["twitter"]["user_name"])
session_.sessions.pop(i)
def update_profile(self, *args, **kwargs):
r = updateProfile.updateProfileController(self.get_best_buffer().session)
def __del__(self):
config.app.write()

View File

@ -79,7 +79,7 @@ class accountSettingsController(globalSettingsController):
self.soundpacks = []
[self.soundpacks.append(i) for i in os.listdir(paths.sound_path()) if os.path.isdir(paths.sound_path(i)) == True ]
self.dialog.create_sound(self.input_devices, self.output_devices, self.soundpacks)
self.dialog.set_value("sound", "volumeCtrl", self.config["sound"]["volume"])
self.dialog.set_value("sound", "volumeCtrl", self.config["sound"]["volume"]*100)
self.dialog.set_value("sound", "input", self.config["sound"]["input_device"])
self.dialog.set_value("sound", "output", self.config["sound"]["output_device"])
self.dialog.set_value("sound", "global_mute", self.config["sound"]["global_mute"])
@ -136,7 +136,9 @@ class accountSettingsController(globalSettingsController):
self.config["sound"]["output_device"] = "default"
self.config["sound"]["volume"] = self.dialog.get_value("sound", "volumeCtrl")/100.0
self.config["sound"]["global_mute"] = self.dialog.get_value("sound", "global_mute")
print self.dialog.sound.get("soundpack")
self.config["sound"]["soundpack"] = self.dialog.sound.get("soundpack")
self.buffer.session.sound.config = self.config["sound"]
self.buffer.session.sound.check_soundpack()
self.config["sound"]["sndup_api_key"] = self.dialog.get_value("services", "apiKey")

View File

@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
import widgetUtils
import output
from wxUI.dialogs import update_profile
from twython import TwythonError
class updateProfileController(object):
def __init__(self, session, user=None):
super(updateProfileController, self).__init__()
self.file = None
self.session = session
self.user = user
self.dialog = update_profile.updateProfileDialog()
if user == None:
self.get_data(screen_name=self.session.db["user_name"])
self.uploaded = False
widgetUtils.connect_event(self.dialog.upload_image, widgetUtils.BUTTON_PRESSED, self.upload_image)
else:
self.get_data(screen_name=self.user)
self.dialog.set_readonly()
if self.dialog.get_response() == widgetUtils.OK and self.user == None:
self.do_update()
def get_data(self, screen_name):
data = self.session.twitter.twitter.show_user(screen_name=screen_name)
self.dialog.set_name(data["name"])
if data["url"] != None:
self.dialog.set_url(data["url"])
if len(data["location"]) > 0:
self.dialog.set_location(data["location"])
if len(data["description"]) > 0:
self.dialog.set_description(data["description"])
def get_image(self):
file = self.dialog.upload_picture()
if file != None:
self.file = open(file, "rb")
self.uploaded = True
self.dialog.change_upload_button(self.uploaded)
def discard_image(self):
self.file = None
output.speak(_(u"Discarded"))
self.uploaded = False
self.dialog.change_upload_button(self.uploaded)
def upload_image(self, *args, **kwargs):
if self.uploaded == False:
self.get_image()
elif self.uploaded == True:
self.discard_image()
def do_update(self):
name = self.dialog.get("name")
description = self.dialog.get("description")
location = self.dialog.get("location")
url = self.dialog.get("url")
if self.file != None:
try:
self.session.twitter.twitter.update_profile_image(image=self.file)
except TwythonError as e:
output.speak(u"Error %s. %s" % (e.error_code, e.msg))
try:
self.session.twitter.twitter.update_profile(name=name, description=description, location=location, url=url)
except TwythonError as e:
output.speak(u"Error %s. %s" % (e.error_code, e.msg))

View File

@ -16,7 +16,7 @@ actions = {
"send_dm": _(u"Send direct message"),
"add_to_favourites": _(u"Mark as favourite"),
"remove_from_favourites": _(u"Remove from favourites"),
"action": _(u"Open the actions dialogue"),
"follow": _(u"Open the actions dialogue"),
"details": _(u"See user details"),
"view_item": _(u"Show tweet"),
"exit": _(u"Quit"),

View File

@ -2,7 +2,6 @@
import sys
import url_shortener
import audio_services
import config
import os
import logging as original_logger
log = original_logger.getLogger("sound")
@ -107,7 +106,7 @@ class URLStream(object):
self.url = transformer(self.url)
self.prepared = True
def play(self, url):
def play(self, url, volume=1.0):
if hasattr(self, "stream") and self.stream.is_playing:
output.speak(_(u"Stopped"))
self.stream.stop()
@ -117,7 +116,7 @@ class URLStream(object):
self.prepare(url)
if self.prepared == True:
self.stream = sound_lib.stream.URLStream(url=self.url)
self.stream.volume = float(config.app["app-settings"]["volume"])
self.stream.volume = float(volume)
self.stream.play()
@staticmethod

View File

@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
import wx
import baseDialog
class updateProfile(wx.Dialog):
def __init__(self, parent):
super(updateProfile, self).__init__(parent=None, id=-1)
class updateProfileDialog(baseDialog.BaseWXDialog):
def __init__(self):
super(updateProfileDialog, self).__init__(parent=None, id=-1)
self.SetTitle(_(u"Update your profile"))
panel = wx.Panel(self)
labelName = wx.StaticText(panel, -1, _(u"Name (20 characters maximum)"))
@ -29,10 +30,8 @@ class updateProfile(wx.Dialog):
self.description.SetSize(dc.GetTextExtent("0"*160))
self.image = None
self.upload_image = wx.Button(panel, -1, _(u"Upload a picture"))
self.upload_image.Bind(wx.EVT_BUTTON, self.onUpload_picture)
ok = wx.Button(panel, wx.ID_OK, _(u"Update profile"))
ok.Bind(wx.EVT_BUTTON, self.onUpdateProfile)
ok.SetDefault()
self.ok = wx.Button(panel, wx.ID_OK, _(u"Update profile"))
self.ok.SetDefault()
close = wx.Button(panel, wx.ID_CANCEL, _("Close"))
sizer = wx.BoxSizer(wx.VERTICAL)
nameBox = wx.BoxSizer(wx.HORIZONTAL)
@ -53,23 +52,47 @@ class updateProfile(wx.Dialog):
sizer.Add(descriptionBox, 0, wx.ALL, 5)
sizer.Add(self.upload_image, 5, wx.CENTER, 5)
btnBox = wx.BoxSizer(wx.HORIZONTAL)
btnBox.Add(ok, 0, wx.ALL, 5)
btnBox.Add(self.ok, 0, wx.ALL, 5)
btnBox.Add(close, 0, wx.ALL, 5)
sizer.Add(btnBox, 0, wx.ALL, 5)
panel.SetSizer(sizer)
self.SetClientSize(sizer.CalcMin())
def onUpload_picture(self, ev):
if self.upload_image.GetLabel() == _(u"Discard image"):
self.upload_image.SetLabel(_(u"Upload a picture"))
self.controller.clear_file()
else:
openFileDialog = wx.FileDialog(self, _(u"Select the picture to be uploaded"), "", "", _("Image files (*.png, *.jpg, *.gif)|*.png; *.jpg; *.gif"), wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return
self.controller.get_file(openFileDialog.GetPath())
self.upload_image.SetLabel(_(u"Discard image"))
ev.Skip()
def set_name(self, name):
self.set("name", name)
def get_response(self):
return self.ShowModal()
def set_description(self, description):
self.set("description", description)
def set_location(self, location):
self.set("location", location)
def set_url(self, url):
self.set("url", url)
def change_upload_button(self, uploaded=False):
if uploaded == False:
self.upload_image.SetLabel(_(u"Upload a picture"))
else:
self.upload_image.SetLabel(_(u"Discard image"))
def upload_picture(self):
openFileDialog = wx.FileDialog(self, _(u"Select the picture to be uploaded"), "", "", _("Image files (*.png, *.jpg, *.gif)|*.png; *.jpg; *.gif"), wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return None
return openFileDialog.GetPath()
def hide_upload_button(self, hide):
self.upload_image.Enable(hide)
def set_readonly(self):
self.name.style = wx.TE_READONLY
self.name.Refresh()
self.description.style = wx.TE_READONLY
self.description.Refresh()
self.location.style = wx.TE_READONLY
self.location.Refresh()
self.url.style = wx.TE_READONLY
self.url.Refresh()
self.hide_upload_button(False)
self.ok.Enable(False)

View File

@ -14,7 +14,6 @@ class mainFrame(wx.Frame):
app = wx.Menu()
self.manage_accounts = app.Append(wx.NewId(), _(u"Manage accounts"))
self.updateProfile = app.Append(wx.NewId(), _(u"&Update profile"))
self.updateProfile.Enable(False)
self.show_hide = app.Append(wx.NewId(), _(u"&Hide window"))
self.menuitem_search = app.Append(wx.NewId(), _(u"&Search"))
self.trends = app.Append(wx.NewId(), _(u"View &trending topics"))