It is possible to modify Preview Blur value with a script ?
I can’t find info in the API doc.
The code above is for when you want to implement the blur in a different view (e.g. when writing your own plugin). You can get the current blur value like so:
blurRadius = Glyphs.defaults['GSPreview_Radius']
Writing to this value is also possible, but it will not change the value for already opened tabs, only newly opened tabs:
Glyphs.defaults['GSPreview_Radius'] = 15
The value is in the range 0–20.
Thanks Florian,
So a hack to actualise the preview is to close/reopen current tab ?
You could probably hack your way into the slider of the current tab and manipulate that, but that might break sooner or later. What are you trying to do? Then we might be able to get to a cleaner solution.
I would like to write a script to toggle blur value without to having to do it manually with the slider.
This script work but it’s a bit glitchy :
font = Glyphs.font
blurRadius = Glyphs.defaults['GSPreview_Radius']
tabIndex = -1
if blurRadius == 0:
Glyphs.defaults['GSPreview_Radius'] = 5
savedTabText = font.currentTab.text
for tab in font.tabs:
tabIndex += 1
if tab == font.currentTab:
font.tabs[tabIndex-1].close()
font.newTab(savedTabText)
break
else :
Glyphs.defaults['GSPreview_Radius'] = 0
savedTabText = font.currentTab.text
for tab in font.tabs:
tabIndex += 1
if tab == font.currentTab:
font.tabs[tabIndex-1].close()
font.newTab(savedTabText)
break
The blur can be set directly:
Font.currentTab.previewView().setRadius_(0)
print(Font.currentTab.previewView().radius())
This also sets the defaults["GSPreview_Radius"]
.
Thanks !
#MenuTitle: Toggle Blur in Preview Bar
# -*- coding: utf-8 -*-
font = Glyphs.font
if not font.userData["com.hugojourdan.TogglePreviewBlurValue"]:
font.userData["com.hugojourdan.TogglePreviewBlurValue"] = Font.currentTab.previewView().radius()
if Font.currentTab.previewView().radius() != 0:
font.userData["com.hugojourdan.TogglePreviewBlurValue"] = Font.currentTab.previewView().radius()
Font.currentTab.previewView().setRadius_(0)
else:
Font.currentTab.previewView().setRadius_(font.userData["com.hugojourdan.TogglePreviewBlurValue"])
font.userData["com.hugojourdan.TogglePreviewBlurValue"] = Font.currentTab.previewView().radius()
I think you don’t need the last line in your script.