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