View Single Post
  #1  
Old 12-09-2014, 08:30 AM
mape2k mape2k is offline
Member
 
Join Date: Mar 2013
Posts: 60
Changes in vizdlg or vizact in Vizard 5?

Hello,

I have a problem running most of my files in Vizard 5:

To display text, images, ... I build my own vizdlg.Dialog class to create a panel which I can use to display and hide messages very easily (I used a small tutorial that is somewhere in the Vizard documentation).

Since I upgrade to Vizard 5, the background of the panel won't hide anymore. To show you guys what I mean, I created a small example (with a simplified version of my vizdlg.Dialog class).

The code pasted below works fine with Vizard 4: the text 'Bla' is displayed for 2 seconds, then the screen goes black
However, in Vizard 5, the text will also go away after 2 seconds, but the grey background will stay without any error message.

Have there been any changes to the built-in librarys that could cause such a problem?

Cheers,
Johannes


EDIT: I fixed it by changing line 68 'self.panel.addAction(vizact.fadeTo(0,time=fade))' to 'self.panel.background.addAction(vizact.fadeTo(0,t ime=fade))'


Code:
import os
import sys

import viz
import vizdlg
import vizact
import viztask


# text panel class

class displayInfo(vizdlg.Dialog):

	def __init__(self,mode = 'fit',fontSize = 50,textAlignment = viz.ALIGN_CENTER,border = True,background = True, padding = 5,**kw):
		
		vizdlg.Dialog.__init__(self,**kw)
		
		self.fontSize = fontSize
		self.textAlignment = textAlignment
		self.textColor = (1,1,1)
		self.borderDesired = border
		self.bgDesired = background
		self._padding = padding
		
		# define own color theme
		blackTheme = viz.getTheme()
		blackTheme.backColor = (0.4,0.4,0.4,1)
		blackTheme.lightBackColor = (0.6,0.6,0.6,1)
		blackTheme.darkBackColor = (0.2,0.2,0.2,1)
		blackTheme.highBackColor = (0.2,0.2,0.2,1)
		blackTheme.textColor = (self.textColor)
		
		if mode == 'fullscreen':
			self.panel = vizdlg.Panel(theme = blackTheme,align = vizdlg.ALIGN_CENTER,border = False, background = self.bgDesired) # add panel without border
			self.panel.background.setScale(5000,5000,1) # if fullscreen is passed, scale the background so it covers fullscreen
		elif mode == 'fit':
			self.panel = vizdlg.Panel(theme = blackTheme,align = vizdlg.ALIGN_CENTER, border = self.borderDesired, background = self.bgDesired, padding = self._padding) # add panel

		self.panel.background.alpha(1) 			# set background alpha
		viz.link(viz.CenterCenter,self.panel)	# link the panel to center of screen
	
		# switch variables to determine state of message panel
		self.textDisplayed = False
	
	# display message
	def message(self,text,fade = 0):
		
		# init text
		self.text = self.panel.addItem(viz.addText(text))	# if message should be displayed, add text item
		
		# set attributes
		self.text.fontSize(self.fontSize)
		self.text.alignment(self.textAlignment)
		self.text.color(self.textColor)
		
		# let the panel fade in
		self.panel.addAction(vizact.fadeTo(1,time=fade))
		
		# fade in of the text (if desired)
		self.text.addAction(vizact.fadeTo(1,time=fade))
	
	# hide text and panel
	def hide(self, fade = 0):
		
		for item in self.panel.getItems():
			self.panel.removeItem(item)
		
		self.panel.addAction(vizact.fadeTo(0,time=fade))
	


# small example

textPanel = displayInfo(mode = 'fullscreen',fontSize = 30, textAlignment = viz.ALIGN_LEFT_CENTER)	# fullscreen text for introduction text

def main():
	
	textPanel.message('Bla')
	
	yield viztask.waitTime(2)
	
	textPanel.hide()
	
viztask.schedule(main())

viz.go()

Last edited by mape2k; 12-09-2014 at 08:38 AM.
Reply With Quote