Removed temprecord.json

This commit is contained in:
LOUDO 2024-02-01 13:46:49 +01:00
parent 5aa978dff7
commit 397db1a1ae
3 changed files with 13 additions and 21 deletions

View File

@ -20,7 +20,6 @@ class Macro:
self.keyboardControl = keyboard.Controller()
self.record = False
self.playback = False
self.playback = False
self.macro_events = {'events': []}
self.main_app = main_app
self.user_settings = self.main_app.settings
@ -91,12 +90,8 @@ class Macro:
self.main_menu.file_menu.entryconfig('New', state=NORMAL, command=self.macro_file_management.new_macro)
self.main_menu.file_menu.entryconfig('Load', state=NORMAL)
record_file = open(path.join(self.user_settings.get_path(), "temprecord.json"), "w")
json_macroEvents = dumps(self.macro_events, indent=4)
record_file.write(json_macroEvents)
record_file.close()
self.main_app.macro_recorded = True
self.main_app.macro_saved = False
if userSettings["Minimization"]["When_Recording"]:
self.main_app.deiconify()

View File

@ -6,14 +6,14 @@ from utils.warning_pop_up_save import confirm_save
class RecordFileManagement:
"""Manage save and load record from main app"""
def __init__(self, main_app, menu_bar):
self.main_app = main_app
self.record_path = path.join(self.main_app.settings.get_path(), "temprecord.json")
self.menu_bar = menu_bar
self.current_file = None
def save_macro_as(self, event=None):
if not self.main_app.macro_recorded:
if not self.main_app.macro_recorded or self.main_app.macro.playback:
return
self.main_app.prevent_record = True
macroSaved = filedialog.asksaveasfile(filetypes=[('PyMacroRecord Files', '*.pmr'), ('Json Files', '*.json')], defaultextension='.pmr')
@ -24,16 +24,20 @@ class RecordFileManagement:
self.main_app.prevent_record = False
def save_macro(self, event=None):
if not self.main_app.macro_recorded:
if not self.main_app.macro_recorded or self.main_app.macro.playback:
return
if self.current_file is not None:
self.__import_export(self.record_path, self.current_file)
with open(self.current_file, "w") as current_file:
json_macroEvents = dumps(self.main_app.macro.macro_events, indent=4)
current_file.write(json_macroEvents)
else:
self.save_macro_as()
def load_macro(self, event=None):
if self.main_app.macro.playback:
return
self.main_app.prevent_record = True
if not self.main_app.macro_saved and self.main_app.macro_recorded:
wantToSave = confirm_save()
@ -43,19 +47,19 @@ class RecordFileManagement:
return
macroFile = filedialog.askopenfile(filetypes=[('PyMacroRecord Files', '*.pmr'), ('Json Files', '*.json')], defaultextension='.pmr')
if macroFile is not None:
self.__import_export(macroFile.name, self.record_path)
self.main_app.playBtn.configure(state=NORMAL, command=self.main_app.macro.start_playback)
self.menu_bar.file_menu.entryconfig('Save', state=NORMAL, command=self.save_macro)
self.menu_bar.file_menu.entryconfig('Save as', state=NORMAL, command=self.save_macro_as)
self.menu_bar.file_menu.entryconfig('New', state=NORMAL, command=self.new_macro)
macroFile.close()
with open(self.record_path, "r") as macroContent:
with open(macroFile.name, "r") as macroContent:
self.main_app.macro.import_record(load(macroContent))
self.main_app.macro_recorded = True
self.main_app.macro_saved = True
self.main_app.prevent_record = False
def new_macro(self, event=None):
if not self.main_app.macro_recorded:
if not self.main_app.macro_recorded or self.main_app.macro.playback:
return
if not self.main_app.macro_saved and self.main_app.macro_recorded:
wantToSave = confirm_save()
@ -71,10 +75,3 @@ class RecordFileManagement:
self.current_file = None
self.main_app.macro_saved = False
self.main_app.macro_recorded = False
def __import_export(self, toRead, toWrite):
with open(toRead, "r") as macroContent:
loaded_events = load(macroContent)
with open(toWrite, "w") as fileToWrite:
json_macroEvents = dumps(loaded_events, indent=4)
fileToWrite.write(json_macroEvents)

View File

@ -13,7 +13,7 @@ from utils.version import Version
from windows.others.new_ver_avalaible import NewVerAvailable
from hotkeys.hotkeys_manager import HotkeysManager
from macro import Macro
from os import path
from os import path, remove
from sys import platform, argv
from pystray import Icon
from pystray import MenuItem