コード例 #1
0
ファイル: accountprefsdialog.py プロジェクト: mpm2050/Raven
    def __init__(self, parent, jumpTo=None):
        self.model = ZAccountManagerModel()
        self.model.getService().addListener(self)
        jumpToPageId = self._resolveJumpTo(jumpTo)

        ZPreferencesDialog.__init__(self, parent, jumpToPageId)
        ZPersistentPrefsDialogMixin.__init__(
            self, IZAppUserPrefsKeys.ACCOUNT_MANAGER_DIALOG, False)
コード例 #2
0
    def __init__(self, parent, jumpTo=None):
        self.model = ZAccountManagerModel()
        self.model.getService().addListener(self)
        jumpToPageId = self._resolveJumpTo(jumpTo)

        ZPreferencesDialog.__init__(self, parent, jumpToPageId)
        ZPersistentPrefsDialogMixin.__init__(self, IZAppUserPrefsKeys.ACCOUNT_MANAGER_DIALOG, False)
コード例 #3
0
class ZAccountManagerDialog(ZPreferencesDialog, ZPersistentPrefsDialogMixin, IZAccountStoreListener):
    def __init__(self, parent, jumpTo=None):
        self.model = ZAccountManagerModel()
        self.model.getService().addListener(self)
        jumpToPageId = self._resolveJumpTo(jumpTo)

        ZPreferencesDialog.__init__(self, parent, jumpToPageId)
        ZPersistentPrefsDialogMixin.__init__(self, IZAppUserPrefsKeys.ACCOUNT_MANAGER_DIALOG, False)

    # end __init__()

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

    # end _getHeaderTitle()

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

    # end _getHeaderMessage()

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

    # end _getHeaderImagePath()

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

    # end onAccountAdded()

    def onAccountChanged(self, account):  # @UnusedVariable
        self.prefsTreeView.refresh()

    # end onAccountChange()

    def onAccountDeleted(self, account):  # @UnusedVariable
        self.prefsTreeView.refresh()

    # end onAccountDeleted()

    def _resolveJumpTo(self, jumpTo):
        if isinstance(jumpTo, IZBlogAccount) or isinstance(jumpTo, IZBlogFromAccount):
            return jumpTo.getId()
        else:
            return None

    # end _resolveJumpTo()

    def _resolveNodeId(self, treeNode):
        if isinstance(treeNode, IZBlogAccount) or isinstance(treeNode, IZBlogFromAccount):
            return treeNode.getId()
        else:
            return None

    # end _resolveNodeId()

    def _getDefaultPageId(self):
        userPrefs = getApplicationModel().getUserProfile().getPreferences()
        return userPrefs.getUserPreference(IZAppUserPrefsKeys.ACCOUNT_MANAGER_DIALOG + u".page-id", None)  # $NON-NLS-1$

    # end _getDefaultPageId()

    def _createTreeProvider(self):
        return ZAccountManagerTreeProvider(self.model)

    # end _createTreeProvider()

    def _createTreeButtons(self, parent):
        self.addAccountButton = wx.Button(parent, wx.ID_ANY, _extstr(u"accountprefsdialog.AddAccount"))  # $NON-NLS-1$
        self.removeAccountButton = wx.Button(
            parent, wx.ID_ANY, _extstr(u"accountprefsdialog.RemoveAccount")
        )  # $NON-NLS-1$
        self.removeAccountButton.Enable(False)
        return [self.addAccountButton, self.removeAccountButton]

    # end _createTreeButtons()

    def _bindWidgetEvents(self):
        ZPreferencesDialog._bindWidgetEvents(self)

        self.Bind(wx.EVT_BUTTON, self.onAddAccount, self.addAccountButton)
        self.Bind(wx.EVT_BUTTON, self.onRemoveAccount, self.removeAccountButton)

        self.Bind(wx.EVT_TREE_DELETE_ITEM, self.onAccountTreeItemDeleted, self.prefsTreeView)
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.onAccountTreeItemChanged, self.prefsTreeView)

    # end _bindWidgetEvents()

    def _createPrefPage(self, parent, selectedNode):
        if isinstance(selectedNode, IZBlogAccount):
            return ZAccountPrefsPage(parent, selectedNode)
        elif isinstance(selectedNode, IZBlogFromAccount):
            return ZBlogPrefsPage(parent, selectedNode)
        return ZDefaultPreferencePage(parent)

    # end _createPrefPage()

    def onAddAccount(self, event):
        ZNewPublisherSiteUiUtil().createNewSite(self)
        event.Skip()

    # end onAddAccount()

    def onRemoveAccount(self, event):
        nodes = self.prefsTreeView.getSelectedNodes()
        if nodes and isinstance(nodes[0], IZAccount):
            account = nodes[0]
            if ZShowYesNoMessage(
                self,
                _extstr(u"accountprefsdialog.DeleteAccountNamed") % account.getName(),
                _extstr(u"accountprefsdialog.DeleteAccount"),
            ):  # $NON-NLS-2$ #$NON-NLS-1$
                self.model.deleteAccount(account)
        event.Skip()

    # end onRemoveAccount()

    def onAccountTreeItemChanged(self, event):
        self._updateButtonAndPageStates()
        event.Skip()

    # end onAccountTreeItemChanged()

    def onAccountTreeItemDeleted(self, event):
        fireUIExecEvent(ZMethodRunnable(self._updateButtonAndPageStates), self)
        event.Skip()

    # end onAccountTreeItemChanged()

    def _updateButtonAndPageStates(self):
        nodes = self.prefsTreeView.getSelectedNodes()
        if nodes and isinstance(nodes[0], IZAccount):
            self.removeAccountButton.Enable(True)
        else:
            self.removeAccountButton.Enable(False)
        # if nothing selected, make sure to change the current page
        if not nodes:
            self.currentSelection = None
            self._changePreferencePage()

    # end _updateButtonAndPageStates()

    def _getInitialSize(self):
        return wx.Size(550, 450)

    # end _getInitialSize()

    def _destroy(self):
        ZPreferencesDialog._destroy(self)

        self.model.getService().removeListener(self)
コード例 #4
0
ファイル: accountprefsdialog.py プロジェクト: mpm2050/Raven
class ZAccountManagerDialog(ZPreferencesDialog, ZPersistentPrefsDialogMixin,
                            IZAccountStoreListener):
    def __init__(self, parent, jumpTo=None):
        self.model = ZAccountManagerModel()
        self.model.getService().addListener(self)
        jumpToPageId = self._resolveJumpTo(jumpTo)

        ZPreferencesDialog.__init__(self, parent, jumpToPageId)
        ZPersistentPrefsDialogMixin.__init__(
            self, IZAppUserPrefsKeys.ACCOUNT_MANAGER_DIALOG, False)

    # end __init__()

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

    # end _getHeaderTitle()

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

    # end _getHeaderMessage()

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

    # end _getHeaderImagePath()

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

    # end onAccountAdded()

    def onAccountChanged(self, account):  #@UnusedVariable
        self.prefsTreeView.refresh()

    # end onAccountChange()

    def onAccountDeleted(self, account):  #@UnusedVariable
        self.prefsTreeView.refresh()

    # end onAccountDeleted()

    def _resolveJumpTo(self, jumpTo):
        if isinstance(jumpTo, IZBlogAccount) or isinstance(
                jumpTo, IZBlogFromAccount):
            return jumpTo.getId()
        else:
            return None

    # end _resolveJumpTo()

    def _resolveNodeId(self, treeNode):
        if isinstance(treeNode, IZBlogAccount) or isinstance(
                treeNode, IZBlogFromAccount):
            return treeNode.getId()
        else:
            return None

    # end _resolveNodeId()

    def _getDefaultPageId(self):
        userPrefs = getApplicationModel().getUserProfile().getPreferences()
        return userPrefs.getUserPreference(
            IZAppUserPrefsKeys.ACCOUNT_MANAGER_DIALOG + u".page-id",
            None)  #$NON-NLS-1$

    # end _getDefaultPageId()

    def _createTreeProvider(self):
        return ZAccountManagerTreeProvider(self.model)

    # end _createTreeProvider()

    def _createTreeButtons(self, parent):
        self.addAccountButton = wx.Button(
            parent, wx.ID_ANY,
            _extstr(u"accountprefsdialog.AddAccount"))  #$NON-NLS-1$
        self.removeAccountButton = wx.Button(
            parent, wx.ID_ANY,
            _extstr(u"accountprefsdialog.RemoveAccount"))  #$NON-NLS-1$
        self.removeAccountButton.Enable(False)
        return [self.addAccountButton, self.removeAccountButton]

    # end _createTreeButtons()

    def _bindWidgetEvents(self):
        ZPreferencesDialog._bindWidgetEvents(self)

        self.Bind(wx.EVT_BUTTON, self.onAddAccount, self.addAccountButton)
        self.Bind(wx.EVT_BUTTON, self.onRemoveAccount,
                  self.removeAccountButton)

        self.Bind(wx.EVT_TREE_DELETE_ITEM, self.onAccountTreeItemDeleted,
                  self.prefsTreeView)
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.onAccountTreeItemChanged,
                  self.prefsTreeView)

    # end _bindWidgetEvents()

    def _createPrefPage(self, parent, selectedNode):
        if isinstance(selectedNode, IZBlogAccount):
            return ZAccountPrefsPage(parent, selectedNode)
        elif isinstance(selectedNode, IZBlogFromAccount):
            return ZBlogPrefsPage(parent, selectedNode)
        return ZDefaultPreferencePage(parent)

    # end _createPrefPage()

    def onAddAccount(self, event):
        ZNewPublisherSiteUiUtil().createNewSite(self)
        event.Skip()

    # end onAddAccount()

    def onRemoveAccount(self, event):
        nodes = self.prefsTreeView.getSelectedNodes()
        if nodes and isinstance(nodes[0], IZAccount):
            account = nodes[0]
            if ZShowYesNoMessage(
                    self,
                    _extstr(u"accountprefsdialog.DeleteAccountNamed") %
                    account.getName(),
                    _extstr(u"accountprefsdialog.DeleteAccount"
                            )):  #$NON-NLS-2$ #$NON-NLS-1$
                self.model.deleteAccount(account)
        event.Skip()

    # end onRemoveAccount()

    def onAccountTreeItemChanged(self, event):
        self._updateButtonAndPageStates()
        event.Skip()

    # end onAccountTreeItemChanged()

    def onAccountTreeItemDeleted(self, event):
        fireUIExecEvent(ZMethodRunnable(self._updateButtonAndPageStates), self)
        event.Skip()

    # end onAccountTreeItemChanged()

    def _updateButtonAndPageStates(self):
        nodes = self.prefsTreeView.getSelectedNodes()
        if nodes and isinstance(nodes[0], IZAccount):
            self.removeAccountButton.Enable(True)
        else:
            self.removeAccountButton.Enable(False)
        # if nothing selected, make sure to change the current page
        if not nodes:
            self.currentSelection = None
            self._changePreferencePage()

    # end _updateButtonAndPageStates()

    def _getInitialSize(self):
        return wx.Size(550, 450)

    # end _getInitialSize()

    def _destroy(self):
        ZPreferencesDialog._destroy(self)

        self.model.getService().removeListener(self)