From 65faa682a723832ef8083ccff078bbd4506d7db3 Mon Sep 17 00:00:00 2001 From: Tumppi066 <83072683+Tumppi066@users.noreply.github.com> Date: Sat, 24 Feb 2024 15:35:44 +0200 Subject: [PATCH] UI fixed and changes --- blog/V1.10.Minor.md | 5 +++ changelog.txt | 4 +- plugins/PluginManager/main.py | 10 ++--- src/mainUI.py | 69 ++++++++++++++++++++++++++++++++--- version.txt | 2 +- 5 files changed, 77 insertions(+), 13 deletions(-) diff --git a/blog/V1.10.Minor.md b/blog/V1.10.Minor.md index 3f06e969a..8f0fd3a5e 100644 --- a/blog/V1.10.Minor.md +++ b/blog/V1.10.Minor.md @@ -16,6 +16,11 @@ title: Version 1.10 > Minor This changelog will contain all changes from 1.10.0 onwards before the next major version. !!! +==- Version 1.10.27 +Fix UIs and PluginFrames not correctly resetting. This manifested as weird UI bugs after a reload. +Added a favorites bar. +Slightly tweaked the plugin manager to make it fit in the frame correctly. +[!badge variant="dark" text="Tumppi066"] [!badge variant="ghost" text="Main UI"] [!badge variant="ghost" text="Plugin Manager"] ==- Version 1.10.26 The app will no longer hang when the server is not available. [!badge variant="dark" text="Tumppi066"] [!badge variant="ghost" text="App Backend"] diff --git a/changelog.txt b/changelog.txt index f2c65f24f..f6ce590da 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1 +1,3 @@ -The app will no longer hang when the server is not available. \ No newline at end of file +Fix UIs and PluginFrames not correctly resetting. This manifested as weird UI bugs after a reload. +Added a favorites bar. +Slightly tweaked the plugin manager to make it fit in the frame correctly. \ No newline at end of file diff --git a/plugins/PluginManager/main.py b/plugins/PluginManager/main.py index 65b533364..a2bfb490d 100644 --- a/plugins/PluginManager/main.py +++ b/plugins/PluginManager/main.py @@ -57,7 +57,7 @@ def __init__(self, master) -> None: self.lastTheme = settings.GetSettings("User Interface", "Theme") self.lastPlugin = 0 self.lastList = 0 - resizeWindow(1220, 700) + resizeWindow(1220, 715) self.page0() self.selectedPlugin(self.plugins[0]) self.keybindTimer = time.time() @@ -68,7 +68,7 @@ def destroy(self): del self def tabFocused(self): - resizeWindow(1220, 700) + resizeWindow(1220, 715) def page0(self): @@ -91,17 +91,17 @@ def page0(self): self.screenCaptureVariable = tk.StringVar() self.screenCaptureVariable.set([helpers.ConvertCapitalizationToSpaces(p.PluginInfo.name) for p in self.plugins if p.PluginInfo.exclusive == "ScreenCapture"]) - self.pluginList = tk.Listbox(self.root, width=20, height=31, listvariable=self.listVariable, font=("Roboto", 12), selectmode="single", activestyle="none", justify="center") + self.pluginList = tk.Listbox(self.root, width=20, height=30, listvariable=self.listVariable, font=("Roboto", 12), selectmode="single", activestyle="none", justify="center") self.pluginList.grid(row=2, column=0, padx=10, pady=2) # Bind double click self.pluginList.bind('', lambda x: self.switchPluginState(self.pluginList.curselection()[0], self.pluginList)) - self.laneDetectionList = tk.Listbox(self.root, width=20, height=31, listvariable=self.laneDetectionVariable, font=("Roboto", 12), selectmode="single", activestyle="none", justify="center") + self.laneDetectionList = tk.Listbox(self.root, width=20, height=30, listvariable=self.laneDetectionVariable, font=("Roboto", 12), selectmode="single", activestyle="none", justify="center") self.laneDetectionList.grid(row=2, column=1, padx=10, pady=2) # Bind double click self.laneDetectionList.bind('', lambda x: self.switchPluginState(self.laneDetectionList.curselection()[0], self.laneDetectionList)) - self.screenCaptureList = tk.Listbox(self.root, width=20, height=31, listvariable=self.screenCaptureVariable, font=("Roboto", 12), selectmode="single", activestyle="none", justify="center") + self.screenCaptureList = tk.Listbox(self.root, width=20, height=30, listvariable=self.screenCaptureVariable, font=("Roboto", 12), selectmode="single", activestyle="none", justify="center") self.screenCaptureList.grid(row=2, column=2, padx=10, pady=2) # Bind double click self.screenCaptureList.bind('', lambda x: self.switchPluginState(self.screenCaptureList.curselection()[0], self.screenCaptureList)) diff --git a/src/mainUI.py b/src/mainUI.py index 2b717a6ad..8e2e65689 100644 --- a/src/mainUI.py +++ b/src/mainUI.py @@ -123,11 +123,13 @@ def switchSelectedPlugin(pluginName:str): if pluginName.split(".")[1] in notebookNames: pluginNotebook.select(notebookNames.index(pluginName.split(".")[1])) ui = UIs[pluginNotebook.index(pluginNotebook.select())] + plugin = __import__(pluginName, fromlist=["UI", "PluginInfo"]) return else: if pluginName.split(".")[1] + "." + pluginName.split(".")[2] in notebookNames: pluginNotebook.select(notebookNames.index(pluginName.split(".")[1] + "." + pluginName.split(".")[2])) ui = UIs[pluginNotebook.index(pluginNotebook.select())] + plugin = __import__(pluginName, fromlist=["UI", "PluginInfo"]) return plugin = __import__(pluginName, fromlist=["UI", "PluginInfo"]) @@ -181,6 +183,22 @@ def quit(): root.destroy() del root +def addCurrentToFavorites(): + """Will add (or remove) the currently open tab from the favorites.""" + try: + tabName = plugin.PluginInfo.name + fullPath = f"plugins.{tabName}.main" + # Check if the tab is already in the favorites + favorites = settings.GetSettings("User Interface", "Favorites", value=["plugins.MainMenu.main"]) + if fullPath in favorites: + settings.RemoveFromList("User Interface", "Favorites", fullPath) + else: + settings.AddToList("User Interface", "Favorites", fullPath, exclusive=True) + + variables.RELOAD = True + except: + print("Failed to add current tab to favorites") + def drawButtons(refresh:bool=False): """Will draw the buttons on the left menu. @@ -195,6 +213,9 @@ def drawButtons(refresh:bool=False): for child in buttonFrame.winfo_children(): child.destroy() + for child in customButtonFrame.winfo_children(): + child.destroy() + enableButton = helpers.MakeButton(buttonFrame, "Enable", lambda: (variables.ToggleEnable(), enableButton.config(text=("Disable" if variables.ENABLELOOP else "Enable"))), 0, 0, width=11, padx=9, style="Accent.TButton") helpers.MakeButton(buttonFrame, "Panels", lambda: switchSelectedPlugin("plugins.PanelManager.main"), 1, 0, width=11, padx=9) helpers.MakeButton(buttonFrame, "Plugins", lambda: switchSelectedPlugin("plugins.PluginManager.main"), 2, 0, width=11, padx=9) @@ -206,6 +227,16 @@ def drawButtons(refresh:bool=False): import webbrowser helpers.MakeButton(buttonFrame, "Discord", lambda: webbrowser.open("https://discord.gg/DpJpkNpqwD"), 8, 0, width=11, padx=9, style="Accent.TButton", translate=False) + # Draw the favorites + helpers.MakeButton(customButtonFrame, "Add/Remove", lambda: addCurrentToFavorites(), 0, 0, width=11, padx=9, autoplace=True, style="Accent.TButton") + favorites = settings.GetSettings("User Interface", "Favorites", value=["plugins.MainMenu.main"]) + for favorite in favorites: + name = favorite.split(".")[1] + name = helpers.ConvertCapitalizationToSpaces(name) + if len(name) > 11: + name = name[:10] + "..." + helpers.MakeButton(customButtonFrame, name, lambda: switchSelectedPlugin(favorite), 0, 0, width=11, padx=9, autoplace=True) + prevFrame = 100 def update(data:dict): @@ -271,10 +302,13 @@ def resizeWindow(newWidth:int, newHeight:int): # Offsets for the new tabs newHeight += 20 newWidth += 40 + # Offset for the new favorites screen + newWidth += 150 root.geometry(f"{newWidth}x{newHeight}") pluginNotebook.config(width=newWidth, height=newHeight-20) buttonFrame.config(height=newHeight-20) + customButtonFrame.config(height=newHeight-20) root.update() def changeTheme(): @@ -326,6 +360,7 @@ def CreateRoot(): """ global root global buttonFrame + global customButtonFrame global pluginFrames global UIs global pluginNotebook @@ -355,14 +390,14 @@ def CreateRoot(): # the argument is the awareness level, which can be 0, 1 or 2: # for 1-to-1 pixel control I seem to need it to be non-zero (I'm using level 2) - try: - root.destroy() - except: - pass width = 800 height = 600 + try: + root.destroy() + except: + pass root = tk.Tk() UpdateTitle() @@ -420,13 +455,31 @@ def CreateRoot(): if showFps: fpsLabel = ttk.Label(root, textvariable=fps, font=("Roboto", 8)).pack(side="bottom", anchor="s", padx=10, pady=0) - buttonFrame = ttk.LabelFrame(root, text="Lane Assist", width=width-675, height=height-20) - + # Button Frame + try: + buttonFrame.destroy() + except: + pass + buttonFrame = ttk.LabelFrame(root, text="Lane Assist", width=width-675, height=height) buttonFrame.pack_propagate(0) buttonFrame.grid_propagate(0) buttonFrame.pack(side="left", anchor="n", padx=10, pady=10) + + # Create the custom button frame on the right side of the window + try: + customButtonFrame.destroy() + except: + pass + customButtonFrame = ttk.LabelFrame(root, text="Favorites", width=width-675, height=height) + customButtonFrame.pack_propagate(0) + customButtonFrame.grid_propagate(0) + customButtonFrame.pack(side="right", anchor="n", padx=10, pady=10) # Create the plugin notebook + try: + pluginNotebook.destroy() + except: + pass pluginNotebook = ttk.Notebook(root, width=width, height=height-20) pluginNotebook.pack_propagate(0) pluginNotebook.grid_propagate(0) @@ -436,6 +489,10 @@ def CreateRoot(): # Make a callback for selecting another tab pluginNotebook.bind("<>", lambda e: selectedOtherTab()) + # Reset the pluginFrames and UIs + pluginFrames = [] + UIs = [] + # Bind middleclick on a tab to close it closeMMB = settings.GetSettings("User Interface", "CloseTabMMB") if closeMMB == None: diff --git a/version.txt b/version.txt index 23aa90704..7fa69eb07 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.10.26 \ No newline at end of file +1.10.27 \ No newline at end of file