-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Disable minimap for Diff editor (performance mode)
- Loading branch information
Showing
3 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import tkinter | ||
from math import e | ||
from tkinter.dnd import * | ||
|
||
|
||
class Tester: | ||
def __init__(self, root): | ||
self.top = tkinter.Toplevel(root) | ||
self.canvas = tkinter.Canvas(self.top, width=100, height=100) | ||
self.canvas.pack(fill="both", expand=1) | ||
self.canvas.dnd_accept = self.dnd_accept | ||
self.top.minsize(300, 150) | ||
|
||
def dnd_accept(self, source, event): | ||
return self | ||
|
||
def dnd_enter(self, source, event): | ||
self.canvas.focus_set() # Show highlight border | ||
x, y = source.where(self.canvas, event) | ||
x1, y1, x2, y2 = source.canvas.bbox(source.id) | ||
dx, dy = x2-x1, y2-y1 | ||
self.dndid = self.canvas.create_rectangle(x, y, x+dx, y+dy) | ||
self.dnd_motion(source, event) | ||
|
||
def dnd_motion(self, source, event): | ||
x, y = source.where(self.canvas, event) | ||
x1, y1, x2, y2 = self.canvas.bbox(self.dndid) | ||
self.canvas.move(self.dndid, x-x1, y-y1) | ||
|
||
def dnd_leave(self, source, event): | ||
self.top.focus_set() # Hide highlight border | ||
self.canvas.delete(self.dndid) | ||
self.dndid = None | ||
|
||
def dnd_commit(self, source, event): | ||
self.dnd_leave(source, event) | ||
x, y = source.where(self.canvas, event) | ||
source.attach(self.canvas, x, y) | ||
|
||
class Icon: | ||
|
||
def __init__(self, name): | ||
self.name = name | ||
self.canvas = self.label = self.id = None | ||
|
||
def attach(self, canvas, x=10, y=10): | ||
if canvas is self.canvas: | ||
self.canvas.coords(self.id, x, y) | ||
return | ||
if self.canvas is not None: | ||
self.detach() | ||
if canvas is None: | ||
return | ||
label = tkinter.Label(canvas, text=self.name, | ||
borderwidth=2, relief="raised") | ||
id = canvas.create_window(x, y, window=label, anchor="nw") | ||
self.canvas = canvas | ||
self.label = label | ||
self.id = id | ||
label.bind("<ButtonPress>", self.press) | ||
|
||
def detach(self): | ||
canvas = self.canvas | ||
if canvas is None: | ||
return | ||
id = self.id | ||
label = self.label | ||
self.canvas = self.label = self.id = None | ||
canvas.delete(id) | ||
label.destroy() | ||
|
||
def press(self, event): | ||
if dnd_start(self, event): | ||
# where the pointer is relative to the label widget: | ||
self.x_off = event.x | ||
self.y_off = event.y | ||
# where the widget is relative to the canvas: | ||
self.x_orig, self.y_orig = self.canvas.coords(self.id) | ||
|
||
def move(self, event): | ||
x, y = self.where(self.canvas, event) | ||
self.canvas.coords(self.id, x, y) | ||
|
||
def putback(self): | ||
self.canvas.coords(self.id, self.x_orig, self.y_orig) | ||
|
||
def where(self, canvas, event): | ||
# where the corner of the canvas is relative to the screen: | ||
x_org = canvas.winfo_rootx() | ||
y_org = canvas.winfo_rooty() | ||
# where the pointer is relative to the canvas widget: | ||
x = event.x_root - x_org | ||
y = event.y_root - y_org | ||
# compensate for initial pointer offset | ||
return x - self.x_off, y - self.y_off | ||
|
||
def dnd_end(self, target, event): | ||
if not target: | ||
t = Tester(self.canvas) | ||
t.top.title(self.name) | ||
t.top.geometry(f"+{event.x_root}+{event.y_root}") | ||
t.dnd_enter(self, event) | ||
t.dnd_commit(self, event) | ||
|
||
root = tkinter.Tk() | ||
root.geometry("+1+1") | ||
tkinter.Button(command=root.quit, text="Quit").pack() | ||
t1 = Tester(root) | ||
t1.top.geometry("+1+60") | ||
t2 = Tester(root) | ||
t2.top.geometry("+220+60") | ||
t3 = Tester(root) | ||
t3.top.geometry("+340+60") | ||
i1 = Icon("ICON1") | ||
i2 = Icon("ICON2") | ||
i3 = Icon("ICON3") | ||
i1.attach(t1.canvas) | ||
i2.attach(t2.canvas) | ||
i3.attach(t3.canvas) | ||
root.mainloop() |