Top > OOoBasic > Dialog > Wizard

ウィザード Edit

OOo 3.3 から com.sun.star.ui.dialogs.Wizard サービスが利用できます。

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

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

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# 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