2010-06-10 12:52:36 +00:00
|
|
|
# Terminator by Chris Jones <cmsj@tenshu.net>
|
|
|
|
# GPL v2 only
|
|
|
|
"""terminalshot.py - Terminator Plugin to take 'screenshots' of individual
|
|
|
|
terminals"""
|
|
|
|
|
|
|
|
import os
|
2014-09-19 14:08:08 +00:00
|
|
|
from gi.repository import Gtk
|
2016-12-20 19:33:50 +00:00
|
|
|
from gi.repository import GdkPixbuf
|
2010-06-10 12:52:36 +00:00
|
|
|
import terminatorlib.plugin as plugin
|
|
|
|
from terminatorlib.translation import _
|
|
|
|
from terminatorlib.util import widget_pixbuf
|
|
|
|
|
2010-06-10 15:56:17 +00:00
|
|
|
# Every plugin you want Terminator to load *must* be listed in 'AVAILABLE'
|
|
|
|
AVAILABLE = ['TerminalShot']
|
2010-06-10 12:52:36 +00:00
|
|
|
|
|
|
|
class TerminalShot(plugin.MenuItem):
|
|
|
|
"""Add custom commands to the terminal menu"""
|
|
|
|
capabilities = ['terminal_menu']
|
2014-09-19 14:08:08 +00:00
|
|
|
dialog_action = Gtk.FileChooserAction.SAVE
|
2015-08-04 01:17:05 +00:00
|
|
|
dialog_buttons = (_("_Cancel"), Gtk.ResponseType.CANCEL,
|
|
|
|
_("_Save"), Gtk.ResponseType.OK)
|
2010-06-10 12:52:36 +00:00
|
|
|
|
2010-06-10 15:53:53 +00:00
|
|
|
def __init__(self):
|
|
|
|
plugin.MenuItem.__init__(self)
|
2010-06-10 12:52:36 +00:00
|
|
|
|
|
|
|
def callback(self, menuitems, menu, terminal):
|
|
|
|
"""Add our menu items to the menu"""
|
2015-08-04 01:17:05 +00:00
|
|
|
item = Gtk.MenuItem.new_with_mnemonic(_('Terminal _screenshot'))
|
2010-06-10 12:52:36 +00:00
|
|
|
item.connect("activate", self.terminalshot, terminal)
|
|
|
|
menuitems.append(item)
|
|
|
|
|
2010-06-10 15:53:53 +00:00
|
|
|
def terminalshot(self, _widget, terminal):
|
|
|
|
"""Handle the taking, prompting and saving of a terminalshot"""
|
2010-06-10 12:52:36 +00:00
|
|
|
# Grab a pixbuf of the terminal
|
|
|
|
orig_pixbuf = widget_pixbuf(terminal)
|
|
|
|
|
2015-08-03 19:15:28 +00:00
|
|
|
savedialog = Gtk.FileChooserDialog(title=_("Save image"),
|
2010-06-10 15:53:53 +00:00
|
|
|
action=self.dialog_action,
|
|
|
|
buttons=self.dialog_buttons)
|
2016-12-12 19:45:50 +00:00
|
|
|
savedialog.set_transient_for(_widget.get_toplevel())
|
2010-06-10 12:52:36 +00:00
|
|
|
savedialog.set_do_overwrite_confirmation(True)
|
|
|
|
savedialog.set_local_only(True)
|
|
|
|
|
|
|
|
pixbuf = orig_pixbuf.scale_simple(orig_pixbuf.get_width() / 2,
|
|
|
|
orig_pixbuf.get_height() / 2,
|
2014-09-19 14:08:08 +00:00
|
|
|
GdkPixbuf.InterpType.BILINEAR)
|
2016-12-20 19:33:50 +00:00
|
|
|
image = Gtk.Image.new_from_pixbuf(pixbuf)
|
2010-06-10 12:52:36 +00:00
|
|
|
savedialog.set_preview_widget(image)
|
|
|
|
|
|
|
|
savedialog.show_all()
|
|
|
|
response = savedialog.run()
|
2010-06-10 13:51:24 +00:00
|
|
|
path = None
|
2014-09-19 14:08:08 +00:00
|
|
|
if response == Gtk.ResponseType.OK:
|
2010-06-10 12:52:36 +00:00
|
|
|
path = os.path.join(savedialog.get_current_folder(),
|
|
|
|
savedialog.get_filename())
|
2016-12-20 19:33:50 +00:00
|
|
|
orig_pixbuf.savev(path, 'png', [], [])
|
2010-06-10 12:52:36 +00:00
|
|
|
|
2010-06-10 15:53:53 +00:00
|
|
|
savedialog.destroy()
|