From b24df9a77c2b0a99a5ed259f86e73ab1d223f3f1 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Mon, 17 Mar 2025 09:00:39 +0000 Subject: [PATCH] swattign all the bugs meybe fix memory leak fix a lot of stuff, improvemetns --- .nova/Configuration.json | 4 +- .nova/Tasks/Custom Task.json | 17 ---- .nova/Tasks/Python Debug.json | 37 ++++++++ .nova/Tasks/Virtual Environment.json | 21 +++++ DockPhobiaPy/.DS_Store | Bin 6148 -> 6148 bytes DockPhobiaPy/main.py | 133 ++++++++++++++++----------- DockPhobiaPy/requirements.txt | 3 + 7 files changed, 141 insertions(+), 74 deletions(-) delete mode 100644 .nova/Tasks/Custom Task.json create mode 100644 .nova/Tasks/Python Debug.json create mode 100644 .nova/Tasks/Virtual Environment.json diff --git a/.nova/Configuration.json b/.nova/Configuration.json index cb11c8e..4ddd0b3 100644 --- a/.nova/Configuration.json +++ b/.nova/Configuration.json @@ -1,4 +1,6 @@ { "python.analysis.typeCheckingMode" : "strict", - "python.pipRequirements" : "DockPhobiaPy\/requirements.txt" + "python.interpreter" : ".\/DockPhobiaPy\/venv\/bin\/python3", + "python.pipRequirements" : "DockPhobiaPy\/requirements.txt", + "python.pythonPath" : "\/Users\/neon443\/Documents\/Xcode\/DockPhobia\/DockPhobiaPy\/venv\/bin\/python3" } diff --git a/.nova/Tasks/Custom Task.json b/.nova/Tasks/Custom Task.json deleted file mode 100644 index cd2984c..0000000 --- a/.nova/Tasks/Custom Task.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "actions" : { - "build" : { - "enabled" : true, - "script" : "#!\/bin\/sh\ncd DockPhobiaPy\npython3 -m venv venv\n. venv\/bin\/activate\npip3 install -r requirements.txt" - }, - "clean" : { - "enabled" : true, - "script" : "#!\/bin\/sh\ncd DockPhobiaPy\n. venv\/bin\/activate\npip3 freeze > requirements.txt\nrm -rf venv" - }, - "run" : { - "enabled" : true, - "script" : "#!\/bin\/sh\ncd DockPhobiaPy\n. venv\/bin\/activate\npython3 main.py" - } - }, - "openLogOnRun" : "start" -} diff --git a/.nova/Tasks/Python Debug.json b/.nova/Tasks/Python Debug.json new file mode 100644 index 0000000..46d5b3e --- /dev/null +++ b/.nova/Tasks/Python Debug.json @@ -0,0 +1,37 @@ +{ + "actions" : { + "build" : { + "postActions" : [ + { + "script" : "cd DockPhobiaPy\npython3 -m venv venv\n. venv\/bin\/activate\npip3 install -r requirements.txt", + "type" : "runScript" + } + ] + }, + "clean" : { + "postActions" : [ + { + "script" : "cd DockPhobiaPy\n. venv\/bin\/activate\npip3 freeze > requirements.txt\nrm -rf venv", + "type" : "runScript" + } + ] + }, + "run" : { + "postActions" : [ + { + "script" : ". DockPhobiaPy\/yvenv\/bin\/activate", + "type" : "runScript" + } + ] + } + }, + "extension" : { + "identifier" : "panic.Python", + "name" : "Python" + }, + "extensionTemplate" : "pythonDebug", + "extensionValues" : { + "python.debug.script" : "main.py", + "python.debug.workingDirectory" : "DockPhobiaPy" + } +} diff --git a/.nova/Tasks/Virtual Environment.json b/.nova/Tasks/Virtual Environment.json new file mode 100644 index 0000000..f1240e8 --- /dev/null +++ b/.nova/Tasks/Virtual Environment.json @@ -0,0 +1,21 @@ +{ + "actions" : { + "run" : { + "postActions" : [ + { + "script" : "python3 main.py", + "type" : "runScript" + } + ] + } + }, + "extension" : { + "identifier" : "net.danwatson.Python", + "name" : "Python" + }, + "extensionTemplate" : "virtualenv", + "extensionValues" : { + "script" : "*Py\/main.py", + "workdir" : "." + } +} diff --git a/DockPhobiaPy/.DS_Store b/DockPhobiaPy/.DS_Store index e8b9eea77a8c9c3870450a598610fd71fd5e9ea8..f66cd179579bc968aa900beec930999b0185ce7f 100644 GIT binary patch delta 167 zcmZoMXfc=|#>CJ*u~2NHo+2j;0|Nsi1A_p=#3*A%mdQPgl5w50T!Dft3}pB`mF;Q%yo}w@Z0|Nsi1A_nqLt;+4VQ_MOZoyS*w%sOt_jKjwq(N&}nP*IQpu^p%n2$%vGCiY0i zrX_C%a#(;aNCmp24A~yT&2NtNKJJAqDWr= diff --git a/DockPhobiaPy/main.py b/DockPhobiaPy/main.py index 7b249cc..9e031e9 100644 --- a/DockPhobiaPy/main.py +++ b/DockPhobiaPy/main.py @@ -1,18 +1,19 @@ -from pynput.mouse import Button, Controller +from pynput.mouse import Controller import subprocess -import time import AppKit +import time import pdb +from memory_profiler import profile mouse = Controller() -#while True: - def getDockSide(): - # pdb.set_trace() script = "defaults read com.apple.Dock orientation" result = subprocess.run(["bash", "-c", script], capture_output=True,text=True) - return result.stdout + + formattedResult = result.stdout.strip() + return formattedResult + def moveDock(to): script = f""" @@ -43,7 +44,6 @@ def getScreenSize(): return [] screenSize = getScreenSize() -print(f"Screen size: {screenSize}") def getDockHeight(): screen = AppKit.NSScreen.mainScreen() @@ -53,67 +53,88 @@ def getDockHeight(): dockHeight = fullHeight - visibleHeight percentage = (dockHeight / fullHeight) - return percentage+0.05 # increase size + return percentage -screenSize = getScreenSize() - -print(getDockHeight()) print(getScreenSize()) -moveDock("bottom") -dockSide = "bottom" -dockHeight = getDockHeight() +# moveDock("bottom") +dockSide = getDockSide() +startedOutAt = dockSide print() -dockFromBottom = screenSize[1]-(screenSize[1]*dockHeight) +def calcDockFromBottom(): + # screenSize = getScreenSize() + dockHeight = getDockHeight() + return screenSize[1]-(screenSize[1]*dockHeight) + +dockFromBottom = calcDockFromBottom() print(dockFromBottom) -print() -dockFromLeft = screenSize[1]*dockHeight +def calcDockFromLeft(): + # screenSize = getScreenSize() + dockHeight = getDockHeight() + return screenSize[1]*dockHeight + +dockFromLeft = calcDockFromLeft() print(dockFromLeft) -print() -dockFromRight = screenSize[1]*dockHeight -dockFromRight = screenSize[0]-(screenSize[1]*dockHeight) +def calcDockFromRight(): + # screenSize = getScreenSize() + dockHeight = getDockHeight() + return screenSize[0]-(screenSize[1]*dockHeight) +dockFromRight = calcDockFromRight() print(dockFromRight) +@profile +def run_loop(): + global dockSide, dockFromBottom, dockFromLeft, dockFromRight, startedOutAt + while True: + # for i in range(0,100000): + if dockSide == "bottom": + if mouse.position[1] > dockFromBottom: + if mouse.position[0] < screenSize[0]/2: + moveDock("right") + dockSide = "right" + #if mouse is at bottom and is on the left + else: + moveDock("left") + dockSide = "left" + #mouse is at bottom but on the right of screen + # neverbeenside = False + elif dockSide == "left": + if mouse.position[0] < dockFromLeft: + if mouse.position[1] < screenSize[1]/2: + moveDock("bottom") + dockSide = "bottom" + #mouse is at left but top half + else: + moveDock("right") + dockSide = "right" + #mouse is at left but bottom half + elif dockSide == "right": + if mouse.position[0] > dockFromRight: + if mouse.position[1] < screenSize[1]/2: + moveDock("bottom") + dockSide = "bottom" + #mouse is at right but top half + else: + moveDock("left") + dockSide = "left" + #mouse is at right but bottom half + if startedOutAt == "": + continue + elif startedOutAt == "bottom" and dockSide != "bottom": + # started at bottom, dock is at side, recalc the actuation distance from sides + dockFromLeft = calcDockFromLeft() + dockFromRight = calcDockFromRight() + startedOutAt = "" + elif startedOutAt == "right" or startedOutAt == "left" and dockSide == "bottom": + #started on the side, now at bottom recalc the distance from bottom + dockFromBottom = calcDockFromBottom() + startedOutAt = "" + time.sleep(0.001) -while True: - # print(dockSide) - if dockSide == "bottom": - if mouse.position[1] > dockFromBottom: - if mouse.position[0] < screenSize[0]/2: - moveDock("right") - dockSide = "right" - #if mouse is at bottom and is on the left - else: - moveDock("left") - dockSide = "left" - #mouse is at bottom but on the right of screen - - elif dockSide == "left": - if mouse.position[0] < dockFromLeft: - if mouse.position[1] < screenSize[1]/2: - moveDock("bottom") - dockSide = "bottom" - #mouse is at left but top half - else: - moveDock("right") - dockSide = "right" - #mouse is at left but bottom half - - elif dockSide == "right": - if mouse.position[0] > dockFromRight: - if mouse.position[1] < screenSize[1]/2: - moveDock("bottom") - dockSide = "bottom" - #mouse is at right but top half - else: - moveDock("left") - dockSide = "left" - #mouse is at right but bottom half - -# time.sleep(0.01) +run_loop() diff --git a/DockPhobiaPy/requirements.txt b/DockPhobiaPy/requirements.txt index c9b7d36..624e28f 100644 --- a/DockPhobiaPy/requirements.txt +++ b/DockPhobiaPy/requirements.txt @@ -1,4 +1,7 @@ +debugpy==1.8.13 +memory-profiler==0.61.0 MouseInfo==0.1.3 +psutil==7.0.0 PyAutoGUI==0.9.54 PyGetWindow==0.0.9 PyMsgBox==1.0.9