Timer Plugin or Script?

Hi there,

I want to create a Reporter plugin that functions as a timer, displaying next to the currently edited glyph, to help me keep track of how much time I spend on it (in line with the Pomodoro Technique).

My idea is to use the updateInterfaceCallback to record the name of selectedLayers[0] if it’s existed. When the name of the new glyph is different from the last record, the timer will write the timer’s time into userData for accumulation in the next session.

However, it appears that updateInterfaceCallback gets called even when I’m working on the same glyph, making my idea ineffective.

Do you have any suggestions for implementing a timer, or perhaps know of an existing plugin that serves this purpose?

Thank you.

1 Like

You could try using GSGlyph.lastChange.

updateInterfaceCallback is called on every change in the ui, not only when working on the same glyph. But even when the selection changes, or you move your text cursor, etc. So if you use that, you need to filter out what changes you prefer.

GSGlyph.lastChange could be one helpful data, but I guess for your plan you might need to mix it with update callbacks, because using only the lastChange could mislead, as you might need to keep track of when you leave and come back to that glyph (otherwise the time will accumulate even if you work on another glyph).

Isn’t it tricky to filter out what “working on a glyph” is and is not in the first place? Having the layer open? Dragging the cursor across it? Modifying the curves? Spacing, kerning and proofing…? Might be more reliable to play/pause the timer manually.

Well, defining what kind of action is “working” can be a bit challenging.

In my concept, as long as a layer is selected, whether the cursor is actively being moved or not, I consider that I’m working on it.

A manual timer seems another solution, thank you all.

Then just refresh the timer when the layer changes and add that into the layer’s timer? Here’s a quick macro sketch that seems to do so (needs finishing especially when no layer is selected etc.). Note that text/typing mode also counts as selectedLayers[0].

# Count time of the layer being selected.
from vanilla import FloatingWindow
import time

class Timer():
	def __init__(self):
		self.currentLayer = Glyphs.font.selectedLayers[0] if Glyphs.font.selectedLayers else None
		self.start = time.time()
		self.w = FloatingWindow((100, 100))
		self.w.bind('close', self.removeCallbacks)
	def addCallbacks(self):
		Glyphs.addCallback( self.updateInterface, UPDATEINTERFACE )
	def removeCallbacks(self, sender):
		Glyphs.removeCallback( self.updateInterface, UPDATEINTERFACE )
	def updateInterface(self, sender):			
		# layer has changed
		if self.currentLayer != Glyphs.font.selectedLayers[0]:
			# get time elapsed 
			timeElapsed = time.time() - self.start
			# save in the current layer user data
			if 'timer' not in self.currentLayer.userData:
				self.currentLayer.userData['timer'] = timeElapsed
				print('Layer’s initial timer: ', self.currentLayer.userData['timer'])
				print('Layer’s previous timer: ', self.currentLayer.userData['timer'])
				print('Time elapsed: ', timeElapsed)
				self.currentLayer.userData['timer'] += timeElapsed
				print('Layer’s new timer: ', self.currentLayer.userData['timer'])
			# reset timer
			self.start = time.time()
			self.currentLayer = Glyphs.font.selectedLayers[0]

1 Like