Skip to content

Instantly share code, notes, and snippets.

@mmmunk
Last active February 8, 2021 14:10
Show Gist options
  • Save mmmunk/29b7f2b43c39c23550d83feed9dc77ff to your computer and use it in GitHub Desktop.
Save mmmunk/29b7f2b43c39c23550d83feed9dc77ff to your computer and use it in GitHub Desktop.
Quick'n'dirty ½-færdigt hello world Eye of Gnome plugin inkluderende en ½-færdig dialog
# Placeres i ~/.local/share/eog/plugins
# Baseret på https://wiki.gnome.org/Apps/EyeOfGnome/Plugins
from gi.repository import GObject, Gdk, Gtk, Eog
class TextDialog(Gtk.Dialog):
def __init__(self, parent, initialtext):
Gtk.Dialog.__init__(self, title="My Dialog", transient_for=parent, flags=0)
self.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK, Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
self.set_default_size(300, 100)
box = self.get_content_area()
box.add(Gtk.Label(label='Image text'))
box.add(Gtk.Entry(text=initialtext))
self.show_all()
class HelloWorldPlugin(GObject.Object, Eog.WindowActivatable):
window = GObject.property(type=Eog.Window)
key_press_id = None
@property
def view(self):
return self.window.get_view()
def key_press_cb(self, widget, event):
assert widget is self.view
#if event.state & Gdk.ModifierType.MODIFIER_MASK != 0:
if event.keyval != Gdk.KEY_t:
return False
#print(event.state)
#print(event.keyval)
im = self.window.get_image()
fi = im.get_file()
#fi.get_basename()
#fi.get_path()
dialog = TextDialog(self.window, 'image text here')
dialog.run()
dialog.destroy()
return True
def do_activate(self):
print('The answer landed on my rooftop, whoa')
#TODO: Bør være en Accel/Action i stedet for at kapre key-press-event:
self.key_press_id = self.view.connect('key-press-event', self.key_press_cb)
def do_deactivate(self):
print('The answer fell off my rooftop, woot')
self.view.disconnect(self.key_press_id)
self.key_press_id = None
[Plugin]
Module=eog-helloworld
IAge=2
Loader=python3
Name=Hellloooooooooo
Icon=postr
Description=Print a greeting to the console where eog is running
Authors=Somebody <some@email>
Copyright=Copyright © 2021 Creative Commons
Website=about:blank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment