From 09e18889b0605b4c0ded372ffa766bdb0c3cfb8c Mon Sep 17 00:00:00 2001 From: bharnden <32446120+bharnden@users.noreply.github.com> Date: Fri, 1 Nov 2019 18:14:36 -0700 Subject: [PATCH] start to hooks dialog and hook dialog create/edit --- coretk/coretk/coremenubar.py | 2 +- coretk/coretk/dialogs/hooks.py | 106 +++++++++++++++++++++++++++++++++ coretk/coretk/menuaction.py | 10 ++-- 3 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 coretk/coretk/dialogs/hooks.py diff --git a/coretk/coretk/coremenubar.py b/coretk/coretk/coremenubar.py index 7b3f2633..0751ee06 100644 --- a/coretk/coretk/coremenubar.py +++ b/coretk/coretk/coremenubar.py @@ -607,7 +607,7 @@ class CoreMenubar(object): label="Comments...", command=action.session_comments, underline=0 ) session_menu.add_command( - label="Hooks...", command=action.session_hooks, underline=0 + label="Hooks...", command=self.menu_action.session_hooks, underline=0 ) session_menu.add_command( label="Reset node positions", diff --git a/coretk/coretk/dialogs/hooks.py b/coretk/coretk/dialogs/hooks.py new file mode 100644 index 00000000..bdf96d33 --- /dev/null +++ b/coretk/coretk/dialogs/hooks.py @@ -0,0 +1,106 @@ +import tkinter as tk +from tkinter import ttk + +from core.api.grpc import core_pb2 +from coretk.dialogs.dialog import Dialog + + +class HookDialog(Dialog): + def __init__(self, master, app): + super().__init__(master, app, "Hook", modal=True) + self.name = tk.StringVar() + self.data = None + self.hook = None + self.draw() + + def draw(self): + self.columnconfigure(0, weight=1) + + # name and states + frame = tk.Frame(self) + frame.grid(row=0, sticky="ew", pady=2) + frame.columnconfigure(0, weight=2) + frame.columnconfigure(1, weight=7) + frame.columnconfigure(2, weight=1) + label = tk.Label(frame, text="Name") + label.grid(row=0, column=0, sticky="ew") + entry = tk.Entry(frame, textvariable=self.name) + entry.grid(row=0, column=1, sticky="ew") + combobox = ttk.Combobox(frame, values=("DEFINITION", "CONFIGURATION")) + combobox.grid(row=0, column=2, sticky="ew") + + # data + self.data = tk.Text(self) + self.data.grid(row=1, sticky="nsew", pady=2) + + # button row + frame = tk.Frame(self) + frame.grid(row=2, sticky="ew", pady=2) + for i in range(2): + frame.columnconfigure(i, weight=1) + button = tk.Button(frame, text="Save", command=lambda: self.save()) + button.grid(row=0, column=0, sticky="ew") + button = tk.Button(frame, text="Cancel", command=lambda: self.destroy()) + button.grid(row=0, column=1, sticky="ew") + + def set(self, hook): + self.hook = hook + self.name.set(hook.file) + self.data.delete(1.0, tk.END) + self.data.insert(tk.END, hook.data) + + def save(self): + data = self.data.get("1.0", tk.END).strip() + self.hook = core_pb2.Hook(file=self.name.get(), data=data) + self.destroy() + + +class HooksDialog(Dialog): + def __init__(self, master, app): + super().__init__(master, app, "Hooks", modal=True) + self.listbox = None + self.edit = None + self.delete = None + self.selected = None + self.hooks = {} + self.draw() + + def draw(self): + self.columnconfigure(0, weight=1) + self.listbox = tk.Listbox(self) + self.listbox.grid(row=0, sticky="ew") + self.listbox.bind("<>", self.select) + frame = tk.Frame(self) + frame.grid(row=1, sticky="ew") + for i in range(4): + frame.columnconfigure(i, weight=1) + button = tk.Button(frame, text="Create", command=self.click_create) + button.grid(row=0, column=0, sticky="ew") + self.edit = tk.Button( + frame, text="Edit", state=tk.DISABLED, command=self.click_edit + ) + self.edit.grid(row=0, column=1, sticky="ew") + self.delete = tk.Button(frame, text="Delete", state=tk.DISABLED) + self.delete.grid(row=0, column=2, sticky="ew") + button = tk.Button(frame, text="Cancel", command=lambda: self.destroy()) + button.grid(row=0, column=3, sticky="ew") + + def click_create(self): + dialog = HookDialog(self, self.app) + dialog.show() + hook = dialog.hook + if hook: + self.hooks[hook.file] = hook + self.listbox.insert(tk.END, hook.file) + + def click_edit(self): + hook = self.hooks[self.selected] + dialog = HookDialog(self, self.app) + dialog.set(hook) + dialog.show() + + def select(self, event): + self.edit.config(state=tk.NORMAL) + self.delete.config(state=tk.NORMAL) + index = self.listbox.curselection()[0] + self.selected = self.listbox.get(index) diff --git a/coretk/coretk/menuaction.py b/coretk/coretk/menuaction.py index bfbb5c5d..64caf8ae 100644 --- a/coretk/coretk/menuaction.py +++ b/coretk/coretk/menuaction.py @@ -8,6 +8,7 @@ from tkinter import filedialog, messagebox from core.api.grpc import core_pb2 from coretk.appdirs import XML_PATH +from coretk.dialogs.hooks import HooksDialog from coretk.dialogs.sessionoptions import SessionOptionsDialog from coretk.dialogs.sessions import SessionsDialog from coretk.setwallpaper import CanvasWallpaper @@ -299,10 +300,6 @@ def session_comments(): logging.debug("Click session comments") -def session_hooks(): - logging.debug("Click session hooks") - - def session_reset_node_positions(): logging.debug("Click session reset node positions") @@ -406,3 +403,8 @@ class MenuAction: logging.debug("Click session change sessions") dialog = SessionsDialog(self.app, self.app) dialog.show() + + def session_hooks(self): + logging.debug("Click session hooks") + dialog = HooksDialog(self.app, self.app) + dialog.show()