← Back to team overview

zim-wiki team mailing list archive

Re: Request for Plugin

 

Hi Bo,
Until someone writes a decent plugin to solve this properly, I've made a rather simple implementation which I hope can at least partially save your neck in the meantime :). It automatically scrolls the text to the center of the window after pressing some keys like Up, Down, Enter etc. If the text is near the beginning/end scrolling is disabled, to avoid this you can temporarily put there some text or newlines. To install it put the file to the plugins' directory and enable it in preferences. You can enable/disable it by clicking on the toggle button in the Toolbar menu. It shouldn't break anything but as with all programs keep backups.
Regards, Pl

On 20.04.2016 , Bo Grimes wrote:
I don't like looking at the bottom of the screen all the time. Hurts my neck for one. Since the physical structure of my desk prevents me from raising the monitor more than 3 inches off the desk (roll top), my other option is to resize my window to only go to half screen. I don't like that either, and can't in fullscreen mode.

I first discovered typewriter scroll with Scrivener, and would love to see a plug-in for Zim that can be turned on and off, like Sublime Text has. See: https://github.com/alehandrof/Typewriter.

I have no idea how difficult this might be. I am willing to pay $100.00 for the development of this plug-in, that also works in fullscreen mode and on both Windows and Linux versions. That isn't much--unless it took 5 minutes and 10 lines of code--but all I could offer. If multiple parties wished to cooperate to develop it, I could make it a donation to Zim instead or divide it equally across the developers, so I guess upfront coordination would be necessary to avoid duplication of time and effort. It would need to be more than an Emacs M-x recenter, though even that is better than every word processor ever made.

I really don't know how supporting developers directly works, as I have only supported projects, so if I sound stupid or naive or it's too hard and I'm showing ignorance, you can mock me (but be gentle, please). But if this is do-able and the list is an appropriate place to hammer it out or others also wish to support this then great!

Cheers,
Bo Grimes

# -*- coding: utf-8 -*-

# Copyright 2016 Pavel_M <plprgt@xxxxxxxxx>,
# released under the GNU GPL (v2 or v3).
# This plugin is for Zim program by Jaap Karssenberg <jaap.karssenberg@xxxxxxxxx>.

import gobject
import gtk

from zim.actions import toggle_action
from zim.plugins import PluginClass, extends, WindowExtension

import logging
logger = logging.getLogger('zim.plugins.ScrollToCenter')


class ScrollToCenterPlugin(PluginClass):

	plugin_info = {
	'name': _('ScrollToCenter'), # T: plugin name
	'description': _('''\
		This plugin automatically scrolls textview to keep typed text in the center.
		'''), # T: plugin description
	'author': 'Pavel_M',
	'help': 'Plugins:ScrollToText',}


KEYVALS_SCROLL = map(gtk.gdk.keyval_from_name, ('Up', 'Down', 'Page_Up', 'Page_Down'))
KEYVALS_ENTER = map(gtk.gdk.keyval_from_name, ('Return', 'KP_Enter', 'ISO_Enter'))

@extends('MainWindow')
class ScrollToCenterExtension(WindowExtension):
	uimanager_xml = '''
	<ui>
	<toolbar name='toolbar'>
		<placeholder name='tools'>
			<toolitem action='toggle_scrolling'/>
		</placeholder>
	</toolbar>
	</ui>'''

	def __init__(self, plugin, window):
		WindowExtension.__init__(self, plugin, window)
		self._textview = self.window.pageview.view
		self._signal = None

	def _enable(self):
		if self._signal:
			self._disable()
		try:
			self._signal = self._textview.connect('key-release-event', self._scroll)
		except AttributeError:
			logger.error('ScrollToCenter: plugin is not initialized.')

	def _disable(self):
		if self._signal:
			self._textview.disconnect(self._signal)
			self._signal = None

	def teardown(self):
		self._disable()

	def _scroll(self, textview, event):
		if (event.keyval in KEYVALS_SCROLL \
		and not event.state & gtk.gdk.SHIFT_MASK) \
		or event.keyval in KEYVALS_ENTER:
			buffer = self._textview.get_buffer()
			self._textview.scroll_to_mark(buffer.get_insert(), within_margin = 0.0,
							use_align=True, xalign=0.0, yalign=0.5)

	@toggle_action(_('Enable Scrolling'), stock = gtk.STOCK_GOTO_BOTTOM,
			tooltip = 'Enable Scrolling') # T: menu item
	def toggle_scrolling(self, active):
		if active:
			self._enable()
		else:
			self._disable()



References