Moved profile displayer to MVP pattern. User info is collected in a thread

This commit is contained in:
2019-01-06 19:41:00 -06:00
parent 0f68d2d0fc
commit 73d2d4a95d
10 changed files with 160 additions and 158 deletions

View File

@@ -27,7 +27,6 @@ from . import messages
from . import buffers
from . import player
from . import posts
from . import profiles
from . import longpollthread
from . import selector
@@ -663,7 +662,7 @@ class Controller(object):
player.player.volume = 0
def user_profile(self, person):
p = profiles.userProfile(self.session, person)
p = presenters.userProfilePresenter(session=self.session, user_id=person, view=views.userProfileDialog(), interactor=interactors.userProfileInteractor())
def view_my_profile(self, *args, **kwargs):
self.user_profile(self.session.user_id)

View File

@@ -17,7 +17,7 @@ import webbrowser
import logging
from sessionmanager import session, renderers, utils # We'll use some functions from there
from pubsub import pub
from wxUI.dialogs import postDialogs, urlList, profiles
from wxUI.dialogs import postDialogs, urlList
from extra import SpellChecker, translator
from mysc.thread_utils import call_threaded
from wxUI import menus
@@ -510,107 +510,3 @@ class friendship(object):
def set_friends_list(self, friendslist):
for i in friendslist:
self.dialog.friends.insert_item(False, *[i])
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=_("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(_("Information for groups is not supported, yet."))
person = person[0]
print(person)
# Gets full name.
n = "{0} {1}".format(person["first_name"], person["last_name"])
# Gets birthdate.
if "bdate" in person 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(_("MMMM D"), locale=languageHandler.curLang[:2]))
else:
d = arrow.get(person["bdate"], "D.M.YYYY")
self.dialog.main_info.set("bdate", d.format(_("MMMM D, YYYY"), locale=languageHandler.curLang[:2]))
# Gets current city and home town
city = ""
if "home_town" in person 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 "city" in person and len(person["city"]) > 0:
city = person["city"]["title"]
if "country" in person and person["country"] != "":
if city != "":
city = city+", {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(_("{name}'s profile").format(name=n,))
# Gets website
if "site" in person 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 "status" in person and person["status"] != "":
self.dialog.main_info.enable("status")
self.dialog.main_info.set("status", person["status"])
if "occupation" in person and person["occupation"] != None:
if person["occupation"]["type"] == "work": c1 = _("Work ")
elif person["occupation"]["type"] == "school": c1 = _("Student ")
elif person["occupation"]["type"] == "university": c1 = _("Student ")
if "name" in person["occupation"] and person["occupation"]["name"] != "":
c2 = _("In {0}").format(person["occupation"]["name"],)
else:
c2 = ""
self.dialog.main_info.enable("occupation")
self.dialog.main_info.set("occupation", c1+c2)
if "relation" in person and person["relation"] != 0:
print(person["relation"])
if person["relation"] == 1:
r = _("Single")
elif person["relation"] == 2:
if "relation_partner" in person:
r = _("Dating with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
else:
r = _("Dating")
elif person["relation"] == 3:
r = _("Engaged with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
elif person["relation"] == 4:
r = _("Married with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
elif person["relation"] == 5:
r = _("It's complicated")
elif person["relation"] == 6:
r = _("Actively searching")
elif person["relation"] == 7:
r = _("In love")
self.dialog.main_info.enable("relation")
self.dialog.main_info.relation.SetLabel(_("Relationship: ")+r)
if "last_seen" in person and person["last_seen"] != False:
original_date = arrow.get(person["last_seen"]["time"])
# Translators: This is the date of last seen
last_seen = _("{0}").format(original_date.humanize(locale=languageHandler.curLang[:2]),)
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())
def visit_website(self, *args, **kwargs):
output.speak(_("Opening website..."))
webbrowser.open_new_tab(self.person["site"])