Пример #1
0
class ZNewMediaStorageWizardSitePage(ZNewMediaStorageWizardPage):
    def __init__(self, model, parent):
        ZNewMediaStorageWizardPage.__init__(self, model, parent)
        self.customPages = None
        self.site = None

    # end __init__()

    def _createWidgets(self):
        self.description1 = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"mediastoragewizard.WelcomeMessage"))  #$NON-NLS-1$
        self.description1.SetFont(getDefaultFontBold())
        self.description2 = wx.StaticText(
            self,
            wx.ID_ANY,
            _extstr(u"mediastoragewizard.WizardDescription"),
            size=wx.Size(-1, 80))  #$NON-NLS-1$
        self.siteLabel = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"mediastoragewizard.MediaStorageType"))  #$NON-NLS-1$
        comboValidator = ZNonEmptySelectionValidator(
            _extstr(u"mediastoragewizard.EmptyStoreTypeSelectionError")
        )  #$NON-NLS-1$
        self.siteCombo = ZValidatingBitmapComboBox(comboValidator,
                                                   self,
                                                   wx.ID_ANY,
                                                   style=wx.CB_READONLY)
        self.siteCombo.SetToolTipString(
            _extstr(u"mediastoragewizard.StoreTypeComboTooltip"))  #$NON-NLS-1$
        self.nameLabel = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"mediastoragewizard.MediaStorageName"))  #$NON-NLS-1$
        nameValidator = ZMediaStorageNameValidator(self._getModel())
        self.nameText = ZValidatingTextCtrl(nameValidator, self, wx.ID_ANY)
        self.nameText.SetToolTipString(
            _extstr(
                u"mediastoragewizard.MediaStorageNameTooltip"))  #$NON-NLS-1$
        self.clickHereHyperlink = wx.HyperlinkCtrl(
            self, wx.ID_ANY, _extstr(u"mediastoragewizard.NoStorageLink"),
            u"http://picasaweb.google.com/?ref=ZoundryRaven"
        )  #$NON-NLS-2$ #$NON-NLS-1$

    # end _createWidgets()

    def _populateWidgets(self):
        mediaSites = self._getModel().getMediaSites()
        for site in mediaSites:
            iconPath = site.getIconPath()
            bitmap = getResourceRegistry().getBitmap(iconPath)
            self.siteCombo.Append(site.getDisplayName(), None, bitmap)

    # end _populateWidgets()

    def _bindWidgetEvents(self):
        self._bindValidatingWidget(self.siteCombo)
        self._bindValidatingWidget(self.nameText)

    # end _bindWidgetEvents()

    def _layoutWidgets(self):
        flexGridSizer = wx.FlexGridSizer(2, 2, 5, 5)
        flexGridSizer.AddGrowableCol(1)
        flexGridSizer.Add(self.siteLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.siteCombo, 0, wx.EXPAND | wx.RIGHT, 5)
        flexGridSizer.Add(self.nameLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.nameText, 0, wx.EXPAND | wx.RIGHT, 5)
        flexGridSizer.Add(wx.StaticText(self, wx.ID_ANY, u""), 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)  #$NON-NLS-1$
        flexGridSizer.Add(self.clickHereHyperlink, 0, wx.EXPAND | wx.RIGHT, 5)

        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.description1, 0, wx.EXPAND | wx.ALL, 10)
        box.Add(self.description2, 0, wx.EXPAND | wx.ALL, 10)
        box.AddSizer(flexGridSizer, 0, wx.EXPAND)
        self.SetAutoLayout(True)
        self.SetSizer(box)

    # end _layoutWidgets()

    def getDataProperties(self):
        rval = {}
        rval[u"type-page.site"] = self._getSelectedSite()  #$NON-NLS-1$
        rval[u"type-page.name"] = self.nameText.GetValue()  #$NON-NLS-1$
        return rval

    # end getDataProperties()

    def onEnter(self, session, eventDirection):  #@UnusedVariable
        if eventDirection == ZWizardPage.NEXT:
            mediaSites = self._getModel().getMediaSites()
            idx = 0
            for site in mediaSites:
                if site.getId(
                ) == u"zoundry.blogapp.mediastorage.site.picasa":  #$NON-NLS-1$
                    self.siteCombo.Select(idx)
                    self.siteCombo.validate()
                    self.nameText.SetFocus()
                    return
                idx = idx + 1

        self.siteCombo.SetFocus()

    # end onEnter()

    def onExit(self, session, eventDirection):  #@UnusedVariable
        if eventDirection == ZWizardPage.NEXT:
            site = self._getSelectedSite()
            if site != self.site:
                self.site = site
                # Remove any old custom pages we may have had
                if self.customPages:
                    for page in self.customPages:
                        # magic number - the position of the first custom
                        # page and the position of all custom pages as they
                        # are removed
                        self.wizard.removePage(2)
                    self.customPages = None
                # Now add in new pages
                pages = []
                wizardPageClasses = self.site.createContributedWizardPages()
                insertionPoint = 2
                for wizardPageClass in wizardPageClasses:
                    page = wizardPageClass(self.model, self.wizard)
                    pages.append(page)
                    self.wizard.addPage(page, insertionPoint)
                    insertionPoint = insertionPoint + 1
                self.customPages = pages
        return True

    # end onExit()

    def _getSelectedSite(self):
        idx = self.siteCombo.GetSelection()
        return self._getModel().getMediaSites()[idx]