Exemplo n.º 1
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)
Exemplo n.º 2
0
    def _createWidgets(self):
        self.splitterWindow = ZSplitterWindow(self)

        self.tagsView = ZTagsView(self.splitterWindow)
        self.tagSummaryView = ZTagSummaryView(self.splitterWindow)

        self.splitterWindow.SplitHorizontally(self.tagsView, self.tagSummaryView)
        self.splitterWindow.SetMinimumPaneSize(100)
        self.splitterWindow.SetSashSize(8)
        self.splitterWindow.SetSashGravity(0.0)
Exemplo n.º 3
0
    def _createNonHeaderWidgets(self):
        self.splitterWindow = ZSplitterWindow(self)
        self.splitterWindow.SetMinimumPaneSize(100)
        self.splitterWindow.SetSashSize(3)

        self.leftPanel = self._createLeftTreePanel()
        self.currentPage = self._createDefaultPage()
        self.currentPageId = None

        self.splitterWindow.SplitVertically(self.leftPanel, self.currentPage,
                                            175)

        self.lowerStaticLine = wx.StaticLine(self)
Exemplo n.º 4
0
class ZContextInfoTagsView(ZView):

    def __init__(self, parent):
        ZView.__init__(self, parent, wx.ID_ANY)

        self.sashPosition = 0

        self._createWidgets()
        self._layoutWidgets()
        self._bindWidgetEvents()
    # end __init__()

    def getViewId(self):
        return IZViewIds.TAGS_VIEW
    # end getViewId()

    def _createWidgets(self):
        self.splitterWindow = ZSplitterWindow(self)

        self.tagsView = ZTagsView(self.splitterWindow)
        self.tagSummaryView = ZTagSummaryView(self.splitterWindow)

        self.splitterWindow.SplitHorizontally(self.tagsView, self.tagSummaryView)
        self.splitterWindow.SetMinimumPaneSize(100)
        self.splitterWindow.SetSashSize(8)
        self.splitterWindow.SetSashGravity(0.0)
    # end _createWidgets()

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

        self._restoreSashPosition()
    # end _layoutWidgets()

    def _bindWidgetEvents(self):
        self.Bind(ZEVT_SPLITTER_SASH_POS_CHANGED, self.onSashPosChanged, self.splitterWindow)
    # end _bindWidgetEvents()

    def onSashPosChanged(self, event):
        self.sashPosition = self.splitterWindow.GetSashPosition()
        event.Skip()
    # end onSashPosChanged()

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

    def _saveSashPosition(self):
        userPrefs = getApplicationModel().getUserProfile().getPreferences()
        userPrefs.setUserPreference(IZBlogAppUserPrefsKeys.TAGS_VIEW_SASH_POS, self.splitterWindow.GetSashPosition())
    # end _saveSashPosition()

    def _restoreSashPosition(self):
        userPrefs = getApplicationModel().getUserProfile().getPreferences()
        self.sashPosition = userPrefs.getUserPreferenceInt(IZBlogAppUserPrefsKeys.TAGS_VIEW_SASH_POS, 200)
        self.splitterWindow.SetSashPosition(self.sashPosition)
Exemplo n.º 5
0
    def createUIPanel(self, parent):
        self.panel = ZTransparentPanel(parent, wx.ID_ANY)
        self.splitterWindow = ZSplitterWindow(self.panel)

        self._createToolBar(self.panel)
        self._createNavigatorView(self.splitterWindow)
        self._createContextInfoView(self.splitterWindow)

        self._doSplit()

        self._bindViewEvents()

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.toolBar, 0, wx.EXPAND)
        self.sizer.Add(self.toolBarStaticLine, 0, wx.EXPAND)
        self.sizer.Add(self.splitterWindow, 1, wx.EXPAND | wx.ALL, 5)

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

        self.panel.Layout()
        self._restoreLayout()
        return self.panel
Exemplo n.º 6
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)
Exemplo n.º 7
0
class ZStandardPerspective(IZPerspective):

    def __init__(self):
        self.currentViewSelection = None
        self.panel = None
        self.splitterWindow = None
        self.navView = None
        self.ctxView = None
        self.sizer = None
    # end __init__()

    def destroy(self):
        self._saveLayout()

        self.navView.destroy()
        self.ctxView.destroy()
    # end destroy()

    def createUIPanel(self, parent):
        self.panel = ZTransparentPanel(parent, wx.ID_ANY)
        self.splitterWindow = ZSplitterWindow(self.panel)

        self._createToolBar(self.panel)
        self._createNavigatorView(self.splitterWindow)
        self._createContextInfoView(self.splitterWindow)

        self._doSplit()

        self._bindViewEvents()

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.toolBar, 0, wx.EXPAND)
        self.sizer.Add(self.toolBarStaticLine, 0, wx.EXPAND)
        self.sizer.Add(self.splitterWindow, 1, wx.EXPAND | wx.ALL, 5)

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

        self.panel.Layout()
        self._restoreLayout()
        return self.panel
    # end createUI()

    def _doSplit(self):
        self.splitterWindow.SplitVertically(self.navView, self.ctxView)
        self.splitterWindow.SetMinimumPaneSize(100)
        self.splitterWindow.SetSashSize(8)
        self.splitterWindow.SetSashGravity(0.0)
    # end _doSplit()

    def _createToolBar(self, parent):
        self.toolBarModel = self._createToolBarModel()
        self.toolBarContext = ZStandardPerspectiveToolBarActionContext(parent, self.currentViewSelection)
        contentProvider = ZModelBasedToolBarContentProvider(self.toolBarModel, self.toolBarContext)
        eventHandler = ZModelBasedToolBarEventHandler(self.toolBarModel, self.toolBarContext)
        self.toolBar = ZPersistentToolBar(self._getUserPrefsKey() + u".toolbar", contentProvider, eventHandler, parent, ZToolBar.STYLE_SHOW_TEXT) #$NON-NLS-1$
        self.toolBarStaticLine = wx.StaticLine(parent, wx.ID_ANY)
    # end _createToolBar()

    def _createToolBarModel(self):
        model = ZPluginToolBarModel(IZBlogAppToolBarIds.ZID_STANDARD_PERSPECTIVE_TOOLBAR)
        model.setDefaultToolSize(24)

        # 'Write' Tool
        toolId = model.addItemWithAction(_extstr(u"standard.Write"), 1, ZWriteToolBarAction()) #$NON-NLS-1$
        model.addToolBitmap(toolId, 24, getToolbarBitmap(24, u"file", u"write"))  #$NON-NLS-2$ #$NON-NLS-1$
        model.addToolBitmap(toolId, 32, getToolbarBitmap(32, u"file", u"write"))  #$NON-NLS-2$ #$NON-NLS-1$
        model.addToolDisabledBitmap(toolId, 24, getToolbarBitmap(24, u"file", u"write_disabled")) #$NON-NLS-1$ #$NON-NLS-2$
        model.addToolDisabledBitmap(toolId, 32, getToolbarBitmap(32, u"file", u"write_disabled")) #$NON-NLS-1$ #$NON-NLS-2$
        model.setToolDescription(toolId, _extstr(u"standard.Author_some_new_content_")) #$NON-NLS-1$

        # 'New Account' Tool
        toolId = model.addItemWithAction(_extstr(u"standard.AddAccount"), 3, ZNewAccountToolBarAction()) #$NON-NLS-1$
        model.addToolBitmap(toolId, 24, getToolbarBitmap(24, u"file", u"addAccount"))  #$NON-NLS-2$ #$NON-NLS-1$
        model.addToolBitmap(toolId, 32, getToolbarBitmap(32, u"file", u"addAccount"))  #$NON-NLS-2$ #$NON-NLS-1$
        model.setToolDescription(toolId, _extstr(u"standard.AddAccountDescriton")) #$NON-NLS-1$

        # 'New Storage' Tool
        toolId = model.addItemWithAction(_extstr(u"standard.AddStorage"), 3, ZNewMediaStorageToolBarAction()) #$NON-NLS-1$
        model.addToolBitmap(toolId, 24, getToolbarBitmap(24, u"file", u"addStorage"))  #$NON-NLS-2$ #$NON-NLS-1$
        model.addToolBitmap(toolId, 32, getToolbarBitmap(32, u"file", u"addStorage"))  #$NON-NLS-2$ #$NON-NLS-1$
        model.setToolDescription(toolId, _extstr(u"standard.AddStorageDescription")) #$NON-NLS-1$

        model.addSeparator(10)

        # 'Publish' Tool
        toolId = model.addItemWithAction(_extstr(u"standard.Publish"), 15, ZPublishToolBarAction()) #$NON-NLS-2$ #$NON-NLS-3$ #$NON-NLS-1$
        model.addToolBitmap(toolId, 24, getToolbarBitmap(24, u"api", u"publish"))  #$NON-NLS-2$ #$NON-NLS-1$
        model.addToolBitmap(toolId, 32, getToolbarBitmap(32, u"api", u"publish"))  #$NON-NLS-2$ #$NON-NLS-1$
        model.addToolDisabledBitmap(toolId, 24, getToolbarBitmap(24, u"api", u"publish_disabled")) #$NON-NLS-1$ #$NON-NLS-2$
        model.addToolDisabledBitmap(toolId, 32, getToolbarBitmap(32, u"api", u"publish_disabled")) #$NON-NLS-1$ #$NON-NLS-2$
        model.setToolDescription(toolId, _extstr(u"standard.Publish_some_content_")) #$NON-NLS-1$

        # 'Download' Tool
        toolId = model.addDropDownItemWithAction(_extstr(u"standard.Download"), 20, ZDownloadToolBarAction()) #$NON-NLS-2$ #$NON-NLS-3$ #$NON-NLS-1$
        model.addToolBitmap(toolId, 24, getToolbarBitmap(24, u"api", u"download"))  #$NON-NLS-2$ #$NON-NLS-1$
        model.addToolBitmap(toolId, 32, getToolbarBitmap(32, u"api", u"download"))  #$NON-NLS-2$ #$NON-NLS-1$
        model.addToolDisabledBitmap(toolId, 24, getToolbarBitmap(24, u"api", u"download_disabled")) #$NON-NLS-1$ #$NON-NLS-2$
        model.addToolDisabledBitmap(toolId, 32, getToolbarBitmap(32, u"api", u"download_disabled")) #$NON-NLS-1$ #$NON-NLS-2$
        model.setToolDescription(toolId, _extstr(u"standard.Download_content_")) #$NON-NLS-1$

        # 'View (online)' Tool
        toolId = model.addItemWithAction(_extstr(u"standard.ViewOnline"), 25, ZViewOnlineToolBarAction()) #$NON-NLS-1$
        model.addToolBitmap(toolId, 24, getToolbarBitmap(24, u"api", u"viewOnline"))  #$NON-NLS-2$ #$NON-NLS-1$
        model.addToolBitmap(toolId, 32, getToolbarBitmap(32, u"api", u"viewOnline"))  #$NON-NLS-2$ #$NON-NLS-1$
        model.addToolDisabledBitmap(toolId, 24, getToolbarBitmap(24, u"api", u"viewOnline_disabled")) #$NON-NLS-1$ #$NON-NLS-2$
        model.addToolDisabledBitmap(toolId, 32, getToolbarBitmap(32, u"api", u"viewOnline_disabled")) #$NON-NLS-1$ #$NON-NLS-2$
        model.setToolDescription(toolId, _extstr(u"standard.ViewOnlineDescription")) #$NON-NLS-1$

        model.addSeparator(50)

        # 'Delete' Tool
        toolId = model.addItemWithAction(_extstr(u"standard.Delete"), 55, ZDeleteToolBarAction()) #$NON-NLS-2$ #$NON-NLS-3$ #$NON-NLS-1$
        model.addToolBitmap(toolId, 24, getToolbarBitmap(24, u"file", u"delete"))  #$NON-NLS-2$ #$NON-NLS-1$
        model.addToolBitmap(toolId, 32, getToolbarBitmap(32, u"file", u"delete"))  #$NON-NLS-2$ #$NON-NLS-1$
        model.addToolDisabledBitmap(toolId, 24, getToolbarBitmap(24, u"file", u"delete_disabled")) #$NON-NLS-1$ #$NON-NLS-2$
        model.addToolDisabledBitmap(toolId, 32, getToolbarBitmap(32, u"file", u"delete_disabled")) #$NON-NLS-1$ #$NON-NLS-2$
        model.setToolDescription(toolId, _extstr(u"standard.DeleteDescription")) #$NON-NLS-1$

        return model
    # end _createToolBarModel()

    def _createContextInfoView(self, parent):
        self.ctxView = ZContextInfoView(parent)
    # end _createContextInfoView()

    def _createNavigatorView(self, parent):
        self.navView = ZNavigatorView(parent)
    # end _createNavigatorView()

    def _bindViewEvents(self):
        self.toolBar.Bind(ZEVT_TOOLBAR_RESIZE, self.onToolBarResize, self.toolBar)
        ZEVT_VIEW_SELECTION_CHANGED(self.navView, self.onViewSelectionChanged)
    # end _bindViewEvents()

    def onToolBarResize(self, event):
        self.panel.Layout()
        self.panel.Refresh()
        event.Skip()
    # end onToolBarResize()

    def onViewSelectionChanged(self, event):
        self.toolBarContext.setViewSelection(event.getSelection())
        self.toolBar.refresh()
        event.Skip()
    # end onViewSelectionChanged()

    def _saveLayout(self):
        if self.panel.IsShown():
            key = self._getUserPrefsKey() + u".sash-width" #$NON-NLS-1$
            userPrefs = getApplicationModel().getUserProfile().getPreferences()
            userPrefs.setUserPreference(key, self.splitterWindow.GetSashPosition())
    # end _saveLayout()

    def _restoreLayout(self):
        key = self._getUserPrefsKey() + u".sash-width" #$NON-NLS-1$
        userPrefs = getApplicationModel().getUserProfile().getPreferences()
        sashPos = userPrefs.getUserPreferenceInt(key, 200)
        self.splitterWindow.SetSashPosition(sashPos)
    # end _restoreLayout()

    def _getUserPrefsKey(self):
        return IZBlogAppUserPrefsKeys.STANDARD_PERSPECTIVE_LAYOUT
Exemplo n.º 8
0
class ZPreferencesDialog(ZHeaderDialog):
    def __init__(self, parent, jumpToPageId=None):
        self.currentSelection = None
        self.currentPage = None
        self.currentPageId = None
        self.pageCache = {}
        style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
        title = self._getDialogTitle()
        size = self._getInitialSize()

        ZHeaderDialog.__init__(self,
                               parent,
                               wx.ID_ANY,
                               title,
                               name=u"PrefsDialog",
                               style=style,
                               size=size)  #$NON-NLS-1$

        self._enableButtons(False)
        self.jumpToPage(jumpToPageId)
        self.prefsTreeView.SetFocus()

    # end __init__()

    def _getNonHeaderContentBorder(self):
        return 0

    # end _getNonHeaderContentBorder()

    def _createNonHeaderWidgets(self):
        self.splitterWindow = ZSplitterWindow(self)
        self.splitterWindow.SetMinimumPaneSize(100)
        self.splitterWindow.SetSashSize(3)

        self.leftPanel = self._createLeftTreePanel()
        self.currentPage = self._createDefaultPage()
        self.currentPageId = None

        self.splitterWindow.SplitVertically(self.leftPanel, self.currentPage,
                                            175)

        self.lowerStaticLine = wx.StaticLine(self)

    # end _createNonHeaderWidgets()

    def _createLeftTreePanel(self):
        panel = ZTransparentPanel(self.splitterWindow,
                                  wx.ID_ANY,
                                  style=wx.NO_BORDER)

        # Create the prefs tree view.
        provider = self._createTreeProvider()
        treeStyle = wx.NO_BORDER | wx.TR_HIDE_ROOT | wx.TR_LINES_AT_ROOT | wx.TR_SINGLE | wx.TR_HAS_BUTTONS
        self.prefsTreeView = ZTreeView(provider, panel, style=treeStyle)
        self.prefsTreeView.refresh()

        self.treeButtons = self._createTreeButtons(panel)

        # Create a little static vertical line (aesthetic only)
        self.middleStaticLine = wx.StaticLine(panel, style=wx.LI_VERTICAL)

        return panel

    # end _createLeftTreePanel()

    def _createTreeButtons(self, parent):  #@UnusedVariable
        return []

    # end _createTreeButtons()

    # This is the page created when no pref page is selected.
    def _createDefaultPage(self):
        defaultPrefPage = ZDefaultPreferencePage(self.splitterWindow)
        return defaultPrefPage

    # end _createDefaultPage()

    def _populateNonHeaderWidgets(self):
        self._enableApplyButton(False)

    # end _populateNonHeaderWidgets()

    def _layoutNonHeaderWidgets(self):
        treeSizer = wx.BoxSizer(wx.VERTICAL)
        treeSizer.Add(self.prefsTreeView, 1, wx.EXPAND)
        for button in self.treeButtons:
            treeSizer.Add(button, 0, wx.EXPAND | wx.ALL, 2)

        leftPanelSizer = wx.BoxSizer(wx.HORIZONTAL)
        leftPanelSizer.Add(treeSizer, 1, wx.EXPAND)
        leftPanelSizer.Add(self.middleStaticLine, 0, wx.EXPAND)
        self.leftPanel.SetAutoLayout(True)
        self.leftPanel.SetSizer(leftPanelSizer)
        self.leftPanel.Layout()

        verticalSizer = wx.BoxSizer(wx.VERTICAL)
        verticalSizer.Add(self.splitterWindow, 1, wx.EXPAND)
        verticalSizer.Add(self.lowerStaticLine, 0, wx.EXPAND)
        return verticalSizer

    # end _layoutNonHeaderWidgets()

    def _bindWidgetEvents(self):
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.onTreeItemSelected,
                  self.prefsTreeView)
        self.Bind(wx.EVT_TREE_SEL_CHANGING, self.onTreeItemChanging,
                  self.prefsTreeView)

        self._bindOkButton(self.onOK)
        self._bindCancelButton(self.onCancel)
        self._bindApplyButton(self.onApply)

    # end _bindWidgetEvents()

    def onTreeItemChanging(self, event):
        if self.currentPage is not None:
            if self.currentPage.isDirty():
                # FIXME (EPW) provide override for this message and title
                if not ZShowYesNoMessage(
                        self, _extstr(u"prefsdialog.PrefPageSwitchMessage"),
                        _extstr(u"prefsdialog.DiscardChanges")
                ):  #$NON-NLS-2$ #$NON-NLS-1$
                    event.Veto()
                    return
                else:
                    self.currentPage.rollback()
        event.Skip()

    # end onTreeItemChanging()

    def onTreeItemSelected(self, event):
        node = self.prefsTreeView.GetPyData(event.GetItem())
        self.currentSelection = node
        self._updateHeader()
        self._changePreferencePage()

        event.Skip()

    # end onTreeItemSelected()

    # This method is called when the user is changing to a new preference page.
    def _changePreferencePage(self):
        oldPage = self.currentPage
        oldPage.Show(False)

        if self.currentSelection is None:
            self.currentPage = self._createDefaultPage()
            self.currentPage.Show(True)
        elif self.currentSelection in self.pageCache:
            self.currentPage = self.pageCache[self.currentSelection]
            self.currentPage.Show(True)
        else:
            # Construct the preference page.
            self.currentPage = self._createPrefPage(self.splitterWindow,
                                                    self.currentSelection)
            self.currentPage.setPrefsDialog(self)

            # Create, populate, layout the page.
            self.currentPage.createWidgets()
            self.currentPage.bindWidgetEvents()
            self.currentPage.populateWidgets()
            self.currentPage.layoutWidgets()
            self.pageCache[self.currentSelection] = self.currentPage
        # Call rollback here, which should clear out the page's session
        # and force it to update its visual state (this is useful when one
        # pref page's initial visual state depends on another page's data,
        # which may have changed since this page was created).
        self.currentPage.rollback()

        self.currentPageId = self._resolveNodeId(self.currentSelection)

        self.splitterWindow.ReplaceWindow(oldPage, self.currentPage)
        self.splitterWindow.Layout()
        self.currentPage.Layout()

    # end _changePreferencePage()

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

    # end _getButtonTypes()

    # Called by the active pref page when the user changes something.
    def onPrefPageChange(self):
        if self.currentPage is not None:
            if self.currentPage.isDirty() and self.currentPage.isValid():
                self._enableButtons(True)
            else:
                self._enableButtons(False)

    # end onPrefPageChange()

    def _enableButtons(self, enabled=True):
        self._enableOkButton(enabled)
        self._enableApplyButton(enabled)
        cancelButton = self.FindWindowById(wx.ID_CANCEL)
        if enabled:
            cancelButton.SetLabel(_extstr(u"Cancel"))  #$NON-NLS-1$
        else:
            cancelButton.SetLabel(_extstr(u"Close"))  #$NON-NLS-1$

    # end _enableButtons()

    def onOK(self, event):
        try:
            self.currentPage.apply()
            self._destroyPages()
        except Exception, e:
            ZShowExceptionMessage(self, e)
        event.Skip()