Files
LorenEteval_Furious/Furious/Window/XrayAssetViewerWindow.py
T
2026-08-12 12:20:14 +08:00

114 lines
3.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Copyright (C) 2024present Loren Eteval & contributors <loren.eteval@proton.me>
#
# This file is part of Furious.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Provide the application window for Xray asset viewer window."""
from __future__ import annotations
from Furious.Frozenlib import *
from Furious.Qt import *
from Furious.Qt import gettext as _
from Furious.Widget.XrayAssetViewerQListWidget import *
from PySide6.QtGui import *
from PySide6.QtWidgets import *
import logging
__all__ = ['XrayAssetViewerWindow']
logger = logging.getLogger(__name__)
class XrayAssetViewerWindow(AppQMainWindow):
"""Present the Xray asset viewer window."""
def __init__(self, *args, **kwargs):
"""Initialize the XrayAssetViewerWindow."""
super().__init__(*args, **kwargs)
self.setWindowTitle(_('Xray-core Asset File'))
self.xrayAssetViewerWidget = XrayAssetViewerQListWidget(parent=self)
self.setCentralWidget(self.xrayAssetViewerWidget)
if versionToValue(PYSIDE6_VERSION) <= versionToValue('6.1.3'):
openAssetDirectoryActions = []
else:
# openUrl will crash on PySide6 6.1.3, probably a Qt bug
openAssetDirectoryActions = [
AppQAction(
_('Open Asset Directory'),
callback=lambda: self.openAssetDirectory(),
shortcut=QtCore.QKeyCombination(
QtCore.Qt.KeyboardModifier.ControlModifier,
QtCore.Qt.Key.Key_O,
),
),
]
self.fileMenu = AppQMenu(
AppQAction(
_('Refresh'),
callback=lambda: self.flushItem(),
shortcut=QtCore.QKeyCombination(
QtCore.Qt.KeyboardModifier.ControlModifier,
QtCore.Qt.Key.Key_R,
),
),
AppQSeperator(),
*openAssetDirectoryActions,
AppQAction(
_('Import From File...'),
callback=lambda: self.appendNewItem(),
),
AppQSeperator(),
AppQAction(
_('Exit'),
callback=lambda: self.close(),
),
title=_('File'),
parent=self.menuBar(),
)
self.menuBar().addMenu(self.fileMenu)
def setWidthAndHeight(self):
"""Apply the default size for the Xray asset viewer window."""
self.resize(360, 360 * GOLDEN_RATIO)
def flushItem(self):
"""Refresh item."""
self.xrayAssetViewerWidget.flushItem()
@staticmethod
def openAssetDirectory():
"""Open asset directory."""
if QDesktopServices.openUrl(QtCore.QUrl.fromLocalFile(XRAY_ASSET_DIR)):
logger.info(f'open Xray-core asset dir success')
else:
logger.error(f'open Xray-core asset dir failed')
def appendNewItem(self):
"""Append new item."""
filename, selectedFilter = QFileDialog.getOpenFileName(
None, _('Import File'), filter=_('All files (*)')
)
if filename:
self.xrayAssetViewerWidget.appendNewItem(filename)