Skip to content

Commit c392b9f

Browse files
committed
Merge branch 'dev' of https://github.com/Toufool/AutoSplit into dev
2 parents 5cba9b4 + 3773f47 commit c392b9f

12 files changed

+41
-57
lines changed

Diff for: .github/workflows/lint-and-build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
# Ruff is version and platform sensible
4747
matrix:
4848
os: [windows-latest, ubuntu-22.04]
49-
python-version: ["3.10", "3.11", "3.12"]
49+
python-version: ["3.11", "3.12"]
5050
steps:
5151
- name: Checkout ${{ github.repository }}/${{ github.ref }}
5252
uses: actions/checkout@v4
@@ -66,7 +66,7 @@ jobs:
6666
# Pyright is version and platform sensible
6767
matrix:
6868
os: [windows-latest, ubuntu-22.04]
69-
python-version: ["3.10", "3.11", "3.12"]
69+
python-version: ["3.11", "3.12"]
7070
steps:
7171
- name: Checkout ${{ github.repository }}/${{ github.ref }}
7272
uses: actions/checkout@v4

Diff for: .sonarcloud.properties

-1
This file was deleted.

Diff for: README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ To understand how to use AutoSplit and how it works in-depth, please read the [t
4747
- Should work on Ubuntu 20.04+ (Only tested on Ubuntu 22.04)
4848
- Wayland is not currently supported
4949
- WSL2/WSLg requires an additional Desktop Environment, external X11 server, and/or systemd
50-
- Python 3.10+ (Not required for normal use. Refer to the [build instructions](/docs/build%20instructions.md) if you'd like run the application directly in Python).
50+
- Python 3.11+ (Not required for normal use. Refer to the [build instructions](/docs/build%20instructions.md) if you'd like run the application directly in Python).
5151

5252
## Timer Integration
5353

@@ -102,6 +102,8 @@ Not a developer? You can still help through the following methods:
102102
- <https://github.com/opencv/opencv/issues/23906>
103103
- <https://github.com/pywinrt/python-winsdk/issues/11>
104104
- <https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/807>
105+
- <https://github.com/hukkin/tomli-w/pull/46>
106+
- <https://github.com/uiri/toml/issues/270>
105107
- <https://github.com/microsoft/vscode/issues/40239>
106108
- <https://github.com/microsoft/vscode/issues/168411>
107109
- <https://github.com/python/mypy/issues/6700>

Diff for: docs/build instructions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
### All platforms
1515

16-
- [Python](https://www.python.org/downloads/) 3.10+.
16+
- [Python](https://www.python.org/downloads/) 3.11+.
1717
- [Node](https://nodejs.org) is optional, but required for complete linting.
1818
- Alternatively you can install the [pyright python wrapper](https://pypi.org/project/pyright/) which has a bit of an overhead delay.
1919
- [PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell) is used to run all the scripts.

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# https://github.com/microsoft/pyright/blob/main/docs/configuration.md#sample-pyprojecttoml-file
22
[tool.pyright]
33
typeCheckingMode = "strict"
4-
pythonVersion = "3.10"
4+
pythonVersion = "3.11"
55
# Prefer `pyright: ignore`
66
enableTypeIgnoreComments = false
77

Diff for: ruff.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# These configs are incompatible with ruff<0.5.7
88

99
# https://docs.astral.sh/ruff/configuration/
10-
target-version = "py310" # Change this to the oldest supported version by your application
10+
target-version = "py311" # Change this to the oldest supported version by your application
1111
line-length = 100
1212
preview = true
1313

Diff for: scripts/python_build_from_source_linux.bash

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ sudo apt update
77
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev tk-dev
88

99
# Download Python binary package:
10-
wget https://www.python.org/ftp/python/3.10.13/Python-3.10.13.tgz
10+
wget https://www.python.org/ftp/python/3.11.10/Python-3.11.10.tgz
1111

1212
# Unzip the package:
13-
tar -xzf Python-3.10.13.tgz
13+
tar -xzf Python-3.11.10.tgz
1414

1515
# Execute configure script
16-
cd Python-3.10.13
16+
cd Python-3.11.10
1717
./configure --enable-optimizations --enable-shared
1818

19-
# Build Python 3.10
19+
# Build Python 3.11
2020
make -j 2
2121

22-
# Install Python 3.10
22+
# Install Python 3.11
2323
sudo make install
2424

2525
# Verify the installation
26-
python3.10 -V
26+
python3.11 -V
2727

2828
echo "If Python version did not print, you may need to stop active processes"

Diff for: scripts/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ PyWinCtl>=0.0.42 # py.typed
1515
# When needed, dev builds can be found at https://download.qt.io/snapshots/ci/pyside/dev?C=M;O=D
1616
PySide6-Essentials>=6.6.0 # Python 3.12 support
1717
scipy>=1.11.2 # Python 3.12 support
18-
toml
18+
tomli-w
1919
typing-extensions>=4.4.0 # @override decorator support
2020
#
2121
# Build and compile resources

Diff for: src/AutoSplitImage.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import os
2+
import tomllib
23
from enum import IntEnum, auto
34
from math import sqrt
45
from typing import TYPE_CHECKING
56

67
import cv2
78
import numpy as np
8-
import toml
99
from cv2.typing import MatLike
1010

1111
import error_messages
@@ -133,8 +133,8 @@ def __parse_text_file(self, path: str):
133133
error_messages.tesseract_missing(path)
134134
return
135135

136-
with open(path, encoding="utf-8") as f:
137-
data = toml.load(f)
136+
with open(path, mode="rb") as f:
137+
data = tomllib.load(f)
138138

139139
self.texts = [text.lower().strip() for text in data["texts"]]
140140
self.__rect = (data["left"], data["right"], data["top"], data["bottom"])

Diff for: src/capture_method/__init__.py

+9-28
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import sys
33
from collections import OrderedDict
44
from dataclasses import dataclass
5-
from enum import Enum, EnumMeta, auto, unique
5+
from enum import EnumMeta, StrEnum, auto, unique
66
from itertools import starmap
7-
from typing import TYPE_CHECKING, TypedDict, cast
7+
from typing import TYPE_CHECKING, Never, TypedDict, cast
88

9-
from typing_extensions import Never, override
9+
from typing_extensions import override
1010

1111
from capture_method.CaptureMethodBase import CaptureMethodBase
1212
from capture_method.VideoCaptureDeviceCaptureMethod import VideoCaptureDeviceCaptureMethod
@@ -49,7 +49,7 @@ class Region(TypedDict):
4949
height: int
5050

5151

52-
class CaptureMethodEnumMeta(EnumMeta):
52+
class ContainerEnumMeta(EnumMeta):
5353
# Allow checking if simple string is enum
5454
@override
5555
def __contains__(cls, other: object):
@@ -61,35 +61,16 @@ def __contains__(cls, other: object):
6161

6262

6363
@unique
64-
# TODO: Try StrEnum in Python 3.11
65-
class CaptureMethodEnum(Enum, metaclass=CaptureMethodEnumMeta):
66-
# Allow TOML to save as a simple string
67-
@override
68-
def __repr__(self):
69-
return self.value
70-
71-
# Allow direct comparison with strings
72-
@override
73-
def __eq__(self, other: object):
74-
if isinstance(other, str):
75-
return self.value == other
76-
if isinstance(other, Enum):
77-
return self.value == other.value
78-
return other == self
79-
80-
# Restore hashing functionality for use in Maps
81-
@override
82-
def __hash__(self):
83-
return self.value.__hash__()
84-
64+
class CaptureMethodEnum(StrEnum, metaclass=ContainerEnumMeta):
65+
# Capitalize the string value from auto()
8566
@override
8667
@staticmethod
8768
def _generate_next_value_(
88-
name: "str | CaptureMethodEnum",
69+
name: str,
8970
start: int,
9071
count: int,
91-
last_values: list["str | CaptureMethodEnum"],
92-
):
72+
last_values: list[str],
73+
) -> str:
9374
return name
9475

9576
NONE = ""

Diff for: src/menu_bar.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def __setup_bindings(self):
362362

363363
def add_or_del(checked: Literal[0, 2], command: CommandStr = command):
364364
if checked:
365-
_screenshot_on_setting.add(command)
365+
_screenshot_on_setting.append(command)
366366
else:
367367
_screenshot_on_setting.remove(command)
368368

@@ -502,10 +502,10 @@ def get_default_settings_from_ui(autosplit: "AutoSplit"):
502502
"split_image_directory": autosplit.split_image_folder_input.text(),
503503
"screenshot_directory": default_settings_dialog.screenshot_directory_input.text(),
504504
"open_screenshot": default_settings_dialog.open_screenshot_checkbox.isChecked(),
505-
"screenshot_on": {
505+
"screenshot_on": [
506506
getattr(default_settings_dialog, f"screenshot_on_{command}_checkbox").isChecked()
507507
for command in _DEBUG_SCREENSHOT_COMMANDS
508-
},
508+
],
509509
"captured_window_title": "",
510510
"capture_region": {
511511
"x": autosplit.x_spinbox.value(),

Diff for: src/user_profile.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import os
2+
import tomllib
23
from copy import deepcopy
34
from typing import TYPE_CHECKING, TypedDict, cast
45

5-
import toml
6+
import tomli_w
67
from PySide6 import QtCore, QtWidgets
78
from typing_extensions import deprecated, override
89

@@ -40,7 +41,7 @@ class UserProfileDict(TypedDict):
4041
split_image_directory: str
4142
screenshot_directory: str
4243
open_screenshot: bool
43-
screenshot_on: set[CommandStr]
44+
screenshot_on: list[CommandStr]
4445
captured_window_title: str
4546
capture_region: Region
4647

@@ -73,7 +74,7 @@ def copy():
7374
split_image_directory="",
7475
screenshot_directory="",
7576
open_screenshot=True,
76-
screenshot_on=set(),
77+
screenshot_on=[],
7778
captured_window_title="",
7879
capture_region=Region(x=0, y=0, width=1, height=1),
7980
)
@@ -112,8 +113,9 @@ def save_settings_as(autosplit: "AutoSplit"):
112113

113114
def __save_settings_to_file(autosplit: "AutoSplit", save_settings_file_path: str):
114115
# Save settings to a .toml file
115-
with open(save_settings_file_path, "w", encoding="utf-8") as file:
116-
toml.dump(autosplit.settings_dict, file)
116+
with open(save_settings_file_path, "wb") as file:
117+
# https://github.com/hukkin/tomli-w/pull/46
118+
tomli_w.dump(autosplit.settings_dict, file) # pyright: ignore[reportArgumentType]
117119
autosplit.last_saved_settings = deepcopy(autosplit.settings_dict)
118120
autosplit.last_successfully_loaded_settings_file_path = save_settings_file_path
119121
return save_settings_file_path
@@ -132,14 +134,14 @@ def __load_settings_from_file(autosplit: "AutoSplit", load_settings_file_path: s
132134
settings_widget.close()
133135

134136
try:
135-
with open(load_settings_file_path, encoding="utf-8") as file:
137+
with open(load_settings_file_path, mode="rb") as file:
136138
# Casting here just so we can build an actual UserProfileDict once we're done validating
137139
# Fallback to default settings if some are missing from the file.
138140
# This happens when new settings are added.
139-
loaded_settings = DEFAULT_PROFILE | cast(UserProfileDict, toml.load(file))
141+
loaded_settings = DEFAULT_PROFILE | cast(UserProfileDict, tomllib.load(file))
140142

141143
# TODO: Data Validation / fallbacks ?
142-
loaded_settings["screenshot_on"] = set(loaded_settings["screenshot_on"])
144+
loaded_settings["screenshot_on"] = list(set(loaded_settings["screenshot_on"]))
143145
autosplit.settings_dict = UserProfileDict(**loaded_settings)
144146
autosplit.last_saved_settings = deepcopy(autosplit.settings_dict)
145147

@@ -148,7 +150,7 @@ def __load_settings_from_file(autosplit: "AutoSplit", load_settings_file_path: s
148150
autosplit.width_spinbox.setValue(autosplit.settings_dict["capture_region"]["width"])
149151
autosplit.height_spinbox.setValue(autosplit.settings_dict["capture_region"]["height"])
150152
autosplit.split_image_folder_input.setText(autosplit.settings_dict["split_image_directory"])
151-
except (FileNotFoundError, MemoryError, TypeError, toml.TomlDecodeError):
153+
except (FileNotFoundError, MemoryError, TypeError, tomllib.TOMLDecodeError):
152154
autosplit.show_error_signal.emit(error_messages.invalid_settings)
153155
return False
154156

0 commit comments

Comments
 (0)