removed icon dialog, just use file chooser directly
This commit is contained in:
parent
f154733e2e
commit
eca92af588
4 changed files with 27 additions and 81 deletions
|
@ -3,11 +3,12 @@ import tkinter as tk
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
|
||||||
|
from coretk import nodeutils
|
||||||
from coretk.dialogs.dialog import Dialog
|
from coretk.dialogs.dialog import Dialog
|
||||||
from coretk.dialogs.icondialog import IconDialog
|
from coretk.images import Images
|
||||||
from coretk.nodeutils import NodeDraw
|
from coretk.nodeutils import NodeDraw
|
||||||
from coretk.themes import FRAME_PAD, PADX, PADY
|
from coretk.themes import FRAME_PAD, PADX, PADY
|
||||||
from coretk.widgets import CheckboxList, ListboxScroll
|
from coretk.widgets import CheckboxList, ListboxScroll, image_chooser
|
||||||
|
|
||||||
|
|
||||||
class ServicesSelectDialog(Dialog):
|
class ServicesSelectDialog(Dialog):
|
||||||
|
@ -170,11 +171,11 @@ class CustomNodesDialog(Dialog):
|
||||||
self.image_button.config(image="")
|
self.image_button.config(image="")
|
||||||
|
|
||||||
def click_icon(self):
|
def click_icon(self):
|
||||||
dialog = IconDialog(self, self.app, self.name.get(), self.image)
|
file_path = image_chooser(self)
|
||||||
dialog.show()
|
if file_path:
|
||||||
if dialog.image:
|
image = Images.create(file_path, nodeutils.ICON_SIZE)
|
||||||
self.image = dialog.image
|
self.image = image
|
||||||
self.image_file = dialog.file_path.get()
|
self.image_file = file_path
|
||||||
self.image_button.config(image=self.image)
|
self.image_button.config(image=self.image)
|
||||||
|
|
||||||
def click_services(self):
|
def click_services(self):
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
import tkinter as tk
|
|
||||||
from tkinter import filedialog, ttk
|
|
||||||
|
|
||||||
from coretk import nodeutils
|
|
||||||
from coretk.appconfig import ICONS_PATH
|
|
||||||
from coretk.dialogs.dialog import Dialog
|
|
||||||
from coretk.images import Images
|
|
||||||
from coretk.themes import PADX, PADY
|
|
||||||
|
|
||||||
|
|
||||||
class IconDialog(Dialog):
|
|
||||||
def __init__(self, master, app, name, image):
|
|
||||||
super().__init__(master, app, f"{name} Icon", modal=True)
|
|
||||||
self.file_path = tk.StringVar()
|
|
||||||
self.image_label = None
|
|
||||||
self.image = image
|
|
||||||
self.draw()
|
|
||||||
|
|
||||||
def draw(self):
|
|
||||||
self.top.columnconfigure(0, weight=1)
|
|
||||||
|
|
||||||
# row one
|
|
||||||
frame = ttk.Frame(self.top)
|
|
||||||
frame.grid(pady=PADY, sticky="ew")
|
|
||||||
frame.columnconfigure(0, weight=1)
|
|
||||||
frame.columnconfigure(1, weight=3)
|
|
||||||
label = ttk.Label(frame, text="Image")
|
|
||||||
label.grid(row=0, column=0, sticky="ew", padx=PADX)
|
|
||||||
entry = ttk.Entry(frame, textvariable=self.file_path)
|
|
||||||
entry.grid(row=0, column=1, sticky="ew", padx=PADX)
|
|
||||||
button = ttk.Button(frame, text="...", command=self.click_file)
|
|
||||||
button.grid(row=0, column=2)
|
|
||||||
|
|
||||||
# row two
|
|
||||||
self.image_label = ttk.Label(self.top, image=self.image, anchor=tk.CENTER)
|
|
||||||
self.image_label.grid(pady=PADY, sticky="ew")
|
|
||||||
|
|
||||||
# spacer
|
|
||||||
self.draw_spacer()
|
|
||||||
|
|
||||||
# row three
|
|
||||||
frame = ttk.Frame(self.top)
|
|
||||||
frame.grid(sticky="ew")
|
|
||||||
frame.columnconfigure(0, weight=1)
|
|
||||||
frame.columnconfigure(1, weight=1)
|
|
||||||
button = ttk.Button(frame, text="Apply", command=self.destroy)
|
|
||||||
button.grid(row=0, column=0, sticky="ew", padx=PADX)
|
|
||||||
|
|
||||||
button = ttk.Button(frame, text="Cancel", command=self.click_cancel)
|
|
||||||
button.grid(row=0, column=1, sticky="ew")
|
|
||||||
|
|
||||||
def click_file(self):
|
|
||||||
file_path = filedialog.askopenfilename(
|
|
||||||
initialdir=str(ICONS_PATH),
|
|
||||||
title="Open",
|
|
||||||
filetypes=(
|
|
||||||
("images", "*.gif *.jpg *.png *.bmp *pcx *.tga ..."),
|
|
||||||
("All Files", "*"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
if file_path:
|
|
||||||
self.image = Images.create(file_path, nodeutils.ICON_SIZE)
|
|
||||||
self.image_label.config(image=self.image)
|
|
||||||
self.file_path.set(file_path)
|
|
||||||
|
|
||||||
def click_cancel(self):
|
|
||||||
self.image = None
|
|
||||||
self.destroy()
|
|
|
@ -3,12 +3,13 @@ import tkinter as tk
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
|
||||||
|
from coretk import nodeutils
|
||||||
from coretk.dialogs.dialog import Dialog
|
from coretk.dialogs.dialog import Dialog
|
||||||
from coretk.dialogs.icondialog import IconDialog
|
|
||||||
from coretk.dialogs.nodeservice import NodeService
|
from coretk.dialogs.nodeservice import NodeService
|
||||||
|
from coretk.images import Images
|
||||||
from coretk.nodeutils import NodeUtils
|
from coretk.nodeutils import NodeUtils
|
||||||
from coretk.themes import FRAME_PAD, PADX, PADY
|
from coretk.themes import FRAME_PAD, PADX, PADY
|
||||||
from coretk.widgets import FrameScroll
|
from coretk.widgets import FrameScroll, image_chooser
|
||||||
|
|
||||||
|
|
||||||
def mac_auto(is_auto, entry):
|
def mac_auto(is_auto, entry):
|
||||||
|
@ -196,10 +197,9 @@ class NodeConfigDialog(Dialog):
|
||||||
dialog.show()
|
dialog.show()
|
||||||
|
|
||||||
def click_icon(self):
|
def click_icon(self):
|
||||||
dialog = IconDialog(self, self.app, self.node.name, self.canvas_node.image)
|
file_path = image_chooser(self)
|
||||||
dialog.show()
|
if file_path:
|
||||||
if dialog.image:
|
self.image = Images.create(file_path, nodeutils.ICON_SIZE)
|
||||||
self.image = dialog.image
|
|
||||||
self.image_button.config(image=self.image)
|
self.image_button.config(image=self.image)
|
||||||
|
|
||||||
def config_apply(self):
|
def config_apply(self):
|
||||||
|
|
|
@ -5,6 +5,7 @@ from tkinter import filedialog, font, ttk
|
||||||
from tkinter.scrolledtext import ScrolledText
|
from tkinter.scrolledtext import ScrolledText
|
||||||
|
|
||||||
from core.api.grpc import core_pb2
|
from core.api.grpc import core_pb2
|
||||||
|
from coretk.appconfig import ICONS_PATH
|
||||||
from coretk.themes import FRAME_PAD, PADX, PADY
|
from coretk.themes import FRAME_PAD, PADX, PADY
|
||||||
|
|
||||||
INT_TYPES = {
|
INT_TYPES = {
|
||||||
|
@ -229,3 +230,15 @@ class Spinbox(ttk.Entry):
|
||||||
|
|
||||||
def set(self, value):
|
def set(self, value):
|
||||||
self.tk.call(self._w, "set", value)
|
self.tk.call(self._w, "set", value)
|
||||||
|
|
||||||
|
|
||||||
|
def image_chooser(parent):
|
||||||
|
return filedialog.askopenfilename(
|
||||||
|
parent=parent,
|
||||||
|
initialdir=str(ICONS_PATH),
|
||||||
|
title="Select Icon",
|
||||||
|
filetypes=(
|
||||||
|
("images", "*.gif *.jpg *.png *.bmp *pcx *.tga ..."),
|
||||||
|
("All Files", "*"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue