Using system.gui.transform for Window Size

Hey all,

Couldn’t find any existing topics where this question was asked. I’m working on a few popups with existing “flyouts,” where we currently have a button script that toggles the width of a window between an “expanded” and “collapsed” dimension. We accomplish this with the window.size property (roughly) as follows:

flyout = event.source.parent.FlyoutActive 
window = event.source.parent.parent.parent.parent
titlebarHeight = event.source.parent.parent.parent.parent.titlebarHeight

if(flyout == 0):
	window.size = (800, 400+titlebarHeight)	
	event.source.parent.FlyoutActive = 1		
else:		
	window.size = (400, 400+titlebarHeight)	
	event.source.parent.FlyoutActive = 0

This works for our purposes, but we would love to use a smoother transition (similar to system.gui.transform) to make this feel more natural and less jerky. Since system.gui.transform only works on components and not windows directly, this isn’t as easy to do.

I’ve toyed with the idea of a delay loop and resizing the window one or two pixels at a time, but that feels a little hacky:

if(flyout == 0): stepWidth = collapsedWidth while stepWidth < expandedWidth: stepWidth = stepWidth + 1 window.size = (stepWidth,alwaysHeight) sleep(0.005) event.source.parent.FlyoutActive = 1

Does anyone have any clever ideas or suggestions?

Thanks!

Update:

We were able to get this working pretty well. Here is some rough code to accomplish the animation. I’m not sure I have the delay code 100% correct, but it does result in a fluid animation to transform the height and width of a window.

EDIT: Works best with a delayPerPixel of ~0.001

Not a finished product, but a proof of concept. Hope this helps anyone else with the same desire.

def windowTransform(window, newWidth, newHeight, delayPerPixel):
	from time import sleep	
		
	#Wrapper for Asynchronous function definition.		
	def windowTransformSub(window = window, newWidth = newWidth, newHeight = newHeight, delayPerPixel = delayPerPixel):
		
		#Check if Width is Increasing or Decreasing
		if newWidth > window.width:
			wStep = 1
		else:
			wStep = -1
	
		#Check if Height is Increasing or Decreasing		
		if newHeight > window.height:
			hStep = 1
		else:
			hStep = -1	
		
		#Initialize Width/Height
		stepWidth = window.width
		stepHeight = window.height
		
		#Loop until Width & Height are both at target
		while (stepWidth != newWidth) | (stepHeight != newHeight):					
			if (stepWidth != newWidth):
				stepWidth = stepWidth + wStep
			if(stepHeight != newHeight):
				stepHeight = stepHeight + hStep
			#Delay between iterations
			sleep(delayPerPixel)			
			#Send Updated window size back to GUI
			def updateUI(window = window, stepWidth = stepWidth, stepHeight = stepHeight):
				window.size = (stepWidth,stepHeight)				
			system.util.invokeLater(updateUI)

	system.util.invokeAsynchronous(windowTransformSub)
1 Like