From 326b563917f9e9e3f2737b5ac95b4b1646108c7b Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Thu, 25 Aug 2022 00:24:01 +0200 Subject: [PATCH] Start: Can display svg and get mouse events and coordinates --- coordinates_extension.inx | 14 ++++++++ coordinates_extension.py | 74 +++++++++++++++++++++++++++++++++++++++ coordinates_test.py | 31 ++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 coordinates_extension.inx create mode 100755 coordinates_extension.py create mode 100644 coordinates_test.py diff --git a/coordinates_extension.inx b/coordinates_extension.inx new file mode 100644 index 0000000..638d042 --- /dev/null +++ b/coordinates_extension.inx @@ -0,0 +1,14 @@ + + + Georeference + org.smolnet.code.inkscape-coordinates + Geo reference an image + + + + + + + diff --git a/coordinates_extension.py b/coordinates_extension.py new file mode 100755 index 0000000..4745a0b --- /dev/null +++ b/coordinates_extension.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +# coding=utf-8 +# +# Copyright (C) 2022 Mikael Nordin, hej@mic.ke +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # noqa: E501 +# +""" +Description of this extension +""" +import inkex +import inkex.gui +import gi + +gi.require_version("Gtk", "3.0") +gi.require_version("Gdk", "3.0") +from gi.repository import Gtk, Gdk # noqa: E402 + + +class GeoReferencerWindow(Gtk.Window): + def __init__(self, svg): + super().__init__(title="Georeferencer") + self.svg = svg + self.set_events(Gdk.EventMask.POINTER_MOTION_MASK | + Gdk.EventMask.BUTTON_PRESS_MASK) + self.box = Gtk.Box() + self.add(self.box) + self.button = Gtk.Button(label="Georeference") + self.button.connect("clicked", self.on_button_clicked) + self.box.pack_start(self.button, True, True, 0) + self.pix_man = inkex.gui.pixmap.PixmapManager() + self.pixmap = self.pix_man.get_pixmap(self.svg) + self.event_box = Gtk.EventBox() + self.image = Gtk.Image.new_from_pixbuf(self.pixmap) + self.event_box.add(self.image) + self.event_box.set_above_child(above_child=True) + self.event_box.connect('motion-notify-event', self.on_motion_notify) + self.event_box.connect('enter-notify-event', self.on_motion_notify) + self.event_box.connect('button-press-event', self.on_mouse_click) + self.box.pack_start(self.event_box, True, True, 0) + self.connect("destroy", Gtk.main_quit) + + def on_button_clicked(self, widget): + self.destroy() + + def on_motion_notify(self, widget, event): + widget.set_tooltip_text("x:{}, y:{}".format(event.x, event.y)) + + def on_mouse_click(self, widget, event): + widget.set_tooltip_text("HAHA x:{}, y:{}".format(event.x, event.y)) + + +class CoordinatesExtension(inkex.EffectExtension): + + def effect(self): + self.window = GeoReferencerWindow(self.svg.tostring()) + self.window.show_all() + self.eventloop = Gtk.main() + + +if __name__ == '__main__': + CoordinatesExtension().run() diff --git a/coordinates_test.py b/coordinates_test.py new file mode 100644 index 0000000..cf869fb --- /dev/null +++ b/coordinates_test.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +# coding=utf-8 +""" +Test elements extra logic from svg xml lxml custom classes. +""" + +from inkex.tester import TestCase +from inkex.tester.inx import InxMixin + +from my_effect_extension import UnnamedEffectExtension + +import sys +sys.path.insert(0, '.') + +class UnnamedBasicTestCase(InxMixin, TestCase): + """Test INX files and other things""" + def test_inx_file(self): + """Get all inx files and test each of them""" + self.assertInxIsGood("tutorial_01.inx") + + def test_other_things(self): + """Things work out""" + pass + +class UnnamedComparisonsTestCase(ComparisonMixin, TestCase): + """Test input and output variations""" + effect_class = UnnamedEffectExtension + comparisons = [ + ('--my_option=True',), + ('--my_option=False',), + ]