view user info is now posible from the menu bar or control+win+shift+n

This commit is contained in:
2015-03-08 14:18:29 -06:00
parent 007da773c9
commit 2cc865b62c
11 changed files with 185 additions and 87 deletions

View File

@@ -7,7 +7,7 @@ import output
import config
import sound
import messages
import updateProfile
import user
import languageHandler
import logging
from twitter import compose, utils
@@ -415,6 +415,19 @@ class baseBufferController(bufferController):
except TwythonError:
self.session.sound.play("error.ogg")
@_tweets_exist
def user_details(self):
tweet = self.get_tweet()
if self.type == "dm":
users = utils.get_all_users(tweet, self.session.db)
elif self.type == "people":
users = [tweet["screen_name"]]
else:
users = utils.get_all_users(tweet, self.session.db)
dlg = dialogs.utils.selectUserDialog(title=_(u"User details"), users=users)
if dlg.get_response() == widgetUtils.OK:
user.profileController(session=self.session, user=dlg.get_user())
class eventsBufferController(bufferController):
def __init__(self, parent, name, session, account, *args, **kwargs):
super(eventsBufferController, self).__init__(parent, *args, **kwargs)
@@ -545,7 +558,7 @@ class peopleBufferController(baseBufferController):
self.buffer.list.clear()
def url(self):
updateProfile.updateProfileController(self.session, user=self.get_right_tweet()["screen_name"])
user.profileController(self.session, user=self.get_right_tweet()["screen_name"])
class searchBufferController(baseBufferController):
def start_stream(self):

View File

@@ -28,7 +28,7 @@ if platform.system() == "Windows":
from keyboard_handler.wx_handler import WXKeyboardHandler
import userActionsController
import trendingTopics
import updateProfile
import user
import webbrowser
log = logging.getLogger("mainController")
@@ -151,6 +151,7 @@ class Controller(object):
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, widgetUtils.MENU, self.user_details, menuitem=self.view.details)
widgetUtils.connect_event(self.view.nb, widgetUtils.NOTEBOOK_PAGE_CHANGED, self.buffer_changed)
def __init__(self):
@@ -1073,7 +1074,13 @@ class Controller(object):
session_.sessions.pop(i)
def update_profile(self, *args, **kwargs):
r = updateProfile.updateProfileController(self.get_best_buffer().session)
r = user.profileController(self.get_best_buffer().session)
def user_details(self, *args, **kwargs):
buffer = self.get_current_buffer()
if not hasattr(buffer, "session") or buffer.session == None: return
if hasattr(buffer, "user_details"):
buffer.user_details()
def __del__(self):
config.app.write()

View File

@@ -1,67 +0,0 @@
# -*- 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))

99
src/controller/user.py Normal file
View File

@@ -0,0 +1,99 @@
# -*- coding: utf-8 -*-
import webbrowser
import widgetUtils
import output
from wxUI.dialogs import update_profile, show_user
from twython import TwythonError
class profileController(object):
def __init__(self, session, user=None):
super(profileController, self).__init__()
self.file = None
self.session = session
self.user = user
if user == None:
self.dialog = update_profile.updateProfileDialog()
self.get_data(screen_name=self.session.db["user_name"])
self.fill_profile_fields()
self.uploaded = False
widgetUtils.connect_event(self.dialog.upload_image, widgetUtils.BUTTON_PRESSED, self.upload_image)
else:
self.dialog = show_user.showUserProfile()
self.get_data(screen_name=self.user)
string = self.get_user_info()
self.dialog.set("text", string)
self.dialog.set_title(_(u"Information for %s") % (self.data["screen_name"]))
if self.data["url"] != None:
self.dialog.enable_url()
widgetUtils.connect_event(self.dialog.url, widgetUtils.BUTTON_PRESSED, self.visit_url)
if self.dialog.get_response() == widgetUtils.OK and self.user == None:
self.do_update()
def get_data(self, screen_name):
self.data = self.session.twitter.twitter.show_user(screen_name=screen_name)
def fill_profile_fields(self):
self.dialog.set_name(self.data["name"])
if self.data["url"] != None:
self.dialog.set_url(self.data["url"])
if len(self.data["location"]) > 0:
self.dialog.set_location(self.data["location"])
if len(self.data["description"]) > 0:
self.dialog.set_description(self.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):
if self.user != None: return
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))
def get_user_info(self):
string = u""
string = string + _(u"Username: @%s\n") % (self.data["screen_name"])
string = string + _(u"Name: %s\n") % (self.data["name"])
if self.data["location"] != "":
string = string + _(u"Location: %s\n") % (self.data["location"])
if self.data["url"] != None:
string = string+ _(u"URL: %s\n") % (self.data["url"])
if self.data["description"] != "":
string = string+ _(u"Bio: %s\n") % (self.data["description"])
if self.data["protected"] == True: protected = _(u"Yes")
else: protected = _(u"No")
string = string+ _(u"Protected: %s\n") % (protected)
string = string+_(u"Followers: %s\n Friends: %s\n") % (self.data["followers_count"], self.data["friends_count"])
string = string+ _(u"Tweets: %s\n") % (self.data["statuses_count"])
string = string+ _(u"Favourites: %s") % (self.data["favourites_count"])
return string
def visit_url(self, *args, **kwargs):
webbrowser.open_new_tab(self.data["url"])