Exemplo n.º 1
0
class ZTestPreferencePage(ZApplicationPreferencesPrefPage):
    def __init__(self, parent):
        ZApplicationPreferencesPrefPage.__init__(self, parent)

    # end __init__()

    def createWidgets(self):
        self.label1 = wx.StaticText(self, wx.ID_ANY, u"Label 1:")  #$NON-NLS-1$
        self.value1 = ZValidatingTextCtrl(ZValue1Validator(), self)
        self.label2 = wx.StaticText(self, wx.ID_ANY, u"Label 2:")  #$NON-NLS-1$
        self.value2 = ZValidatingTextCtrl(ZValue2Validator(), self)

        self._bindEvents()

    # end createWidgets()

    def populateWidgets(self):
        value1 = self.userPrefs.getUserPreference(
            u"zoundry.test.pref.value1", u"")  #$NON-NLS-1$ #$NON-NLS-2$
        value2 = self.userPrefs.getUserPreference(
            u"zoundry.test.pref.value2", u"")  #$NON-NLS-1$ #$NON-NLS-2$

        self.value1.SetValue(value1)
        self.value2.SetValue(value2)

    # end populateWidgets()

    def layoutWidgets(self):
        sizer = wx.FlexGridSizer(3, 2, 5, 5)
        sizer.AddGrowableCol(1)
        sizer.Add(self.label1, 0,
                  wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 5)
        sizer.Add(self.value1, 0, wx.EXPAND | wx.RIGHT, 5)
        sizer.Add(self.label2, 0,
                  wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 5)
        sizer.Add(self.value2, 0, wx.EXPAND | wx.RIGHT, 5)
        self.SetAutoLayout(True)
        self.SetSizer(sizer)
        self.Layout()

    # end layoutWidgets()

    def _bindEvents(self):
        self.Bind(EVT_TEXT, self.onValue1Change, self.value1)
        self.Bind(EVT_TEXT, self.onValue2Change, self.value2)

        self._bindValidatingWidget(self.value1)
        self._bindValidatingWidget(self.value2)

    # end _bindEvents()

    def onValue1Change(self, event):  #@UnusedVariable
        self.userPrefs.setUserPreference(u"zoundry.test.pref.value1",
                                         self.value1.GetValue())  #$NON-NLS-1$

    # end onValue1Change

    def onValue2Change(self, event):  #@UnusedVariable
        self.userPrefs.setUserPreference(u"zoundry.test.pref.value2",
                                         self.value2.GetValue())  #$NON-NLS-1$
Exemplo n.º 2
0
class ZLinkDialog(ZValidatingHeaderDialog, ZPersistentDialogMixin):

    def __init__(self, parent, model):
        self.model = model
        ZValidatingHeaderDialog.__init__(self, parent, wx.ID_ANY, _extstr(u"linkdialog.EnterLinkInfo"), style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, name = u"ZLinkDialog") #$NON-NLS-2$ #$NON-NLS-1$

        bestHeight = self.GetBestSizeTuple()[1]
        self.SetMinSize(wx.Size(-1, bestHeight))

        ZPersistentDialogMixin.__init__(self, IZBlogAppUserPrefsKeys.LINK_DIALOG, True, True)
    # end __init__()

    def _createNonHeaderWidgets(self):
        wildcard = u"all files|*.*" #$NON-NLS-1$
        self.filePicker = wx.FilePickerCtrl(self, wildcard=wildcard,style=wx.FLP_OPEN|wx.FLP_FILE_MUST_EXIST )#|wx.FLP_USE_TEXTCTRL)
        
        self.urlLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"linkdialog.URL")) #$NON-NLS-1$ #$NON-NLS-2$
        self.titleLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"linkdialog.Title")) #$NON-NLS-1$ #$NON-NLS-2$
        self.targetLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"linkdialog.Target")) #$NON-NLS-1$ #$NON-NLS-2$
        self.classLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"linkdialog.Class")) #$NON-NLS-1$ #$NON-NLS-2$
        self.relLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"linkdialog.Rel")) #$NON-NLS-1$ #$NON-NLS-2$

        self.urlText = ZValidatingTextCtrl(ZFileUrlSelectionValidator(_extstr(u"linkdialog.InvalidURLError")), self, wx.ID_ANY) #$NON-NLS-1$
        self.titleText = wx.TextCtrl(self, wx.ID_ANY)
        self.newWindowCB = wx.CheckBox(self, wx.ID_ANY, _extstr(u"linkdialog.OpenInNewWindow")) #$NON-NLS-1$
        self.targetText = wx.TextCtrl(self, wx.ID_ANY)
        self.classText = wx.TextCtrl(self, wx.ID_ANY)
        self.relText = wx.TextCtrl(self, wx.ID_ANY)
    # end _createNonHeaderWidgets()

    def _populateNonHeaderWidgets(self):
        self.urlText.SetValue( getSafeString( self.model.getAttribute(u"href") ) ) #$NON-NLS-1$
        self.titleText.SetValue( getSafeString( self.model.getAttribute(u"title") ) ) #$NON-NLS-1$
        self.targetText.SetValue( getSafeString( self.model.getAttribute(u"target") ) ) #$NON-NLS-1$
        self.newWindowCB.SetValue( self.model.isOpenInNewWindow() )
        self.classText.SetValue( getSafeString( self.model.getAttribute(u"class") ) ) #$NON-NLS-1$
        self.relText.SetValue( getSafeString( self.model.getAttribute(u"rel") ) ) #$NON-NLS-1$

        if not self.model.isEditMode() and not self.urlText.GetValue():
            self.urlText.SetValue(u'http://') #$NON-NLS-1$
    # end _populateNonHeaderWidgets()

    def _updateModel(self):
        self.model.setAttribute(u"href", self.urlText.GetValue().strip()) #$NON-NLS-1$
        self.model.setAttribute(u"title", self.titleText.GetValue().strip() ) #$NON-NLS-1$
        self.model.setAttribute(u"class", self.classText.GetValue().strip() ) #$NON-NLS-1$
        self.model.setAttribute(u"rel", self.relText.GetValue().strip()) #$NON-NLS-1$
        if self.newWindowCB.IsChecked():
            target = self.targetText.GetValue().strip()
            if target == u"": #$NON-NLS-1$
                target = u"_blank" #$NON-NLS-1$
            self.model.setAttribute(u"target", target) #$NON-NLS-1$
        elif self.model.isOpenInNewWindow():
            # remove target attr.
            self.model.setAttribute(u"target", None) #$NON-NLS-1$
    # end _updateModel()

    def _layoutNonHeaderWidgets(self):
        hrefAndFileSizer = wx.BoxSizer(wx.HORIZONTAL)
        hrefAndFileSizer.Add(self.urlText, 1, wx.EXPAND | wx.ALL, 1)
        hrefAndFileSizer.Add(self.filePicker, 0, wx.ALL, 1)        
        
        flexGridSizer = wx.FlexGridSizer(6, 2, 2, 2)
        flexGridSizer.AddGrowableCol(1)
        flexGridSizer.Add(self.urlLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
        flexGridSizer.AddSizer(hrefAndFileSizer, 1, wx.EXPAND | wx.ALL, 2)
        flexGridSizer.Add(self.titleLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
        flexGridSizer.Add(self.titleText, 1, wx.EXPAND | wx.ALL, 2)
        flexGridSizer.Add(wx.StaticText(self, wx.ID_ANY, u""), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2) #$NON-NLS-1$
        flexGridSizer.Add(self.newWindowCB, 1, wx.EXPAND | wx.ALL, 2)
        flexGridSizer.Add(self.targetLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
        flexGridSizer.Add(self.targetText, 1, wx.EXPAND | wx.ALL, 2)
        flexGridSizer.Add(self.classLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
        flexGridSizer.Add(self.classText, 1, wx.EXPAND | wx.ALL, 2)
        flexGridSizer.Add(self.relLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
        flexGridSizer.Add(self.relText, 1, wx.EXPAND | wx.ALL, 2)

        staticBoxSizer = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, _extstr(u"linkdialog.LinkProperties")), wx.VERTICAL) #$NON-NLS-1$
        staticBoxSizer.AddSizer(flexGridSizer, 1, wx.EXPAND | wx.ALL, 5)

        self.targetText.Enable(False)

        return staticBoxSizer
    # end _layoutNonHeaderWidgets()

    def _setInitialFocus(self):
        self.urlText.SetFocus()
        if not self.model.isEditMode() and self.urlText.GetValue() and u"http://" != self.urlText.GetValue(): #$NON-NLS-1$
            self.urlText.SetSelection(-1, -1)
        else:
            self.urlText.SetInsertionPointEnd()
    # end _setInitialFocus()

    def _bindWidgetEvents(self):
        self._bindValidatingWidget(self.urlText)
        self.Bind(wx.EVT_CHECKBOX, self.onNewWindowCB, self.newWindowCB)
        self.Bind(wx.EVT_BUTTON, self.onOK, self.FindWindowById(wx.ID_OK))
        self.Bind(wx.EVT_FILEPICKER_CHANGED, self.onFilePickerChanged, self.filePicker)
    # end _bindWidgetEvents()

    def onOK(self, event):
        # persist settings to model.
        self._updateModel()
        event.Skip()
    # end onOK()
        
    def onFilePickerChanged(self, event):
        path = getNoneString( event.GetPath())
        if path:
            self.urlText.SetValue(path)
        event.Skip()
    # end onFilePickerChanged        

    def onNewWindowCB(self, event):
        self.targetText.Enable(event.IsChecked())
    # end onNewWindowCB()

    def _getHeaderTitle(self):
        if self.model.isEditMode():
            return _extstr(u"linkdialog.EditHyperlink") #$NON-NLS-1$
        else:
            return _extstr(u"linkdialog.CreateHyperlink") #$NON-NLS-1$
    # end _getHeaderTitle()

    def _getHeaderMessage(self):
        return _extstr(u"linkdialog.LinkDialogDescription") #$NON-NLS-1$
    # end _getHeaderMessage()

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

    def _getButtonTypes(self):
        return ZBaseDialog.OK_BUTTON | ZBaseDialog.CANCEL_BUTTON
Exemplo n.º 3
0
class ZImageDialog(ZValidatingHeaderDialog, ZPersistentDialogMixin):
    
    def __init__(self, parent, model):
        # model is instance of ZEditImageModel.
        self.model = model
        self.aspectRatio = 0.0
        
        title = _extstr(u"imagedialog.EditImageInformation") #$NON-NLS-1$
        if not self.model.isEditMode():
            title = _extstr(u"imagedialog.InsertImage") #$NON-NLS-1$
        ZValidatingHeaderDialog.__init__(self, parent, wx.ID_ANY, title, style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, name = u"ZImageDialog") #$NON-NLS-1$

        bestHeight = self.GetBestSizeTuple()[1]
        self.SetMinSize(wx.Size(-1, bestHeight))

        ZPersistentDialogMixin.__init__(self, IZBlogAppUserPrefsKeys.IMAGE_DIALOG, True, True)
    # end __init__()

    def _createNonHeaderWidgets(self):
        self.imagePropsStaticBox = wx.StaticBox(self, wx.ID_ANY, _extstr(u"imagedialog.ImageProperties")) #$NON-NLS-1$
        self.sizeStaticBox = wx.StaticBox(self, wx.ID_ANY, _extstr(u"imagedialog.Size")) #$NON-NLS-1$
        self.alignmentStaticBox = wx.StaticBox(self, wx.ID_ANY, _extstr(u"imagedialog.Alignment")) #$NON-NLS-1$
        self.borderStaticBox = wx.StaticBox(self, wx.ID_ANY, _extstr(u"imagedialog.Border")) #$NON-NLS-1$

        self.srcLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"imagedialog.Src")) #$NON-NLS-1$ #$NON-NLS-2$
        self.altTextLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"imagedialog.ALTText")) #$NON-NLS-1$ #$NON-NLS-2$
        self.titleLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"imagedialog.Title")) #$NON-NLS-1$ #$NON-NLS-2$
        self.classLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"imagedialog.Class")) #$NON-NLS-1$ #$NON-NLS-2$

        self.widthLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"imagedialog.Width")) #$NON-NLS-1$ #$NON-NLS-2$
        self.heightLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"imagedialog.Height")) #$NON-NLS-1$ #$NON-NLS-2$
        wildcard = u"Image files|*.gif;*.jpg;*.png;*.jpeg" #$NON-NLS-1$
        self.filePicker = wx.FilePickerCtrl(self, wildcard=wildcard,style=wx.FLP_OPEN|wx.FLP_FILE_MUST_EXIST )#|wx.FLP_USE_TEXTCTRL)

        self.srcText = ZValidatingTextCtrl(ZFileUrlSelectionValidator(_extstr(u"imagedialog.InvalidImageURLError")), self, wx.ID_ANY) #$NON-NLS-1$
        self.altText = wx.TextCtrl(self, wx.ID_ANY)
        self.titleText = wx.TextCtrl(self, wx.ID_ANY)
        self.classText = wx.TextCtrl(self, wx.ID_ANY)

        self.lockAspect = wx.CheckBox(self,wx.ID_ANY, u"%s" % _extstr(u"imagedialog.LockAspect")) #$NON-NLS-2$ #$NON-NLS-1$
        flags = ZIntegerSelectionValidator.ALLOW_EMPTY | ZIntegerSelectionValidator.ALLOW_ZERO | ZIntegerSelectionValidator.POSITIVE_ONLY
        self.widthText = ZValidatingTextCtrl(ZIntegerSelectionValidator(flags=flags), self, wx.ID_ANY)
        self.heightText = ZValidatingTextCtrl(ZIntegerSelectionValidator(flags=flags), self, wx.ID_ANY)

        alignments = []
        for aname in ZImageAlignMenuLabels.ALIGN_KEYWORDS:
            alignments.append( ZImageAlignMenuLabels.ALIGN_LABELS[aname] ) #$NON-NLS-1$
        self.alignChoices = wx.Choice(self, wx.ID_ANY, (100, 50), choices = alignments)

        self.borderStyleLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"imagedialog.Style")) #$NON-NLS-1$ #$NON-NLS-2$
        self.borderWidthLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"imagedialog.Width")) #$NON-NLS-1$ #$NON-NLS-2$
        self.borderColorLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"imagedialog.Color")) #$NON-NLS-1$ #$NON-NLS-2$
        
        borders = []
        for bname in ZImageBorderMenuLabels.BORDER_KEYWORDS:
            borders.append( ZImageBorderMenuLabels.BORDER_LABELS[bname] )
        
        self.borderStyles = wx.Choice(self, wx.ID_ANY, (200, 50), choices = borders)

        self.borderWidthValidator = ZCssLengthSelectionValidator()
        self.borderWidthText = ZValidatingTextCtrl(self.borderWidthValidator, self, wx.ID_ANY)
        self.borderColorPicker = wx.ColourPickerCtrl(self)

        self.marginStaticBox = wx.StaticBox(self, wx.ID_ANY, _extstr(u"imagedialog.Margin")) #$NON-NLS-1$
        self.marginLeftLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"imagedialog.Left")) #$NON-NLS-1$ #$NON-NLS-2$
        self.marginRightLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"imagedialog.Right")) #$NON-NLS-1$ #$NON-NLS-2$
        self.marginTopLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"imagedialog.Top")) #$NON-NLS-1$ #$NON-NLS-2$
        self.marginBotLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"imagedialog.Bottom")) #$NON-NLS-1$ #$NON-NLS-2$

        self.marginTopText = ZValidatingTextCtrl(ZCssLengthSelectionValidator(flags=ZCssLengthSelectionValidator.ALLOW_EMPTY), self, wx.ID_ANY)
        self.marginBotText = ZValidatingTextCtrl(ZCssLengthSelectionValidator(flags=ZCssLengthSelectionValidator.ALLOW_EMPTY), self, wx.ID_ANY)
        self.marginLeftText = ZValidatingTextCtrl(ZCssLengthSelectionValidator(flags=ZCssLengthSelectionValidator.ALLOW_EMPTY), self, wx.ID_ANY)
        self.marginRightText = ZValidatingTextCtrl(ZCssLengthSelectionValidator(flags=ZCssLengthSelectionValidator.ALLOW_EMPTY), self, wx.ID_ANY)
    # end _createNonHeaderWidgets()

    def _initAspectRatio(self):
        try:
            self.aspectRatio = (float(self.widthText.GetValue() ) / float(self.heightText.GetValue() ))
        except:
            self.aspectRatio = 0.0
        self.lockAspect.SetValue(self.aspectRatio > 0)
        self.lockAspect.Enable(self.aspectRatio > 0)
    # end _initAspectRatio()

    def _populateNonHeaderWidgets(self):
        self.srcText.SetValue( getSafeString( self.model.getAttribute(u"src") ) ) #$NON-NLS-1$
        self.altText.SetValue( getSafeString( self.model.getAttribute(u"alt") ) ) #$NON-NLS-1$
        self.titleText.SetValue( getSafeString( self.model.getAttribute(u"title") ) ) #$NON-NLS-1$
        self.classText.SetValue( getSafeString( self.model.getAttribute(u"class") ) ) #$NON-NLS-1$

        self.widthText.SetValue( getSafeString( self.model.getAttribute(u"width") ) ) #$NON-NLS-1$
        self.heightText.SetValue( getSafeString( self.model.getAttribute(u"height") ) ) #$NON-NLS-1$
        self._initAspectRatio()

        (top, right, bot, left) = self.model.getMargins()
        self.marginTopText.SetValue(getSafeString(top))
        self.marginRightText.SetValue(getSafeString(right))
        self.marginBotText.SetValue(getSafeString(bot))
        self.marginLeftText.SetValue(getSafeString(left))

        (width, style, cssColor) = self.model.getBorder()
        if cssColor:
            color = wx.Colour(cssColor.getRed(), cssColor.getGreen(), cssColor.getBlue())
            self.borderColorPicker.SetColour(color)
        self.borderWidthText.SetValue(getSafeString(width))
        style = getSafeString(style).lower()
        idx = 0
        try:
            idx = ZImageBorderMenuLabels.BORDER_KEYWORDS.index( style )
        except:
            idx = 0
        self.borderStyles.SetSelection(idx)
        self._updateBorderControlsState()

        align = getSafeString( self.model.getAttribute(u"align") ) #$NON-NLS-1$
        # align = None, Left etc.
        # find index within keywords
        idx = 0
        try:
            idx = ZImageAlignMenuLabels.ALIGN_KEYWORDS.index( align.lower() )
        except:
            idx = 0
        self.alignChoices.SetSelection(idx)

    # end _populateNonHeaderWidgets()

    def _layoutNonHeaderWidgets(self):
        # Image Properties
        srcAndFileSizer = wx.BoxSizer(wx.HORIZONTAL)
        srcAndFileSizer.Add(self.srcText, 1, wx.EXPAND | wx.ALL, 1)
        srcAndFileSizer.Add(self.filePicker, 0, wx.ALL, 1)

        imagePropsGridSizer = wx.FlexGridSizer(4, 2, 2, 2)
        imagePropsGridSizer.AddGrowableCol(1)
        imagePropsGridSizer.Add(self.srcLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        imagePropsGridSizer.AddSizer(srcAndFileSizer, 1, wx.EXPAND | wx.ALL, 1)

        imagePropsGridSizer.Add(self.altTextLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        imagePropsGridSizer.Add(self.altText, 1, wx.EXPAND | wx.ALL, 1)
        imagePropsGridSizer.Add(self.titleLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        imagePropsGridSizer.Add(self.titleText, 1, wx.EXPAND | wx.ALL, 1)
        imagePropsGridSizer.Add(self.classLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        imagePropsGridSizer.Add(self.classText, 1, wx.EXPAND | wx.ALL, 1)

        imagePropsStaticBoxSizer = wx.StaticBoxSizer(self.imagePropsStaticBox, wx.VERTICAL)
        imagePropsStaticBoxSizer.AddSizer(imagePropsGridSizer, 1, wx.EXPAND | wx.ALL, 5)

        # Size
        sizeGridSizer = wx.FlexGridSizer(2, 2, 2, 2)
        sizeGridSizer.Add(self.widthLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        sizeGridSizer.Add(self.widthText, 1, wx.EXPAND | wx.ALL, 1)
        sizeGridSizer.Add(self.heightLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        sizeGridSizer.Add(self.heightText, 1, wx.EXPAND | wx.ALL, 1)

        sizeStaticBoxSizer = wx.StaticBoxSizer(self.sizeStaticBox, wx.VERTICAL)
        sizeStaticBoxSizer.Add(self.lockAspect, 0,  wx.EXPAND | wx.ALL, 5)
        sizeStaticBoxSizer.AddSizer(sizeGridSizer, 1, wx.EXPAND | wx.ALL, 5)

        alignmentStaticBoxSizer = wx.StaticBoxSizer(self.alignmentStaticBox, wx.VERTICAL)
        alignmentStaticBoxSizer.Add(self.alignChoices, 1, wx.EXPAND | wx.ALL, 5)

        # Border
        borderGridSizer = wx.FlexGridSizer(3, 2, 2, 2)
        borderGridSizer.Add(self.borderStyleLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        borderGridSizer.Add(self.borderStyles, 1, wx.EXPAND | wx.ALL, 1)
        borderGridSizer.Add(self.borderWidthLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        borderGridSizer.Add(self.borderWidthText, 1, wx.EXPAND | wx.ALL, 1)
        borderGridSizer.Add(self.borderColorLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        borderGridSizer.Add(self.borderColorPicker, 0,wx.ALL, 1)
        borderStaticBoxSizer = wx.StaticBoxSizer(self.borderStaticBox, wx.VERTICAL)
        borderStaticBoxSizer.AddSizer(borderGridSizer, 1, wx.EXPAND | wx.ALL, 5)

        marginGridSizer = wx.FlexGridSizer(4, 4, 2, 2)
        marginGridSizer.Add(self.marginTopLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        marginGridSizer.Add(self.marginTopText, 1, wx.EXPAND | wx.ALL, 1)
        marginGridSizer.Add(self.marginLeftLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        marginGridSizer.Add(self.marginLeftText, 1, wx.EXPAND | wx.ALL, 1)
        marginGridSizer.Add(self.marginBotLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        marginGridSizer.Add(self.marginBotText, 1, wx.EXPAND | wx.ALL, 1)
        marginGridSizer.Add(self.marginRightLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        marginGridSizer.Add(self.marginRightText, 1, wx.EXPAND | wx.ALL, 1)
        marginStaticBoxSizer = wx.StaticBoxSizer(self.marginStaticBox, wx.VERTICAL)
        marginStaticBoxSizer.AddSizer(marginGridSizer, 1, wx.EXPAND | wx.ALL, 5)


        # Size + Alignment Box Sizer
        sizeAndAlignmentBoxSizer = wx.FlexGridSizer(2, 2, 2, 2)
        sizeAndAlignmentBoxSizer.AddSizer(sizeStaticBoxSizer, 1, wx.EXPAND | wx.ALL, 2)
        sizeAndAlignmentBoxSizer.AddSizer(borderStaticBoxSizer, 1, wx.EXPAND | wx.ALL, 2)
        sizeAndAlignmentBoxSizer.AddSizer(alignmentStaticBoxSizer, 1, wx.EXPAND | wx.ALL, 2)
        sizeAndAlignmentBoxSizer.AddSizer(marginStaticBoxSizer, 1, wx.EXPAND | wx.ALL, 2)

        # Dialog Sizer
        dialogBoxSizer = wx.BoxSizer(wx.VERTICAL)
        dialogBoxSizer.AddSizer(imagePropsStaticBoxSizer, 0, wx.EXPAND | wx.ALL, 5)
        dialogBoxSizer.AddSizer(sizeAndAlignmentBoxSizer, 0, wx.EXPAND | wx.ALL, 5)

        return dialogBoxSizer
    # end _layoutNonHeaderWidgets()

    def _bindWidgetEvents(self):
        self.Bind(wx.EVT_FILEPICKER_CHANGED, self.onFilePickerChanged, self.filePicker)
        self.Bind(wx.EVT_CHOICE, self.onBorderStyleChanged, self.borderStyles)
        self.Bind(wx.EVT_TEXT, self.onImageWidthChange, self.widthText)
        self.Bind(wx.EVT_TEXT, self.onImageHeightChange, self.heightText)

        self._bindValidatingWidget(self.srcText)
        self._bindValidatingWidget(self.widthText)
        self._bindValidatingWidget(self.heightText)
        self._bindValidatingWidget(self.borderWidthText)
        self._bindValidatingWidget(self.marginTopText)
        self._bindValidatingWidget(self.marginRightText)
        self._bindValidatingWidget(self.marginBotText)
        self._bindValidatingWidget(self.marginLeftText)

        self.Bind(wx.EVT_BUTTON, self.onOK, self.FindWindowById(wx.ID_OK))
    # end _bindWidgetEvents()

    def _updateModel(self):
        self.model.setAttribute(u"src", self.srcText.GetValue().strip() ) #$NON-NLS-1$
        self.model.setAttribute(u"alt", self.altText.GetValue().strip() ) #$NON-NLS-1$
        self.model.setAttribute(u"title", self.titleText.GetValue().strip() ) #$NON-NLS-1$
        self.model.setAttribute(u"class", self.classText.GetValue().strip() ) #$NON-NLS-1$

        idx = self.alignChoices.GetSelection()
        if idx >=0 and idx < len(ZImageAlignMenuLabels.ALIGN_KEYWORDS):
            align = ZImageAlignMenuLabels.ALIGN_KEYWORDS[idx]
            self.model.setAttribute(u"align", align.lower() ) #$NON-NLS-1$

        # Width and height
        width = 0
        height = 0
        try:
            width = int(self.widthText.GetValue())
            height = int(self.heightText.GetValue())
        except:
            pass
        if width > 0 and height > 0:
            self.model.setAttribute(u"width", u"%d" % width ) #$NON-NLS-1$ #$NON-NLS-2$
            self.model.setAttribute(u"height", u"%d" % height ) #$NON-NLS-1$ #$NON-NLS-2$
        # Margin
        t = self.marginTopText.GetValue().strip()
        r = self.marginRightText.GetValue().strip()
        b = self.marginBotText.GetValue().strip()
        l = self.marginLeftText.GetValue().strip()
        self.model.setMargins(t,r,b,l)
        # Border
        style = ZImageBorderMenuLabels.BORDER_KEYWORDS[0] # default is None
        idx = self.borderStyles.GetSelection()
        if idx >=0 and idx < len(ZImageBorderMenuLabels.BORDER_KEYWORDS):
            style = ZImageBorderMenuLabels.BORDER_KEYWORDS[idx]
        width = self.borderWidthText.GetValue().strip()
        cssHexColor = self.borderColorPicker.GetColour().GetAsString(wx.C2S_HTML_SYNTAX)
        self.model.setBorder(width, style, cssHexColor)
    # end updateModel

    def onOK(self, event):
        self._updateModel()
        event.Skip()
    # end onOK()

    def onImageHeightChange(self, event): #@UnusedVariable
        if self.lockAspect.IsChecked() and self.aspectRatio > 0:
            try:
                height = int(self.heightText.GetValue())
                width = int(height * self.aspectRatio)
                self.widthText.ChangeValue(unicode(width))
            except:
                pass
            event.Skip()
    # end onImageHeightChange()

    def onImageWidthChange(self, event): #@UnusedVariable
        if self.lockAspect.IsChecked() and self.aspectRatio > 0:
            try:
                width = int(self.widthText.GetValue())
                height = int(width / self.aspectRatio)
                self.heightText.ChangeValue(unicode(height))
            except:
                pass
            event.Skip()
    # end onImageWidthChange()

    def _updateBorderControlsState(self):
        enable = self.borderStyles.GetCurrentSelection() > 0
        if enable:
            self.borderWidthValidator.setFlags(0)
        else:
            self.borderWidthValidator.setFlags(ZCssLengthSelectionValidator.ALLOW_EMPTY)
            self.borderWidthText.validate()

        if enable and not self.borderWidthText.GetValue():
            self.borderWidthText.SetValue(u"1px") #$NON-NLS-1$
        self.borderWidthText.Enable(enable)
        self.borderColorPicker.Enable(enable)
    # end _updateBorderControlsState()

    def onBorderStyleChanged(self, event): #@UnusedVariable
        self._updateBorderControlsState()
    # end onBorderStyleChanged

    def onFilePickerChanged(self, event):
        path = getNoneString( event.GetPath())
        if path:
            self.srcText.SetValue(path)
        event.Skip()
    # end onFilePickerChanged

    def _getHeaderTitle(self):
        if self.model.isEditMode():
            return _extstr(u"imagedialog.Edit_Image") #$NON-NLS-1$
        else:
            return _extstr(u"imagedialog.Insert_Image") #$NON-NLS-1$
    # end _getHeaderTitle()

    def _getHeaderMessage(self):
        if self.model.isEditMode():
            return _extstr(u"imagedialog.ImageDialogEditDescription") #$NON-NLS-1$
        else:
            return _extstr(u"imagedialog.ImageDialogInsertDescription") #$NON-NLS-1$
    # end _getHeaderMessage()

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

    def _getButtonTypes(self):
        return ZBaseDialog.OK_BUTTON | ZBaseDialog.CANCEL_BUTTON
Exemplo n.º 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
Exemplo n.º 5
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
Exemplo n.º 6
0
class ZAccountSettingsPrefSubPage(ZAccountPrefsSubPage):
    def __init__(self, parent, session):
        ZAccountPrefsSubPage.__init__(self, parent, session)

    # end __init__()

    def _createWidgets(self):
        self.staticBox = wx.StaticBox(
            self, wx.ID_ANY,
            _extstr(u"settingssubpage.Credentials"))  #$NON-NLS-1$
        self.usernameLabel = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"settingssubpage.Username"))  #$NON-NLS-1$
        self.username = ZValidatingTextCtrl(
            ZNonEmptySelectionValidator(
                _extstr(u"settingssubpage.InvalidUsernameError")),
            self)  #$NON-NLS-1$
        self.passwordLabel = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"settingssubpage.Password"))  #$NON-NLS-1$
        self.password = ZValidatingPasswordCtrl(
            ZNonEmptySelectionValidator(
                _extstr(u"settingssubpage.InvalidPasswordError")),
            self)  #$NON-NLS-1$

        # FIXME (EPW) add read-only widget for the API type
        self.staticBox2 = wx.StaticBox(
            self, wx.ID_ANY,
            _extstr(u"settingssubpage.APIInformation"))  #$NON-NLS-1$
        self.endpointLabel = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"settingssubpage.Endpoint"))  #$NON-NLS-1$
        self.endpoint = ZValidatingTextCtrl(
            ZUrlSelectionValidator(
                _extstr(u"settingssubpage.InvalidEndpointError")),
            self)  #$NON-NLS-1$

    # end _createWidgets()

    def _bindWidgetEvents(self):
        self._bindValidatingWidget(self.username)
        self._bindValidatingWidget(self.password)
        self._bindValidatingWidget(self.endpoint)

        self.Bind(wx.EVT_TEXT, self.onUsername, self.username)
        self.Bind(wx.EVT_TEXT, self.onPassword, self.password)
        self.Bind(wx.EVT_TEXT, self.onEndpoint, self.endpoint)

    # end _bindWidgetEvents()

    def _populateWidgets(self):
        username = self._getSession().getAccountUsername()
        password = self._getSession().getAccountPassword()
        endpoint = self._getSession().getAccountAPIUrl()
        self.username.SetValue(getSafeString(username))
        self.password.SetValue(getSafeString(password))
        self.endpoint.SetValue(getSafeString(endpoint))

    # end _populateWidgets()

    def _layoutWidgets(self):
        box = wx.BoxSizer(wx.VERTICAL)

        flexGridSizer = wx.FlexGridSizer(2, 2, 5, 5)
        flexGridSizer.AddGrowableCol(1)

        flexGridSizer.Add(self.usernameLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
                          2)
        flexGridSizer.Add(self.username, 0, wx.EXPAND | wx.ALL, 2)
        flexGridSizer.Add(self.passwordLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
                          2)
        flexGridSizer.Add(self.password, 0, wx.EXPAND | wx.ALL, 2)

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

        flexGridSizer = wx.FlexGridSizer(1, 2, 5, 5)
        flexGridSizer.AddGrowableCol(1)
        flexGridSizer.Add(self.endpointLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
                          2)
        flexGridSizer.Add(self.endpoint, 0, wx.EXPAND | wx.ALL, 2)

        # Static box sizer that has a label of "API Information"
        staticBoxSizer = wx.StaticBoxSizer(self.staticBox2, wx.VERTICAL)
        staticBoxSizer.AddSizer(flexGridSizer, 0, wx.EXPAND | wx.ALL, 5)
        box.AddSizer(staticBoxSizer, 0, wx.EXPAND | wx.ALL, 5)

        self.SetAutoLayout(True)
        self.SetSizer(box)
        self.Layout()

    # end layoutWidgets()

    def onUsername(self, event):
        self._getSession().setAccountUsername(self.username.GetValue())
        event.Skip()

    # end onUsername()

    def onPassword(self, event):
        self._getSession().setAccountPassword(self.password.GetValue())
        event.Skip()

    # end onPassword()

    def onEndpoint(self, event):
        self._getSession().setAccountAPIUrl(self.endpoint.GetValue())
        event.Skip()
Exemplo n.º 7
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]
Exemplo n.º 8
0
class ZThumbnailImageDialog(ZValidatingHeaderDialog, ZPersistentDialogMixin):

    def __init__(self, parent):
        self.model = ZThumbnailImageDialogModel()
        title = _extstr(u"imagehandlerdialog.Generate_Thumbnail") #$NON-NLS-1$
        ZValidatingHeaderDialog.__init__(self, parent, wx.ID_ANY, title, style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, name = u"ZThumbnailImageDialog") #$NON-NLS-1$

        bestHeight = self.GetBestSizeTuple()[1]
        self.SetMinSize(wx.Size(-1, bestHeight))

        ZPersistentDialogMixin.__init__(self, IZBlogAppUserPrefsKeys.DND_THUMBNAIL_DIALOG, True, True)
    # end __init__()

    def _createNonHeaderWidgets(self):
        self.doNotGenRadioButton = wx.RadioButton(self, wx.ID_ANY, _extstr(u"imagehandlerdialog.DoNotGenerateOption")) #$NON-NLS-1$
        self.genRadioButton = wx.RadioButton(self, wx.ID_ANY, _extstr(u"imagehandlerdialog.GenerateOption")) #$NON-NLS-1$

        self.tnSettingsGroupBox = wx.StaticBox(self, wx.ID_ANY, _extstr(u"imagehandlerdialog.ThumbnailSettings")) #$NON-NLS-1$
        self.sizeLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"imagehandlerdialog.Size")) #$NON-NLS-1$ #$NON-NLS-2$

        sizeChoices = []
        for size in ZThumbnailSizeMenuLabels.SIZE_KEYWORDS:
            sizeChoices.append(ZThumbnailSizeMenuLabels.SIZE_LABELS[size])
        self.sizeChoice = wx.Choice(self, wx.ID_ANY, (100, 50), choices = sizeChoices)

        self.alignLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _blogappextstr(u"imagedialog.Alignment")) #$NON-NLS-1$ #$NON-NLS-2$
        alignments = []
        for aname in ZImageAlignMenuLabels.ALIGN_KEYWORDS:
            alignments.append( ZImageAlignMenuLabels.ALIGN_LABELS[aname] ) #$NON-NLS-1$
        self.alignChoice = wx.Choice(self, wx.ID_ANY, (100, 50), choices = alignments)

        self.borderStaticBox = wx.StaticBox(self, wx.ID_ANY, _blogappextstr(u"imagedialog.Border")) #$NON-NLS-1$
        self.borderStyleLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _blogappextstr(u"imagedialog.Style")) #$NON-NLS-1$ #$NON-NLS-2$
        self.borderWidthLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _blogappextstr(u"imagedialog.Width")) #$NON-NLS-1$ #$NON-NLS-2$
        self.borderColorLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _blogappextstr(u"imagedialog.Color")) #$NON-NLS-1$ #$NON-NLS-2$

        borders = []
        for bname in ZImageBorderMenuLabels.BORDER_KEYWORDS:
            borders.append( ZImageBorderMenuLabels.BORDER_LABELS[bname] )
        self.borderStyleChoice = wx.Choice(self, wx.ID_ANY, (200, 50), choices = borders)

        self.borderWidthValidator = ZCssLengthSelectionValidator()
        self.borderWidthText = ZValidatingTextCtrl(self.borderWidthValidator, self, wx.ID_ANY)
        self.borderColorPicker = wx.ColourPickerCtrl(self)

        self.marginStaticBox = wx.StaticBox(self, wx.ID_ANY, _blogappextstr(u"imagedialog.Margin")) #$NON-NLS-1$
        self.marginLeftLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _blogappextstr(u"imagedialog.Left")) #$NON-NLS-1$ #$NON-NLS-2$
        self.marginRightLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _blogappextstr(u"imagedialog.Right")) #$NON-NLS-1$ #$NON-NLS-2$
        self.marginTopLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _blogappextstr(u"imagedialog.Top")) #$NON-NLS-1$ #$NON-NLS-2$
        self.marginBotLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _blogappextstr(u"imagedialog.Bottom")) #$NON-NLS-1$ #$NON-NLS-2$

        self.marginTopText = ZValidatingTextCtrl(ZCssLengthSelectionValidator(flags=ZCssLengthSelectionValidator.ALLOW_EMPTY), self, wx.ID_ANY, size=wx.Size(25, -1))
        self.marginBotText = ZValidatingTextCtrl(ZCssLengthSelectionValidator(flags=ZCssLengthSelectionValidator.ALLOW_EMPTY), self, wx.ID_ANY, size=wx.Size(25, -1))
        self.marginLeftText = ZValidatingTextCtrl(ZCssLengthSelectionValidator(flags=ZCssLengthSelectionValidator.ALLOW_EMPTY), self, wx.ID_ANY, size=wx.Size(25, -1))
        self.marginRightText = ZValidatingTextCtrl(ZCssLengthSelectionValidator(flags=ZCssLengthSelectionValidator.ALLOW_EMPTY), self, wx.ID_ANY, size=wx.Size(25, -1))
    # end _createNonHeaderWidgets()

    def _populateNonHeaderWidgets(self):
        genTNFlag = self.model.generateTNFlag
        self.genRadioButton.SetValue(genTNFlag)
        self.doNotGenRadioButton.SetValue(not genTNFlag)
        self._enableWidgets(genTNFlag)

        tnSize = self._recallThumbnailSize()
        idx = 0
        try:
            idx = ZThumbnailSizeMenuLabels.SIZE_KEYWORDS.index( tnSize )
        except:
            idx = 1
        self.sizeChoice.SetSelection(idx)

        (top, right, bot, left) = self._recallMargins()
        self.marginTopText.SetValue(getSafeString(top))
        self.marginRightText.SetValue(getSafeString(right))
        self.marginBotText.SetValue(getSafeString(bot))
        self.marginLeftText.SetValue(getSafeString(left))

        (width, style, cssColor) = self._recallBorder()
        if cssColor:
            red = cssColor[0]
            green = cssColor[1]
            blue = cssColor[2]
            color = wx.Colour(red, green, blue)
            self.borderColorPicker.SetColour(color)
        self.borderWidthText.SetValue(getSafeString(width))
        style = getSafeString(style).lower()
        idx = 0
        try:
            idx = ZImageBorderMenuLabels.BORDER_KEYWORDS.index( style )
        except:
            idx = 0
        self.borderStyleChoice.SetSelection(idx)
        self._updateBorderControlsState()

        align = getSafeString(self._recallAlignment())
        idx = 0
        try:
            idx = ZImageAlignMenuLabels.ALIGN_KEYWORDS.index( align.lower() )
        except:
            idx = 0
        self.alignChoice.SetSelection(idx)
    # end _populateNonHeaderWidgets()

    def _recallThumbnailSize(self):
        return self.model.size
    # end _recallThumbnailSize()

    def _recallMargins(self):
        return (self.model.marginTop, self.model.marginRight, self.model.marginBottom, self.model.marginLeft)
    # end _recallMargins()

    def _recallBorder(self):
        return (self.model.borderWidth, self.model.borderStyle, self.model.borderColor)
    # end _recallBorder()

    def _recallAlignment(self):
        return self.model.alignment
    # end _recallAlignment()

    def _layoutNonHeaderWidgets(self):
        # Border
        borderGridSizer = wx.FlexGridSizer(3, 2, 2, 2)
        borderGridSizer.Add(self.borderStyleLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        borderGridSizer.Add(self.borderStyleChoice, 1, wx.EXPAND | wx.ALL, 1)
        borderGridSizer.Add(self.borderWidthLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        borderGridSizer.Add(self.borderWidthText, 1, wx.EXPAND | wx.ALL, 1)
        borderGridSizer.Add(self.borderColorLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        borderGridSizer.Add(self.borderColorPicker, 0,wx.ALL, 1)

        # Margins
        marginGridSizer = wx.FlexGridSizer(4, 4, 2, 2)
        marginGridSizer.AddGrowableCol(1)
        marginGridSizer.AddGrowableCol(3)
        marginGridSizer.Add(self.marginTopLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        marginGridSizer.Add(self.marginTopText, 1, wx.EXPAND | wx.ALL, 1)
        marginGridSizer.Add(self.marginLeftLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        marginGridSizer.Add(self.marginLeftText, 1, wx.EXPAND | wx.ALL, 1)
        marginGridSizer.Add(self.marginBotLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        marginGridSizer.Add(self.marginBotText, 1, wx.EXPAND | wx.ALL, 1)
        marginGridSizer.Add(self.marginRightLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
        marginGridSizer.Add(self.marginRightText, 1, wx.EXPAND | wx.ALL, 1)

        borderSizer = wx.StaticBoxSizer(self.borderStaticBox, wx.VERTICAL)
        borderSizer.AddSizer(borderGridSizer, 1, wx.EXPAND | wx.ALL, 2)

        marginSizer = wx.StaticBoxSizer(self.marginStaticBox, wx.VERTICAL)
        marginSizer.AddSizer(marginGridSizer, 1, wx.EXPAND | wx.ALL, 2)

        sizeSizer = wx.BoxSizer(wx.HORIZONTAL)
        sizeSizer.Add(self.sizeLabel, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2)
        sizeSizer.Add(self.sizeChoice, 0, wx.ALL, 2)

        alignSizer = wx.BoxSizer(wx.HORIZONTAL)
        alignSizer.Add(self.alignLabel, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2)
        alignSizer.Add(self.alignChoice, 0, wx.ALL, 2)

        sizeAndBorderSizer = wx.BoxSizer(wx.VERTICAL)
        sizeAndBorderSizer.AddSizer(sizeSizer, 0, wx.EXPAND | wx.ALL, 1)
        sizeAndBorderSizer.AddSizer(borderSizer, 1, wx.EXPAND | wx.ALL, 1)

        alignAndMarginSizer = wx.BoxSizer(wx.VERTICAL)
        alignAndMarginSizer.AddSizer(alignSizer, 0, wx.EXPAND | wx.ALL, 1)
        alignAndMarginSizer.AddSizer(marginSizer, 1, wx.EXPAND | wx.ALL, 1)

        twoColumnSizer = wx.BoxSizer(wx.HORIZONTAL)
        twoColumnSizer.AddSizer(sizeAndBorderSizer, 2, wx.EXPAND | wx.ALL, 1)
        twoColumnSizer.AddSizer(alignAndMarginSizer, 3, wx.EXPAND | wx.ALL, 1)

        tnSettingsSizer = wx.StaticBoxSizer(self.tnSettingsGroupBox, wx.VERTICAL)
        tnSettingsSizer.AddSizer(twoColumnSizer, 0, wx.EXPAND | wx.ALL, 2)

        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(self.doNotGenRadioButton, 0, wx.ALL, 3)
        mainSizer.Add(self.genRadioButton, 0, wx.ALL, 3)
        mainSizer.AddSizer(tnSettingsSizer, 1, wx.EXPAND | wx.ALL, 3)

        return mainSizer
    # end _layoutNonHeaderWidgets()

    def _bindWidgetEvents(self):
        self.Bind(wx.EVT_CHOICE, self.onBorderStyleChanged, self.borderStyleChoice)
        self.Bind(wx.EVT_RADIOBUTTON, self.onDoNotGenButton, self.doNotGenRadioButton)
        self.Bind(wx.EVT_RADIOBUTTON, self.onGenerateButton, self.genRadioButton)

        self._bindValidatingWidget(self.borderWidthText)
        self._bindValidatingWidget(self.marginTopText)
        self._bindValidatingWidget(self.marginRightText)
        self._bindValidatingWidget(self.marginBotText)
        self._bindValidatingWidget(self.marginLeftText)

        self.Bind(wx.EVT_BUTTON, self.onOK, self.FindWindowById(wx.ID_OK))
    # end _bindWidgetEvents()

    def _enableWidgets(self, enabled = True):
        self.tnSettingsGroupBox.Enable(enabled)
        self.sizeLabel.Enable(enabled)
        self.sizeChoice.Enable(enabled)
        self.alignLabel.Enable(enabled)
        self.alignChoice.Enable(enabled)
        self.borderStaticBox.Enable(enabled)
        self.borderStyleLabel.Enable(enabled)
        self.borderStyleChoice.Enable(enabled)
        self.borderWidthLabel.Enable(enabled)
        self.borderWidthText.Enable(enabled)
        self.borderColorLabel.Enable(enabled)
        self.borderColorPicker.Enable(enabled)
        self.marginStaticBox.Enable(enabled)
        self.marginTopLabel.Enable(enabled)
        self.marginTopText.Enable(enabled)
        self.marginLeftLabel.Enable(enabled)
        self.marginLeftText.Enable(enabled)
        self.marginBotLabel.Enable(enabled)
        self.marginBotText.Enable(enabled)
        self.marginRightLabel.Enable(enabled)
        self.marginRightText.Enable(enabled)
    # end _enableWidgets()

    def _updateModel(self):
        self.model.generateTNFlag = self.genRadioButton.GetValue()

        # TN Size
        idx = self.sizeChoice.GetSelection()
        if idx >=0 and idx < len(ZThumbnailSizeMenuLabels.SIZE_KEYWORDS):
            size = ZThumbnailSizeMenuLabels.SIZE_KEYWORDS[idx]
            self.model.size = size

        # Alignment
        idx = self.alignChoice.GetSelection()
        if idx >=0 and idx < len(ZImageAlignMenuLabels.ALIGN_KEYWORDS):
            align = ZImageAlignMenuLabels.ALIGN_KEYWORDS[idx]
            self.model.alignment = align

        # Margin
        t = self.marginTopText.GetValue().strip()
        r = self.marginRightText.GetValue().strip()
        b = self.marginBotText.GetValue().strip()
        l = self.marginLeftText.GetValue().strip()
        self.model.marginTop = t
        self.model.marginRight = r
        self.model.marginBottom = b
        self.model.marginLeft = l

        # Border
        style = ZImageBorderMenuLabels.BORDER_KEYWORDS[0] # default is None
        idx = self.borderStyleChoice.GetSelection()
        if idx >=0 and idx < len(ZImageBorderMenuLabels.BORDER_KEYWORDS):
            style = ZImageBorderMenuLabels.BORDER_KEYWORDS[idx]
        width = self.borderWidthText.GetValue().strip()
        color = self.borderColorPicker.GetColour()

        self.model.borderStyle = style
        self.model.borderWidth = width
        self.model.borderColor = (color.Red(), color.Green(), color.Blue())
    # end updateModel()

    def onDoNotGenButton(self, event):
        self._enableWidgets(False)
        self.isValid = True
        self._doValid()
        event.Skip()
    # end onDoNotGenButton()

    def onGenerateButton(self, event):
        self._enableWidgets(True)
        self._validate()
        event.Skip()
    # end onGenerateButton()

    def onOK(self, event):
        self._updateModel()
        self.model._saveToPrefs()
        event.Skip()
    # end onOK()

    def _updateBorderControlsState(self):
        enable = self.borderStyleChoice.GetCurrentSelection() > 0
        if enable:
            self.borderWidthValidator.setFlags(0)
        else:
            self.borderWidthValidator.setFlags(ZCssLengthSelectionValidator.ALLOW_EMPTY)
            self.borderWidthText.validate()

        if enable and not self.borderWidthText.GetValue():
            self.borderWidthText.SetValue(u"1px") #$NON-NLS-1$
        self.borderWidthText.Enable(enable)
        self.borderColorPicker.Enable(enable)
    # end _updateBorderControlsState()

    def onBorderStyleChanged(self, event):
        self._updateBorderControlsState()
        event.Skip()
    # end onBorderStyleChanged()

    def getModel(self):
        return self.model
    # end getModel()

    def _getHeaderTitle(self):
        return _extstr(u"imagehandlerdialog.CreateImageThumbnail") #$NON-NLS-1$
    # end _getHeaderTitle()

    def _getHeaderMessage(self):
        return _extstr(u"imagehandlerdialog.CreateImageThumbnailDesc") #$NON-NLS-1$
    # end _getHeaderMessage()

    def _getHeaderImagePath(self):
        return u"images/dialogs/image/header_image.png" #$NON-NLS-1$
Exemplo n.º 9
0
class ZInsertTableDialog(ZBaseDialog):
    def __init__(self, parent, model):
        # model is instance of ZTableModel.
        self.model = model
        ZBaseDialog.__init__(
            self,
            parent,
            wx.ID_ANY,
            _extstr(u"tabledialog.DialogTitle"),
            style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
            name=u"ZInsertTableDialog")  #$NON-NLS-1$ #$NON-NLS-2$
        bestHeight = self.GetBestSizeTuple()[1]
        self.SetSize(wx.Size(-1, bestHeight))

    # end __init__()

    def _getButtonTypes(self):
        return ZBaseDialog.OK_BUTTON | ZBaseDialog.CANCEL_BUTTON

    # end _getButtonTypes()

    def _createContentWidgets(self):
        self.settingsStaticBox = wx.StaticBox(
            self, wx.ID_ANY,
            _extstr(u"tabledialog.TableSettings"))  #$NON-NLS-1$
        if self.model.isInsertMode():
            self.rowsLabel = wx.StaticText(
                self, wx.ID_ANY, u"%s:" %
                _extstr(u"tabledialog.Rows"))  #$NON-NLS-1$ #$NON-NLS-2$
            self.rowsText = ZValidatingTextCtrl(
                ZIntegerSelectionValidator(
                    flags=ZIntegerSelectionValidator.POSITIVE_ONLY), self,
                wx.ID_ANY)
            self.colsLabel = wx.StaticText(
                self, wx.ID_ANY, u"%s:" %
                _extstr(u"tabledialog.Cols"))  #$NON-NLS-1$ #$NON-NLS-2$
            self.colsText = ZValidatingTextCtrl(
                ZIntegerSelectionValidator(
                    flags=ZIntegerSelectionValidator.POSITIVE_ONLY), self,
                wx.ID_ANY)

        flags = ZCssLengthSelectionValidator.ALLOW_EMPTY

        self.paddingLabel = wx.StaticText(
            self, wx.ID_ANY, u"%s:" %
            _extstr(u"tabledialog.CellPadding"))  #$NON-NLS-1$ #$NON-NLS-2$
        self.paddingText = ZValidatingTextCtrl(
            ZCssLengthSelectionValidator(flags=flags), self, wx.ID_ANY)
        self.spacingLabel = wx.StaticText(
            self, wx.ID_ANY, u"%s:" %
            _extstr(u"tabledialog.CellSpacing"))  #$NON-NLS-1$ #$NON-NLS-2$
        self.spacingText = ZValidatingTextCtrl(
            ZCssLengthSelectionValidator(flags=flags), self, wx.ID_ANY)
        self.borderLabel = wx.StaticText(
            self, wx.ID_ANY,
            u"%s:" % _extstr(u"tabledialog.Border"))  #$NON-NLS-1$ #$NON-NLS-2$
        self.borderText = ZValidatingTextCtrl(
            ZCssLengthSelectionValidator(flags=flags), self, wx.ID_ANY)
        self.widthLabel = wx.StaticText(
            self, wx.ID_ANY,
            u"%s:" % _extstr(u"tabledialog.Width"))  #$NON-NLS-1$ #$NON-NLS-2$
        self.widthText = ZValidatingTextCtrl(ZCssLengthSelectionValidator(),
                                             self, wx.ID_ANY)

    # end _createNonHeaderWidgets()

    def _populateContentWidgets(self):
        if self.model.isInsertMode():
            self.rowsText.SetValue(str(self.model.getRows()))
            self.colsText.SetValue(str(self.model.getCols()))

        self.borderText.SetValue(getSafeString(self.model.getBorder()))
        self.paddingText.SetValue(getSafeString(self.model.getPadding()))
        self.spacingText.SetValue(getSafeString(self.model.getSpacing()))
        self.widthText.SetValue(getSafeString(self.model.getWidth()))

    # end _populateNonHeaderWidgets()

    def _layoutContentWidgets(self):
        nrows = 3
        if self.model.isInsertMode():
            nrows = 2
        sizeGridSizer = wx.FlexGridSizer(nrows, 4, 2, 2)

        if self.model.isInsertMode():
            sizeGridSizer.Add(
                self.rowsLabel, 0,
                wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
            sizeGridSizer.Add(self.rowsText, 1, wx.EXPAND | wx.ALL, 1)
            sizeGridSizer.Add(
                self.colsLabel, 0,
                wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 1)
            sizeGridSizer.Add(self.colsText, 1, wx.EXPAND | wx.ALL, 1)

        sizeGridSizer.Add(self.paddingLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
                          1)
        sizeGridSizer.Add(self.paddingText, 1, wx.EXPAND | wx.ALL, 1)

        sizeGridSizer.Add(self.spacingLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
                          1)
        sizeGridSizer.Add(self.spacingText, 1, wx.EXPAND | wx.ALL, 1)

        sizeGridSizer.Add(self.borderLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
                          1)
        sizeGridSizer.Add(self.borderText, 1, wx.EXPAND | wx.ALL, 1)

        sizeGridSizer.Add(self.widthLabel, 0,
                          wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
                          1)
        sizeGridSizer.Add(self.widthText, 1, wx.EXPAND | wx.ALL, 1)

        staticBoxSizer = wx.StaticBoxSizer(self.settingsStaticBox, wx.VERTICAL)
        staticBoxSizer.AddSizer(sizeGridSizer, 1, wx.EXPAND | wx.ALL, 1)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.AddSizer(staticBoxSizer, 0, wx.EXPAND | wx.ALL, 4)
        return sizer

    # end _layoutNonHeaderWidgets()

    def _bindWidgetEvents(self):
        self.Bind(wx.EVT_BUTTON, self.onOK, self.FindWindowById(wx.ID_OK))

    # end _bindWidgetEvents()

    def _updateModel(self):
        if self.model.isInsertMode():
            self.model.setRows(int(self.rowsText.GetValue()))
            self.model.setCols(int(self.colsText.GetValue()))

        if getNoneString(self.borderText.GetValue()):
            self.model.setBorder(self.borderText.GetValue())
        else:
            self.model.setBorder(None)

        if getNoneString(self.widthText.GetValue()):
            self.model.setWidth(self.widthText.GetValue())
        else:
            self.model.setWidth(None)

        if getNoneString(self.paddingText.GetValue()):
            self.model.setPadding(self.paddingText.GetValue())
        else:
            self.model.setPadding(None)

        if getNoneString(self.spacingText.GetValue()):
            self.model.setSpacing(self.spacingText.GetValue())
        else:
            self.model.setSpacing(None)

    # end _updateModel()

    def onOK(self, event):
        # persist settings to model.
        self._updateModel()
        event.Skip()
Exemplo n.º 10
0
class ZProxyPreferencePage(ZApplicationPreferencesPrefPage):
    
    def __init__(self, parent):
        ZApplicationPreferencesPrefPage.__init__(self, parent)
    # end __init__()

    def createWidgets(self):
        self.staticBox = wx.StaticBox(self, wx.ID_ANY, _extstr(u"prefpage.general.proxy.name")) #$NON-NLS-1$
        
        self.enableCB = wx.CheckBox(self, wx.ID_ANY, _extstr(u"prefpage.general.proxy.enable")) #$NON-NLS-1$
        self.controlsPanel = ZTransparentPanel(self, wx.ID_ANY)
        self.hostLabel = wx.StaticText(self.controlsPanel, wx.ID_ANY, _extstr(u"prefpage.general.proxy.host")) #$NON-NLS-1$
        self.hostTxt = wx.TextCtrl(self.controlsPanel, wx.ID_ANY)
        self.portLabel = wx.StaticText(self.controlsPanel, wx.ID_ANY, _extstr(u"prefpage.general.proxy.port")) #$NON-NLS-1$
        flags = ZIntegerSelectionValidator.ALLOW_EMPTY | ZIntegerSelectionValidator.POSITIVE_ONLY
        self.portTxt = ZValidatingTextCtrl(ZIntegerSelectionValidator(flags=flags), self.controlsPanel, wx.ID_ANY)
        
        self.usernameLabel = wx.StaticText(self.controlsPanel, wx.ID_ANY, _extstr(u"prefpage.general.proxy.username")) #$NON-NLS-1$
        self.usernameTxt = wx.TextCtrl(self.controlsPanel, wx.ID_ANY)
        self.passwordLabel = wx.StaticText(self.controlsPanel, wx.ID_ANY, _extstr(u"prefpage.general.proxy.password")) #$NON-NLS-1$
        self.passwordTxt = wx.TextCtrl(self.controlsPanel, wx.ID_ANY, style=wx.TE_PASSWORD)
    # end createWidgets()

    def populateWidgets(self):
        enable = self.session.getUserPreferenceBool(IZAppUserPrefsKeys.PROXY_ENABLE, False) #$NON-NLS-1$
        self.enableCB.SetValue(enable)
        self.controlsPanel.Enable(enable)
        
        host = self.session.getUserPreference(IZAppUserPrefsKeys.PROXY_HOST, u"") #$NON-NLS-1$
        port = self.session.getUserPreferenceInt(IZAppUserPrefsKeys.PROXY_PORT, 0) #$NON-NLS-1$
        if not host:
            # get data from os registry
            proxy = getOSUtil().getProxyConfig()
            if proxy and proxy.isConfigured():
                host = proxy.getHost()            
                port = proxy.getPortInt()
        self.hostTxt.SetValue(host)        
        if port > 0:
            self.portTxt.SetValue( unicode(port) )
        username = self.session.getUserPreference(IZAppUserPrefsKeys.PROXY_USERNAME, u"") #$NON-NLS-1$
        self.usernameTxt.SetValue(username)

        cyppass = self.session.getUserPreference(IZAppUserPrefsKeys.PROXY_PASSWORD, u"") #$NON-NLS-1$
        cyppass = getNoneString(cyppass)
        if cyppass:
            password = crypt.decryptCipherText(cyppass, PASSWORD_ENCRYPTION_KEY)
            self.passwordTxt.SetValue(password)
    # end populateWidgets()

    def bindWidgetEvents(self):
        self.Bind(wx.EVT_CHECKBOX, self.onEnableCB, self.enableCB)
        self.Bind(wx.EVT_TEXT, self.onDataChanged, self.hostTxt)
        self.Bind(wx.EVT_TEXT, self.onDataChanged, self.portTxt)
        self.Bind(wx.EVT_TEXT, self.onDataChanged, self.usernameTxt)
        self.Bind(wx.EVT_TEXT, self.onPasswordChanged, self.passwordTxt)
    # end bindWidgetEvents()

    def layoutWidgets(self):        
        flexGridSizer = wx.FlexGridSizer(4, 2, 5, 5)
        flexGridSizer.AddGrowableCol(1)
        flexGridSizer.Add(self.hostLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 5)
        flexGridSizer.Add(self.hostTxt, 0, wx.EXPAND | wx.RIGHT, 5)
        flexGridSizer.Add(self.portLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 5)
        flexGridSizer.Add(self.portTxt, 0, wx.RIGHT, 5)
        flexGridSizer.Add(self.usernameLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 5)
        flexGridSizer.Add(self.usernameTxt, 0, wx.EXPAND | wx.RIGHT, 5)
        flexGridSizer.Add(self.passwordLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 5)
        flexGridSizer.Add(self.passwordTxt, 0, wx.EXPAND | wx.RIGHT, 5)     
        self.controlsPanel.SetAutoLayout(True)
        self.controlsPanel.SetSizer(flexGridSizer)
                 
        staticBoxSizer = wx.StaticBoxSizer(self.staticBox, wx.VERTICAL)
        staticBoxSizer.Add(self.enableCB, 0, wx.EXPAND | wx.ALL, 2)
        staticBoxSizer.Add(self.controlsPanel, 1, wx.EXPAND | wx.ALL, 2)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.AddSizer(staticBoxSizer, 1, wx.EXPAND | wx.ALL, 5)
        self.SetAutoLayout(True)
        self.SetSizer(sizer)
        self.Layout()
    # end layoutWidgets()
    
    def onDataChanged(self, event):
        if self.enableCB.GetValue():
            (h, p) = self._getHostPortFromUI()
            self.session.setUserPreference(IZAppUserPrefsKeys.PROXY_HOST, h)
            self.session.setUserPreference(IZAppUserPrefsKeys.PROXY_PORT, p)
            self.session.setUserPreference(IZAppUserPrefsKeys.PROXY_USERNAME, getSafeString(self.usernameTxt.GetValue()))
            self.onSessionChange()            
        event.Skip()
    # end  onDataChanged
    
    def onPasswordChanged(self, event):
        if self.enableCB.GetValue():
            s = getSafeString(self.passwordTxt.GetValue())
            if s:
                s = crypt.encryptPlainText(s, PASSWORD_ENCRYPTION_KEY)
            self.session.setUserPreference(IZAppUserPrefsKeys.PROXY_PASSWORD, s)            
            self.onSessionChange()            
        event.Skip()
    # end  onPasswordChanged   
           
    def onEnableCB(self, event):
        self.session.setUserPreference(IZAppUserPrefsKeys.PROXY_ENABLE, event.IsChecked())
        self.controlsPanel.Enable(event.IsChecked())
        self.onSessionChange()
        event.Skip()
    # end onDebugCB() 
    
    def _getHostPortFromUI(self):        
        host = getSafeString( self.hostTxt.GetValue() )
        port = getSafeString( self.portTxt.GetValue() )
        if host.lower().startswith(u"http"): #$NON-NLS-1$
            (scheme, netloc, path, query, fragment) = urlsplit(host, u"http") #$NON-NLS-1$ @UnusedVariable
            desHostPort = netloc.split(u":") #$NON-NLS-1$
            h = desHostPort[0]
            p = u"80" #$NON-NLS-1$
            if len(desHostPort) == 2:
                p = desHostPort[1]
            if scheme == u"ssl" and p == u"80": #$NON-NLS-1$ #$NON-NLS-2$
                p = u"443" #$NON-NLS-1$
            if h:
                host = h
            if not port and p:
                port = p
        return (host, port)
    # end _getHostPortFromUI
    
    def apply(self):
        # also set changes to the global value
        (h, p) = self._getHostPortFromUI()
        proxy = ZHttpProxyConfiguration()
        proxy.setEnable( self.enableCB.GetValue() )
        proxy.setHost( h )
        port = 8080
        try:
            port  = int( p )
        except:
            pass
        proxy.setPort( port )
        proxy.setProxyAuthorization( getSafeString(self.usernameTxt.GetValue()), getSafeString(self.passwordTxt.GetValue()) )
        return ZApplicationPreferencesPrefPage.apply(self)