Esempio n. 1
0
    def _createCreditsPage(self):
        self.creditsPanel = wx.Panel(self.notebook, wx.ID_ANY)
        self.creditsPanel.SetBackgroundColour(wx.WHITE)

        self.htmlWidget = ZHTMLViewControl(self.creditsPanel)

        return self.creditsPanel
Esempio n. 2
0
    def _createContentWidgets(self):
        self.sizeStaticBox = wx.StaticBox(self, wx.ID_ANY, _extstr(u"fontdialog.FontSettings")) #$NON-NLS-1$
        self.previewStaticBox = wx.StaticBox(self, wx.ID_ANY, _extstr(u"fontdialog.FontPreview")) #$NON-NLS-1$
        self.fontLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"fontdialog.FontName")) #$NON-NLS-1$ #$NON-NLS-2$
        self.sizeLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"fontdialog.FontSize")) #$NON-NLS-1$ #$NON-NLS-2$
        self.colorLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"fontdialog.Color")) #$NON-NLS-1$ #$NON-NLS-2$
        self.backgroundLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"fontdialog.BackgroundColor")) #$NON-NLS-1$ #$NON-NLS-2$

        sizes = u"Default,8px,10px,12px,14px,16px,18px,24px,36px".split(u",") #$NON-NLS-1$ #$NON-NLS-2$
        self.sizeChoices = wx.Choice(self, wx.ID_ANY, (100, -1), choices = sizes)

        fonts = [u"Default"] #$NON-NLS-1$
        fonts.extend(self.systemFontNames)
        self.fontChoices = wx.Choice(self, wx.ID_ANY, (100, -1), choices = fonts)

        colors = [u"Default"] #$NON-NLS-1$
        self.colorChoicesHasRecent = False
        self.colorChoices = wx.Choice(self, wx.ID_ANY, (100, -1), choices = colors)
        self.colorPicker = wx.ColourPickerCtrl(self)

        bgColors = [u"Default"] #$NON-NLS-1$
        self.bgColorChoicesHasRecent = False
        self.bgColorChoices = wx.Choice(self, wx.ID_ANY, (100, -1), choices = bgColors)
        self.bgColorPicker = wx.ColourPickerCtrl(self)

        self.previewCntrl = ZHTMLViewControl(self, wx.ID_ANY)
Esempio n. 3
0
    def _createWindowWidgets(self, parent):
        self.headerPanel = self._createHeaderPanel(parent)
        self.headerStaticLine = wx.StaticLine(parent, wx.ID_ANY)

        self.splitterWindow = ZSplitterWindow(parent)
        self.splitterWindow.SetSizeHints(700, 600)

        self.topPanel = ZTransparentPanel(self.splitterWindow, wx.ID_ANY)
        self.topStaticBox = wx.StaticBox(self.topPanel, wx.ID_ANY, _extstr(u"templatemanager.Templates")) #$NON-NLS-1$

        provider = ZTemplateListProvider(self.model)
        self.templateList = ZListViewEx(provider, self.topPanel)

        self.addButton = wx.Button(self.topPanel, wx.ID_ANY, _extstr(u"templatemanager.Add")) #$NON-NLS-1$
        self.removeButton = wx.Button(self.topPanel, wx.ID_ANY, _extstr(u"templatemanager.Remove")) #$NON-NLS-1$
        self.removeButton.Enable(False)

        self.preview = ZHTMLViewControl(self.splitterWindow, wx.ID_ANY, style = wx.NO_FULL_REPAINT_ON_RESIZE | wx.SIMPLE_BORDER)

        self.splitterWindow.SetSashSize(10)
        self.splitterWindow.SplitHorizontally(self.topPanel, self.preview, 150)
        self.splitterWindow.SetMinimumPaneSize(100)

        self.statusBar = self._createStatusBar()
        self.SetStatusBar(self.statusBar)
Esempio n. 4
0
    def _createCreditsPage(self):
        self.creditsPanel = wx.Panel(self.notebook, wx.ID_ANY)
        self.creditsPanel.SetBackgroundColour(wx.WHITE)

        self.htmlWidget = ZHTMLViewControl(self.creditsPanel)

        return self.creditsPanel
Esempio n. 5
0
    def createWidgets(self):
        self.sizeStaticBox = wx.StaticBox(
            self, wx.ID_ANY, _extstr(u"fontdialog.FontSettings"))  #$NON-NLS-1$
        self.previewStaticBox = wx.StaticBox(
            self, wx.ID_ANY, _extstr(u"fontdialog.FontPreview"))  #$NON-NLS-1$
        self.fontLabel = wx.StaticText(
            self, wx.ID_ANY, u"%s:" %
            _extstr(u"fontdialog.FontName"))  #$NON-NLS-1$ #$NON-NLS-2$
        self.sizeLabel = wx.StaticText(
            self, wx.ID_ANY, u"%s:" %
            _extstr(u"fontdialog.FontSize"))  #$NON-NLS-1$ #$NON-NLS-2$

        sizes = u"Default,10px,12px,14px,16px,18px,22px,24px,26px,28px,36px".split(
            u",")  #$NON-NLS-1$ #$NON-NLS-2$
        self.sizeChoices = wx.Choice(self, wx.ID_ANY, (100, -1), choices=sizes)

        fonts = [u"Default"]  #$NON-NLS-1$
        fonts.extend(self.systemFontNames)
        self.fontChoices = wx.Choice(self, wx.ID_ANY, (100, -1), choices=fonts)
        self.previewCntrl = ZHTMLViewControl(self, wx.ID_ANY)
Esempio n. 6
0
    def createWidgets(self):
        self.sizeStaticBox = wx.StaticBox(self, wx.ID_ANY, _extstr(u"fontdialog.FontSettings")) #$NON-NLS-1$
        self.previewStaticBox = wx.StaticBox(self, wx.ID_ANY, _extstr(u"fontdialog.FontPreview")) #$NON-NLS-1$
        self.fontLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"fontdialog.FontName")) #$NON-NLS-1$ #$NON-NLS-2$
        self.sizeLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"fontdialog.FontSize")) #$NON-NLS-1$ #$NON-NLS-2$

        sizes = u"Default,10px,12px,14px,16px,18px,22px,24px,26px,28px,36px".split(u",") #$NON-NLS-1$ #$NON-NLS-2$
        self.sizeChoices = wx.Choice(self, wx.ID_ANY, (100, -1), choices = sizes)

        fonts = [u"Default"] #$NON-NLS-1$
        fonts.extend(self.systemFontNames)
        self.fontChoices = wx.Choice(self, wx.ID_ANY, (100, -1), choices = fonts)
        self.previewCntrl = ZHTMLViewControl(self, wx.ID_ANY)
Esempio n. 7
0
 def _createWidgets(self):
     self.htmlViewer = ZHTMLViewControl(self, wx.ID_ANY)
     self._clearHtmlContent()
Esempio n. 8
0
class ZPreviewBlogPostDetailsPanel(ZAbstractDetailsPanel, IZDataStoreListener,
                                   IZUserPreferencesListener):
    def __init__(self, parent):
        self.document = None

        # Get the "use template" param from the user prefs
        appModel = getApplicationModel()
        userProfile = appModel.getUserProfile()
        userPrefs = userProfile.getPreferences()
        self.useTemplateInPreview = userPrefs.getUserPreferenceBool(
            IZBlogAppUserPrefsKeys.POST_PREVIEW_VIEW_USE_TEMPLATE, True)

        ZAbstractDetailsPanel.__init__(self, parent)

        self._registerAsListener()

    # end __init__()

    def _createWidgets(self):
        self.htmlViewer = ZHTMLViewControl(self, wx.ID_ANY)
        self._clearHtmlContent()

    # end _createWidgets()

    def _bindWidgetEvents(self):
        self.Bind(ZEVT_REFRESH, self.onZoundryRefresh, self)

    # end _bindWidgetEvents()

    def _layoutWidgets(self):
        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.htmlViewer, 1, wx.EXPAND)
        self.SetAutoLayout(True)
        self.SetSizer(box)
        self.Layout()

    # end _layoutWidgets()

    def onUserPreferenceChange(self, key, newValue):
        if key == IZBlogAppUserPrefsKeys.POST_PREVIEW_VIEW_USE_TEMPLATE:
            self.useTemplateInPreview = newValue
            self._refreshContent()

    # end onUserPreferenceChange()

    # FIXME (EPW) need additional context info - what blog are we looking at?
    def onSelectionChanged(self, document):
        oldDoc = self.document
        self.document = document

        if oldDoc is not None and oldDoc.getId() == document.getId():
            return

        self._refreshContent()

    # end onSelectionChanged()

    def _refreshContent(self):
        document = self.document

        # Clear content if no document is set.
        if document is None:
            self._clearHtmlContent()
            return

        content = document.getContent()
        if content is not None:
            xhtmlDoc = content.getXhtmlDocument()
            blog = getBlogFromDocument(document)
            if blog is not None and self.useTemplateInPreview:
                template = getTemplateFromBlog(blog)
                if template is not None:
                    templatedDoc = applyTemplateToDocument(
                        template, document, APPLY_TEMPLATE_MODE_TITLE_AND_BODY)
                    if templatedDoc is not None:
                        xhtmlDoc = templatedDoc
                    disableTemplatePreviewJavaScript(xhtmlDoc)
                    self.htmlViewer.setXhtmlDocument(xhtmlDoc, False)
                    return

            self.htmlViewer.setXhtmlDocument(xhtmlDoc, True)

    # end _refreshContent()

    def _clearHtmlContent(self):
        self.document = None
        xhtmlDoc = loadXhtmlDocumentFromString(u"")  #$NON-NLS-1$
        self.htmlViewer.setXhtmlDocument(xhtmlDoc, False)

    # end _clearHtmlContent()

    def destroy(self):
        self._unregisterAsListener()

    # end destroy()

    # Document changed event from IZDataStoreListener
    def onDocumentChanged(self, document, metaDataOnly):
        if not metaDataOnly and self.document is not None and self.document.getId(
        ) == document.getId():
            self.document = document
            fireRefreshEvent(self, None)

    # end onDocumentChange()

    def onDocumentDeleted(self, document):
        if self.document is not None and self.document.getId(
        ) == document.getId():
            self.document = None
            fireRefreshEvent(self, None)

    # end onDocumentDeleted()

    def onZoundryRefresh(self, event):
        self._refreshContent()
        event.Skip()

    # end onZoundryRefresh()

    def _registerAsListener(self):
        # Register as a data store listener
        service = getApplicationModel().getService(
            IZBlogAppServiceIDs.DATA_STORE_SERVICE_ID)
        service.addListener(self)

        # Register as a user prefs listener
        appModel = getApplicationModel()
        userProfile = appModel.getUserProfile()
        userPrefs = userProfile.getPreferences()
        userPrefs.addListener(self)

    # end _registerAsListener()

    def _unregisterAsListener(self):
        # Unregister from the data store
        service = getApplicationModel().getService(
            IZBlogAppServiceIDs.DATA_STORE_SERVICE_ID)
        service.removeListener(self)

        # Unregister from the user prefs object
        # Register as a user prefs listener
        appModel = getApplicationModel()
        userProfile = appModel.getUserProfile()
        userPrefs = userProfile.getPreferences()
        userPrefs.removeListener(self)
Esempio n. 9
0
class ZEditorFontPreferencePage(ZApplicationPreferencesPrefPage):

    def __init__(self, parent):
        fontsEnum = wx.FontEnumerator()
        fontsEnum.EnumerateFacenames()
        self.systemFontNames = fontsEnum.GetFacenames()
        self.systemFontNames.sort()
        ZApplicationPreferencesPrefPage.__init__(self, parent)
    # end __init__()

    def _getUserPrefFontName(self):
        fontName = getSafeString( self.session.getUserPreference(IZBlogAppUserPrefsKeys.EDITOR_FONT_NAME, u"") ) #$NON-NLS-1$
        return fontName
    # end _getUserPrefFontName()

    def _setUserPrefFontName(self, fontName):
        fontName = getSafeString(fontName)   
        prev = self._getUserPrefFontName()
        if fontName != prev:     
            self.session.setUserPreference(IZBlogAppUserPrefsKeys.EDITOR_FONT_NAME, fontName)
    # end _setUserPrefFontName()

    def _getUserPrefFontSize(self):
        fontSize = getSafeString( self.session.getUserPreference(IZBlogAppUserPrefsKeys.EDITOR_FONT_SIZE, u"") ) #$NON-NLS-1$
        return fontSize
    # end _getUserPrefFontSize()

    def _setUserPrefFontSize(self, fontSize):
        fontSize = getSafeString(fontSize)
        prev = self._getUserPrefFontSize()
        if fontSize != prev:             
            self.session.setUserPreference(IZBlogAppUserPrefsKeys.EDITOR_FONT_SIZE, fontSize)
    # end _setUserPrefFontSize()

    def createWidgets(self):
        self.sizeStaticBox = wx.StaticBox(self, wx.ID_ANY, _extstr(u"fontdialog.FontSettings")) #$NON-NLS-1$
        self.previewStaticBox = wx.StaticBox(self, wx.ID_ANY, _extstr(u"fontdialog.FontPreview")) #$NON-NLS-1$
        self.fontLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"fontdialog.FontName")) #$NON-NLS-1$ #$NON-NLS-2$
        self.sizeLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"fontdialog.FontSize")) #$NON-NLS-1$ #$NON-NLS-2$

        sizes = u"Default,10px,12px,14px,16px,18px,22px,24px,26px,28px,36px".split(u",") #$NON-NLS-1$ #$NON-NLS-2$
        self.sizeChoices = wx.Choice(self, wx.ID_ANY, (100, -1), choices = sizes)

        fonts = [u"Default"] #$NON-NLS-1$
        fonts.extend(self.systemFontNames)
        self.fontChoices = wx.Choice(self, wx.ID_ANY, (100, -1), choices = fonts)
        self.previewCntrl = ZHTMLViewControl(self, wx.ID_ANY)
    # end createWidgets()

    def bindWidgetEvents(self):
        self.Bind(wx.EVT_CHOICE, self.onFontChoiceChanged, self.fontChoices)
        self.Bind(wx.EVT_CHOICE, self.onSizeChoiceChanged, self.sizeChoices)
    # end bindWidgetEvents()

    def populateWidgets(self):
        self._selectChoiceItem(self.fontChoices,  self._getUserPrefFontName() )
        self._selectChoiceItem(self.sizeChoices,  self._getUserPrefFontSize() )
        self._updatePreview()
    # end populateWidgets()

    def layoutWidgets(self):
        sizeGridSizer = wx.FlexGridSizer(2, 2, 1, 1)
        sizeGridSizer.Add(self.fontLabel, 0, wx.ALL, 1)
        sizeGridSizer.Add(self.sizeLabel, 0, wx.ALL, 1)
        sizeGridSizer.Add(self.fontChoices, 1, wx.EXPAND | wx.ALL, 1)
        sizeGridSizer.Add(self.sizeChoices, 1, wx.EXPAND | wx.ALL, 1)

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

        previewStaticBoxSizer = wx.StaticBoxSizer(self.previewStaticBox, wx.VERTICAL)
        previewStaticBoxSizer.Add(self.previewCntrl, 1, wx.EXPAND | wx.ALL, 1)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.AddSizer(sizeStaticBoxSizer, 0, wx.EXPAND | wx.ALL, 4)
        sizer.AddSizer(previewStaticBoxSizer, 2, wx.EXPAND | wx.ALL, 4)
        self.SetAutoLayout(True)
        self.SetSizer(sizer)
        self.Layout()
    # end layoutWidgets()

    def _updatePreview(self):
        style = u"" #$NON-NLS-1$
        if self.fontChoices.GetSelection() > 0:
            style = style + u"font-family:%s; "  % self.fontChoices.GetStringSelection() #$NON-NLS-1$
        if self.sizeChoices.GetSelection() > 0:
            style = style + u"font-size:%s; "  % self.sizeChoices.GetStringSelection() #$NON-NLS-1$

        self.previewCntrl.setHtmlValue( PREVIEW_HTML % style)
    # end _updatePreview()

    def _selectChoiceItem(self, choiceControl, value):
        selectIdx = 0
        if value:
            value = value.lower().strip()
            for idx in range( choiceControl.GetCount() ):
                s = choiceControl.GetString(idx).lower().strip()
                if s == value:
                    selectIdx = idx
                    break
        choiceControl.Select(selectIdx)
    # end _selectChoiceItem

    def onFontChoiceChanged(self, event): #@UnusedVariable
        self._updatePreview()
        fontName = self.fontChoices.GetStringSelection()
        self._setUserPrefFontName(fontName)
    # end onFontChoiceChanged()

    def onSizeChoiceChanged(self, event): #@UnusedVariable
        self._updatePreview()
        fontSize = self.sizeChoices.GetStringSelection()
        self._setUserPrefFontSize(fontSize)
    # end onSizeChoiceChanged()

    def apply(self):
        return ZApplicationPreferencesPrefPage.apply(self)
Esempio n. 10
0
class ZFontDialog(ZBaseDialog):

    def __init__(self, parent, model):
        # model is instance of ZFontModel.
        self.model = model
        fontsEnum = wx.FontEnumerator()
        fontsEnum.EnumerateFacenames()
        self.systemFontNames = fontsEnum.GetFacenames()
        self.systemFontNames.sort()

        ZBaseDialog.__init__(self, parent, wx.ID_ANY, _extstr(u"fontdialog.DialogTitle"), style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, name = u"ZFontDialog") #$NON-NLS-1$ #$NON-NLS-2$
        #bestHeight = self.GetBestSizeTuple()[1]
        #self.SetMinSize(wx.Size(-1, bestHeight))
    # end __init__()

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

    def _createContentWidgets(self):
        self.sizeStaticBox = wx.StaticBox(self, wx.ID_ANY, _extstr(u"fontdialog.FontSettings")) #$NON-NLS-1$
        self.previewStaticBox = wx.StaticBox(self, wx.ID_ANY, _extstr(u"fontdialog.FontPreview")) #$NON-NLS-1$
        self.fontLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"fontdialog.FontName")) #$NON-NLS-1$ #$NON-NLS-2$
        self.sizeLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"fontdialog.FontSize")) #$NON-NLS-1$ #$NON-NLS-2$
        self.colorLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"fontdialog.Color")) #$NON-NLS-1$ #$NON-NLS-2$
        self.backgroundLabel = wx.StaticText(self, wx.ID_ANY, u"%s:" % _extstr(u"fontdialog.BackgroundColor")) #$NON-NLS-1$ #$NON-NLS-2$

        sizes = u"Default,8px,10px,12px,14px,16px,18px,24px,36px".split(u",") #$NON-NLS-1$ #$NON-NLS-2$
        self.sizeChoices = wx.Choice(self, wx.ID_ANY, (100, -1), choices = sizes)

        fonts = [u"Default"] #$NON-NLS-1$
        fonts.extend(self.systemFontNames)
        self.fontChoices = wx.Choice(self, wx.ID_ANY, (100, -1), choices = fonts)

        colors = [u"Default"] #$NON-NLS-1$
        self.colorChoicesHasRecent = False
        self.colorChoices = wx.Choice(self, wx.ID_ANY, (100, -1), choices = colors)
        self.colorPicker = wx.ColourPickerCtrl(self)

        bgColors = [u"Default"] #$NON-NLS-1$
        self.bgColorChoicesHasRecent = False
        self.bgColorChoices = wx.Choice(self, wx.ID_ANY, (100, -1), choices = bgColors)
        self.bgColorPicker = wx.ColourPickerCtrl(self)

        self.previewCntrl = ZHTMLViewControl(self, wx.ID_ANY)

    # end _createNonHeaderWidgets()

    def _populateContentWidgets(self):

        w3cColors = []
        for (n,v) in ZCssColor.COLOR_NAMES.iteritems(): #@UnusedVariable
            w3cColors.append(n.title())
        w3cColors.sort()

        global G_USER_FONT_SETTINGS_MAP
        colors = [u"Default"] #$NON-NLS-1$
        colors.extend(w3cColors)
        colors.append(u"Custom") #$NON-NLS-1$
        if G_USER_FONT_SETTINGS_MAP.has_key(u"cssColor") and G_USER_FONT_SETTINGS_MAP[u"cssColor"]: #$NON-NLS-1$ #$NON-NLS-2$
            self.colorChoicesHasRecent = True
            colors.append(u"Recent %s" % G_USER_FONT_SETTINGS_MAP[u"cssColor"].getCssColor() ) #$NON-NLS-1$ #$NON-NLS-2$
        else:
            colors.append(u"Recent") #$NON-NLS-1$
        self.colorChoices.Clear()
        for c in colors:
            self.colorChoices.Append(c)

        bgColors = [u"Default"] #$NON-NLS-1$
        bgColors.extend(w3cColors)
        bgColors.append(u"Custom") #$NON-NLS-1$
        if G_USER_FONT_SETTINGS_MAP.has_key(u"cssBgColor") and G_USER_FONT_SETTINGS_MAP[u"cssBgColor"]: #$NON-NLS-1$ #$NON-NLS-2$
            self.bgColorChoicesHasRecent = True
            bgColors.append(u"Recent %s" % G_USER_FONT_SETTINGS_MAP[u"cssBgColor"].getCssColor() ) #$NON-NLS-1$ #$NON-NLS-2$
        else:
            bgColors.append(u"Recent") #$NON-NLS-1$
        self.bgColorChoices.Clear()
        for c in bgColors:
            self.bgColorChoices.Append(c)

        self._selectChoiceItem(self.fontChoices, self.model.getFontName() )
        self._selectChoiceItem(self.sizeChoices, self.model.getFontSize() )
        if self.model.getColor():
            color = wx.Colour(self.model.getColor().getRed(), self.model.getColor().getGreen(), self.model.getColor().getBlue())
            self.colorPicker.SetColour(color)
            self._handleOnPickColorSelection( self.colorChoices, self.colorPicker)

        if self.model.getBackground():
            color = wx.Colour(self.model.getBackground().getRed(), self.model.getBackground().getGreen(), self.model.getBackground().getBlue())
            self.bgColorPicker.SetColour(color)
            self._handleOnPickColorSelection( self.bgColorChoices, self.bgColorPicker)
        self._updatePreview()
    # end _populateNonHeaderWidgets()

    def _layoutContentWidgets(self):
        sizeGridSizer = wx.FlexGridSizer(4, 2, 1, 1)

        sizeGridSizer.Add(self.fontLabel, 0, wx.ALL, 1)
        sizeGridSizer.Add(self.sizeLabel, 0, wx.ALL, 1)
        sizeGridSizer.Add(self.fontChoices, 1, wx.EXPAND | wx.ALL, 1)
        sizeGridSizer.Add(self.sizeChoices, 1, wx.EXPAND | wx.ALL, 1)

        sizeGridSizer.Add(self.colorLabel, 0, wx.ALL, 1)
        sizeGridSizer.Add(self.backgroundLabel, 0, wx.ALL, 1)

        hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
        hsizer1.Add(self.colorChoices, 1,  wx.EXPAND |wx.ALL, 1)
        hsizer1.Add(self.colorPicker, 0, wx.ALL, 1)

        sizeGridSizer.AddSizer(hsizer1, 1,  wx.EXPAND |wx.ALL, 1)

        hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
        hsizer2.Add(self.bgColorChoices, 1,  wx.EXPAND | wx.ALL, 1)
        hsizer2.Add(self.bgColorPicker, 0, wx.ALL, 1)

        sizeGridSizer.AddSizer(hsizer2, 1,  wx.EXPAND |wx.ALL, 1)

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

        previewStaticBoxSizer = wx.StaticBoxSizer(self.previewStaticBox, wx.VERTICAL)
        previewStaticBoxSizer.Add(self.previewCntrl, 1, wx.EXPAND | wx.ALL, 1)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.AddSizer(sizeStaticBoxSizer, 0, wx.EXPAND | wx.ALL, 4)
        sizer.AddSizer(previewStaticBoxSizer, 2, wx.EXPAND | wx.ALL, 4)
        return sizer
    # end _layoutNonHeaderWidgets()

    def _bindWidgetEvents(self):
        self.Bind(wx.EVT_BUTTON, self.onOK, self.FindWindowById(wx.ID_OK) )
        self.Bind(wx.EVT_CHOICE, self.onFontChoiceChanged, self.fontChoices)
        self.Bind(wx.EVT_CHOICE, self.onSizeChoiceChanged, self.sizeChoices)
        self.Bind(wx.EVT_CHOICE, self.onColorChoiceChanged, self.colorChoices)
        self.Bind(wx.EVT_CHOICE, self.onBgColorChoiceChanged, self.bgColorChoices)
        self.Bind(wx.EVT_COLOURPICKER_CHANGED, self.onColorPicked, self.colorPicker)
        self.Bind(wx.EVT_COLOURPICKER_CHANGED, self.onBgColorPicked, self.bgColorPicker)
    # end _bindWidgetEvents()

    def _updatePreview(self):
        style = u"" #$NON-NLS-1$
        if self.colorChoices.GetSelection() > 0:
            style = style + u"color:%s; " %  self.colorPicker.GetColour().GetAsString(wx.C2S_HTML_SYNTAX)  #$NON-NLS-1$
        if self.bgColorChoices.GetSelection() > 0:
            style = style + u"background:%s; " %  self.bgColorPicker.GetColour().GetAsString(wx.C2S_HTML_SYNTAX)  #$NON-NLS-1$

        if self.fontChoices.GetSelection() > 0:
            style = style + u"font-family:%s; "  % self.fontChoices.GetStringSelection() #$NON-NLS-1$

        if self.sizeChoices.GetSelection() > 0:
            style = style + u"font-size:%s; "  % self.sizeChoices.GetStringSelection() #$NON-NLS-1$

        self.previewCntrl.setHtmlValue( PREVIEW_HTML % style)
    # end _updatePreview()

    def _selectChoiceItem(self, choiceControl, value):
        selectIdx = 0
        if value:
            value = value.lower().strip()
            for idx in range( choiceControl.GetCount() ):
                s = choiceControl.GetString(idx).lower().strip()
                if s == value:
                    selectIdx = idx
                    break
        choiceControl.Select(selectIdx)
    # end _selectChoiceItem

    def _handleOnColorChoiceSelection(self, choiceControl, colorPickerControl):
        idx = choiceControl.GetSelection()
        max = choiceControl.GetCount()
        # idx = 0: default
        # idx = N-2: Custom
        # idx = N-1: recent
         
        if idx > 0 and idx < (max-2):
            colorName = choiceControl.GetStringSelection().strip().lower()
            cssColor = ZCssColor(colorName)
            color = wx.Colour(cssColor.getRed(), cssColor.getGreen(), cssColor.getBlue())
            colorPickerControl.SetColour(color)
        elif idx == (max-2):
            # custom
            pass
        elif idx == (max-1):
            # recent...
            global G_USER_FONT_SETTINGS_MAP
            cssColor = None
            if self.colorChoices == choiceControl and G_USER_FONT_SETTINGS_MAP.has_key(u"cssColor"): #$NON-NLS-1$ #$NON-NLS-2$
                cssColor = G_USER_FONT_SETTINGS_MAP[u"cssColor"] #$NON-NLS-1$
            elif self.bgColorChoices == choiceControl and G_USER_FONT_SETTINGS_MAP.has_key(u"cssBgColor"): #$NON-NLS-1$ #$NON-NLS-2$
                cssColor = G_USER_FONT_SETTINGS_MAP[u"cssBgColor"] #$NON-NLS-1$
            if cssColor:     
                color = wx.Colour(cssColor.getRed(), cssColor.getGreen(), cssColor.getBlue())
                colorPickerControl.SetColour(color)
        
    # end _handleOnColorChoiceSelection

    def _handleOnPickColorSelection(self, choiceControl, colorPickerControl):
        cssHexColor = colorPickerControl.GetColour().GetAsString(wx.C2S_HTML_SYNTAX).lower()
        max = choiceControl.GetCount()
        # Default is the last-1 choice i.e. "custom".
        idx = max-2
        for i in range(0, max):
            colorName = choiceControl.GetString(i).lower().strip()
            if ZCssColor.COLOR_NAMES.has_key(colorName) and ZCssColor.COLOR_NAMES[colorName].lower() == cssHexColor:
                idx = i
                break
        choiceControl.SetSelection(idx)
    # end _handleOnPickColorSelection

    def _updateModel(self):
        fontName = None
        fontSize = None
        cssColor = None
        cssBgColor = None

        global G_USER_FONT_SETTINGS_MAP

        if self.fontChoices.GetSelection() > 0:
            fontName = self.fontChoices.GetStringSelection()
            G_USER_FONT_SETTINGS_MAP[u"fontName"] = fontName    #$NON-NLS-1$

        if self.sizeChoices.GetSelection() > 0:
            fontSize = self.sizeChoices.GetStringSelection()
            G_USER_FONT_SETTINGS_MAP[u"fontSize"] = fontSize    #$NON-NLS-1$

        if self.colorChoices.GetSelection() > 0:
            cssColor = ZCssColor( self.colorPicker.GetColour().GetAsString(wx.C2S_HTML_SYNTAX) )
            G_USER_FONT_SETTINGS_MAP[u"cssColor"] = cssColor    #$NON-NLS-1$

        if self.bgColorChoices.GetSelection() > 0:
            cssBgColor = ZCssColor( self.bgColorPicker.GetColour().GetAsString(wx.C2S_HTML_SYNTAX) )
            G_USER_FONT_SETTINGS_MAP[u"cssBgColor"] = cssBgColor    #$NON-NLS-1$

        self.model.setFontName(fontName)
        self.model.setFontSize(fontSize)
        self.model.setColor(cssColor)
        self.model.setBackground(cssBgColor)
    # end _updateModel()

    def onFontChoiceChanged(self, event): #@UnusedVariable
        self._updatePreview()
    # end onFontChoiceChanged()

    def onSizeChoiceChanged(self, event): #@UnusedVariable
        self._updatePreview()
    # end onSizeChoiceChanged()

    def onColorChoiceChanged(self, event): #@UnusedVariable
        self._handleOnColorChoiceSelection( self.colorChoices, self.colorPicker)
        self._updatePreview()
    # end onColorChoiceChanged()

    def onBgColorChoiceChanged(self, event): #@UnusedVariable
        self._handleOnColorChoiceSelection( self.bgColorChoices, self.bgColorPicker)
        self._updatePreview()
    # end onBgColorChoiceChanged()

    def onColorPicked(self, event): #@UnusedVariable
        self._handleOnPickColorSelection( self.colorChoices, self.colorPicker)
        self._updatePreview()
    # end onColorPicked

    def onBgColorPicked(self, event): #@UnusedVariable
        self._handleOnPickColorSelection( self.bgColorChoices, self.bgColorPicker)
        self._updatePreview()
    # end onBgColorPicked

    def onOK(self, event):
        # persist settings to model.
        self._updateModel()
        event.Skip()
    # end onOK()

# end ZFontDialog
Esempio n. 11
0
 def _createWidgets(self):
     self.htmlWidget = ZHTMLViewControl(self, wx.ID_ANY)
     self.htmlWidget.setLinkCallback(self)
Esempio n. 12
0
class ZInfoTagCloudPanel(ZTransparentPanel):

    def __init__(self, parent, model):
        self.blog = None

        ZTransparentPanel.__init__(self, parent, wx.ID_ANY, style = wx.NO_BORDER)
        self.htmlWidget = None
        self.model = model
        self._createWidgets()
        self._bindWidgetEvents()
        self._layoutWidgets()
    # end __init__()

    def setBlog(self, blog):
        self.blog = blog
    # end setBlog()

    def setModel(self, model):
        self.model = model
    # end setModel()

    def _createWidgets(self):
        self.htmlWidget = ZHTMLViewControl(self, wx.ID_ANY)
        self.htmlWidget.setLinkCallback(self)
    # end _createWidgets()

    def _bindWidgetEvents(self):
        pass
    # end _bindWidgetEvents()

    def _layoutWidgets(self):
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.htmlWidget, 1, wx.EXPAND)
        self.SetSizer(sizer)
    # end _layoutWidgets()

    def onTag(self, tagId):
        #Call back when tag link is clicked on
        tagId = convertToUnicode(tagId)
        tagIDO = self.model.getTagIDO(tagId)
        fireViewSelectionEvent(ZTagSelection(tagIDO, self.blog), self)
        return False
    # end onTag()

    def refresh(self):
        idx = 0
        colors = [u"black", u"blue", u"orange", u"red", u"green", u"magenta"] #$NON-NLS-1$ #$NON-NLS-2$ #$NON-NLS-3$ #$NON-NLS-4$ #$NON-NLS-5$ #$NON-NLS-6$
        s = u"" #$NON-NLS-1$
        idoHitCountTupleList = []
        idoHitCountTupleList.extend( self.model.getTagsMap().itervalues() )
        idoHitCountTupleList.sort( lambda x, y: cmp( x[0].getId(), y[0].getId() ) )
        for (tagIdo, hitCount) in idoHitCountTupleList:
            fz = u"3.0em"  #$NON-NLS-1$
            if hitCount < 9:
                fz = u"1.%dem" % (hitCount-1)  #$NON-NLS-1$
            elif hitCount < 20:
                fz = u"2.%dem" % (hitCount-10)  #$NON-NLS-1$
            color = colors[ idx % len(colors) ]
            idx = idx+1
            #tagstr = u"""<span style="font-size:%s;color:%s">%s<a href="py::onTag('%s')">(%d)</a></span>&nbsp;&nbsp; """ % (fz, color, tagIdo.getTagword(), tagIdo.getId(), hitCount) #$NON-NLS-1$
            tagstr = u"""<span><a style="font-size:%s;color:%s;text-decoration:none" href="py::onTag('%s')">%s</a>(%d)</span>&nbsp;&nbsp; """ % (fz, color, tagIdo.getId(), tagIdo.getTagword(), hitCount) #$NON-NLS-1$
            s = s + tagstr
        html = u"""<html><body><table border="0" cellspacing="5"><tr><td>%s</td></tr></table></body></html>""" %s #$NON-NLS-1$
        self.htmlWidget.setHtmlValue(html)
Esempio n. 13
0
class ZTemplateManagerWindow(ZBaseWindow, ZPersistentDialogMixin, IZTemplateServiceListener):

    def __init__(self, parent):
        self.model = ZTemplateManagerModel()
        self.selectedTemplate = None

        style = wx.DEFAULT_FRAME_STYLE | wx.FULL_REPAINT_ON_RESIZE | wx.CLIP_CHILDREN
        ZBaseWindow.__init__(self, parent, _extstr(u"templatemanager.BlogTemplateManager"), name = u"ZTemplateManager", style = style) #$NON-NLS-2$ #$NON-NLS-1$
        ZPersistentDialogMixin.__init__(self, IZBlogAppUserPrefsKeys.TEMPLATE_WINDOW)
        self.Layout()

        self._installListener()
    # end __init__()

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

    def _createWindowWidgets(self, parent):
        self.headerPanel = self._createHeaderPanel(parent)
        self.headerStaticLine = wx.StaticLine(parent, wx.ID_ANY)

        self.splitterWindow = ZSplitterWindow(parent)
        self.splitterWindow.SetSizeHints(700, 600)

        self.topPanel = ZTransparentPanel(self.splitterWindow, wx.ID_ANY)
        self.topStaticBox = wx.StaticBox(self.topPanel, wx.ID_ANY, _extstr(u"templatemanager.Templates")) #$NON-NLS-1$

        provider = ZTemplateListProvider(self.model)
        self.templateList = ZListViewEx(provider, self.topPanel)

        self.addButton = wx.Button(self.topPanel, wx.ID_ANY, _extstr(u"templatemanager.Add")) #$NON-NLS-1$
        self.removeButton = wx.Button(self.topPanel, wx.ID_ANY, _extstr(u"templatemanager.Remove")) #$NON-NLS-1$
        self.removeButton.Enable(False)

        self.preview = ZHTMLViewControl(self.splitterWindow, wx.ID_ANY, style = wx.NO_FULL_REPAINT_ON_RESIZE | wx.SIMPLE_BORDER)

        self.splitterWindow.SetSashSize(10)
        self.splitterWindow.SplitHorizontally(self.topPanel, self.preview, 150)
        self.splitterWindow.SetMinimumPaneSize(100)

        self.statusBar = self._createStatusBar()
        self.SetStatusBar(self.statusBar)
    # end _createWindowWidgets()

    def _createHeaderPanel(self, parent):
        panel = wx.Panel(parent, wx.ID_ANY)
        panel.SetBackgroundColour(wx.WHITE)

        self.headerLink = wx.HyperlinkCtrl(panel, wx.ID_ANY, self._getHeaderTitle(), self._getHeaderHelpURL())
        self.headerLink.SetFont(getDefaultFontBold())
        self.headerMessage = wx.StaticText(panel, wx.ID_ANY, self._getHeaderMessage())
        headerImagePath = self._getHeaderImagePath()
        if not headerImagePath:
            headerImagePath = u"images/dialogs/image/header_image.png" #$NON-NLS-1$
        self.headerIcon = ZStaticBitmap(panel, getResourceRegistry().getBitmap(headerImagePath))

        linkAndMsgSizer = wx.BoxSizer(wx.VERTICAL)
        linkAndMsgSizer.Add(self.headerLink, 0, wx.ALL, 2)
        linkAndMsgSizer.Add(self.headerMessage, 1, wx.EXPAND | wx.ALL, 2)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.AddSizer(linkAndMsgSizer, 1, wx.EXPAND | wx.ALL, 5)
        sizer.Add(self.headerIcon, 0, wx.EXPAND | wx.ALL, 10)

        panel.SetAutoLayout(True)
        panel.SetSizer(sizer)

        return panel
    # end _createHeaderPanel()

    def _createStatusBar(self):
        self.statusBarModel = ZStatusBarModel()
        self.statusBarModel.addPane(u"name") #$NON-NLS-1$
        self.statusBarModel.setPaneWidth(u"name", 1) #$NON-NLS-1$
        self.statusBarModel.setPaneText(u"name", u"") #$NON-NLS-1$ #$NON-NLS-2$
        provider = ZStatusBarModelBasedContentProvider(self.statusBarModel)
        statusBar = ZStatusBar(self, provider)
        return statusBar
    # end _createStatusBar()

    def _populateWindowWidgets(self):
        self.SetIcons(getResourceRegistry().getIconBundle(ICON_IMAGES))
        self.refresh()
    # end _populateWindowWidgets()

    def _layoutWindowWidgets(self):
        staticBoxSizer = wx.StaticBoxSizer(self.topStaticBox, wx.VERTICAL)
        staticBoxSizer.Add(self.templateList, 1, wx.ALL | wx.EXPAND, 3)
        buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
        buttonSizer.Add(self.addButton, 0, wx.ALL | wx.EXPAND, 2)
        buttonSizer.Add(self.removeButton, 0, wx.ALL | wx.EXPAND, 2)
        staticBoxSizer.AddSizer(buttonSizer, 0, wx.ALL | wx.EXPAND, 2)

        self.topPanel.SetSizer(staticBoxSizer)
        self.topPanel.SetAutoLayout(True)

        sizer = wx.BoxSizer(wx.VERTICAL)

        sizer.Add(self.headerPanel, 0, wx.EXPAND | wx.ALL, 0)
        sizer.Add(self.headerStaticLine, 0, wx.EXPAND | wx.ALL, 0)
        sizer.Add(self.splitterWindow, 1, wx.EXPAND | wx.ALL, 5)

        return sizer
    # end _layoutWindowWidgets()

    def _bindWidgetEvents(self):
        self.Bind(wx.EVT_BUTTON, self.onAdd, self.addButton)
        self.Bind(wx.EVT_BUTTON, self.onRemove, self.removeButton)
        self.Bind(wx.EVT_CLOSE, self.onClose, self)
        self.Bind(ZEVT_REFRESH, self.onRefresh, self)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onTemplateSelected, self.templateList)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onTemplateRightClick, self.templateList)
    # end _bindWidgetEvents()

    def onRefresh(self, event):
        self.templateList.Refresh()
        event.Skip()
    # end onRefresh()

    def onAdd(self, event):
        action = ZAddTemplateFromBlogAction()
        action.runAction(ZTemplateManagerActionContext(self, self.selectedTemplate))
        event.Skip()
    # end onAdd()

    def onRemove(self, event):
        action = ZRemoveTemplateAction()
        action.runAction(ZTemplateManagerActionContext(self, self.selectedTemplate))
        event.Skip()
    # end onRemove()

    def onTemplateSelected(self, event):
        self.selectedTemplate = self.model.getTemplates()[event.GetItem().GetId()]
        self.removeButton.Enable(True)
        self.refresh()
        event.Skip()
    # end onTemplateSelected()

    def onTemplateRightClick(self, event):
        event.Skip()
    # end onTemplateRightClick()

    def _setInitialFocus(self):
        pass
    # end _setInitialFocus()

    def refresh(self):
        self.templateList.refresh()
        self.statusBar.refresh()
        if self.selectedTemplate is not None:
            document = self.model.getSampleDocument()
            xhtmlDoc = applyTemplateToDocument(self.selectedTemplate, document, APPLY_TEMPLATE_MODE_FULL)
            disableTemplatePreviewJavaScript(xhtmlDoc)
        else:
            xhtmlDoc = loadXhtmlDocumentFromString(u"Select a template to view a preview of it.") #$NON-NLS-1$
        self.preview.setXhtmlDocument(xhtmlDoc, False)
    # end refresh()

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

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

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

    def _getHeaderHelpURL(self):
        return u"http://www.zoundry.com" #$NON-NLS-1$
    # end _getHeaderHelpUrl()

    def onClose(self, event):
        global TEMPLATE_MANAGER_WINDOW
        TEMPLATE_MANAGER_WINDOW = None

        self._uninstallListener()

        event.Skip()
    # end onClose()

    def _installListener(self):
        self.model.getService().addListener(self)
    # end _installListener()

    def _uninstallListener(self):
        self.model.getService().removeListener(self)
    # end _uninstallListener()

    def onTemplateCreated(self, template): #@UnusedVariable
        fireUIExecEvent(ZMethodRunnable(self.refresh), self)
    # end onTemplateCreated()

    def onTemplateDeleted(self, template):
        if self.selectedTemplate.getId() == template.getId():
            self.selectedTemplate = None

        self.refresh()
        self.templateList.deselectAll()
        self.removeButton.Enable(False)
    # end onTemplateDeleted()

    def onTemplateModified(self, template): #@UnusedVariable
        fireUIExecEvent(ZMethodRunnable(self.refresh), self)
Esempio n. 14
0
class ZAboutDialog(ZBaseDialog):
    def __init__(self, parent):
        ZBaseDialog.__init__(self, parent, wx.ID_ANY,
                             _extstr(u"aboutdialog.AboutRaven"))  #$NON-NLS-1$

        size = self.GetBestSize()
        self.SetSize(size)

    # end __init__()

    def _createContentWidgets(self):
        self.notebook = fnb.FlatNotebook(
            self,
            wx.ID_ANY,
            style=fnb.FNB_BOTTOM | fnb.FNB_NO_NAV_BUTTONS | fnb.FNB_NO_X_BUTTON
            | fnb.FNB_NODRAG)
        self.notebook.AddPage(self._createRavenInfoPage(),
                              _extstr(u"aboutdialog.Info"), True,
                              -1)  #$NON-NLS-1$
        self.notebook.AddPage(self._createCreditsPage(),
                              _extstr(u"aboutdialog.Credits"), False,
                              -1)  #$NON-NLS-1$

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

    # end _createContentWidgets()

    def _createRavenInfoPage(self):
        self.infoPanel = wx.Panel(self.notebook, wx.ID_ANY)
        self.infoPanel.SetBackgroundColour(wx.WHITE)

        self.aboutBmp = getResourceRegistry().getBitmap(
            u"images/about/about.png")  #$NON-NLS-1$
        self.aboutImage = ZStaticBitmap(self.infoPanel, self.aboutBmp)

        ver = version.ZVersion()
        verDate = ZSchemaDateTime(ver.getBuildDate())

        self.versionLabelLabel = wx.StaticText(
            self.infoPanel, wx.ID_ANY,
            u"%s: " % _extstr(u"splash.Version"))  #$NON-NLS-1$ #$NON-NLS-2$
        self.versionLabelLabel.SetFont(getDefaultFontBold())
        self.versionLabel = wx.StaticText(self.infoPanel, wx.ID_ANY,
                                          ver.getFullVersionString())
        self.dateLabelLabel = wx.StaticText(
            self.infoPanel, wx.ID_ANY,
            u"%s: " % _extstr(u"splash.BuiltOn"))  #$NON-NLS-1$ #$NON-NLS-2$
        self.dateLabelLabel.SetFont(getDefaultFontBold())
        self.dateLabel = wx.StaticText(self.infoPanel, wx.ID_ANY,
                                       verDate.toString(localTime=True))

        return self.infoPanel

    # end _createRavenInfoPage()

    def _createCreditsPage(self):
        self.creditsPanel = wx.Panel(self.notebook, wx.ID_ANY)
        self.creditsPanel.SetBackgroundColour(wx.WHITE)

        self.htmlWidget = ZHTMLViewControl(self.creditsPanel)

        return self.creditsPanel

    # end _createCreditsPage()

    def _populateContentWidgets(self):
        xhtmlDoc = loadXhtmlDocumentFromFile(
            getResourceRegistry().getResourcePath(
                u"html/about/credits.html"))  #$NON-NLS-1$
        self.htmlWidget.setXhtmlDocument(xhtmlDoc)

    # end _populateContentWidgets()

    def _layoutContentWidgets(self):
        sizer = wx.BoxSizer(wx.VERTICAL)

        self._layoutInfoPanel()
        self._layoutCreditsPanel()

        sizer.Add(self.notebook, 1, wx.EXPAND)
        sizer.Add(self.staticLine, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 2)

        return sizer

    # end _layoutContentWidgets()

    def _layoutInfoPanel(self):
        verAndDateSizer = wx.BoxSizer(wx.HORIZONTAL)
        verAndDateSizer.Add(self.versionLabelLabel, 0, wx.EXPAND | wx.RIGHT, 2)
        verAndDateSizer.Add(self.versionLabel, 0, wx.EXPAND | wx.RIGHT, 10)
        verAndDateSizer.Add(self.dateLabelLabel, 0, wx.EXPAND | wx.RIGHT, 2)
        verAndDateSizer.Add(self.dateLabel, 0, wx.EXPAND)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.aboutImage, 0, wx.EXPAND)
        sizer.AddSizer(verAndDateSizer, 0, wx.EXPAND | wx.ALL, 5)

        self.infoPanel.SetSizer(sizer)
        self.infoPanel.SetAutoLayout(True)

    # end _layoutInfoPanel()

    def _layoutCreditsPanel(self):
        sizer = wx.BoxSizer(wx.VERTICAL)

        sizer.Add(self.htmlWidget, 1, wx.EXPAND)

        self.creditsPanel.SetSizer(sizer)
        self.creditsPanel.SetAutoLayout(True)

    # end _layoutCreditsPanel()

    def _bindWidgetEvents(self):
        pass

    # end _bindWidgetEvents()

    def _getButtonTypes(self):
        return ZBaseDialog.OK_BUTTON
Esempio n. 15
0
class ZEditorFontPreferencePage(ZApplicationPreferencesPrefPage):
    def __init__(self, parent):
        fontsEnum = wx.FontEnumerator()
        fontsEnum.EnumerateFacenames()
        self.systemFontNames = fontsEnum.GetFacenames()
        self.systemFontNames.sort()
        ZApplicationPreferencesPrefPage.__init__(self, parent)

    # end __init__()

    def _getUserPrefFontName(self):
        fontName = getSafeString(
            self.session.getUserPreference(
                IZBlogAppUserPrefsKeys.EDITOR_FONT_NAME, u""))  #$NON-NLS-1$
        return fontName

    # end _getUserPrefFontName()

    def _setUserPrefFontName(self, fontName):
        fontName = getSafeString(fontName)
        prev = self._getUserPrefFontName()
        if fontName != prev:
            self.session.setUserPreference(
                IZBlogAppUserPrefsKeys.EDITOR_FONT_NAME, fontName)

    # end _setUserPrefFontName()

    def _getUserPrefFontSize(self):
        fontSize = getSafeString(
            self.session.getUserPreference(
                IZBlogAppUserPrefsKeys.EDITOR_FONT_SIZE, u""))  #$NON-NLS-1$
        return fontSize

    # end _getUserPrefFontSize()

    def _setUserPrefFontSize(self, fontSize):
        fontSize = getSafeString(fontSize)
        prev = self._getUserPrefFontSize()
        if fontSize != prev:
            self.session.setUserPreference(
                IZBlogAppUserPrefsKeys.EDITOR_FONT_SIZE, fontSize)

    # end _setUserPrefFontSize()

    def createWidgets(self):
        self.sizeStaticBox = wx.StaticBox(
            self, wx.ID_ANY, _extstr(u"fontdialog.FontSettings"))  #$NON-NLS-1$
        self.previewStaticBox = wx.StaticBox(
            self, wx.ID_ANY, _extstr(u"fontdialog.FontPreview"))  #$NON-NLS-1$
        self.fontLabel = wx.StaticText(
            self, wx.ID_ANY, u"%s:" %
            _extstr(u"fontdialog.FontName"))  #$NON-NLS-1$ #$NON-NLS-2$
        self.sizeLabel = wx.StaticText(
            self, wx.ID_ANY, u"%s:" %
            _extstr(u"fontdialog.FontSize"))  #$NON-NLS-1$ #$NON-NLS-2$

        sizes = u"Default,10px,12px,14px,16px,18px,22px,24px,26px,28px,36px".split(
            u",")  #$NON-NLS-1$ #$NON-NLS-2$
        self.sizeChoices = wx.Choice(self, wx.ID_ANY, (100, -1), choices=sizes)

        fonts = [u"Default"]  #$NON-NLS-1$
        fonts.extend(self.systemFontNames)
        self.fontChoices = wx.Choice(self, wx.ID_ANY, (100, -1), choices=fonts)
        self.previewCntrl = ZHTMLViewControl(self, wx.ID_ANY)

    # end createWidgets()

    def bindWidgetEvents(self):
        self.Bind(wx.EVT_CHOICE, self.onFontChoiceChanged, self.fontChoices)
        self.Bind(wx.EVT_CHOICE, self.onSizeChoiceChanged, self.sizeChoices)

    # end bindWidgetEvents()

    def populateWidgets(self):
        self._selectChoiceItem(self.fontChoices, self._getUserPrefFontName())
        self._selectChoiceItem(self.sizeChoices, self._getUserPrefFontSize())
        self._updatePreview()

    # end populateWidgets()

    def layoutWidgets(self):
        sizeGridSizer = wx.FlexGridSizer(2, 2, 1, 1)
        sizeGridSizer.Add(self.fontLabel, 0, wx.ALL, 1)
        sizeGridSizer.Add(self.sizeLabel, 0, wx.ALL, 1)
        sizeGridSizer.Add(self.fontChoices, 1, wx.EXPAND | wx.ALL, 1)
        sizeGridSizer.Add(self.sizeChoices, 1, wx.EXPAND | wx.ALL, 1)

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

        previewStaticBoxSizer = wx.StaticBoxSizer(self.previewStaticBox,
                                                  wx.VERTICAL)
        previewStaticBoxSizer.Add(self.previewCntrl, 1, wx.EXPAND | wx.ALL, 1)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.AddSizer(sizeStaticBoxSizer, 0, wx.EXPAND | wx.ALL, 4)
        sizer.AddSizer(previewStaticBoxSizer, 2, wx.EXPAND | wx.ALL, 4)
        self.SetAutoLayout(True)
        self.SetSizer(sizer)
        self.Layout()

    # end layoutWidgets()

    def _updatePreview(self):
        style = u""  #$NON-NLS-1$
        if self.fontChoices.GetSelection() > 0:
            style = style + u"font-family:%s; " % self.fontChoices.GetStringSelection(
            )  #$NON-NLS-1$
        if self.sizeChoices.GetSelection() > 0:
            style = style + u"font-size:%s; " % self.sizeChoices.GetStringSelection(
            )  #$NON-NLS-1$

        self.previewCntrl.setHtmlValue(PREVIEW_HTML % style)

    # end _updatePreview()

    def _selectChoiceItem(self, choiceControl, value):
        selectIdx = 0
        if value:
            value = value.lower().strip()
            for idx in range(choiceControl.GetCount()):
                s = choiceControl.GetString(idx).lower().strip()
                if s == value:
                    selectIdx = idx
                    break
        choiceControl.Select(selectIdx)

    # end _selectChoiceItem

    def onFontChoiceChanged(self, event):  #@UnusedVariable
        self._updatePreview()
        fontName = self.fontChoices.GetStringSelection()
        self._setUserPrefFontName(fontName)

    # end onFontChoiceChanged()

    def onSizeChoiceChanged(self, event):  #@UnusedVariable
        self._updatePreview()
        fontSize = self.sizeChoices.GetStringSelection()
        self._setUserPrefFontSize(fontSize)

    # end onSizeChoiceChanged()

    def apply(self):
        return ZApplicationPreferencesPrefPage.apply(self)
Esempio n. 16
0
 def createContentPreviewer(self, parentWindow, zblogPostEditor, model): #@UnusedVariable
     u"""createContentPreviewer(wxWindow, ZBlogPostEditor, ZBlogPostEditorModel) -> IZHTMLViewControl
     """ #$NON-NLS-1$
     htmlview = ZHTMLViewControl(parentWindow, wx.ID_ANY)
     return htmlview
Esempio n. 17
0
 def _createWidgets(self):
     self.htmlViewer = ZHTMLViewControl(self, wx.ID_ANY)
     self._clearHtmlContent()
Esempio n. 18
0
class ZPreviewBlogPostDetailsPanel(ZAbstractDetailsPanel, IZDataStoreListener, IZUserPreferencesListener):

    def __init__(self, parent):
        self.document = None

        # Get the "use template" param from the user prefs
        appModel = getApplicationModel()
        userProfile = appModel.getUserProfile()
        userPrefs = userProfile.getPreferences()
        self.useTemplateInPreview = userPrefs.getUserPreferenceBool(IZBlogAppUserPrefsKeys.POST_PREVIEW_VIEW_USE_TEMPLATE, True)

        ZAbstractDetailsPanel.__init__(self, parent)

        self._registerAsListener()
    # end __init__()

    def _createWidgets(self):
        self.htmlViewer = ZHTMLViewControl(self, wx.ID_ANY)
        self._clearHtmlContent()
    # end _createWidgets()

    def _bindWidgetEvents(self):
        self.Bind(ZEVT_REFRESH, self.onZoundryRefresh, self)
    # end _bindWidgetEvents()

    def _layoutWidgets(self):
        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.htmlViewer, 1, wx.EXPAND)
        self.SetAutoLayout(True)
        self.SetSizer(box)
        self.Layout()
    # end _layoutWidgets()

    def onUserPreferenceChange(self, key, newValue):
        if key == IZBlogAppUserPrefsKeys.POST_PREVIEW_VIEW_USE_TEMPLATE:
            self.useTemplateInPreview = newValue
            self._refreshContent()
    # end onUserPreferenceChange()

    # FIXME (EPW) need additional context info - what blog are we looking at?
    def onSelectionChanged(self, document):
        oldDoc = self.document
        self.document = document

        if oldDoc is not None and oldDoc.getId() == document.getId():
            return

        self._refreshContent()
    # end onSelectionChanged()

    def _refreshContent(self):
        document = self.document

        # Clear content if no document is set.
        if document is None:
            self._clearHtmlContent()
            return

        content = document.getContent()
        if content is not None:
            xhtmlDoc = content.getXhtmlDocument()
            blog = getBlogFromDocument(document)
            if blog is not None and self.useTemplateInPreview:
                template = getTemplateFromBlog(blog)
                if template is not None:
                    templatedDoc = applyTemplateToDocument(template, document, APPLY_TEMPLATE_MODE_TITLE_AND_BODY)
                    if templatedDoc is not None:
                        xhtmlDoc = templatedDoc
                    disableTemplatePreviewJavaScript(xhtmlDoc)
                    self.htmlViewer.setXhtmlDocument(xhtmlDoc, False)
                    return

            self.htmlViewer.setXhtmlDocument( xhtmlDoc, True )
    # end _refreshContent()

    def _clearHtmlContent(self):
        self.document = None
        xhtmlDoc = loadXhtmlDocumentFromString(u"") #$NON-NLS-1$
        self.htmlViewer.setXhtmlDocument(xhtmlDoc, False)
    # end _clearHtmlContent()

    def destroy(self):
        self._unregisterAsListener()
    # end destroy()

    # Document changed event from IZDataStoreListener
    def onDocumentChanged(self, document, metaDataOnly):
        if not metaDataOnly and self.document is not None and self.document.getId() == document.getId():
            self.document = document
            fireRefreshEvent(self, None)
    # end onDocumentChange()

    def onDocumentDeleted(self, document):
        if self.document is not None and self.document.getId() == document.getId():
            self.document = None
            fireRefreshEvent(self, None)
    # end onDocumentDeleted()

    def onZoundryRefresh(self, event):
        self._refreshContent()
        event.Skip()
    # end onZoundryRefresh()

    def _registerAsListener(self):
        # Register as a data store listener
        service = getApplicationModel().getService(IZBlogAppServiceIDs.DATA_STORE_SERVICE_ID)
        service.addListener(self)

        # Register as a user prefs listener
        appModel = getApplicationModel()
        userProfile = appModel.getUserProfile()
        userPrefs = userProfile.getPreferences()
        userPrefs.addListener(self)
    # end _registerAsListener()

    def _unregisterAsListener(self):
        # Unregister from the data store
        service = getApplicationModel().getService(IZBlogAppServiceIDs.DATA_STORE_SERVICE_ID)
        service.removeListener(self)
        
        # Unregister from the user prefs object
        # Register as a user prefs listener
        appModel = getApplicationModel()
        userProfile = appModel.getUserProfile()
        userPrefs = userProfile.getPreferences()
        userPrefs.removeListener(self)
Esempio n. 19
0
class ZAboutDialog(ZBaseDialog):

    def __init__(self, parent):
        ZBaseDialog.__init__(self, parent, wx.ID_ANY, _extstr(u"aboutdialog.AboutRaven")) #$NON-NLS-1$

        size = self.GetBestSize()
        self.SetSize(size)
    # end __init__()

    def _createContentWidgets(self):
        self.notebook = fnb.FlatNotebook(self, wx.ID_ANY, style = fnb.FNB_BOTTOM | fnb.FNB_NO_NAV_BUTTONS | fnb.FNB_NO_X_BUTTON | fnb.FNB_NODRAG)
        self.notebook.AddPage(self._createRavenInfoPage(), _extstr(u"aboutdialog.Info"), True, -1) #$NON-NLS-1$
        self.notebook.AddPage(self._createCreditsPage(), _extstr(u"aboutdialog.Credits"), False, -1) #$NON-NLS-1$

        self.staticLine = wx.StaticLine(self, wx.HORIZONTAL)
    # end _createContentWidgets()

    def _createRavenInfoPage(self):
        self.infoPanel = wx.Panel(self.notebook, wx.ID_ANY)
        self.infoPanel.SetBackgroundColour(wx.WHITE)

        self.aboutBmp = getResourceRegistry().getBitmap(u"images/about/about.png") #$NON-NLS-1$
        self.aboutImage = ZStaticBitmap(self.infoPanel, self.aboutBmp)

        ver = version.ZVersion()
        verDate = ZSchemaDateTime(ver.getBuildDate())

        self.versionLabelLabel = wx.StaticText(self.infoPanel, wx.ID_ANY, u"%s: " % _extstr(u"splash.Version")) #$NON-NLS-1$ #$NON-NLS-2$
        self.versionLabelLabel.SetFont(getDefaultFontBold())
        self.versionLabel = wx.StaticText(self.infoPanel, wx.ID_ANY, ver.getFullVersionString())
        self.dateLabelLabel = wx.StaticText(self.infoPanel, wx.ID_ANY, u"%s: " % _extstr(u"splash.BuiltOn")) #$NON-NLS-1$ #$NON-NLS-2$
        self.dateLabelLabel.SetFont(getDefaultFontBold())
        self.dateLabel = wx.StaticText(self.infoPanel, wx.ID_ANY, verDate.toString(localTime = True))

        return self.infoPanel
    # end _createRavenInfoPage()

    def _createCreditsPage(self):
        self.creditsPanel = wx.Panel(self.notebook, wx.ID_ANY)
        self.creditsPanel.SetBackgroundColour(wx.WHITE)

        self.htmlWidget = ZHTMLViewControl(self.creditsPanel)

        return self.creditsPanel
    # end _createCreditsPage()

    def _populateContentWidgets(self):
        xhtmlDoc = loadXhtmlDocumentFromFile(getResourceRegistry().getResourcePath(u"html/about/credits.html")) #$NON-NLS-1$
        self.htmlWidget.setXhtmlDocument(xhtmlDoc)
    # end _populateContentWidgets()

    def _layoutContentWidgets(self):
        sizer = wx.BoxSizer(wx.VERTICAL)

        self._layoutInfoPanel()
        self._layoutCreditsPanel()

        sizer.Add(self.notebook, 1, wx.EXPAND)
        sizer.Add(self.staticLine, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 2)

        return sizer
    # end _layoutContentWidgets()

    def _layoutInfoPanel(self):
        verAndDateSizer = wx.BoxSizer(wx.HORIZONTAL)
        verAndDateSizer.Add(self.versionLabelLabel, 0, wx.EXPAND | wx.RIGHT, 2)
        verAndDateSizer.Add(self.versionLabel, 0, wx.EXPAND | wx.RIGHT, 10)
        verAndDateSizer.Add(self.dateLabelLabel, 0, wx.EXPAND | wx.RIGHT, 2)
        verAndDateSizer.Add(self.dateLabel, 0, wx.EXPAND)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.aboutImage, 0, wx.EXPAND)
        sizer.AddSizer(verAndDateSizer, 0, wx.EXPAND | wx.ALL, 5)

        self.infoPanel.SetSizer(sizer)
        self.infoPanel.SetAutoLayout(True)
    # end _layoutInfoPanel()

    def _layoutCreditsPanel(self):
        sizer = wx.BoxSizer(wx.VERTICAL)

        sizer.Add(self.htmlWidget, 1, wx.EXPAND)

        self.creditsPanel.SetSizer(sizer)
        self.creditsPanel.SetAutoLayout(True)
    # end _layoutCreditsPanel()

    def _bindWidgetEvents(self):
        pass
    # end _bindWidgetEvents()

    def _getButtonTypes(self):
        return ZBaseDialog.OK_BUTTON