From 669756b391d26661cf2e2a97a304e73343ef6655 Mon Sep 17 00:00:00 2001 From: tassaron Date: Sun, 11 Jan 2026 14:29:58 -0500 Subject: update to Qt 6 and Pillow 12 and yeah, I accidentally ran black on the codebase. I don't want to spend more free time fixing that. All of these changes are simple renames or removals, nothing too major. --- src/toolkit/common.py | 87 +++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 44 deletions(-) (limited to 'src/toolkit/common.py') diff --git a/src/toolkit/common.py b/src/toolkit/common.py index 2e800eb..e35aba2 100644 --- a/src/toolkit/common.py +++ b/src/toolkit/common.py @@ -1,7 +1,8 @@ -''' - Common functions -''' -from PyQt5 import QtWidgets +""" +Common functions +""" + +from PyQt6 import QtWidgets import string import os import sys @@ -11,43 +12,38 @@ from copy import copy from collections import OrderedDict -log = logging.getLogger('AVP.Toolkit.Common') +log = logging.getLogger("AVP.Toolkit.Common") class blockSignals: - ''' - Context manager to temporarily block list of QtWidgets from updating, - and guarantee restoring the previous state afterwards. - ''' + """ + Context manager to temporarily block list of QtWidgets from updating, + and guarantee restoring the previous state afterwards. + """ + def __init__(self, widgets): if type(widgets) is dict: self.widgets = concatDictVals(widgets) else: - self.widgets = ( - widgets if hasattr(widgets, '__iter__') - else [widgets] - ) + self.widgets = widgets if hasattr(widgets, "__iter__") else [widgets] def __enter__(self): log.verbose( - 'Blocking signals for %s', - ", ".join([ - str(w.__class__.__name__) for w in self.widgets - ]) + "Blocking signals for %s", + ", ".join([str(w.__class__.__name__) for w in self.widgets]), ) self.oldStates = [w.signalsBlocked() for w in self.widgets] for w in self.widgets: w.blockSignals(True) def __exit__(self, *args): - log.verbose( - 'Resetting blockSignals to %s', str(bool(sum(self.oldStates)))) + log.verbose("Resetting blockSignals to %s", str(bool(sum(self.oldStates)))) for w, state in zip(self.widgets, self.oldStates): w.blockSignals(state) def concatDictVals(d): - '''Concatenates all values in given dict into one list.''' + """Concatenates all values in given dict into one list.""" key, value = d.popitem() d[key] = value final = copy(value) @@ -60,22 +56,22 @@ def concatDictVals(d): def badName(name): - '''Returns whether a name contains non-alphanumeric chars''' + """Returns whether a name contains non-alphanumeric chars""" return any([letter in string.punctuation for letter in name]) def alphabetizeDict(dictionary): - '''Alphabetizes a dict into OrderedDict ''' + """Alphabetizes a dict into OrderedDict""" return OrderedDict(sorted(dictionary.items(), key=lambda t: t[0])) def presetToString(dictionary): - '''Returns string repr of a preset''' + """Returns string repr of a preset""" return repr(alphabetizeDict(dictionary)) def presetFromString(string): - '''Turns a string repr of OrderedDict into a regular dict''' + """Turns a string repr of OrderedDict into a regular dict""" return dict(eval(string)) @@ -86,19 +82,21 @@ def appendUppercase(lst): def pipeWrapper(func): - '''A decorator to insert proper kwargs into Popen objects.''' + """A decorator to insert proper kwargs into Popen objects.""" + def pipeWrapper(commandList, **kwargs): - if sys.platform == 'win32': + if sys.platform == "win32": # Stop CMD window from appearing on Windows startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW - kwargs['startupinfo'] = startupinfo + kwargs["startupinfo"] = startupinfo - if 'bufsize' not in kwargs: - kwargs['bufsize'] = 10**8 - if 'stdin' not in kwargs: - kwargs['stdin'] = subprocess.DEVNULL + if "bufsize" not in kwargs: + kwargs["bufsize"] = 10**8 + if "stdin" not in kwargs: + kwargs["stdin"] = subprocess.DEVNULL return func(commandList, **kwargs) + return pipeWrapper @@ -113,6 +111,7 @@ def disableWhenEncoding(func): return else: return func(self, *args, **kwargs) + return decorator @@ -122,13 +121,14 @@ def disableWhenOpeningProject(func): return else: return func(self, *args, **kwargs) + return decorator def rgbFromString(string): - '''Turns an RGB string like "255, 255, 255" into a tuple''' + """Turns an RGB string like "255, 255, 255" into a tuple""" try: - tup = tuple([int(i) for i in string.split(',')]) + tup = tuple([int(i) for i in string.split(",")]) if len(tup) != 3: raise ValueError for i in tup: @@ -141,42 +141,42 @@ def rgbFromString(string): def formatTraceback(tb=None): import traceback + if tb is None: import sys + tb = sys.exc_info()[2] - return 'Traceback:\n%s' % "\n".join(traceback.format_tb(tb)) + return "Traceback:\n%s" % "\n".join(traceback.format_tb(tb)) def connectWidget(widget, func): if type(widget) == QtWidgets.QLineEdit: widget.textChanged.connect(func) - elif type(widget) == QtWidgets.QSpinBox \ - or type(widget) == QtWidgets.QDoubleSpinBox: + elif type(widget) == QtWidgets.QSpinBox or type(widget) == QtWidgets.QDoubleSpinBox: widget.valueChanged.connect(func) elif type(widget) == QtWidgets.QCheckBox: widget.stateChanged.connect(func) elif type(widget) == QtWidgets.QComboBox: widget.currentIndexChanged.connect(func) else: - log.warning('Failed to connect %s ', str(widget.__class__.__name__)) + log.warning("Failed to connect %s ", str(widget.__class__.__name__)) return False return True def setWidgetValue(widget, val): - '''Generic setValue method for use with any typical QtWidget''' - log.verbose('Setting %s to %s' % (str(widget.__class__.__name__), val)) + """Generic setValue method for use with any typical QtWidget""" + log.verbose("Setting %s to %s" % (str(widget.__class__.__name__), val)) if type(widget) == QtWidgets.QLineEdit: widget.setText(val) - elif type(widget) == QtWidgets.QSpinBox \ - or type(widget) == QtWidgets.QDoubleSpinBox: + elif type(widget) == QtWidgets.QSpinBox or type(widget) == QtWidgets.QDoubleSpinBox: widget.setValue(val) elif type(widget) == QtWidgets.QCheckBox: widget.setChecked(val) elif type(widget) == QtWidgets.QComboBox: widget.setCurrentIndex(val) else: - log.warning('Failed to set %s ', str(widget.__class__.__name__)) + log.warning("Failed to set %s ", str(widget.__class__.__name__)) return False return True @@ -184,8 +184,7 @@ def setWidgetValue(widget, val): def getWidgetValue(widget): if type(widget) == QtWidgets.QLineEdit: return widget.text() - elif type(widget) == QtWidgets.QSpinBox \ - or type(widget) == QtWidgets.QDoubleSpinBox: + elif type(widget) == QtWidgets.QSpinBox or type(widget) == QtWidgets.QDoubleSpinBox: return widget.value() elif type(widget) == QtWidgets.QCheckBox: return widget.isChecked() -- cgit v1.2.3