currentVisibleRect doesn't work

bug

#1

Since a recent update this script stopped working, I use it to sync up the cursor position and zoom level between font files:

Font = Glyphs.font

thisTab = Font.currentTab

currentGraphicView = thisTab.graphicView()
currentVisibleRect = currentGraphicView.visibleRect()
currentScale = currentGraphicView.scale()
currentSelectedRange = currentGraphicView.selectedRange()
currentFrameHeight = thisTab.previewHeight
currentMasterIndex =  thisTab.masterIndex()

for eachFont in Glyphs.fonts:
	otherTab = eachFont.currentTab
	otherGraphicView = eachFont.currentTab.graphicView()
	otherGraphicView.setSelectedRange_(currentSelectedRange)
	otherGraphicView.zoomViewToAbsoluteScale_(currentScale)
	otherGraphicView.scrollRectToVisible_(currentVisibleRect)
	otherTab.previewHeight = currentFrameHeight
	otherTab.setMasterIndex_(currentMasterIndex)

Glyphs.redraw()

Seems something with the currentVisibleRect doesn’t work. i.e. if i duplicate a file, and have the same text in a tab, and run the script the view positions do not match up like they used to.


#2

I think this effects @Mark’s sync tab plugin and also @Tosche’s script.


#3

It is not the visibleRect() but the scrollRectToVisible_(). I fixed it.


#4

This issue came up again.


#5

What exactly happened. Can you show some code?


#6

Exactly the same thing as original post.


#7

I tried to run your code from above in the macro window and it did work. Do you get any errors?


#8

No errors just the window doesn’t sync up anymore, please see the video.

  1. I got this file,
  2. duplicated it
  3. Opened both and put this text in
Dienstag, 9.11.2010, 53°57,5’ N 008°01,5’ E, +49.(0)89.333 990, 04:05 Uhr, 324 453 m, 14 kg, Seite 37–39, 1422–1498 1422– nach 1498, Mo – Fr 09:30–20:00, 0.1–1.7% carbon, Fishing off Delmarva.
  1. Ran the script

Previously the windows font size and position synced up perfectly – when both are the same size with the same preview panel height, now the positions are always slightly off.

This script is very important for my workflow when comparing different files.


(Oddly the master icon doesn’t change even though the master has changed)

Version 2.6.1 (1206)


#9

I found the problem:
use this line to get to the visible rect.

currentVisibleRect = thisTab.frameView().visibleRect()

edit:
It turned out it is fixed in 2.6.1 already, if you use the correct API:

Font = Glyphs.font
thisTab = Font.currentTab

currentVisibleRect = thisTab.viewPort
currentScale = thisTab.scale
currentSelectedRange = thisTab.textRange
currentFrameHeight = thisTab.previewHeight
currentMasterIndex = Font.masterIndex

for eachFont in Glyphs.fonts:
	if Font == eachFont:
		continue
	otherTab = eachFont.currentTab
	otherTab.setMasterIndex_(currentMasterIndex)
	otherTab.textRange = currentSelectedRange
	otherTab.scale = currentScale
	otherTab.viewPort = currentVisibleRect
	otherTab.previewHeight = currentFrameHeight

The masterIndex was set to late, so if the masterIndex was different it would produce a wrong positioning.
I added a .masterIndex property to the Tab. So with the next update you can do (just cosmetics):

Font = Glyphs.font
thisTab = Font.currentTab

currentVisibleRect = thisTab.viewPort
currentScale = thisTab.scale
currentSelectedRange = thisTab.textRange
currentFrameHeight = thisTab.previewHeight
currentMasterIndex = thisTab.masterIndex

for eachFont in Glyphs.fonts:
	if Font == eachFont:
		continue
	otherTab = eachFont.currentTab
	otherTab.masterIndex = currentMasterIndex
	otherTab.textRange = currentSelectedRange
	otherTab.scale = currentScale
	otherTab.viewPort = currentVisibleRect
	otherTab.previewHeight = currentFrameHeight

if you need it in 2.6:

Font = Glyphs.font

thisTab = Font.currentTab

currentVisibleRect = thisTab.viewPort
currentScale = thisTab.scale
currentSelectedRange = thisTab.textRange
currentFrameHeight = thisTab.previewHeight
currentMasterIndex =  Font.masterIndex

print currentVisibleRect
print currentScale
print currentFrameHeight

for eachFont in Glyphs.fonts:
	if Font == eachFont:
		continue
	otherTab = eachFont.currentTab
	otherTab.textRange = currentSelectedRange
	otherTab.scale = currentScale
	otherTab.frameView().zoomViewToRect_(currentVisibleRect)
	otherTab.previewHeight = currentFrameHeight
	otherTab.setMasterIndex_(currentMasterIndex)

(do you remember why you needed the Glyphs.redraw())


#10

Thanks for taking the time to fix and explain that Georg. I appreciate it! Can’t remember why I did the redraw.

One thing is that the cursor doesn’t seem to sync up.
I realised I had to use textCursor to sync up the cursor!


#11

But the otherTab.textRange = currentSelectedRange should take case of that. Are you saying that is not working for you?


#12

It only syncs the length of the selection not the position


#13

Yes. I just saw that. The textRange property is confusing me sometimes (I didn’t write that part myself).

you need to do that also.

otherTab.textCursor = currentSelectedCursor