Skip to content

Commit 711850e

Browse files
committed
Merge branch 'dev' of https://github.com/Toufool/AutoSplit into dev
2 parents 36511e5 + cec2f91 commit 711850e

File tree

6 files changed

+156
-23
lines changed

6 files changed

+156
-23
lines changed

res/settings.ui

Lines changed: 107 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
<rect>
88
<x>0</x>
99
<y>0</y>
10-
<width>285</width>
11-
<height>294</height>
10+
<width>284</width>
11+
<height>334</height>
1212
</rect>
1313
</property>
1414
<property name="minimumSize">
1515
<size>
16-
<width>285</width>
17-
<height>294</height>
16+
<width>284</width>
17+
<height>334</height>
1818
</size>
1919
</property>
2020
<property name="maximumSize">
2121
<size>
22-
<width>285</width>
23-
<height>294</height>
22+
<width>284</width>
23+
<height>334</height>
2424
</size>
2525
</property>
2626
<property name="font">
@@ -41,7 +41,7 @@
4141
<x>-3</x>
4242
<y>-3</y>
4343
<width>291</width>
44-
<height>301</height>
44+
<height>341</height>
4545
</rect>
4646
</property>
4747
<property name="currentIndex">
@@ -88,7 +88,7 @@
8888
<rect>
8989
<x>10</x>
9090
<y>40</y>
91-
<width>141</width>
91+
<width>261</width>
9292
<height>24</height>
9393
</rect>
9494
</property>
@@ -107,7 +107,7 @@
107107
<rect>
108108
<x>10</x>
109109
<y>70</y>
110-
<width>151</width>
110+
<width>261</width>
111111
<height>16</height>
112112
</rect>
113113
</property>
@@ -158,7 +158,7 @@
158158
<rect>
159159
<x>10</x>
160160
<y>120</y>
161-
<width>151</width>
161+
<width>261</width>
162162
<height>16</height>
163163
</rect>
164164
</property>
@@ -210,7 +210,7 @@
210210
<rect>
211211
<x>10</x>
212212
<y>220</y>
213-
<width>181</width>
213+
<width>261</width>
214214
<height>24</height>
215215
</rect>
216216
</property>
@@ -224,6 +224,102 @@
224224
<bool>false</bool>
225225
</property>
226226
</widget>
227+
<widget class="QCheckBox" name="screenshot_on_split_checkbox">
228+
<property name="geometry">
229+
<rect>
230+
<x>10</x>
231+
<y>280</y>
232+
<width>131</width>
233+
<height>24</height>
234+
</rect>
235+
</property>
236+
<property name="text">
237+
<string>Screenshot on Split</string>
238+
</property>
239+
<property name="tristate">
240+
<bool>false</bool>
241+
</property>
242+
</widget>
243+
<widget class="QCheckBox" name="screenshot_on_start_checkbox">
244+
<property name="geometry">
245+
<rect>
246+
<x>10</x>
247+
<y>240</y>
248+
<width>131</width>
249+
<height>24</height>
250+
</rect>
251+
</property>
252+
<property name="text">
253+
<string>Screenshot on Start</string>
254+
</property>
255+
<property name="tristate">
256+
<bool>false</bool>
257+
</property>
258+
</widget>
259+
<widget class="QCheckBox" name="screenshot_on_reset_checkbox">
260+
<property name="geometry">
261+
<rect>
262+
<x>10</x>
263+
<y>260</y>
264+
<width>131</width>
265+
<height>24</height>
266+
</rect>
267+
</property>
268+
<property name="text">
269+
<string>Screenshot on Reset</string>
270+
</property>
271+
<property name="tristate">
272+
<bool>false</bool>
273+
</property>
274+
</widget>
275+
<widget class="QCheckBox" name="screenshot_on_skip_checkbox">
276+
<property name="geometry">
277+
<rect>
278+
<x>140</x>
279+
<y>260</y>
280+
<width>131</width>
281+
<height>24</height>
282+
</rect>
283+
</property>
284+
<property name="text">
285+
<string>Screenshot on Skip</string>
286+
</property>
287+
<property name="tristate">
288+
<bool>false</bool>
289+
</property>
290+
</widget>
291+
<widget class="QCheckBox" name="screenshot_on_undo_checkbox">
292+
<property name="geometry">
293+
<rect>
294+
<x>140</x>
295+
<y>240</y>
296+
<width>131</width>
297+
<height>24</height>
298+
</rect>
299+
</property>
300+
<property name="text">
301+
<string>Screenshot on Undo</string>
302+
</property>
303+
<property name="tristate">
304+
<bool>false</bool>
305+
</property>
306+
</widget>
307+
<widget class="QCheckBox" name="screenshot_on_pause_checkbox">
308+
<property name="geometry">
309+
<rect>
310+
<x>140</x>
311+
<y>280</y>
312+
<width>131</width>
313+
<height>24</height>
314+
</rect>
315+
</property>
316+
<property name="text">
317+
<string>Screenshot on Pause</string>
318+
</property>
319+
<property name="tristate">
320+
<bool>false</bool>
321+
</property>
322+
</widget>
227323
</widget>
228324
<widget class="QWidget" name="image_settings_tab">
229325
<attribute name="title">

src/AutoControlledThread.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def run(self):
2424
break
2525
except EOFError:
2626
continue
27+
if line in self._autosplit_ref.settings_dict["screenshot_on"]:
28+
self._autosplit_ref.screenshot_signal.emit()
2729
match line:
2830
# This is for use in a Development environment
2931
case "kill":

src/AutoSplitImage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ def compare_with_capture(self, default: "AutoSplit | int", capture: MatLike | No
215215

216216
if not is_valid_image(self.byte_array):
217217
return 0.0
218-
resized_capture = cv2.resize(capture, self.byte_array.shape[1::-1], interpolation=cv2.INTER_NEAREST)
218+
resized_capture = cv2.resize(
219+
capture, self.byte_array.shape[1::-1], interpolation=cv2.INTER_NEAREST
220+
)
219221

220222
return get_comparison_method_by_index(
221223
self.__get_comparison_method_index(default),

src/hotkeys.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
SET_HOTKEY_TEXT = "Set Hotkey"
3030
PRESS_A_KEY_TEXT = "Press a key..."
3131

32-
Commands = Literal["split", "start", "pause", "reset", "skip", "undo"]
32+
CommandStr = Literal["split", "start", "pause", "reset", "skip", "undo"]
3333
Hotkey = Literal[
3434
"split",
3535
"reset",
@@ -80,16 +80,18 @@ def after_setting_hotkey(autosplit: "AutoSplit"):
8080
getattr(autosplit.SettingsWidget, f"set_{hotkey}_hotkey_button").setEnabled(True)
8181

8282

83-
def send_command(autosplit: "AutoSplit", command: Commands):
84-
# Note: Rather than having the start image able to also reset the timer,
85-
# having the reset image check be active at all time would be a better, more organic solution,
86-
# but that is dependent on migrating to an observer pattern (#219) and
87-
# being able to reload all images.
83+
def send_command(autosplit: "AutoSplit", command: CommandStr):
84+
if command in autosplit.settings_dict["screenshot_on"]:
85+
autosplit.screenshot_signal.emit()
8886
match command:
8987
case _ if autosplit.is_auto_controlled:
9088
if command == "start" and autosplit.settings_dict["start_also_resets"]:
9189
print("reset", flush=True)
9290
print(command, flush=True)
91+
# Note: Rather than having the start image able to also reset the timer, having
92+
# the reset image check be active at all time would be a better, more organic solution.
93+
# But that is dependent on migrating to an observer pattern (#219) and
94+
# being able to reload all images.
9395
case "start" if autosplit.settings_dict["start_also_resets"]:
9496
_send_hotkey(autosplit.settings_dict["reset_hotkey"])
9597
case "reset":

src/menu_bar.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
import webbrowser
44
from functools import partial
5-
from typing import TYPE_CHECKING, Any, cast
5+
from typing import TYPE_CHECKING, Any, Literal, cast
66
from urllib.error import URLError
77
from urllib.request import urlopen
88

@@ -23,7 +23,7 @@
2323
get_all_video_capture_devices,
2424
)
2525
from gen import about, design, settings as settings_ui, update_checker
26-
from hotkeys import HOTKEYS, HOTKEYS_WHEN_AUTOCONTROLLED, set_hotkey
26+
from hotkeys import HOTKEYS, HOTKEYS_WHEN_AUTOCONTROLLED, CommandStr, set_hotkey
2727
from utils import AUTOSPLIT_VERSION, GITHUB_REPOSITORY, ONE_SECOND, decimal, fire_and_forget
2828

2929
if TYPE_CHECKING:
@@ -38,6 +38,15 @@
3838
+ "\nRun: sudo apt-get install scrot"
3939
) if sys.platform == "linux" else "" # fmt: skip
4040

41+
_DEBUG_SCREENSHOT_COMMANDS: tuple[CommandStr, ...] = (
42+
"split",
43+
"start",
44+
"reset",
45+
"undo",
46+
"skip",
47+
"pause",
48+
)
49+
4150

4251
class __AboutWidget(QtWidgets.QWidget, about.Ui_AboutAutoSplitWidget): # noqa: N801 # Private class
4352
"""About Window."""
@@ -326,7 +335,7 @@ def __select_screenshot_directory(self):
326335
)
327336

328337
def __setup_bindings(self):
329-
"""Hotkey initial values and bindings."""
338+
# Hotkey initial values and bindings
330339
for hotkey in HOTKEYS:
331340
hotkey_input: QtWidgets.QLineEdit = getattr(self, f"{hotkey}_input")
332341
set_hotkey_hotkey_button: QtWidgets.QPushButton = getattr(
@@ -344,6 +353,21 @@ def __setup_bindings(self):
344353
partial(set_hotkey, self._autosplit_ref, hotkey=hotkey)
345354
)
346355

356+
# Debug screenshot selection checkboxes initial values and bindings
357+
_screenshot_on_setting = self._autosplit_ref.settings_dict["screenshot_on"]
358+
for command in _DEBUG_SCREENSHOT_COMMANDS:
359+
checkbox: QtWidgets.QCheckBox = getattr(self, f"screenshot_on_{command}_checkbox")
360+
361+
checkbox.setChecked(command in _screenshot_on_setting)
362+
363+
def add_or_del(checked: Literal[0, 2], command: CommandStr = command):
364+
if checked:
365+
_screenshot_on_setting.add(command)
366+
else:
367+
_screenshot_on_setting.remove(command)
368+
369+
checkbox.stateChanged.connect(add_or_del)
370+
347371
# region Set initial values
348372
# Capture Settings
349373
self.fps_limit_spinbox.setValue(self._autosplit_ref.settings_dict["fps_limit"])
@@ -478,6 +502,10 @@ def get_default_settings_from_ui(autosplit: "AutoSplit"):
478502
"split_image_directory": autosplit.split_image_folder_input.text(),
479503
"screenshot_directory": default_settings_dialog.screenshot_directory_input.text(),
480504
"open_screenshot": default_settings_dialog.open_screenshot_checkbox.isChecked(),
505+
"screenshot_on": {
506+
getattr(default_settings_dialog, f"screenshot_on_{command}_checkbox").isChecked()
507+
for command in _DEBUG_SCREENSHOT_COMMANDS
508+
},
481509
"captured_window_title": "",
482510
"capture_region": {
483511
"x": autosplit.x_spinbox.value(),

src/user_profile.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import error_messages
1010
from capture_method import CAPTURE_METHODS, CaptureMethodEnum, Region, change_capture_method
1111
from gen import design
12-
from hotkeys import HOTKEYS, Hotkey, remove_all_hotkeys, set_hotkey
12+
from hotkeys import HOTKEYS, CommandStr, Hotkey, remove_all_hotkeys, set_hotkey
1313
from menu_bar import open_settings
1414
from utils import auto_split_directory
1515

@@ -40,6 +40,7 @@ class UserProfileDict(TypedDict):
4040
split_image_directory: str
4141
screenshot_directory: str
4242
open_screenshot: bool
43+
screenshot_on: set[CommandStr]
4344
captured_window_title: str
4445
capture_region: Region
4546

@@ -72,6 +73,7 @@ def copy():
7273
split_image_directory="",
7374
screenshot_directory="",
7475
open_screenshot=True,
76+
screenshot_on=set(),
7577
captured_window_title="",
7678
capture_region=Region(x=0, y=0, width=1, height=1),
7779
)
@@ -122,7 +124,7 @@ def __load_settings_from_file(autosplit: "AutoSplit", load_settings_file_path: s
122124
autosplit.show_error_signal.emit(error_messages.old_version_settings_file)
123125
return False
124126

125-
# Allow seemlessly reloading the entire settings widget
127+
# Allow seamlessly reloading the entire settings widget
126128
settings_widget_was_open = False
127129
settings_widget = cast(QtWidgets.QWidget | None, autosplit.SettingsWidget)
128130
if settings_widget:
@@ -137,6 +139,7 @@ def __load_settings_from_file(autosplit: "AutoSplit", load_settings_file_path: s
137139
loaded_settings = DEFAULT_PROFILE | cast(UserProfileDict, toml.load(file))
138140

139141
# TODO: Data Validation / fallbacks ?
142+
loaded_settings["screenshot_on"] = set(loaded_settings["screenshot_on"])
140143
autosplit.settings_dict = UserProfileDict(**loaded_settings)
141144
autosplit.last_saved_settings = deepcopy(autosplit.settings_dict)
142145

0 commit comments

Comments
 (0)