Skip to content

Commit

Permalink
Migrated from PyQt4 to PyQt5
Browse files Browse the repository at this point in the history
Added Build requirements

Pinned some libraries version
  • Loading branch information
Avasam committed Jun 12, 2021
1 parent b71dd7a commit a43c20e
Show file tree
Hide file tree
Showing 17 changed files with 248 additions and 243 deletions.
10 changes: 8 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"recommendations": [
"ms-pyright.pyright",
"ms-python.vscode-pylance",
"ms-python.python",
"sonarsource.sonarlint-vscode",
"davidanson.vscode-markdownlint"
"davidanson.vscode-markdownlint",
"shardulm94.trailing-spaces",
"eamodio.gitlens"
],
"unwantedRecommendations": [
"ms-pyright.pyright",
"esbenp.prettier-vscode"
]
}
19 changes: 8 additions & 11 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,13 @@
120,
]
},
"[py]": {
"editor.tabSize": 4,
"editor.rulers": [
72,
79,
120,
]
},
"//1": "Keeping autoformat to false for now to keep minimal changes",
// Keeping autoformat to false for now to keep minimal changes
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll": false,
},
"python.linting.pylintEnabled": false,
"//2": "Using flake8 as other linters are incomplete or have too many false positives last I tried",
// Using flake8 as other linters are incomplete or have too many false positives last I tried
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.linting.pycodestyleEnabled": false,
Expand All @@ -43,6 +35,11 @@
"python.formatting.autopep8Args": [
"--max-line-length=120"
],
"python.pythonPath": "",
"files.insertFinalNewline": true,
"trailing-spaces.deleteModifiedLinesOnly": true,
"trailing-spaces.includeEmptyLines": true,
"trailing-spaces.trimOnSave": true,
"trailing-spaces.syntaxIgnore": [
"markdown"
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This program compares split images to a capture region of any window (OBS, xspli
- Windows 7 and 10.

### Building
- Read [requirements.txt](/requirements.txt) for information on how to run/build the python code
- Read [requirements.txt](/scripts/requirements.txt) for information on how to run/build the python code

### Opening the program
- Download the [latest version](https://github.com/austinryan/Auto-Split/releases)
Expand Down
22 changes: 0 additions & 22 deletions requirements.txt

This file was deleted.

4 changes: 4 additions & 0 deletions scripts/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

BASEDIR=$(dirname "$0")
pyinstaller -w -F --icon=src/icon.ico "BASEDIR/../src/AutoSplit.py"
4 changes: 4 additions & 0 deletions scripts/install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

BASEDIR=$(dirname "$0")
pip3 install -r "BASEDIR/requirements.txt"
21 changes: 21 additions & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Requirements file for AutoSplit
#
# Python: CPython 3.7+
#
# Usage: ./install.bat
#
# If you're having issues with the libraries, you might want to first run:
# pip3 uninstall -r requirements.txt
#
# Creating AutoSplit.exe with PyInstaller: ./build.bat
#
# Comment this out if you don't want to create AutoSplit.exe:
PyInstaller
#
# Other dependencies:
PyQT5==5.9
opencv-python
Pillow
ImageHash
pywin32==226
keyboard
32 changes: 17 additions & 15 deletions src/AutoSplit.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
from PyQt4 import QtGui, QtCore, QtTest
#!/usr/bin/python3.7
# -*- coding: utf-8 -*-

from PyQt5 import QtCore, QtGui, QtTest, QtWidgets
from win32 import win32gui
import sys
import os
import win32gui
import cv2
import time
import ctypes.wintypes
import ctypes
import keyboard
import glob
import numpy as np

import design
import about
import compare
import capture_windows
import split_parser

class AutoSplit(QtGui.QMainWindow, design.Ui_MainWindow):

class AutoSplit(QtWidgets.QMainWindow, design.Ui_MainWindow):
from hotkeys import beforeSettingHotkey, afterSettingHotkey, setSplitHotkey, setResetHotkey, setSkipSplitHotkey, setUndoSplitHotkey, setPauseHotkey
from error_messages import (splitImageDirectoryError, splitImageDirectoryNotFoundError, imageTypeError, regionError, regionSizeError,
splitHotkeyError, customThresholdError, customPauseError, alphaChannelError, alignRegionImageTypeError, alignmentNotMatchedError,
Expand Down Expand Up @@ -122,7 +124,7 @@ def __init__(self, parent=None):
def browse(self):
# User selects the file with the split images in it.
self.split_image_directory = str(
QtGui.QFileDialog.getExistingDirectory(self, "Select Split Image Directory")) + '\\'
QtWidgets.QFileDialog.getExistingDirectory(self, "Select Split Image Directory")) + '\\'

# If the user doesn't select a folder, it defaults to \. Set it back to whats in the LineEdit, and return
if self.split_image_directory == '\\':
Expand Down Expand Up @@ -498,7 +500,7 @@ def autoSplitter(self):
if self.waiting_for_split_delay == True:
time_millis = int(round(time.time() * 1000))
if time_millis < self.split_time:
QtGui.QApplication.processEvents()
QtWidgets.QApplication.processEvents()
continue

self.updateSplitImage()
Expand Down Expand Up @@ -595,7 +597,7 @@ def autoSplitter(self):
# limit the number of time the comparison runs to reduce cpu usage
fps_limit = self.fpslimitSpinBox.value()
time.sleep((1 / fps_limit) - (time.time() - start) % (1 / fps_limit))
QtGui.QApplication.processEvents()
QtWidgets.QApplication.processEvents()

# comes here when threshold gets met

Expand Down Expand Up @@ -690,7 +692,7 @@ def autoSplitter(self):
else:
self.undosplitButton.setEnabled(True)

QtGui.QApplication.processEvents()
QtWidgets.QApplication.processEvents()

# I have a pause loop here so that it can check if the user presses skip split, undo split, or reset here.
# Also updates the current split image text, counting down the time until the next split image
Expand Down Expand Up @@ -745,7 +747,7 @@ def guiChangesOnStart(self):
self.custompausetimesCheckBox.setEnabled(False)
self.customthresholdsCheckBox.setEnabled(False)
self.groupDummySplitsCheckBox.setEnabled(False)
QtGui.QApplication.processEvents()
QtWidgets.QApplication.processEvents()

def guiChangesOnReset(self):
self.startautosplitterButton.setText('Start Auto Splitter')
Expand All @@ -767,7 +769,7 @@ def guiChangesOnReset(self):
self.custompausetimesCheckBox.setEnabled(True)
self.customthresholdsCheckBox.setEnabled(True)
self.groupDummySplitsCheckBox.setEnabled(True)
QtGui.QApplication.processEvents()
QtWidgets.QApplication.processEvents()

def compareImage(self, image, mask, capture):
if mask is None:
Expand Down Expand Up @@ -924,7 +926,7 @@ def closeEvent(self, event):
if self.haveSettingsChanged():
#give a different warning if there was never a settings file that was loaded successfully, and save as instead of save.
if self.last_successfully_loaded_settings_file_path == None:
msgBox = QtGui.QMessageBox
msgBox = QtWidgets.QMessageBox
warning = msgBox.warning(self, "AutoSplit","Do you want to save changes made to settings file Untitled?", msgBox.Yes | msgBox.No | msgBox.Cancel)
if warning == msgBox.Yes:
self.saveSettingsAs()
Expand All @@ -938,7 +940,7 @@ def closeEvent(self, event):
event.ignore()
return
else:
msgBox = QtGui.QMessageBox
msgBox = QtWidgets.QMessageBox
warning = msgBox.warning(self, "AutoSplit", "Do you want to save the changes made to the settings file " + os.path.basename(self.last_successfully_loaded_settings_file_path) + " ?", msgBox.Yes | msgBox.No | msgBox.Cancel)
if warning == msgBox.Yes:
self.saveSettings()
Expand All @@ -958,7 +960,7 @@ def closeEvent(self, event):


def main():
app = QtGui.QApplication(sys.argv)
app = QtWidgets.QApplication(sys.argv)
app.setWindowIcon(QtGui.QIcon('icon.ico'))
w = AutoSplit()
w.setWindowIcon(QtGui.QIcon('icon.ico'))
Expand All @@ -967,4 +969,4 @@ def main():


if __name__ == '__main__':
main()
main()
28 changes: 14 additions & 14 deletions src/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

# Form implementation generated from reading ui file 'about.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
# Created by: PyQt5 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
from PyQt5 import QtCore, QtGui, QtWidgets

try:
_fromUtf8 = QtCore.QString.fromUtf8
Expand All @@ -15,12 +15,12 @@ def _fromUtf8(s):
return s

try:
_encoding = QtGui.QApplication.UnicodeUTF8
_encoding = QtWidgets.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
return QtWidgets.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
return QtWidgets.QApplication.translate(context, text, disambig)

class Ui_aboutAutoSplitWidget(object):
def setupUi(self, aboutAutoSplitWidget):
Expand All @@ -31,28 +31,28 @@ def setupUi(self, aboutAutoSplitWidget):
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/resources/icon.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
aboutAutoSplitWidget.setWindowIcon(icon)
self.okButton = QtGui.QPushButton(aboutAutoSplitWidget)
self.okButton = QtWidgets.QPushButton(aboutAutoSplitWidget)
self.okButton.setGeometry(QtCore.QRect(190, 220, 71, 21))
self.okButton.setObjectName(_fromUtf8("okButton"))
self.createdbyLabel = QtGui.QLabel(aboutAutoSplitWidget)
self.createdbyLabel = QtWidgets.QLabel(aboutAutoSplitWidget)
self.createdbyLabel.setGeometry(QtCore.QRect(10, 44, 151, 16))
self.createdbyLabel.setObjectName(_fromUtf8("createdbyLabel"))
self.versionLabel = QtGui.QLabel(aboutAutoSplitWidget)
self.versionLabel = QtWidgets.QLabel(aboutAutoSplitWidget)
self.versionLabel.setGeometry(QtCore.QRect(10, 21, 71, 16))
self.versionLabel.setObjectName(_fromUtf8("versionLabel"))
self.donatetextLabel = QtGui.QLabel(aboutAutoSplitWidget)
self.donatetextLabel = QtWidgets.QLabel(aboutAutoSplitWidget)
self.donatetextLabel.setGeometry(QtCore.QRect(46, 95, 191, 41))
self.donatetextLabel.setObjectName(_fromUtf8("donatetextLabel"))
self.donatebuttonLabel = QtGui.QLabel(aboutAutoSplitWidget)
self.donatebuttonLabel = QtWidgets.QLabel(aboutAutoSplitWidget)
self.donatebuttonLabel.setGeometry(QtCore.QRect(52, 127, 171, 91))
self.donatebuttonLabel.setAlignment(QtCore.Qt.AlignCenter)
self.donatebuttonLabel.setObjectName(_fromUtf8("donatebuttonLabel"))
self.iconLabel = QtGui.QLabel(aboutAutoSplitWidget)
self.iconLabel = QtWidgets.QLabel(aboutAutoSplitWidget)
self.iconLabel.setGeometry(QtCore.QRect(190, 17, 62, 71))
self.iconLabel.setObjectName(_fromUtf8("iconLabel"))

self.retranslateUi(aboutAutoSplitWidget)
QtCore.QObject.connect(self.okButton, QtCore.SIGNAL(_fromUtf8("clicked()")), aboutAutoSplitWidget.close)
self.okButton.clicked.connect(aboutAutoSplitWidget.close)
QtCore.QMetaObject.connectSlotsByName(aboutAutoSplitWidget)

def retranslateUi(self, aboutAutoSplitWidget):
Expand All @@ -69,8 +69,8 @@ def retranslateUi(self, aboutAutoSplitWidget):

if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
aboutAutoSplitWidget = QtGui.QWidget()
app = QtWidgets.QApplication(sys.argv)
aboutAutoSplitWidget = QtWidgets.QWidget()
ui = Ui_aboutAutoSplitWidget()
ui.setupUi(aboutAutoSplitWidget)
aboutAutoSplitWidget.show()
Expand Down
18 changes: 8 additions & 10 deletions src/capture_windows.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import numpy
import cv2

from win32 import win32gui
import win32ui
import win32gui
import win32con
import numpy as np

def capture_region(hwnd, rect):
"""
Expand All @@ -14,25 +12,25 @@ def capture_region(hwnd, rect):
@param rect: The coordinates of the region
@return: The image of the region in the window in BGRA format
"""

width = rect.right - rect.left
height = rect.bottom - rect.top

wDC = win32gui.GetWindowDC(hwnd)
dcObj = win32ui.CreateDCFromHandle(wDC)
cDC = dcObj.CreateCompatibleDC()
bmp = win32ui.CreateBitmap()
bmp.CreateCompatibleBitmap(dcObj, width, height)
cDC.SelectObject(bmp)
cDC.BitBlt((0, 0), (width, height), dcObj, (rect.left, rect.top), win32con.SRCCOPY)

img = bmp.GetBitmapBits(True)
img = numpy.frombuffer(img, dtype='uint8')
img = np.frombuffer(img, dtype='uint8')
img.shape = (height, width, 4)

dcObj.DeleteDC()
cDC.DeleteDC()
win32gui.ReleaseDC(hwnd, wDC)
win32gui.DeleteObject(bmp.GetHandle())

return img
Loading

0 comments on commit a43c20e

Please sign in to comment.