Top > OOoBasic > Dialog > Wizard
* ウィザード [#qc052e4a]
OOo 3.3 から com.sun.star.ui.dialogs.Wizard サービスが利用できます。

ウィザードダイアログの全体のサイズは中のウィンドウのサイズで決まります。小さすぎるウィンドウを表示仕様とすると下部のボタン配置が重なることがあります。

以下の例ではダイアログエディタで作成したファイルから生成したウィンドウを利用しています。

#code(python){{
# Python
import uno
import unohelper
from com.sun.star.ui.dialogs import XWizardController, XWizardPage


class ComponentBase(object):
	def dispose(self): pass
	def addEventListener(self, ev): pass
	def removeEventListener(self, ev): pass


class WizardPage(ComponentBase, unohelper.Base, XWizardPage):
	def __init__(self, wizard, id, page):
		self.wizard = wizard
		self.id = id
		self.page = page
	
	def dispose(self):
		self.wizard = None
		self.page = None
	
	# XWizardPage
	def activatePage(self):
		# initialize page
		pass
	
	def commitPage(self, reason):
		# asked before page proceed. Next page is shown if True is returned.
		return True
	
	def canAdvance(self):
		return True
	
	@property
	def Window(self):
		return self.page
	
	@property
	def PageId(self):
		return self.id


class Wizard(object, unohelper.Base, XWizardController):
	
	URI_PAGE_1 = "vnd.sun.star.script:Standard.Page1?location=application"
	URI_PAGE_2 = "vnd.sun.star.script:Standard.Page2?location=application"
	
	TITLE_PAGE_1 = "Page 1"
	TITLE_PAGE_2 = "Page 2"
	
	def __init__(self, ctx, title=None, help_url=None):
		self.ctx = ctx
		self.title = title
		self.pages = {} # id: page
		self.cwp = self.create_service("com.sun.star.awt.ContainerWindowProvider")
		wizard = self.create_service("com.sun.star.ui.dialogs.Wizard")
		uno.invoke(wizard, "initialize", ((uno.Any("[]short", (1, 2)), self),))
		self.wizard = wizard
		if self.title:
			wizard.setTitle(title)
		if help_url:
			wizard.HelpURL = help_url
	
	def create_service(self, name, args=None):
		if args:
			return self.ctx.getServiceManager().\
				createInstanceWithArgumentsAndContext(name, args, self.ctx)
		else:
			return self.ctx.getServiceManager().\
				createInstanceWithContext(name, self.ctx)
	
	def dispose(self):
		self.wizard.dispose()
	
	def execute(self):
		if self.wizard.execute():
			return 
		return None
	
	# XWizardController
	def createPage(self, parent, id):
		uri = getattr(self, "URI_PAGE_%s" % id)
		#title = getattr(self, "TITLE_PAGE_%s" % id)
		page = self.cwp.createContainerWindow(uri, "", parent, None)
		wizard_page = WizardPage(self, id, page)
		self.pages[id] = wizard_page
		return wizard_page
	
	def getPageTitle(self, id):
		# called before pages are created
		#if id in self.pages:
		#	wizard_page = self.pages[id]
		#	return wizard_page.get_title()
		return getattr(self, "TITLE_PAGE_%s" % id)
	
	def canAdvance(self):
		return True
	
	def onActivatePage(self, id):
		pass
	
	def onDeactivatePage(self, id):
		pass
	
	def confirmFinish(self):
		# asked before close by OK. If False returned, dialog can not be closed.
		return True



def wizard(*args):
	ctx = XSCRIPTCONTEXT.getComponentContext()
	try:
		wizard = Wizard(ctx)
		result = wizard.execute()
		print(result)
	except Exception, e:
		print(e)
		import traceback
		traceback.print_exc()
}}

Reload   New Lower page making Edit Freeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup   Help   RSS of recent changes