added fields for created_at, locked, bot and discoverable

This commit is contained in:
Abdulqadir Ahmad 2023-08-12 10:32:29 +01:00
parent 35ba915be6
commit 15e2032afb
2 changed files with 63 additions and 35 deletions

View File

@ -291,7 +291,8 @@ class Handler(object):
call_threaded(session.api_call, "account_update_credentials", _("Update profile"), report_success=True, **updated_data) call_threaded(session.api_call, "account_update_credentials", _("Update profile"), report_success=True, **updated_data)
def showUserProfile(self, buffer): def showUserProfile(self, buffer):
"""Displays user profile in a dialog.""" """Displays user profile in a dialog.
This works as long as the focused item hass a 'account' key."""
log.debug("Scraping for users in handler") log.debug("Scraping for users in handler")
if not hasattr(buffer, 'get_item'): if not hasattr(buffer, 'get_item'):
return # Tell user? return # Tell user?
@ -300,20 +301,15 @@ class Handler(object):
return # empty buffer return # empty buffer
holdUser = item.get('account') holdUser = item.get('account')
if item.get('username'): users = [holdUser]
# item is an account dict if item.get('mentions'):
users = [(item.display_name, item.username, item.id)] # mentions in statuses
elif item.get('mentions'):
# statuse
if item.reblog: if item.reblog:
item = item.reblog item = item.reblog
users = [(user.acct, user.id) for user in item.mentions] users = [(user.acct, user.id) for user in item.mentions]
users.insert(0, (item.account.display_name, item.account.username, item.account.id)) users.insert(0, (item.account.display_name, item.account.username, item.account.id))
holdUser = item.account holdUser = item.account
elif hasattr(item, 'account'): elif not holdUser:
# Notifications
users = [(item.account.display_name, item.account.username, item.account.id)]
else:
dialogs.no_user() dialogs.no_user()
return return
@ -326,9 +322,10 @@ class Handler(object):
return # Canceled selection return # Canceled selection
elif selectedUser[-1] == holdUser.id: elif selectedUser[-1] == holdUser.id:
user = holdUser user = holdUser
else: else: # We don't have this user's dictionary, get it!
user = buffer.session.api.account(selectedUser[-1]) user = buffer.session.api.account(selectedUser[-1])
dlg = showUserProfile.ShowUserProfile( dlg = showUserProfile.ShowUserProfile(
user.display_name, user.url, html_filter(user.note), user.header, user.avatar, user.display_name, user.url, user.created_at, html_filter(user.note), user.header, user.avatar,
[(field.name, html_filter(field.value)) for field in user.fields], False, False, False) [(field.name, html_filter(field.value)) for field in user.fields], user.locked, user.bot, user.discoverable
)
dlg.ShowModal() dlg.ShowModal()

View File

@ -2,7 +2,6 @@
"""Wx dialogs for showing a user's profile.""" """Wx dialogs for showing a user's profile."""
from io import BytesIO from io import BytesIO
import os
from typing import Tuple from typing import Tuple
import requests import requests
import wx import wx
@ -59,7 +58,7 @@ class ShowUserProfile(wx.Dialog):
``` ```
""" """
def __init__(self, display_name: str, url: str, note: str, header: str, avatar: str, fields: list, locked: bool, bot: bool, discoverable: bool): def __init__(self, display_name: str, url: str, created_at, note: str, header: str, avatar: str, fields: list, locked: bool, bot: bool, discoverable: bool):
"""Initialize update profile dialog """Initialize update profile dialog
Parameters: Parameters:
- display_name: The user's display name to show in the display name field - display_name: The user's display name to show in the display name field
@ -71,24 +70,29 @@ class ShowUserProfile(wx.Dialog):
super().__init__(parent=None) super().__init__(parent=None)
self.SetTitle(_("{}'s Profile").format(display_name)) self.SetTitle(_("{}'s Profile").format(display_name))
self.panel = wx.Panel(self) self.panel = wx.Panel(self)
wrapper = wx.BoxSizer(wx.VERTICAL) wrapperSizer = wx.BoxSizer(wx.VERTICAL)
sizer = wx.GridSizer(2, 11, 5, 5) topSizer = wx.GridSizer(2, 10, 5, 5)
# create widgets # create widgets
nameLabel = wx.StaticText(self.panel, label=_("Name: ")) nameLabel = wx.StaticText(self.panel, label=_("Name: "))
name = self.createTextCtrl(display_name, size=(200, 30)) name = self.createTextCtrl(display_name, size=(200, 30))
sizer.Add(nameLabel, wx.SizerFlags().Center()) topSizer.Add(nameLabel, wx.SizerFlags().Center())
sizer.Add(name, wx.SizerFlags().Center()) topSizer.Add(name, wx.SizerFlags().Center())
urlLabel = wx.StaticText(self.panel, label=_("URL: ")) urlLabel = wx.StaticText(self.panel, label=_("URL: "))
url = self.createTextCtrl(url, size=(200, 30)) url = self.createTextCtrl(url, size=(200, 30))
sizer.Add(urlLabel, wx.SizerFlags().Center()) topSizer.Add(urlLabel, wx.SizerFlags().Center())
sizer.Add(url, wx.SizerFlags().Center()) topSizer.Add(url, wx.SizerFlags().Center())
joinLabel = wx.StaticText(self.panel, label=_("Joined at: "))
joinText = self.createTextCtrl(created_at.strftime('%d %B, %Y'), (80, 30))
topSizer.Add(joinLabel, wx.SizerFlags().Center())
topSizer.Add(joinText, wx.SizerFlags().Center())
bioLabel = wx.StaticText(self.panel, label=_("Bio: ")) bioLabel = wx.StaticText(self.panel, label=_("Bio: "))
bio = self.createTextCtrl(note, (400, 60)) bio = self.createTextCtrl(note, (400, 60))
sizer.Add(bioLabel, wx.SizerFlags().Center()) topSizer.Add(bioLabel, wx.SizerFlags().Center())
sizer.Add(bio, wx.SizerFlags().Center()) topSizer.Add(bio, wx.SizerFlags().Center())
# header # header
headerLabel = wx.StaticText(self.panel, label=_("Header: ")) headerLabel = wx.StaticText(self.panel, label=_("Header: "))
@ -104,11 +108,11 @@ class ShowUserProfile(wx.Dialog):
headerImage = wx.StaticBitmap(self.panel, bitmap=image.ConvertToBitmap()) headerImage = wx.StaticBitmap(self.panel, bitmap=image.ConvertToBitmap())
headerImage.AcceptsFocusFromKeyboard = returnTrue headerImage.AcceptsFocusFromKeyboard = returnTrue
sizer.Add(headerLabel, wx.SizerFlags().Center()) topSizer.Add(headerLabel, wx.SizerFlags().Center())
sizer.Add(headerImage, wx.SizerFlags().Center()) topSizer.Add(headerImage, wx.SizerFlags().Center())
# avatar # avatar
avatarLabel = wx.StaticText(self.panel, label=_("Avatar")) avatarLabel = wx.StaticText(self.panel, label=_("Avatar: "))
try: try:
response = requests.get(avatar) response = requests.get(avatar)
except requests.exceptions.RequestException: except requests.exceptions.RequestException:
@ -121,32 +125,59 @@ class ShowUserProfile(wx.Dialog):
avatarImage = wx.StaticBitmap(self.panel, bitmap=image.ConvertToBitmap()) avatarImage = wx.StaticBitmap(self.panel, bitmap=image.ConvertToBitmap())
avatarImage.AcceptsFocusFromKeyboard = returnTrue avatarImage.AcceptsFocusFromKeyboard = returnTrue
sizer.Add(avatarLabel, wx.SizerFlags().Center()) topSizer.Add(avatarLabel, wx.SizerFlags().Center())
sizer.Add(avatarImage, wx.SizerFlags().Center()) topSizer.Add(avatarImage, wx.SizerFlags().Center())
self.fields = [] self.fields = []
for num, (label, content) in enumerate(fields): for num, (label, content) in enumerate(fields):
labelSizer = wx.BoxSizer(wx.HORIZONTAL) labelSizer = wx.BoxSizer(wx.HORIZONTAL)
labelLabel = wx.StaticText(self.panel, label=_("Field {} - Label: ").format(num)) labelLabel = wx.StaticText(self.panel, label=_("Field {} - Label: ").format(num + 1))
labelSizer.Add(labelLabel, wx.SizerFlags().Center().Border(wx.ALL, 5)) labelSizer.Add(labelLabel, wx.SizerFlags().Center().Border(wx.ALL, 5))
labelText = self.createTextCtrl(label, (230, 30), True) labelText = self.createTextCtrl(label, (230, 30), True)
labelSizer.Add(labelText, wx.SizerFlags().Expand().Border(wx.ALL, 5)) labelSizer.Add(labelText, wx.SizerFlags().Expand().Border(wx.ALL, 5))
sizer.Add(labelSizer, 0, wx.CENTER) topSizer.Add(labelSizer, 0, wx.CENTER)
contentSizer = wx.BoxSizer(wx.HORIZONTAL) contentSizer = wx.BoxSizer(wx.HORIZONTAL)
contentLabel = wx.StaticText(self.panel, label=_("Content: ")) contentLabel = wx.StaticText(self.panel, label=_("Content: "))
contentSizer.Add(contentLabel, wx.SizerFlags().Center()) contentSizer.Add(contentLabel, wx.SizerFlags().Center())
contentText = self.createTextCtrl(content, (400, 60), True) contentText = self.createTextCtrl(content, (400, 60), True)
contentSizer.Add(contentText, wx.SizerFlags().Center()) contentSizer.Add(contentText, wx.SizerFlags().Center())
sizer.Add(contentSizer, 0, wx.CENTER | wx.LEFT, 10) topSizer.Add(contentSizer, 0, wx.CENTER | wx.LEFT, 10)
# 3 X 2 grid sizer
bottomSizer = wx.GridSizer(3, 2, 10, 5)
bullSwitch = {True: _('Yes'), False: _('No'), None: _('No')}
privateSizer = wx.BoxSizer(wx.HORIZONTAL)
privateLabel = wx.StaticText(self.panel, label=_("Private account: "))
private = self.createTextCtrl(bullSwitch[locked], (30, 30))
privateSizer.Add(privateLabel, wx.SizerFlags().Center())
privateSizer.Add(private, wx.SizerFlags().Center())
bottomSizer.Add(privateSizer, 0, wx.ALL | wx.CENTER)
botSizer = wx.BoxSizer(wx.HORIZONTAL)
botLabel = wx.StaticText(self.panel, label=_("Bot account: "))
botText = self.createTextCtrl(bullSwitch[bot], (30, 30))
botSizer.Add(botLabel, wx.SizerFlags().Center())
botSizer.Add(botText, wx.SizerFlags().Center())
bottomSizer.Add(botSizer, 0, wx.ALL | wx.CENTER)
discoverSizer = wx.BoxSizer(wx.HORIZONTAL)
discoverLabel = wx.StaticText(self.panel, label=_("Discoverable account: "))
discoverText = self.createTextCtrl(bullSwitch[discoverable], (30, 30))
discoverSizer.Add(discoverLabel, wx.SizerFlags().Center())
discoverSizer.Add(discoverText, wx.SizerFlags().Center())
bottomSizer.Add(discoverSizer, 0, wx.ALL | wx.CENTER)
close = wx.Button(self.panel, wx.ID_CLOSE, _("Close")) close = wx.Button(self.panel, wx.ID_CLOSE, _("Close"))
self.SetEscapeId(close.GetId()) self.SetEscapeId(close.GetId())
close.SetDefault() close.SetDefault()
sizer.Add(close, wx.SizerFlags().Center()) wrapperSizer.Add(topSizer, 0, wx.CENTER)
wrapper.Add(sizer, 0, wx.CENTER) # For padding wrapperSizer.Add(bottomSizer, 0, wx.CENTER)
self.panel.SetSizerAndFit(wrapper) wrapperSizer.Add(close, wx.SizerFlags().Center())
sizer.Fit(self) self.panel.SetSizerAndFit(wrapperSizer)
topSizer.Fit(self)
self.Center() self.Center()