Skip to content

First round of QA testing fixes #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/lint-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- run: scripts/install.ps1
shell: pwsh
- name: Analysing the code with Pyright
run: pyright --warnings
run: pyright src/ --warnings
Pylint:
runs-on: windows-latest
strategy:
Expand All @@ -64,7 +64,7 @@ jobs:
- run: scripts/install.ps1
shell: pwsh
- name: Analysing the code with Pylint
run: pylint --reports=y --output-format=colorized src/
run: pylint src/ --reports=y --output-format=colorized
Flake8:
runs-on: windows-latest
strategy:
Expand All @@ -83,7 +83,7 @@ jobs:
- run: scripts/install.ps1
shell: pwsh
- name: Analysing the code with Flake8
run: flake8
run: flake8 src/ typings/
Bandit:
runs-on: windows-latest
steps:
Expand All @@ -98,7 +98,7 @@ jobs:
- run: scripts/install.ps1
shell: pwsh
- name: Analysing the code with Bandit
run: bandit -n 1 --severity-level medium --recursive src
run: bandit src/ -n 1 --severity-level medium --recursive
Build:
runs-on: windows-latest
strategy:
Expand Down
1 change: 1 addition & 0 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sonar.python.version=3.9, 3.10
5 changes: 3 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"ms-python.vscode-pylance",
"ms-vscode.powershell",
"pkief.material-icon-theme",
"redhat.vscode-xml",
"redhat.vscode-yaml",
"shardulm94.trailing-spaces",
"sonarsource.sonarlint-vscode"
"sonarsource.sonarlint-vscode",
],
"unwantedRecommendations": [
// Must disable in this workspace //
Expand All @@ -36,5 +37,5 @@
"johnstoncode.svn-scm",
// Prefer using VSCode itself as a text editor
"vscodevim.vim",
]
],
}
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,6 @@
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.codeFormatting.whitespaceBetweenParameters": true,
"powershell.integratedConsole.showOnStartup": false,
"xml.codeLens.enabled": true,
"xml.format.spaceBeforeEmptyCloseTag": false,
}
6 changes: 0 additions & 6 deletions res/design.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
<height>424</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>777</width>
Expand Down
61 changes: 40 additions & 21 deletions res/settings.ui
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogSettings</class>
<widget class="QDialog" name="DialogSettings">
<class>SettingsWidget</class>
<widget class="QWidget" name="SettingsWidget">
<property name="geometry">
<rect>
<x>0</x>
Expand All @@ -10,12 +10,6 @@
<height>661</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>291</width>
Expand All @@ -40,12 +34,6 @@
<iconset>
<normaloff>:/resources/icon.ico</normaloff>:/resources/icon.ico</iconset>
</property>
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
<property name="modal">
<bool>false</bool>
</property>
<widget class="QGroupBox" name="capture_settings_groupbox">
<property name="geometry">
<rect>
Expand Down Expand Up @@ -352,7 +340,7 @@ It is highly recommended to NOT use pHash if you use masked images. It is very i
<property name="geometry">
<rect>
<x>6</x>
<y>193</y>
<y>190</y>
<width>261</width>
<height>61</height>
</rect>
Expand All @@ -364,7 +352,10 @@ It is highly recommended to NOT use pHash if you use masked images. It is very i
</font>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Custom image settings and flags are set in the &lt;br&gt;&lt;/br&gt; image file name. These will override the default &lt;br&gt;&lt;/br&gt; values. View the &lt;a href=&quot;https://github.com/{GITHUB_REPOSITORY}#readme&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;README&lt;/span&gt;&lt;/a&gt; for full details on all &lt;br&gt;&lt;/br&gt; available custom image settings.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Image settings and flags can be set per image through the image file name. These will override the default values. View the &lt;a href=&quot;https://github.com/{GITHUB_REPOSITORY}#readme&quot;&gt;&lt;span style=&quot;text-decoration: underline; color:#0000ff;&quot;&gt;README&lt;/span&gt;&lt;/a&gt; for full details on all available custom image settings.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="default_delay_time_label">
Expand Down Expand Up @@ -399,6 +390,34 @@ It is highly recommended to NOT use pHash if you use masked images. It is very i
<number>999999999</number>
</property>
</widget>
<widget class="QCommandLinkButton" name="readme_link_button">
<property name="geometry">
<rect>
<x>140</x>
<y>210</y>
<width>71</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>README</string>
</property>
<property name="iconSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="description">
<string>This is a workaround because custom_image_settings_info_label simply will not open links with a left click no matter what we tried.</string>
</property>
</widget>
<widget class="QCheckBox" name="enable_auto_reset_image_checkbox">
<property name="geometry">
<rect>
Expand Down Expand Up @@ -714,11 +733,11 @@ reset image</string>
</widget>
</widget>
<tabstops>
<tabstop>set_split_hotkey_button</tabstop>
<tabstop>set_reset_hotkey_button</tabstop>
<tabstop>set_undo_split_hotkey_button</tabstop>
<tabstop>set_skip_split_hotkey_button</tabstop>
<tabstop>set_pause_hotkey_button</tabstop>
<tabstop>split_input</tabstop>
<tabstop>reset_input</tabstop>
<tabstop>undo_split_input</tabstop>
<tabstop>skip_split_input</tabstop>
<tabstop>pause_input</tabstop>
<tabstop>fps_limit_spinbox</tabstop>
<tabstop>live_capture_region_checkbox</tabstop>
<tabstop>capture_method_combobox</tabstop>
Expand Down
6 changes: 0 additions & 6 deletions res/update_checker.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
<height>133</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>313</width>
Expand Down
12 changes: 8 additions & 4 deletions scripts/lint.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ $originalDirectory = $pwd
Set-Location "$PSScriptRoot/.."
$exitCodes = 0

Write-Host "`nRunning autofixes..."
isort src/ typings/
autopep8 src/ typings/ --in-place

Write-Host "`nRunning Pyright..."
$Env:PYRIGHT_PYTHON_FORCE_VERSION = 'latest'
pyright --warnings
pyright src/ --warnings
$exitCodes += $LastExitCode
if ($LastExitCode -gt 0) {
Write-Host "`Pyright failed ($LastExitCode)" -ForegroundColor Red
Expand All @@ -14,7 +18,7 @@ else {
}

Write-Host "`nRunning Pylint..."
pylint --output-format=colorized src/
pylint src/ --output-format=colorized
$exitCodes += $LastExitCode
if ($LastExitCode -gt 0) {
Write-Host "`Pylint failed ($LastExitCode)" -ForegroundColor Red
Expand All @@ -24,7 +28,7 @@ else {
}

Write-Host "`nRunning Flake8..."
flake8
flake8 src/ typings/
$exitCodes += $LastExitCode
if ($LastExitCode -gt 0) {
Write-Host "`Flake8 failed ($LastExitCode)" -ForegroundColor Red
Expand All @@ -34,7 +38,7 @@ else {
}

Write-Host "`nRunning Bandit..."
bandit -f custom --silent --recursive src
bandit src/ -f custom --silent --recursive
# $exitCodes += $LastExitCode # Returns 1 on low
if ($LastExitCode -gt 0) {
Write-Host "`Bandit warning ($LastExitCode)" -ForegroundColor Yellow
Expand Down
2 changes: 1 addition & 1 deletion scripts/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ flake8-pyi>=22.8.1 # flake8 5 support
flake8-quotes
flake8-simplify
pep8-naming
pylint>=2.13.9 # Respect ignore configuration options with --recursive=y
pylint>=2.13.9,<3.0.0 # Respect ignore configuration options with --recursive=y # 3.0 still in pre-release
pyright
#
# Run `./scripts/designer.ps1` to quickly open the bundled PyQt Designer.
Expand Down
2 changes: 1 addition & 1 deletion scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
numpy>=1.23 # Updated types
opencv-python-headless>=4.5.4,<4.6 # https://github.com/pyinstaller/pyinstaller/issues/6889
PyQt6>=6.2.1 # Python 3.10 support
git+https://github.com/Avasam/imagehash.git@patch-2#egg=ImageHash # Contains type information + setup as package not module
git+https://github.com/JohannesBuchner/imagehash.git#egg=ImageHash # Contains type information + setup as package not module
keyboard
packaging
Pillow
Expand Down
25 changes: 12 additions & 13 deletions src/AutoSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
import signal
import sys
from collections.abc import Callable
from time import time
from types import FunctionType

Expand All @@ -21,7 +20,7 @@
import user_profile
from AutoControlledWorker import AutoControlledWorker
from AutoSplitImage import COMPARISON_RESIZE, START_KEYWORD, AutoSplitImage, ImageType
from capture_method import CaptureMethodEnum, CaptureMethodInterface
from capture_method import CaptureMethodBase, CaptureMethodEnum
from gen import about, design, settings, update_checker
from hotkeys import HOTKEYS, after_setting_hotkey, send_command
from menu_bar import (about_qt, about_qt_for_python, check_for_updates, get_default_settings_from_ui, open_about,
Expand Down Expand Up @@ -64,15 +63,7 @@ class AutoSplit(QMainWindow, design.Ui_MainWindow):
AboutWidget: about.Ui_AboutAutoSplitWidget | None = None
UpdateCheckerWidget: update_checker.Ui_UpdateChecker | None = None
CheckForUpdatesThread: QtCore.QThread | None = None
SettingsWidget: settings.Ui_DialogSettings | None = None

# hotkeys need to be initialized to be passed as thread arguments in hotkeys.py
# and for type safety in both hotkeys.py and settings_file.py
split_hotkey: Callable[[], None] | None = None
reset_hotkey: Callable[[], None] | None = None
skip_split_hotkey: Callable[[], None] | None = None
undo_split_hotkey: Callable[[], None] | None = None
pause_hotkey: Callable[[], None] | None = None
SettingsWidget: settings.Ui_SettingsWidget | None = None

# Initialize a few attributes
hwnd = 0
Expand All @@ -82,7 +73,7 @@ class AutoSplit(QMainWindow, design.Ui_MainWindow):
split_image_number = 0
split_images_and_loop_number: list[tuple[AutoSplitImage, int]] = []
split_groups: list[list[int]] = []
capture_method = CaptureMethodInterface()
capture_method = CaptureMethodBase()

# Last loaded settings empty and last successful loaded settings file path to None until we try to load them
last_loaded_settings = DEFAULT_PROFILE
Expand Down Expand Up @@ -123,6 +114,10 @@ def __init__(self, parent: QWidget | None = None): # pylint: disable=too-many-s
self.width_spinbox.setFrame(False)
self.height_spinbox.setFrame(False)

# Hotkeys need to be initialized to be passed as thread arguments in hotkeys.py
for hotkey in HOTKEYS:
setattr(self, f"{hotkey}_hotkey", None)

# Get default values defined in SettingsDialog
self.settings_dict = get_default_settings_from_ui(self)
user_profile.load_check_for_updates_on_open(self)
Expand Down Expand Up @@ -450,7 +445,7 @@ def skip_split(self, navigate_image_only: bool = False):
# or Splitting/skipping when there are no images left
if self.start_auto_splitter_button.text() == START_AUTO_SPLITTER_TEXT \
or "Delayed Split" in self.current_split_image.text() \
or (not self.skip_split_button.isEnabled() and not self.is_auto_controlled) \
or not (self.skip_split_button.isEnabled() or self.is_auto_controlled or navigate_image_only) \
or self.__is_current_split_out_of_range():
return

Expand Down Expand Up @@ -795,6 +790,10 @@ def __reset_if_should(self, capture: cv2.Mat | None):
self.reset()
else:
self.table_reset_image_live_label.setText("disabled")
else:
self.table_reset_image_live_label.setText("N/A")
self.table_reset_image_threshold_label.setText("N/A")
self.table_reset_image_highest_label.setText("N/A")

return self.__check_for_reset_state_update_ui()

Expand Down
18 changes: 7 additions & 11 deletions src/capture_method/BitBltCaptureMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import win32ui
from win32 import win32gui

from capture_method.interface import CaptureMethodInterface
from capture_method.CaptureMethodBase import CaptureMethodBase
from utils import get_window_bounds, is_valid_hwnd

if TYPE_CHECKING:
Expand All @@ -21,7 +21,7 @@
PW_RENDERFULLCONTENT = 0x00000002


class BitBltCaptureMethod(CaptureMethodInterface):
class BitBltCaptureMethod(CaptureMethodBase):
_render_full_content = False

def get_frame(self, autosplit: AutoSplit) -> tuple[cv2.Mat | None, bool]:
Expand Down Expand Up @@ -57,15 +57,11 @@ def get_frame(self, autosplit: AutoSplit) -> tuple[cv2.Mat | None, bool]:
image.shape = (selection["height"], selection["width"], 4)
except (win32ui.error, pywintypes.error):
return None, False
# We already obtained the image, so we can ignore errors during cleanup
try:
dc_object.DeleteDC()
dc_object.DeleteDC()
compatible_dc.DeleteDC()
win32gui.ReleaseDC(hwnd, window_dc)
win32gui.DeleteObject(bitmap.GetHandle())
except win32ui.error:
pass
# Cleanup DC and handle
dc_object.DeleteDC()
compatible_dc.DeleteDC()
win32gui.ReleaseDC(hwnd, window_dc)
win32gui.DeleteObject(bitmap.GetHandle())
return image, False

def recover_window(self, captured_window_title: str, autosplit: AutoSplit):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# pylint: disable=no-self-use,unnecessary-dunder-call


class CaptureMethodInterface():
class CaptureMethodBase():
def __init__(self, autosplit: AutoSplit | None = None):
pass

Expand Down
4 changes: 2 additions & 2 deletions src/capture_method/VideoCaptureDeviceCaptureMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

import cv2

from capture_method.interface import CaptureMethodInterface
from capture_method.CaptureMethodBase import CaptureMethodBase
from error_messages import CREATE_NEW_ISSUE_MESSAGE, exception_traceback
from utils import is_valid_image

if TYPE_CHECKING:
from AutoSplit import AutoSplit


class VideoCaptureDeviceCaptureMethod(CaptureMethodInterface):
class VideoCaptureDeviceCaptureMethod(CaptureMethodBase):
capture_device: cv2.VideoCapture
capture_thread: Thread | None
last_captured_frame: cv2.Mat | None = None
Expand Down
Loading