Start: Can display svg and get mouse events and coordinates

main
Micke Nordin 2 years ago
commit 326b563917
Signed by: micke
GPG Key ID: 0DA0A7A5708FE257

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Georeference</name>
<id>org.smolnet.code.inkscape-coordinates</id>
<description>Geo reference an image</description>
<effect>
<effects-menu>
<submenu name="Georeference"/>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">coordinates_extension.py</command>
</script>
</inkscape-extension>

@ -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()

@ -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',),
]
Loading…
Cancel
Save