From b5a2e66df261753b7368653a35385c408c5e7487 Mon Sep 17 00:00:00 2001 From: LE LOUER Lucas Date: Tue, 8 Aug 2023 11:06:12 +0200 Subject: [PATCH] Finished menu bar (Visual only) --- .gitignore | 3 ++- macro.py | 21 +++++++++------ software.py | 74 +++++++++++++++++++++++++++++++++++++++++------------ tes.py | 18 +++++++++++++ 4 files changed, 91 insertions(+), 25 deletions(-) create mode 100644 tes.py diff --git a/.gitignore b/.gitignore index a8c1a08..ea2c93f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ data .idea __pycache__ venv -software.spec \ No newline at end of file +software.spec +temprecordloc.txt \ No newline at end of file diff --git a/macro.py b/macro.py index f22250e..00eadef 100644 --- a/macro.py +++ b/macro.py @@ -98,6 +98,7 @@ def startRecord(): keyboard_listener = keyboard.Listener(on_press=on_press, on_release=on_release) mouse_listener.start() keyboard_listener.start() + print('record started') def stopRecord(): @@ -105,10 +106,13 @@ def stopRecord(): Stop record """ global macroEvents, record + record = False mouse_listener.stop() keyboard_listener.stop() json_macroEvents = dumps(macroEvents, indent=4) open(path.join(appdata_local+"/temprecord.json"), "w").write(json_macroEvents) + print('record stopped') + def playRec(): """ @@ -160,19 +164,20 @@ def playRec(): # While loop to detect keybind of user while True: - if (record == False and playback == False): + # Start Record + if record == False and playback == False: if is_pressed('o'): - keyboardControl.release('o') + keyboardControl.release('o') # I release here because for some reason sometimes startRecord is called and then right after stopRecord is called startRecord() - - if (record == False and playback == False and len(macroEvents['events']) != 0): + # Play Back + if record == False and playback == False and len(macroEvents["events"]) != 0: if is_pressed('p'): keyboardControl.release('p') - playback = True playRec() - if (record == True and playback == False): + # Stop Record + if record == True and playback == False: if is_pressed('escape'): keyboardControl.release(Key.esc) - record = False - stopRecord() \ No newline at end of file + stopRecord() + diff --git a/software.py b/software.py index 75f3667..ad91265 100644 --- a/software.py +++ b/software.py @@ -40,7 +40,10 @@ def on_release(key): playbackStatement = False recordBtn.configure(state=NORMAL) playBtn.configure(image=playImg) + file_menu.entryconfig('New', state=NORMAL) file_menu.entryconfig('Load', state=NORMAL) + file_menu.entryconfig('Save', state=NORMAL) + file_menu.entryconfig('Save as', state=NORMAL) def startRecordingAndChangeImg(pressKey=True): @@ -87,8 +90,9 @@ def replay(pressKey=True): Replay the last recorded macro or the loaded one """ global playbackStatement, recordBtn, recordSet - playBtn.configure(image=stopImg) if recordSet == True: + playBtn.configure(image=stopImg) + print('playback') playbackStatement = True file_menu.entryconfig('Save', state=DISABLED) file_menu.entryconfig('Save as', state=DISABLED) @@ -142,17 +146,19 @@ def loadMacro(e=None): global macroPath, recordSet if recordStatement == False and playbackStatement == False: macroFile = filedialog.askopenfile(filetypes=[('Json Files', '*.json')], defaultextension='.json') - macroContent = open(macroFile.name) - macroPath = macroFile.name - macroEvents = load(macroContent) - json_macroEvents = dumps(macroEvents, indent=4) - open(path.join(appdata_local + "/temprecord.json"), "w").write(json_macroEvents) - playBtn.configure(state=NORMAL) - file_menu.entryconfig('Save', state=NORMAL, command=saveMacro) - file_menu.entryconfig('Save as', state=NORMAL, command=saveMacroAs) - file_menu.entryconfig('New', state=NORMAL, command=newMacro) - recordSet = True - macroFile.close() + if macroFile is not None: + macroContent = open(macroFile.name) + macroPath = macroFile.name + macroEvents = load(macroContent) + json_macroEvents = dumps(macroEvents, indent=4) + open(path.join(appdata_local + "/temprecord.json"), "w").write(json_macroEvents) + playBtn.configure(state=NORMAL) + file_menu.entryconfig('Save', state=NORMAL, command=saveMacro) + file_menu.entryconfig('Save as', state=NORMAL, command=saveMacroAs) + file_menu.entryconfig('New', state=NORMAL, command=newMacro) + macroFile.close() + print("loaded") + recordSet = True def newMacro(e=None): @@ -197,13 +203,49 @@ window.config(menu=my_menu) # File Section file_menu = Menu(my_menu, tearoff=0) my_menu.add_cascade(label="File", menu=file_menu) -file_menu.add_command(label="New", state=DISABLED) -file_menu.add_command(label="Load", command=loadMacro) -file_menu.add_command(label="Save", state=DISABLED) -file_menu.add_command(label="Save as", state=DISABLED) +file_menu.add_command(label="New", state=DISABLED, accelerator="Ctrl+N") +file_menu.add_command(label="Load", command=loadMacro, accelerator="Ctrl+L") +file_menu.add_command(label="Save", state=DISABLED, accelerator="Ctrl+S") +file_menu.add_command(label="Save as", state=DISABLED, accelerator="Ctrl+Shift+S") file_menu.add_separator() file_menu.add_command(label="Exit", command=window.quit) +# Options Section +options_menu = Menu(my_menu, tearoff=0) +my_menu.add_cascade(label="Options", menu=options_menu) + +# Playback Sub +playback_sub = Menu(options_menu, tearoff=0) +options_menu.add_cascade(label="Playback", menu=playback_sub) +playback_sub.add_command(label="Speed") +playback_sub.add_command(label="Repeat") + +# Recordings Sub +recordings_sub = Menu(options_menu, tearoff=0) +options_menu.add_cascade(label="Recordings", menu=recordings_sub) +recordings_sub.add_command(label="Mouse movement") +recordings_sub.add_command(label="Mouse Click") +recordings_sub.add_command(label="Keyboard") + +# Options Sub +options_sub = Menu(options_menu, tearoff=0) +options_menu.add_cascade(label="Options", menu=options_sub) +options_sub.add_command(label="Hotkeys") + +minimization_sub = Menu(options_sub, tearoff=0) +options_sub.add_cascade(label="Minimization", menu=minimization_sub) +minimization_sub.add_command(label="Minimized when playing") +minimization_sub.add_command(label="Minimized when recording") + +options_sub.add_command(label="Run on startup") +options_sub.add_command(label="After recording") + +help_section = Menu(my_menu, tearoff=0) +my_menu.add_cascade(label="Help", menu=help_section) +help_section.add_command(label="Github Page") +help_section.add_command(label="About") + + # Play Button playImg = PhotoImage(file=r"assets/button/play.png") playBtn = Button(window, image=playImg, command=replay, state=DISABLED) diff --git a/tes.py b/tes.py new file mode 100644 index 0000000..d01a6ef --- /dev/null +++ b/tes.py @@ -0,0 +1,18 @@ +import tkinter as tk + +parent = tk.Tk() + +menubar = tk.Menu(parent) +show_all = tk.BooleanVar() +show_all.set(True) +show_done = tk.BooleanVar() +show_not_done = tk.BooleanVar() + +view_menu = tk.Menu(menubar) +view_menu.add_checkbutton(label="Show All", onvalue=1, offvalue=0, variable=show_all) +view_menu.add_checkbutton(label="Show Done", onvalue=1, offvalue=0, variable=show_done) +view_menu.add_checkbutton(label="Show Not Done", onvalue=1, offvalue=0, variable=show_not_done) +menubar.add_cascade(label='View', menu=view_menu) +parent.config(menu=menubar) + +parent.mainloop() \ No newline at end of file