Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
th3w1zard1 committed Mar 13, 2024
1 parent fa4d980 commit fa31ddd
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 27 deletions.
4 changes: 3 additions & 1 deletion Libraries/PyKotor/src/pykotor/common/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from __future__ import annotations

from collections.abc import ItemsView, Iterable, Iterator, Mapping
from collections.abc import Mapping
from enum import Enum, IntEnum
from typing import TYPE_CHECKING, ClassVar, Generic, TypeVar, overload

Expand All @@ -13,6 +13,8 @@
if TYPE_CHECKING:
import os

from collections.abc import ItemsView, Iterable, Iterator

T = TypeVar("T")
VT = TypeVar("VT")
_unique_sentinel = object()
Expand Down
1 change: 0 additions & 1 deletion Libraries/PyKotorGL/src/pykotor/gl/models/mdl.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import ctypes
import io
import math
import struct

Expand Down
2 changes: 1 addition & 1 deletion Tools/HolocronToolset/src/toolset/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from typing import TYPE_CHECKING

from PyQt5.QtCore import QFile, QTextStream, QThread
from PyQt5.QtCore import QThread
from PyQt5.QtWidgets import QApplication

if TYPE_CHECKING:
Expand Down
3 changes: 2 additions & 1 deletion Tools/HolocronToolset/src/toolset/gui/dialogs/asyncloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def _onFailed(self, error: Exception):
file.write("\n----------------------\n")

if self.errorTitle:
QMessageBox(QMessageBox.Critical, self.errorTitle, str(universal_simplify_exception(error))).exec_()
error_msg = str(universal_simplify_exception(error)).replace("\n", "<br>")
QMessageBox(QMessageBox.Critical, self.errorTitle, error_msg).exec_()


class AsyncWorker(QThread):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

if TYPE_CHECKING:
from PyQt5.QtWidgets import QWidget

from pykotor.common.module import Module
from pykotor.extract.file import FileResource
from toolset.data.installation import HTInstallation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

if TYPE_CHECKING:
from PyQt5.QtWidgets import QWidget

from pykotor.common.misc import CaseInsensitiveDict
from toolset.data.installation import HTInstallation

Expand Down
6 changes: 4 additions & 2 deletions Tools/HolocronToolset/src/toolset/gui/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,11 @@ def saveAs(self):
identifier = ResourceIdentifier.from_path(filepath_str).validate()
except ValueError as e:
print(format_exception_with_variables(e))
error_msg = str(universal_simplify_exception(e)).replace("\n", "<br>")
QMessageBox(
QMessageBox.Critical,
"Invalid filename/extension",
f"Check the filename and try again. Could not save!{os.linesep * 2}{universal_simplify_exception(e)}",
f"Check the filename and try again. Could not save!<br><br>{error_msg}",
).exec_()
return

Expand Down Expand Up @@ -265,7 +266,8 @@ def save(self):
lines = format_exception_with_variables(e)
file.writelines(lines)
file.write("\n----------------------\n")
QMessageBox(QMessageBox.Critical, "Failed to write to file", str(universal_simplify_exception(e))).exec_()
error_msg = str(universal_simplify_exception(e)).replace("\n", "<br>")
QMessageBox(QMessageBox.Critical, "Failed to write to file", error_msg).exec_()

def _saveCurrentFile(self):
"""Implementation of saving the current file.
Expand Down
3 changes: 1 addition & 2 deletions Tools/HolocronToolset/src/toolset/gui/editors/are.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
from toolset.gui.editor import Editor

if TYPE_CHECKING:
from PyQt5.QtWidgets import QLabel, QWidget
import os

from pykotor.extract.file import ResourceResult
from PyQt5.QtWidgets import QLabel, QWidget

from pykotor.extract.file import ResourceResult
from pykotor.resource.formats.bwm.bwm_data import BWM
from pykotor.resource.formats.lyt.lyt_data import LYT
from pykotor.resource.formats.tpc.tpc_data import TPC
Expand Down
3 changes: 2 additions & 1 deletion Tools/HolocronToolset/src/toolset/gui/editors/erf.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,11 @@ def addResources(self, filepaths: list[str]):
lines = format_exception_with_variables(e)
file.writelines(lines)
file.write("\n----------------------\n")
error_msg = str(universal_simplify_exception(e)).replace("\n", "<br>")
QMessageBox(
QMessageBox.Critical,
"Failed to add resource",
f"Could not add resource at {c_filepath.absolute()}:\n{universal_simplify_exception(e)}",
f"Could not add resource at {c_filepath.absolute()}:<br><br>{error_msg}",
).exec_()

def selectFilesToAdd(self):
Expand Down
6 changes: 0 additions & 6 deletions Tools/HolocronToolset/src/toolset/gui/editors/gff.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,12 +809,6 @@ def selectTalkTable(self):
Args:
----
self: The class instance
Processing Logic:
----------------
- Open a file dialog to select a TLK file
- Get the selected file path and filter from the dialog
- If a file is selected, load it as a TalkTable and assign to self._talktable.
"""
filepath, filter = QFileDialog.getOpenFileName(self, "Select a TLK file", "", "TalkTable (*.tlk)")
if not filepath:
Expand Down
1 change: 0 additions & 1 deletion Tools/HolocronToolset/src/toolset/gui/editors/tlk.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from toolset.gui.editor import Editor
from toolset.gui.widgets.settings.installations import GlobalSettings
from toolset.utils.window import addWindow, openResourceEditor
from utility.misc import is_debug_mode

if TYPE_CHECKING:
import os
Expand Down
7 changes: 4 additions & 3 deletions Tools/HolocronToolset/src/toolset/gui/editors/twoda.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pykotor.resource.formats.twoda import TwoDA, read_2da, write_2da
from pykotor.resource.type import ResourceType
from toolset.gui.editor import Editor
from utility.error_handling import assert_with_variable_trace
from utility.error_handling import assert_with_variable_trace, universal_simplify_exception

if TYPE_CHECKING:
import os
Expand Down Expand Up @@ -117,8 +117,9 @@ def load(self, filepath: os.PathLike | str, resref: str, restype: ResourceType,

try:
self._load_main(data)
except ValueError:
QMessageBox(QMessageBox.Critical, "Failed to load file.", "Failed to open or load file data.").exec_()
except ValueError as e:
error_msg = str(universal_simplify_exception(e)).replace("\n", "<br>")
QMessageBox(QMessageBox.Critical, "Failed to load file.", f"Failed to open or load file data.<br>{error_msg}").exec_()
self.proxyModel.setSourceModel(self.model)
self.new()

Expand Down
1 change: 0 additions & 1 deletion Tools/HolocronToolset/src/toolset/gui/editors/utd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from toolset.utils.window import openResourceEditor

if TYPE_CHECKING:
from PyQt5.QtWidgets import QWidget
import os

from PyQt5.QtCore import QObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
QPaintEvent,
QWheelEvent,
)

from pykotor.common.geometry import SurfaceMaterial
from pykotor.resource.formats.bwm import BWM, BWMFace
from pykotor.resource.formats.tpc import TPC
Expand Down
18 changes: 14 additions & 4 deletions Tools/HolocronToolset/src/toolset/gui/windows/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ def _setupContentsRecJSON(self, parent: QTreeWidgetItem | None, data: dict):
if "structure" in data:
for title in data["structure"]:
item = QTreeWidgetItem([title])
item.setData(0, QtCore.Qt.UserRole, data["structure"][title]["filename"]) # type: ignore[attr-defined]
item.setData(0, QtCore.Qt.UserRole, data["structure"][title]["filename"])
add(item)
self._setupContentsRecJSON(item, data["structure"][title])

def _setupContentsRecXML(self, parent: QTreeWidgetItem | None, element: ElemTree.Element):
add: Callable[..., None] = self.ui.contentsTree.addTopLevelItem if parent is None else parent.addChild

for child in element:
item = QTreeWidgetItem([child.get("name")]) # FIXME: typing
item = QTreeWidgetItem([child.get("name", "")])
item.setData(0, QtCore.Qt.UserRole, child.get("file"))
add(item)
self._setupContentsRecXML(item, child)
Expand Down Expand Up @@ -170,17 +170,27 @@ def task():
loader = AsyncLoader(self, "Download newer help files...", task, "Failed to update.")
if loader.exec_():
self._setupContents()
except Exception as e:
except (ConnectionError, requests.HTTPError, requests.ConnectionError, requests.RequestException):
error_msg = str(universal_simplify_exception(e)).replace("\n", "<br>")
QMessageBox(
QMessageBox.Information,
"Unable to fetch latest version of the help booklet.",
(
f"{universal_simplify_exception(e)}\n"
f"{error_msg}<br>"
"Check if you are connected to the internet."
),
QMessageBox.Ok,
self,
).exec_()
except Exception as e:
error_msg = str(universal_simplify_exception(e)).replace("\n", "<br>")
QMessageBox(
QMessageBox.Information,
"An unexpected error occurred while fetching the help booklet.",
error_msg,
QMessageBox.Ok,
self,
).exec_()

def _downloadUpdate(self):
help_path = Path("help").resolve()
Expand Down
2 changes: 1 addition & 1 deletion Tools/HolocronToolset/src/toolset/gui/windows/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ def refreshModuleList(
def _getOverrideList(self, *, reload=True):
if self.active is None:
print("no installation is currently loaded, cannot refresh override list")
return
return None
if reload:
self.active.load_override()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from pykotor.common.module import Module, ModuleResource
from pykotor.common.stream import BinaryWriter
from pykotor.extract.file import ResourceIdentifier
from pykotor.resource.formats.bwm.bwm_data import BWM
from pykotor.resource.generics.git import (
GITCamera,
GITCreature,
Expand Down Expand Up @@ -47,21 +46,22 @@
from toolset.utils.misc import QtMouse
from toolset.utils.window import openResourceEditor
from utility.error_handling import assert_with_variable_trace
from utility.system.path import Path

if TYPE_CHECKING:
from PyQt5.QtGui import QFont, QKeyEvent
from PyQt5.QtWidgets import QCheckBox, QWidget
from glm import vec3

from pykotor.gl.scene import Camera
from pykotor.resource.formats.bwm.bwm_data import BWM
from pykotor.resource.generics.are import ARE
from pykotor.resource.generics.git import GIT
from pykotor.resource.generics.ifo import IFO
from pykotor.tools.path import CaseAwarePath
from toolset.data.installation import HTInstallation
from toolset.gui.widgets.renderer.module import ModuleRenderer
from toolset.gui.widgets.renderer.walkmesh import WalkmeshRenderer
from utility.system.path import Path


class MoveCommand(QUndoCommand):
Expand Down

0 comments on commit fa31ddd

Please sign in to comment.