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 tkinter import ttk
|
||||
|
||||
from coretk import nodeutils
|
||||
from coretk.dialogs.dialog import Dialog
|
||||
from coretk.dialogs.icondialog import IconDialog
|
||||
from coretk.images import Images
|
||||
from coretk.nodeutils import NodeDraw
|
||||
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):
|
||||
|
@ -170,11 +171,11 @@ class CustomNodesDialog(Dialog):
|
|||
self.image_button.config(image="")
|
||||
|
||||
def click_icon(self):
|
||||
dialog = IconDialog(self, self.app, self.name.get(), self.image)
|
||||
dialog.show()
|
||||
if dialog.image:
|
||||
self.image = dialog.image
|
||||
self.image_file = dialog.file_path.get()
|
||||
file_path = image_chooser(self)
|
||||
if file_path:
|
||||
image = Images.create(file_path, nodeutils.ICON_SIZE)
|
||||
self.image = image
|
||||
self.image_file = file_path
|
||||
self.image_button.config(image=self.image)
|
||||
|
||||
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 tkinter import ttk
|
||||
|
||||
from coretk import nodeutils
|
||||
from coretk.dialogs.dialog import Dialog
|
||||
from coretk.dialogs.icondialog import IconDialog
|
||||
from coretk.dialogs.nodeservice import NodeService
|
||||
from coretk.images import Images
|
||||
from coretk.nodeutils import NodeUtils
|
||||
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):
|
||||
|
@ -196,10 +197,9 @@ class NodeConfigDialog(Dialog):
|
|||
dialog.show()
|
||||
|
||||
def click_icon(self):
|
||||
dialog = IconDialog(self, self.app, self.node.name, self.canvas_node.image)
|
||||
dialog.show()
|
||||
if dialog.image:
|
||||
self.image = dialog.image
|
||||
file_path = image_chooser(self)
|
||||
if file_path:
|
||||
self.image = Images.create(file_path, nodeutils.ICON_SIZE)
|
||||
self.image_button.config(image=self.image)
|
||||
|
||||
def config_apply(self):
|
||||
|
|
|
@ -5,6 +5,7 @@ from tkinter import filedialog, font, ttk
|
|||
from tkinter.scrolledtext import ScrolledText
|
||||
|
||||
from core.api.grpc import core_pb2
|
||||
from coretk.appconfig import ICONS_PATH
|
||||
from coretk.themes import FRAME_PAD, PADX, PADY
|
||||
|
||||
INT_TYPES = {
|
||||
|
@ -229,3 +230,15 @@ class Spinbox(ttk.Entry):
|
|||
|
||||
def set(self, 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