initial test
This commit is contained in:
+62
-3
@@ -26,7 +26,7 @@ import gi
|
|||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
|
|
||||||
import xdot.ui
|
import xdot.ui
|
||||||
from gi.repository import Gio, Gtk
|
from gi.repository import Gdk, Gio, GObject, Gtk
|
||||||
|
|
||||||
|
|
||||||
def __icon_button__(icon_name: str) -> Gtk.Button:
|
def __icon_button__(icon_name: str) -> Gtk.Button:
|
||||||
@@ -37,6 +37,13 @@ def __icon_button__(icon_name: str) -> Gtk.Button:
|
|||||||
return button
|
return button
|
||||||
|
|
||||||
|
|
||||||
|
def get_handler_id(obj, signal_name):
|
||||||
|
signal_id, detail = GObject.signal_parse_name(signal_name, obj, True)
|
||||||
|
return GObject.signal_handler_find(
|
||||||
|
obj, GObject.SignalMatchType.ID, signal_id, detail, None, None, None
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class MyDotWindow(Gtk.Window):
|
class MyDotWindow(Gtk.Window):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(title="Test")
|
super().__init__(title="Test")
|
||||||
@@ -71,10 +78,11 @@ class MyDotWindow(Gtk.Window):
|
|||||||
self.search_entry = Gtk.Entry()
|
self.search_entry = Gtk.Entry()
|
||||||
self.search_entry.connect("activate", self.search)
|
self.search_entry.connect("activate", self.search)
|
||||||
self.search_entry.connect("changed", self.search)
|
self.search_entry.connect("changed", self.search)
|
||||||
|
self.search_entry.connect("key-press-event", self.search_key_pressed)
|
||||||
self.search_entry.set_placeholder_text("Search...")
|
self.search_entry.set_placeholder_text("Search...")
|
||||||
|
|
||||||
box.add(self.search_entry)
|
box.add(self.search_entry)
|
||||||
button = __icon_button__("find")
|
button = __icon_button__("edit-find")
|
||||||
button.connect("clicked", self.search)
|
button.connect("clicked", self.search)
|
||||||
box.add(button)
|
box.add(button)
|
||||||
|
|
||||||
@@ -83,6 +91,9 @@ class MyDotWindow(Gtk.Window):
|
|||||||
self.add(self.dot)
|
self.add(self.dot)
|
||||||
|
|
||||||
self.set_focus(self.dot)
|
self.set_focus(self.dot)
|
||||||
|
self.dot.connect("clicked", self.on_click)
|
||||||
|
self.dot.disconnect(get_handler_id(self.dot, "key-press-event"))
|
||||||
|
self.dot.connect("key-press-event", self.on_key_pressed)
|
||||||
|
|
||||||
def set_dotcode(self, code):
|
def set_dotcode(self, code):
|
||||||
self.dot.set_dotcode(code)
|
self.dot.set_dotcode(code)
|
||||||
@@ -110,11 +121,59 @@ class MyDotWindow(Gtk.Window):
|
|||||||
else:
|
else:
|
||||||
self.dot.set_highlight(None, search=True)
|
self.dot.set_highlight(None, search=True)
|
||||||
|
|
||||||
|
def search_key_pressed(self, _, event):
|
||||||
|
if event.keyval == 65307:
|
||||||
|
self.set_focus(self.dot)
|
||||||
|
|
||||||
|
def on_click(self, _, url, event):
|
||||||
|
print(url, event)
|
||||||
|
# center element
|
||||||
|
x, y = int(event.x), int(event.y)
|
||||||
|
jump = self.dot.get_jump(x, y)
|
||||||
|
if jump is not None:
|
||||||
|
self.dot.animate_to(jump.x, jump.y)
|
||||||
|
|
||||||
|
def on_key_pressed(self, _, event):
|
||||||
|
if event.keyval in (Gdk.KEY_f, Gdk.KEY_slash):
|
||||||
|
self.set_focus(self.search_entry)
|
||||||
|
return True
|
||||||
|
if event.keyval == Gdk.KEY_w:
|
||||||
|
self.dot.zoom_to_fit()
|
||||||
|
return True
|
||||||
|
if event.keyval == Gdk.KEY_plus:
|
||||||
|
self.dot.zoom_image(self.dot.zoom_ratio * 1.1)
|
||||||
|
return True
|
||||||
|
if event.keyval == Gdk.KEY_minus:
|
||||||
|
self.dot.zoom_image(self.dot.zoom_ratio / 1.1)
|
||||||
|
return True
|
||||||
|
if event.keyval == Gdk.KEY_equal:
|
||||||
|
self.dot.zoom_image(1.0)
|
||||||
|
return True
|
||||||
|
if event.keyval == Gdk.KEY_Left:
|
||||||
|
self.dot.x -= self.dot.POS_INCREMENT / self.dot.zoom_ratio
|
||||||
|
self.dot.queue_draw()
|
||||||
|
return True
|
||||||
|
if event.keyval == Gdk.KEY_Right:
|
||||||
|
self.dot.x += self.dot.POS_INCREMENT / self.dot.zoom_ratio
|
||||||
|
self.dot.queue_draw()
|
||||||
|
return True
|
||||||
|
if event.keyval == Gdk.KEY_Up:
|
||||||
|
self.dot.y -= self.dot.POS_INCREMENT / self.dot.zoom_ratio
|
||||||
|
self.dot.queue_draw()
|
||||||
|
return True
|
||||||
|
if event.keyval == Gdk.KEY_Down:
|
||||||
|
self.dot.y += self.dot.POS_INCREMENT / self.dot.zoom_ratio
|
||||||
|
self.dot.queue_draw()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
dotcode = b"""
|
dotcode = b"""
|
||||||
digraph G {
|
digraph G {
|
||||||
|
node [fontname="Hack", shape=rect]
|
||||||
Hello [URL="http://en.wikipedia.org/wiki/Hello"]
|
Hello [URL="http://en.wikipedia.org/wiki/Hello"]
|
||||||
World [URL="http://en.wikipedia.org/wiki/World"]
|
World [URL="World,Test
|
||||||
|
layout.set_attributes(attrs)"]
|
||||||
|
Test
|
||||||
Hello -> World
|
Hello -> World
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user