Popup Calendar size

Hi,
I have a vision window with popup calendar and it displays as below (font size-12),
image
I would like to reduce the size of the calendar (Day names). How to achieve this?

Below is a script that changes the font size of the days only in a calendar component when fired from a button in the same container; it should be easily modifiable for your usage case. I would probably modify the jpanel's path and stick the script into the internalFrameOpened event handler of the parent window.

from java.awt import Font
fontSize = 8
font = Font('Dialog',0,fontSize)
jPanel = event.source.parent.getComponent('Calendar').getComponent(0).getComponent(1).getComponent(0).getComponent(1).getComponent(1)
sunLabel = jPanel.getComponent(0)
monLabel = jPanel.getComponent(1)
tueLabel = jPanel.getComponent(2)
wedLabel = jPanel.getComponent(3)
thuLabel = jPanel.getComponent(4)
friLabel = jPanel.getComponent(5)
satLabel = jPanel.getComponent(6)
weekLabels = [sunLabel, monLabel, tueLabel, wedLabel, thuLabel, friLabel, satLabel]
for label in weekLabels:
	label.setFont(font)

The preceding script produces the following result:
image

Edit: Here is a simpler refactored version of the script:

from java.awt import Font
fontSize = 8
font = Font('Dialog',0,fontSize)
jPanel = event.source.parent.getComponent('Calendar').getComponent(0).getComponent(1).getComponent(0).getComponent(1).getComponent(1)
for label in range(7):
	jPanel.getComponent(label).setFont(font)

Hey Justin,
I am getting the below error,
Traceback (most recent call last):
File "event:internalFrameOpened", line 4, in
TypeError: getComponent(): 1st arg can't be coerced to int
Script I used:

from java.awt import Font
fontSize = 8
font = Font('Dialog',0,fontSize)
jPanel = event.source.parent.getComponent('EndDate_dropdown').getComponent(0).getComponent(1).getComponent(0).getComponent(1).getComponent(1)
for label in range(7):
	jPanel.getComponent(label).setFont(font)


image

The path has to be changed to find the component from the parent window:

from java.awt import Font
fontSize = 8
font = Font('Dialog',0,fontSize)
calender = system.gui.getParentWindow(event).getComponentForPath('Root Container.Date_Group.EndDate_dropdown')
jPanel = calender.getComponent(0).getComponent(1).getComponent(0).getComponent(1).getComponent(1)
for label in range(7):
	jPanel.getComponent(label).setFont(font)

Now i am getting the below error,

Traceback (most recent call last):
  File "<event:internalFrameOpened>", line 5, in <module>
java.lang.ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException: No such child: 1

	caused by ArrayIndexOutOfBoundsException: No such child: 1

Ignition v8.1.22 (b2022110109)
Java: Azul Systems, Inc. 11.0.16.1

Interesting.
What gets returned by this script?

calender = system.gui.getParentWindow(event).getComponentForPath('Root Container.Date_Group.EndDate_dropdown')
try:
	print type(calender)
	print type(calender.getComponent(0))
	print type(calender.getComponent(0).getComponent(1))
	print type(calender.getComponent(0).getComponent(1).getComponent(0))
	print type(calender.getComponent(0).getComponent(1).getComponent(0).getComponent(1))
	print type(calender.getComponent(0).getComponent(1).getComponent(0).getComponent(1).getComponent(1))
except:
	pass

Mine returns this:

<type 'com.inductiveautomation.factorypmi.application.components.PMIDateTimeSelector'>
<type 'com.inductiveautomation.ignition.client.util.gui.date_selector.Titled_date_selector'>
<type 'com.inductiveautomation.ignition.client.util.gui.date_selector.Navigable_date_selector'>
<type 'com.inductiveautomation.ignition.client.util.gui.date_selector.Time_date_selector'>
<type 'com.inductiveautomation.ignition.client.util.gui.date_selector.Date_selector_panel'>
<type 'javax.swing.JPanel'>

No. it is not returning.

from java.awt import Font
fontSize = 8
font = Font('Dialog',0,fontSize)
#calender = system.gui.getParentWindow(event).getComponentForPath('Root Container.Date_Group.EndDate_dropdown')
#jPanel = calender.getComponent(0).getComponent(1).getComponent(0).getComponent(1).getComponent(1)
#for label in range(7):
#	jPanel.getComponent(label).setFont(font)


print "Test"
calender = system.gui.getParentWindow(event).getComponentForPath('Root Container.Date_Group.EndDate_dropdown')
try:
	print type(calender)
	print type(calender.getComponent(0))
	print type(calender.getComponent(0).getComponent(1))
	print type(calender.getComponent(0).getComponent(1).getComponent(0))
	print type(calender.getComponent(0).getComponent(1).getComponent(0).getComponent(1))
	print type(calender.getComponent(0).getComponent(1).getComponent(0).getComponent(1).getComponent(1))
except:
	pass

For testing, I have added test print. It is working

Oops. I see the problem. I wrote the script for a "calendar" component, but you are using a "popup calendar", so the calendar is not directly accessible through the getComponents() method. I'll take a look at the other component to see if I can do anything with it.

I found a way to do the same thing with the popup calendar. The following script was written for use on the popup calendar's mouseClicked event handler:

from java.awt import Font
fontSize = 8
font = Font('Dialog',0,fontSize)
popupCalender = event.source
calendar = popupCalender.getClass().getDeclaredField('popup')
calendar.setAccessible(True)
popup = calendar.get(popupCalender)
jPanel = popup.getComponent(0).getComponent(0).getComponent(1).getComponent(0).getComponent(1).getComponent(1)
for label in range(7):
	jPanel.getComponent(label).setFont(font)

Here is a version that will work from the internalFrameOpened event handler if that would be preferable:

from java.awt import Font
fontSize = 6
font = Font('Dialog',0,fontSize)
popupCalender = system.gui.getParentWindow(event).getComponentForPath('Root Container.Date_Group.EndDate_dropdown')
calendar = popupCalender.getClass().getDeclaredField('popup')
calendar.setAccessible(True)
popup = calendar.get(popupCalender)
jPanel = popup.getComponent(0).getComponent(0).getComponent(1).getComponent(0).getComponent(1).getComponent(1)
for label in range(7):
	jPanel.getComponent(label).setFont(font)
1 Like

Again i am getting 'No such child' error

hmmm...
Try this script on the popupCalendar's mouseEntered event handler, and tell me if it has the desired effect:

from java.awt import Font
fontSize = 4
font = Font('Dialog',0,fontSize)
popupCalender = event.source
calendar = popupCalender.getClass().getDeclaredField('popup')
calendar.setAccessible(True)
popup = calendar.get(popupCalender)
jPanel = popup.getComponent(0).getComponent(0).getComponent(1).getComponent(0).getComponent(1).getComponent(1)
for label in range(7):
	jPanel.getComponent(label).setFont(font)

If that doesn't work, then I have exhausted my ideas.

Traceback (most recent call last):
  File "<event:mouseEntered>", line 8, in <module>
java.lang.ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException: No such child: 1

	caused by ArrayIndexOutOfBoundsException: No such child: 1

Ignition v8.1.22 (b2022110109)
Java: Azul Systems, Inc. 11.0.16.1

Again !!?

I'm just not sure. This is the result on my system:

This approach must not be the correct way to go about isolating the day labels. All I've done is look through the sub components until I find the container that has the labels. Then I just loop through and apply the font change. Your component must be structured differently from mine.

Still, it did not worked. I endedup increasing the width of the component!! Will try to adapt this script to the component.

I had another idea on this. Here is an approach designed for the mouseEntered event handler that also works on my system except, instead of using specific subcomponents, it actually searches all of the subcomponents until it finds all of the labels:

from javax.swing import JLabel
from java.awt import Font
fontSize = 7
font = Font('Dialog',0,fontSize)
dayList = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
dayListCount = 0
def dayLabelFinder(calendar):
	try:
		if calendar.componentCount > 0:
			for component in calendar.getComponents():
				try:
					if isinstance(component, JLabel) and component.getText() in dayList:
						component.setFont(font)
						dayListCount +=1
						if dayListCount == 7:
							return
					dayLabelFinder(component)
				except:
					pass
	except:
		pass
popupCalender = event.source
calendar = popupCalender.getClass().getDeclaredField('popup')
calendar.setAccessible(True)
popup = calendar.get(popupCalender)
dayLabelFinder(popup)

Result:
image

1 Like

Note that the variant of getComponent() that takes an integer will not deliver a component that is wrapped for full functionality in jython unless you have installed my Simulation Aids 3rd-party module. See this topic for the intricate details:

1 Like