Getting mouse position in GlyphPreview in ObjectGs.py

Hi,

Sorry, preformatted text not working…

I am trying to getting mouse position in GlyphPreview() in ObjectGS.py.
I tried two ways like below, but I got errors with the ways. How can I solve it?

1. in class GlyphPreviewView(NSView):

    def mouseDown_(self, event):
        try:
            if event.clickCount() == 2:
                if self._delegate.mouseDoubleDownCallBack:
                    self._delegate.mouseDoubleDownCallBack(self)
                    # --------------------------------
                    location = event.locationInWindow
                    pt = self.convertPoint_fromView_(location,None)
                    # --------------------------------
                return;
            if self._delegate.mouseDownCallBack:
                self._delegate.mouseDownCallBack(self)
        except:
            print traceback.format_exc()

Error Message
pt = self.convertPoint_fromView(location, None)_
TypeError: depythonifying struct, got no sequence


2. in class Preview(GeneralPlugin):

    def showWindow(self, sender):
        self.w = Window((w, h), 'Preview', minSize=(300, 300))
        self.w.Preview = GlyphPreview((0, 0, -0, -40))

    def mouseDoubleDownCallBack(self, sender):
        pt = self.w.mouseLocationOutsideOfEventStream()
        print self.w.Preview._nsObject.convertPoint_fromView_(pt, self)

and the error message is like below.
Error Message
pt = self.w.mouseLocationOutsideOfEventStream()
AttributeError: ‘Window’ object has no attribute ‘mouseLocationOutsideOfEventStream’

Thanks in advance.

(I edited you post. When you add three grave characters before and after code, it will look much nicer.)

On those cases, it helps a lot, if you add a print "__location", location before the line that throws the error. That way you might get an idea what is going on. And in this case it might be that you need some parenthesis after event.locationInWindow > event.locationInWindow().

1 Like