Skip to content

Commit

Permalink
WIndow Orientation (#6)
Browse files Browse the repository at this point in the history
* Create python-tests.yml

* Update python-tests.yml

* Update python-tests.yml

* Update python-tests.yml

* Update python-tests.yml

* Update python-tests.yml

* center inital window, justify popups relative

* Update cmdcompass/gui/command_tag_operation.py

Co-authored-by: John Wang <[email protected]>

* Update cmdcompass/gui/command_tag_operation.py

Co-authored-by: John Wang <[email protected]>

---------

Co-authored-by: John Wang <[email protected]>
  • Loading branch information
DCRepublic and johnwangwyx authored Oct 26, 2024
1 parent a5466bc commit cb6fe07
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
10 changes: 10 additions & 0 deletions cmdcompass/gui/command_tag_operation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import customtkinter as ctk
from cmdcompass.models.tag import Tag
from CTkMessagebox import CTkMessagebox
from cmdcompass.utils.utils import getScreenSize


class TagOperation:
Expand All @@ -9,8 +10,17 @@ def __init__(self, master, data_manager):
self.data_manager = data_manager

def open_add_tag_window(self, command):
screenSize = getScreenSize()
add_tag_window = ctk.CTkToplevel(self.master)
add_tag_window.title("Add/Remove Tag for This Command")

add_tag_window_width = 450
add_tag_window_height = 200

x = (screenSize["SCREEN_WIDTH"]/2) - (add_tag_window_width/2) + screenSize["CENTER_OFFSET"]
y = (screenSize["SCREEN_HEIGHT"]/2) - (add_tag_window_height/2)

add_tag_window.geometry('%dx%d+%d+%d' % (add_tag_window_width, add_tag_window_height, x, y))

# Existing Tags Frame (Row 0)
existing_tags_frame = ctk.CTkFrame(add_tag_window)
Expand Down
11 changes: 11 additions & 0 deletions cmdcompass/gui/global_tag.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import customtkinter as ctk
from cmdcompass.models.tag import Tag
from CTkMessagebox import CTkMessagebox
from cmdcompass.utils.utils import getScreenSize

TAG_COLORS = ["Orange", "Cyan", "Azure", "Yellow", "Pink", "Green", "Red", "Purple", "Gray"]

Expand All @@ -9,6 +10,16 @@ class GlobalTagWindow(ctk.CTkToplevel):
def __init__(self, master, data_manager):
super().__init__(master)
self.title("Create New Tag")

screenSize = getScreenSize()
tag_window_height = 800
tag_window_width = 270

x = (screenSize["SCREEN_WIDTH"]*0.01)
y = (screenSize["SCREEN_HEIGHT"]/2) - (tag_window_height/2)

self.geometry('%dx%d+%d+%d' % (tag_window_width, tag_window_height, x, y))

self.data_manager = data_manager

# Main frame to hold everything
Expand Down
23 changes: 21 additions & 2 deletions cmdcompass/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from cmdcompass.gui.manpagebox import ManPageBox
from cmdcompass.utils.utils import load_ctk_image
from CTkToolTip import CTkToolTip
from cmdcompass.utils.utils import getScreenSize

from CTkMessagebox import CTkMessagebox
import platform
Expand All @@ -21,7 +22,8 @@

class GUIConfig:
WINDOW_TITLE = "cmdCompass"
WINDOW_GEOMETRY = "900x670"
WINDOW_WIDTH = 900
WINDOW_HEIGHT = 670
DEFAULT_APPEARANCE_MODE = "light"


Expand Down Expand Up @@ -66,7 +68,13 @@ def __init__(self):
def configure_main_window(self):
ctk.set_appearance_mode(GUIConfig.DEFAULT_APPEARANCE_MODE)
self.title(GUIConfig.WINDOW_TITLE)
self.geometry(GUIConfig.WINDOW_GEOMETRY)

screenSize = getScreenSize()

x = (screenSize["SCREEN_WIDTH"]/2) - (GUIConfig.WINDOW_WIDTH/2) + screenSize["CENTER_OFFSET"]
y = (screenSize["SCREEN_HEIGHT"]/2) - (GUIConfig.WINDOW_HEIGHT/2)

self.geometry('%dx%d+%d+%d' % (GUIConfig.WINDOW_WIDTH, GUIConfig.WINDOW_HEIGHT, x, y))

def create_left_and_right_penal(self):
# Create main frames
Expand Down Expand Up @@ -282,6 +290,17 @@ def on_add_collection_click(self):
text="Enter your new collection name",
title="Add New Collection",
)

dialog_window_width = 250
dialog_window_height = 150
screenSize = getScreenSize()

x = (screenSize["SCREEN_WIDTH"]/2) - (dialog_window_width/2) + screenSize["CENTER_OFFSET"]
y = (screenSize["SCREEN_HEIGHT"]/2) - (dialog_window_height/2)

dialog.geometry('%dx%d+%d+%d' % (dialog_window_width, dialog_window_height, x, y))


collection_name = dialog.get_input()
if collection_name:
# Check for duplicate collection name
Expand Down
15 changes: 15 additions & 0 deletions cmdcompass/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from pathlib import Path
import platform
from platformdirs import PlatformDirs
import customtkinter as ctk


APP_NAME = "CmdCompass"
IMG_DIR = "static"
Expand All @@ -27,6 +29,19 @@ def get_command_name(command_str):
raise ValueError(f"Unable to find the command name for {command_str}")


def getScreenSize():
root = ctk.CTk()
root.attributes("-alpha", 0)

screenSize = {
"SCREEN_WIDTH" : root.winfo_screenwidth(),
"SCREEN_HEIGHT" : root.winfo_screenheight(),
"CENTER_OFFSET" : 50
}
root.destroy()

return screenSize

def copy_resources(resource_name, source_root, dest_dir):
source_path = source_root / resource_name
dest_path = dest_dir / resource_name
Expand Down

0 comments on commit cb6fe07

Please sign in to comment.