Skip to content

Commit af8036b

Browse files
committed
Added macro settings in macro files #69
Optimized settings import
1 parent f8be77d commit af8036b

File tree

16 files changed

+80
-44
lines changed

16 files changed

+80
-44
lines changed

TUTORIAL.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ To change, simply click to the one you want to disable.
6767
Macro are wrote with JSON, and to make the file smaller, I compact everything. But, if do like writing your own lines, you can disable this option so you have a beautiful and readable file (but more bigger in size).
6868
To enable/disable go to `Options` -> `Settings` -> `Compact macro data`.
6969

70+
### Always import macro settings
71+
72+
If you always want to import macro settings when loading a macro, enable this option in `Options` -> `Settings` -> `Always import macro settings`.
73+
This will remove the confirmation windows each time you load a macro and automatically import the macro settings.
74+
7075
### Hotkeys
7176

7277
To change your hotkeys to start, stop, start playback and stop playback, go to `Options` -> `Settings` -> `Hotkeys`.

src/hotkeys/hotkeys_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __win32_event_filter(self, msg, data):
4545
return True
4646

4747
def __on_press(self, key):
48-
userSettings = self.settings.get_config()
48+
userSettings = self.settings.settings_dict
4949
if self.changeKey:
5050
keyPressed = getKeyPressed(self.keyboard_listener, key)
5151
if keyPressed not in self.hotkeys:

src/langs/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"confirm_save": "Do you want to save your record?",
1616
"confirm": "Confirm",
1717
"information": "Information",
18-
"restart_software_text": "You need to restart the software for it to take effect."
18+
"restart_software_text": "You need to restart the software for it to take effect.",
19+
"load_macro_settings": "Import macro settings too?"
1920
},
2021
"new_version": {
2122
"title": "Software update",
@@ -85,6 +86,7 @@
8586
"json_compact": "Compact macro data",
8687
"settings_menu": {
8788
"settings_text": "Settings",
89+
"always_import_macro_settings": "Always import macro settings",
8890
"lang_text": "Language",
8991
"lang_settings": {
9092
"title": "Language settings",

src/langs/fr.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"confirm_save": "Voulez-vous sauvegarder votre enregistrement?",
1616
"confirm": "Confirmer",
1717
"information": "Information",
18-
"restart_software_text": "Vous devez redémarrer le logiciel pour que cela prenne effet."
18+
"restart_software_text": "Vous devez redémarrer le logiciel pour que cela prenne effet.",
19+
"load_macro_settings": "Importer les paramètres macro également ?"
1920
},
2021
"new_version": {
2122
"title": "Mise à jour du logiciel",
@@ -85,6 +86,7 @@
8586
"json_compact": "Données macro compactes",
8687
"settings_menu": {
8788
"settings_text": "Paramètres",
89+
"always_import_macro_settings": "Toujours importer les paramètres macro",
8890
"lang_text": "Language",
8991
"lang_settings": {
9092
"title": "Réglage du language",

src/macro/macro.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, main_app):
2424
self.keyboardControl = keyboard.Controller()
2525
self.record = False
2626
self.playback = False
27-
self.macro_events = {"events": []}
27+
self.macro_events = {}
2828
self.main_app = main_app
2929
self.user_settings = self.main_app.settings
3030
self.main_menu = self.main_app.menu
@@ -56,7 +56,7 @@ def start_record(self, by_hotkey=False):
5656
self.record = True
5757
self.time = time()
5858
self.event_delta_time=0
59-
userSettings = self.user_settings.get_config()
59+
userSettings = self.user_settings.settings_dict
6060
self.showEventsOnStatusBar = userSettings["Recordings"]["Show_Events_On_Status_Bar"]
6161
if (
6262
userSettings["Recordings"]["Mouse_Move"]
@@ -100,7 +100,7 @@ def start_record(self, by_hotkey=False):
100100
def stop_record(self):
101101
if not self.record:
102102
return
103-
userSettings = self.user_settings.get_config()
103+
userSettings = self.user_settings.settings_dict
104104
self.record = False
105105
if self.mouseBeingListened:
106106
self.mouse_listener.stop()
@@ -131,7 +131,7 @@ def stop_record(self):
131131
print("record stopped")
132132

133133
def start_playback(self):
134-
userSettings = self.user_settings.get_config()
134+
userSettings = self.user_settings.settings_dict
135135
self.playback = True
136136
self.main_app.playBtn.configure(
137137
image=self.main_app.stopImg, command=lambda: self.stop_playback(True)
@@ -155,7 +155,7 @@ def start_playback(self):
155155
print("playback started")
156156

157157
def __play_interval(self):
158-
userSettings = self.user_settings.get_config()
158+
userSettings = self.user_settings.settings_dict
159159
if userSettings["Playback"]["Repeat"]["For"] > 0:
160160
self.__play_for()
161161
else:
@@ -172,15 +172,15 @@ def __play_interval(self):
172172

173173

174174
def __play_for(self):
175-
userSettings = self.user_settings.get_config()
175+
userSettings = self.user_settings.settings_dict
176176
debut = time()
177177
while self.playback and (time() - debut) < userSettings["Playback"]["Repeat"]["For"]:
178178
self.__play_events()
179179
if userSettings["Playback"]["Repeat"]["Interval"] == 0:
180180
self.stop_playback()
181181

182182
def __play_events(self):
183-
userSettings = self.user_settings.get_config()
183+
userSettings = self.user_settings.settings_dict
184184
click_func = {
185185
"leftClickEvent": Button.left,
186186
"rightClickEvent": Button.right,
@@ -302,7 +302,7 @@ def stop_playback(self, playback_stopped_manually=False):
302302
print("playback stopped")
303303
else:
304304
print("playback stopped manually")
305-
userSettings = self.user_settings.get_config()
305+
userSettings = self.user_settings.settings_dict
306306
self.main_app.recordBtn.configure(state=NORMAL)
307307
self.main_app.playBtn.configure(
308308
image=self.main_app.playImg, command=self.start_playback

src/utils/record_file_management.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from tkinter import *
22
from tkinter import filedialog
3+
from tkinter import messagebox
34
from os import path
45
from json import load, dumps
56

@@ -34,11 +35,21 @@ def save_macro(self, event=None):
3435
return
3536
if self.main_app.current_file is not None:
3637
with open(self.main_app.current_file, "w") as current_file:
37-
compactJson = UserSettings(self.main_app).get_config()["Saving"]["Compact_json"]
38+
compactJson = UserSettings(self.main_app).settings_dict["Saving"]["Compact_json"]
39+
userSettings = self.main_app.settings.settings_dict
40+
macroSettings = {"settings": {
41+
"Playback": userSettings["Playback"],
42+
"Minimization": userSettings["Minimization"],
43+
"After_Playback": userSettings["After_Playback"]
44+
}}
45+
macroData = {
46+
**macroSettings,
47+
**self.main_app.macro.macro_events
48+
}
3849
if compactJson:
39-
json_macroEvents = dumps(self.main_app.macro.macro_events, separators=(',', ':'))
50+
json_macroEvents = dumps(macroData, separators=(',', ':'))
4051
else:
41-
json_macroEvents = dumps(self.main_app.macro.macro_events, indent=4)
52+
json_macroEvents = dumps(macroData, indent=4)
4253
current_file.write(json_macroEvents)
4354
else:
4455
self.save_macro_as()
@@ -77,8 +88,15 @@ def load_macro(self, event=None):
7788
self.main_app.macro_recorded = True
7889
self.main_app.macro_saved = True
7990
self.main_app.current_file = macroFile.name
91+
if not self.main_app.settings.settings_dict["Loading"]["Always_import_macro_settings"]:
92+
if messagebox.askyesno("PyMacroRecord", self.config_text["global"]["load_macro_settings"]):
93+
macro_settings = self.main_app.macro.macro_events["settings"]
94+
self.main_app.settings.settings_dict["Playback"] = macro_settings["Playback"]
95+
self.main_app.settings.settings_dict["Minimization"] = macro_settings["Minimization"]
96+
self.main_app.settings.settings_dict["After_Playback"] = macro_settings["After_Playback"]
8097
self.main_app.prevent_record = False
8198

99+
82100
def new_macro(self, event=None):
83101
if not self.main_app.macro_recorded or self.main_app.macro.playback:
84102
return

src/utils/user_settings.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def __init__(self, main_app):
2424
self.first_time = True
2525
self.init_settings()
2626

27+
self.settings_dict = self.__get_config()
2728
self.check_new_options()
2829

2930
def init_settings(self):
@@ -57,6 +58,9 @@ def init_settings(self):
5758
"Saving": {
5859
"Compact_json": True
5960
},
61+
"Loading": {
62+
"Always_import_macro_settings": False
63+
},
6064

6165
"Hotkeys": {
6266
"Record_Start": [],
@@ -94,15 +98,15 @@ def init_settings(self):
9498
with open(self.user_setting, "w") as settingFile:
9599
settingFile.write(userSettings_json)
96100

97-
def get_config(self):
101+
def __get_config(self):
98102
"""Get settings of users"""
99103
with open(self.user_setting, "r") as settingFile:
100104
settingFile_json = load(settingFile)
101105
return settingFile_json
102106

103-
def update_settings(self, updatedValues):
107+
def update_settings(self):
104108
with open(self.user_setting, "w") as settingFile:
105-
settingFile.write(updatedValues)
109+
settingFile.write(dumps(self.settings_dict, indent=4))
106110

107111
def reset_settings(self):
108112
if messagebox.askyesno(self.main_app.text_content["global"]["confirm"], self.main_app.text_content["options_menu"]["others_menu"]["reset_settings_confirmation"]):
@@ -113,33 +117,32 @@ def get_path(self):
113117

114118
def change_settings(self, category, option=None, option2=None, newValue=None):
115119
"""Change settings of user"""
116-
userSettings = self.get_config()
117120
if option == "Show_Events_On_Status_Bar":
118-
if userSettings[category][option]:
121+
if self.settings_dict[category][option]:
119122
self.main_app.status_text.pack_forget()
120123
else:
121124
self.main_app.status_text.pack(side=BOTTOM, fill=X)
122-
if not category in userSettings:
123-
userSettings[category] = ""
125+
if not category in self.settings_dict:
126+
self.settings_dict[category] = ""
124127
if newValue is None:
125128
if option is None:
126-
userSettings[category] = not userSettings[category]
129+
self.settings_dict[category] = not self.settings_dict[category]
127130
elif option2 is not None:
128-
userSettings[category][option][option2] = not userSettings[category][option][option2]
131+
self.settings_dict[category][option][option2] = not self.settings_dict[category][option][option2]
129132
else:
130-
userSettings[category][option] = not userSettings[category][option]
133+
self.settings_dict[category][option] = not self.settings_dict[category][option]
131134

132135
elif option is not None and newValue is not None:
133136
if option2 is not None:
134-
userSettings[category][option][option2] = newValue
137+
self.settings_dict[category][option][option2] = newValue
135138
else:
136-
userSettings[category][option] = newValue
139+
self.settings_dict[category][option] = newValue
137140
elif option is None and option2 is None:
138-
userSettings[category] = newValue
139-
self.update_settings(dumps(userSettings, indent=4))
141+
self.settings_dict[category] = newValue
142+
self.update_settings()
140143

141144
def check_new_options(self):
142-
userSettings = self.get_config()
145+
userSettings = self.settings_dict
143146
if "Others" not in userSettings:
144147
userSettings["Others"] = {"Check_update": True}
145148
if "Fixed_timestamp" not in userSettings["Others"]:
@@ -161,5 +164,9 @@ def check_new_options(self):
161164
if "Infinite" not in userSettings["Playback"]["Repeat"]:
162165
userSettings["Playback"]["Repeat"]["Infinite"] = False
163166
if "Show_Events_On_Status_Bar" not in userSettings["Recordings"]:
164-
userSettings["Recordings"]["Show_Events_On_Status_Bar"]=False
165-
self.update_settings(dumps(userSettings, indent=4))
167+
userSettings["Recordings"]["Show_Events_On_Status_Bar"] = False
168+
if "Loading" not in userSettings:
169+
userSettings["Loading"] = {}
170+
if "Always_import_macro_settings" not in userSettings["Loading"]:
171+
userSettings["Loading"]["Always_import_macro_settings"] = False
172+
self.update_settings()

src/windows/main/main_app.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self):
5353
self.current_file = None
5454
self.prevent_record = False
5555

56-
self.version = Version(self.settings.get_config(), self)
56+
self.version = Version(self.settings.settings_dict, self)
5757

5858
self.menu = MenuBar(self) # Menu Bar
5959
self.macro = Macro(self)
@@ -63,7 +63,7 @@ def __init__(self):
6363
self.hotkeyManager = HotkeysManager(self)
6464

6565
self.status_text = Label(self, text='', relief=SUNKEN, anchor=W)
66-
if self.settings.get_config()["Recordings"]["Show_Events_On_Status_Bar"]:
66+
if self.settings.settings_dict["Recordings"]["Show_Events_On_Status_Bar"]:
6767
self.status_text.pack(side=BOTTOM, fill=X)
6868

6969
# Main Buttons (Start record, stop record, start playback, stop playback)
@@ -110,14 +110,14 @@ def __init__(self):
110110
if platform != "win32" and self.settings.first_time:
111111
NotWindows(self)
112112

113-
if self.settings.get_config()["Others"]["Check_update"]:
113+
if self.settings.settings_dict["Others"]["Check_update"]:
114114
if self.version.new_version != "" and self.version.version != self.version.new_version:
115-
if time() > self.settings.get_config()["Others"]["Remind_new_ver_at"]:
115+
if time() > self.settings.settings_dict["Others"]["Remind_new_ver_at"]:
116116
NewVerAvailable(self, self.version.new_version)
117117
self.mainloop()
118118

119119
def load_language(self):
120-
self.lang = self.settings.get_config()["Language"]
120+
self.lang = self.settings.settings_dict["Language"]
121121
with open(resource_path(path.join('langs', self.lang + '.json')), encoding='utf-8') as f:
122122
self.text_content = json.load(f)
123123
self.text_content = self.text_content["content"]

src/windows/main/menu_bar.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(self, parent):
1313
super().__init__(parent)
1414

1515
settings = parent.settings
16-
userSettings = settings.get_config()
16+
userSettings = settings.settings_dict
1717
self.text_config = parent.text_content
1818

1919

@@ -71,7 +71,9 @@ def __init__(self, parent):
7171
# Settings Sub
7272
self.options_sub = Menu(self.options_menu, tearoff=0)
7373
self.compactJson = BooleanVar(value=userSettings["Saving"]["Compact_json"])
74+
self.always_import_macro_settings = BooleanVar(value=userSettings["Loading"]["Always_import_macro_settings"])
7475
self.options_sub.add_checkbutton(label=self.text_config["options_menu"]["json_compact"], command=lambda: settings.change_settings("Saving", "Compact_json"), variable=self.compactJson)
76+
self.options_sub.add_checkbutton(label=self.text_config["options_menu"]["settings_menu"]["always_import_macro_settings"], command=lambda: settings.change_settings("Loading", "Always_import_macro_settings"), variable=self.always_import_macro_settings)
7577
self.options_menu.add_cascade(label=self.text_config["options_menu"]["settings_menu"]["settings_text"], menu=self.options_sub)
7678
self.options_sub.add_command(label=self.text_config["options_menu"]["settings_menu"]["hotkeys_text"], command=lambda: Hotkeys(self, parent))
7779
self.options_sub.add_command(label=self.text_config["options_menu"]["settings_menu"]["lang_text"], command=lambda: SelectLanguage(self, parent))

src/windows/options/playback/delay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def __init__(self, parent, main_app):
1010
main_app.prevent_record = True
1111
self.settings = main_app.settings
1212
Label(self, text=main_app.text_content["options_menu"]["playback_menu"]["delay_settings"]["sub_text"], font=('Segoe UI', 10)).pack(side=TOP, pady=10)
13-
userSettings = main_app.settings.get_config()
13+
userSettings = main_app.settings.settings_dict
1414
setNewDelayInput = Spinbox(self, from_=1, to=100000000, width=7, validate="key",
1515
validatecommand=(main_app.validate_cmd, "%d", "%P"))
1616
setNewDelayInput.insert(0, str(userSettings["Playback"]["Repeat"]["Delay"]))

0 commit comments

Comments
 (0)