Disable buttons on PDF Viewer toolbar

Does anyone know if it’s possible to disable individual buttons from working on the PDF Viewer toolbar in the Vision client? I would like to disable the print and fullscreen buttons. Further this, is it possible to hide the disabled buttons?

Theoretically, something like this (in a propertyChange script) might do it:

if event.propertyName == "componentRunning":
	from org.icepdf.ri.util import PropertiesManager
	props = PropertiesManager.getInstance()
	props.setBoolean(PropertiesManager.PROPERTY_SHOW_UTILITY_PRINT, False)

Available keys are documented here:
http://res.icesoft.org/docs/icepdf/latest/viewer/org/icepdf/ri/util/PropertiesManager.html

Yes that worked, it wasn’t at first but that’s because I didn’t realise that you had to have Designer running in ‘preview mode’ and then you have to reload the window before the PDF Viewer is refreshed.

I managed to get hide a few components with:

if event.propertyName == "componentRunning":
	from org.icepdf.ri.util import PropertiesManager
	props = PropertiesManager.getInstance()
	props.setBoolean(PropertiesManager.PROPERTY_SHOW_TOOLBAR_UTILITY, False)
	props.setBoolean(PropertiesManager.PROPERTY_SHOW_UTILITY_SEARCH, False)
	props.setBoolean(PropertiesManager.PROPERTY_SHOW_UTILITY_PRINT, False)

Result is below, I went through the link you sent me but couldn’t seem to figure out how to remove the ‘Full Screen’ and ‘Show/Hide Form Highlighting’ buttons, I’ve marked them in the image below if anyone else has better luck?

Hi, I'm trying to do this for disabling the "Save As" button which doesn't seem to function in the first place.

Where do we put that scripting code in? I've tried scripting on the window, using EventHandlers/vision/visionWindowOpened and just get an error:

Traceback (most recent call last):
File "event:visionWindowOpened", line 1, in
AttributeError: 'com.inductiveautomation.factorypmi.application.com' object has no attribute 'propertyName'

Would this code be different for Ignition 8.1.35?

That code example needs to be in the propertyChange event script on the viewer itself. (Only a propertyChange event gets a propertyName field in its event object.)

Thanks for the quick response.
I've tried that now, and it seems to replicate the same bug unforunately.

My PDF viewer toolbar doesn't seem to have a "Save As" button. Which one is it?

This one:

Interesting; mine doesn't have that.

In any case, I would go about it like this:

Throw a test button in the window, and write a script to recursively find the JButtons, looking for a way to uniquely identify the "Save Button." The JButton's toolTipText property would probably work.

Example:

def listViewerButtons(viewer):
	for component in viewer.components:
		if 'JButton' in component.__class__.__name__:
			print component.toolTipText
		listViewerButtons(component)
viewer = event.source.parent.getComponent('PDF Viewer')
listViewerButtons(viewer)

When I run this on my PDF viewer, this is the output:

Print Document
Search Document
First Page
Previous Page
Next Page
Last Page
Zoom Out
Zoom In
Full Screen
Rotate Right
Rotate Left
Search markup annotations
Clear search results

In yours, I imagine that there will be a tool tip that says something like: "Save As"

If so, modify the recursive script to find it specifically:

# Recursive Script to hide JButtons based on toolTipText
def ButtonHider(component, toolTipText):

	# Cycle through all of the sub components of a given component
	for subComponent in component.components:

		# If there is a JButton with the given tool tip text, hide it
		if 'JButton' in subComponent.__class__.__name__ and subComponent.toolTipText == toolTipText:
			subComponent.visible = False			
		ButtonHider(subComponent, toolTipText)
		
# Get the PDF Viewer Component
viewer = event.source.parent.getComponent('PDF Viewer')

# Call the button hider script with the tool tip text of the button to hide
ButtonHider(viewer, "Save As")

This version could be placed generically in a library script and called from your componentRunning propertyChange event to hide any button in the viewer, and if needed in the future, it could be used to hide buttons as needed in any other component in the project.

@Michael_Knudsen , @R_S
Edit: Corrected an error in the code example that was actually hiding the parent container of the button instead of the button itself.

3 Likes