Mouse click events in reporter

Is there a way for a reporter to get notified when certain mouse events happen? I want to freeze a reporter’s view on a particular signal (say a Ctrl-doubleclick).

(If not, I can put it in a context menu option, but it wouldn’t be as user friendly.)

What I could find briefly is this fragment:

controller = Font.currentTab.view().window().windowController()
# OR:
tool = controller.toolEventHandler()

I just don’t know what argument to pass into the mouseDown_ or if it is the proper thing at all :slight_smile:

The tool.mouseDown_ methods should not be called manually. They are called by the system. I just added support for mouseDown/Up. It works like the existing mouseMoved callback.

1 Like

I’m confused. This is in a reporter plugin, and currently it’s picking up mouse moved events like so:

def willActivate(self):
    Glyphs.addCallback(self.mouseDidMove, MOUSEMOVED)

def mouseDidMove(self, notification):

There’s no MOUSEDOWN in the ObjectWrapper at the moment. Can I receive notifications by implementing a mouseDown method, or…?

In the upcoming cutting edge version, yes.

I’m having difficulty getting this to work. I’ve added Glyphs.addCallback(self.somefunction, MOUSEDOWN), but Glyphs then doesn’t launch, saying there no global variable for MOUSEDOWN.

How should one go about running a function on mousedown in a reporter plugin?

Which version of Glyphs are you running?

I was using an older beta, but just updated to build 1134. I still get the same error. This is the code, in the ReporterPlugin; maybe I’m putting things in the wrong place?

def willActivate(self):
		Glyphs.addCallback(self.mouseDidMove, MOUSEMOVED)
		Glyphs.addCallback(self.mouseDidPress, MOUSEDOWN)
		print traceback.format_exc()

def willDeactivate(self):
		Glyphs.removeCallback(self.mouseDidMove, MOUSEMOVED)
		Glyphs.removeCallback(self.mouseDidPress, MOUSEDOWN)
		print traceback.format_exc()

		import traceback

Ok, so explicitly calling from GlyphsApp import MOUSEDOWN stopped the error that there was no global variable of that name. However, a simple print statement in the self.mouseDidPress function attributed to the callback isn’t working. Is this implemented in the current version? If so, and I’m being blind to something obvious let me know. I though there was something on callbacks in the SDK docs but can’t find it at all and not sure if I just imagined it

The doc needs a little updating. I need to some testing myself before I can give you a proper answer. Other callback hooks work as expected for you?

The wrapper callbacks are a bit difficult because they try to do to things at once. Thy should work with scripts and with plugins. Specially removing is a bit tricky. Until we solve that, can you use the native API:

	def mouseDidMove(self, event):
		print "__mouseDidMove", event
	def willActivate(self):
		if not self.hasObserver:
			selector = objc.selector(self.mouseDidMove, signature="v@:@")
			NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, selector, MOUSEMOVED, objc.nil)
			self.hasObserver = True

	def willDeactivate(self):
		if self.hasObserver:
			NSNotificationCenter.defaultCenter().removeObserver_name_object_(self, MOUSEMOVED, objc.nil)
			self.hasObserver = False

The self.hasObserver has to be set to False in self.settings. Sometimes the willActivate is called more than once so you need to make sure you don’t add the observer twice.

1 Like

Thanks Georg, I’ll try this later

In an objc reporter i got the “mouseDownNotification” and the “mouseUpNotification” working, but trying to implement the “mouseMovedNotification” exactly the same way, it doesn’t get fired. Any clues why?

For anybody else who finds this thread about mouse events. The expected MOUSEDOWN and MOUSEUP are supported as of now in Glyphs 3, but missing from the documentation.