예제 #1
0
class ZNewProfileDialog(ZValidatingHeaderDialog):
    def __init__(self, parent, profilesModel):
        self.profilesModel = profilesModel
        ZValidatingHeaderDialog.__init__(
            self, parent, wx.ID_ANY,
            _extstr(u"newprofile.CreateNewProfile"))  #$NON-NLS-1$

        # Tell the dialog to resize itself to best-fit its children.
        self.Fit()

    # end __init__()

    def getProfileInfo(self):
        return (self.profileNameText.GetValue(),
                self.profilePathCtrl.getPath())

    # end getProfileInfo()

    def _createNonHeaderWidgets(self):
        self.profileInfoStaticBox = wx.StaticBox(
            self, label=_extstr(u"newprofile.ProfileInfo"))  #$NON-NLS-1$
        self.profileNameLabel = wx.StaticText(
            self, wx.ID_ANY, _extstr(u"newprofile.Name:"))  #$NON-NLS-1$
        self.profileNameText = ZValidatingTextCtrl(ZProfileNameValidator(
            self.profilesModel),
                                                   self,
                                                   wx.ID_ANY,
                                                   size=wx.Size(325, -1))
        self.profileNameText.SetToolTipString(
            _extstr(u"newprofile.ProfileNameTooltip"))  #$NON-NLS-1$
        self.profilePathLabel = wx.StaticText(
            self, wx.ID_ANY, _extstr(u"newprofile.Path:"))  #$NON-NLS-1$
        self.profilePathCtrl = ZValidatingFileChooserCtrl(
            ZProfilePathValidator(), self, ZFCC_DIRECTORY_TYPE,
            _extstr(u"newprofile.ChooseAProfileLocation"))  #$NON-NLS-1$
        self.profilePathCtrl.SetToolTipString(
            _extstr(u"newprofile.ProfilePathTooltip"))  #$NON-NLS-1$

    # end _createNonHeaderWidgets()

    def _populateNonHeaderWidgets(self):
        # populate with something?
        pass

    # end _populateNonHeaderWidgets()

    def _layoutNonHeaderWidgets(self):
        # Flexible grid sizer where all of the label->text ctrl pairs will live
        flexGridSizer = wx.FlexGridSizer(3, 2, 5, 5)
        flexGridSizer.AddGrowableCol(1)
        # NOTE: Called so that the import profile dialog can add widgets.
        self._layoutAdditionalNonHeaderWidgets(flexGridSizer)
        flexGridSizer.Add(self.profileNameLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.profileNameText, 0, wx.EXPAND | wx.RIGHT, 5)
        flexGridSizer.Add(self.profilePathLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.profilePathCtrl, 0, wx.EXPAND | wx.RIGHT, 5)

        # Static box sizer that has a label of "Profile Info"
        staticBoxSizer = wx.StaticBoxSizer(self.profileInfoStaticBox,
                                           wx.VERTICAL)
        staticBoxSizer.AddSizer(flexGridSizer, 0, wx.EXPAND | wx.ALL, 5)
        return staticBoxSizer

    # end _layoutNonHeaderWidgets()

    def _layoutAdditionalNonHeaderWidgets(self, sizer):  #@UnusedVariable
        pass

    # end _layoutAdditionalNonHeaderWidgets()

    def _bindWidgetEvents(self):
        self._bindValidatingWidget(self.profileNameText)
        self._bindValidatingWidget(self.profilePathCtrl)

    # end _bindWidgetEvents()

    def _setInitialFocus(self):
        self.profileNameText.SetFocus()

    # end _setInitialFocus()

    def _getHeaderTitle(self):
        return _extstr(u"newprofile.NewProfile")  #$NON-NLS-1$

    # end _getHeaderTitle()

    def _getHeaderMessage(self):
        return _extstr(u"newprofile.DialogUseMsg")  #$NON-NLS-1$

    # end _getHeaderMessage()

    def _getHeaderImagePath(self):
        return u"images/profile/new_dialog/header_image.png"  #$NON-NLS-1$

    # end _getHeaderImagePath()

    def setProfilePath(self, path):
        self.profilePathCtrl.setPath(path)

    # end setProfilePath()

    def setProfileName(self, name):
        self.profileNameText.SetValue(name)
예제 #2
0
class ZNewPublisherSiteApiInfoPage(ZNewPublisherSiteWizardPageBase):
    def __init__(self, model, parent):
        ZNewPublisherSiteWizardPageBase.__init__(self, model, parent)

    # end __init__()

    def _createWidgets(self):
        self.description1 = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"publishersitewizard.ApiInfo"))  #$NON-NLS-1$
        self.description1.SetFont(getDefaultFontBold())
        self.description2 = wx.StaticText(
            self,
            wx.ID_ANY,
            _extstr(u"publishersitewizard.ApiInfoDescription"),
            size=wx.Size(-1, 40))  #$NON-NLS-1$

        self.accLabel = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"publishersitewizard.AccountNameLabel"))  #$NON-NLS-1$
        accNameValidator = ZPublisherAccountNameValidator(self._getModel())
        self.accText = ZValidatingTextCtrl(accNameValidator, self, wx.ID_ANY)
        self.accText.SetToolTipString(
            _extstr(u"publishersitewizard.AccountNameTooltip"))  #$NON-NLS-1$

        self.siteLabel = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"publishersitewizard.SiteTypeLabel"))  #$NON-NLS-1$
        comboValidator = ZNonEmptySelectionValidator(
            _extstr(u"publishersitewizard.EmptySiteTypeSelectionError")
        )  #$NON-NLS-1$
        self.siteCombo = ZValidatingBitmapComboBox(comboValidator,
                                                   self,
                                                   wx.ID_ANY,
                                                   style=wx.CB_READONLY)
        self.siteCombo.SetToolTipString(
            _extstr(u"publishersitewizard.SiteTypeTooltip"))  #$NON-NLS-1$
        self.Bind(wx.EVT_COMBOBOX, self.onComboEvent, self.siteCombo.widget)

        self.autodiscoveryHint = wx.StaticText(self, wx.ID_ANY,
                                               u"")  #$NON-NLS-1$

        self.usernameLabel = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"publishersitewizard.UsernameLabel"))  #$NON-NLS-1$
        usernameValidator = ZNonEmptySelectionValidator(
            _extstr(u"publishersitewizard.EmptyUsername"))  #$NON-NLS-1$
        self.usernameText = ZValidatingTextCtrl(usernameValidator, self,
                                                wx.ID_ANY)
        self.usernameText.SetToolTipString(
            _extstr(u"publishersitewizard.UsernameTooltip"))  #$NON-NLS-1$

        self.passwordLabel = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"publishersitewizard.PasswordLabel"))  #$NON-NLS-1$
        passwordValidator = ZNonEmptySelectionValidator(
            _extstr(u"publishersitewizard.EmptyPassword"))  #$NON-NLS-1$
        self.passwordText = ZValidatingTextCtrl(passwordValidator,
                                                self,
                                                wx.ID_ANY,
                                                style=wx.TE_PASSWORD)
        self.passwordText.SetToolTipString(
            _extstr(u"publishersitewizard.PasswordTooltip"))  #$NON-NLS-1$

        self.apiUrlLabel = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"publishersitewizard.ApiUrlLabel"))  #$NON-NLS-1$
        apiUrlValidator = ZUrlSelectionValidator(
            _extstr(u"publishersitewizard.ApiUrlInvalid"))  #$NON-NLS-1$
        self.apiUrlText = ZValidatingTextCtrl(apiUrlValidator, self, wx.ID_ANY)
        self.apiUrlText.SetToolTipString(
            _extstr(u"publishersitewizard.ApiUrlTooltip"))  #$NON-NLS-1$
        self.apiUrlHint = wx.StaticText(self, wx.ID_ANY,
                                        u"Api Url hints")  #$NON-NLS-1$
        self.animateControl = ZProgressLabelCtrl(self)

    # end _createWidgets()

    def _populateWidgets(self):
        self._showBusy(False)
        siteDefList = []
        siteDefList.extend(self._getModel().listPublisherSites())
        siteDefList.sort(lambda x, y: cmp(x.getName().lower(),
                                          y.getName().lower()))
        for siteDef in siteDefList:
            bitmap = siteDef.getIconAsBitmap()
            self.siteCombo.Append(siteDef.getName(), siteDef, bitmap)

    # end _populateWidgets()

    def _bindWidgetEvents(self):
        self._bindValidatingWidget(self.accText)
        self._bindValidatingWidget(self.siteCombo)
        self._bindValidatingWidget(self.usernameText)
        self._bindValidatingWidget(self.passwordText)
        self._bindValidatingWidget(self.apiUrlText)

    # end _bindWidgetEvents()

    def _layoutWidgets(self):
        flexGridSizer = wx.FlexGridSizer(7, 2, 5, 5)
        flexGridSizer.AddGrowableCol(1)
        flexGridSizer.Add(self.accLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.accText, 0, wx.EXPAND | wx.RIGHT, 5)
        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(wx.StaticText(self, wx.ID_ANY), 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.autodiscoveryHint, 0, wx.EXPAND | wx.RIGHT, 5)
        flexGridSizer.Add(self.usernameLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.usernameText, 0, wx.EXPAND | wx.RIGHT, 5)
        flexGridSizer.Add(self.passwordLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.passwordText, 0, wx.EXPAND | wx.RIGHT, 5)
        flexGridSizer.Add(self.apiUrlLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.apiUrlText, 0, wx.EXPAND | wx.RIGHT, 5)
        flexGridSizer.Add(wx.StaticText(self, wx.ID_ANY), 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.apiUrlHint, 0, wx.EXPAND | wx.RIGHT, 5)
        flexGridSizer.Add(wx.StaticText(self, wx.ID_ANY), 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.animateControl, 0,
                          wx.EXPAND | wx.ALIGN_LEFT | 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"apiinfo-page.accname"] = self.accText.GetValue().strip(
        )  #$NON-NLS-1$
        site = self._getSelectedSite()
        id = None
        if site:
            id = site.getId()
        rval[u"apiinfo-page.siteid"] = id  #$NON-NLS-1$
        rval[u"apiinfo-page.username"] = self.usernameText.GetValue().strip(
        )  #$NON-NLS-1$
        rval[u"apiinfo-page.password"] = self.passwordText.GetValue().strip(
        )  #$NON-NLS-1$
        rval[u"apiinfo-page.apiurl"] = self.apiUrlText.GetValue().strip(
        )  #$NON-NLS-1$
        return rval

    # end getDataProperties()

    def _enableControls(self, enable):
        self.accText.Enable(enable)
        self.siteCombo.Enable(enable)
        self.usernameText.Enable(enable)
        self.passwordText.Enable(enable)
        self.apiUrlText.Enable(enable)

    def _showBusy(self, enable, text=u""):  #$NON-NLS-1$
        if getNoneString(text):
            self.animateControl.setLabel(text)
        self.animateControl.Show(enable)

    def _updateDiscoverInfo(self, discoverInfo):
        hint = u""  #$NON-NLS-1$
        if discoverInfo:
            if discoverInfo.engineName:
                hint = u"Autodiscovered %s" % discoverInfo.engineName  #$NON-NLS-1$
            else:
                hint = u"Autodiscover information not available."  #$NON-NLS-1$
            if discoverInfo.username and not self.usernameText.GetValue():
                self.usernameText.SetValue(discoverInfo.username)
            if discoverInfo.siteId:
                self._selectSiteId(discoverInfo.siteId)

            apiUrl = None
            if getNoneString(discoverInfo.apiUrl):
                apiUrl = discoverInfo.apiUrl
            else:
                # find api url from site def
                apiUrl = self._getDefaultUrlForSelectedSite()
            if apiUrl:
                self.apiUrlText.SetValue(apiUrl)

        self.autodiscoveryHint.SetLabel(hint)

    def _refresh(self, eventType, eventData):
        if eventType == u"begin-listblogs":  #$NON-NLS-1$
            self._enableControls(False)
            self._showBusy(True, u"Getting blog list...")  #$NON-NLS-1$
        elif eventType == u"end-listblogs":  #$NON-NLS-1$
            self._enableControls(True)
            self._showBusy(False)
        elif eventType == u"error-listblogs":  #$NON-NLS-1$
            (errMsg, errDetails, err) = eventData  #@UnusedVariable
            ZShowErrorMessage(self, errMsg, errDetails)

    def onEnter(self, session, eventDirection):
        self.accText.SetFocus()
        if eventDirection == ZWizardPage.NEXT:
            discoverInfo = session.getProperty(
                u"siteurl-page.discover-info")  #$NON-NLS-1$
            #print u"ApiInfoPageinfo-Enter discinfo=", discoverInfo # FIXME (PJ) delete this #$NON-NLS-1$
            self._updateDiscoverInfo(discoverInfo)

    def onExit(self, session, eventDirection):
        # look up blog list if data has changed
        if eventDirection == ZWizardPage.NEXT:
            siteId = self._getSelectedSite().getId()
            username = self.usernameText.GetValue().strip()
            password = self.passwordText.GetValue().strip()
            apiUrl = self.apiUrlText.GetValue().strip()
            key = siteId + username + password + apiUrl
            oldKey = session.getProperty(
                u"apiinfo-page.modifykey")  #$NON-NLS-1$
            if not oldKey or oldKey != key:
                task = ZListBlogsTask(self, session, siteId, username,
                                      password, apiUrl, key)
                self._fireBeginBackgroundTaskEvent(task)
                return False
        return True

    def onComboEvent(self, event):  #@UnusedVariable
        defUrl = self._getDefaultUrlForSelectedSite()
        if defUrl:
            self.apiUrlText.SetValue(defUrl)

    def _getDefaultUrlForSelectedSite(self):
        # Attempts to get the default or predefined url for the currenly selected site.
        siteDef = self._getSelectedSite()
        defUrl = self._getModel().getDefaultApiUrl(siteDef)
        return defUrl

    def _selectSiteId(self, siteId):
        n = self.siteCombo.GetCount()
        for idx in range(n):
            data = self.siteCombo.GetClientData(idx)
            if data and data.getId() == siteId:
                self.siteCombo.SetSelection(idx)
                self.siteCombo.validate()
                break

    def _getSelectedSite(self):
        data = None
        idx = self.siteCombo.GetSelection()
        if idx != -1:
            data = self.siteCombo.GetClientData(idx)
            # print "SELSITE %s %s" % (data.getName(),data.getId())
        return data
예제 #3
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]
예제 #4
0
class ZNewPublisherSiteUrlPage(ZNewPublisherSiteWizardPageBase):
    def __init__(self, model, parent):
        ZNewPublisherSiteWizardPageBase.__init__(self, model, parent)

    # end __init__()

    def _createWidgets(self):
        self.description1 = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"publishersitewizard.WelcomeMessage"))  #$NON-NLS-1$
        self.description1.SetFont(getDefaultFontBold())
        self.description2 = wx.StaticText(
            self,
            wx.ID_ANY,
            _extstr(u"publishersitewizard.WizardDescription"),
            size=wx.Size(-1, 80))  #$NON-NLS-1$
        self.urlLabel = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"publishersitewizard.BlogUrlLabel"))  #$NON-NLS-1$
        urlValidator = ZUrlSelectionValidator(
            _extstr(u"publishersitewizard.BlogUrlInvalid"),
            nonEmpty=False)  #$NON-NLS-1$
        self.urlText = ZValidatingTextCtrl(urlValidator, self, wx.ID_ANY)
        self.urlText.SetToolTipString(
            _extstr(u"publishersitewizard.BlogUrlTooltip"))  #$NON-NLS-1$
        self.animateControl = ZProgressLabelCtrl(self)
        self.clickHereHyperlink = wx.HyperlinkCtrl(
            self, wx.ID_ANY, _extstr(u"publishersitewizard.NoBlogYet"),
            u"http://www.blogger.com/?ref=ZoundryRaven"
        )  #$NON-NLS-2$ #$NON-NLS-1$

    # end _createWidgets()

    def _populateWidgets(self):
        self._showBusy(False)

    # end _populateWidgets()

    def _bindWidgetEvents(self):
        self._bindValidatingWidget(self.urlText)

    # end _bindWidgetEvents()

    def _layoutWidgets(self):
        flexGridSizer = wx.FlexGridSizer(1, 2, 5, 5)
        flexGridSizer.AddGrowableCol(1)
        flexGridSizer.Add(self.urlLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.urlText, 0, wx.EXPAND | wx.RIGHT, 5)
        flexGridSizer.Add(wx.StaticText(self, wx.ID_ANY), 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.animateControl, 0,
                          wx.EXPAND | wx.ALIGN_LEFT | wx.RIGHT, 5)
        flexGridSizer.Add(wx.StaticText(self, wx.ID_ANY), 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.clickHereHyperlink, 0, wx.ALL, 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 _showBusy(self, enable, text=u""):  #$NON-NLS-1$
        if getNoneString(text):
            self.animateControl.setLabel(text)
        self.animateControl.Show(enable)

    # end _showBusy()

    def _getSiteUrl(self):
        return self.urlText.GetValue().strip()

    # end _getSiteUrl()

    def getDataProperties(self):
        rval = {}
        rval[u"siteurl-page.url"] = self._getSiteUrl()  #$NON-NLS-1$
        return rval

    # end getDataProperties()

    def _refresh(self, eventType, eventData):
        if eventType == u"begin-autodiscover":  #$NON-NLS-1$
            self.urlText.Enable(False)
            self._showBusy(True, u"Checking... %s" %
                           self._getSiteUrl())  #$NON-NLS-1$
        elif eventType == u"end-autodiscover":  #$NON-NLS-1$
            self.urlText.Enable(True)
            self._showBusy(False)
        elif eventType == u"error-autodiscover":  #$NON-NLS-1$
            (errMsg, errDetails, err) = eventData  #@UnusedVariable
            ZShowErrorMessage(self, errMsg, errDetails)

    # end _refresh()

    def onEnter(self, session, eventDirection):  #@UnusedVariable
        self.urlText.SetFocus()

    # end onEnter()

    def onExit(self, session, eventDirection):
        if eventDirection == ZWizardPage.NEXT:
            oldValue = session.getProperty(u"siteurl-page.url")  #$NON-NLS-1$
            newValue = self._getSiteUrl()
            # auto discover if there is a new value and it not empty
            if newValue and newValue != oldValue:
                # check for cached discover data
                cacheMap = session.getProperty(
                    u"siteurl-page.discover-info-cache")  #$NON-NLS-1$
                if cacheMap and cacheMap.has_key(newValue):
                    discoverInfo = cacheMap[newValue]
                    session.setProperty(u"siteurl-page.discover-info",
                                        discoverInfo)  #$NON-NLS-1$
                else:
                    task = ZAutodiscoverTask(self, session)
                    self._fireBeginBackgroundTaskEvent(task)
                    return False
            elif oldValue and not newValue:
                # new value does not exist. reset auto-disc.
                session.setProperty(u"siteurl-page.discover-info",
                                    None)  #$NON-NLS-1$
        return True
예제 #5
0
class ZAddTemplateFromBlogDialog(ZValidatingHeaderDialog,
                                 ZPersistentDialogMixin):
    def __init__(self, parent):
        self.model = ZAddTemplateFromBlogModel()

        ZValidatingHeaderDialog.__init__(
            self, parent, wx.ID_ANY,
            _extstr(u"templatedialogs.AddTemplate"))  #$NON-NLS-1$
        ZPersistentDialogMixin.__init__(
            self, IZBlogAppUserPrefsKeys.ADD_TEMPLATE_FROM_BLOG_DIALOG, True,
            True)

    # end __init__()

    def getSelectedBlog(self):
        return self.blogPicker.getBlog()

    # end getSelectedBlog()

    def getTemplateName(self):
        return self.templateNameText.GetValue()

    # end getTemplateName()

    def isMakeDefaultTemplate(self):
        return self.makeDefaultTemplateCB.IsChecked()

    # end isMakeDefaultTemplate()

    def selectBlog(self, blog):
        self.blogPicker.selectBlog(blog.getAccount().getId(), blog.getId())
        self.blogPicker.validate()

    # end selectBlog()

    def _createNonHeaderWidgets(self):
        self.blogLabel = wx.StaticText(
            self, wx.ID_ANY, u"%s:" %
            _extstr(u"templatedialogs.FromBlog"))  #$NON-NLS-1$ #$NON-NLS-2$
        self.blogPicker = ZValidatingBlogSelectorCombo(
            ZNonEmptySelectionValidator(
                _extstr(u"templatedialogs.ChooseABlog")), self.model,
            self)  #$NON-NLS-1$
        self.templateNameLabel = wx.StaticText(
            self, wx.ID_ANY, u"%s:" % _extstr(u"templatedialogs.TemplateName")
        )  #$NON-NLS-1$ #$NON-NLS-2$
        self.templateNameText = ZValidatingTextCtrl(
            ZTemplateNameValidator(self.model), self, wx.ID_ANY)
        self.templateNameText.SetToolTipString(
            _extstr(
                u"templatedialogs.PickAFriendlyTemplateName"))  #$NON-NLS-1$
        self.makeDefaultTemplateCB = wx.CheckBox(
            self, wx.ID_ANY,
            _extstr(
                u"templatedialogs.MakeThisTemplateTheDefault"))  #$NON-NLS-1$

        self.staticLine = wx.StaticLine(self, wx.HORIZONTAL)

    # end _createNonHeaderWidgets()

    def _populateNonHeaderWidgets(self):
        self.makeDefaultTemplateCB.SetValue(True)

    # end _populateNonHeaderWidgets()

    def _layoutNonHeaderWidgets(self):
        # Flexible grid sizer where all of the label->text ctrl pairs will live
        flexGridSizer = wx.FlexGridSizer(2, 2, 5, 5)
        flexGridSizer.AddGrowableCol(1)

        flexGridSizer.Add(self.blogLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.blogPicker, 0, wx.EXPAND | wx.RIGHT, 5)
        flexGridSizer.Add(self.templateNameLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.templateNameText, 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.makeDefaultTemplateCB, 0, wx.EXPAND | wx.RIGHT,
                          5)

        # Static box sizer that has a label of "Profile Info"
        boxSizer = wx.BoxSizer(wx.VERTICAL)
        boxSizer.AddSizer(flexGridSizer, 0, wx.EXPAND | wx.ALL, 5)
        boxSizer.Add(self.staticLine, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 3)
        return boxSizer

    # end _layoutNonHeaderWidgets()

    def _bindWidgetEvents(self):
        self._bindValidatingWidget(self.blogPicker)
        self._bindValidatingWidget(self.templateNameText)

    # end _bindWidgetEvents()

    def _setInitialFocus(self):
        self.blogPicker.SetFocus()

    # end _setInitialFocus()

    def _getHeaderTitle(self):
        return _extstr(u"templatedialogs.AddTemplateFromBlog")  #$NON-NLS-1$

    # end _getHeaderTitle()

    def _getHeaderMessage(self):
        return _extstr(
            u"templatedialogs.DialogDescriptionMessage")  #$NON-NLS-1$

    # end _getHeaderMessage()

    def _getHeaderImagePath(self):
        return u"images/dialogs/template/manager/header_image.png"  #$NON-NLS-1$

    # end _getHeaderImagePath()

    def setProfilePath(self, path):
        self.profilePathCtrl.setPath(path)

    # end setProfilePath()

    def setProfileName(self, name):
        self.profileNameText.SetValue(name)