Revision 8d66cd4c

b/image_creator/dialog_wizard.py
83 83
        idx = 0
84 84
        while True:
85 85
            try:
86
                idx += self.pages[idx].run(self.session, idx, len(self.pages))
86
                total = len(self.pages)
87
                title = "(%d/%d) %s" % (idx + 1, total, self.pages[idx].title)
88
                idx += self.pages[idx].run(self.session, title)
87 89
            except WizardExit:
88 90
                return False
89 91
            except WizardReloadPage:
90 92
                continue
91 93

  
92 94
            if idx >= len(self.pages):
93
                msg = "All necessary information has been gathered:\n\n"
95
                text = "All necessary information has been gathered:\n\n"
94 96
                for page in self.pages:
95
                    msg += " * %s\n" % page.info
96
                msg += "\nContinue with the image creation process?"
97
                    text += " * %s\n" % page.info
98
                text += "\nContinue with the image creation process?"
97 99

  
98 100
                ret = self.d.yesno(
99
                    msg, width=PAGE_WIDTH, height=8 + len(self.pages),
101
                    text, width=PAGE_WIDTH, height=8 + len(self.pages),
100 102
                    ok_label="Yes", cancel="Back", extra_button=1,
101 103
                    extra_label="Quit", title="Confirmation")
102 104

  
......
116 118
    NEXT = 1
117 119
    PREV = -1
118 120

  
119
    def __init__(self, **kargs):
121
    def __init__(self, name, display_name, text, **kargs):
122
        self.name = name
123
        self.display_name = display_name
124
        self.text = text
125

  
126
        self.title = kargs['title'] if 'title' in kargs else ""
127
        self.default = kargs['default'] if 'default' in kargs else ""
128
        self.extra = kargs['extra'] if 'extra' in kargs else None
129
        self.extra_label = \
130
            kargs['extra_label'] if 'extra_label' in kargs else 'Extra'
131

  
132
        self.info = "%s: <none>" % self.display_name
133

  
120 134
        validate = kargs['validate'] if 'validate' in kargs else lambda x: x
121 135
        setattr(self, "validate", validate)
122 136

  
123 137
        display = kargs['display'] if 'display' in kargs else lambda x: x
124 138
        setattr(self, "display", display)
125 139

  
126
    def run(self, session, index, total):
140
    def run(self, session, title):
127 141
        """Display this wizard page
128 142

  
129 143
        This function is used by the wizard program when accessing a page.
......
131 145
        raise NotImplementedError
132 146

  
133 147

  
134
class WizardRadioListPage(WizardPage):
135
    """Represent a Radio List in a wizard"""
136
    def __init__(self, name, printable, message, choices, **kargs):
137
        super(WizardRadioListPage, self).__init__(**kargs)
138
        self.name = name
139
        self.printable = printable
140
        self.message = message
148
class WizardPageWthChoices(WizardPage):
149
    """Represents a Wizard Page that allows the user to select something from
150
    a list of choices.
151

  
152
    The available choices are created by a function passed to the class through
153
    the choices variable. If the choices function returns an empty list, a
154
    fallback funtion is executed if available.
155
    """
156
    def __init__(self, name, display_name, text, choices, **kargs):
157
        super(WizardPageWthChoices, self).__init__(name, display_name, text,
158
                                                   **kargs)
141 159
        self.choices = choices
142
        self.title = kargs['title'] if 'title' in kargs else ''
143
        self.default = kargs['default'] if 'default' in kargs else ""
160
        self.fallback = kargs['fallback'] if 'fallback' in kargs else None
161

  
162

  
163
class WizardRadioListPage(WizardPageWthChoices):
164
    """Represent a Radio List in a wizard"""
144 165

  
145
    def run(self, session, index, total):
166
    def run(self, session, title):
146 167
        d = session['dialog']
147 168
        w = session['wizard']
148 169

  
......
152 173
            choices.append((choice[0], choice[1], default))
153 174

  
154 175
        (code, answer) = d.radiolist(
155
            self.message, width=PAGE_WIDTH, ok_label="Next", cancel="Back",
156
            choices=choices, height=PAGE_HEIGHT,
157
            title="(%d/%d) %s" % (index + 1, total, self.title))
176
            self.text, width=PAGE_WIDTH, ok_label="Next", cancel="Back",
177
            choices=choices, height=PAGE_HEIGHT, title=title)
158 178

  
159 179
        if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
160 180
            return self.PREV
161 181

  
162 182
        w[self.name] = self.validate(answer)
163 183
        self.default = answer
164
        self.info = "%s: %s" % (self.printable, self.display(w[self.name]))
184
        self.info = "%s: %s" % (self.display_name, self.display(w[self.name]))
165 185

  
166 186
        return self.NEXT
167 187

  
168 188

  
169 189
class WizardInputPage(WizardPage):
170 190
    """Represents an input field in a wizard"""
171
    def __init__(self, name, printable, message, **kargs):
172
        super(WizardInputPage, self).__init__(**kargs)
173
        self.name = name
174
        self.printable = printable
175
        self.message = message
176
        self.info = "%s: <none>" % self.printable
177
        self.title = kargs['title'] if 'title' in kargs else ''
178
        self.init = kargs['init'] if 'init' in kargs else ''
179 191

  
180
    def run(self, session, index, total):
192
    def run(self, session, title):
181 193
        d = session['dialog']
182 194
        w = session['wizard']
183 195

  
184 196
        (code, answer) = d.inputbox(
185
            self.message, init=self.init, width=PAGE_WIDTH, ok_label="Next",
186
            cancel="Back", height=PAGE_HEIGHT,
187
            title="(%d/%d) %s" % (index + 1, total, self.title))
197
            self.text, init=self.default, width=PAGE_WIDTH, ok_label="Next",
198
            cancel="Back", height=PAGE_HEIGHT, title=title)
188 199

  
189 200
        if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
190 201
            return self.PREV
191 202

  
192 203
        value = answer.strip()
193
        self.init = value
204
        self.default = value
194 205
        w[self.name] = self.validate(value)
195
        self.info = "%s: %s" % (self.printable, self.display(w[self.name]))
206
        self.info = "%s: %s" % (self.display_name, self.display(w[self.name]))
196 207

  
197 208
        return self.NEXT
198 209

  
199 210

  
200
class WizardMenuPage(WizardPage):
201
    """Represents a menu dialog in a wizard"""
202
    def __init__(self, name, printable, message, choices, **kargs):
203
        super(WizardMenuPage, self).__init__(**kargs)
204
        self.name = name
205
        self.printable = printable
206
        self.message = message
207
        self.info = "%s: <none>" % self.printable
208
        self.choices = choices
209
        self.title = kargs['title'] if 'title' in kargs else ''
210
        self.default = kargs['default'] if 'default' in kargs else ""
211
        self.extra = kargs['extra'] if 'extra' in kargs else None
212
        self.extra_label = \
213
            kargs['extra_label'] if 'extra_label' in kargs else 'Extra'
214
        self.fallback = kargs['fallback'] if 'fallback' in kargs else None
211
class WizardMenuPage(WizardPageWthChoices):
212
    """Represents a menu dialog with available choices in a wizard"""
215 213

  
216
    def run(self, session, index, total):
214
    def run(self, session, title):
217 215
        d = session['dialog']
218 216
        w = session['wizard']
219 217

  
......
231 229
        default_item = self.default if self.default else choices[0][0]
232 230

  
233 231
        (code, choice) = d.menu(
234
            self.message, width=PAGE_WIDTH, ok_label="Next", cancel="Back",
235
            title="(%d/%d) %s" % (index + 1, total, self.title),
236
            choices=choices, height=PAGE_HEIGHT, default_item=default_item,
237
            extra_label=self.extra_label, extra_button=extra_button)
232
            self.text, width=PAGE_WIDTH, ok_label="Next", cancel="Back",
233
            title=title, choices=choices, height=PAGE_HEIGHT,
234
            default_item=default_item, extra_label=self.extra_label,
235
            extra_button=extra_button)
238 236

  
239 237
        if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
240 238
            return self.PREV
......
244 242

  
245 243
        self.default = choice
246 244
        w[self.name] = self.validate(choice)
247
        self.info = "%s: %s" % (self.printable, self.display(w[self.name]))
245
        self.info = "%s: %s" % (self.display_name, self.display(w[self.name]))
248 246

  
249 247
        return self.NEXT
250 248

  
......
293 291

  
294 292
    name = WizardInputPage(
295 293
        "ImageName", "Image Name", "Please provide a name for the image:",
296
        title="Image Name", init=ostype if distro == "unknown" else distro)
294
        title="Image Name", default=ostype if distro == "unknown" else distro)
297 295

  
298 296
    descr = WizardInputPage(
299 297
        "ImageDescription", "Image Description",
300 298
        "Please provide a description for the image:",
301
        title="Image Description", init=session['metadata']['DESCRIPTION'] if
302
        'DESCRIPTION' in session['metadata'] else '')
299
        title="Image Description", default=session['metadata']['DESCRIPTION']
300
        if 'DESCRIPTION' in session['metadata'] else '')
303 301

  
304 302
    def registration_choices():
305 303
        return [("Private", "Image is accessible only by this user"),

Also available in: Unified diff