Exemplo n.º 1
0
    def __init__(self, parent, addonUpdateInfo, auto=True):
        # Translators: The title of the add-on updates dialog.
        super(AddonUpdatesDialog,
              self).__init__(parent, title=_("NVDA Add-on Updates"))
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        addonsSizerHelper = guiHelper.BoxSizerHelper(self,
                                                     orientation=wx.VERTICAL)
        self.addonUpdateInfo = addonUpdateInfo
        self.auto = auto

        if addonUpdateInfo:
            entriesSizer = wx.BoxSizer(wx.VERTICAL)
            self.addonsList = AutoWidthColumnCheckListCtrl(self,
                                                           -1,
                                                           style=wx.LC_REPORT
                                                           | wx.LC_SINGLE_SEL,
                                                           size=(550, 350))
            self.addonsList.Bind(wx.EVT_CHECKLISTBOX, self.onAddonsChecked)
            self.addonsList.InsertColumn(0, translate("Package"), width=150)
            # Translators: The label for a column in add-ons list used to identify add-on's running status (example: status is running).
            self.addonsList.InsertColumn(1, _("Current version"), width=50)
            # Translators: The label for a column in add-ons list used to identify add-on's version (example: version is 0.3).
            self.addonsList.InsertColumn(2, _("New version"), width=50)
            entriesSizer.Add(self.addonsList, proportion=8)
            for entry in sorted(addonUpdateInfo.keys()):
                addon = addonUpdateInfo[entry]
                self.addonsList.Append(
                    (addon['summary'], addon['curVersion'], addon['version']))
                self.addonsList.CheckItem(self.addonsList.GetItemCount() - 1)
            self.addonsList.Select(0)
            self.addonsList.SetItemState(0, wx.LIST_STATE_FOCUSED,
                                         wx.LIST_STATE_FOCUSED)
            addonsSizerHelper.addItem(entriesSizer)
        else:
            # Translators: Message displayed when no add-on updates are available.
            addonsSizerHelper.addItem(
                wx.StaticText(self, label=_("No add-on update available.")))

        bHelper = addonsSizerHelper.addDialogDismissButtons(
            guiHelper.ButtonHelper(wx.HORIZONTAL))
        if addonUpdateInfo:
            # Translators: The label of a button to update add-ons.
            label = _("&Update add-ons")
            self.updateButton = bHelper.addButton(self, label=label)
            self.updateButton.Bind(wx.EVT_BUTTON, self.onUpdate)

        closeButton = bHelper.addButton(self,
                                        wx.ID_CLOSE,
                                        label=translate("&Close"))
        closeButton.Bind(wx.EVT_BUTTON, self.onClose)
        self.Bind(wx.EVT_CLOSE, lambda evt: self.onClose)
        self.EscapeId = wx.ID_CLOSE

        mainSizer.Add(addonsSizerHelper.sizer,
                      border=guiHelper.BORDER_FOR_DIALOGS,
                      flag=wx.ALL)
        self.Sizer = mainSizer
        mainSizer.Fit(self)
        self.Center(wx.BOTH | wx.CENTER_ON_SCREEN)
        wx.CallAfter(self.Show)
Exemplo n.º 2
0
class AddonUpdatesDialog(wx.Dialog):
    def __init__(self, parent, addonUpdateInfo, auto=True):
        # Translators: The title of the add-on updates dialog.
        super(AddonUpdatesDialog,
              self).__init__(parent, title=_("NVDA Add-on Updates"))
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        addonsSizerHelper = guiHelper.BoxSizerHelper(self,
                                                     orientation=wx.VERTICAL)
        self.addonUpdateInfo = addonUpdateInfo
        self.auto = auto

        if addonUpdateInfo:
            if len(addonUpdateInfo) > 1:
                # Translators: Message displayed when add-on updates are available.
                updateText = _("{updateCount} add-on updates are available."
                               ).format(updateCount=len(addonUpdateInfo))
            else:
                # Translators: Message displayed when add-on updates are available.
                updateText = _("1 add-on update is available.")
            addonsSizerHelper.addItem(wx.StaticText(self, label=updateText))
            entriesSizer = wx.BoxSizer(wx.VERTICAL)
            self.addonsList = AutoWidthColumnCheckListCtrl(self,
                                                           -1,
                                                           style=wx.LC_REPORT
                                                           | wx.LC_SINGLE_SEL,
                                                           size=(550, 350))
            self.addonsList.Bind(wx.EVT_CHECKLISTBOX, self.onAddonsChecked)
            self.addonsList.InsertColumn(0, translate("Package"), width=150)
            # Translators: The label for a column in add-ons list used to identify add-on's running status (example: status is running).
            self.addonsList.InsertColumn(1, _("Current version"), width=50)
            # Translators: The label for a column in add-ons list used to identify add-on's version (example: version is 0.3).
            self.addonsList.InsertColumn(2, _("New version"), width=50)
            entriesSizer.Add(self.addonsList, proportion=8)
            for entry in sorted(addonUpdateInfo.keys()):
                addon = addonUpdateInfo[entry]
                self.addonsList.Append(
                    (addon['summary'], addon['curVersion'], addon['version']))
                self.addonsList.CheckItem(self.addonsList.GetItemCount() - 1)
            self.addonsList.Select(0)
            self.addonsList.SetItemState(0, wx.LIST_STATE_FOCUSED,
                                         wx.LIST_STATE_FOCUSED)
            addonsSizerHelper.addItem(entriesSizer)
        else:
            # Translators: Message displayed when no add-on updates are available.
            addonsSizerHelper.addItem(
                wx.StaticText(self, label=_("No add-on update available.")))

        bHelper = addonsSizerHelper.addDialogDismissButtons(
            guiHelper.ButtonHelper(wx.HORIZONTAL))
        if addonUpdateInfo:
            # Translators: The label of a button to update add-ons.
            label = _("&Update add-ons")
            self.updateButton = bHelper.addButton(self, label=label)
            self.updateButton.Bind(wx.EVT_BUTTON, self.onUpdate)

        closeButton = bHelper.addButton(self,
                                        wx.ID_CLOSE,
                                        label=translate("&Close"))
        closeButton.Bind(wx.EVT_BUTTON, self.onClose)
        self.Bind(wx.EVT_CLOSE, lambda evt: self.onClose)
        self.EscapeId = wx.ID_CLOSE

        mainSizer.Add(addonsSizerHelper.sizer,
                      border=guiHelper.BORDER_FOR_DIALOGS,
                      flag=wx.ALL)
        self.Sizer = mainSizer
        mainSizer.Fit(self)
        self.Center(wx.BOTH | wx.CENTER_ON_SCREEN)
        wx.CallAfter(self.Show)

    def onAddonsChecked(self, evt):
        try:
            self.updateButton.Enable() if any([
                self.addonsList.IsChecked(addon)
                for addon in range(self.addonsList.GetItemCount())
            ]) else self.updateButton.Disable()
        except NameError:
            self.updateButton.Enable() if any([
                self.addonsList.IsChecked(addon)
                for addon in range(self.addonsList.GetItemCount())
            ]) else self.updateButton.Disable()

    def onUpdate(self, evt):
        self.Destroy()
        # #3208: do not display add-ons manager while updates are in progress.
        # Also, Skip the below step if this is an automatic update check.
        if not self.auto:
            self.Parent.Hide()
        availableAddons = sorted(self.addonUpdateInfo.keys())
        try:
            for addon in range(self.addonsList.GetItemCount()):
                if not self.addonsList.IsChecked(addon):
                    del self.addonUpdateInfo[availableAddons[addon]]
            next(
                updateAddonsGenerator(self.addonUpdateInfo.values(),
                                      auto=self.auto))
        except NameError:
            for addon in range(self.addonsList.GetItemCount()):
                if not self.addonsList.IsChecked(addon):
                    del self.addonUpdateInfo[availableAddons[addon]]
            next(
                updateAddonsGenerator(list(self.addonUpdateInfo.values()),
                                      auto=self.auto))

    def onClose(self, evt):
        self.Destroy()