NOTICE : This article is out of date.
see update : my LineSpacing plugin for Gedit 3.12 and upper
I made tiny plugin script for Gedit 3. This plugin let line-spacing in gedit text pane.
File : linespacing.plugin
[Plugin] Loader=python Module=linespacing IAge=3 Name=Line-spacing Description=Increase or decrease space between lines Authors= Copyright= Website=
File : linespacing.py
from gi.repository import GObject, Gtk, Gedit UI_XML = """<ui> <menubar name="MenuBar"> <menu name="ToolsMenu" action="Tools"> <placeholder name="ToolsOps_3"> <menuitem name="LineSpacingAction0" action="LineSpacingAction0"/> <menuitem name="LineSpacingAction1" action="LineSpacingAction1"/> <menuitem name="LineSpacingAction2" action="LineSpacingAction2"/> </placeholder> </menu> </menubar> </ui>""" class LineSpacing(GObject.Object, Gedit.WindowActivatable): __gtype_name__ = "LineSpacing" window = GObject.property(type=Gedit.Window) def __init__(self): GObject.Object.__init__(self) def _add_ui(self): manager = self.window.get_ui_manager() self._actions = Gtk.ActionGroup("LineSpacingActions") self._actions.add_actions([ ('LineSpacingAction0', Gtk.STOCK_INFO, "Reset Line spacing", "<Control><Alt>0", "Reset Line spacing", self.on_linespacing_action_activate0), ('LineSpacingAction1', Gtk.STOCK_INFO, "Decrease Line spacing", "<Control><Alt>8", "Decrease Line spacing", self.on_linespacing_action_activate1), ('LineSpacingAction2', Gtk.STOCK_INFO, "Increase Line spacing", "<Control><Alt>9", "Increase Line spacing", self.on_linespacing_action_activate2), ]) manager.insert_action_group(self._actions) self._ui_merge_id = manager.add_ui_from_string(UI_XML) manager.ensure_update() def do_activate(self): self._add_ui() def do_deactivate(self): self._remove_ui() def do_update_state(self): pass def on_linespacing_action_activate0(self, action, data=None): view = self.window.get_active_view() if view: view.set_pixels_below_lines(0) view.set_pixels_inside_wrap(0) def on_linespacing_action_activate1(self, action, data=None): view = self.window.get_active_view() if view: if view.get_pixels_below_lines() >= 0: view.set_pixels_below_lines(view.get_pixels_below_lines() - 1) if view.get_pixels_inside_wrap() >= 0: view.set_pixels_inside_wrap(view.get_pixels_inside_wrap() - 1) def on_linespacing_action_activate2(self, action, data=None): view = self.window.get_active_view() if view: view.set_pixels_below_lines(view.get_pixels_below_lines() + 1) view.set_pixels_inside_wrap(view.get_pixels_inside_wrap() + 1) def _remove_ui(self): manager = self.window.get_ui_manager() manager.remove_ui(self._ui_merge_id) manager.remove_action_group(self._actions) manager.ensure_update()
To install, place these two files into $home/.local/share/gedit/plugins/ folder. (If these folder is not found, made it by hand)
And restart Gedit, pull down “Edit” -> “Settings”, “Plugin” tab. You’ll find “Line-Spacing” plugin, check it to enable.
After plugin enable, see Pull down “Tool” menu. You will see these three items.
1) Reset Line spacing Ctrl+Alt+0
2) Decrease Line spacing Ctrl+Alt+8
3) Increase Line spacing Ctrl+Alt+9
use pull down menu, or key combinations.
Notice :
at default, line spacing works for ‘Phisical line’, not ‘Logical line’. to let working for logical line, remark the line which contains ‘pixels_inside_wrap’.
$ mv linespacing.py linespacing.bak $ awk '{ if ($0 ~ "pixels_inside_wrap") { print "#" $0 } else print }' linespacing.bak > linespacing.py
I refered gedit3 plugin tutorial to write this plugin. Thanks !
Writing Plugins for gedit 3 with Python – micah carrick
http://www.micahcarrick.com/writing-plugins-for-gedit-3-in-python.html
I am sorry of my poor english and … enjoy !
log:fixed indentation on 2013/05/15
ピンバック: Ubuntu:gedit: how to increase spaces between lines? – Ubuntu Linux Questions