#!/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()