From 4ca9ab910e40c46a724f654944f3c549e8e8b253 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Mon, 9 Dec 2019 13:05:07 -0800 Subject: [PATCH] added spinbox missing from 3.6, added spinbox theme, updated config gen to display a file picker for labels with file in it --- coretk/coretk/dialogs/dialog.py | 1 + coretk/coretk/themes.py | 8 ++++++++ coretk/coretk/widgets.py | 30 +++++++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/coretk/coretk/dialogs/dialog.py b/coretk/coretk/dialogs/dialog.py index 29362960..d814a47c 100644 --- a/coretk/coretk/dialogs/dialog.py +++ b/coretk/coretk/dialogs/dialog.py @@ -9,6 +9,7 @@ DIALOG_PAD = 5 class Dialog(tk.Toplevel): def __init__(self, master, app, title, modal=False): super().__init__(master) + self.geometry("800x600") self.withdraw() self.app = app self.modal = modal diff --git a/coretk/coretk/themes.py b/coretk/coretk/themes.py index ad91276a..b80caf87 100644 --- a/coretk/coretk/themes.py +++ b/coretk/coretk/themes.py @@ -88,6 +88,14 @@ def load(style): }, "map": {"fieldbackground": [("disabled", Colors.frame)]}, }, + "TSpinbox": { + "configure": { + "fieldbackground": Colors.white, + "foreground": Colors.black, + "padding": (2, 0), + }, + "map": {"fieldbackground": [("disabled", Colors.frame)]}, + }, "TCombobox": { "configure": { "fieldbackground": Colors.white, diff --git a/coretk/coretk/widgets.py b/coretk/coretk/widgets.py index 760846a3..486370e0 100644 --- a/coretk/coretk/widgets.py +++ b/coretk/coretk/widgets.py @@ -1,7 +1,7 @@ import logging import tkinter as tk from functools import partial -from tkinter import font, ttk +from tkinter import filedialog, font, ttk from tkinter.scrolledtext import ScrolledText from core.api.grpc import core_pb2 @@ -19,6 +19,12 @@ INT_TYPES = { PAD = 5 +def file_button_click(value): + file_path = filedialog.askopenfilename(title="Select File") + if file_path: + value.set(file_path) + + class FrameScroll(ttk.LabelFrame): def __init__(self, master, app, _cls=ttk.Frame, **kw): super().__init__(master, **kw) @@ -100,8 +106,18 @@ class ConfigFrame(FrameScroll): combobox.grid(row=index, column=1, sticky="ew", pady=pady) elif option.type == core_pb2.ConfigOptionType.STRING: value.set(option.value) - entry = ttk.Entry(frame, textvariable=value) - entry.grid(row=index, column=1, sticky="ew", pady=pady) + if "file" in option.label: + file_frame = ttk.Frame(frame) + file_frame.grid(row=index, column=1, sticky="ew", pady=pady) + file_frame.columnconfigure(0, weight=1) + entry = ttk.Entry(file_frame, textvariable=value) + entry.grid(row=0, column=0, sticky="ew", padx=padx) + func = partial(file_button_click, value) + button = ttk.Button(file_frame, text="...", command=func) + button.grid(row=0, column=1) + else: + entry = ttk.Entry(frame, textvariable=value) + entry.grid(row=index, column=1, sticky="ew", pady=pady) elif option.type in INT_TYPES: value.set(option.value) entry = ttk.Entry(frame, textvariable=value) @@ -179,3 +195,11 @@ class CodeText(ScrolledText): relief=tk.FLAT, **kwargs ) + + +class Spinbox(ttk.Entry): + def __init__(self, master=None, **kwargs): + super().__init__(master, "ttk::spinbox", **kwargs) + + def set(self, value): + self.tk.call(self._w, "set", value)