--- a/src/eric7/Plugins/VcsPlugins/vcsMercurial/HgBookmarksInOutDialog.py Sun Jan 07 19:54:03 2024 +0100 +++ b/src/eric7/Plugins/VcsPlugins/vcsMercurial/HgBookmarksInOutDialog.py Mon Jan 08 11:14:48 2024 +0100 @@ -7,31 +7,37 @@ Module implementing a dialog to show a list of incoming or outgoing bookmarks. """ +import enum + from PyQt6.QtCore import QCoreApplication, Qt from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QHeaderView, QTreeWidgetItem from .Ui_HgBookmarksInOutDialog import Ui_HgBookmarksInOutDialog +class HgBookmarksInOutDialogMode(enum.Enum): + """ + Class defining the modes of the dialog. + """ + + INCOMING = 0 + OUTGOING = 1 + + class HgBookmarksInOutDialog(QDialog, Ui_HgBookmarksInOutDialog): """ Class implementing a dialog to show a list of incoming or outgoing bookmarks. """ - # TODO: change this to an enum - INCOMING = 0 - OUTGOING = 1 - def __init__(self, vcs, mode, parent=None): """ Constructor @param vcs reference to the vcs object @type Hg - @param mode mode of the dialog (HgBookmarksInOutDialog.INCOMING, - HgBookmarksInOutDialog.OUTGOING) - @type int + @param mode mode of the dialog + @type HgBookmarksInOutDialogMode @param parent reference to the parent widget @type QWidget @exception ValueError raised to indicate an invalid dialog mode @@ -43,15 +49,16 @@ self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False) self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True) - if mode not in [self.INCOMING, self.OUTGOING]: + if not isinstance(mode, HgBookmarksInOutDialogMode): raise ValueError("Bad value for mode") - if mode == self.INCOMING: + + if mode == HgBookmarksInOutDialogMode.INCOMING: self.setWindowTitle(self.tr("Mercurial Incoming Bookmarks")) - elif mode == self.OUTGOING: + elif mode == HgBookmarksInOutDialogMode.OUTGOING: self.setWindowTitle(self.tr("Mercurial Outgoing Bookmarks")) self.vcs = vcs - self.mode = mode + self.__mode = mode self.__hgClient = vcs.getClient() self.bookmarksList.headerItem().setText(self.bookmarksList.columnCount(), "") @@ -75,20 +82,15 @@ def start(self): """ Public slot to start the bookmarks command. - - @exception ValueError raised to indicate an invalid dialog mode """ self.errorGroup.hide() self.intercept = False self.activateWindow() - if self.mode not in (self.INCOMING, self.OUTGOING): - raise ValueError("Bad value for mode") - args = ( self.vcs.initCommand("incoming") - if self.mode == self.INCOMING + if self.__mode == HgBookmarksInOutDialogMode.INCOMING else self.vcs.initCommand("outgoing") )