Skip to content

Commit 6bfd4cb

Browse files
committed
Merge branch 'dev' of https://github.com/Toufool/Auto-Split into 2.0.0
2 parents cb4b293 + ab9b2c0 commit 6bfd4cb

File tree

6 files changed

+137
-59
lines changed

6 files changed

+137
-59
lines changed

res/update_checker.ui

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
<widget class="QLabel" name="labelUpdateStatus">
5050
<property name="geometry">
5151
<rect>
52-
<x>17</x>
52+
<x>20</x>
5353
<y>10</y>
54-
<width>281</width>
54+
<width>218</width>
5555
<height>16</height>
5656
</rect>
5757
</property>
@@ -62,13 +62,13 @@
6262
</sizepolicy>
6363
</property>
6464
<property name="text">
65-
<string/>
65+
<string>There is an update available for AutoSplit.</string>
6666
</property>
6767
</widget>
6868
<widget class="QLabel" name="labelCurrentVersion">
6969
<property name="geometry">
7070
<rect>
71-
<x>17</x>
71+
<x>20</x>
7272
<y>30</y>
7373
<width>91</width>
7474
<height>16</height>
@@ -81,7 +81,7 @@
8181
<widget class="QLabel" name="labelLatestVersion">
8282
<property name="geometry">
8383
<rect>
84-
<x>17</x>
84+
<x>20</x>
8585
<y>50</y>
8686
<width>81</width>
8787
<height>16</height>
@@ -94,14 +94,14 @@
9494
<widget class="QLabel" name="labelGoToDownload">
9595
<property name="geometry">
9696
<rect>
97-
<x>17</x>
98-
<y>76</y>
99-
<width>241</width>
97+
<x>20</x>
98+
<y>80</y>
99+
<width>119</width>
100100
<height>16</height>
101101
</rect>
102102
</property>
103103
<property name="text">
104-
<string/>
104+
<string>Open download page?</string>
105105
</property>
106106
</widget>
107107
<widget class="QPushButton" name="pushButtonLeft">
@@ -117,7 +117,7 @@
117117
<enum>Qt::NoFocus</enum>
118118
</property>
119119
<property name="text">
120-
<string/>
120+
<string>Open</string>
121121
</property>
122122
</widget>
123123
<widget class="QPushButton" name="pushButtonRight">
@@ -130,7 +130,7 @@
130130
</rect>
131131
</property>
132132
<property name="text">
133-
<string/>
133+
<string>Later</string>
134134
</property>
135135
</widget>
136136
<widget class="QLabel" name="labelCurrentVersionNumber">
@@ -162,9 +162,9 @@
162162
<widget class="QCheckBox" name="checkBoxDoNotAskMeAgain">
163163
<property name="geometry">
164164
<rect>
165-
<x>17</x>
166-
<y>100</y>
167-
<width>141</width>
165+
<x>20</x>
166+
<y>102</y>
167+
<width>131</width>
168168
<height>20</height>
169169
</rect>
170170
</property>

src/AutoSplit.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
import split_parser
3232
from AutoControlledWorker import AutoControlledWorker
3333
from capture_windows import capture_region, Rect
34-
from gen import design
34+
from compare import checkIfImageHasTransparency, compareImage
35+
from gen import about, design, update_checker
3536
from hotkeys import send_command, afterSettingHotkey, setSplitHotkey, setResetHotkey, setSkipSplitHotkey, \
3637
setUndoSplitHotkey, setPauseHotkey
37-
from menu_bar import AboutWidget, VERSION, UpdateCheckerWidget, about, viewHelp, checkForUpdates
38+
from menu_bar import open_about, VERSION, viewHelp, checkForUpdates, open_update_checker
3839
from screen_region import selectRegion, selectWindow, alignRegion, validateBeforeComparison
3940
from split_parser import BELOW_FLAG, DUMMY_FLAG, PAUSE_FLAG
40-
from compare import checkIfImageHasTransparency, compareImage
4141

4242

4343
# Resize to these width and height so that FPS performance increases
@@ -67,6 +67,7 @@ class AutoSplit(QMainWindow, design.Ui_MainWindow):
6767
undoSplitSignal = QtCore.pyqtSignal()
6868
pauseSignal = QtCore.pyqtSignal()
6969
afterSettingHotkeySignal = QtCore.pyqtSignal()
70+
updateCheckerWidgetSignal = QtCore.pyqtSignal(str, bool)
7071
# Use this signal when trying to show an error from outside the main thread
7172
showErrorSignal = QtCore.pyqtSignal(FunctionType)
7273

@@ -75,8 +76,9 @@ class AutoSplit(QMainWindow, design.Ui_MainWindow):
7576
timerStartImage = QtCore.QTimer()
7677

7778
# Windows
78-
aboutWidget: AboutWidget
79-
updateCheckerWidget: UpdateCheckerWidget
79+
AboutWidget: about.Ui_aboutAutoSplitWidget
80+
UpdateCheckerWidget: update_checker.Ui_UpdateChecker
81+
CheckForUpdatesThread: QtCore.QThread
8082

8183
# Settings
8284
split_image_directory = ""
@@ -155,7 +157,7 @@ def __init__(self, parent: Optional[QWidget] = None):
155157

156158
# close all processes when closing window
157159
self.actionView_Help.triggered.connect(viewHelp)
158-
self.actionAbout.triggered.connect(lambda: about(self))
160+
self.actionAbout.triggered.connect(lambda: open_about(self))
159161
self.actionCheck_for_Updates.triggered.connect(lambda: checkForUpdates(self))
160162
self.actionSave_Settings.triggered.connect(lambda: settings.saveSettings(self))
161163
self.actionSave_Settings_As.triggered.connect(lambda: settings.saveSettingsAs(self))
@@ -210,6 +212,9 @@ def __init__(self, parent: Optional[QWidget] = None):
210212
self.alignregionButton.clicked.connect(lambda: alignRegion(self))
211213
self.selectwindowButton.clicked.connect(lambda: selectWindow(self))
212214
self.startImageReloadButton.clicked.connect(lambda: self.loadStartImage(True, True))
215+
self.actionCheck_for_Updates_on_Open.changed.connect(lambda: self.set_check_for_updates_on_open(
216+
self.actionCheck_for_Updates_on_Open.isChecked())
217+
)
213218

214219
# update x, y, width, and height when changing the value of these spinbox's are changed
215220
self.xSpinBox.valueChanged.connect(self.updateX)
@@ -221,6 +226,8 @@ def __init__(self, parent: Optional[QWidget] = None):
221226
self.updateCurrentSplitImage.connect(self.updateSplitImageGUI)
222227
self.afterSettingHotkeySignal.connect(lambda: afterSettingHotkey(self))
223228
self.startAutoSplitterSignal.connect(self.autoSplitter)
229+
self.updateCheckerWidgetSignal.connect(lambda latest_version, check_on_open:
230+
open_update_checker(self, latest_version, check_on_open))
224231
self.resetSignal.connect(self.reset)
225232
self.skipSplitSignal.connect(self.skipSplit)
226233
self.undoSplitSignal.connect(self.undoSplit)
@@ -1107,10 +1114,6 @@ def updateSplitImage(self, custom_image_file: str = "", from_start_image: bool =
11071114
# exit safely when closing the window
11081115

11091116
def closeEvent(self, a0: Optional[QtGui.QCloseEvent] = None):
1110-
# save global setting values here
1111-
self.setting_check_for_updates_on_open.setValue("check_for_updates_on_open",
1112-
self.actionCheck_for_Updates_on_Open.isChecked())
1113-
11141117
def exitProgram():
11151118
if a0 is not None:
11161119
a0.accept()
@@ -1161,7 +1164,7 @@ def main():
11611164
main_window.show()
11621165
# Needs to be after main_window.show() to be shown over
11631166
if main_window.actionCheck_for_Updates_on_Open.isChecked():
1164-
checkForUpdates(main_window, check_for_updates_on_open=True)
1167+
checkForUpdates(main_window, check_on_open=True)
11651168

11661169
# Kickoff the event loop every so often so we can handle KeyboardInterrupt (^C)
11671170
timer = QtCore.QTimer()

src/gen/design.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from PyQt6.QtGui import QAction
12
from PyQt6.QtWidgets import QMainWindow
23

34

45
class Ui_MainWindow():
6+
actionCheck_for_Updates_on_Open: QAction
7+
58
def setupUi(self, MainWindow: QMainWindow) -> None:
69
...

src/menu_bar.py

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,25 @@
44
from AutoSplit import AutoSplit
55

66
import os
7+
78
import requests
8-
from PyQt6 import QtWidgets
9+
from simplejson.errors import JSONDecodeError
910
from packaging import version
10-
from gen import about as about_, resources_rc, update_checker # noqa: F401
11+
from PyQt6 import QtWidgets
12+
from PyQt6.QtCore import QThread
13+
from requests.exceptions import RequestException
14+
1115
import error_messages
16+
import settings_file
17+
from gen import about, design, resources_rc, update_checker # noqa: F401
18+
1219

1320
# AutoSplit Version number
1421
VERSION = "1.6.1"
1522

1623

1724
# About Window
18-
class AboutWidget(QtWidgets.QWidget, about_.Ui_aboutAutoSplitWidget):
25+
class __AboutWidget(QtWidgets.QWidget, about.Ui_aboutAutoSplitWidget):
1926
def __init__(self):
2027
super().__init__()
2128
self.setupUi(self)
@@ -25,57 +32,64 @@ def __init__(self):
2532
self.show()
2633

2734

28-
class UpdateCheckerWidget(QtWidgets.QWidget, update_checker.Ui_UpdateChecker):
29-
def __init__(self, latest_version: str, autosplit: AutoSplit, check_for_updates_on_open: bool = False):
35+
def open_about(self: AutoSplit):
36+
self.AboutWidget = __AboutWidget()
37+
38+
39+
class __UpdateCheckerWidget(QtWidgets.QWidget, update_checker.Ui_UpdateChecker):
40+
def __init__(self, latest_version: str, design_window: design.Ui_MainWindow, check_on_open: bool = False):
3041
super().__init__()
3142
self.setupUi(self)
3243
self.labelCurrentVersionNumber.setText(VERSION)
3344
self.labelLatestVersionNumber.setText(latest_version)
3445
self.pushButtonLeft.clicked.connect(self.openUpdate)
35-
self.pushButtonRight.clicked.connect(self.closeWindow)
36-
self.autosplit = autosplit
46+
self.checkBoxDoNotAskMeAgain.stateChanged.connect(self.doNotAskMeAgainStateChanged)
47+
self.design_window = design_window
3748
if version.parse(latest_version) > version.parse(VERSION):
38-
self.labelUpdateStatus.setText("There is an update available for AutoSplit.")
39-
self.labelGoToDownload.setText("Open download page?")
40-
self.pushButtonLeft.setVisible(True)
41-
self.pushButtonLeft.setText("Open")
42-
self.pushButtonRight.setText("Later")
43-
if not check_for_updates_on_open:
44-
self.checkBoxDoNotAskMeAgain.setVisible(False)
49+
self.checkBoxDoNotAskMeAgain.setVisible(check_on_open)
4550
self.show()
46-
elif not check_for_updates_on_open:
51+
elif not check_on_open:
4752
self.labelUpdateStatus.setText("You are on the latest AutoSplit version.")
53+
self.labelGoToDownload.setVisible(False)
4854
self.pushButtonLeft.setVisible(False)
4955
self.pushButtonRight.setText("OK")
5056
self.checkBoxDoNotAskMeAgain.setVisible(False)
5157
self.show()
5258

5359
def openUpdate(self):
54-
if self.checkBoxDoNotAskMeAgain.isChecked():
55-
self.autosplit.actionCheck_for_Updates_on_Open.setChecked(False)
5660
os.system('start "" https://github.com/Toufool/Auto-Split/releases/latest')
5761
self.close()
5862

59-
def closeWindow(self):
60-
if self.checkBoxDoNotAskMeAgain.isChecked():
61-
self.autosplit.actionCheck_for_Updates_on_Open.setChecked(False)
62-
self.close()
63+
def doNotAskMeAgainStateChanged(self):
64+
settings_file.set_check_for_updates_on_open(
65+
self.design_window,
66+
self.checkBoxDoNotAskMeAgain.isChecked())
67+
68+
69+
def open_update_checker(autosplit: AutoSplit, latest_version: str, check_on_open: bool):
70+
autosplit.UpdateCheckerWidget = __UpdateCheckerWidget(latest_version, autosplit, check_on_open)
6371

6472

6573
def viewHelp():
6674
os.system('start "" https://github.com/Toufool/Auto-Split#tutorial')
6775

6876

69-
def about(autosplit: AutoSplit):
70-
autosplit.aboutWidget = AboutWidget()
77+
class __CheckForUpdatesThread(QThread):
78+
def __init__(self, autosplit: AutoSplit, check_on_open: bool):
79+
super().__init__()
80+
self.autosplit = autosplit
81+
self.check_on_open = check_on_open
82+
83+
def run(self):
84+
try:
85+
response = requests.get("https://duckduckgo.com/?q=pyright+generate+stub+file&t=opera&ia=web")
86+
latest_version = response.json()["name"].split("v")[1]
87+
self.autosplit.updateCheckerWidgetSignal.emit(latest_version, self.check_on_open)
88+
except (RequestException, KeyError, JSONDecodeError):
89+
if not self.check_on_open:
90+
self.autosplit.showErrorSignal.emit(error_messages.checkForUpdatesError)
7191

7292

73-
def checkForUpdates(autosplit: AutoSplit, check_for_updates_on_open: bool = False):
74-
try:
75-
response = requests.get("https://api.github.com/repos/Toufool/Auto-Split/releases/latest")
76-
latest_version = response.json()["name"].split("v")[1]
77-
except requests.exceptions.RequestException:
78-
if not check_for_updates_on_open:
79-
error_messages.checkForUpdatesError()
80-
else:
81-
autosplit.updateCheckerWidget = UpdateCheckerWidget(latest_version, autosplit, check_for_updates_on_open)
93+
def checkForUpdates(autosplit: AutoSplit, check_on_open: bool = False):
94+
autosplit.CheckForUpdatesThread = __CheckForUpdatesThread(autosplit, check_on_open)
95+
autosplit.CheckForUpdatesThread.start()

src/settings_file.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
import pickle
99
import keyboard # https://github.com/boppreh/keyboard/issues/505
1010
from win32 import win32gui
11-
from PyQt6 import QtWidgets
11+
from PyQt6 import QtCore, QtWidgets
1212

13+
from gen import design
1314
import error_messages
1415
# TODO with settings refactoring
1516
from hotkeys import _hotkey_action # type: ignore
@@ -21,7 +22,7 @@
2122
class RestrictedUnpickler(pickle.Unpickler):
2223

2324
def find_class(self, module: str, name: str):
24-
raise pickle.UnpicklingError("'%s.%s' is forbidden" % (module, name))
25+
raise pickle.UnpicklingError(f"'{module}.{name}' is forbidden")
2526

2627

2728
def loadPyQtSettings(autosplit: AutoSplit):
@@ -319,3 +320,26 @@ def loadSettings(autosplit: AutoSplit, load_settings_on_open: bool = False, load
319320
autosplit.last_successfully_loaded_settings_file_path = autosplit.load_settings_file_path
320321
autosplit.checkLiveImage()
321322
autosplit.loadStartImage()
323+
324+
325+
def load_check_for_updates_on_open(designWindow: design.Ui_MainWindow):
326+
"""
327+
Retrieve the "Check For Updates On Open" QSettings and set the checkbox state
328+
These are only global settings values. They are not *pkl settings values.
329+
"""
330+
331+
value = QtCore \
332+
.QSettings("AutoSplit", "Check For Updates On Open") \
333+
.value("check_for_updates_on_open", True, type=bool)
334+
designWindow.actionCheck_for_Updates_on_Open.setChecked(value)
335+
336+
337+
def set_check_for_updates_on_open(designWindow: design.Ui_MainWindow, value: bool):
338+
"""
339+
Sets the "Check For Updates On Open" QSettings value and the checkbox state
340+
"""
341+
342+
designWindow.actionCheck_for_Updates_on_Open.setChecked(value)
343+
QtCore \
344+
.QSettings("AutoSplit", "Check For Updates On Open") \
345+
.setValue("check_for_updates_on_open", value)

typings/simplejson/errors.pyi

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
This type stub file was generated by pyright.
3+
"""
4+
5+
"""Error classes used by simplejson
6+
"""
7+
__all__ = ['JSONDecodeError']
8+
def linecol(doc, pos): # -> tuple[Unknown, Unknown]:
9+
...
10+
11+
def errmsg(msg, doc, pos, end=...): # -> str:
12+
...
13+
14+
class JSONDecodeError(ValueError):
15+
"""Subclass of ValueError with the following additional properties:
16+
17+
msg: The unformatted error message
18+
doc: The JSON document being parsed
19+
pos: The start index of doc where parsing failed
20+
end: The end index of doc where parsing failed (may be None)
21+
lineno: The line corresponding to pos
22+
colno: The column corresponding to pos
23+
endlineno: The line corresponding to end (may be None)
24+
endcolno: The column corresponding to end (may be None)
25+
26+
"""
27+
def __init__(self, msg, doc, pos, end=...) -> None:
28+
...
29+
30+
def __reduce__(self): # -> tuple[Type[Self@JSONDecodeError], tuple[Unknown, Unknown, Unknown, Unknown]]:
31+
...
32+
33+
34+

0 commit comments

Comments
 (0)