Mae profile viewer a tabbed window. Added photo to the dialog. Separated profile code from other post types
This commit is contained in:
@@ -9,6 +9,7 @@ import buffers
|
||||
import configuration
|
||||
import player
|
||||
import posts
|
||||
import profiles
|
||||
import webbrowser
|
||||
import logging
|
||||
import longpollthread
|
||||
@@ -160,6 +161,7 @@ class Controller(object):
|
||||
# widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_volume_up, menuitem=self.window.player_volume_up)
|
||||
# widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_mute, menuitem=self.window.player_mute)
|
||||
pub.subscribe(self.get_chat, "order-sent-message")
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.view_my_profile, menuitem=self.window.view_profile)
|
||||
|
||||
def disconnect_events(self):
|
||||
log.debug("Disconnecting some events...")
|
||||
@@ -577,4 +579,7 @@ class Controller(object):
|
||||
player.player.volume = 0
|
||||
|
||||
def user_profile(self, person):
|
||||
p = posts.userProfile(self.session, person)
|
||||
p = profiles.userProfile(self.session, person)
|
||||
|
||||
def view_my_profile(self, *args, **kwargs):
|
||||
self.user_profile(self.session.user_id)
|
@@ -16,7 +16,7 @@ import logging
|
||||
from sessionmanager import session # We'll use some functions from there
|
||||
from sessionmanager.session import utils
|
||||
from pubsub import pub
|
||||
from wxUI.dialogs import postDialogs, urlList
|
||||
from wxUI.dialogs import postDialogs, urlList, profiles
|
||||
from extra import SpellChecker, translator
|
||||
from mysc.thread_utils import call_threaded
|
||||
from wxUI import menus
|
||||
@@ -513,36 +513,39 @@ class userProfile(object):
|
||||
self.person = None
|
||||
self.session = session
|
||||
self.user_id = user_id
|
||||
self.dialog = postDialogs.userProfile()
|
||||
self.dialog = profiles.userProfile(title=_(u"Profile"))
|
||||
self.dialog.create_controls("main_info")
|
||||
self.dialog.realice()
|
||||
self.get_basic_information()
|
||||
if self.person != None:
|
||||
self.dialog.get_response()
|
||||
|
||||
def get_basic_information(self):
|
||||
""" Gets and inserts basic user information"""
|
||||
fields = "first_name, last_name, bdate, city, country, home_town, photo_200_orig, online, site, status, last_seen, occupation, relation, relatives"
|
||||
""" Gets and inserts basic user information.
|
||||
See https://vk.com/dev/users.get"""
|
||||
fields = "first_name, last_name, bdate, city, country, home_town, photo_200_orig, online, site, status, last_seen, occupation, relation, relatives, personal, connections, activities, interests, music, movies, tv, books, games, about, quotes, can_write_private_message"
|
||||
person = self.session.vk.client.users.get(user_ids=self.user_id, fields=fields)
|
||||
if len(person) == 0:
|
||||
return output.speak(_(u"Information for groups is not supported, yet."))
|
||||
person = person[0]
|
||||
print person.keys()
|
||||
print person
|
||||
# Gets full name.
|
||||
n = u"{0} {1}".format(person["first_name"], person["last_name"])
|
||||
# Gets birthdate.
|
||||
if person.has_key("bdate") and person["bdate"] != "":
|
||||
self.dialog.enable("bdate")
|
||||
self.dialog.main_info.enable("bdate")
|
||||
if len(person["bdate"]) <= 5:
|
||||
d = arrow.get(person["bdate"], "D.m")
|
||||
self.dialog.set("bdate", d.format(_(u"MMMM D"), locale=languageHandler.getLanguage()))
|
||||
self.dialog.main_info.set("bdate", d.format(_(u"MMMM D"), locale=languageHandler.getLanguage()))
|
||||
else:
|
||||
d = arrow.get(person["bdate"], "D.M.YYYY")
|
||||
self.dialog.set("bdate", d.format(_(u"MMMM D, YYYY"), locale=languageHandler.getLanguage()))
|
||||
self.dialog.main_info.set("bdate", d.format(_(u"MMMM D, YYYY"), locale=languageHandler.getLanguage()))
|
||||
# Gets current city and home town
|
||||
city = ""
|
||||
if person.has_key("home_town") and person["home_town"] != "":
|
||||
home_town = person["home_town"]
|
||||
self.dialog.enable("home_town")
|
||||
self.dialog.set("home_town", home_town)
|
||||
self.dialog.main_info.enable("home_town")
|
||||
self.dialog.main_info.set("home_town", home_town)
|
||||
if person.has_key("city") and len(person["city"]) > 0:
|
||||
city = person["city"]["title"]
|
||||
if person.has_key("country") and person["country"] != "":
|
||||
@@ -550,18 +553,19 @@ class userProfile(object):
|
||||
city = city+u", {0}".format(person["country"]["title"])
|
||||
else:
|
||||
city = person["country"]["title"]
|
||||
self.dialog.enable("city")
|
||||
self.dialog.set("city", city)
|
||||
self.dialog.set("name", n)
|
||||
self.dialog.main_info.enable("city")
|
||||
self.dialog.main_info.set("city", city)
|
||||
self.dialog.main_info.set("name", n)
|
||||
self.dialog.SetTitle(_(u"{name}'s profile").format(name=n,))
|
||||
# Gets website
|
||||
if person.has_key("site") and person["site"] != "":
|
||||
self.dialog.enable("website")
|
||||
self.dialog.set("website", person["site"])
|
||||
self.dialog.enable("go_site")
|
||||
widgetUtils.connect_event(self.dialog.go_site, widgetUtils.BUTTON_PRESSED, self.visit_website)
|
||||
self.dialog.main_info.enable("website")
|
||||
self.dialog.main_info.set("website", person["site"])
|
||||
self.dialog.main_info.enable("go_site")
|
||||
widgetUtils.connect_event(self.dialog.main_info.go_site, widgetUtils.BUTTON_PRESSED, self.visit_website)
|
||||
if person.has_key("status") and person["status"] != "":
|
||||
self.dialog.enable("status")
|
||||
self.dialog.set("status", person["status"])
|
||||
self.dialog.main_info.enable("status")
|
||||
self.dialog.main_info.set("status", person["status"])
|
||||
if person.has_key("occupation") and person["occupation"] != None:
|
||||
if person["occupation"]["type"] == "work": c1 = _(u"Work ")
|
||||
elif person["occupation"]["type"] == "school": c1 = _(u"Student ")
|
||||
@@ -570,8 +574,8 @@ class userProfile(object):
|
||||
c2 = _(u"In {0}").format(person["occupation"]["name"],)
|
||||
else:
|
||||
c2 = ""
|
||||
self.dialog.enable("occupation")
|
||||
self.dialog.set("occupation", c1+c2)
|
||||
self.dialog.main_info.enable("occupation")
|
||||
self.dialog.main_info.set("occupation", c1+c2)
|
||||
if person.has_key("relation") and person["relation"] != 0:
|
||||
print person["relation"]
|
||||
if person["relation"] == 1:
|
||||
@@ -591,14 +595,14 @@ class userProfile(object):
|
||||
r = _(u"Actively searching")
|
||||
elif person["relation"] == 7:
|
||||
r = _(u"In love")
|
||||
self.dialog.enable("relation")
|
||||
self.dialog.relation.SetLabel(_(u"Relationship: ")+r)
|
||||
self.dialog.main_info.enable("relation")
|
||||
self.dialog.main_info.relation.SetLabel(_(u"Relationship: ")+r)
|
||||
if person.has_key("last_seen") and person["last_seen"] != False:
|
||||
original_date = arrow.get(person["last_seen"]["time"])
|
||||
# Translators: This is the date of last seen
|
||||
last_seen = _(u"{0}").format(original_date.humanize(locale=languageHandler.getLanguage()),)
|
||||
self.dialog.enable("last_seen")
|
||||
self.dialog.set("last_seen", last_seen)
|
||||
self.dialog.main_info.enable("last_seen")
|
||||
self.dialog.main_info.set("last_seen", last_seen)
|
||||
log.info("getting info...")
|
||||
self.person = person
|
||||
self.dialog.SetClientSize(self.dialog.sizer.CalcMin())
|
||||
|
138
src/controller/profiles.py
Normal file
138
src/controller/profiles.py
Normal file
@@ -0,0 +1,138 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import arrow
|
||||
import requests
|
||||
import languageHandler
|
||||
import widgetUtils
|
||||
import output
|
||||
import wx
|
||||
import cStringIO
|
||||
import webbrowser
|
||||
import logging
|
||||
from sessionmanager.session import utils
|
||||
from wxUI.dialogs import urlList, profiles
|
||||
|
||||
log = logging.getLogger("controller.post")
|
||||
|
||||
def get_user(id, profiles):
|
||||
""" Returns an user name and last name based in the id receibed."""
|
||||
for i in profiles:
|
||||
if i["id"] == id:
|
||||
return u"{0} {1}".format(i["first_name"], i["last_name"])
|
||||
# Translators: This string is used when socializer can't find the right user information.
|
||||
return _(u"Unknown username")
|
||||
|
||||
def get_message(status):
|
||||
message = ""
|
||||
if status.has_key("text"):
|
||||
message = utils.clean_text(status["text"])
|
||||
return message
|
||||
|
||||
class userProfile(object):
|
||||
|
||||
def __init__(self, session, user_id):
|
||||
self.person = None
|
||||
self.session = session
|
||||
self.user_id = user_id
|
||||
self.dialog = profiles.userProfile(title=_(u"Profile"))
|
||||
self.dialog.create_controls("main_info")
|
||||
self.dialog.realice()
|
||||
self.get_basic_information()
|
||||
if self.person != None:
|
||||
self.dialog.get_response()
|
||||
|
||||
def get_basic_information(self):
|
||||
""" Gets and inserts basic user information.
|
||||
See https://vk.com/dev/users.get"""
|
||||
fields = "first_name, last_name, bdate, city, country, home_town, photo_200_orig, online, site, status, last_seen, occupation, relation, relatives, personal, connections, activities, interests, music, movies, tv, books, games, about, quotes, can_write_private_message"
|
||||
person = self.session.vk.client.users.get(user_ids=self.user_id, fields=fields)
|
||||
if len(person) == 0:
|
||||
return output.speak(_(u"Information for groups is not supported, yet."))
|
||||
person = person[0]
|
||||
# print person
|
||||
# Gets full name.
|
||||
n = u"{0} {1}".format(person["first_name"], person["last_name"])
|
||||
# Gets birthdate.
|
||||
if person.has_key("bdate") and person["bdate"] != "":
|
||||
self.dialog.main_info.enable("bdate")
|
||||
if len(person["bdate"]) <= 5:
|
||||
d = arrow.get(person["bdate"], "D.m")
|
||||
self.dialog.main_info.set("bdate", d.format(_(u"MMMM D"), locale=languageHandler.getLanguage()))
|
||||
else:
|
||||
d = arrow.get(person["bdate"], "D.M.YYYY")
|
||||
self.dialog.main_info.set("bdate", d.format(_(u"MMMM D, YYYY"), locale=languageHandler.getLanguage()))
|
||||
# Gets current city and home town
|
||||
city = ""
|
||||
if person.has_key("home_town") and person["home_town"] != "":
|
||||
home_town = person["home_town"]
|
||||
self.dialog.main_info.enable("home_town")
|
||||
self.dialog.main_info.set("home_town", home_town)
|
||||
if person.has_key("city") and len(person["city"]) > 0:
|
||||
city = person["city"]["title"]
|
||||
if person.has_key("country") and person["country"] != "":
|
||||
if city != "":
|
||||
city = city+u", {0}".format(person["country"]["title"])
|
||||
else:
|
||||
city = person["country"]["title"]
|
||||
self.dialog.main_info.enable("city")
|
||||
self.dialog.main_info.set("city", city)
|
||||
self.dialog.main_info.set("name", n)
|
||||
self.dialog.SetTitle(_(u"{name}'s profile").format(name=n,))
|
||||
# Gets website
|
||||
if person.has_key("site") and person["site"] != "":
|
||||
self.dialog.main_info.enable("website")
|
||||
self.dialog.main_info.set("website", person["site"])
|
||||
self.dialog.main_info.enable("go_site")
|
||||
widgetUtils.connect_event(self.dialog.main_info.go_site, widgetUtils.BUTTON_PRESSED, self.visit_website)
|
||||
if person.has_key("status") and person["status"] != "":
|
||||
self.dialog.main_info.enable("status")
|
||||
self.dialog.main_info.set("status", person["status"])
|
||||
if person.has_key("occupation") and person["occupation"] != None:
|
||||
if person["occupation"]["type"] == "work": c1 = _(u"Work ")
|
||||
elif person["occupation"]["type"] == "school": c1 = _(u"Student ")
|
||||
elif person["occupation"]["type"] == "university": c1 = _(u"Student ")
|
||||
if person["occupation"].has_key("name") and person["occupation"]["name"] != "":
|
||||
c2 = _(u"In {0}").format(person["occupation"]["name"],)
|
||||
else:
|
||||
c2 = ""
|
||||
self.dialog.main_info.enable("occupation")
|
||||
self.dialog.main_info.set("occupation", c1+c2)
|
||||
if person.has_key("relation") and person["relation"] != 0:
|
||||
if person["relation"] == 1:
|
||||
r = _(u"Single")
|
||||
elif person["relation"] == 2:
|
||||
if person.has_key("relation_partner"):
|
||||
r = _(u"Dating with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
|
||||
else:
|
||||
r = _(u"Dating")
|
||||
elif person["relation"] == 3:
|
||||
r = _(u"Engaged with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
|
||||
elif person["relation"] == 4:
|
||||
r = _(u"Married with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
|
||||
elif person["relation"] == 5:
|
||||
r = _(u"It's complicated")
|
||||
elif person["relation"] == 6:
|
||||
r = _(u"Actively searching")
|
||||
elif person["relation"] == 7:
|
||||
r = _(u"In love")
|
||||
self.dialog.main_info.enable("relation")
|
||||
self.dialog.main_info.relation.SetLabel(_(u"Relationship: ")+r)
|
||||
if person.has_key("last_seen") and person["last_seen"] != False:
|
||||
original_date = arrow.get(person["last_seen"]["time"])
|
||||
# Translators: This is the date of last seen
|
||||
last_seen = _(u"{0}").format(original_date.humanize(locale=languageHandler.getLanguage()),)
|
||||
self.dialog.main_info.enable("last_seen")
|
||||
self.dialog.main_info.set("last_seen", last_seen)
|
||||
log.info("getting info...")
|
||||
self.person = person
|
||||
if person.has_key("photo_200_orig"):
|
||||
img = requests.get(person["photo_200_orig"])
|
||||
image = wx.Image(stream=cStringIO.StringIO(requests.get(person["photo_200_orig"]).content))
|
||||
try:
|
||||
self.dialog.image.SetBitmap(wx.Bitmap(image))
|
||||
except ValueError:
|
||||
return
|
||||
self.dialog.panel.Layout()
|
||||
|
||||
def visit_website(self, *args, **kwargs):
|
||||
output.speak(_(u"Opening website..."))
|
||||
webbrowser.open_new_tab(self.person["site"])
|
Reference in New Issue
Block a user