July 21, 2017, 3:13am
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.)
July 21, 2017, 11:01am
What I could find briefly is this fragment:
controller = Font.currentTab.view().window().windowController()
tool = controller.toolEventHandler()
I just don’t know what argument to pass into the
mouseDown_ or if it is the proper thing at all
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.
July 27, 2017, 2:40am
I’m confused. This is in a reporter plugin, and currently it’s picking up mouse moved events like so:
def mouseDidMove(self, notification):
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?
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
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
NSNotificationCenter.defaultCenter().removeObserver_name_object_(self, MOUSEMOVED, objc.nil)
self.hasObserver = False
self.hasObserver has to be set to
self.settings. Sometimes the
willActivate is called more than once so you need to make sure you don’t add the observer twice.
Thanks Georg, I’ll try this later
December 13, 2019, 6:24pm
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?
January 4, 2021, 12:23pm
For anybody else who finds this thread about mouse events. The expected
MOUSEUP are supported as of now in Glyphs 3, but
missing from the documentation.