more work on coretk
This commit is contained in:
parent
b097028a4a
commit
5829e3ae42
10 changed files with 548 additions and 74 deletions
|
@ -59,7 +59,7 @@ class Application(tk.Frame):
|
|||
master=self,
|
||||
grpc=self.core_grpc,
|
||||
background="#cccccc",
|
||||
scrollregion=(0, 0, 1000, 1000),
|
||||
scrollregion=(0, 0, 1200, 1000),
|
||||
)
|
||||
self.canvas.pack(fill=tk.BOTH, expand=True)
|
||||
|
||||
|
|
|
@ -35,9 +35,9 @@ class CoreGrpc:
|
|||
|
||||
def log_throughput(self, event):
|
||||
interface_throughputs = event.interface_throughputs
|
||||
# for i in interface_throughputs:
|
||||
# print(i)
|
||||
# return
|
||||
for i in interface_throughputs:
|
||||
print("")
|
||||
return
|
||||
throughputs_belong_to_session = []
|
||||
for if_tp in interface_throughputs:
|
||||
if if_tp.node_id in self.node_ids:
|
||||
|
@ -58,8 +58,9 @@ class CoreGrpc:
|
|||
|
||||
# handle events session may broadcast
|
||||
self.session_id = response.session_id
|
||||
self.master.title("CORE Session ID " + str(self.session_id))
|
||||
self.core.events(self.session_id, self.log_event)
|
||||
self.core.throughputs(self.log_throughput)
|
||||
# self.core.throughputs(self.log_throughput)
|
||||
|
||||
def query_existing_sessions(self, sessions):
|
||||
"""
|
||||
|
|
|
@ -169,7 +169,9 @@ class CoreMenubar(object):
|
|||
canvas_menu.add_command(
|
||||
label="Size/scale...", command=self.menu_action.canvas_size_and_scale
|
||||
)
|
||||
canvas_menu.add_command(label="Wallpaper...", command=action.canvas_wallpaper)
|
||||
canvas_menu.add_command(
|
||||
label="Wallpaper...", command=self.menu_action.canvas_set_wallpaper
|
||||
)
|
||||
|
||||
canvas_menu.add_separator()
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@ class CanvasGraph(tk.Canvas):
|
|||
self.edges = {}
|
||||
self.drawing_edge = None
|
||||
|
||||
self.grid = None
|
||||
self.meters_per_pixel = 1.5
|
||||
self.setup_menus()
|
||||
self.setup_bindings()
|
||||
self.draw_grid()
|
||||
|
@ -89,7 +91,7 @@ class CanvasGraph(tk.Canvas):
|
|||
self.bind("<B1-Motion>", self.click_motion)
|
||||
self.bind("<Button-3>", self.context)
|
||||
|
||||
def draw_grid(self, width=1000, height=750):
|
||||
def draw_grid(self, width=1000, height=800):
|
||||
"""
|
||||
Create grid
|
||||
|
||||
|
@ -98,7 +100,7 @@ class CanvasGraph(tk.Canvas):
|
|||
|
||||
:return: nothing
|
||||
"""
|
||||
rectangle_id = self.create_rectangle(
|
||||
self.grid = self.create_rectangle(
|
||||
0,
|
||||
0,
|
||||
width,
|
||||
|
@ -108,11 +110,11 @@ class CanvasGraph(tk.Canvas):
|
|||
width=1,
|
||||
tags="rectangle",
|
||||
)
|
||||
self.tag_lower(rectangle_id)
|
||||
self.tag_lower(self.grid)
|
||||
for i in range(0, width, 27):
|
||||
self.create_line(i, 0, i, height, dash=(2, 4), tags="grid line")
|
||||
self.create_line(i, 0, i, height, dash=(2, 4), tags="gridline")
|
||||
for i in range(0, height, 27):
|
||||
self.create_line(0, i, width, i, dash=(2, 4), tags="grid line")
|
||||
self.create_line(0, i, width, i, dash=(2, 4), tags="gridline")
|
||||
|
||||
def draw_existing_component(self):
|
||||
"""
|
||||
|
@ -235,6 +237,7 @@ class CanvasGraph(tk.Canvas):
|
|||
:return: the item that the mouse point to
|
||||
"""
|
||||
overlapping = self.find_overlapping(event.x, event.y, event.x, event.y)
|
||||
print(overlapping)
|
||||
nodes = set(self.find_withtag("node"))
|
||||
selected = None
|
||||
for _id in overlapping:
|
||||
|
@ -260,6 +263,7 @@ class CanvasGraph(tk.Canvas):
|
|||
self.focus_set()
|
||||
self.selected = self.get_selected(event)
|
||||
logging.debug(f"click release selected: {self.selected}")
|
||||
print(self.mode)
|
||||
if self.mode == GraphMode.EDGE:
|
||||
self.handle_edge_release(event)
|
||||
elif self.mode == GraphMode.NODE:
|
||||
|
@ -359,7 +363,8 @@ class CanvasGraph(tk.Canvas):
|
|||
self.node_context.post(event.x_root, event.y_root)
|
||||
|
||||
def add_node(self, x, y, image, node_name):
|
||||
if self.selected == 1:
|
||||
plot_id = self.find_all()[0]
|
||||
if self.selected == plot_id:
|
||||
node = CanvasNode(
|
||||
x=x,
|
||||
y=y,
|
||||
|
@ -510,7 +515,7 @@ class CanvasNode:
|
|||
else:
|
||||
self.canvas.coords(edge.id, x1, y1, new_x, new_y)
|
||||
edge.link_info.recalculate_info()
|
||||
self.canvas.core_grpc.throughput_draw.update_throughtput_location(edge)
|
||||
# self.canvas.core_grpc.throughput_draw.update_throughtput_location(edge)
|
||||
|
||||
self.canvas.helper.update_wlan_connection(
|
||||
old_x, old_y, new_x, new_y, self.wlans
|
||||
|
|
|
@ -7,6 +7,7 @@ import webbrowser
|
|||
from tkinter import filedialog, messagebox
|
||||
|
||||
from core.api.grpc import core_pb2
|
||||
from coretk.setwallpaper import CanvasWallpaper
|
||||
from coretk.sizeandscale import SizeAndScale
|
||||
|
||||
SAVEDIR = "/home/ncs/Desktop/"
|
||||
|
@ -418,7 +419,10 @@ class MenuAction:
|
|||
# print(t1 - t0)
|
||||
|
||||
def canvas_size_and_scale(self):
|
||||
SizeAndScale()
|
||||
SizeAndScale(self.application)
|
||||
|
||||
def canvas_set_wallpaper(self):
|
||||
CanvasWallpaper(self.application)
|
||||
|
||||
def help_core_github(self):
|
||||
webbrowser.open_new("https://github.com/coreemu/core")
|
||||
|
|
|
@ -30,7 +30,7 @@ class NodeConfig:
|
|||
self.select_definition()
|
||||
|
||||
def open_icon_dir(self, toplevel, entry_text):
|
||||
imgfile = filedialog.askopenfilename(
|
||||
filename = filedialog.askopenfilename(
|
||||
initialdir=ICONS_DIR,
|
||||
title="Open",
|
||||
filetypes=(
|
||||
|
@ -38,16 +38,15 @@ class NodeConfig:
|
|||
("All Files", "*"),
|
||||
),
|
||||
)
|
||||
if len(imgfile) > 0:
|
||||
img = Image.open(imgfile)
|
||||
if len(filename) > 0:
|
||||
img = Image.open(filename)
|
||||
tk_img = ImageTk.PhotoImage(img)
|
||||
lb = toplevel.grid_slaves(1, 0)[0]
|
||||
lb.configure(image=tk_img)
|
||||
lb.image = tk_img
|
||||
entry_text.set(imgfile)
|
||||
entry_text.set(filename)
|
||||
|
||||
def click_apply(self, toplevel, entry_text):
|
||||
print("click apply")
|
||||
imgfile = entry_text.get()
|
||||
if imgfile:
|
||||
img = Image.open(imgfile)
|
||||
|
|
294
coretk/coretk/setwallpaper.py
Normal file
294
coretk/coretk/setwallpaper.py
Normal file
|
@ -0,0 +1,294 @@
|
|||
"""
|
||||
set wallpaper
|
||||
"""
|
||||
import enum
|
||||
import logging
|
||||
import os
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
PATH = os.path.abspath(os.path.dirname(__file__))
|
||||
WALLPAPER_DIR = os.path.join(PATH, "wallpaper")
|
||||
|
||||
|
||||
class ScaleOption(enum.Enum):
|
||||
UPPER_LEFT = 1
|
||||
CENTERED = 2
|
||||
SCALED = 3
|
||||
TILED = 4
|
||||
|
||||
|
||||
class CanvasWallpaper:
|
||||
def __init__(self, application):
|
||||
self.application = application
|
||||
self.canvas = self.application.canvas
|
||||
|
||||
self.top = tk.Toplevel()
|
||||
self.top.title("Set Canvas Wallpaper")
|
||||
self.radiovar = tk.IntVar()
|
||||
self.show_grid_var = tk.IntVar()
|
||||
self.adjust_to_dim_var = tk.IntVar()
|
||||
self.wallpaper = None
|
||||
|
||||
self.create_image_label()
|
||||
self.create_text_label()
|
||||
self.open_image()
|
||||
self.display_options()
|
||||
self.additional_options()
|
||||
self.apply_cancel()
|
||||
|
||||
def create_image_label(self):
|
||||
image_label = tk.Label(
|
||||
self.top, text="(image preview)", height=8, width=32, bg="white"
|
||||
)
|
||||
image_label.grid(pady=5)
|
||||
|
||||
def create_text_label(self):
|
||||
text_label = tk.Label(self.top, text="Image filename: ")
|
||||
text_label.grid()
|
||||
|
||||
def open_image_link(self):
|
||||
filename = filedialog.askopenfilename(
|
||||
initialdir=WALLPAPER_DIR,
|
||||
title="Open",
|
||||
filetypes=(
|
||||
("images", "*.gif *.jpg *.png *.bmp *pcx *.tga ..."),
|
||||
("All Files", "*"),
|
||||
),
|
||||
)
|
||||
|
||||
# fill the file name into the file name entry
|
||||
img_open_frame = self.top.grid_slaves(2, 0)[0]
|
||||
filename_entry = img_open_frame.grid_slaves(0, 0)[0]
|
||||
filename_entry.delete(0, tk.END)
|
||||
filename_entry.insert(tk.END, filename)
|
||||
|
||||
# display that onto the label
|
||||
img_label = self.top.grid_slaves(0, 0)[0]
|
||||
if filename:
|
||||
img = Image.open(filename)
|
||||
img = img.resize((250, 135), Image.ANTIALIAS)
|
||||
tk_img = ImageTk.PhotoImage(img)
|
||||
img_label.config(image=tk_img, width=250, height=135)
|
||||
img_label.image = tk_img
|
||||
|
||||
def clear_link(self):
|
||||
# delete entry
|
||||
img_open_frame = self.top.grid_slaves(2, 0)[0]
|
||||
filename_entry = img_open_frame.grid_slaves(0, 0)[0]
|
||||
filename_entry.delete(0, tk.END)
|
||||
|
||||
# delete display image
|
||||
img_label = self.top.grid_slaves(0, 0)[0]
|
||||
img_label.config(image="", width=32, height=8)
|
||||
|
||||
def open_image(self):
|
||||
f = tk.Frame(self.top)
|
||||
|
||||
var = tk.StringVar(f, value="")
|
||||
e = tk.Entry(f, textvariable=var)
|
||||
e.focus()
|
||||
e.grid()
|
||||
|
||||
b = tk.Button(f, text="...", command=self.open_image_link)
|
||||
b.grid(row=0, column=1)
|
||||
|
||||
b = tk.Button(f, text="Clear", command=self.clear_link)
|
||||
b.grid(row=0, column=2)
|
||||
|
||||
f.grid()
|
||||
|
||||
def display_options(self):
|
||||
f = tk.Frame(self.top)
|
||||
|
||||
b1 = tk.Radiobutton(f, text="upper-left", value=1, variable=self.radiovar)
|
||||
b1.grid(row=0, column=0)
|
||||
|
||||
b2 = tk.Radiobutton(f, text="centered", value=2, variable=self.radiovar)
|
||||
b2.grid(row=0, column=1)
|
||||
|
||||
b3 = tk.Radiobutton(f, text="scaled", value=3, variable=self.radiovar)
|
||||
b3.grid(row=0, column=2)
|
||||
|
||||
b4 = tk.Radiobutton(f, text="titled", value=4, variable=self.radiovar)
|
||||
b4.grid(row=0, column=3)
|
||||
|
||||
self.radiovar.set(1)
|
||||
|
||||
f.grid()
|
||||
|
||||
def additional_options(self):
|
||||
b = tk.Checkbutton(self.top, text="Show grid", variable=self.show_grid_var)
|
||||
b.grid(sticky=tk.W, padx=5)
|
||||
b = tk.Checkbutton(
|
||||
self.top,
|
||||
text="Adjust canvas size to image dimensions",
|
||||
variable=self.adjust_to_dim_var,
|
||||
)
|
||||
b.grid(sticky=tk.W, padx=5)
|
||||
self.show_grid_var.set(1)
|
||||
self.adjust_to_dim_var.set(0)
|
||||
|
||||
def delete_previous_wallpaper(self):
|
||||
prev_wallpaper = self.canvas.find_withtag("wallpaper")
|
||||
if prev_wallpaper:
|
||||
for i in prev_wallpaper:
|
||||
self.canvas.delete(i)
|
||||
|
||||
def get_canvas_width_and_height(self):
|
||||
"""
|
||||
retrieve canvas width and height in pixels
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
canvas = self.application.canvas
|
||||
grid = canvas.find_withtag("rectangle")[0]
|
||||
x0, y0, x1, y1 = canvas.coords(grid)
|
||||
canvas_w = abs(x0 - x1)
|
||||
canvas_h = abs(y0 - y1)
|
||||
return canvas_w, canvas_h
|
||||
|
||||
def determine_cropped_image_dimension(self):
|
||||
"""
|
||||
determine the dimension of the image after being cropped
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
return
|
||||
|
||||
def upper_left(self, img):
|
||||
tk_img = ImageTk.PhotoImage(img)
|
||||
|
||||
# crop image if it is bigger than canvas
|
||||
canvas_w, canvas_h = self.get_canvas_width_and_height()
|
||||
|
||||
cropx = img_w = tk_img.width()
|
||||
cropy = img_h = tk_img.height()
|
||||
|
||||
if img_w > canvas_w:
|
||||
|
||||
cropx -= img_w - canvas_w
|
||||
if img_h > canvas_h:
|
||||
cropy -= img_h - canvas_h
|
||||
cropped = img.crop((0, 0, cropx, cropy))
|
||||
cropped_tk = ImageTk.PhotoImage(cropped)
|
||||
|
||||
# place left corner of image to the left corner of the canvas
|
||||
self.application.croppedwallpaper = cropped_tk
|
||||
|
||||
self.delete_previous_wallpaper()
|
||||
|
||||
wid = self.canvas.create_image(
|
||||
(cropx / 2, cropy / 2), image=cropped_tk, tags="wallpaper"
|
||||
)
|
||||
self.application.wallpaper_id = wid
|
||||
|
||||
def center(self, img):
|
||||
"""
|
||||
place the image at the center of canvas
|
||||
|
||||
:param Image img: image object
|
||||
:return: nothing
|
||||
"""
|
||||
tk_img = ImageTk.PhotoImage(img)
|
||||
canvas_w, canvas_h = self.get_canvas_width_and_height()
|
||||
|
||||
cropx = img_w = tk_img.width()
|
||||
cropy = img_h = tk_img.height()
|
||||
|
||||
# dimension of the cropped image
|
||||
if img_w > canvas_w:
|
||||
cropx -= img_w - canvas_w
|
||||
if img_h > canvas_h:
|
||||
cropy -= img_h - canvas_h
|
||||
|
||||
x0 = (img_w - cropx) / 2
|
||||
y0 = (img_h - cropy) / 2
|
||||
x1 = x0 + cropx
|
||||
y1 = y0 + cropy
|
||||
cropped = img.crop((x0, y0, x1, y1))
|
||||
cropped_tk = ImageTk.PhotoImage(cropped)
|
||||
|
||||
# place the center of the image at the center of the canvas
|
||||
self.application.croppedwallpaper = cropped_tk
|
||||
self.delete_previous_wallpaper()
|
||||
wid = self.canvas.create_image(
|
||||
(canvas_w / 2, canvas_h / 2), image=cropped_tk, tags="wallpaper"
|
||||
)
|
||||
self.application.wallpaper_id = wid
|
||||
|
||||
def scaled(self, img):
|
||||
"""
|
||||
scale image based on canvas dimension
|
||||
|
||||
:param Image img: image object
|
||||
:return: nothing
|
||||
"""
|
||||
canvas_w, canvas_h = self.get_canvas_width_and_height()
|
||||
resized_image = img.resize((int(canvas_w), int(canvas_h)), Image.ANTIALIAS)
|
||||
image_tk = ImageTk.PhotoImage(resized_image)
|
||||
self.application.croppedwallpaper = image_tk
|
||||
|
||||
self.delete_previous_wallpaper()
|
||||
|
||||
wid = self.canvas.create_image(
|
||||
(canvas_w / 2, canvas_h / 2), image=image_tk, tags="wallpaper"
|
||||
)
|
||||
self.application.wallpaper_id = wid
|
||||
|
||||
def tiled(self, img):
|
||||
return
|
||||
|
||||
def show_grid(self):
|
||||
"""
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
if self.show_grid_var.get() == 0:
|
||||
for i in self.canvas.find_withtag("gridline"):
|
||||
self.canvas.itemconfig(i, state=tk.HIDDEN)
|
||||
elif self.show_grid_var.get() == 1:
|
||||
for i in self.canvas.find_withtag("gridline"):
|
||||
self.canvas.itemconfig(i, state=tk.NORMAL)
|
||||
self.canvas.lift(i)
|
||||
else:
|
||||
logging.error("setwallpaper.py show_grid invalid value")
|
||||
|
||||
def click_apply(self):
|
||||
img_link_frame = self.top.grid_slaves(2, 0)[0]
|
||||
filename = img_link_frame.grid_slaves(0, 0)[0].get()
|
||||
if not filename:
|
||||
self.top.destroy()
|
||||
return
|
||||
try:
|
||||
img = Image.open(filename)
|
||||
except FileNotFoundError:
|
||||
print("invalid filename, draw original white plot")
|
||||
if self.application.wallpaper_id:
|
||||
self.canvas.delete(self.application.wallpaper_id)
|
||||
self.top.destroy()
|
||||
return
|
||||
if self.radiovar.get() == ScaleOption.UPPER_LEFT.value:
|
||||
self.upper_left(img)
|
||||
elif self.radiovar.get() == ScaleOption.CENTERED.value:
|
||||
self.center(img)
|
||||
elif self.radiovar.get() == ScaleOption.SCALED.value:
|
||||
self.scaled(img)
|
||||
elif self.radiovar.get() == ScaleOption.TILED.value:
|
||||
print("not implemented yet")
|
||||
|
||||
self.show_grid()
|
||||
self.top.destroy()
|
||||
|
||||
def apply_cancel(self):
|
||||
f = tk.Frame(self.top)
|
||||
|
||||
b = tk.Button(f, text="Apply", command=self.click_apply)
|
||||
b.grid(row=0, column=0)
|
||||
|
||||
b = tk.Button(f, text="Cancel", command=self.top.destroy)
|
||||
b.grid(row=0, column=1)
|
||||
|
||||
f.grid(pady=5)
|
|
@ -1,86 +1,255 @@
|
|||
"""
|
||||
size and scale
|
||||
"""
|
||||
|
||||
import tkinter as tk
|
||||
from functools import partial
|
||||
|
||||
DRAW_OBJECT_TAGS = ["edge", "node", "nodename", "linkinfo", "antenna"]
|
||||
|
||||
|
||||
class SizeAndScale:
|
||||
def __init__(self):
|
||||
def __init__(self, application):
|
||||
"""
|
||||
create an instance for size and scale object
|
||||
|
||||
:param application: main application
|
||||
"""
|
||||
self.application = application
|
||||
self.top = tk.Toplevel()
|
||||
self.top.title("Canvas Size and Scale")
|
||||
self.meter_per_pixel = self.application.canvas.meters_per_pixel
|
||||
|
||||
self.size_chart()
|
||||
self.scale_chart()
|
||||
self.reference_point_chart()
|
||||
self.save_as_default()
|
||||
self.apply_cancel()
|
||||
|
||||
self.pixel_width_text = None
|
||||
def pixel_scrollbar_command(self, size_frame, entry_row, entry_column, event):
|
||||
"""
|
||||
change the value shown based on scrollbar action
|
||||
|
||||
def click_scrollbar(self, e1, e2, e3):
|
||||
print(e1, e2, e3)
|
||||
:param tkinter.Frame frame: pixel dimension frame
|
||||
:param int entry_row: row number of entry of the frame
|
||||
:param int entry_column: column number of entry of the frame
|
||||
:param event: scrollbar event
|
||||
:return: nothing
|
||||
"""
|
||||
pixel_frame = size_frame.grid_slaves(0, 0)[0]
|
||||
pixel_entry = pixel_frame.grid_slaves(entry_row, entry_column)[0]
|
||||
val = int(pixel_entry.get())
|
||||
|
||||
def create_text_label(self, frame, text, row, column):
|
||||
if event == "-1":
|
||||
new_val = val + 2
|
||||
elif event == "1":
|
||||
new_val = val - 2
|
||||
|
||||
pixel_entry.delete(0, tk.END)
|
||||
pixel_entry.insert(tk.END, str(new_val))
|
||||
|
||||
# change meter dimension
|
||||
meter_frame = size_frame.grid_slaves(1, 0)[0]
|
||||
meter_entry = meter_frame.grid_slaves(entry_row, entry_column)[0]
|
||||
meter_entry.delete(0, tk.END)
|
||||
meter_entry.insert(tk.END, str(new_val * self.meter_per_pixel))
|
||||
|
||||
def meter_scrollbar_command(self, size_frame, entry_row, entry_column, event):
|
||||
"""
|
||||
change the value shown based on scrollbar action
|
||||
|
||||
:param tkinter.Frame size_frame: size frame
|
||||
:param int entry_row: row number of entry in the frame it is contained in
|
||||
:param int entry_column: column number of entry in the frame in is contained in
|
||||
:param event: scroolbar event
|
||||
:return: nothing
|
||||
"""
|
||||
meter_frame = size_frame.grid_slaves(1, 0)[0]
|
||||
meter_entry = meter_frame.grid_slaves(entry_row, entry_column)[0]
|
||||
val = float(meter_entry.get())
|
||||
|
||||
if event == "-1":
|
||||
val += 100.0
|
||||
elif event == "1":
|
||||
val -= 100.0
|
||||
meter_entry.delete(0, tk.END)
|
||||
meter_entry.insert(tk.END, str(val))
|
||||
|
||||
# change pixel dimension
|
||||
pixel_frame = size_frame.grid_slaves(0, 0)[0]
|
||||
pixel_entry = pixel_frame.grid_slaves(entry_row, entry_column)[0]
|
||||
pixel_entry.delete(0, tk.END)
|
||||
pixel_entry.insert(tk.END, str(int(val / self.meter_per_pixel)))
|
||||
|
||||
def create_text_label(self, frame, text, row, column, sticky=None):
|
||||
"""
|
||||
create text label
|
||||
:param tkinter.Frame frame: parent frame
|
||||
:param str text: label text
|
||||
:param int row: row number
|
||||
:param int column: column number
|
||||
:param sticky: sticky value
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
text_label = tk.Label(frame, text=text)
|
||||
text_label.grid(row=row, column=column)
|
||||
text_label.grid(row=row, column=column, sticky=sticky, padx=3, pady=3)
|
||||
|
||||
def create_entry(self, frame, default_value, row, column, width):
|
||||
text_var = tk.StringVar(frame, value=str(default_value))
|
||||
entry = tk.Entry(
|
||||
frame, textvariable=text_var, width=width, bg="white", state=tk.NORMAL
|
||||
)
|
||||
entry.focus()
|
||||
entry.grid(row=row, column=column, padx=3, pady=3)
|
||||
|
||||
def size_chart(self):
|
||||
f = tk.Frame(self.top)
|
||||
t = tk.Label(f, text="Size")
|
||||
t.grid(row=0, column=0, sticky=tk.W)
|
||||
label = tk.Label(self.top, text="Size")
|
||||
label.grid(sticky=tk.W, padx=5)
|
||||
|
||||
scrollbar = tk.Scrollbar(f, orient=tk.VERTICAL)
|
||||
scrollbar.grid(row=1, column=1)
|
||||
e = tk.Entry(f, text="1000", xscrollcommand=scrollbar.set)
|
||||
e.focus()
|
||||
e.grid(row=1, column=0)
|
||||
scrollbar.config(command=self.click_scrollbar)
|
||||
canvas = self.application.canvas
|
||||
plot = canvas.find_withtag("rectangle")
|
||||
x0, y0, x1, y1 = canvas.bbox(plot[0])
|
||||
w = abs(x0 - x1) - 2
|
||||
h = abs(y0 - y1) - 2
|
||||
|
||||
# l = tk.Label(f, text="W")
|
||||
# l.grid(row=1, column=2)
|
||||
# l = tk.Label(f, text=" X ")
|
||||
# l.grid(row=1, column=3)
|
||||
self.create_text_label(f, "W", 1, 2)
|
||||
self.create_text_label(f, " X ", 1, 3)
|
||||
f = tk.Frame(
|
||||
self.top,
|
||||
highlightbackground="#b3b3b3",
|
||||
highlightcolor="#b3b3b3",
|
||||
highlightthickness=0.5,
|
||||
bd=0,
|
||||
)
|
||||
|
||||
hpixel_scrollbar = tk.Scrollbar(f, orient=tk.VERTICAL)
|
||||
hpixel_scrollbar.grid(row=1, column=5)
|
||||
f1 = tk.Frame(f)
|
||||
pw_scrollbar = tk.Scrollbar(f1, orient=tk.VERTICAL)
|
||||
pw_scrollbar.grid(row=0, column=1)
|
||||
self.create_entry(f1, w, 0, 0, 6)
|
||||
pw_scrollbar.config(command=partial(self.pixel_scrollbar_command, f, 0, 0))
|
||||
|
||||
hpixel_entry = tk.Entry(f, text="750", xscrollcommand=hpixel_scrollbar.set)
|
||||
hpixel_entry.focus()
|
||||
hpixel_entry.grid(row=1, column=4)
|
||||
self.create_text_label(f1, " W x ", 0, 2)
|
||||
|
||||
h_label = tk.Label(f, text="H")
|
||||
h_label.grid(row=1, column=6)
|
||||
scrollbar = tk.Scrollbar(f1, orient=tk.VERTICAL)
|
||||
scrollbar.grid(row=0, column=4)
|
||||
self.create_entry(f1, h, 0, 3, 6)
|
||||
scrollbar.config(command=partial(self.pixel_scrollbar_command, f, 0, 3))
|
||||
self.create_text_label(f1, " H pixels ", 0, 7)
|
||||
f1.grid(sticky=tk.W, pady=3)
|
||||
|
||||
self.create_text_label(f, "pixels", 1, 7)
|
||||
# pixel_label = tk.Label(f, text="pixels")
|
||||
# pixel_label.grid(row=1, column=7)
|
||||
f2 = tk.Frame(f)
|
||||
scrollbar = tk.Scrollbar(f2, orient=tk.VERTICAL)
|
||||
scrollbar.grid(row=0, column=1)
|
||||
self.create_entry(f2, w * self.meter_per_pixel, 0, 0, 8)
|
||||
scrollbar.config(command=partial(self.meter_scrollbar_command, f, 0, 0))
|
||||
self.create_text_label(f2, " x ", 0, 2)
|
||||
|
||||
wmeter_scrollbar = tk.Scrollbar(f, orient=tk.VERTICAL)
|
||||
wmeter_scrollbar.grid(row=2, column=2)
|
||||
scrollbar = tk.Scrollbar(f2, orient=tk.VERTICAL)
|
||||
scrollbar.grid(row=0, column=4)
|
||||
self.create_entry(f2, h * self.meter_per_pixel, 0, 3, 8)
|
||||
scrollbar.config(command=partial(self.meter_scrollbar_command, f, 0, 3))
|
||||
self.create_text_label(f2, " meters ", 0, 5)
|
||||
|
||||
wmeter_entry = tk.Entry(f, text="1500.0", xscrollcommand=wmeter_scrollbar.set)
|
||||
wmeter_entry.focus()
|
||||
wmeter_entry.grid(row=2, column=0, columnspan=2, sticky=tk.W + tk.E)
|
||||
f2.grid(sticky=tk.W, pady=3)
|
||||
|
||||
# l = tk.Label(f, text=" X ")
|
||||
# l.grid(row=2, column=3)
|
||||
self.create_text_label(f, " X ", row=2, column=3)
|
||||
f.grid(sticky=tk.W + tk.E, padx=5, pady=5, columnspan=2)
|
||||
|
||||
def scale_chart(self):
|
||||
label = tk.Label(self.top, text="Scale")
|
||||
label.grid(padx=5, sticky=tk.W)
|
||||
f = tk.Frame(
|
||||
self.top,
|
||||
highlightbackground="#b3b3b3",
|
||||
highlightcolor="#b3b3b3",
|
||||
highlightthickness=0.5,
|
||||
bd=0,
|
||||
)
|
||||
# self.create_text_label(f, "Scale", 0, 0, tk.W)
|
||||
# f1 = tk.Frame(f)
|
||||
hmeter_scrollbar = tk.Scrollbar(f, orient=tk.VERTICAL)
|
||||
hmeter_scrollbar.grid(row=2, column=6)
|
||||
self.create_text_label(f, "100 pixels = ", 0, 0)
|
||||
self.create_entry(f, self.meter_per_pixel * 100, 0, 1, 10)
|
||||
self.create_text_label(f, "meters", 0, 2)
|
||||
# f1.grid(sticky=tk.W, pady=3)
|
||||
f.grid(sticky=tk.W + tk.E, padx=5, pady=5, columnspan=2)
|
||||
|
||||
hmeter_entry = tk.Entry(f, text="1125.0", xscrollcommand=hmeter_scrollbar.set)
|
||||
hmeter_entry.focus()
|
||||
hmeter_entry.grid(row=2, column=4, columnspan=2, sticky=tk.W + tk.E)
|
||||
def reference_point_chart(self):
|
||||
label = tk.Label(self.top, text="Reference point")
|
||||
label.grid(padx=5, sticky=tk.W)
|
||||
|
||||
self.create_text_label(f, "pixels", 2, 7)
|
||||
# pixel_label = tk.Label(f, text="pixels")
|
||||
# pixel_label.grid(row=2, column=7)
|
||||
# hmeter_entry.pack(side=tk.LEFT)
|
||||
#
|
||||
# hmeter_scrollbar = tk.Scrollbar(hmeter_entry, orient=tk.VERTICAL)
|
||||
# hmeter_scrollbar.pack(side=tk.LEFT)
|
||||
# f1.grid(row=2, column=4)
|
||||
f = tk.Frame(
|
||||
self.top,
|
||||
highlightbackground="#b3b3b3",
|
||||
highlightcolor="#b3b3b3",
|
||||
highlightthickness=0.5,
|
||||
bd=0,
|
||||
)
|
||||
self.create_text_label(
|
||||
f,
|
||||
"The default reference point is (0, 0), the upper left corner of the canvas.",
|
||||
1,
|
||||
0,
|
||||
tk.W,
|
||||
)
|
||||
f1 = tk.Frame(f)
|
||||
self.create_entry(f1, 0, 0, 0, 4)
|
||||
self.create_text_label(f1, " X, ", 0, 1)
|
||||
self.create_entry(f1, 0, 0, 2, 4)
|
||||
self.create_text_label(f1, "Y = ", 0, 3)
|
||||
self.create_entry(f1, 47.5791667, 0, 4, 13)
|
||||
self.create_text_label(f1, " lat, ", 0, 5)
|
||||
self.create_entry(f1, -122.132322, 0, 6, 13)
|
||||
self.create_text_label(f1, "long", 0, 7)
|
||||
f1.grid(row=2, column=0, sticky=tk.W, pady=3)
|
||||
|
||||
f.grid()
|
||||
f2 = tk.Frame(f)
|
||||
self.create_text_label(f2, "Altitude: ", 0, 0)
|
||||
self.create_entry(f2, 2.0, 0, 1, 11)
|
||||
self.create_text_label(f2, " meters ", 0, 2)
|
||||
f2.grid(row=3, column=0, sticky=tk.W, pady=3)
|
||||
|
||||
# def scale_chart(self):
|
||||
f.grid(sticky=tk.W, padx=5, pady=5, columnspan=2)
|
||||
|
||||
def save_as_default(self):
|
||||
var = tk.IntVar()
|
||||
button = tk.Checkbutton(self.top, text="Save as default", variable=var)
|
||||
button.grid(sticky=tk.W, padx=5, pady=5, columnspan=2)
|
||||
|
||||
def redraw_grid(self, pixel_width, pixel_height):
|
||||
"""
|
||||
redraw grid with new dimension
|
||||
|
||||
:param int pixel_width: width in pixel
|
||||
:param int pixel_height: height in pixel
|
||||
:return: nothing
|
||||
"""
|
||||
canvas = self.application.canvas
|
||||
canvas.config(scrollregion=(0, 0, pixel_width + 200, pixel_height + 200))
|
||||
|
||||
# delete old plot and redraw
|
||||
for i in canvas.find_withtag("gridline"):
|
||||
canvas.delete(i)
|
||||
for i in canvas.find_withtag("rectangle"):
|
||||
canvas.delete(i)
|
||||
|
||||
canvas.draw_grid(width=pixel_width, height=pixel_height)
|
||||
# lift anything that is drawn on the plot before
|
||||
for tag in DRAW_OBJECT_TAGS:
|
||||
for i in canvas.find_withtag(tag):
|
||||
canvas.lift(i)
|
||||
|
||||
def click_apply(self):
|
||||
size_frame = self.top.grid_slaves(1, 0)[0]
|
||||
pixel_size_frame = size_frame.grid_slaves(0, 0)[0]
|
||||
|
||||
pixel_width = int(pixel_size_frame.grid_slaves(0, 0)[0].get())
|
||||
pixel_height = int(pixel_size_frame.grid_slaves(0, 3)[0].get())
|
||||
|
||||
scale_frame = self.top.grid_slaves(3, 0)[0]
|
||||
meter_per_pixel = float(scale_frame.grid_slaves(0, 1)[0].get()) / 100
|
||||
self.application.canvas.meters_per_pixel = meter_per_pixel
|
||||
self.redraw_grid(pixel_width, pixel_height)
|
||||
self.top.destroy()
|
||||
|
||||
def apply_cancel(self):
|
||||
apply_button = tk.Button(self.top, text="Apply", command=self.click_apply)
|
||||
apply_button.grid(row=7, column=0, pady=5)
|
||||
cancel_button = tk.Button(self.top, text="Cancel", command=self.top.destroy)
|
||||
cancel_button.grid(row=7, column=1, pady=5)
|
||||
|
|
BIN
coretk/coretk/wallpaper/sample1-bg.gif
Normal file
BIN
coretk/coretk/wallpaper/sample1-bg.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 312 KiB |
BIN
coretk/coretk/wallpaper/sample4-bg.jpg
Normal file
BIN
coretk/coretk/wallpaper/sample4-bg.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 196 KiB |
Loading…
Add table
Reference in a new issue