Fixed: icon computation cached
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
from io import BytesIO
|
||||||
|
from PIL import Image, ImageQt # type: ignore
|
||||||
|
from PySide2 import QtGui # type: ignore
|
||||||
|
|
||||||
|
from .....utils import async_request
|
||||||
|
|
||||||
|
|
||||||
|
icon_cache = {}
|
||||||
|
|
||||||
|
|
||||||
|
def get_weapon_icon(weapon):
|
||||||
|
global icon_cache
|
||||||
|
|
||||||
|
url = f'https://albiononline2d.ams3.cdn.digitaloceanspaces.com/thumbnails/orig/{weapon}'
|
||||||
|
|
||||||
|
if weapon in icon_cache:
|
||||||
|
return icon_cache[weapon]
|
||||||
|
|
||||||
|
try:
|
||||||
|
r = async_request.get(url)
|
||||||
|
img = Image.open(BytesIO(r.content))
|
||||||
|
|
||||||
|
img_qt = ImageQt.ImageQt(img)
|
||||||
|
pix = QtGui.QPixmap.fromImage(img_qt)
|
||||||
|
|
||||||
|
icon_cache[weapon] = QtGui.QIcon(pix)
|
||||||
|
return icon_cache[weapon]
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
from io import BytesIO
|
|
||||||
import collections
|
import collections
|
||||||
import functools
|
import functools
|
||||||
import re
|
import re
|
||||||
from typing import List
|
from typing import List
|
||||||
from PIL import Image, ImageQt # type: ignore
|
|
||||||
|
|
||||||
from PySide2 import QtCore # type: ignore
|
from PySide2 import QtCore # type: ignore
|
||||||
from PySide2 import QtGui # type: ignore
|
from PySide2 import QtGui # type: ignore
|
||||||
@@ -22,10 +20,11 @@ from PySide2.QtWidgets import QVBoxLayout # type: ignore
|
|||||||
|
|
||||||
from .....stats.list_item import PlayerListItem
|
from .....stats.list_item import PlayerListItem
|
||||||
from .....utils import assets
|
from .....utils import assets
|
||||||
from .....utils import async_request
|
|
||||||
from .....utils import names
|
from .....utils import names
|
||||||
from .....utils import weapon
|
from .....utils import weapon
|
||||||
|
|
||||||
|
from .icon import get_weapon_icon as player_icon
|
||||||
|
|
||||||
Style = collections.namedtuple('Style', 'bg')
|
Style = collections.namedtuple('Style', 'bg')
|
||||||
|
|
||||||
enchant_re = re.compile(r"(.*)@(\d+)")
|
enchant_re = re.compile(r"(.*)@(\d+)")
|
||||||
@@ -77,20 +76,6 @@ def player_style(items):
|
|||||||
return Style(bg='#42413c')
|
return Style(bg='#42413c')
|
||||||
|
|
||||||
|
|
||||||
def player_icon(weapon):
|
|
||||||
url = f'https://albiononline2d.ams3.cdn.digitaloceanspaces.com/thumbnails/orig/{weapon}'
|
|
||||||
try:
|
|
||||||
r = async_request.get(url)
|
|
||||||
img = Image.open(BytesIO(r.content))
|
|
||||||
|
|
||||||
img_qt = ImageQt.ImageQt(img)
|
|
||||||
pix = QtGui.QPixmap.fromImage(img_qt)
|
|
||||||
|
|
||||||
return QtGui.QIcon(pix)
|
|
||||||
except Exception:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
class ListItemView(QListView):
|
class ListItemView(QListView):
|
||||||
class Item(QtGui.QStandardItem):
|
class Item(QtGui.QStandardItem):
|
||||||
def __init__(self, player, parent):
|
def __init__(self, player, parent):
|
||||||
|
|||||||
Reference in New Issue
Block a user