Skip to content

Commit

Permalink
Batch of updates and fixes for 2.0.0 (#188)
Browse files Browse the repository at this point in the history
* Point python_grabber to andreaschiavinato

* Added summary of histogram

* Backport changes from linux branch

* Improved pyright and formatters usage

* Config updates

* Fix links

* Disable next/previous while delaying

* proper `is_running` variable

* Fix loading and clearing of start image

* Rename "already_running" to "already_open"

* Fix delay intervals

* Add support for start image pause time

* Default to MediaCapture's d3d

* Re-enable buttons after delay

* Beta 1 (feature-freeze, bugfixes only)
  • Loading branch information
Avasam authored Nov 19, 2022
1 parent a698ec8 commit aa975fa
Show file tree
Hide file tree
Showing 29 changed files with 479 additions and 321 deletions.
9 changes: 4 additions & 5 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ max-line-length=120
exclude=src/gen/, typings/cv2-stubs/__init__.pyi
ignore=
W503, ; Linebreak before binary operator
E124, ; Closing bracket may not match multi-line method invocation style (enforced by add-trailing-comma)
E402, ; Allow imports at the bottom of file
Y026, ; Not using typing_extensions
SIM105, ; contextlib.suppress is roughly 3x slower than try/except
CCE001, ; False positives for attribute docstrings
per-file-ignores=
; Docstrings in type stubs
; Function bodys contain other than just ... (eg: raise)
; Single quote docstrings
typings/cv2-stubs/__init__.pyi: Q000,E704,E501,N8,A001,A002,A003,CCE002,F401, Y021,Y010,Q002
; Quotes
; Allow ... on same line as class
; Allow ... on same line as def
; Line too long
; Naming conventions can't be controlled for external libraries
Expand All @@ -23,7 +21,8 @@ per-file-ignores=
; Attribute names can't be controlled for external libraries
; False positive Class level expression with elipsis
; Type re-exports
*.pyi: Q000,E704,E501,N8,A001,A002,A003,CCE002,F401
; mypy 3.7 Union issue
*.pyi: Q000,E701,E704,E501,N8,A001,A002,A003,CCE002,F401,Y037
; PyQt methods
ignore-names=closeEvent,paintEvent,keyPressEvent,mousePressEvent,mouseMoveEvent,mouseReleaseEvent
; McCabe max-complexity is also taken care of by Pylint and doesn't fail the build there
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/lint-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ jobs:
runs-on: windows-latest
strategy:
fail-fast: false
# Pyright is version and platform sensible
matrix:
python-version: ["3.9", "3.10"]
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand All @@ -63,11 +62,15 @@ jobs:
- run: scripts/install.ps1
shell: pwsh
- name: Analysing the code with Pyright
run: pyright src/ --warnings
uses: jakebailey/pyright-action@v1
with:
working-directory: src/
extra-args: --warnings
Pylint:
runs-on: windows-latest
strategy:
fail-fast: false
# Pylint is version and platform sensible
matrix:
python-version: ["3.9", "3.10"]
steps:
Expand All @@ -87,6 +90,7 @@ jobs:
runs-on: windows-latest
strategy:
fail-fast: false
# Flake8 is tied to the version of Python on which it runs. Platform checks are ignored
matrix:
python-version: ["3.9", "3.10"]
steps:
Expand All @@ -103,6 +107,7 @@ jobs:
- name: Analysing the code with Flake8
run: flake8 src/ typings/
Bandit:
# Bandit only matters on the version deployed. Platform checks are ignored
runs-on: windows-latest
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
Expand All @@ -121,6 +126,7 @@ jobs:
runs-on: windows-latest
strategy:
fail-fast: false
# Only the Python version we plan on shipping matters.
matrix:
python-version: ["3.10"]
steps:
Expand Down
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"bungcip.better-toml",
"davidanson.vscode-markdownlint",
"eamodio.gitlens",
"emeraldwalk.runonsave",
"ms-python.autopep8",
"ms-python.flake8",
"ms-python.isort",
"ms-python.pylint",
"ms-python.python",
"ms-python.vscode-pylance",
Expand All @@ -18,6 +21,8 @@
// Must disable in this workspace //
// https://github.com/microsoft/vscode/issues/40239 //
//
// We use autopep8
"ms-python.black-formatter",
// VSCode has implemented an optimized version
"coenraads.bracket-pair-colorizer",
"coenraads.bracket-pair-colorizer-2",
Expand Down
18 changes: 17 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
"trailing-spaces.syntaxIgnore": [
"markdown"
],
"emeraldwalk.runonsave": {
"commands": [
{
"match": "\\.pyi?",
"cmd": "unify ${file} --in-place --quote=\"\\\"\""
},
{
"match": "\\.pyi?",
"cmd": "add-trailing-comma ${file} --py36-plus"
},
]
},
"files.associations": {
"*.json": "json",
"extensions.json": "jsonc",
Expand All @@ -47,15 +59,18 @@
"*.lock": true,
},
"[python]": {
// Cannot use autotpep8 until https://github.com/microsoft/vscode-autopep8/issues/32 is fixed
"editor.defaultFormatter": "ms-python.python",
"editor.tabSize": 4,
"editor.rulers": [
72, // PEP8-17 docstrings
// 79, // PEP8-17 default max
// 88, // Black default
99, // PEP8-17 acceptable max
// 99, // PEP8-17 acceptable max
120, // Our hard rule
],
},
"python.formatting.provider": "autopep8",
"python.analysis.diagnosticMode": "workspace",
"python.linting.enabled": true,
// Use the new Pylint extension instead
Expand Down Expand Up @@ -115,6 +130,7 @@
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.codeFormatting.whitespaceBetweenParameters": true,
"powershell.integratedConsole.showOnStartup": false,
"terminal.integrated.defaultProfile.windows": "PowerShell",
"xml.codeLens.enabled": true,
"xml.format.spaceBeforeEmptyCloseTag": false,
}
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,8 @@ This program can be used to automatically start, split, and reset your preferred

### Building

(This is not required for normal use)

- Python 3.9 - 3.10.
- Microsoft Visual C++ 14.0 or greater may be required to build the executable. Get it with [Microsoft C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/).

- Read [requirements.txt](/scripts/requirements.txt) for more information on how to install, run and build the python code.
- Run `./scripts/install.ps1` to install all dependencies.
- Run the app directly with `./scripts/start.ps1 [--auto-controlled]`.
- Run `./scripts/build.ps1` to build an executable.
- Recompile resources after modifications by running `./scripts/compile_resources.ps1`.
- All configured for VSCode, including Run (F5) and Build (Ctrl+Shift+B) commands.
(This is not required for normal use)
Refer to the [build instructions](build%20instructions.md) if you'd like to build the application yourself or run it directly in Python.

## OPTIONS

Expand Down Expand Up @@ -72,6 +63,7 @@ This program can be used to automatically start, split, and reset your preferred
- There are three comparison methods to choose from: L2 Norm, Histograms, and Perceptual Hash (or pHash).
- L2 Norm: This method should be fine to use for most cases. It finds the difference between each pixel, squares it, sums it over the entire image and takes the square root. This is very fast but is a problem if your image is high frequency. Any translational movement or rotation can cause similarity to be very different.
- Histograms: An explanation on Histograms comparison can be found [here](https://mpatacchiola.github.io/blog/2016/11/12/the-simplest-classifier-histogram-intersection.html). This is a great method to use if you are using several masked images.
> This algorithm is particular reliable when the colour is a strong predictor of the object identity. The histogram intersection [...] is robust to occluding objects in the foreground.
- Perceptual Hash: An explanation on pHash comparison can be found [here](http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html). It is highly recommended to NOT use pHash if you use masked images. It is very inaccurate.

#### Capture Method
Expand Down Expand Up @@ -224,7 +216,7 @@ The AutoSplit LiveSplit Component will directly connect AutoSplit with LiveSplit
- Place the .dll file into your `[...]\LiveSplit\Components` folder.
- Open LiveSplit -> Right Click -> Edit Layout -> Plus Button -> Control -> AutoSplit Integration.
- Click Layout Settings -> AutoSplit Integration
- Click the Browse buttons to locate your AutoSplit Path (path to AutoSplit.exe) and Profile Path (path to your AutoSplit `.toml` profile file) respectively.
- Click the Browse buttons to locate your AutoSplit Path (path to AutoSplit executable) and Profile Path (path to your AutoSplit `.toml` profile file) respectively.
- If you have not yet set saved a profile, you can do so using AutoSplit, and then go back and set your Settings Path.
- Once set, click OK, and then OK again to close the Layout Editor. Right click LiveSplit -> Save Layout to save your layout. AutoSplit and your selected profile will now open automatically when opening that LiveSplit Layout `.lsl` file.

Expand Down
25 changes: 25 additions & 0 deletions build instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Install and Build instructions

## Requirements

### Windows

- Microsoft Visual C++ 14.0 or greater may be required to build the executable. Get it with [Microsoft C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/).

### All platforms

- [Python](https://www.python.org/downloads/) 3.9+.
- [Node](https://nodejs.org) is optional, but required for complete linting.
- Alternatively you can install the [pyright python wrapper](https://pypi.org/project/pyright/) which has a bit of an overhead delay.
- [VSCode](https://code.visualstudio.com/Download) is not required, but highly recommended.
- Everything already configured in the workspace, including Run (F5) and Build (Ctrl+Shift+B) commands, default shell, and recommended extensions.
- [PyCharm](https://www.jetbrains.com/pycharm/) is also a good Python IDE, but nothing is configured. If you are a PyCharm user, feel free to open a PR with all necessary workspace configurations!

## Install and Build steps

- Read [requirements.txt](/scripts/requirements.txt) for more information on how to install, run and build the python code.
- Run `./scripts/install.ps1` to install all dependencies.
- Run the app directly with `./scripts/start.ps1 [--auto-controlled]`.
- Or debug by pressing `F5` in VSCode
- Run `./scripts/build.ps1` or press `CTRL+Shift+B` in VSCode to build an executable.
- Recompile resources after modifications by running `./scripts/compile_resources.ps1`.
28 changes: 13 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@
max_line_length = 120
recursive = true
aggressive = 3
ignore = ["E70"] # Allow ... on same line as def
ignore = [
"E124", # Closing bracket may not match multi-line method invocation style (enforced by add-trailing-comma)
"E70" # Allow ... on same line as def
]


# https://github.com/microsoft/pyright/blob/main/docs/configuration.md#sample-pyprojecttoml-file
[tool.pyright]
typeCheckingMode = "strict"
# Extra strict
reportImplicitStringConcatenation="error"
reportCallInDefaultInitializer="error"
reportMissingSuperCall="none" # False positives on base classes
reportPropertyTypeMismatch="error"
reportUninitializedInstanceVariable="error"
reportUnnecessaryTypeIgnoreComment="error"
reportImplicitStringConcatenation = "error"
reportCallInDefaultInitializer = "error"
reportMissingSuperCall = "none" # False positives on base classes
reportPropertyTypeMismatch = "error"
reportUninitializedInstanceVariable = "error"
reportUnnecessaryTypeIgnoreComment = "error"
# Exclude from scanning when running pyright
exclude = [
# Auto generated, produces unecessary `# type: ignore`
Expand All @@ -27,7 +30,7 @@ ignore = [
# We expect stub files to be incomplete or contain useless statements
"**/*.pyi",
]
reportUnusedCallResult="none"
reportUnusedCallResult = "none"
# Type stubs may not be completable
reportMissingTypeStubs = "warning"
# False positives with TYPE_CHECKING
Expand Down Expand Up @@ -105,13 +108,6 @@ max-branches = 15
valid-classmethod-first-arg = "self"
# https://pylint.pycqa.org/en/latest/user_guide/options.html#naming-styles
module-naming-style = "any"
# Can't make private class with PascalCase
class-rgx = "_?_?[a-zA-Z]+?$"
good-names = [
# PyQt methods
"closeEvent", "paintEvent", "keyPressEvent", "mousePressEvent", "mouseMoveEvent", "mouseReleaseEvent",
# https://github.com/PyCQA/pylint/issues/2018
"id", "x", "y", "a0", "i", "t0", "t1"]
disable = [
# No need to mention the fixmes
"fixme",
Expand All @@ -121,6 +117,8 @@ disable = [
"unused-import",
"wrong-import-order",
"wrong-import-position",
# Already taken care of by Flake8-naming, which does a better job
"invalid-name",
# Already taken care of and grayed out. Also conflicts with Pylance reportIncompatibleMethodOverride
"unused-argument",
# Only reports a single instance. Pyright does a better job anyway
Expand Down
6 changes: 4 additions & 2 deletions res/about.ui
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
</property>
<property name="windowIcon">
<iconset resource="resources.qrc">
<normaloff>:/resources/icon.ico</normaloff>:/resources/icon.ico</iconset>
<normaloff>:/resources/icon.ico</normaloff>
:/resources/icon.ico
</iconset>
</property>
<widget class="QPushButton" name="ok_button">
<property name="geometry">
Expand Down Expand Up @@ -101,7 +103,7 @@ Thank you!</string>
</rect>
</property>
<property name="text">
<string/>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;amp;business=BYRHQG69YRHBA&amp;amp;item_name=AutoSplit+development&amp;amp;currency_code=USD&amp;amp;source=url&quot;&gt;&lt;img src=&quot;:/resources/btn_donateCC_LG.png&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="pixmap">
<pixmap resource="resources.qrc">:/resources/btn_donateCC_LG.png</pixmap>
Expand Down
40 changes: 27 additions & 13 deletions res/design.ui
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,26 @@
</property>
<property name="windowIcon">
<iconset resource="resources.qrc">
<normaloff>:/resources/icon.ico</normaloff>:/resources/icon.ico</iconset>
<normaloff>:/resources/icon.ico</normaloff>
:/resources/icon.ico
</iconset>
</property>
<widget class="QWidget" name="central_widget">
<widget class="QLabel" name="x_label">
<property name="geometry">
<rect>
<x>30</x>
<x>11</x>
<y>143</y>
<width>7</width>
<height>16</height>
<width>44</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>X</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QPushButton" name="select_region_button">
<property name="geometry">
Expand Down Expand Up @@ -235,28 +240,34 @@
<widget class="QLabel" name="width_label">
<property name="geometry">
<rect>
<x>17</x>
<x>11</x>
<y>183</y>
<width>33</width>
<height>16</height>
<width>44</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Width</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="height_label">
<property name="geometry">
<rect>
<x>70</x>
<x>66</x>
<y>183</y>
<width>41</width>
<height>16</height>
<width>44</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Height</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="fps_value_label">
<property name="geometry">
Expand Down Expand Up @@ -416,15 +427,18 @@
<widget class="QLabel" name="y_label">
<property name="geometry">
<rect>
<x>85</x>
<x>66</x>
<y>143</y>
<width>7</width>
<height>16</height>
<width>44</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Y</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QPushButton" name="align_region_button">
<property name="geometry">
Expand Down
Loading

0 comments on commit aa975fa

Please sign in to comment.