Skip to content

Commit

Permalink
feat: add profile dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
bit-dome committed Aug 3, 2023
1 parent 67f0120 commit 51f65b5
Show file tree
Hide file tree
Showing 25 changed files with 1,118 additions and 95 deletions.
Binary file added assets/images/add_drop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/add_prof.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/prof_drop_head.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/proj_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/proj_icon_blank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/rename.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/themes/google_theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"fg_color": ["gray95", "gray10"]
},
"CTkFrame": {
"corner_radius": 0,
"corner_radius": 8,
"border_width": 1,
"fg_color": ["white", "white"],
"top_fg_color": ["white" ,"white"],
Expand Down
2 changes: 1 addition & 1 deletion configs/default.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"default": "profile_1"}
{"default": "default"}
10 changes: 5 additions & 5 deletions configs/profile_1/cursor.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"tracking_vert_idxs": [
8
],
"spd_up": 40,
"spd_down": 40,
"spd_left": 40,
"spd_right": 40,
"pointer_smooth": 6,
"spd_up": 41,
"spd_down": 41,
"spd_left": 41,
"spd_right": 41,
"pointer_smooth": 15,
"shape_smooth": 10,
"tick_interval_ms": 16,
"hold_trigger_ms": 500,
Expand Down
10 changes: 5 additions & 5 deletions configs/profile_2/cursor.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"tracking_vert_idxs": [
8
],
"spd_up": 40,
"spd_down": 40,
"spd_left": 40,
"spd_right": 40,
"pointer_smooth": 6,
"spd_up": 42,
"spd_down": 42,
"spd_left": 42,
"spd_right": 42,
"pointer_smooth": 15,
"shape_smooth": 10,
"tick_interval_ms": 16,
"hold_trigger_ms": 500,
Expand Down
15 changes: 8 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
flatbuffers==2.0.0
sounddevice==0.4.6
matplotlib==3.7.1
opencv-contrib-python==4.7.0.72
psutil==5.9.4
pyautogui==0.9.53
customtkinter==5.1.2
PyDirectInput==1.0.4
pywin32==306
matplotlib
opencv-python
opencv-contrib-python
psutil
pyautogui
customtkinter
PyDirectInput
pywin32
mediapipe==0.9.3.0
3 changes: 2 additions & 1 deletion run_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@

import logging
import sys

import customtkinter

import src.gui as gui
from src.task_killer import TaskKiller
from src.pipeline import Pipeline
from src.task_killer import TaskKiller

FORMAT = "%(asctime)s %(levelname)s %(name)s: %(funcName)s: %(message)s"
logging.basicConfig(format=FORMAT,
Expand Down
8 changes: 8 additions & 0 deletions src/camera_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,16 @@ def read_camera_loop(self, stop_flag) -> None:

frame.flags.writeable = False
h, w, _ = frame.shape

# Trim image
if h != ConfigManager().config["fix_height"] or w != ConfigManager(
).config["fix_width"]:
target_width = int(h * 4 / 3)
if w > target_width:
trim_width = w - target_width
trim_left = trim_width // 2
trim_right = trim_width - trim_left
frame = frame[:, trim_left:-trim_right, :]
frame = cv2.resize(frame,
(ConfigManager().config["fix_width"],
ConfigManager().config["fix_height"]))
Expand Down
19 changes: 16 additions & 3 deletions src/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
import copy
import json
import logging
import tkinter as tk
import time
import shutil
import time
import tkinter as tk
from pathlib import Path

from src.singleton_meta import Singleton
from src.task_killer import TaskKiller

VERSION = "0.3.30"
VERSION = "0.3.33"

DEFAULT_JSON = Path("configs/default.json")
BACKUP_PROFILE = Path("configs/default")
Expand All @@ -46,6 +46,8 @@ def __init__(self):
self.curr_profile_name = tk.StringVar()
self.is_started = False

self.profiles = self.list_profile()

def start(self):
if not self.is_started:
logger.info("Start ConfigManager singleton")
Expand Down Expand Up @@ -75,18 +77,29 @@ def list_profile(self) -> list:
def remove_profile(self, profile_name):
logger.info(f"Remove profile {profile_name}")
shutil.rmtree(Path(DEFAULT_JSON.parent, profile_name))
self.profiles.remove(profile_name)
logger.info(f"Current profiles: {self.profiles}")

def add_profile(self):
# Random name base on local timestamp
new_profile_name = "profile_z" + str(hex(int(time.time() * 1000)))[2:]
logger.info(f"Add profile {new_profile_name}")
shutil.copytree(BACKUP_PROFILE,
Path(DEFAULT_JSON.parent, new_profile_name))
self.profiles.append(new_profile_name)
logger.info(f"Current profiles: {self.profiles}")

def rename_profile(self, old_profile_name, new_profile_name):
logger.info(f"Rename profile {old_profile_name} to {new_profile_name}")
shutil.move(Path(DEFAULT_JSON.parent, old_profile_name),
Path(DEFAULT_JSON.parent, new_profile_name))
self.profiles.remove(old_profile_name)
self.profiles.append(new_profile_name)

if self.curr_profile_name.get() == old_profile_name:
self.curr_profile_name.set(new_profile_name)



def load_profile(self, profile_name: str) -> list[bool, Path]:
profile_path = Path(DEFAULT_JSON.parent, profile_name)
Expand Down
7 changes: 4 additions & 3 deletions src/controllers/keybinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# limitations under the License.

import copy
import logging
import math
import time
import logging

import pydirectinput
import win32api
Expand Down Expand Up @@ -195,8 +195,9 @@ def act(self, blendshape_values) -> dict:
if mon_id is None:
return

pydirectinput.moveTo(self.monitors[mon_id]["center_x"],
self.monitors[mon_id]["center_y"])
pydirectinput.moveTo(
self.monitors[mon_id]["center_x"],
self.monitors[mon_id]["center_y"])
self.key_states[state_name] = True
elif (val < thres) and (self.key_states[state_name] is
True):
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/mouse_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import logging
import threading
import time
import pyautogui
import tkinter as tk

import numpy as np
import numpy.typing as npt
import pyautogui

import src.utils as utils
from src.accel_graph import SigmoidAccel
Expand Down Expand Up @@ -100,7 +100,7 @@ def main_loop(self) -> None:

if self.is_destroyed:
return

while not self.stop_flag.is_set():
if not self.is_active.get():
time.sleep(0.001)
Expand Down Expand Up @@ -132,7 +132,7 @@ def main_loop(self) -> None:
vel_y *= self.accel(vel_y)

# pydirectinput is not working here
pyautogui.move(xOffset=vel_x, yOffset=vel_y)
pyautogui.move(xOffset=vel_x, yOffset=vel_y)

time.sleep(ConfigManager().config["tick_interval_ms"] / 1000)

Expand Down
3 changes: 2 additions & 1 deletion src/gui/frames/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@

from .frame_cam_preview import *
from .frame_menu import *
from .frame_profile import *
from .frame_profile_editor import *
from .frame_profile_switcher import *
from .safe_disposable_frame import *
45 changes: 36 additions & 9 deletions src/gui/frames/frame_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@
import customtkinter
from PIL import Image

from src.config_manager import ConfigManager
from src.gui.frames.safe_disposable_frame import SafeDisposableFrame

LIGHT_BLUE = "#F9FBFE"
BTN_SIZE = 225, 48
PROF_DROP_SIZE = 220, 40


class FrameMenu(SafeDisposableFrame):

def __init__(self, master, master_callback: callable, **kwargs):
super().__init__(master, **kwargs)

self.grid_rowconfigure(11, weight=1)
self.grid_rowconfigure(6, weight=1)
self.grid_columnconfigure(0, weight=1)
self.grid_propagate(False)
self.configure(fg_color=LIGHT_BLUE)
Expand All @@ -38,8 +40,7 @@ def __init__(self, master, master_callback: callable, **kwargs):
self.menu_btn_images = {
"page_home": [
customtkinter.CTkImage(
Image.open("assets/images/menu_btn_home.png").resize(
BTN_SIZE, resample=Image.ANTIALIAS),
Image.open("assets/images/menu_btn_home.png"),
size=BTN_SIZE),
customtkinter.CTkImage(
Image.open("assets/images/menu_btn_home_selected.png"),
Expand Down Expand Up @@ -79,10 +80,35 @@ def __init__(self, master, master_callback: callable, **kwargs):
]
}

# Profile button
prof_drop = customtkinter.CTkImage(
Image.open("assets/images/prof_drop_head.png"), size=PROF_DROP_SIZE)
profile_btn = customtkinter.CTkLabel(
master=self,
textvariable=ConfigManager().curr_profile_name,
image=prof_drop,
height=42,
compound="center",
anchor="w",
cursor="hand2",
)
profile_btn.bind("<Button-1>",
partial(self.master_callback, "show_profile_switcher"))

profile_btn.grid(row=0,
column=0,
padx=35,
pady=10,
ipadx=0,
ipady=0,
sticky="nw",
columnspan=1,
rowspan=1)

self.btns = {}
self.btns = self.create_tab_btn(self.menu_btn_images)
self.btns = self.create_tab_btn(self.menu_btn_images, offset=1)

def create_tab_btn(self, btns: dict):
def create_tab_btn(self, btns: dict, offset):

out_dict = {}
for idx, (k, im_paths) in enumerate(btns.items()):
Expand All @@ -94,11 +120,12 @@ def create_tab_btn(self, btns: dict):
hover=False,
corner_radius=0,
text="",
command=partial(self.master_callback,
command="change_page",
args={"target": k}))
command=partial(
self.master_callback,
function_name="change_page",
args={"target": k}))

btn.grid(row=idx,
btn.grid(row=idx + offset,
column=0,
padx=(0, 0),
pady=0,
Expand Down
Loading

0 comments on commit 51f65b5

Please sign in to comment.