示例#1
0
class ZMediaBlogPostDetailsPanel(ZAbstractDetailsPanel):
    def __init__(self, parent):
        self.imageContentProvider = ZMediaListViewContentProvider()

        ZAbstractDetailsPanel.__init__(self, parent)

    # end __init__()

    def _createWidgets(self):
        style = wx.LC_VIRTUAL | wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_HRULES | wx.NO_BORDER
        self.imageListView = ZListViewEx(self.imageContentProvider, self, style=style)

    # end _createWidgets()

    def _bindWidgetEvents(self):
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onActivated, self.imageListView)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onRightClick, self.imageListView)

    # end _bindWidgetEvents()

    def _layoutWidgets(self):
        imageSBSizer = wx.BoxSizer(wx.HORIZONTAL)
        imageSBSizer.Add(self.imageListView, 1, wx.EXPAND)

        box = wx.BoxSizer(wx.VERTICAL)
        box.AddSizer(imageSBSizer, 1, wx.EXPAND)
        self.SetAutoLayout(True)
        self.SetSizer(box)

    # end _layoutWidgets()

    def onSelectionChanged(self, document):
        self.imageContentProvider.setDocument(document)
        self.imageListView.refresh()

    # end onSelectionChanged()

    def onActivated(self, event):
        url = self.imageListView.GetItemText(event.GetIndex())
        if url:
            context = ZImageActionContext(self, url)
            openAction = getApplicationModel().getActionRegistry().findAction(IZAppActionIDs.OPEN_IMAGE_ACTION)
            openAction.runAction(context)
        event.Skip

    # end onActivated()

    def onRightClick(self, event):
        url = self.imageListView.GetItemText(event.GetIndex())
        if url:
            context = ZImageActionContext(self, url)
            menuModel = ZImageMenuModel()
            menu = ZModelBasedMenu(menuModel, context, self)
            self.PopupMenu(menu)
            menu.Destroy()
        event.Skip()
示例#2
0
class ZMediaBlogPostDetailsPanel(ZAbstractDetailsPanel):

    def __init__(self, parent):
        self.imageContentProvider = ZMediaListViewContentProvider()

        ZAbstractDetailsPanel.__init__(self, parent)
    # end __init__()

    def _createWidgets(self):
        style = wx.LC_VIRTUAL | wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_HRULES | wx.NO_BORDER
        self.imageListView = ZListViewEx(self.imageContentProvider, self, style = style)
    # end _createWidgets()

    def _bindWidgetEvents(self):
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onActivated, self.imageListView)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onRightClick, self.imageListView)
    # end _bindWidgetEvents()

    def _layoutWidgets(self):
        imageSBSizer = wx.BoxSizer(wx.HORIZONTAL)
        imageSBSizer.Add(self.imageListView, 1, wx.EXPAND)

        box = wx.BoxSizer(wx.VERTICAL)
        box.AddSizer(imageSBSizer, 1, wx.EXPAND)
        self.SetAutoLayout(True)
        self.SetSizer(box)
    # end _layoutWidgets()

    def onSelectionChanged(self, document):
        self.imageContentProvider.setDocument(document)
        self.imageListView.refresh()
    # end onSelectionChanged()

    def onActivated(self, event):
        url = self.imageListView.GetItemText(event.GetIndex())
        if url:
            context = ZImageActionContext(self, url)
            openAction = getApplicationModel().getActionRegistry().findAction(IZAppActionIDs.OPEN_IMAGE_ACTION)
            openAction.runAction(context)
        event.Skip
    # end onActivated()

    def onRightClick(self, event):
        url = self.imageListView.GetItemText(event.GetIndex())
        if url:
            context = ZImageActionContext(self, url)
            menuModel = ZImageMenuModel()
            menu = ZModelBasedMenu(menuModel, context, self)
            self.PopupMenu(menu)
            menu.Destroy()
        event.Skip()
示例#3
0
class ZAccountBrowseView(ZView, IZAccountStoreListener):

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

        self._createWidgets()
        self._layoutWidgets()
        self._populateWidgets()
        self._bindWidgetEvents()

        self._registerAsAccountListener()
    # end __init__()

    def _createWidgets(self):
        self.accountListProvider = ZAccountListProvider()
        self.accountListView = ZListViewEx(self.accountListProvider, self)
    # end _createWidgets()

    def _layoutWidgets(self):
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.accountListView, 1, wx.EXPAND)

        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        self.Layout()
    # end _layoutWidgets()

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

    def _bindWidgetEvents(self):
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onAccountSelected, self.accountListView)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onAccountRightClick, self.accountListView)
        self._bindRefreshEvent(self.onZoundryRefresh)
    # end _bindWidgetEvents()

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

    def onAccountRightClick(self, event):
        account = self._getSelectedAccount()
        if account is not None:
            menu = self._createAccountCtxMenu(account)
            self.PopupMenu(menu)
            menu.Destroy()
        event.Skip()
    # end onAccountRightClick()

    def onAccountSelected(self, event):
        account = self._getSelectedAccount()
        if account is not None:
            selection = None
            if account.getId() == -1:
                selection = ZViewSelection(IZViewSelectionTypes.UNPUBLISHED_ACCOUNT_SELECTION, None)
            else:
                selection = ZViewSelection(IZViewSelectionTypes.ACCOUNT_SELECTION, account.getId())
            fireViewSelectionEvent(selection, self)
        else:
            fireViewUnselectionEvent()
        event.Skip()
    # end onAccountSelected()

    def onAccountAdded(self, account): #@UnusedVariable
        self.accountListProvider.refresh()
        fireRefreshEvent(self)
    # end onAccountAdded()

    def onAccountDeleted(self, account): #@UnusedVariable
        if self._getSelectedAccount().getId() == account.getId():
            selection = ZViewSelection(IZViewSelectionTypes.UNPUBLISHED_ACCOUNT_SELECTION, None)
            fireViewSelectionEvent(selection, self)

        self.accountListProvider.refresh()
        fireRefreshEvent(self)
    # end onAccountDeleted()

    def _createAccountCtxMenu(self, account):
        menuContext = ZAccountMenuActionContext(self, account)
        menuModel = ZBlogAccountMenuModel()
        provider = ZModelBasedMenuContentProvider(menuModel, menuContext)
        eventHandler = ZModelBasedMenuEventHandler(menuModel, menuContext)
        return ZMenu(self, menuModel.getRootNode(), provider, eventHandler)
    # end _createAccountCtxMenu()

    def _registerAsAccountListener(self):
        accountStore = getApplicationModel().getService(IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
        accountStore.addListener(self)
    # end _registerAsAccountListener()

    def _unregisterAsAccountListener(self):
        accountStore = getApplicationModel().getService(IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
        accountStore.removeListener(self)
    # end _unregisterAsAccountListener()

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

    def _getSelectedAccount(self):
        itemIndexes = self.accountListView.getSelection()
        if itemIndexes:
            itemIndex = itemIndexes[0]
            return self.accountListProvider.getAccountAtIndex(itemIndex)
        return None
示例#4
0
class ZTranslationEditor(ZHeaderDialog, ZPersistentDialogMixin):

    def __init__(self, parent, translation, defaultTranslation, translationDisplayName):
        self.translationDisplayName = translationDisplayName
        self.model = ZTranslationEditorModel(translation, defaultTranslation)
        style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER

        ZHeaderDialog.__init__(self, parent, wx.ID_ANY, _extstr(u"translationeditor.EditTranslation_") % translationDisplayName, style = style) #$NON-NLS-1$
        ZPersistentDialogMixin.__init__(self, IZBlogAppUserPrefsKeys.TRANSLATION_DIALOG, True, True)

        self.selectedKey = None
        self.selectedValue = None
    # end __init__()

    def GetBestSize(self):
        return wx.Size(600, 500)
    # end GetBestSize()

    def _createNonHeaderWidgets(self):
        self.showOnlyCB = wx.CheckBox(self, wx.ID_ANY, _extstr(u"translationeditor.ShowOnlyUntranslated")) #$NON-NLS-1$
        self.listProvider = ZStringBundleProvider(self.model)
        self.listBox = ZListViewEx(self.listProvider, self, wx.ID_ANY)
        bitmap = getFlagBitmapForLocale(u"en_US") #$NON-NLS-1$
        self.englishFlag = ZStaticBitmap(self, bitmap)
        self.englishLabel = wx.StaticText(self, wx.ID_ANY, _extstr(u"translationeditor.EnglishValue")) #$NON-NLS-1$
        bitmap = getFlagBitmapForLocale(self.model.getTranslation().getLocale().toString())
        if bitmap is None:
            bitmap = getEmptyFlagBitmap()
        self.translationFlag = ZStaticBitmap(self, bitmap)
        self.translationLabel = wx.StaticText(self, wx.ID_ANY, self.translationDisplayName)
        self.englishText = wx.TextCtrl(self, wx.ID_ANY, style = wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_BESTWRAP)
        self.translationText = wx.TextCtrl(self, wx.ID_ANY, style = wx.TE_MULTILINE | wx.TE_BESTWRAP | wx.TE_PROCESS_ENTER)

        self.translationText.Enable(False)

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

    def _populateNonHeaderWidgets(self):
        self.showOnlyCB.SetValue(False)
    # end _populateNonHeaderWidgets()

    def _layoutNonHeaderWidgets(self):
        englishSizer = wx.BoxSizer(wx.HORIZONTAL)
        englishSizer.Add(self.englishFlag, 0, wx.ALL | wx.EXPAND, 2)
        englishSizer.Add(self.englishLabel, 1, wx.ALL | wx.EXPAND, 2)
        translationSizer = wx.BoxSizer(wx.HORIZONTAL)
        translationSizer.Add(self.translationFlag, 0, wx.ALL | wx.EXPAND, 2)
        translationSizer.Add(self.translationLabel, 1, wx.ALL | wx.EXPAND, 2)
        labelSizer = wx.BoxSizer(wx.HORIZONTAL)
        labelSizer.AddSizer(englishSizer, 1, wx.EXPAND)
        labelSizer.AddSizer(translationSizer, 1, wx.EXPAND)

        valueSizer = wx.BoxSizer(wx.HORIZONTAL)
        valueSizer.Add(self.englishText, 1, wx.ALL | wx.EXPAND, 2)
        valueSizer.Add(self.translationText, 1, wx.ALL | wx.EXPAND, 2)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.showOnlyCB, 0, wx.ALL | wx.EXPAND, 3)
        sizer.Add(self.listBox, 2, wx.ALL | wx.EXPAND, 3)
        sizer.AddSizer(labelSizer, 0, wx.ALL | wx.EXPAND, 1)
        sizer.AddSizer(valueSizer, 1, wx.ALL | wx.EXPAND, 1)
        sizer.Add(self.staticLine, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 2)
        return sizer
    # end _layoutNonHeaderWidgets()

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

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

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

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

    def _bindWidgetEvents(self):
        self._bindOkButton(self.onSave)
        self._bindCancelButton(self.onCancel)
        self.Bind(wx.EVT_CHECKBOX, self.onShowOnly, self.showOnlyCB)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onListSelection, self.listBox)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onListActivation, self.listBox)
        self.Bind(wx.EVT_TEXT_ENTER, self.onTranslationActivation, self.translationText)

        wx.EVT_KILL_FOCUS(self.translationText, self.onTranslationUnfocus)
    # end _bindWidgetEvents()

    def _setInitialFocus(self):
        self.listBox.SetFocus()
    # end _setInitialFocus()

    def _getOKButtonLabel(self):
        return _extstr(u"translationeditor.Save") #$NON-NLS-1$
    # end _getOKButtonLabel()

    def onSave(self, event):
        wx.BusyCursor()
        self.model.save()
        event.Skip()
    # end onSave()

    def onCancel(self, event):
        if self.model.isDirty() and ZShowYesNoMessage(self, _extstr(u"translationeditor.CancelTranslationMessage"), _extstr(u"translationeditor.CancelTranslationTitle")): #$NON-NLS-2$ #$NON-NLS-1$
            self.model.getTranslation().clear()
            event.Skip()
        elif not self.model.isDirty():
            event.Skip()
    # end onCancel()

    def onListSelection(self, event):
        self._doListSelection()
        event.Skip()
    # end onListSelection()

    def onShowOnly(self, event):
        self.model.setShowOnlyUntranslated(event.IsChecked())
        self.listBox.refresh()
        event.Skip()
    # end onShowOnly()

    def onTranslationUnfocus(self, event):
        value = self.translationText.GetValue()
        # if there is a selection, and the value has changed
        if self.selectedKey is not None and value != self.selectedValue:
            value = getSafeString(value).strip()
            self.model.setTranslationValue(self.selectedKey, value)
            self.listBox.refresh()
        self.translationText.Enable(False)
        event.Skip()
    # end onTranslationUnfocus()

    def onListActivation(self, event):
        self._doListSelection()
        self.translationText.Enable(True)
        self.translationText.SetFocus()
        event.Skip()
    # end onListActivation()

    def onTranslationActivation(self, event):
        self.listBox.SetFocus()
        selectionIdx = self.listBox.getSelection()[0]
        if not self.showOnlyCB.IsChecked():
            selectionIdx = selectionIdx + 1
        self.listBox.Select(selectionIdx, True)
        self._doListSelection()
        event.Skip()
    # end onTranslationActivation()

    def _doListSelection(self):
        selectionIdx = self.listBox.getSelection()[0]
        self.selectedKey = self.model.getKeys()[selectionIdx]
        defValue = self.model.getDefaultValue(self.selectedKey)
        transValue = self.model.getTranslationValue(self.selectedKey)
        self.selectedValue = getSafeString(transValue).strip()

        self.englishText.SetValue(defValue)
        self.translationText.SetValue(self.selectedValue)
示例#5
0
class ZFoldersBrowseView(ZView):

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

        self._createWidgets()
        self._layoutWidgets()
        self._populateWidgets()
        self._bindWidgetEvents()

        self._registerAsAccountListener()
    # end __init__()

    def _createWidgets(self):
        self.folderListProvider = ZFolderListProvider()
        self.folderListView = ZListViewEx(self.folderListProvider, self)
    # end _createWidgets()

    def _layoutWidgets(self):
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.folderListView, 1, wx.EXPAND)

        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        self.Layout()
    # end _layoutWidgets()

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

    def _bindWidgetEvents(self):
        self.Bind(ZEVT_VIEW_SELECTION_CHANGED, self.onViewSelection)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onFolderSelected, self.folderListView)
        self._bindRefreshEvent(self.onZoundryRefresh)
    # end _bindWidgetEvents()

    def onViewSelection(self, event):
        selection = event.getSelection()
        if selection.getType() == IZViewSelectionTypes.BLOG_SELECTION:
            (accountId, blogId) = selection.getData()
            self._refreshListView(accountId, blogId)
        elif selection.getType() == IZViewSelectionTypes.UNPUBLISHED_ACCOUNT_SELECTION:
            self._refreshListView(UNPUBLISHED_ACCOUNT_ID, None)
        elif selection.getType() == IZViewSelectionTypes.ACCOUNT_SELECTION:
            self._refreshListView(None, None)

        event.Skip()
    # end onViewSelection()

    def _refreshListView(self, accountId, blogId):
        self.folderListProvider.setAccountId(accountId)
        self.folderListProvider.setBlogId(blogId)
        self.folderListProvider.refresh()
        self.folderListView.refresh()
        self.folderListView.deselectAll()
    # end _refreshListView()

    def onFolderSelected(self, event):
        folderType = self._getSelectedFolderType()
        if folderType is not None:
            accountId = self.folderListProvider.getAccountId()
            blogId = self.folderListProvider.getBlogId()
            if accountId == UNPUBLISHED_ACCOUNT_ID:
                accountId = None
                blogId = None
            selection = ZViewSelection(folderType, (accountId, blogId))
            fireViewSelectionEvent(selection, self)
        else:
            fireViewUnselectionEvent()
        event.Skip()
    # end onFolderSelected()

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

    def onAccountDeleted(self, account):
        if account.getId() == self.folderListProvider.getAccountId():
            self.folderListProvider.setAccountId(None)
            self.folderListProvider.setBlogId(None)
            self.folderListProvider.refresh()
            fireRefreshEvent(self)
    # end onAccountDeleted()

    def _registerAsAccountListener(self):
        accountStore = getApplicationModel().getService(IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
        accountStore.addListener(self)
    # end _registerAsAccountListener()

    def _unregisterAsAccountListener(self):
        accountStore = getApplicationModel().getService(IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
        accountStore.removeListener(self)
    # end _unregisterAsAccountListener()

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

    def _getSelectedFolderType(self):
        itemIndexes = self.folderListView.getSelection()
        if itemIndexes:
            itemIndex = itemIndexes[0]
            return self.folderListProvider.getFolderType(itemIndex)
        return None
示例#6
0
class ZPersonalDictionaryPreferencePage(ZApplicationPreferencesPrefPage,
                                        IZSpellCheckServiceListener):
    def __init__(self, parent):
        self.model = ZPersonalDictionaryPrefPageModel()
        ZApplicationPreferencesPrefPage.__init__(self, parent)

        self.model.getSpellcheckService().addListener(self)

    # end __init__()

    def createWidgets(self):
        self.warningMsg = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"personaldictprefpage.SpellCheckingMustBeEnabled"
                    ))  #$NON-NLS-1$
        self.warningMsg.SetFont(getDefaultFontBold())
        self.staticBox = wx.StaticBox(self, wx.ID_ANY)
        provider = ZPersonalDictionaryContentProvider(self.model)
        self.personalDictionaryListView = ZListViewEx(provider, self)
        self.addButton = wx.Button(
            self, wx.ID_ANY,
            _extstr(u"personaldictprefpage.Add"))  #$NON-NLS-1$
        self.removeButton = wx.Button(
            self, wx.ID_ANY,
            _extstr(u"personaldictprefpage.Remove"))  #$NON-NLS-1$
        self.clearButton = wx.Button(
            self, wx.ID_ANY,
            _extstr(u"personaldictprefpage.Clear"))  #$NON-NLS-1$

    # end createWidgets()

    def populateWidgets(self):
        self._refreshButtonStates()
        isEnabled = self.model.isSpellcheckEnabled()
        self.warningMsg.Show(not isEnabled)
        self.personalDictionaryListView.Enable(isEnabled)
        self.addButton.Enable(isEnabled)
        self.removeButton.Enable(isEnabled)
        self.clearButton.Enable(isEnabled)

    # end populateWidgets()

    def bindWidgetEvents(self):
        self.Bind(wx.EVT_BUTTON, self.onAddWord, self.addButton)
        self.Bind(wx.EVT_BUTTON, self.onRemoveWord, self.removeButton)
        self.Bind(wx.EVT_BUTTON, self.onClear, self.clearButton)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onWordSelected,
                  self.personalDictionaryListView)

    # end bindWidgetEvents()

    def layoutWidgets(self):
        buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
        buttonSizer.Add(self.addButton, 0, wx.EXPAND | wx.ALL, 2)
        buttonSizer.Add(self.removeButton, 0, wx.EXPAND | wx.ALL, 2)
        buttonSizer.Add(self.clearButton, 0, wx.EXPAND | wx.ALL, 2)

        sizer = wx.StaticBoxSizer(self.staticBox, wx.VERTICAL)
        sizer.Add(self.personalDictionaryListView, 1, wx.EXPAND | wx.ALL, 5)
        sizer.AddSizer(buttonSizer, 0, wx.EXPAND | wx.ALL, 1)

        prefSizer = wx.BoxSizer(wx.VERTICAL)
        prefSizer.Add(self.warningMsg, 0, wx.EXPAND | wx.ALL, 2)
        prefSizer.AddSizer(sizer, 1, wx.EXPAND | wx.ALL, 5)

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

    # end layoutWidgets()

    def onAddWord(self, event):
        word = ZShowDataEntryDialog(
            self, _extstr(u"personaldictprefpage.AddPersonalDictionaryWord"),
            _extstr(u"personaldictprefpage.Word"))  #$NON-NLS-2$ #$NON-NLS-1$
        if word is not None:
            self.model.addWord(word)
            self.personalDictionaryListView.refresh()
            self._refreshButtonStates()
            self.getPrefsDialog().onPrefPageChange()
        event.Skip()

    # end onAddWord()

    def onRemoveWord(self, event):
        selection = self.personalDictionaryListView.getSelection()
        if selection:
            selectedWord = self.model.getWordList()[selection[0]]
            if self.model.deleteWord(selectedWord):
                self.personalDictionaryListView.refresh()
                self._refreshButtonStates()
                self.getPrefsDialog().onPrefPageChange()
        event.Skip()

    # end onRemoveWord()

    def onClear(self, event):
        self.model.clearWords()
        self.personalDictionaryListView.refresh()
        self._refreshButtonStates()
        self.getPrefsDialog().onPrefPageChange()
        event.Skip()

    # end onClear()

    def onWordSelected(self, event):
        self._refreshButtonStates()
        event.Skip()

    # end onWordSelected()

    def onSpellcheckEnabled(self, spellChecker):  #@UnusedVariable
        self.rollback()

    # end onSpellcheckEnabled()

    def onSpellcheckDisabled(self):
        self.rollback()

    # end onSpellcheckDisabled()

    def _refreshButtonStates(self):
        self.removeButton.Enable(
            self.personalDictionaryListView.GetSelectedItemCount() > 0)
        self.clearButton.Enable(len(self.model.getWordList()) > 0)

    # end _refreshButtonStates()

    def isDirty(self):
        return self.model.isDirty()

    # end isDirty()

    def isValid(self):
        return True

    # end isValid()

    def apply(self):
        self.model.commit()
        return True

    # end apply()

    def rollback(self):
        self.model.rollback()
        self.personalDictionaryListView.refresh()
        self.populateWidgets()

    # end rollback()

    def destroy(self):
        self.model.getSpellcheckService().removeListener(self)
示例#7
0
class ZFoldersBrowseView(ZView):

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

        self._createWidgets()
        self._layoutWidgets()
        self._populateWidgets()
        self._bindWidgetEvents()

        self._registerAsAccountListener()
    # end __init__()

    def _createWidgets(self):
        self.folderListProvider = ZFolderListProvider()
        self.folderListView = ZListViewEx(self.folderListProvider, self)
    # end _createWidgets()

    def _layoutWidgets(self):
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.folderListView, 1, wx.EXPAND)

        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        self.Layout()
    # end _layoutWidgets()

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

    def _bindWidgetEvents(self):
        self.Bind(ZEVT_VIEW_SELECTION_CHANGED, self.onViewSelection)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onFolderSelected, self.folderListView)
        self._bindRefreshEvent(self.onZoundryRefresh)
    # end _bindWidgetEvents()

    def onViewSelection(self, event):
        selection = event.getSelection()
        if selection.getType() == IZViewSelectionTypes.BLOG_SELECTION:
            (accountId, blogId) = selection.getData()
            self._refreshListView(accountId, blogId)
        elif selection.getType() == IZViewSelectionTypes.UNPUBLISHED_ACCOUNT_SELECTION:
            self._refreshListView(UNPUBLISHED_ACCOUNT_ID, None)
        elif selection.getType() == IZViewSelectionTypes.ACCOUNT_SELECTION:
            self._refreshListView(None, None)

        event.Skip()
    # end onViewSelection()

    def _refreshListView(self, accountId, blogId):
        self.folderListProvider.setAccountId(accountId)
        self.folderListProvider.setBlogId(blogId)
        self.folderListProvider.refresh()
        self.folderListView.refresh()
        self.folderListView.deselectAll()
    # end _refreshListView()

    def onFolderSelected(self, event):
        folderType = self._getSelectedFolderType()
        if folderType is not None:
            accountId = self.folderListProvider.getAccountId()
            blogId = self.folderListProvider.getBlogId()
            if accountId == UNPUBLISHED_ACCOUNT_ID:
                accountId = None
                blogId = None
            selection = ZViewSelection(folderType, (accountId, blogId))
            fireViewSelectionEvent(selection, self)
        else:
            fireViewUnselectionEvent()
        event.Skip()
    # end onFolderSelected()

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

    def onAccountDeleted(self, account):
        if account.getId() == self.folderListProvider.getAccountId():
            self.folderListProvider.setAccountId(None)
            self.folderListProvider.setBlogId(None)
            self.folderListProvider.refresh()
            fireRefreshEvent(self)
    # end onAccountDeleted()

    def _registerAsAccountListener(self):
        accountStore = getApplicationModel().getService(IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
        accountStore.addListener(self)
    # end _registerAsAccountListener()

    def _unregisterAsAccountListener(self):
        accountStore = getApplicationModel().getService(IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
        accountStore.removeListener(self)
    # end _unregisterAsAccountListener()

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

    def _getSelectedFolderType(self):
        itemIndexes = self.folderListView.getSelection()
        if itemIndexes:
            itemIndex = itemIndexes[0]
            return self.folderListProvider.getFolderType(itemIndex)
        return None
示例#8
0
class ZBlogPostsView(ZBoxedView, IZDocumentIndexListener):
    def __init__(self, parent):
        filter = ZDocumentSearchFilter()
        filter.setAccountIdCriteria(
            IZDocumentSearchFilter.UNPUBLISHED_ACCOUNT_ID)
        filter.setBlogIdCriteria(IZDocumentSearchFilter.UNPUBLISHED_BLOG_ID)
        self.model = ZContextInfoPostsModel(filter)
        self.openAction = getApplicationModel().getActionRegistry().findAction(
            IZBlogAppActionIDs.OPEN_BLOG_POST_ACTION)
        self.blogPostContextMenu = ZBlogPostMenuModel()
        self.postsAccelTable = ZBlogPostsListAcceleratorTable(self)
        self.document = None
        self.blog = None
        self.hasFocus = False

        self.indexService = getApplicationModel().getService(
            IZBlogAppServiceIDs.DOCUMENT_INDEX_SERVICE_ID)
        self.docStore = getApplicationModel().getService(
            IZBlogAppServiceIDs.DATA_STORE_SERVICE_ID)
        self.accountStore = getApplicationModel().getService(
            IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)

        ZBoxedView.__init__(self, parent)

        self._registerAsIndexListener()

    # end __init__()

    def getViewId(self):
        return IZViewIds.POSTS_LIST_VIEW

    # end getViewId()

    def _getHeaderBitmap(self):
        return getResourceRegistry().getBitmap(
            u"images/perspectives/standard/posts.png")  #$NON-NLS-1$

    # end _getHeaderBitmap()

    def _getHeaderLabel(self):
        return _extstr(u"postsview.BlogPosts")  #$NON-NLS-1$

    # end _getHeaderLabel()

    def _createHeaderWidgets(self, parent, widgetList):
        self.viewLabel = wx.StaticText(
            parent, wx.ID_ANY, _extstr(u"postsview.Filter"))  #$NON-NLS-1$
        choices = self._getViewChoices()
        self.viewCombo = wx.ComboBox(parent,
                                     wx.ID_ANY,
                                     _extstr(u"postsview.All"),
                                     style=wx.CB_READONLY,
                                     choices=choices)  #$NON-NLS-1$
        choices = self._getSearchBoxChoices()
        bitmap = getResourceRegistry().getBitmap(
            u"images/perspectives/standard/contextinfo/postsview/search.png"
        )  #$NON-NLS-1$
        self.searchTextBox = ZAdvancedTextBox(parent, bitmap, choices, False)
        self.searchTextBox.setCurrentChoice(SEARCH_TB_TITLE)
        self.searchTextBox.SetSizeHints(220, -1)

        widgetList.append(self.viewLabel)
        widgetList.append(self.viewCombo)
        widgetList.append(self.searchTextBox)

    # end _createHeaderWidgets()

    def _createContentWidgets(self, parent):
        provider = ZBlogEntryListContentProvider(self.model)
        style = wx.LC_VIRTUAL | wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.NO_BORDER
        self.entriesListView = ZListViewEx(provider, parent, style=style)
        self.entriesListView.SetAcceleratorTable(self.postsAccelTable)

    # end _createContentWidgets()

    def _layoutContentWidgets(self):
        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.entriesListView, 1, wx.EXPAND)
        return box

    # end _layoutContentWidgets()

    def _bindWidgetEvents(self):
        ZBoxedView._bindWidgetEvents(self)

        self.postsAccelTable.bindTo(self.entriesListView)

        self.Bind(ZEVT_REFRESH, self.onZoundryRefresh, self)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onEntryActivated,
                  self.entriesListView)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onEntrySelected,
                  self.entriesListView)
        self.Bind(wx.EVT_LIST_BEGIN_DRAG, self.onEntryBeginDrag,
                  self.entriesListView)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onEntryRightClick,
                  self.entriesListView)
        self.Bind(wx.EVT_COMBOBOX, self.onViewCombo, self.viewCombo)
        self.Bind(wx.EVT_TEXT_ENTER, self.onSearchText, self.searchTextBox)
        self.Bind(ZEVT_VIEW_SELECTION_CHANGED, self.onViewSelectionChanged)
        wx.EVT_SET_FOCUS(self.entriesListView, self.onFocus)
        wx.EVT_KILL_FOCUS(self.entriesListView, self.onUnFocus)

    # end _bindWidgetEvents()

    def refreshContent(self, selection):
        isUnselecting = False
        if self.entriesListView.getSelection():
            isUnselecting = True

        (accountId, blogId) = selection.getData()

        filter = ZDocumentSearchFilter()
        if blogId is not None:
            account = self.accountStore.getAccountById(accountId)
            self.blog = account.getBlogById(blogId)
            filter.setAccountIdCriteria(accountId)
            filter.setBlogIdCriteria(blogId)
        else:
            self.blog = None
            filter.setAccountIdCriteria(
                IZDocumentSearchFilter.UNPUBLISHED_ACCOUNT_ID)
            filter.setBlogIdCriteria(
                IZDocumentSearchFilter.UNPUBLISHED_BLOG_ID)

        self.model = ZContextInfoPostsModel(filter)
        self.entriesListView.setContentProvider(
            ZBlogEntryListContentProvider(self.model))
        self.entriesListView.refresh()
        self.entriesListView.deselectAll()
        self.onInvalidSelection()
        if isUnselecting:
            fireViewUnselectionEvent()

    # end refreshContent()

    def onViewSelectionChanged(self, event):
        if event.getSelection().getType(
        ) == IZViewSelectionTypes.BLOG_POSTS_SELECTION:
            self.refreshContent(event.getSelection())
        event.Skip()

    # end onViewSelectionChanged()

    def onFocus(self, event):
        if not self.hasFocus:
            if self.document:
                fireViewSelectionEvent(
                    ZDocumentSelection(self.document, self.blog), self)
            else:
                fireViewUnselectionEvent()
            self.hasFocus = True
        event.Skip()

    # end onFocus()

    def onUnFocus(self, event):
        if self.hasFocus:
            fireViewUnselectionEvent()
            self.hasFocus = False
        event.Skip()

    # end onUnFocus()

    def onViewCombo(self, event):
        choice = event.GetSelection()
        self.model.clearDraftCriteria()
        self.model.clearDateRangeCriteria()
        if choice == VIEW_CHOICE_DRAFTS:
            self.model.setDraftCriteria()
        elif choice == VIEW_CHOICE_PUBLISHED:
            self.model.setDraftCriteria(False)
        elif choice == VIEW_CHOICE_TODAY:
            dateRange = getRangeForToday()
            self.model.setDateRangeCriteria(dateRange.getStartDate(),
                                            dateRange.getEndDate())
        elif choice == VIEW_CHOICE_YESTERDAY:
            dateRange = getRangeForYesterday()
            self.model.setDateRangeCriteria(dateRange.getStartDate(),
                                            dateRange.getEndDate())
        elif choice == VIEW_CHOICE_THISWEEK:
            dateRange = getRangeForThisWeek()
            self.model.setDateRangeCriteria(dateRange.getStartDate(),
                                            dateRange.getEndDate())
        elif choice == VIEW_CHOICE_THISMONTH:
            dateRange = getRangeForThisMonth()
            self.model.setDateRangeCriteria(dateRange.getStartDate(),
                                            dateRange.getEndDate())
        self.model.refresh()
        self.entriesListView.refresh()
        self.entriesListView.deselectAll()
        self.onInvalidSelection()

        fireViewEvent(ZViewEvent(VIEWBLOGPOSTSFILTERCHANGEDEVENT, self))
        event.Skip()

    # end onViewCombo()

    def onSearchText(self, event):
        self.model.setTitleCriteria(event.GetString())
        self.model.refresh()
        self.entriesListView.refresh()
        self.entriesListView.deselectAll()
        self.onInvalidSelection()

        fireViewEvent(ZViewEvent(VIEWBLOGPOSTSFILTERCHANGEDEVENT, self))
        event.Skip()

    # end onSearchText()

    def onEntryBeginDrag(self, event):
        index = event.GetIndex()
        docIDO = self.model.getEntry(index)
        docId = docIDO.getId()

        # FIXME (EPW) also add some sort of custom format for dragging to the Explorer/TextPad (use a composite data object)
        data = wx.DataObjectComposite()
        #        url = self._getUrlFromDocIDO(docIDO)
        #        if url is not None:
        #            data.Add(ZURLDataObject(url))
        data.Add(ZBlogPostDataObjectInternal(docId))
        #        data.Add(wx.TextDataObject(str(convertToUtf8(u"Hello World"))))

        dragSource = wx.DropSource(self)
        dragSource.SetData(data)
        dragSource.DoDragDrop(wx.Drag_CopyOnly)
        event.Skip()

    # end onEntryBeginDrag()

    def _updateModel(self, refreshData):
        (eventType, documentIDO) = refreshData
        shouldRefresh = False
        if eventType == IZDocIndexEvent.DOCINDEX_EVENTTYPE_ADD:
            shouldRefresh = self.model.addEntry(documentIDO)
        elif eventType == IZDocIndexEvent.DOCINDEX_EVENTTYPE_REMOVE:
            shouldRefresh = self.model.removeEntry(documentIDO)
        elif eventType == IZDocIndexEvent.DOCINDEX_EVENTTYPE_UPDATE:
            shouldRefresh = self.model.updateEntry(documentIDO)
        return shouldRefresh

    # end _updateModel()

    # This is the only method that can happen on a non-UI thread.  It will
    # gather up the needed data, then fire a "refresh ui" event.  That event
    # will get picked up by the UI thread and the view will refresh.
    def onIndexChange(self, event):
        if event.getDataType() == IZDocIndexEvent.DOCINDEX_DATATYPE_DOCUMENT:
            refreshData = (event.getEventType(), event.getDocumentIDO())
            fireRefreshEvent(self, refreshData)

    # end onIndexChange()

    def onZoundryRefresh(self, event):  #@UnusedVariable
        if self._updateModel(event.getData()):
            self.entriesListView.refresh()
            selection = self.entriesListView.getSelection()
            if not selection:
                self.onInvalidSelection()
                fireViewUnselectionEvent()
            else:
                selIdx = selection[0]
                newDocIDO = self.model.getEntry(selIdx)
                newDoc = self.docStore.getDocument(newDocIDO.getId())
                self.document = newDoc
                fireViewSelectionEvent(
                    ZDocumentSelection(self.document, self.blog), self)
        event.Skip()

    # end onZoundryRefresh()

    def onEntryRightClick(self, event):
        index = event.GetIndex()
        docIDO = self.model.getEntry(index)
        blogId = None
        if self.blog is not None:
            blogId = self.blog.getId()
        actionContext = ZBlogPostActionContext(self, docIDO, blogId)
        provider = ZModelBasedMenuContentProvider(self.blogPostContextMenu,
                                                  actionContext)
        handler = ZModelBasedMenuEventHandler(self.blogPostContextMenu,
                                              actionContext)
        menu = ZMenu(self, self.blogPostContextMenu.getRootNode(), provider,
                     handler)
        self.PopupMenu(menu)
        event.Skip()

    # end onEntryRightClick()

    def onEntryActivated(self, event):
        index = event.GetIndex()
        docIDO = self.model.getEntry(index)
        blogId = None
        if self.blog is not None:
            blogId = self.blog.getId()
        actionContext = ZBlogPostActionContext(self, docIDO, blogId)
        self.openAction.runAction(actionContext)
        event.Skip()

    # end onEntryActivated()

    def onEntrySelected(self, event):
        index = event.GetIndex()
        docIDO = self.model.getEntry(index)
        docId = docIDO.getId()
        self.document = self.docStore.getDocument(docId)

        if self.document:
            fireViewSelectionEvent(
                ZDocumentSelection(self.document, self.blog), self)
        else:
            fireViewUnselectionEvent()

        event.Skip()

    # end onEntrySelected()

    def onInvalidSelection(self):
        self.document = None

    # end onInvalidSelection()

    def createActionContext(self):
        docIDO = None
        blogId = None
        selection = self.entriesListView.getSelection()
        if selection:
            index = selection[0]
            docIDO = self.model.getEntry(index)
            if self.blog is not None:
                blogId = self.blog.getId()
        return ZBlogPostActionContext(self, docIDO, blogId)

    # end createActionContext()

    def destroy(self):
        self._unregisterAsIndexListener()

    # end destroy()

    def _getViewChoices(self):
        return [
            _extstr(u"postsview.All"),  #$NON-NLS-1$
            _extstr(u"postsview.Drafts"),  #$NON-NLS-1$
            _extstr(u"postsview.Published"),  #$NON-NLS-1$
            _extstr(u"postsview.Today"),  #$NON-NLS-1$
            u"-----------",  #$NON-NLS-1$
            _extstr(u"postsview.Yesterday"),  #$NON-NLS-1$
            _extstr(u"postsview.ThisWeek"),  #$NON-NLS-1$
            _extstr(u"postsview.ThisMonth")  #$NON-NLS-1$
        ]

    # end _getViewChoices()

    def _getSearchBoxChoices(self):
        return [
            (_extstr(u"postsview.Title"), None, SEARCH_TB_TITLE),  #$NON-NLS-1$
        ]

    # end _getSearchBoxChoices()

    def _getUrlFromDocIDO(self, docIDO):
        url = None
        if self.blog is not None:
            pdIDO = docIDO.getPubDataIDO(self.blog.getId())
            if pdIDO is not None:
                url = pdIDO.getUrl()
        return url

    # end _getUrlFromDocIDO()

    def _registerAsIndexListener(self):
        self.indexService.addListener(self)

    # end _registerAsIndexListener()

    def _unregisterAsIndexListener(self):
        self.indexService.removeListener(self)
示例#9
0
class ZLinkBlogPostDetailsPanel(ZAbstractDetailsPanel):

    def __init__(self, parent):
        self.selectedLink = None
        self.document = None
        # FIXME (EPW) need to update the value of self.blog in onSelectionChanged()
        self.blog = None
        self.linkContentProvider = ZLinkListViewContentProvider()

        ZAbstractDetailsPanel.__init__(self, parent)
    # end __init__()

    def _createWidgets(self):
        style = wx.LC_VIRTUAL | wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_HRULES | wx.NO_BORDER
        self.linkListView = ZListViewEx(self.linkContentProvider, self, style = style)
    # end _createWidgets()

    def _bindWidgetEvents(self):
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onSelected, self.linkListView)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onActivated, self.linkListView)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onRightClick, self.linkListView)

        wx.EVT_SET_FOCUS(self.linkListView, self.onFocus)
        wx.EVT_KILL_FOCUS(self.linkListView, self.onUnFocus)
    # end _bindWidgetEvents()

    def _layoutWidgets(self):
        linkSBSizer = wx.BoxSizer(wx.HORIZONTAL)
        linkSBSizer.Add(self.linkListView, 1, wx.EXPAND)

        box = wx.BoxSizer(wx.VERTICAL)
        box.AddSizer(linkSBSizer, 1, wx.EXPAND)
        self.SetAutoLayout(True)
        self.SetSizer(box)
    # end _layoutWidgets()

    def onSelectionChanged(self, document):
        self.document = document
        self.selectedLink = None
        self.linkContentProvider.setDocument(document)
        self.linkListView.refresh()
    # end onSelectionChanged()

    def onSelected(self, event):
        link = self.linkContentProvider.getLink(event.GetIndex())
        self.selectedLink = link
        self._fireLinkSelectionEvent(link)
        event.Skip()
    # end onSelected()

    def onActivated(self, event):
        url = self.linkListView.GetItemText(event.GetIndex())
        if url:
            context = ZLinkActionContext(self, url)
            openLinkAction = getApplicationModel().getActionRegistry().findAction(IZAppActionIDs.OPEN_LINK_ACTION)
            openLinkAction.runAction(context)
        event.Skip
    # end onActivated()

    def onRightClick(self, event):
        url = self.linkListView.GetItemText(event.GetIndex())
        if url:
            context = ZLinkActionContext(self, url)
            menuModel = ZLinkMenuModel()
            menu = ZModelBasedMenu(menuModel, context, self)
            self.PopupMenu(menu)
            menu.Destroy()
        event.Skip()
    # end onRightClick()

    def onFocus(self, event):
        self._fireLinkSelectionEvent(self.selectedLink)
        event.Skip()
    # end onFocus()

    def onUnFocus(self, event):
        fireViewUnselectionEvent()
        event.Skip()
    # end onUnFocus()

    def _fireLinkSelectionEvent(self, link):
        if link:
            linkIDO = ZLinkIDO(None, self.document.getId(), link.getHref())
            linkSelection = ZLinkSelection(linkIDO, self.blog)
            fireViewSelectionEvent(linkSelection, None)
示例#10
0
class ZBlogBrowseView(ZView, IZAccountStoreListener):

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

        self._createWidgets()
        self._layoutWidgets()
        self._populateWidgets()
        self._bindWidgetEvents()

        self._registerAsAccountListener()
    # end __init__()

    def _createWidgets(self):
        self.blogListProvider = ZBlogListProvider()
        self.blogListView = ZListViewEx(self.blogListProvider, self)
    # end _createWidgets()

    def _layoutWidgets(self):
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.blogListView, 1, wx.EXPAND)

        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        self.Layout()
    # end _layoutWidgets()

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

    def _bindWidgetEvents(self):
        self.Bind(ZEVT_VIEW_SELECTION_CHANGED, self.onViewSelection)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onBlogSelected, self.blogListView)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onBlogRightClick, self.blogListView)
        self._bindRefreshEvent(self.onZoundryRefresh)
    # end _bindWidgetEvents()

    def onBlogRightClick(self, event):
        blog = self._getSelectedBlog()
        if blog is not None:
            menu = self._createBlogCtxMenu(blog)
            self.PopupMenu(menu)
            menu.Destroy()
        event.Skip()
    # end onBlogRightClick()

    def _createBlogCtxMenu(self, blog):
        menuContext = ZBlogMenuActionContext(self, blog)
        menuModel = ZBlogMenuModel()
        provider = ZModelBasedMenuContentProvider(menuModel, menuContext)
        eventHandler = ZModelBasedMenuEventHandler(menuModel, menuContext)
        return ZMenu(self, menuModel.getRootNode(), provider, eventHandler)
    # end _createBlogCtxMenu()

    def onViewSelection(self, event):
        selection = event.getSelection()
        if selection.getType() == IZViewSelectionTypes.ACCOUNT_SELECTION:
            accountId = selection.getData()
            self.blogListProvider.setAccountId(accountId)
            self.blogListProvider.refresh()
            self.blogListView.refresh()
            self.blogListView.deselectAll()
        elif selection.getType() == IZViewSelectionTypes.UNPUBLISHED_ACCOUNT_SELECTION:
            self.blogListProvider.setAccountId(None)
            self.blogListProvider.refresh()
            self.blogListView.refresh()
            self.blogListView.deselectAll()

        event.Skip()
    # end onViewSelection()

    def onBlogSelected(self, event):
        blog = self._getSelectedBlog()
        if blog is not None:
            account = blog.getAccount()
            accountId = account.getId()
            blogId = blog.getId()
            selection = ZViewSelection(IZViewSelectionTypes.BLOG_SELECTION, (accountId, blogId))
            fireViewSelectionEvent(selection, self)
        else:
            fireViewUnselectionEvent()
        event.Skip()
    # end onBlogSelected()

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

    def onAccountChanged(self, account):
        if account.getId() == self.blogListProvider.getAccountId():
            self.blogListProvider.refresh()
            fireRefreshEvent(self)
    # end onAccountChanged()

    def onAccountDeleted(self, account):
        if account.getId() == self.blogListProvider.getAccountId():
            self.blogListProvider.setAccountId(None)
            self.blogListProvider.refresh()
            fireRefreshEvent(self)
    # end onAccountDeleted()

    def _registerAsAccountListener(self):
        accountStore = getApplicationModel().getService(IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
        accountStore.addListener(self)
    # end _registerAsAccountListener()

    def _unregisterAsAccountListener(self):
        accountStore = getApplicationModel().getService(IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
        accountStore.removeListener(self)
    # end _unregisterAsAccountListener()

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

    def _getSelectedBlog(self):
        itemIndexes = self.blogListView.getSelection()
        if itemIndexes:
            itemIndex = itemIndexes[0]
            return self.blogListProvider.getBlogAtIndex(itemIndex)
        return None
示例#11
0
class ZTranslationEditor(ZHeaderDialog, ZPersistentDialogMixin):
    def __init__(self, parent, translation, defaultTranslation,
                 translationDisplayName):
        self.translationDisplayName = translationDisplayName
        self.model = ZTranslationEditorModel(translation, defaultTranslation)
        style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER

        ZHeaderDialog.__init__(self,
                               parent,
                               wx.ID_ANY,
                               _extstr(u"translationeditor.EditTranslation_") %
                               translationDisplayName,
                               style=style)  #$NON-NLS-1$
        ZPersistentDialogMixin.__init__(
            self, IZBlogAppUserPrefsKeys.TRANSLATION_DIALOG, True, True)

        self.selectedKey = None
        self.selectedValue = None

    # end __init__()

    def GetBestSize(self):
        return wx.Size(600, 500)

    # end GetBestSize()

    def _createNonHeaderWidgets(self):
        self.showOnlyCB = wx.CheckBox(
            self, wx.ID_ANY,
            _extstr(u"translationeditor.ShowOnlyUntranslated"))  #$NON-NLS-1$
        self.listProvider = ZStringBundleProvider(self.model)
        self.listBox = ZListViewEx(self.listProvider, self, wx.ID_ANY)
        bitmap = getFlagBitmapForLocale(u"en_US")  #$NON-NLS-1$
        self.englishFlag = ZStaticBitmap(self, bitmap)
        self.englishLabel = wx.StaticText(
            self, wx.ID_ANY,
            _extstr(u"translationeditor.EnglishValue"))  #$NON-NLS-1$
        bitmap = getFlagBitmapForLocale(
            self.model.getTranslation().getLocale().toString())
        if bitmap is None:
            bitmap = getEmptyFlagBitmap()
        self.translationFlag = ZStaticBitmap(self, bitmap)
        self.translationLabel = wx.StaticText(self, wx.ID_ANY,
                                              self.translationDisplayName)
        self.englishText = wx.TextCtrl(self,
                                       wx.ID_ANY,
                                       style=wx.TE_MULTILINE | wx.TE_READONLY
                                       | wx.TE_BESTWRAP)
        self.translationText = wx.TextCtrl(
            self,
            wx.ID_ANY,
            style=wx.TE_MULTILINE | wx.TE_BESTWRAP | wx.TE_PROCESS_ENTER)

        self.translationText.Enable(False)

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

    # end _createNonHeaderWidgets()

    def _populateNonHeaderWidgets(self):
        self.showOnlyCB.SetValue(False)

    # end _populateNonHeaderWidgets()

    def _layoutNonHeaderWidgets(self):
        englishSizer = wx.BoxSizer(wx.HORIZONTAL)
        englishSizer.Add(self.englishFlag, 0, wx.ALL | wx.EXPAND, 2)
        englishSizer.Add(self.englishLabel, 1, wx.ALL | wx.EXPAND, 2)
        translationSizer = wx.BoxSizer(wx.HORIZONTAL)
        translationSizer.Add(self.translationFlag, 0, wx.ALL | wx.EXPAND, 2)
        translationSizer.Add(self.translationLabel, 1, wx.ALL | wx.EXPAND, 2)
        labelSizer = wx.BoxSizer(wx.HORIZONTAL)
        labelSizer.AddSizer(englishSizer, 1, wx.EXPAND)
        labelSizer.AddSizer(translationSizer, 1, wx.EXPAND)

        valueSizer = wx.BoxSizer(wx.HORIZONTAL)
        valueSizer.Add(self.englishText, 1, wx.ALL | wx.EXPAND, 2)
        valueSizer.Add(self.translationText, 1, wx.ALL | wx.EXPAND, 2)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.showOnlyCB, 0, wx.ALL | wx.EXPAND, 3)
        sizer.Add(self.listBox, 2, wx.ALL | wx.EXPAND, 3)
        sizer.AddSizer(labelSizer, 0, wx.ALL | wx.EXPAND, 1)
        sizer.AddSizer(valueSizer, 1, wx.ALL | wx.EXPAND, 1)
        sizer.Add(self.staticLine, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 2)
        return sizer

    # end _layoutNonHeaderWidgets()

    def _getHeaderTitle(self):
        return _extstr(u"translationeditor.TranslationEditor")  #$NON-NLS-1$

    # end _getHeaderTitle()

    def _getHeaderMessage(self):
        return _extstr(u"translationeditor.UseThisDialogMsg")  #$NON-NLS-1$

    # end _getHeaderMessage()

    def _getHeaderImagePath(self):
        return u"images/dialogs/translation/editor/header.png"  #$NON-NLS-1$

    # end _getHeaderImagePath()

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

    # end _getHeaderHelpUrl()

    def _bindWidgetEvents(self):
        self._bindOkButton(self.onSave)
        self._bindCancelButton(self.onCancel)
        self.Bind(wx.EVT_CHECKBOX, self.onShowOnly, self.showOnlyCB)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onListSelection,
                  self.listBox)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onListActivation,
                  self.listBox)
        self.Bind(wx.EVT_TEXT_ENTER, self.onTranslationActivation,
                  self.translationText)

        wx.EVT_KILL_FOCUS(self.translationText, self.onTranslationUnfocus)

    # end _bindWidgetEvents()

    def _setInitialFocus(self):
        self.listBox.SetFocus()

    # end _setInitialFocus()

    def _getOKButtonLabel(self):
        return _extstr(u"translationeditor.Save")  #$NON-NLS-1$

    # end _getOKButtonLabel()

    def onSave(self, event):
        wx.BusyCursor()
        self.model.save()
        event.Skip()

    # end onSave()

    def onCancel(self, event):
        if self.model.isDirty() and ZShowYesNoMessage(
                self, _extstr(u"translationeditor.CancelTranslationMessage"),
                _extstr(u"translationeditor.CancelTranslationTitle")
        ):  #$NON-NLS-2$ #$NON-NLS-1$
            self.model.getTranslation().clear()
            event.Skip()
        elif not self.model.isDirty():
            event.Skip()

    # end onCancel()

    def onListSelection(self, event):
        self._doListSelection()
        event.Skip()

    # end onListSelection()

    def onShowOnly(self, event):
        self.model.setShowOnlyUntranslated(event.IsChecked())
        self.listBox.refresh()
        event.Skip()

    # end onShowOnly()

    def onTranslationUnfocus(self, event):
        value = self.translationText.GetValue()
        # if there is a selection, and the value has changed
        if self.selectedKey is not None and value != self.selectedValue:
            value = getSafeString(value).strip()
            self.model.setTranslationValue(self.selectedKey, value)
            self.listBox.refresh()
        self.translationText.Enable(False)
        event.Skip()

    # end onTranslationUnfocus()

    def onListActivation(self, event):
        self._doListSelection()
        self.translationText.Enable(True)
        self.translationText.SetFocus()
        event.Skip()

    # end onListActivation()

    def onTranslationActivation(self, event):
        self.listBox.SetFocus()
        selectionIdx = self.listBox.getSelection()[0]
        if not self.showOnlyCB.IsChecked():
            selectionIdx = selectionIdx + 1
        self.listBox.Select(selectionIdx, True)
        self._doListSelection()
        event.Skip()

    # end onTranslationActivation()

    def _doListSelection(self):
        selectionIdx = self.listBox.getSelection()[0]
        self.selectedKey = self.model.getKeys()[selectionIdx]
        defValue = self.model.getDefaultValue(self.selectedKey)
        transValue = self.model.getTranslationValue(self.selectedKey)
        self.selectedValue = getSafeString(transValue).strip()

        self.englishText.SetValue(defValue)
        self.translationText.SetValue(self.selectedValue)
示例#12
0
class ZTranslationManagerWindow(ZBaseWindow, ZPersistentDialogMixin):
    def __init__(self, parent):
        self.model = ZTranslationManagerModel()
        self.selectedTranslation = None

        style = wx.DEFAULT_FRAME_STYLE | wx.FULL_REPAINT_ON_RESIZE | wx.CLIP_CHILDREN
        ZBaseWindow.__init__(self,
                             parent,
                             _extstr(u"translationmanager.TranslationManager"),
                             style=style)  #$NON-NLS-1$
        ZPersistentDialogMixin.__init__(
            self, IZBlogAppUserPrefsKeys.TRANSLATION_WINDOW)
        self.Layout()

    # 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.bodyPanel = wx.Panel(parent, wx.ID_ANY)

        self.staticBox = wx.StaticBox(
            self.bodyPanel, wx.ID_ANY,
            _extstr(u"translationmanager.Translations"))  #$NON-NLS-1$

        self.translationProvider = ZTranslationListProvider(self.model)
        self.translationList = ZListViewEx(self.translationProvider,
                                           self.bodyPanel)
        self.translationList.SetMinSize(wx.Size(300, 200))

        self.newButton = wx.Button(
            self.bodyPanel, wx.ID_ANY,
            _extstr(u"translationmanager.New"))  #$NON-NLS-1$
        self.editButton = wx.Button(
            self.bodyPanel, wx.ID_ANY,
            _extstr(u"translationmanager.Edit"))  #$NON-NLS-1$
        self.editButton.Enable(False)

        self.staticLine = wx.StaticLine(self.bodyPanel, wx.ID_ANY)

    # 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 _populateWindowWidgets(self):
        self.SetIcons(getResourceRegistry().getIconBundle(ICON_IMAGES))
        self.refresh()

    # end _populateWindowWidgets()

    def _layoutWindowWidgets(self):
        staticBoxSizer = wx.StaticBoxSizer(self.staticBox, wx.VERTICAL)

        buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
        buttonSizer.Add(self.newButton, 0, wx.ALL | wx.EXPAND, 2)
        buttonSizer.Add(self.editButton, 0, wx.ALL | wx.EXPAND, 2)

        staticBoxSizer.Add(self.translationList, 1, wx.ALL | wx.EXPAND, 3)
        staticBoxSizer.AddSizer(buttonSizer, 0, wx.ALL | wx.EXPAND, 2)

        self.bodyPanel.SetSizer(staticBoxSizer)
        self.bodyPanel.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.bodyPanel, 1, wx.EXPAND | wx.ALL, 5)

        return sizer

    # end _layoutWindowWidgets()

    def _bindWidgetEvents(self):
        self.Bind(wx.EVT_BUTTON, self.onAdd, self.newButton)
        self.Bind(wx.EVT_BUTTON, self.onEdit, self.editButton)
        self.Bind(wx.EVT_CLOSE, self.onClose, self)
        self.Bind(ZEVT_REFRESH, self.onRefresh, self)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onTranslationSelected,
                  self.translationList)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onEdit,
                  self.translationList)

    # end _bindWidgetEvents()

    def onRefresh(self, event):
        self.translationList.Refresh()
        event.Skip()

    # end onRefresh()

    def onAdd(self, event):
        dialog = ZNewTranslationDialog(self, self.model)
        result = dialog.ShowModal()
        if result == wx.ID_OK:
            busyIndicator = wx.BusyCursor()
            localeStr = dialog.getData()
            translation = self.model.createNewTranslation(localeStr)
            self.translationProvider.updateImageList()
            self.translationList.refresh()
            translationName = self.model.getNameForLocale(
                translation.getLocale())
            editor = ZTranslationEditor(self, translation,
                                        self.model.getDefaultTranslation(),
                                        translationName)
            del busyIndicator
            editor.ShowModal()
        self.refresh()
        event.Skip()

    # end onAdd()

    def onEdit(self, event):
        busyIndicator = wx.BusyCursor()
        idx = self.translationList.getSelection()[0]
        translation = self.model.getTranslations()[idx]
        translation.load()
        translationName = self.model.getNameForLocale(translation.getLocale())
        editor = ZTranslationEditor(self, translation,
                                    self.model.getDefaultTranslation(),
                                    translationName)
        del busyIndicator
        editor.ShowModal()
        event.Skip()

    # end onEdit()

    def onTranslationSelected(self, event):
        self.selectedTranslation = self.model.getTranslations()[
            event.GetItem().GetId()]
        self.editButton.Enable(True)
        self.refresh()
        event.Skip()

    # end onTranslationSelected()

    def _setInitialFocus(self):
        pass

    # end _setInitialFocus()

    def refresh(self):
        self.translationList.refresh()

    # end refresh()

    def _getHeaderTitle(self):
        return _extstr(u"translationmanager.TranslationManager")  #$NON-NLS-1$

    # end _getHeaderTitle()

    def _getHeaderMessage(self):
        return _extstr(u"translationmanager.UseThisWindowMsg")  #$NON-NLS-1$

    # end _getHeaderMessage()

    def _getHeaderImagePath(self):
        return u"images/dialogs/translation/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 TRANSLATION_MANAGER_WINDOW
        TRANSLATION_MANAGER_WINDOW = None
        event.Skip()
示例#13
0
class ZBlogPostsView(ZBoxedView, IZDocumentIndexListener):

    def __init__(self, parent):
        filter = ZDocumentSearchFilter()
        filter.setAccountIdCriteria(IZDocumentSearchFilter.UNPUBLISHED_ACCOUNT_ID)
        filter.setBlogIdCriteria(IZDocumentSearchFilter.UNPUBLISHED_BLOG_ID)
        self.model = ZContextInfoPostsModel(filter)
        self.openAction = getApplicationModel().getActionRegistry().findAction(IZBlogAppActionIDs.OPEN_BLOG_POST_ACTION)
        self.blogPostContextMenu = ZBlogPostMenuModel()
        self.postsAccelTable = ZBlogPostsListAcceleratorTable(self)
        self.document = None
        self.blog = None
        self.hasFocus = False

        self.indexService = getApplicationModel().getService(IZBlogAppServiceIDs.DOCUMENT_INDEX_SERVICE_ID)
        self.docStore = getApplicationModel().getService(IZBlogAppServiceIDs.DATA_STORE_SERVICE_ID)
        self.accountStore = getApplicationModel().getService(IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)

        ZBoxedView.__init__(self, parent)

        self._registerAsIndexListener()
    # end __init__()

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

    def _getHeaderBitmap(self):
        return getResourceRegistry().getBitmap(u"images/perspectives/standard/posts.png") #$NON-NLS-1$
    # end _getHeaderBitmap()

    def _getHeaderLabel(self):
        return _extstr(u"postsview.BlogPosts") #$NON-NLS-1$
    # end _getHeaderLabel()

    def _createHeaderWidgets(self, parent, widgetList):
        self.viewLabel = wx.StaticText(parent, wx.ID_ANY, _extstr(u"postsview.Filter")) #$NON-NLS-1$
        choices = self._getViewChoices()
        self.viewCombo = wx.ComboBox(parent, wx.ID_ANY, _extstr(u"postsview.All"), style = wx.CB_READONLY, choices = choices) #$NON-NLS-1$
        choices = self._getSearchBoxChoices()
        bitmap = getResourceRegistry().getBitmap(u"images/perspectives/standard/contextinfo/postsview/search.png") #$NON-NLS-1$
        self.searchTextBox = ZAdvancedTextBox(parent, bitmap, choices, False)
        self.searchTextBox.setCurrentChoice(SEARCH_TB_TITLE)
        self.searchTextBox.SetSizeHints(220, -1)

        widgetList.append(self.viewLabel)
        widgetList.append(self.viewCombo)
        widgetList.append(self.searchTextBox)
    # end _createHeaderWidgets()

    def _createContentWidgets(self, parent):
        provider = ZBlogEntryListContentProvider(self.model)
        style = wx.LC_VIRTUAL | wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.NO_BORDER
        self.entriesListView = ZListViewEx(provider, parent, style = style)
        self.entriesListView.SetAcceleratorTable(self.postsAccelTable)
    # end _createContentWidgets()

    def _layoutContentWidgets(self):
        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.entriesListView, 1, wx.EXPAND)
        return box
    # end _layoutContentWidgets()

    def _bindWidgetEvents(self):
        ZBoxedView._bindWidgetEvents(self)

        self.postsAccelTable.bindTo(self.entriesListView)

        self.Bind(ZEVT_REFRESH, self.onZoundryRefresh, self)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onEntryActivated, self.entriesListView)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onEntrySelected, self.entriesListView)
        self.Bind(wx.EVT_LIST_BEGIN_DRAG, self.onEntryBeginDrag, self.entriesListView)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onEntryRightClick, self.entriesListView)
        self.Bind(wx.EVT_COMBOBOX, self.onViewCombo, self.viewCombo)
        self.Bind(wx.EVT_TEXT_ENTER, self.onSearchText, self.searchTextBox)
        self.Bind(ZEVT_VIEW_SELECTION_CHANGED, self.onViewSelectionChanged)
        wx.EVT_SET_FOCUS(self.entriesListView, self.onFocus)
        wx.EVT_KILL_FOCUS(self.entriesListView, self.onUnFocus)
    # end _bindWidgetEvents()

    def refreshContent(self, selection):
        isUnselecting = False
        if self.entriesListView.getSelection():
            isUnselecting = True

        (accountId, blogId) = selection.getData()

        filter = ZDocumentSearchFilter()
        if blogId is not None:
            account = self.accountStore.getAccountById(accountId)
            self.blog = account.getBlogById(blogId)
            filter.setAccountIdCriteria(accountId)
            filter.setBlogIdCriteria(blogId)
        else:
            self.blog = None
            filter.setAccountIdCriteria(IZDocumentSearchFilter.UNPUBLISHED_ACCOUNT_ID)
            filter.setBlogIdCriteria(IZDocumentSearchFilter.UNPUBLISHED_BLOG_ID)

        self.model = ZContextInfoPostsModel(filter)
        self.entriesListView.setContentProvider(ZBlogEntryListContentProvider(self.model))
        self.entriesListView.refresh()
        self.entriesListView.deselectAll()
        self.onInvalidSelection()
        if isUnselecting:
            fireViewUnselectionEvent()
    # end refreshContent()

    def onViewSelectionChanged(self, event):
        if event.getSelection().getType() == IZViewSelectionTypes.BLOG_POSTS_SELECTION:
            self.refreshContent(event.getSelection())
        event.Skip()
    # end onViewSelectionChanged()

    def onFocus(self, event):
        if not self.hasFocus:
            if self.document:
                fireViewSelectionEvent(ZDocumentSelection(self.document, self.blog), self)
            else:
                fireViewUnselectionEvent()
            self.hasFocus = True
        event.Skip()
    # end onFocus()

    def onUnFocus(self, event):
        if self.hasFocus:
            fireViewUnselectionEvent()
            self.hasFocus = False
        event.Skip()
    # end onUnFocus()

    def onViewCombo(self, event):
        choice = event.GetSelection()
        self.model.clearDraftCriteria()
        self.model.clearDateRangeCriteria()
        if choice == VIEW_CHOICE_DRAFTS:
            self.model.setDraftCriteria()
        elif choice == VIEW_CHOICE_PUBLISHED:
            self.model.setDraftCriteria(False)
        elif choice == VIEW_CHOICE_TODAY:
            dateRange = getRangeForToday()
            self.model.setDateRangeCriteria(dateRange.getStartDate(), dateRange.getEndDate())
        elif choice == VIEW_CHOICE_YESTERDAY:
            dateRange = getRangeForYesterday()
            self.model.setDateRangeCriteria(dateRange.getStartDate(), dateRange.getEndDate())
        elif choice == VIEW_CHOICE_THISWEEK:
            dateRange = getRangeForThisWeek()
            self.model.setDateRangeCriteria(dateRange.getStartDate(), dateRange.getEndDate())
        elif choice == VIEW_CHOICE_THISMONTH:
            dateRange = getRangeForThisMonth()
            self.model.setDateRangeCriteria(dateRange.getStartDate(), dateRange.getEndDate())
        self.model.refresh()
        self.entriesListView.refresh()
        self.entriesListView.deselectAll()
        self.onInvalidSelection()

        fireViewEvent(ZViewEvent(VIEWBLOGPOSTSFILTERCHANGEDEVENT, self))
        event.Skip()
    # end onViewCombo()

    def onSearchText(self, event):
        self.model.setTitleCriteria(event.GetString())
        self.model.refresh()
        self.entriesListView.refresh()
        self.entriesListView.deselectAll()
        self.onInvalidSelection()

        fireViewEvent(ZViewEvent(VIEWBLOGPOSTSFILTERCHANGEDEVENT, self))
        event.Skip()
    # end onSearchText()

    def onEntryBeginDrag(self, event):
        index = event.GetIndex()
        docIDO = self.model.getEntry(index)
        docId = docIDO.getId()

        # FIXME (EPW) also add some sort of custom format for dragging to the Explorer/TextPad (use a composite data object)
        data = wx.DataObjectComposite()
#        url = self._getUrlFromDocIDO(docIDO)
#        if url is not None:
#            data.Add(ZURLDataObject(url))
        data.Add(ZBlogPostDataObjectInternal(docId))
#        data.Add(wx.TextDataObject(str(convertToUtf8(u"Hello World"))))

        dragSource = wx.DropSource(self)
        dragSource.SetData(data)
        dragSource.DoDragDrop(wx.Drag_CopyOnly)
        event.Skip()
    # end onEntryBeginDrag()

    def _updateModel(self, refreshData):
        (eventType, documentIDO) = refreshData
        shouldRefresh = False
        if eventType == IZDocIndexEvent.DOCINDEX_EVENTTYPE_ADD:
            shouldRefresh = self.model.addEntry(documentIDO)
        elif eventType == IZDocIndexEvent.DOCINDEX_EVENTTYPE_REMOVE:
            shouldRefresh = self.model.removeEntry(documentIDO)
        elif eventType == IZDocIndexEvent.DOCINDEX_EVENTTYPE_UPDATE:
            shouldRefresh = self.model.updateEntry(documentIDO)
        return shouldRefresh
    # end _updateModel()

    # This is the only method that can happen on a non-UI thread.  It will
    # gather up the needed data, then fire a "refresh ui" event.  That event
    # will get picked up by the UI thread and the view will refresh.
    def onIndexChange(self, event):
        if event.getDataType() == IZDocIndexEvent.DOCINDEX_DATATYPE_DOCUMENT:
            refreshData = (event.getEventType(), event.getDocumentIDO())
            fireRefreshEvent(self, refreshData)
    # end onIndexChange()

    def onZoundryRefresh(self, event): #@UnusedVariable
        if self._updateModel(event.getData()):
            self.entriesListView.refresh()
            selection = self.entriesListView.getSelection()
            if not selection:
                self.onInvalidSelection()
                fireViewUnselectionEvent()
            else:
                selIdx = selection[0]
                newDocIDO = self.model.getEntry(selIdx)
                newDoc = self.docStore.getDocument(newDocIDO.getId())
                self.document = newDoc
                fireViewSelectionEvent(ZDocumentSelection(self.document, self.blog), self)
        event.Skip()
    # end onZoundryRefresh()

    def onEntryRightClick(self, event):
        index = event.GetIndex()
        docIDO = self.model.getEntry(index)
        blogId = None
        if self.blog is not None:
            blogId = self.blog.getId()
        actionContext = ZBlogPostActionContext(self, docIDO, blogId)
        provider = ZModelBasedMenuContentProvider(self.blogPostContextMenu, actionContext)
        handler = ZModelBasedMenuEventHandler(self.blogPostContextMenu, actionContext)
        menu = ZMenu(self, self.blogPostContextMenu.getRootNode(), provider, handler)
        self.PopupMenu(menu)
        event.Skip()
    # end onEntryRightClick()

    def onEntryActivated(self, event):
        index = event.GetIndex()
        docIDO = self.model.getEntry(index)
        blogId = None
        if self.blog is not None:
            blogId = self.blog.getId()
        actionContext = ZBlogPostActionContext(self, docIDO, blogId)
        self.openAction.runAction(actionContext)
        event.Skip()
    # end onEntryActivated()

    def onEntrySelected(self, event):
        index = event.GetIndex()
        docIDO = self.model.getEntry(index)
        docId = docIDO.getId()
        self.document = self.docStore.getDocument(docId)

        if self.document:
            fireViewSelectionEvent(ZDocumentSelection(self.document, self.blog), self)
        else:
            fireViewUnselectionEvent()

        event.Skip()
    # end onEntrySelected()

    def onInvalidSelection(self):
        self.document = None
    # end onInvalidSelection()

    def createActionContext(self):
        docIDO = None
        blogId = None
        selection = self.entriesListView.getSelection()
        if selection:
            index = selection[0]
            docIDO = self.model.getEntry(index)
            if self.blog is not None:
                blogId = self.blog.getId()
        return ZBlogPostActionContext(self, docIDO, blogId)
    # end createActionContext()

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

    def _getViewChoices(self):
        return [
                _extstr(u"postsview.All"), #$NON-NLS-1$
                _extstr(u"postsview.Drafts"), #$NON-NLS-1$
                _extstr(u"postsview.Published"), #$NON-NLS-1$
                _extstr(u"postsview.Today"), #$NON-NLS-1$
                u"-----------", #$NON-NLS-1$
                _extstr(u"postsview.Yesterday"), #$NON-NLS-1$
                _extstr(u"postsview.ThisWeek"), #$NON-NLS-1$
                _extstr(u"postsview.ThisMonth") #$NON-NLS-1$
        ]
    # end _getViewChoices()

    def _getSearchBoxChoices(self):
        return [
                (_extstr(u"postsview.Title"), None, SEARCH_TB_TITLE), #$NON-NLS-1$
        ]
    # end _getSearchBoxChoices()

    def _getUrlFromDocIDO(self, docIDO):
        url = None
        if self.blog is not None:
            pdIDO = docIDO.getPubDataIDO(self.blog.getId())
            if pdIDO is not None:
                url = pdIDO.getUrl()
        return url
    # end _getUrlFromDocIDO()

    def _registerAsIndexListener(self):
        self.indexService.addListener(self)
    # end _registerAsIndexListener()

    def _unregisterAsIndexListener(self):
        self.indexService.removeListener(self)
示例#14
0
class ZMediaStorageManagerDialog(ZHeaderDialog, ZPersistentDialogMixin):

    def __init__(self, parent):
        self.model = ZMediaStorageManagerModel()
        self.model.getService().addListener(self)
        ZHeaderDialog.__init__(self, parent, wx.ID_ANY, _extstr(u"mediastoragedialog.DialogTitle"), style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, name = u"ZMediaStorageManagerDialog") #$NON-NLS-2$ #$NON-NLS-1$

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

        ZPersistentDialogMixin.__init__(self, IZAppUserPrefsKeys.MEDIA_STORE_MANAGER_DIALOG)

        self.Layout()
    # end __init__()

    def _createNonHeaderWidgets(self):
        self.staticBox = wx.StaticBox(self, wx.ID_ANY, _extstr(u"mediastoragedialog.MediaStorages")) #$NON-NLS-1$
        provider = ZMediaStorageListContentProvider(self.model)
        self.storageListBox = ZListViewEx(provider, self)
        self.storageListBox.SetSizeHints(-1, 225)
        self.addButton = wx.Button(self, wx.ID_ANY, _extstr(u"mediastoragedialog.NewStore")) #$NON-NLS-1$
    # end _createNonHeaderWidgets()

    def _populateNonHeaderWidgets(self):
        u"Called to populate the non header related widgets.  (abstract)" #$NON-NLS-1$
    # end _populateNonHeaderWidgets()

    def _layoutNonHeaderWidgets(self):
        sizer = wx.StaticBoxSizer(self.staticBox, wx.VERTICAL)
        sizer.Add(self.storageListBox, 1, wx.EXPAND | wx.ALL, 5)
        sizer.Add(self.addButton, 0, wx.LEFT | wx.BOTTOM, 5)

        return sizer
    # end _layoutNonHeaderWidgets()

    def _bindWidgetEvents(self):
        self._bindCancelButton(self.onCancel)

        self.Bind(wx.EVT_BUTTON, self.onNewStore, self.addButton)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onEdit, self.storageListBox)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onSelection, self.storageListBox)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onItemRightClick, self.storageListBox)
        self.Bind(wx.EVT_LIST_KEY_DOWN, self.onKeyPress, self.storageListBox)
    # end _bindWidgetEvents()

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

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

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

    def onEdit(self, event):
        actionContext = self._createMenuActionContext()
        action = ZEditMediaStorageMenuAction()
        action.runAction(actionContext)
        event.Skip()
    # end onEdit()

    def onCancel(self, event):
        self.model.getService().removeListener(self)
        event.Skip()
    # end onCancel()

    def onSelection(self, event):
        self.currentIndex = event.GetIndex()
        event.Skip()
    # end onSelection

    def onKeyPress(self, event):
        if event.GetKeyCode() == wx.WXK_DELETE:
            actionContext = self._createMenuActionContext()
            action = ZDeleteMediaStorageMenuAction()
            action.runAction(actionContext)
        event.Skip()
    # end onKeyPress()

    def onNewStore(self, event):
        ZMediaStorageUtil().createNewMediaStorage(self)
        event.Skip()
    # end onNewStore()

    def onItemRightClick(self, event):
        storage = self._getSelectedStore()
        if storage:
            siteId = storage.getMediaSiteId()
            site = self.model.getService().getMediaSite(siteId)
            if site and site.isInternal():
                event.Skip()
                return
        menu = self._createItemContextMenu()
        self.PopupMenu(menu)
        menu.Destroy()
        event.Skip()
    # end onItemRightClick()

    def onMediaStorageAdded(self, mediaStore): #@UnusedVariable
        self.model.refresh()
        self.storageListBox.refresh()
    # end onMediaStorageAdded()

    def onMediaStorageRemoved(self, mediaStore): #@UnusedVariable
        self.model.refresh()
        self.storageListBox.refresh()
    # end onMediaStorageRemoved() #$NON-NLS-1$

    def _getSelectedStore(self):
        return self.model.getMediaStorages()[self.currentIndex]
    # end _getSelectedStore()

    def _createItemContextMenu(self):
        menuContext = self._createMenuActionContext()
        menuModel = ZPluginMenuModel(u"zoundry.blogapp.ui.core.menu.dialogs.mediastoragemanager.mediastorage") #$NON-NLS-1$
        provider = ZModelBasedMenuContentProvider(menuModel, menuContext)
        eventHandler = ZModelBasedMenuEventHandler(menuModel, menuContext)
        return ZMenu(self, menuModel.getRootNode(), provider, eventHandler)
    # end _createItemContextMenu()

    def _createMenuActionContext(self):
        storage = self._getSelectedStore()
        menuContext = ZMediaStorageMenuActionContext(self, storage, self.model)
        return menuContext
    # end _createMenuActionContext()

    def _getButtonTypes(self):
        return ZBaseDialog.CLOSE_BUTTON
示例#15
0
class ZMediaStorageManagerDialog(ZHeaderDialog, ZPersistentDialogMixin):
    def __init__(self, parent):
        self.model = ZMediaStorageManagerModel()
        self.model.getService().addListener(self)
        ZHeaderDialog.__init__(
            self,
            parent,
            wx.ID_ANY,
            _extstr(u"mediastoragedialog.DialogTitle"),
            style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
            name=u"ZMediaStorageManagerDialog")  #$NON-NLS-2$ #$NON-NLS-1$

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

        ZPersistentDialogMixin.__init__(
            self, IZAppUserPrefsKeys.MEDIA_STORE_MANAGER_DIALOG)

        self.Layout()

    # end __init__()

    def _createNonHeaderWidgets(self):
        self.staticBox = wx.StaticBox(
            self, wx.ID_ANY,
            _extstr(u"mediastoragedialog.MediaStorages"))  #$NON-NLS-1$
        provider = ZMediaStorageListContentProvider(self.model)
        self.storageListBox = ZListViewEx(provider, self)
        self.storageListBox.SetSizeHints(-1, 225)
        self.addButton = wx.Button(
            self, wx.ID_ANY,
            _extstr(u"mediastoragedialog.NewStore"))  #$NON-NLS-1$

    # end _createNonHeaderWidgets()

    def _populateNonHeaderWidgets(self):
        u"Called to populate the non header related widgets.  (abstract)"  #$NON-NLS-1$

    # end _populateNonHeaderWidgets()

    def _layoutNonHeaderWidgets(self):
        sizer = wx.StaticBoxSizer(self.staticBox, wx.VERTICAL)
        sizer.Add(self.storageListBox, 1, wx.EXPAND | wx.ALL, 5)
        sizer.Add(self.addButton, 0, wx.LEFT | wx.BOTTOM, 5)

        return sizer

    # end _layoutNonHeaderWidgets()

    def _bindWidgetEvents(self):
        self._bindCancelButton(self.onCancel)

        self.Bind(wx.EVT_BUTTON, self.onNewStore, self.addButton)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onEdit, self.storageListBox)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onSelection,
                  self.storageListBox)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onItemRightClick,
                  self.storageListBox)
        self.Bind(wx.EVT_LIST_KEY_DOWN, self.onKeyPress, self.storageListBox)

    # end _bindWidgetEvents()

    def _getHeaderTitle(self):
        return _extstr(u"mediastoragedialog.HeaderTitle")  #$NON-NLS-1$

    # end _getHeaderTitle()

    def _getHeaderMessage(self):
        return _extstr(u"mediastoragedialog.HeaderMessage")  #$NON-NLS-1$

    # end _getHeaderMessage()

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

    # end _getHeaderImagePath()

    def onEdit(self, event):
        actionContext = self._createMenuActionContext()
        action = ZEditMediaStorageMenuAction()
        action.runAction(actionContext)
        event.Skip()

    # end onEdit()

    def onCancel(self, event):
        self.model.getService().removeListener(self)
        event.Skip()

    # end onCancel()

    def onSelection(self, event):
        self.currentIndex = event.GetIndex()
        event.Skip()

    # end onSelection

    def onKeyPress(self, event):
        if event.GetKeyCode() == wx.WXK_DELETE:
            actionContext = self._createMenuActionContext()
            action = ZDeleteMediaStorageMenuAction()
            action.runAction(actionContext)
        event.Skip()

    # end onKeyPress()

    def onNewStore(self, event):
        ZMediaStorageUtil().createNewMediaStorage(self)
        event.Skip()

    # end onNewStore()

    def onItemRightClick(self, event):
        storage = self._getSelectedStore()
        if storage:
            siteId = storage.getMediaSiteId()
            site = self.model.getService().getMediaSite(siteId)
            if site and site.isInternal():
                event.Skip()
                return
        menu = self._createItemContextMenu()
        self.PopupMenu(menu)
        menu.Destroy()
        event.Skip()

    # end onItemRightClick()

    def onMediaStorageAdded(self, mediaStore):  #@UnusedVariable
        self.model.refresh()
        self.storageListBox.refresh()

    # end onMediaStorageAdded()

    def onMediaStorageRemoved(self, mediaStore):  #@UnusedVariable
        self.model.refresh()
        self.storageListBox.refresh()

    # end onMediaStorageRemoved() #$NON-NLS-1$

    def _getSelectedStore(self):
        return self.model.getMediaStorages()[self.currentIndex]

    # end _getSelectedStore()

    def _createItemContextMenu(self):
        menuContext = self._createMenuActionContext()
        menuModel = ZPluginMenuModel(
            u"zoundry.blogapp.ui.core.menu.dialogs.mediastoragemanager.mediastorage"
        )  #$NON-NLS-1$
        provider = ZModelBasedMenuContentProvider(menuModel, menuContext)
        eventHandler = ZModelBasedMenuEventHandler(menuModel, menuContext)
        return ZMenu(self, menuModel.getRootNode(), provider, eventHandler)

    # end _createItemContextMenu()

    def _createMenuActionContext(self):
        storage = self._getSelectedStore()
        menuContext = ZMediaStorageMenuActionContext(self, storage, self.model)
        return menuContext

    # end _createMenuActionContext()

    def _getButtonTypes(self):
        return ZBaseDialog.CLOSE_BUTTON
示例#16
0
class ZTranslationManagerWindow(ZBaseWindow, ZPersistentDialogMixin):

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

        style = wx.DEFAULT_FRAME_STYLE | wx.FULL_REPAINT_ON_RESIZE | wx.CLIP_CHILDREN
        ZBaseWindow.__init__(self, parent, _extstr(u"translationmanager.TranslationManager"), style = style) #$NON-NLS-1$
        ZPersistentDialogMixin.__init__(self, IZBlogAppUserPrefsKeys.TRANSLATION_WINDOW)
        self.Layout()
    # 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.bodyPanel = wx.Panel(parent, wx.ID_ANY)

        self.staticBox = wx.StaticBox(self.bodyPanel, wx.ID_ANY, _extstr(u"translationmanager.Translations")) #$NON-NLS-1$

        self.translationProvider = ZTranslationListProvider(self.model)
        self.translationList = ZListViewEx(self.translationProvider, self.bodyPanel)
        self.translationList.SetMinSize(wx.Size(300, 200))

        self.newButton = wx.Button(self.bodyPanel, wx.ID_ANY, _extstr(u"translationmanager.New")) #$NON-NLS-1$
        self.editButton = wx.Button(self.bodyPanel, wx.ID_ANY, _extstr(u"translationmanager.Edit")) #$NON-NLS-1$
        self.editButton.Enable(False)

        self.staticLine = wx.StaticLine(self.bodyPanel, wx.ID_ANY)
    # 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 _populateWindowWidgets(self):
        self.SetIcons(getResourceRegistry().getIconBundle(ICON_IMAGES))
        self.refresh()
    # end _populateWindowWidgets()

    def _layoutWindowWidgets(self):
        staticBoxSizer = wx.StaticBoxSizer(self.staticBox, wx.VERTICAL)

        buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
        buttonSizer.Add(self.newButton, 0, wx.ALL | wx.EXPAND, 2)
        buttonSizer.Add(self.editButton, 0, wx.ALL | wx.EXPAND, 2)

        staticBoxSizer.Add(self.translationList, 1, wx.ALL | wx.EXPAND, 3)
        staticBoxSizer.AddSizer(buttonSizer, 0, wx.ALL | wx.EXPAND, 2)

        self.bodyPanel.SetSizer(staticBoxSizer)
        self.bodyPanel.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.bodyPanel, 1, wx.EXPAND | wx.ALL, 5)

        return sizer
    # end _layoutWindowWidgets()

    def _bindWidgetEvents(self):
        self.Bind(wx.EVT_BUTTON, self.onAdd, self.newButton)
        self.Bind(wx.EVT_BUTTON, self.onEdit, self.editButton)
        self.Bind(wx.EVT_CLOSE, self.onClose, self)
        self.Bind(ZEVT_REFRESH, self.onRefresh, self)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onTranslationSelected, self.translationList)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onEdit, self.translationList)
    # end _bindWidgetEvents()

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

    def onAdd(self, event):
        dialog = ZNewTranslationDialog(self, self.model)
        result = dialog.ShowModal()
        if result == wx.ID_OK:
            busyIndicator = wx.BusyCursor()
            localeStr = dialog.getData()
            translation = self.model.createNewTranslation(localeStr)
            self.translationProvider.updateImageList()
            self.translationList.refresh()
            translationName = self.model.getNameForLocale(translation.getLocale())
            editor = ZTranslationEditor(self, translation, self.model.getDefaultTranslation(), translationName)
            del busyIndicator
            editor.ShowModal()
        self.refresh()
        event.Skip()
    # end onAdd()

    def onEdit(self, event):
        busyIndicator = wx.BusyCursor()
        idx = self.translationList.getSelection()[0]
        translation = self.model.getTranslations()[idx]
        translation.load()
        translationName = self.model.getNameForLocale(translation.getLocale())
        editor = ZTranslationEditor(self, translation, self.model.getDefaultTranslation(), translationName)
        del busyIndicator
        editor.ShowModal()
        event.Skip()
    # end onEdit()

    def onTranslationSelected(self, event):
        self.selectedTranslation = self.model.getTranslations()[event.GetItem().GetId()]
        self.editButton.Enable(True)
        self.refresh()
        event.Skip()
    # end onTranslationSelected()

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

    def refresh(self):
        self.translationList.refresh()
    # end refresh()

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

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

    def _getHeaderImagePath(self):
        return u"images/dialogs/translation/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 TRANSLATION_MANAGER_WINDOW
        TRANSLATION_MANAGER_WINDOW = None
        event.Skip()
示例#17
0
class ZAccountBrowseView(ZView, IZAccountStoreListener):
    def __init__(self, parent):
        ZView.__init__(self, parent, wx.ID_ANY)

        self._createWidgets()
        self._layoutWidgets()
        self._populateWidgets()
        self._bindWidgetEvents()

        self._registerAsAccountListener()

    # end __init__()

    def _createWidgets(self):
        self.accountListProvider = ZAccountListProvider()
        self.accountListView = ZListViewEx(self.accountListProvider, self)

    # end _createWidgets()

    def _layoutWidgets(self):
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.accountListView, 1, wx.EXPAND)

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

    # end _layoutWidgets()

    def _populateWidgets(self):
        pass

    # end _populateWidgets()

    def _bindWidgetEvents(self):
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onAccountSelected,
                  self.accountListView)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onAccountRightClick,
                  self.accountListView)
        self._bindRefreshEvent(self.onZoundryRefresh)

    # end _bindWidgetEvents()

    def onZoundryRefresh(self, event):
        self.accountListView.refresh()
        event.Skip()

    # end onZoundryRefresh()

    def onAccountRightClick(self, event):
        account = self._getSelectedAccount()
        if account is not None:
            menu = self._createAccountCtxMenu(account)
            self.PopupMenu(menu)
            menu.Destroy()
        event.Skip()

    # end onAccountRightClick()

    def onAccountSelected(self, event):
        account = self._getSelectedAccount()
        if account is not None:
            selection = None
            if account.getId() == -1:
                selection = ZViewSelection(
                    IZViewSelectionTypes.UNPUBLISHED_ACCOUNT_SELECTION, None)
            else:
                selection = ZViewSelection(
                    IZViewSelectionTypes.ACCOUNT_SELECTION, account.getId())
            fireViewSelectionEvent(selection, self)
        else:
            fireViewUnselectionEvent()
        event.Skip()

    # end onAccountSelected()

    def onAccountAdded(self, account):  #@UnusedVariable
        self.accountListProvider.refresh()
        fireRefreshEvent(self)

    # end onAccountAdded()

    def onAccountDeleted(self, account):  #@UnusedVariable
        if self._getSelectedAccount().getId() == account.getId():
            selection = ZViewSelection(
                IZViewSelectionTypes.UNPUBLISHED_ACCOUNT_SELECTION, None)
            fireViewSelectionEvent(selection, self)

        self.accountListProvider.refresh()
        fireRefreshEvent(self)

    # end onAccountDeleted()

    def _createAccountCtxMenu(self, account):
        menuContext = ZAccountMenuActionContext(self, account)
        menuModel = ZBlogAccountMenuModel()
        provider = ZModelBasedMenuContentProvider(menuModel, menuContext)
        eventHandler = ZModelBasedMenuEventHandler(menuModel, menuContext)
        return ZMenu(self, menuModel.getRootNode(), provider, eventHandler)

    # end _createAccountCtxMenu()

    def _registerAsAccountListener(self):
        accountStore = getApplicationModel().getService(
            IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
        accountStore.addListener(self)

    # end _registerAsAccountListener()

    def _unregisterAsAccountListener(self):
        accountStore = getApplicationModel().getService(
            IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
        accountStore.removeListener(self)

    # end _unregisterAsAccountListener()

    def destroy(self):
        self._unregisterAsAccountListener()

    # end destroy()

    def _getSelectedAccount(self):
        itemIndexes = self.accountListView.getSelection()
        if itemIndexes:
            itemIndex = itemIndexes[0]
            return self.accountListProvider.getAccountAtIndex(itemIndex)
        return None
示例#18
0
class ZBlogBrowseView(ZView, IZAccountStoreListener):
    def __init__(self, parent):
        ZView.__init__(self, parent, wx.ID_ANY)

        self._createWidgets()
        self._layoutWidgets()
        self._populateWidgets()
        self._bindWidgetEvents()

        self._registerAsAccountListener()

    # end __init__()

    def _createWidgets(self):
        self.blogListProvider = ZBlogListProvider()
        self.blogListView = ZListViewEx(self.blogListProvider, self)

    # end _createWidgets()

    def _layoutWidgets(self):
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.blogListView, 1, wx.EXPAND)

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

    # end _layoutWidgets()

    def _populateWidgets(self):
        pass

    # end _populateWidgets()

    def _bindWidgetEvents(self):
        self.Bind(ZEVT_VIEW_SELECTION_CHANGED, self.onViewSelection)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onBlogSelected,
                  self.blogListView)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onBlogRightClick,
                  self.blogListView)
        self._bindRefreshEvent(self.onZoundryRefresh)

    # end _bindWidgetEvents()

    def onBlogRightClick(self, event):
        blog = self._getSelectedBlog()
        if blog is not None:
            menu = self._createBlogCtxMenu(blog)
            self.PopupMenu(menu)
            menu.Destroy()
        event.Skip()

    # end onBlogRightClick()

    def _createBlogCtxMenu(self, blog):
        menuContext = ZBlogMenuActionContext(self, blog)
        menuModel = ZBlogMenuModel()
        provider = ZModelBasedMenuContentProvider(menuModel, menuContext)
        eventHandler = ZModelBasedMenuEventHandler(menuModel, menuContext)
        return ZMenu(self, menuModel.getRootNode(), provider, eventHandler)

    # end _createBlogCtxMenu()

    def onViewSelection(self, event):
        selection = event.getSelection()
        if selection.getType() == IZViewSelectionTypes.ACCOUNT_SELECTION:
            accountId = selection.getData()
            self.blogListProvider.setAccountId(accountId)
            self.blogListProvider.refresh()
            self.blogListView.refresh()
            self.blogListView.deselectAll()
        elif selection.getType(
        ) == IZViewSelectionTypes.UNPUBLISHED_ACCOUNT_SELECTION:
            self.blogListProvider.setAccountId(None)
            self.blogListProvider.refresh()
            self.blogListView.refresh()
            self.blogListView.deselectAll()

        event.Skip()

    # end onViewSelection()

    def onBlogSelected(self, event):
        blog = self._getSelectedBlog()
        if blog is not None:
            account = blog.getAccount()
            accountId = account.getId()
            blogId = blog.getId()
            selection = ZViewSelection(IZViewSelectionTypes.BLOG_SELECTION,
                                       (accountId, blogId))
            fireViewSelectionEvent(selection, self)
        else:
            fireViewUnselectionEvent()
        event.Skip()

    # end onBlogSelected()

    def onZoundryRefresh(self, event):
        self.blogListView.refresh()
        event.Skip()

    # end onZoundryRefresh()

    def onAccountChanged(self, account):
        if account.getId() == self.blogListProvider.getAccountId():
            self.blogListProvider.refresh()
            fireRefreshEvent(self)

    # end onAccountChanged()

    def onAccountDeleted(self, account):
        if account.getId() == self.blogListProvider.getAccountId():
            self.blogListProvider.setAccountId(None)
            self.blogListProvider.refresh()
            fireRefreshEvent(self)

    # end onAccountDeleted()

    def _registerAsAccountListener(self):
        accountStore = getApplicationModel().getService(
            IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
        accountStore.addListener(self)

    # end _registerAsAccountListener()

    def _unregisterAsAccountListener(self):
        accountStore = getApplicationModel().getService(
            IZBlogAppServiceIDs.ACCOUNT_STORE_SERVICE_ID)
        accountStore.removeListener(self)

    # end _unregisterAsAccountListener()

    def destroy(self):
        self._unregisterAsAccountListener()

    # end destroy()

    def _getSelectedBlog(self):
        itemIndexes = self.blogListView.getSelection()
        if itemIndexes:
            itemIndex = itemIndexes[0]
            return self.blogListProvider.getBlogAtIndex(itemIndex)
        return None
示例#19
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)
示例#20
0
class ZLinkBlogPostDetailsPanel(ZAbstractDetailsPanel):
    def __init__(self, parent):
        self.selectedLink = None
        self.document = None
        # FIXME (EPW) need to update the value of self.blog in onSelectionChanged()
        self.blog = None
        self.linkContentProvider = ZLinkListViewContentProvider()

        ZAbstractDetailsPanel.__init__(self, parent)

    # end __init__()

    def _createWidgets(self):
        style = wx.LC_VIRTUAL | wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_HRULES | wx.NO_BORDER
        self.linkListView = ZListViewEx(self.linkContentProvider,
                                        self,
                                        style=style)

    # end _createWidgets()

    def _bindWidgetEvents(self):
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onSelected,
                  self.linkListView)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onActivated,
                  self.linkListView)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onRightClick,
                  self.linkListView)

        wx.EVT_SET_FOCUS(self.linkListView, self.onFocus)
        wx.EVT_KILL_FOCUS(self.linkListView, self.onUnFocus)

    # end _bindWidgetEvents()

    def _layoutWidgets(self):
        linkSBSizer = wx.BoxSizer(wx.HORIZONTAL)
        linkSBSizer.Add(self.linkListView, 1, wx.EXPAND)

        box = wx.BoxSizer(wx.VERTICAL)
        box.AddSizer(linkSBSizer, 1, wx.EXPAND)
        self.SetAutoLayout(True)
        self.SetSizer(box)

    # end _layoutWidgets()

    def onSelectionChanged(self, document):
        self.document = document
        self.selectedLink = None
        self.linkContentProvider.setDocument(document)
        self.linkListView.refresh()

    # end onSelectionChanged()

    def onSelected(self, event):
        link = self.linkContentProvider.getLink(event.GetIndex())
        self.selectedLink = link
        self._fireLinkSelectionEvent(link)
        event.Skip()

    # end onSelected()

    def onActivated(self, event):
        url = self.linkListView.GetItemText(event.GetIndex())
        if url:
            context = ZLinkActionContext(self, url)
            openLinkAction = getApplicationModel().getActionRegistry(
            ).findAction(IZAppActionIDs.OPEN_LINK_ACTION)
            openLinkAction.runAction(context)
        event.Skip

    # end onActivated()

    def onRightClick(self, event):
        url = self.linkListView.GetItemText(event.GetIndex())
        if url:
            context = ZLinkActionContext(self, url)
            menuModel = ZLinkMenuModel()
            menu = ZModelBasedMenu(menuModel, context, self)
            self.PopupMenu(menu)
            menu.Destroy()
        event.Skip()

    # end onRightClick()

    def onFocus(self, event):
        self._fireLinkSelectionEvent(self.selectedLink)
        event.Skip()

    # end onFocus()

    def onUnFocus(self, event):
        fireViewUnselectionEvent()
        event.Skip()

    # end onUnFocus()

    def _fireLinkSelectionEvent(self, link):
        if link:
            linkIDO = ZLinkIDO(None, self.document.getId(), link.getHref())
            linkSelection = ZLinkSelection(linkIDO, self.blog)
            fireViewSelectionEvent(linkSelection, None)
class ZPersonalDictionaryPreferencePage(ZApplicationPreferencesPrefPage, IZSpellCheckServiceListener):

    def __init__(self, parent):
        self.model = ZPersonalDictionaryPrefPageModel()
        ZApplicationPreferencesPrefPage.__init__(self, parent)
        
        self.model.getSpellcheckService().addListener(self)
    # end __init__()

    def createWidgets(self):
        self.warningMsg = wx.StaticText(self, wx.ID_ANY, _extstr(u"personaldictprefpage.SpellCheckingMustBeEnabled")) #$NON-NLS-1$
        self.warningMsg.SetFont(getDefaultFontBold())
        self.staticBox = wx.StaticBox(self, wx.ID_ANY)
        provider = ZPersonalDictionaryContentProvider(self.model)
        self.personalDictionaryListView = ZListViewEx(provider, self)
        self.addButton = wx.Button(self, wx.ID_ANY, _extstr(u"personaldictprefpage.Add")) #$NON-NLS-1$
        self.removeButton = wx.Button(self, wx.ID_ANY, _extstr(u"personaldictprefpage.Remove")) #$NON-NLS-1$
        self.clearButton = wx.Button(self, wx.ID_ANY, _extstr(u"personaldictprefpage.Clear")) #$NON-NLS-1$
    # end createWidgets()

    def populateWidgets(self):
        self._refreshButtonStates()
        isEnabled = self.model.isSpellcheckEnabled()
        self.warningMsg.Show(not isEnabled)
        self.personalDictionaryListView.Enable(isEnabled)
        self.addButton.Enable(isEnabled)
        self.removeButton.Enable(isEnabled)
        self.clearButton.Enable(isEnabled)
    # end populateWidgets()

    def bindWidgetEvents(self):
        self.Bind(wx.EVT_BUTTON, self.onAddWord, self.addButton)
        self.Bind(wx.EVT_BUTTON, self.onRemoveWord, self.removeButton)
        self.Bind(wx.EVT_BUTTON, self.onClear, self.clearButton)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onWordSelected, self.personalDictionaryListView)
    # end bindWidgetEvents()

    def layoutWidgets(self):
        buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
        buttonSizer.Add(self.addButton, 0, wx.EXPAND | wx.ALL, 2)
        buttonSizer.Add(self.removeButton, 0, wx.EXPAND | wx.ALL, 2)
        buttonSizer.Add(self.clearButton, 0, wx.EXPAND | wx.ALL, 2)

        sizer = wx.StaticBoxSizer(self.staticBox, wx.VERTICAL)
        sizer.Add(self.personalDictionaryListView, 1, wx.EXPAND | wx.ALL, 5)
        sizer.AddSizer(buttonSizer, 0, wx.EXPAND | wx.ALL, 1)
        
        prefSizer = wx.BoxSizer(wx.VERTICAL)
        prefSizer.Add(self.warningMsg, 0, wx.EXPAND | wx.ALL, 2)
        prefSizer.AddSizer(sizer, 1, wx.EXPAND | wx.ALL, 5)

        self.SetAutoLayout(True)
        self.SetSizer(prefSizer)
        self.Layout()
    # end layoutWidgets()
    
    def onAddWord(self, event):
        word = ZShowDataEntryDialog(self, _extstr(u"personaldictprefpage.AddPersonalDictionaryWord"), _extstr(u"personaldictprefpage.Word")) #$NON-NLS-2$ #$NON-NLS-1$
        if word is not None:
            self.model.addWord(word)
            self.personalDictionaryListView.refresh()
            self._refreshButtonStates()
            self.getPrefsDialog().onPrefPageChange()
        event.Skip()
    # end onAddWord()

    def onRemoveWord(self, event):
        selection = self.personalDictionaryListView.getSelection()
        if selection:
            selectedWord = self.model.getWordList()[selection[0]]
            if self.model.deleteWord(selectedWord):
                self.personalDictionaryListView.refresh()
                self._refreshButtonStates()
                self.getPrefsDialog().onPrefPageChange()
        event.Skip()
    # end onRemoveWord()

    def onClear(self, event):
        self.model.clearWords()
        self.personalDictionaryListView.refresh()
        self._refreshButtonStates()
        self.getPrefsDialog().onPrefPageChange()
        event.Skip()
    # end onClear()

    def onWordSelected(self, event):
        self._refreshButtonStates()
        event.Skip()
    # end onWordSelected()
    
    def onSpellcheckEnabled(self, spellChecker): #@UnusedVariable
        self.rollback()
    # end onSpellcheckEnabled()

    def onSpellcheckDisabled(self):
        self.rollback()
    # end onSpellcheckDisabled()

    def _refreshButtonStates(self):
        self.removeButton.Enable(self.personalDictionaryListView.GetSelectedItemCount() > 0)
        self.clearButton.Enable(len(self.model.getWordList()) > 0)
    # end _refreshButtonStates()

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

    def isValid(self):
        return True
    # end isValid()

    def apply(self):
        self.model.commit()
        return True
    # end apply()

    def rollback(self):
        self.model.rollback()
        self.personalDictionaryListView.refresh()
        self.populateWidgets()
    # end rollback()
    
    def destroy(self):
        self.model.getSpellcheckService().removeListener(self)