Пример #1
0
class ZNewPublisherSiteConfirmPage(ZNewPublisherSiteWizardPageBase):
    def __init__(self, model, parent):
        self.blogSiteId = None
        self.blogListProvider = ZBlogCheckboxListContentProvider()
        ZNewPublisherSiteWizardPageBase.__init__(self, model, parent)

    # end __init__()

    def _createWidgets(self):
        self.description1 = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"publishersitewizard.Confirm"))  #$NON-NLS-1$
        self.description1.SetFont(getDefaultFontBold())
        self.description2 = wx.StaticText(
            self,
            wx.ID_ANY,
            _extstr(u"publishersitewizard.ConfirmDescription"),
            size=wx.Size(-1, 40))  #$NON-NLS-1$
        self.staticBox = wx.StaticBox(
            self, wx.ID_ANY, _extstr(u"accountblogs.BlogList"))  #$NON-NLS-1$
        self.blogListControl = ZCheckBoxListViewWithButtons(
            self.blogListProvider, self)
        self.mediaUploadLabel = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(
                u"publishersitewizard.MediaUploadMethodLabel"))  #$NON-NLS-1$
        comboValidator = ZNullControlValidator()
        self.mediaUploadCombo = ZValidatingBitmapComboBox(comboValidator,
                                                          self,
                                                          wx.ID_ANY,
                                                          style=wx.CB_READONLY)
        self.mediaUploadCombo.SetToolTipString(
            _extstr(
                u"publishersitewizard.MediaUploadMethodTooltip"))  #$NON-NLS-1$
        self.mediaWizardButton = wx.Button(
            self, wx.ID_ANY,
            _extstr(
                u"publishersitewizard.CreateNewMediaStorage"))  #$NON-NLS-1$

    def _populateMediaSitesList(self, selectedMediaStorageId=None):
        self.mediaUploadCombo.Clear()
        # FIXME (PJ) create a new 're-usable' model which lists given blog site id + available media storages  => maybe as a new control
        if self.blogSiteId:
            siteDef = self._getModel().getPublisherSite(self.blogSiteId)
            if siteDef.getCapabilities().supportsUploadMedia():
                bitmap = siteDef.getIconAsBitmap()
                name = u"Blog Fileupload (via %s)" % siteDef.getName(
                )  #$NON-NLS-1$
                self.mediaUploadCombo.Append(name, siteDef, bitmap)

        mediaStores = []
        mediaStores.extend(self._getModel().getMediaStorages())
        mediaStores.sort(lambda x, y: cmp(x.getName().lower(),
                                          y.getName().lower()))
        for mediaStore in mediaStores:
            mediaSite = self._getModel().getMediaSite(mediaStore)
            if mediaSite.isInternal():
                continue
            name = mediaStore.getName() + u" (" + mediaSite.getDisplayName(
            ) + u")"  #$NON-NLS-1$ #$NON-NLS-2$
            iconPath = mediaSite.getIconPath()
            bitmap = wx.Image(iconPath,
                              getImageType(iconPath)).ConvertToBitmap()
            self.mediaUploadCombo.Append(name, mediaStore, bitmap)
        # select first item
        if self.mediaUploadCombo.GetCount() > 0:
            if selectedMediaStorageId:
                self._selectMediaSite(selectedMediaStorageId)
            else:
                self.mediaUploadCombo.SetSelection(0)
                self.mediaUploadCombo.validate()

    def _bindWidgetEvents(self):
        self.Bind(wx.EVT_BUTTON, self.onMediaWizardButton,
                  self.mediaWizardButton)
        self.Bind(ZEVT_CHECKBOX_LIST_CHANGE, self.onBlogCheckedEvent,
                  self.blogListControl)

    def _layoutWidgets(self):
        staticBoxSizer = wx.StaticBoxSizer(self.staticBox, wx.VERTICAL)
        staticBoxSizer.AddSizer(self.blogListControl, 1, wx.EXPAND | wx.ALL, 5)

        flexGridSizer = wx.FlexGridSizer(1, 2, 5, 5)
        flexGridSizer.AddGrowableCol(1)
        flexGridSizer.Add(self.mediaUploadLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                          5)
        flexGridSizer.Add(self.mediaUploadCombo, 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.mediaWizardButton, 0, wx.ALIGN_RIGHT | 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(staticBoxSizer, 1, wx.EXPAND | wx.ALL, 5)
        box.AddSizer(flexGridSizer, 0, wx.EXPAND)
        self.SetAutoLayout(True)
        self.SetSizer(box)

    def getDataProperties(self):
        rval = {}
        return rval

    # end getDataProperties()

    def onMediaWizardButton(self, event):  #@UnusedVariable
        storeId = ZMediaStorageUtil().createNewMediaStorage(self)
        if storeId:
            self._populateMediaSitesList(storeId)

    def onEnter(self, session, eventDirection):
        if eventDirection == ZWizardPage.NEXT:
            oldKey = session.getProperty(
                u"confirm-page.modifykey")  #$NON-NLS-1$
            newKey = session.getProperty(
                u"apiinfo-page.modifykey")  #$NON-NLS-1$
            modified = not oldKey or newKey != oldKey
            idBlogList = session.getProperty(
                u"apiinfo-page.id-bloglist")  #$NON-NLS-1$
            if modified and idBlogList:
                self.blogSiteId = session.getProperty(
                    u"apiinfo-page.siteid")  #$NON-NLS-1$
                self._populateMediaSitesList()
                session.setProperty(u"confirm-page.modifykey",
                                    newKey)  #$NON-NLS-1$
                blogs = []
                for (dataId, blog) in idBlogList:  #@UnusedVariable
                    blogs.append(blog)
                self.blogListProvider.setBlogList(blogs)
                self.blogListControl.checkBoxListView.refreshItems()
                # pre-select all
                self.blogListControl.checkBoxListView.checkAll()

    def onExit(self, session, eventDirection):  #@UnusedVariable
        if eventDirection == ZWizardPage.NEXT:
            blogs = self._getSelectedBlogList()
            session.setProperty(u"confirm-page.selected-blogs",
                                blogs)  #$NON-NLS-1$
            obj = self._getSelectedMediaSite()
            uploadmethod = None
            mediastorageid = None
            if obj is not None and isinstance(obj, ZPublisherSiteDef):
                uploadmethod = u"publisher"  #$NON-NLS-1$
            elif obj is not None:
                uploadmethod = u"mediastorage"  #$NON-NLS-1$
                mediastorageid = obj.getId()
            session.setProperty(u"confirm-page.file-upload-method",
                                uploadmethod)  #$NON-NLS-1$
            session.setProperty(u"confirm-page.file-upload-mediastorage-id",
                                mediastorageid)  #$NON-NLS-1$
        return True

    def _getSelectedMediaSite(self):
        data = None
        idx = self.mediaUploadCombo.GetSelection()
        if idx != -1:
            data = self.mediaUploadCombo.GetClientData(idx)
        return data

    # end _getSelectedMediaSite()

    def _selectMediaSite(self, storeId):
        n = self.mediaUploadCombo.GetCount()
        for idx in range(n):
            data = self.mediaUploadCombo.GetClientData(idx)
            if data and data.getId() == storeId:
                self.mediaUploadCombo.SetSelection(idx)
                self.mediaUploadCombo.validate()
                break

    def _getSelectedBlogList(self):
        rval = self.blogListProvider.getSelectedBlogList()
        return rval

    # end _getSelectedBlogList

    def onBlogCheckedEvent(self, event):  #@UnusedVariable
        if len(self.blogListControl.checkBoxListView.getCheckedItems()) > 0:
            self._fireValidEvent()
        else:
            self._fireInvalidEvent()
Пример #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