Skip to content

Commit

Permalink
Fix program sometimes freezing upon manual mode activation/deactivation
Browse files Browse the repository at this point in the history
Add hot reload config option
Minor changes to input handling
  • Loading branch information
nirgoren committed Oct 23, 2021
1 parent fdcd869 commit a0ae361
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ In addition to the recording specific config file, Eddienput also loads some set

* `default_recording`: A path to a recording file to load as the program starts.
* `rec_start_end_sound`: Either set to `true` or `false`, sets whether to play a sound when a recording starts/ends playing.
* `hot_reload`: Either set to `true` to `false`, sets whether the recording file is to be
reloaded automatically upon play.
* `side`: Set to either `P1` or `P2`, sets which player side to use as the program starts up.

## Known Issues:
Expand Down
3 changes: 2 additions & 1 deletion src/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"default_recording": "recordings\\gg_test.txt",
"rec_start_end_sound": "true",
"side": "P2"
"side": "P2",
"hot_reload": "true"
}
2 changes: 1 addition & 1 deletion src/eddiecontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

playing = False
mute = False
hot_reload = True
P1_directions_map = {}
P2_directions_map = {}
direction_maps = [P1_directions_map, P2_directions_map]
Expand Down Expand Up @@ -125,7 +126,6 @@ def play_queue():
playing = False
# for button, val, t in log_queue:
# print("pressed:", button, val, t)
return


# parse a string into a series of frame commands
Expand Down
45 changes: 26 additions & 19 deletions src/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ def load_config():
eddiecontroller.recordings_file = default_rec
set_recording_file(default_rec)
if 'side' in config:
side = config['side'].lower()
if side == 'p1':
if config['side'].lower() == 'p1':
set_side(0)
if 'rec_start_end_sound' in config:
sound = config['rec_start_end_sound'].lower()
if sound == 'false':
if config['rec_start_end_sound'].lower() == 'false':
eddiecontroller.toggle_mute()
if 'hot_reload' in config:
if config['hot_reload'].lower() == 'false':
eddiecontroller.hot_reload = False
except IOError as e:
print('Failed to open config file:', e, file=writer)

Expand Down Expand Up @@ -110,30 +111,40 @@ def on_press(key):
return
key_val = str(key)
#print("received", key_val)
# Ignore all hotkeys but F4 while a recording is playing
if key_val == "Key.f4": # F4
eddiecontroller.playing = False
return
elif eddiecontroller.playing:
return
if capture_activation_key:
# Handled here to not allow setting F9 as the playback button
if key_val == "Key.f9": # F9
activation_key = None
capture_activation_key = True
print('Capturing playback button...', file=writer)
return
elif capture_activation_key:
capture_activation_key = False
activation_key = key_val
print('Playback button set to', key_val, file=writer)
w.playback_button_label.setText('Playback button: \n' + activation_key)
elif key_val == activation_key:
worker = Worker(eddiecontroller.run_scenario)
eddiecontroller.threadpool.start(worker)
return
if eddiecontroller.recordings_file:
if key_val == "Key.f5": # F5
print("Reloading script", file=writer)
eddiecontroller.reset()
# Activation key takes precedence
if key_val == activation_key or key_val == "Key.f3": # F3
if eddiecontroller.hot_reload:
print("Reloading script", file=writer)
eddiecontroller.reset()
worker = Worker(eddiecontroller.run_scenario)
eddiecontroller.threadpool.start(worker)
return
if key_val == "Key.f1": # F1
set_side(0)
if key_val == "Key.f2": # F2
set_side(1)
if key_val == "Key.f3": # F3
worker = Worker(eddiecontroller.run_scenario)
eddiecontroller.threadpool.start(worker)
if key_val == "Key.f5": # F5
print("Reloading script", file=writer)
eddiecontroller.reset()
if key_val == "Key.f6": # F6
set_repetitions(max(1, eddiecontroller.repetitions - 1))
if key_val == "Key.f7": # F7
Expand All @@ -145,10 +156,6 @@ def on_press(key):
if key_val == "Key.f8": # F8
eddiecontroller.toggle_mute()
w.mute_label.setText('Start/End Sequence Sound: ' + on_off_map[eddiecontroller.mute])
if key_val == "Key.f9": # F9
activation_key = None
capture_activation_key = True
print('Capturing playback button...', file=writer)
if key_val == "Key.insert": # insert
global manual_mode
if not manual_mode:
Expand Down Expand Up @@ -287,7 +294,7 @@ def __init__(self):
self.toggle_image_signal.connect(self.toggleImage)
self.setMinimumWidth(1050)
self.setAcceptDrops(True)
self.setWindowTitle('Eddienput v1.1')
self.setWindowTitle('Eddienput v1.2')
self.setWindowIcon(QtGui.QIcon('icon.ico'))
self.setStyleSheet("QWidget { background-color : rgb(54, 57, 63); color : rgb(220, 221, 222); }")
v_layout = QVBoxLayout()
Expand Down

0 comments on commit a0ae361

Please sign in to comment.