Skip to content

Commit

Permalink
v1.2.6 (check changelog)
Browse files Browse the repository at this point in the history
  • Loading branch information
supercam19 committed Oct 20, 2024
1 parent df2b1f9 commit a54df19
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 122 deletions.
16 changes: 9 additions & 7 deletions ProfileManager/SuperWidgets/HelpMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
class HelpMenu:
def __init__(self, root):
self.menu = ctk.CTkToplevel(root)
self.menu.focus()
self.menu.after(10, self.display)
self.menu.geometry("+%d+%d" % (root.winfo_x() + 100, root.winfo_y() + 100))
self.menu.title("Help Menu")
self.menu.resizable(False, False)
Expand All @@ -14,10 +16,10 @@ def __init__(self, root):
self.stack[i].pack(side=ctk.TOP, fill=ctk.BOTH, expand=ctk.YES)

self.stack[0].configure(bg_color='gray24', fg_color='gray24')
self.title = ctk.CTkLabel(self.stack[0], text="SMAPI Profile Manager Help", text_font=("Arial", 20), fg_color="gray24", height=40, anchor='center')
self.title = ctk.CTkLabel(self.stack[0], text="SMAPI Profile Manager Help", font=("Arial", 20), fg_color="gray24", height=40, anchor='center')
self.title.pack(pady=(10, 0), side=ctk.LEFT, fill=ctk.X, expand=ctk.YES)
self.stack[1].configure(bg_color='gray24', fg_color='gray24')
self.seperator = ctk.CTkLabel(self.stack[1], text="\U000023AF"*28, text_font=("Arial", 20), fg_color='gray24', height=5)
self.seperator = ctk.CTkLabel(self.stack[1], text="\U000023AF"*28, font=("Arial", 20), fg_color='gray24', height=5)
self.seperator.pack(side=ctk.LEFT)

self.help_frameL = ctk.CTkFrame(self.stack[2], bg_color='gray20')
Expand All @@ -39,16 +41,16 @@ def __init__(self, root):
self.stack[3].configure(bg_color='gray24', fg_color='gray24')
self.ok_button = ctk.CTkButton(self.stack[3], text="OK", command=self.visit, fg_color='gray24', bg_color='gray24', hover_color='gray18')
self.ok_button.pack(side=ctk.RIGHT, fill='both', expand=True)
self.ok_button.bind("<Enter>", lambda event: self.ok_button.configure(bg_color='gray18'))
self.ok_button.bind("<Leave>", lambda event: self.ok_button.configure(bg_color='gray24'))
self.cancel_button = ctk.CTkButton(self.stack[3], text="Cancel", command=self.menu.destroy, fg_color='gray24', bg_color='gray24', hover_color='gray18')
self.cancel_button.pack(side=ctk.RIGHT, fill='both', expand=True)
self.cancel_button.bind("<Enter>", lambda event: self.cancel_button.configure(bg_color='gray18'))
self.cancel_button.bind("<Leave>", lambda event: self.cancel_button.configure(bg_color='gray24'))

def visit(self):
links = ('https://github.com/supercam19/SMAPI-Profile-Manager',
'https://github.com/supercam19/SMAPI-Profile-Manager#how-to-use',
'https://github.com/supercam19/SMAPI-Profile-Manager/issues/new',
'https://github.com/supercam19/SMAPI-Profile-Manager/pulls')
webbrowser.open(links[self.help_selection.get()])
webbrowser.open(links[self.help_selection.get()])

def display(self):
self.menu.deiconify()
self.menu.focus()
8 changes: 7 additions & 1 deletion ProfileManager/SuperWidgets/ProfileEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def __init__(self, root, profile_data, callback):
self.properties_frame = None
self.protected_values = ('created', 'last_launched', 'mods') # Do not allow user to modify these
self.editor = ctk.CTkToplevel(root, fg_color="gray18")
self.editor.withdraw()
self.editor.after(10, self.display)
self.editor.title("Profile Editor - " + self.prof_info['name'])
self.editor.geometry("+%d+%d" % (root.winfo_x() + 100, root.winfo_y() + 100))

Expand Down Expand Up @@ -77,7 +79,7 @@ def editable_true_false(self, title):
# Creates a frame with a label and a checkbox
frame = Frame(self.editor, width=300, height=40, fg_color='gray18')
frame.pack_propagate(False)
frame.pack()
frame.pack(expand=True, fill='both')
label = ctk.CTkLabel(frame, text=title, width=50, anchor='w')
label.pack(side="left", padx=10)
check = ctk.CTkCheckBox(frame, text='')
Expand Down Expand Up @@ -138,3 +140,7 @@ def browse_path(self):
self.ePathEntry.insert(0, new_path)
# Stop the profile editor from sticking to above other windows (still on top, just not stuck)
self.editor.attributes('-topmost', False)

def display(self):
self.editor.deiconify()
self.editor.focus()
4 changes: 2 additions & 2 deletions ProfileManager/SuperWidgets/SuperWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ def __init__(self, parent, vfx=False, **kwargs):
class Button(ctk.CTkButton):
# Define a custom button that changes colour or image on hover
def __init__(self, parent, type='text', hover_image=None, **kwargs):
super().__init__(parent, **kwargs)
super().__init__(parent, hover=False, **kwargs)
self.text_color_default = kwargs.get("text_color", "white")
self.configure(text_color=self.text_color_default)
self.image_default = kwargs.get("image", None)
self.configure(image=self.image)
self.configure(image=self.image_default)
self.state = kwargs.get("state", "normal")
self.configure(state=self.state)
self.text = kwargs.get("text", "")
Expand Down
92 changes: 34 additions & 58 deletions ProfileManager/SuperWidgets/Tooltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,46 @@
import customtkinter as ctk


class Tooltip:
# Mouse hover tooltips that can be attached to widgets
def __init__(self, widget, text):
self.wait_time = 500 # milliseconds
self.wrap_length = 180
class Tooltip(ctk.CTkToplevel):
def __init__(self, widget, text, follow_mouse=True):
self.widget = widget
super().__init__(self.widget)
self.withdraw()
self.text = text
self.widget.bind("<Enter>", self.schedule, add="+")
self.widget.bind("<Leave>", lambda e: self.widget.after(5, self.leave), add="+")
self.widget.bind("<ButtonPress>", self.leave, add="+")
self.id = None
self.tw = None
self.over_tooltip = False
self.widget.bind("<Enter>", self.show_tip, add="+")
self.widget.bind("<Leave>", self.hide_tip, add="+")
self.widget.bind("<ButtonPress>", self.hide_tip, add="+")

def leave(self, event=None):
if not self.over_tooltip:
self.unschedule()
self.hide_tip()

def schedule(self, event=None):
self.id = self.widget.after(self.wait_time, self.show_tip)
x, y, cx, cy = self.widget.bbox("insert")
x += self.widget.winfo_pointerx() + 10
y += self.widget.winfo_pointery() + 10
self.wm_attributes("-toolwindow", True)
# Leaves only the label and removes the topbar of the window
self.wm_overrideredirect(True)
self.wm_geometry(f'+{x}+{y}')
self.wm_attributes("-transparentcolor", "#e3e3e3") if ctk.get_appearance_mode() == "Light" else self.wm_attributes("-transparentcolor", "#555555")
self.configure(bg=("#bdbdbd", "#555555"))
self.label = ctk.CTkLabel(self, text=self.text, corner_radius=10, bg_color=("#e3e3e3", '#555555'), fg_color=("#e4e4e4", '#545454'),
width=1)
self.label.pack()

def unschedule(self):
# Unschedule scheduled popups
id = self.id
self.id = None
if id:
self.widget.after_cancel(id)
if follow_mouse:
self.widget.bind("<Motion>", self.move_tip, add="+")

def tt_enter(self, event=None):
if not self.over_tooltip:
self.over_tooltip = True
def show_tip(self, event=None):
self.wm_geometry(f'+{self.widget.winfo_pointerx() + 10}+{self.widget.winfo_pointery() + 10}')
self.deiconify()

def tt_leave(self, event=None):
if self.over_tooltip:
self.over_tooltip = False
self.leave()
def hide_tip(self, event=None):
self.withdraw()

def show_tip(self, event=None):
# Get the position the tooltip needs to appear at
x = y = 0
def move_tip(self, event):
x, y, cx, cy = self.widget.bbox("insert")
x += self.widget.winfo_pointerx() + 1
y += self.widget.winfo_pointery() + 1
self.tw = ctk.CTkToplevel(self.widget)
self.tw.withdraw()
self.tw.wm_attributes("-toolwindow", True)
# Leaves only the label and removes the topbar of the window
self.tw.wm_overrideredirect(True)
self.tw.wm_geometry(f'+{x}+{y}')
"""
The background colour and the foreground colour need to be really similar because the label widget
has un-removable anti-aliasing that makes the colors blend -> there will be different colour pixels
on the edge of the label.
"""
self.tw.wm_attributes('-transparentcolor', '#555555')
self.tw.configure(bg="#555555")
label = ctk.CTkLabel(self.tw, text=self.text, corner_radius=10, bg_color='#555555', fg_color='#545454', width=1)
label.pack()
label.bind("<Enter>", self.tt_enter, add="+")
label.bind("<Leave>", self.tt_leave, add="+")
self.tw.geometry = label.winfo_width() + 1, label.winfo_height() + 1
self.tw.deiconify()
x = self.widget.winfo_pointerx() + 10
y = self.widget.winfo_pointery() + 10
self.wm_geometry(f'+{x}+{y}')

def set_text(self, text):
self.text = text
self.label.config(text=self.text)

def hide_tip(self):
self.unschedule()
if self.tw: self.tw.withdraw()
Loading

0 comments on commit a54df19

Please sign in to comment.