diff --git a/angrmanagement/__main__.py b/angrmanagement/__main__.py index cde8d562b..efa643ea3 100644 --- a/angrmanagement/__main__.py +++ b/angrmanagement/__main__.py @@ -75,16 +75,16 @@ def drawContents(self, painter) -> None: # Draw progress bar pbar_height = 3 pbar_width = contentsRect.width() * max(0.0, min(self._progress, 1.0)) - painter.setPen(Qt.transparent) - painter.setBrush(Qt.white) + painter.setPen(Qt.GlobalColor.transparent) + painter.setBrush(Qt.GlobalColor.white) painter.drawRect(QRectF(0, contentsRect.height() - pbar_height, pbar_width, pbar_height)) # Draw version and status text pad = 6 r = contentsRect.marginsRemoved(QMargins(pad, pad, pad, pad + pbar_height)) - painter.setPen(Qt.white) - painter.drawText(r, Qt.AlignTop | Qt.AlignRight, __version__) - painter.drawText(r, Qt.AlignBottom | Qt.AlignLeft, self._progress_message) + painter.setPen(Qt.GlobalColor.white) + painter.drawText(r, Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignRight, __version__) + painter.drawText(r, Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignLeft, self._progress_message) # Fix app title on macOS if sys.platform.startswith("darwin"): @@ -109,12 +109,12 @@ def drawContents(self, painter) -> None: splashscreen_location = os.path.join(IMG_LOCATION, "angr-splash.png") splash_pixmap = QPixmap(splashscreen_location) current_screen = QGuiApplication.screenAt(QCursor.pos()) - splash = SplashScreen(current_screen, splash_pixmap, Qt.WindowStaysOnTopHint) + splash = SplashScreen(current_screen, splash_pixmap, Qt.WindowType.WindowStaysOnTopHint) splash.setFixedSize(splash_pixmap.size()) icon_location = os.path.join(IMG_LOCATION, "angr.png") splash.setWindowIcon(QIcon(icon_location)) - splash.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint) + splash.setWindowFlags(Qt.WindowType.WindowStaysOnTopHint | Qt.WindowType.FramelessWindowHint) splash.setEnabled(False) splash.show() for _ in range(5): diff --git a/angrmanagement/logic/url_scheme.py b/angrmanagement/logic/url_scheme.py index 095f12be4..ae891a4e4 100644 --- a/angrmanagement/logic/url_scheme.py +++ b/angrmanagement/logic/url_scheme.py @@ -63,7 +63,7 @@ def _register_url_scheme_windows(self) -> None: app_path_ = app_path(pythonw=True) reg_path = self.WIN_REG_PATH.format(self.URL_SCHEME) - reg = QSettings(reg_path, QSettings.NativeFormat) + reg = QSettings(reg_path, QSettings.Format.NativeFormat) reg.setValue("Default", "angr management") reg.setValue("URL Protocol", "") @@ -82,13 +82,13 @@ def _register_url_scheme_windows(self) -> None: def _unregister_url_scheme_windows(self) -> None: reg_path = self.WIN_REG_PATH.format(self.URL_SCHEME) - reg = QSettings(reg_path, QSettings.NativeFormat) + reg = QSettings(reg_path, QSettings.Format.NativeFormat) reg.remove("") def _is_url_scheme_registered_windows(self): reg_path = self.WIN_REG_PATH.format(self.URL_SCHEME) - reg = QSettings(reg_path, QSettings.NativeFormat) + reg = QSettings(reg_path, QSettings.Format.NativeFormat) if reg.contains("Default"): reg.beginGroup("shell") diff --git a/angrmanagement/plugins/ail2asm/asm_output.py b/angrmanagement/plugins/ail2asm/asm_output.py index 789cb1022..e638c9e3a 100644 --- a/angrmanagement/plugins/ail2asm/asm_output.py +++ b/angrmanagement/plugins/ail2asm/asm_output.py @@ -1,6 +1,6 @@ from __future__ import annotations -from PySide6.QtGui import Qt +from PySide6.QtCore import Qt from PySide6.QtWidgets import QDialog, QDialogButtonBox, QHBoxLayout, QLabel, QPlainTextEdit, QVBoxLayout @@ -12,7 +12,7 @@ class AsmOutput(QDialog): def __init__(self, s: str, parent=None) -> None: super().__init__(parent) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) + self.setWindowFlags(self.windowFlags() & ~Qt.WindowType.WindowContextHelpButtonHint) self._edit: QPlainTextEdit = None diff --git a/angrmanagement/plugins/dep_viewer/dep_plugin.py b/angrmanagement/plugins/dep_viewer/dep_plugin.py index 49ef3a965..16ee0d543 100644 --- a/angrmanagement/plugins/dep_viewer/dep_plugin.py +++ b/angrmanagement/plugins/dep_viewer/dep_plugin.py @@ -21,7 +21,7 @@ def __init__(self, workspace: Workspace) -> None: self.transitions: set[tuple[int, int]] = set() self.covered_blocks = SortedDict() - self.sink_color = Qt.yellow + self.sink_color = Qt.GlobalColor.yellow def color_insn(self, addr: int, selected, disasm_view) -> QColor | None: if not selected: diff --git a/angrmanagement/plugins/precise_diffing/precisediff_plugin.py b/angrmanagement/plugins/precise_diffing/precisediff_plugin.py index bf345f11a..1eac4dc2e 100644 --- a/angrmanagement/plugins/precise_diffing/precisediff_plugin.py +++ b/angrmanagement/plugins/precise_diffing/precisediff_plugin.py @@ -252,7 +252,7 @@ def color_lines(view: CodeView, start: int, length: int, color: QColor): # Move the cursor to the start position and select the text range cursor.setPosition(start) - cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor, length) + cursor.movePosition(QTextCursor.MoveOperation.Right, QTextCursor.MoveMode.KeepAnchor, length) # Create a QTextCharFormat and set the background color char_format = QTextCharFormat() diff --git a/angrmanagement/plugins/source_importer/__init__.py b/angrmanagement/plugins/source_importer/__init__.py index 0bdbac9f7..de90fb457 100644 --- a/angrmanagement/plugins/source_importer/__init__.py +++ b/angrmanagement/plugins/source_importer/__init__.py @@ -48,7 +48,7 @@ def handle_click_menu(self, idx: int) -> None: self.workspace.main_window, "Select source root", ".", - QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks, + QFileDialog.Option.ShowDirsOnly | QFileDialog.Option.DontResolveSymlinks, ) if result is not None: self.source_paths.append(result) diff --git a/angrmanagement/plugins/source_viewer/source_viewer_plugin.py b/angrmanagement/plugins/source_viewer/source_viewer_plugin.py index 08247287f..0f053d22c 100644 --- a/angrmanagement/plugins/source_viewer/source_viewer_plugin.py +++ b/angrmanagement/plugins/source_viewer/source_viewer_plugin.py @@ -9,9 +9,8 @@ from pyqodeng.core.panels import LineNumberPanel, Marker, MarkerPanel from pyqodeng.core.widgets import SplittableCodeEditTabWidget from PySide6.QtCore import QEvent, Qt -from PySide6.QtGui import QCursor +from PySide6.QtGui import QCursor, QPainter, QPen from PySide6.QtWidgets import QInputDialog, QLineEdit, QMenu, QPlainTextEdit, QStyle, QVBoxLayout -from qtpy import QtCore, QtGui from angrmanagement.plugins import BasePlugin from angrmanagement.ui.views.view import InstanceView @@ -45,15 +44,15 @@ def paintEvent(self, event) -> None: Panel.paintEvent(self, event) if not self.isVisible(): return - painter = QtGui.QPainter(self) + painter = QPainter(self) # get style options (font, size) width = self.width() height = self.editor.fontMetrics().height() font = self.editor.font() bold_font = self.editor.font() bold_font.setBold(True) - pen = QtGui.QPen(self._line_color_u) - pen_selected = QtGui.QPen(self._line_color_s) + pen = QPen(self._line_color_u) + pen_selected = QPen(self._line_color_s) painter.setFont(font) # draw every visible blocks for top, line, _block in self.editor.visible_blocks: @@ -63,7 +62,7 @@ def paintEvent(self, event) -> None: else: painter.setPen(pen) painter.setFont(font) - painter.drawText(-3, top, width, height, QtCore.Qt.AlignRight, str(line + 1)) + painter.drawText(-3, top, width, height, Qt.AlignmentFlag.AlignRight, str(line + 1)) class SourceCodeViewer(CodeEdit): @@ -100,12 +99,12 @@ def updateState(self, state_counter) -> None: self.state_panel.updateState(state_counter) def add_find(self) -> None: - icon = self.style().standardIcon(QStyle.SP_FileDialogContentsView) + icon = self.style().standardIcon(QStyle.StandardPixmap.SP_FileDialogContentsView) desc = self.viewer.add_point(self.file.path, self.current_line, "find") self.breakpoint_panel.add_marker(Marker(self.current_line - 1, icon, desc)) def add_avoid(self) -> None: - icon = self.style().standardIcon(QStyle.SP_BrowserStop) + icon = self.style().standardIcon(QStyle.StandardPixmap.SP_BrowserStop) desc = self.viewer.add_point(self.file.path, self.current_line, "avoid") self.breakpoint_panel.add_marker(Marker(self.current_line - 1, icon, desc)) @@ -145,10 +144,12 @@ def edit_cond(self) -> None: def setHighlighter(self) -> None: self.modes.append(QCCodeHighlighter(self.document(), color_scheme=ColorSchemeIDA())) QPlainTextEdit.setReadOnly(self, True) - self.setTextInteractionFlags(Qt.TextSelectableByKeyboard | Qt.TextSelectableByMouse) + self.setTextInteractionFlags( + Qt.TextInteractionFlag.TextSelectableByKeyboard | Qt.TextInteractionFlag.TextSelectableByMouse + ) def event(self, event): - if event.type() == QEvent.KeyPress and event.key() in (Qt.Key_Slash, Qt.Key_Question): + if event.type() == QEvent.Type.KeyPress and event.key() in (Qt.Key.Key_Slash, Qt.Key.Key_Question): event.accept() self.comment() return True @@ -167,7 +168,7 @@ def comment(self) -> None: else: text, comment = text no_comment = False - new_comment, ok = QInputDialog.getText(None, "Comment", "Comment", QLineEdit.Normal, comment) + new_comment, ok = QInputDialog.getText(None, "Comment", "Comment", QLineEdit.EchoMode.Normal, comment) if not ok: return cursor.movePosition(cursor.EndOfLine, cursor.MoveAnchor) diff --git a/angrmanagement/plugins/trace_viewer/qtrace_viewer.py b/angrmanagement/plugins/trace_viewer/qtrace_viewer.py index aa7d2f898..ff33051d2 100644 --- a/angrmanagement/plugins/trace_viewer/qtrace_viewer.py +++ b/angrmanagement/plugins/trace_viewer/qtrace_viewer.py @@ -108,8 +108,8 @@ def _init_widgets(self) -> None: self.listView = QTableWidget(0, 2) # row, col self.listView.setHorizontalHeaderItem(0, QTableWidgetItem("Trace ID")) self.listView.setHorizontalHeaderItem(1, QTableWidgetItem("Input ID")) - self.listView.setSelectionMode(QAbstractItemView.SingleSelection) - self.listView.setSelectionBehavior(QAbstractItemView.SelectRows) + self.listView.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection) + self.listView.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) # self.listView.horizontalHeader().setStretchLastSection(True) # self.listView.horizontalHeader().setSectionResizeModel(0, QHeaderView.Stretch) self.listView.cellClicked.connect(self._switch_current_trace) @@ -125,9 +125,9 @@ def _init_widgets(self) -> None: self.multiView = QWidget() multiLayout = QVBoxLayout() self.multiTraceList = QTableWidget(0, 2) # row, col - self.multiTraceList.setSelectionMode(QAbstractItemView.MultiSelection) - self.multiTraceList.setSelectionBehavior(QAbstractItemView.SelectRows) - self.multiTraceList.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel) + self.multiTraceList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection) + self.multiTraceList.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) + self.multiTraceList.setHorizontalScrollMode(QAbstractItemView.ScrollMode.ScrollPerPixel) self.multiTraceList.setHorizontalHeaderItem(0, QTableWidgetItem("Trace ID")) self.multiTraceList.setHorizontalHeaderItem(1, QTableWidgetItem("Input ID")) self.selectMultiTrace = QPushButton("Refresh Heatmap") @@ -148,7 +148,7 @@ def _init_widgets(self) -> None: layout = QVBoxLayout() layout.addWidget(self.view) layout.setContentsMargins(0, 0, 0, 0) - layout.setAlignment(self.view, Qt.AlignLeft) + layout.setAlignment(self.view, Qt.AlignmentFlag.AlignLeft) self.setLayout(layout) @@ -177,7 +177,7 @@ def _view_input_seed(self) -> None: msgbox.setWindowTitle("Seed Input") msgbox.setDetailedText(msgDetails) msgbox.setText(msgText) - msgbox.setStandardButtons(QMessageBox.Ok) + msgbox.setStandardButtons(QMessageBox.StandardButton.Ok) msgbox.exec() def _switch_current_trace(self, row) -> None: @@ -367,12 +367,12 @@ def jump_prev_insn(self) -> None: def eventFilter(self, obj, event) -> bool: # specifically to catch arrow keys #pylint: disable=unused-argument # more elegant solution to link w/ self.view's scroll bar keypressevent? if event.type() == QEvent.Type.KeyPress: - if not event.modifiers() & Qt.ShiftModifier: # shift + arrowkeys + if not event.modifiers() & Qt.KeyboardModifier.ShiftModifier: # shift + arrowkeys return False key = event.key() - if key in [Qt.Key_Up, Qt.Key_Left]: + if key in [Qt.Key.Key_Up, Qt.Key.Key_Left]: self.jump_prev_insn() - elif key in [Qt.Key_Down, Qt.Key_Right]: + elif key in [Qt.Key.Key_Down, Qt.Key.Key_Right]: self.jump_next_insn() return True @@ -381,7 +381,11 @@ def eventFilter(self, obj, event) -> bool: # specifically to catch arrow keys # def mousePressEvent(self, event) -> None: button = event.button() pos = self._to_logical_pos(event.pos()) - if button == Qt.LeftButton and self.view.currentIndex() == self.SINGLE_TRACE and self._at_legend(pos): + if ( + button == Qt.MouseButton.LeftButton + and self.view.currentIndex() == self.SINGLE_TRACE + and self._at_legend(pos) + ): func = self._get_func_from_y(pos.y()) bbl_addr = self._get_bbl_from_y(pos.y()) self._use_precise_position = True @@ -458,7 +462,7 @@ def _make_legend_gradient(x1, y1, x2, y2): return gradient def _show_legend(self) -> None: - pen = QPen(Qt.transparent) + pen = QPen(Qt.GlobalColor.transparent) gradient = self._make_legend_gradient( self.LEGEND_X, self.LEGEND_Y, self.LEGEND_X, self.LEGEND_Y + self.legend_height diff --git a/angrmanagement/plugins/trace_viewer/trace_plugin.py b/angrmanagement/plugins/trace_viewer/trace_plugin.py index f232d06f2..270b811b0 100644 --- a/angrmanagement/plugins/trace_viewer/trace_plugin.py +++ b/angrmanagement/plugins/trace_viewer/trace_plugin.py @@ -129,8 +129,8 @@ def handle_click_block(self, qblock, event) -> bool: btn = event.button() if ( - QApplication.keyboardModifiers() == Qt.ControlModifier - and btn == Qt.RightButton + QApplication.keyboardModifiers() == Qt.KeyboardModifier.ControlModifier + and btn == Qt.MouseButton.RightButton and self.multi_trace is not None and self.multi_trace.am_obj is not None ): diff --git a/angrmanagement/plugins/value_search/qsearch_table.py b/angrmanagement/plugins/value_search/qsearch_table.py index 87bf6faa7..3f9b9cd98 100644 --- a/angrmanagement/plugins/value_search/qsearch_table.py +++ b/angrmanagement/plugins/value_search/qsearch_table.py @@ -62,12 +62,14 @@ def rowCount(self, parent=None) -> int: # pylint: disable=unused-argument def columnCount(self, parent=None) -> int: # pylint: disable=unused-argument return len(self.HEADER) - def headerData(self, section, orientation, role=None) -> Any: # pylint: disable=unused-argument - if role == Qt.DisplayRole: + def headerData( + self, section, orientation, role=None # pylint: disable=unused-argument + ) -> Qt.SortOrder | str | None: + if role == Qt.ItemDataRole.DisplayRole: if section < len(self.HEADER): return self.HEADER[section] - elif role == Qt.InitialSortOrderRole: - return Qt.AscendingOrder + elif role == Qt.ItemDataRole.InitialSortOrderRole: + return Qt.SortOrder.AscendingOrder return None @@ -82,9 +84,9 @@ def data(self, index, role=None) -> Any: col = index.column() v = self.values[row] - if role == Qt.DisplayRole: + if role == Qt.ItemDataRole.DisplayRole: return self._get_column_text(v, col) - elif role == Qt.FontRole: + elif role == Qt.ItemDataRole.FontRole: return Conf.tabular_view_font return None @@ -94,7 +96,7 @@ def sort(self, column, order=None) -> Any: self._values = sorted( self.values, key=lambda x: self._get_column_data(x, column), - reverse=order == Qt.DescendingOrder, + reverse=order == Qt.SortOrder.DescendingOrder, ) self.layoutChanged.emit() @@ -130,24 +132,24 @@ def __init__(self, instance: Instance, parent, selection_callback=None) -> None: self._selected = selection_callback self._filter = None - self.setSelectionBehavior(QAbstractItemView.SelectRows) + self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) self.setShowGrid(False) self.verticalHeader().setVisible(False) self.verticalHeader().setDefaultSectionSize(24) - self.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel) + self.setHorizontalScrollMode(QAbstractItemView.ScrollMode.ScrollPerPixel) self._model = QSearchModel(None) self._proxy = QSortFilterProxyModel(self) self._proxy.setSourceModel(self._model) - self._proxy.setFilterCaseSensitivity(Qt.CaseInsensitive) + self._proxy.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive) self.setModel(self._proxy) self.setSortingEnabled(True) - self.setSelectionMode(QAbstractItemView.SingleSelection) + self.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection) # let the last column (string) fill table width - self.horizontalHeader().setSectionResizeMode(QHeaderView.Fixed) - self.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch) + self.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Fixed) + self.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch) self.doubleClicked.connect(self._on_string_selected) @@ -194,7 +196,7 @@ def _on_string_selected(self, model_index) -> None: self._selected(selected_item) def keyPressEvent(self, event: QKeyEvent) -> None: - if event.key() == Qt.Key_X: + if event.key() == Qt.Key.Key_X: # xrefs if self._model is None: return diff --git a/angrmanagement/plugins/varec/varec.py b/angrmanagement/plugins/varec/varec.py index 826409d52..7b1ae3507 100644 --- a/angrmanagement/plugins/varec/varec.py +++ b/angrmanagement/plugins/varec/varec.py @@ -9,7 +9,7 @@ from typing import TYPE_CHECKING import requests -from PySide6.QtGui import Qt +from PySide6.QtCore import Qt from PySide6.QtWidgets import QMessageBox from sortedcontainers import SortedDict @@ -31,7 +31,7 @@ def __init__(self, workspace: Workspace) -> None: self.transitions: set[tuple[int, int]] = set() self.covered_blocks = SortedDict() - self.sink_color = Qt.yellow + self.sink_color = Qt.GlobalColor.yellow MENU_BUTTONS = [ "&Infer variable names", @@ -74,7 +74,7 @@ def infer_variable_names(self) -> None: self.workspace._main_window, "Error in variable name prediction", "Cannot predict variable names. No pseudocode exists in the pseudocode view.", - QMessageBox.Ok, + QMessageBox.StandardButton.Ok, ) return if view.codegen._variable_kb is None: @@ -82,7 +82,7 @@ def infer_variable_names(self) -> None: self.workspace._main_window, "Error in variable name prediction", "Cannot predict variable names. The pseudocode view does not have associated variables KB.", - QMessageBox.Ok, + QMessageBox.StandardButton.Ok, ) return @@ -112,7 +112,7 @@ def infer_variable_names(self) -> None: self.workspace._main_window, "Error in variable name prediction", "Failed to predict names for all variables involved.", - QMessageBox.Ok, + QMessageBox.StandardButton.Ok, ) return @@ -127,7 +127,7 @@ def infer_variable_names(self) -> None: self.workspace._main_window, "Error in variable name prediction", "Unexpected output returned from the backend. 'code' is not found or empty.", - QMessageBox.Ok, + QMessageBox.StandardButton.Ok, ) return if "predictions" not in result["code"][0] or not result["code"][0]["predictions"]: @@ -135,7 +135,7 @@ def infer_variable_names(self) -> None: self.workspace._main_window, "Error in variable name prediction", "Unexpected output returned from the backend. 'predictions' is not found or empty.", - QMessageBox.Ok, + QMessageBox.StandardButton.Ok, ) self._restore_stage(view) return @@ -144,7 +144,7 @@ def infer_variable_names(self) -> None: self.workspace._main_window, "Error in variable name prediction", f"Prediction failed. Error: {result['code'][0]['predictions'][0]}", - QMessageBox.Ok, + QMessageBox.StandardButton.Ok, ) self._restore_stage(view) return diff --git a/angrmanagement/ui/awesome_tooltip_event_filter.py b/angrmanagement/ui/awesome_tooltip_event_filter.py index 4b4f454ae..fc9f9c025 100644 --- a/angrmanagement/ui/awesome_tooltip_event_filter.py +++ b/angrmanagement/ui/awesome_tooltip_event_filter.py @@ -59,7 +59,7 @@ def eventFilter(self, widget: QObject, event: QEvent) -> bool: """ # If this is a tooltip event... - if event.type() == QEvent.ToolTipChange: + if event.type() == QEvent.Type.ToolTipChange: # If the target Qt object containing this tooltip is *NOT* a widget, # raise a human-readable exception. While this should *NEVER* be the # case, edge cases are edge cases because they sometimes happen. diff --git a/angrmanagement/ui/css/__init__.py b/angrmanagement/ui/css/__init__.py index b868d8a24..5459b2856 100644 --- a/angrmanagement/ui/css/__init__.py +++ b/angrmanagement/ui/css/__init__.py @@ -68,29 +68,29 @@ def refresh_theme() -> None: app.setStyle(app_style) palette = QPalette() - palette.setColor(QPalette.Window, Conf.palette_window) - palette.setColor(QPalette.WindowText, Conf.palette_windowtext) - palette.setColor(QPalette.Base, Conf.palette_base) - palette.setColor(QPalette.AlternateBase, Conf.palette_alternatebase) - palette.setColor(QPalette.ToolTipBase, Conf.palette_tooltipbase) - palette.setColor(QPalette.ToolTipText, Conf.palette_tooltiptext) - palette.setColor(QPalette.PlaceholderText, Conf.palette_placeholdertext) - palette.setColor(QPalette.Text, Conf.palette_text) - palette.setColor(QPalette.Button, Conf.palette_button) - palette.setColor(QPalette.ButtonText, Conf.palette_buttontext) - palette.setColor(QPalette.BrightText, Conf.palette_brighttext) - palette.setColor(QPalette.Highlight, Conf.palette_highlight) - palette.setColor(QPalette.HighlightedText, Conf.palette_highlightedtext) - palette.setColor(QPalette.Light, Conf.palette_light) - palette.setColor(QPalette.Midlight, Conf.palette_midlight) - palette.setColor(QPalette.Dark, Conf.palette_dark) - palette.setColor(QPalette.Mid, Conf.palette_mid) - palette.setColor(QPalette.Shadow, Conf.palette_shadow) - palette.setColor(QPalette.Link, Conf.palette_link) - palette.setColor(QPalette.LinkVisited, Conf.palette_linkvisited) - palette.setColor(QPalette.Disabled, QPalette.Text, Conf.palette_disabled_text) - palette.setColor(QPalette.Disabled, QPalette.ButtonText, Conf.palette_disabled_buttontext) - palette.setColor(QPalette.Disabled, QPalette.WindowText, Conf.palette_disabled_windowtext) + palette.setColor(QPalette.ColorRole.Window, Conf.palette_window) + palette.setColor(QPalette.ColorRole.WindowText, Conf.palette_windowtext) + palette.setColor(QPalette.ColorRole.Base, Conf.palette_base) + palette.setColor(QPalette.ColorRole.AlternateBase, Conf.palette_alternatebase) + palette.setColor(QPalette.ColorRole.ToolTipBase, Conf.palette_tooltipbase) + palette.setColor(QPalette.ColorRole.ToolTipText, Conf.palette_tooltiptext) + palette.setColor(QPalette.ColorRole.PlaceholderText, Conf.palette_placeholdertext) + palette.setColor(QPalette.ColorRole.Text, Conf.palette_text) + palette.setColor(QPalette.ColorRole.Button, Conf.palette_button) + palette.setColor(QPalette.ColorRole.ButtonText, Conf.palette_buttontext) + palette.setColor(QPalette.ColorRole.BrightText, Conf.palette_brighttext) + palette.setColor(QPalette.ColorRole.Highlight, Conf.palette_highlight) + palette.setColor(QPalette.ColorRole.HighlightedText, Conf.palette_highlightedtext) + palette.setColor(QPalette.ColorRole.Light, Conf.palette_light) + palette.setColor(QPalette.ColorRole.Midlight, Conf.palette_midlight) + palette.setColor(QPalette.ColorRole.Dark, Conf.palette_dark) + palette.setColor(QPalette.ColorRole.Mid, Conf.palette_mid) + palette.setColor(QPalette.ColorRole.Shadow, Conf.palette_shadow) + palette.setColor(QPalette.ColorRole.Link, Conf.palette_link) + palette.setColor(QPalette.ColorRole.LinkVisited, Conf.palette_linkvisited) + palette.setColor(QPalette.ColorGroup.Disabled, QPalette.ColorRole.Text, Conf.palette_disabled_text) + palette.setColor(QPalette.ColorGroup.Disabled, QPalette.ColorRole.ButtonText, Conf.palette_disabled_buttontext) + palette.setColor(QPalette.ColorGroup.Disabled, QPalette.ColorRole.WindowText, Conf.palette_disabled_windowtext) app.setPalette(palette) CSS.rebuild() app.setStyleSheet(CSS.global_css.am_obj) diff --git a/angrmanagement/ui/dialogs/about.py b/angrmanagement/ui/dialogs/about.py index b72d58e89..14ce59413 100644 --- a/angrmanagement/ui/dialogs/about.py +++ b/angrmanagement/ui/dialogs/about.py @@ -17,7 +17,7 @@ class LoadAboutDialog(QDialog): def __init__(self) -> None: super().__init__() - self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) + self.setWindowFlags(Qt.WindowType.WindowTitleHint | Qt.WindowType.WindowCloseButtonHint) self.setWindowTitle("About") # mdiIcon angr_icon_location = os.path.join(IMG_LOCATION, "angr.png") @@ -32,16 +32,16 @@ def _init_widgets(self) -> None: icon_label.setPixmap(angr_icon) # textbox angr_text = QLabel("angr") - angr_text.setFont(QFont("Consolas", 24, weight=QFont.Bold)) + angr_text.setFont(QFont("Consolas", 24, weight=QFont.Weight.Bold)) version_text_tup = "Version: " + angrmanagement.__version__ version_text = QLabel(version_text_tup) - version_text.setFont(QFont("Consolas", weight=QFont.Bold)) - version_text.setAlignment(Qt.AlignCenter) - version_text.setTextInteractionFlags(Qt.TextSelectableByMouse) + version_text.setFont(QFont("Consolas", weight=QFont.Weight.Bold)) + version_text.setAlignment(Qt.AlignmentFlag.AlignCenter) + version_text.setTextInteractionFlags(Qt.TextInteractionFlag.TextSelectableByMouse) credits_text = QLabel('Credits') - credits_text.setFont(QFont("Consolas", weight=QFont.Bold)) - credits_text.setTextFormat(Qt.RichText) - credits_text.setTextInteractionFlags(Qt.TextBrowserInteraction) + credits_text.setFont(QFont("Consolas", weight=QFont.Weight.Bold)) + credits_text.setTextFormat(Qt.TextFormat.RichText) + credits_text.setTextInteractionFlags(Qt.TextInteractionFlag.TextBrowserInteraction) credits_text.setOpenExternalLinks(True) structure = QVBoxLayout() diff --git a/angrmanagement/ui/dialogs/analysis_options.py b/angrmanagement/ui/dialogs/analysis_options.py index 0f0663b78..6abdc4950 100644 --- a/angrmanagement/ui/dialogs/analysis_options.py +++ b/angrmanagement/ui/dialogs/analysis_options.py @@ -244,8 +244,8 @@ def _init_widgets(self) -> None: for analysis in self._analyses.analyses: item = QListWidgetItem(analysis.display_name, self._analysis_list) - item.setFlags(item.flags() | Qt.ItemIsUserCheckable) - item.setCheckState(Qt.Checked if analysis.enabled else Qt.Unchecked) + item.setFlags(item.flags() | Qt.ItemFlag.ItemIsUserCheckable) + item.setCheckState(Qt.CheckState.Checked if analysis.enabled else Qt.CheckState.Unchecked) self._analysis_list.addItem(item) # @@ -333,7 +333,7 @@ def _update_item_details(self) -> None: def _on_item_changed(self, item) -> None: analysis = self._analyses[self._analysis_list.indexFromItem(item).row()] - analysis.enabled = item.checkState() == Qt.Checked + analysis.enabled = item.checkState() == Qt.CheckState.Checked self._update_item_details() def _on_run_clicked(self) -> None: diff --git a/angrmanagement/ui/dialogs/assemble_patch.py b/angrmanagement/ui/dialogs/assemble_patch.py index 6c3b9b43a..1e6b70f85 100644 --- a/angrmanagement/ui/dialogs/assemble_patch.py +++ b/angrmanagement/ui/dialogs/assemble_patch.py @@ -92,7 +92,7 @@ def _init_widgets(self) -> None: buttons.setStandardButtons(QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok) buttons.accepted.connect(self._on_ok_clicked) buttons.rejected.connect(self.close) - self._ok_button = buttons.button(QDialogButtonBox.Ok) + self._ok_button = buttons.button(QDialogButtonBox.StandardButton.Ok) self._ok_button.setEnabled(False) self.main_layout.addWidget(buttons) diff --git a/angrmanagement/ui/dialogs/breakpoint.py b/angrmanagement/ui/dialogs/breakpoint.py index 4cd3683bf..c88bd2709 100644 --- a/angrmanagement/ui/dialogs/breakpoint.py +++ b/angrmanagement/ui/dialogs/breakpoint.py @@ -54,7 +54,7 @@ def _init_widgets(self) -> None: self._status_label = QLabel(self) row = 0 - layout.addWidget(QLabel("Break on:", self), row, 0, Qt.AlignRight) + layout.addWidget(QLabel("Break on:", self), row, 0, Qt.AlignmentFlag.AlignRight) self._type_radio_group = QButtonGroup(self) self._type_radio_group.addButton(QRadioButton("Execute", self), BreakpointType.Execute.value) self._type_radio_group.addButton(QRadioButton("Write", self), BreakpointType.Write.value) @@ -65,21 +65,21 @@ def _init_widgets(self) -> None: self._type_radio_group.button(self.breakpoint.type.value).setChecked(True) - layout.addWidget(QLabel("Address:", self), row, 0, Qt.AlignRight) + layout.addWidget(QLabel("Address:", self), row, 0, Qt.AlignmentFlag.AlignRight) self._address_box = QAddressInput( self._on_address_changed, self.workspace, parent=self, default=f"{self.breakpoint.addr:#x}" ) layout.addWidget(self._address_box, row, 1) row += 1 - layout.addWidget(QLabel("Size:", self), row, 0, Qt.AlignRight) + layout.addWidget(QLabel("Size:", self), row, 0, Qt.AlignmentFlag.AlignRight) self._size_box = QLineEdit(self) self._size_box.setText(f"{self.breakpoint.size:#x}") self._size_box.textChanged.connect(self._on_size_changed) layout.addWidget(self._size_box, row, 1) row += 1 - layout.addWidget(QLabel("Comment:", self), row, 0, Qt.AlignRight) + layout.addWidget(QLabel("Comment:", self), row, 0, Qt.AlignmentFlag.AlignRight) self._comment_box = QLineEdit(self) self._comment_box.setText(self.breakpoint.comment) layout.addWidget(self._comment_box, row, 1) @@ -91,7 +91,7 @@ def _init_widgets(self) -> None: buttons.setStandardButtons(QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok) buttons.accepted.connect(self._on_ok_clicked) buttons.rejected.connect(self.close) - self._ok_button = buttons.button(QDialogButtonBox.Ok) + self._ok_button = buttons.button(QDialogButtonBox.StandardButton.Ok) self._ok_button.setEnabled(False) self.main_layout.addWidget(buttons) diff --git a/angrmanagement/ui/dialogs/command_palette.py b/angrmanagement/ui/dialogs/command_palette.py index 19d97cf95..720dfa114 100644 --- a/angrmanagement/ui/dialogs/command_palette.py +++ b/angrmanagement/ui/dialogs/command_palette.py @@ -119,7 +119,7 @@ def get_icon_color_and_text_for_item(self, item: Function) -> tuple[QColor | Non elif item.alignment: color = Conf.function_table_alignment_color else: - color = Qt.gray + color = Qt.GlobalColor.gray return (color, "f") def get_caption_for_item(self, item: Function) -> str: @@ -170,7 +170,7 @@ def _get_text_document(index): def paint(self, painter, option, index) -> None: if index.column() == 0: - if option.state & QStyle.State_Selected: + if option.state & QStyle.StateFlag.State_Selected: b = QBrush(option.palette.highlight()) painter.fillRect(option.rect, b) @@ -183,7 +183,9 @@ def paint(self, painter, option, index) -> None: annotation_text = model.get_annotation_for_item(item) if annotation_text: painter.drawText( - option.rect.marginsRemoved(QMargins(3, 3, 3, 3)), Qt.AlignRight | Qt.AlignVCenter, annotation_text + option.rect.marginsRemoved(QMargins(3, 3, 3, 3)), + Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter, + annotation_text, ) painter.save() @@ -195,8 +197,8 @@ def paint(self, painter, option, index) -> None: if icon_color: painter.fillRect(icon_rect, QBrush(QColor(icon_color))) if icon_text: - painter.setPen(Qt.white) - painter.drawText(icon_rect, Qt.AlignCenter, icon_text) + painter.setPen(Qt.GlobalColor.white) + painter.drawText(icon_rect, Qt.AlignmentFlag.AlignCenter, icon_text) painter.translate(self.icon_width, 0) td.drawContents(painter) @@ -272,9 +274,9 @@ def _get_selected(self): def keyPressEvent(self, event) -> None: key = event.key() - if key in {Qt.Key_Up, Qt.Key_Down}: + if key in {Qt.Key.Key_Up, Qt.Key.Key_Down}: self._view.keyPressEvent(event) - elif key in {Qt.Key_Enter, Qt.Key_Return}: + elif key in {Qt.Key.Key_Enter, Qt.Key.Key_Return}: self.accept() else: super().keyPressEvent(event) diff --git a/angrmanagement/ui/dialogs/env_config.py b/angrmanagement/ui/dialogs/env_config.py index 3d07125d1..b3461dba1 100644 --- a/angrmanagement/ui/dialogs/env_config.py +++ b/angrmanagement/ui/dialogs/env_config.py @@ -29,10 +29,10 @@ def __init__(self, items, parent) -> None: self.setColumnCount(len(header_labels)) self.setHorizontalHeaderLabels(header_labels) - self.setSelectionBehavior(QAbstractItemView.SelectItems) + self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectItems) header = self.horizontalHeader() - header.setSectionResizeMode(0, QHeaderView.Stretch) - header.setSectionResizeMode(1, QHeaderView.Stretch) + header.setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch) + header.setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch) self.setRowCount(len(items)) for idx, item in enumerate(items): @@ -71,7 +71,7 @@ class EnvConfig(QDialog): def __init__(self, env_config=None, instance: Instance | None = None, parent=None) -> None: super().__init__(parent) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) + self.setWindowFlags(self.windowFlags() & ~Qt.WindowType.WindowContextHelpButtonHint) self._instance = instance self._parent = parent self.env_config = env_config or [] diff --git a/angrmanagement/ui/dialogs/fs_mount.py b/angrmanagement/ui/dialogs/fs_mount.py index 98b3db42b..b79b84a8d 100644 --- a/angrmanagement/ui/dialogs/fs_mount.py +++ b/angrmanagement/ui/dialogs/fs_mount.py @@ -15,7 +15,7 @@ class FilesystemMount(QDialog): def __init__(self, fs_config=None, instance: Instance | None = None, parent=None) -> None: super().__init__(parent) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) + self.setWindowFlags(self.windowFlags() & ~Qt.WindowType.WindowContextHelpButtonHint) self._instance = instance self._parent = parent self.fs_config = fs_config or [] diff --git a/angrmanagement/ui/dialogs/func_doc.py b/angrmanagement/ui/dialogs/func_doc.py index d380a1371..e040edc6b 100644 --- a/angrmanagement/ui/dialogs/func_doc.py +++ b/angrmanagement/ui/dialogs/func_doc.py @@ -22,7 +22,7 @@ def __init__( super().__init__(parent) # initialization - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) + self.setWindowFlags(self.windowFlags() & ~Qt.WindowType.WindowContextHelpButtonHint) self.instance = instance self._addr = addr diff --git a/angrmanagement/ui/dialogs/function.py b/angrmanagement/ui/dialogs/function.py index 3c2ce5ebb..086de389e 100644 --- a/angrmanagement/ui/dialogs/function.py +++ b/angrmanagement/ui/dialogs/function.py @@ -32,7 +32,7 @@ def __init__(self, function, parent=None) -> None: self.workspace = GlobalInfo.main_window.workspace self.function = function self._init_widgets() - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) + self.setWindowFlags(self.windowFlags() & ~Qt.WindowType.WindowContextHelpButtonHint) self.setWindowTitle(f"Function {self.function.name}") self.setMinimumWidth(600) self.adjustSize() diff --git a/angrmanagement/ui/dialogs/hook.py b/angrmanagement/ui/dialogs/hook.py index 965123bf9..1729610b9 100644 --- a/angrmanagement/ui/dialogs/hook.py +++ b/angrmanagement/ui/dialogs/hook.py @@ -141,7 +141,7 @@ def _init_widgets(self) -> None: function_box.modes.append(PygmentsSyntaxHighlighter(function_box.document())) function_box.modes.append(AutoIndentMode()) - function_box.setWordWrapMode(QTextOption.WordWrap) + function_box.setWordWrapMode(QTextOption.WrapMode.WordWrap) self._function_box = function_box layout.addWidget(function_box, row, 0) @@ -151,7 +151,7 @@ def _init_widgets(self) -> None: buttons = QDialogButtonBox(parent=self) buttons.setStandardButtons(QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok) - buttons.button(QDialogButtonBox.Ok).setText("Append to Console") + buttons.button(QDialogButtonBox.StandardButton.Ok).setText("Append to Console") def do_ok() -> None: code = function_box.toPlainText() diff --git a/angrmanagement/ui/dialogs/jumpto.py b/angrmanagement/ui/dialogs/jumpto.py index 3ab3e2df0..ec6fccca1 100644 --- a/angrmanagement/ui/dialogs/jumpto.py +++ b/angrmanagement/ui/dialogs/jumpto.py @@ -58,7 +58,7 @@ def _init_widgets(self) -> None: buttons.setStandardButtons(QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok) buttons.accepted.connect(self._on_ok_clicked) buttons.rejected.connect(self.close) - self._ok_button = buttons.button(QDialogButtonBox.Ok) + self._ok_button = buttons.button(QDialogButtonBox.StandardButton.Ok) self._ok_button.setEnabled(False) self.main_layout.addWidget(buttons) diff --git a/angrmanagement/ui/dialogs/load_binary.py b/angrmanagement/ui/dialogs/load_binary.py index 69f0a8701..a2b5269c6 100644 --- a/angrmanagement/ui/dialogs/load_binary.py +++ b/angrmanagement/ui/dialogs/load_binary.py @@ -143,7 +143,7 @@ def _try_loading(self, partial_ld) -> None: dep_list: QListWidget = self.option_widgets["dep_list"] for dep in deps: dep_item = QListWidgetItem(dep) - dep_item.setData(Qt.CheckStateRole, Qt.Unchecked) + dep_item.setData(Qt.ItemDataRole.CheckStateRole, Qt.CheckState.Unchecked) dep_list.addItem(dep_item) if partial_ld.main_object is not None: @@ -186,7 +186,7 @@ def _init_widgets(self) -> None: filename = QLabel(self) filename.setText(self.filename) - layout.addWidget(filename_caption, 0, 0, Qt.AlignRight) + layout.addWidget(filename_caption, 0, 0, Qt.AlignmentFlag.AlignRight) layout.addWidget(filename, 0, 1) # md5 @@ -198,7 +198,7 @@ def _init_widgets(self) -> None: md5.setText(self.md5) md5.setReadOnly(True) - layout.addWidget(md5_caption, 1, 0, Qt.AlignRight) + layout.addWidget(md5_caption, 1, 0, Qt.AlignmentFlag.AlignRight) layout.addWidget(md5, 1, 1) # sha256 @@ -210,7 +210,7 @@ def _init_widgets(self) -> None: sha256.setText(self.sha256) sha256.setReadOnly(True) - layout.addWidget(sha256_caption, 2, 0, Qt.AlignRight) + layout.addWidget(sha256_caption, 2, 0, Qt.AlignmentFlag.AlignRight) layout.addWidget(sha256, 2, 1) # central tab @@ -456,7 +456,7 @@ def _on_ok_clicked(self) -> None: dep_list: QListWidget = self.option_widgets["dep_list"] for i in range(dep_list.count()): item: QListWidgetItem = dep_list.item(i) - if item.checkState() == Qt.Checked: + if item.checkState() == Qt.CheckState.Checked: force_load_libs.append(item.text()) else: skip_libs.add(item.text()) diff --git a/angrmanagement/ui/dialogs/load_docker_prompt.py b/angrmanagement/ui/dialogs/load_docker_prompt.py index cc79bd635..b27af9962 100644 --- a/angrmanagement/ui/dialogs/load_docker_prompt.py +++ b/angrmanagement/ui/dialogs/load_docker_prompt.py @@ -17,7 +17,7 @@ def __init__(self, parent=None) -> None: super().__init__(parent) self.setComboBoxItems(get_docker_images(self)) - self.setOption(QInputDialog.UsePlainTextEditForTextInput, True) + self.setOption(QInputDialog.InputDialogOption.UsePlainTextEditForTextInput, True) self.setLabelText("Select a docker target") self.setComboBoxEditable(False) self.setModal(True) diff --git a/angrmanagement/ui/dialogs/load_plugins.py b/angrmanagement/ui/dialogs/load_plugins.py index 608dad609..38bdca7bf 100644 --- a/angrmanagement/ui/dialogs/load_plugins.py +++ b/angrmanagement/ui/dialogs/load_plugins.py @@ -83,9 +83,9 @@ def _populate_installed_plugin_list(self) -> None: for _, desc in self._pm.loaded_plugins.items(): plugin_item = QPluginListWidgetItem(plugin_desc=desc) if self._pm.get_plugin_instance_by_name(desc.shortname) is not None: - plugin_item.setCheckState(Qt.Checked) + plugin_item.setCheckState(Qt.CheckState.Checked) else: - plugin_item.setCheckState(Qt.Unchecked) + plugin_item.setCheckState(Qt.CheckState.Unchecked) self._installed_plugin_list.addItem(plugin_item) def _init_widgets(self) -> None: @@ -107,9 +107,9 @@ def _init_widgets(self) -> None: # def _on_ok_clicked(self) -> None: - list_items: list[QPluginListWidgetItem] = self._installed_plugin_list.findItems("*", Qt.MatchWildcard) + list_items: list[QPluginListWidgetItem] = self._installed_plugin_list.findItems("*", Qt.MatchFlag.MatchWildcard) for i in list_items: - checked = i.checkState() == Qt.Checked + checked = i.checkState() == Qt.CheckState.Checked if checked and self._pm.get_plugin_instance_by_name(i.plugin_desc.shortname) is None: self._pm.activate_plugin_by_name(i.plugin_desc.shortname) @@ -133,6 +133,6 @@ def _on_load_clicked(self) -> None: for plugin in plugins: plugin_item = QPluginListWidgetItem(plugin_desc=plugin) - plugin_item.setCheckState(Qt.Unchecked) + plugin_item.setCheckState(Qt.CheckState.Unchecked) self._pm.loaded_plugins[plugin.shortname] = plugin self._installed_plugin_list.addItem(plugin_item) diff --git a/angrmanagement/ui/dialogs/new_state.py b/angrmanagement/ui/dialogs/new_state.py index 64ad6ec4d..73eb36dda 100644 --- a/angrmanagement/ui/dialogs/new_state.py +++ b/angrmanagement/ui/dialogs/new_state.py @@ -306,7 +306,9 @@ def mode_changed() -> None: self._options.clear() self._options.update(angr.sim_options.modes[mode_combo.currentData()]) for child in children_items: - child.setCheckState(0, Qt.Checked if child.text(0) in self._options else Qt.Unchecked) + child.setCheckState( + 0, Qt.CheckState.Checked if child.text(0) in self._options else Qt.CheckState.Unchecked + ) mode_combo.currentIndexChanged.connect(mode_changed) self._options.clear() @@ -331,21 +333,21 @@ def mode_changed() -> None: continue parent = QTreeWidgetItem(options_tree) parent.setText(0, name) - parent.setFlags(parent.flags() | Qt.ItemIsAutoTristate | Qt.ItemIsUserCheckable) + parent.setFlags(parent.flags() | Qt.ItemFlag.ItemIsAutoTristate | Qt.ItemFlag.ItemIsUserCheckable) for option in members: child = QTreeWidgetItem(parent) child.setText(0, option) - child.setFlags(child.flags() | Qt.ItemIsUserCheckable) - child.setCheckState(0, Qt.Checked if option in self._options else Qt.Unchecked) + child.setFlags(child.flags() | Qt.ItemFlag.ItemIsUserCheckable) + child.setCheckState(0, Qt.CheckState.Checked if option in self._options else Qt.CheckState.Unchecked) children_items.append(child) parent = QTreeWidgetItem(options_tree) parent.setText(0, "All options") - parent.setFlags(parent.flags() | Qt.ItemIsAutoTristate | Qt.ItemIsUserCheckable) + parent.setFlags(parent.flags() | Qt.ItemFlag.ItemIsAutoTristate | Qt.ItemFlag.ItemIsUserCheckable) for option in {x for x in angr.sim_options.__dict__.values() if isinstance(x, str) and is_option(x)}: child = QTreeWidgetItem(parent) child.setText(0, option) - child.setFlags(child.flags() | Qt.ItemIsUserCheckable) - child.setCheckState(0, Qt.Checked if option in self._options else Qt.Unchecked) + child.setFlags(child.flags() | Qt.ItemFlag.ItemIsUserCheckable) + child.setCheckState(0, Qt.CheckState.Checked if option in self._options else Qt.CheckState.Unchecked) children_items.append(child) def maintain_model(item: QTreeWidgetItem, _) -> None: @@ -446,7 +448,7 @@ def do_ok() -> None: self.close() - ok_button = buttons.button(QDialogButtonBox.Ok) + ok_button = buttons.button(QDialogButtonBox.StandardButton.Ok) buttons.accepted.connect(do_ok) def validation_update() -> None: diff --git a/angrmanagement/ui/dialogs/preferences.py b/angrmanagement/ui/dialogs/preferences.py index d6b85632d..275c14378 100644 --- a/angrmanagement/ui/dialogs/preferences.py +++ b/angrmanagement/ui/dialogs/preferences.py @@ -135,7 +135,7 @@ def _init_widgets(self) -> None: scheme_loader_layout = QHBoxLayout() color_scheme_lbl = QLabel("Load Theme:") - color_scheme_lbl.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)) + color_scheme_lbl.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)) scheme_loader_layout.addWidget(color_scheme_lbl) self._schemes_combo = QComboBox(self) @@ -210,7 +210,7 @@ def _init_widgets(self) -> None: # Log format log_format_layout = QHBoxLayout() log_format_lbl = QLabel("Log datetime Format String:") - log_format_lbl.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)) + log_format_lbl.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)) log_format_layout.addWidget(log_format_lbl) self.log_format_entry = QComboBox(self) @@ -270,8 +270,8 @@ def __init__(self, workspace: Workspace, parent=None) -> None: def _init_widgets(self) -> None: # contents contents = QListWidget() - contents.setViewMode(QListView.ListMode) - contents.setMovement(QListView.Static) + contents.setViewMode(QListView.ViewMode.ListMode) + contents.setMovement(QListView.Movement.Static) # set the width to match the width of the content contents.setSizeAdjustPolicy(QAbstractScrollArea.SizeAdjustPolicy.AdjustToContents) @@ -295,7 +295,7 @@ def item_changed(item: QListWidgetItem) -> None: # buttons buttons = QDialogButtonBox(parent=self) buttons.setStandardButtons(QDialogButtonBox.StandardButton.Close | QDialogButtonBox.StandardButton.Ok) - buttons.button(QDialogButtonBox.Ok).setText("Save") + buttons.button(QDialogButtonBox.StandardButton.Ok).setText("Save") buttons.accepted.connect(self._on_ok_clicked) buttons.rejected.connect(self.close) diff --git a/angrmanagement/ui/dialogs/rename.py b/angrmanagement/ui/dialogs/rename.py index 68ae87772..7839bf61f 100644 --- a/angrmanagement/ui/dialogs/rename.py +++ b/angrmanagement/ui/dialogs/rename.py @@ -71,7 +71,7 @@ def _init_widgets(self) -> None: buttons.setStandardButtons(QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok) buttons.accepted.connect(self._on_ok_clicked) buttons.rejected.connect(self.close) - self._ok_button = buttons.button(QDialogButtonBox.Ok) + self._ok_button = buttons.button(QDialogButtonBox.StandardButton.Ok) self._ok_button.setEnabled(False) self.main_layout.addWidget(buttons) diff --git a/angrmanagement/ui/dialogs/rename_label.py b/angrmanagement/ui/dialogs/rename_label.py index 81f4ee7da..3ba95bae1 100644 --- a/angrmanagement/ui/dialogs/rename_label.py +++ b/angrmanagement/ui/dialogs/rename_label.py @@ -90,7 +90,7 @@ def _init_widgets(self) -> None: buttons.setStandardButtons(QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok) buttons.accepted.connect(self._on_ok_clicked) buttons.rejected.connect(self.close) - self._ok_button = buttons.button(QDialogButtonBox.Ok) + self._ok_button = buttons.button(QDialogButtonBox.StandardButton.Ok) self._ok_button.setEnabled(False) self.main_layout.addWidget(buttons) diff --git a/angrmanagement/ui/dialogs/rename_node.py b/angrmanagement/ui/dialogs/rename_node.py index 3c39befe4..db3f6720e 100644 --- a/angrmanagement/ui/dialogs/rename_node.py +++ b/angrmanagement/ui/dialogs/rename_node.py @@ -61,7 +61,7 @@ def __init__( super().__init__(parent) # initialization - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) + self.setWindowFlags(self.windowFlags() & ~Qt.WindowType.WindowContextHelpButtonHint) self._code_view = code_view self._node = node @@ -143,7 +143,7 @@ def _init_widgets(self) -> None: buttons.setStandardButtons(QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok) buttons.accepted.connect(self._on_ok_clicked) buttons.rejected.connect(self.close) - self._ok_button = buttons.button(QDialogButtonBox.Ok) + self._ok_button = buttons.button(QDialogButtonBox.StandardButton.Ok) self._ok_button.setEnabled(False) self.main_layout.addWidget(buttons) diff --git a/angrmanagement/ui/dialogs/retype_node.py b/angrmanagement/ui/dialogs/retype_node.py index 203e1bcd6..00444dbdd 100644 --- a/angrmanagement/ui/dialogs/retype_node.py +++ b/angrmanagement/ui/dialogs/retype_node.py @@ -112,7 +112,7 @@ def __init__( self._ok_button: QPushButton = None self.setWindowTitle("Specify a type") - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) + self.setWindowFlags(self.windowFlags() & ~Qt.WindowType.WindowContextHelpButtonHint) self.main_layout = QVBoxLayout() @@ -169,7 +169,7 @@ def _init_widgets(self) -> None: buttons.setStandardButtons(QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok) buttons.accepted.connect(self._on_ok_clicked) buttons.rejected.connect(self._on_cancel_clicked) - self._ok_button = buttons.button(QDialogButtonBox.Ok) + self._ok_button = buttons.button(QDialogButtonBox.StandardButton.Ok) self._ok_button.setEnabled(False) self.main_layout.addWidget(buttons) diff --git a/angrmanagement/ui/dialogs/socket_config.py b/angrmanagement/ui/dialogs/socket_config.py index 4564935ea..9125eb212 100644 --- a/angrmanagement/ui/dialogs/socket_config.py +++ b/angrmanagement/ui/dialogs/socket_config.py @@ -96,12 +96,12 @@ def createEditor(self, widget, option, index): return editor def setEditorData(self, editor, index) -> None: - value = index.model().data(index, role=Qt.DisplayRole) + value = index.model().data(index, role=Qt.ItemDataRole.DisplayRole) if value: editor.setText(str(value)) def setModelData(self, editor, model, index) -> None: - model.setData(index, editor.toPlainText(), role=Qt.DisplayRole) + model.setData(index, editor.toPlainText(), role=Qt.ItemDataRole.DisplayRole) def updateEditorGeometry(self, editor, option, index) -> None: editor.setGeometry(option.rect) @@ -262,7 +262,7 @@ class SocketView(QTreeView): def __init__(self) -> None: super().__init__() - self.setTextElideMode(Qt.ElideNone) + self.setTextElideMode(Qt.TextElideMode.ElideNone) def _action_accepted_socket(self) -> None: current = self.currentIndex() @@ -301,7 +301,7 @@ class SocketConfig(QDialog): def __init__(self, socket_config=None, instance: Instance | None = None, parent=None) -> None: super().__init__(parent) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) + self.setWindowFlags(self.windowFlags() & ~Qt.WindowType.WindowContextHelpButtonHint) self._instance = instance self._editor = SimPackagePersistentEditor(instance=instance) self._parent = parent diff --git a/angrmanagement/ui/dialogs/type_editor.py b/angrmanagement/ui/dialogs/type_editor.py index 529ee0f3f..948a66a34 100644 --- a/angrmanagement/ui/dialogs/type_editor.py +++ b/angrmanagement/ui/dialogs/type_editor.py @@ -46,7 +46,7 @@ def __init__( self._init_widgets(base_text, multiline) self.setWindowTitle("Type editor") - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) + self.setWindowFlags(self.windowFlags() & ~Qt.WindowType.WindowContextHelpButtonHint) self.result = [] @@ -55,7 +55,7 @@ def _init_widgets(self, base_text, multiline) -> None: buttons.setStandardButtons(QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok) buttons.accepted.connect(self._on_ok_pressed) buttons.rejected.connect(self._on_cancel_pressed) - self._ok_button = buttons.button(QDialogButtonBox.Ok) + self._ok_button = buttons.button(QDialogButtonBox.StandardButton.Ok) if multiline: editor = QCommentTextBox( diff --git a/angrmanagement/ui/dialogs/welcome.py b/angrmanagement/ui/dialogs/welcome.py index 7fce2a17e..c634f790d 100644 --- a/angrmanagement/ui/dialogs/welcome.py +++ b/angrmanagement/ui/dialogs/welcome.py @@ -39,7 +39,7 @@ def _init_widgets(self) -> None: banner_pixmap = QPixmap(os.path.join(IMG_LOCATION, "angr-splash.png")) banner_view = QGraphicsView(self) banner_view.setContentsMargins(0, 0, 0, 0) - banner_view.setFrameStyle(QFrame.NoFrame) + banner_view.setFrameStyle(QFrame.Shape.NoFrame) banner_view.resize(banner_pixmap.size()) banner_scene = QGraphicsScene() banner_view.setScene(banner_scene) @@ -47,7 +47,7 @@ def _init_widgets(self) -> None: font = QApplication.font() font.setPointSizeF(9.0) ti = banner_scene.addSimpleText(__version__, font) - ti.setBrush(Qt.white) + ti.setBrush(Qt.GlobalColor.white) ti.moveBy(pi.boundingRect().width() - ti.boundingRect().width() - 6, 6) # Recent files diff --git a/angrmanagement/ui/dialogs/xref.py b/angrmanagement/ui/dialogs/xref.py index 89ae74c80..fb979adf6 100644 --- a/angrmanagement/ui/dialogs/xref.py +++ b/angrmanagement/ui/dialogs/xref.py @@ -58,7 +58,9 @@ def __init__( self._init_widgets() - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint | Qt.WindowCloseButtonHint) + self.setWindowFlags( + self.windowFlags() & ~Qt.WindowType.WindowContextHelpButtonHint | Qt.WindowType.WindowCloseButtonHint + ) self.setMinimumSize(self.sizeHint()) self.adjustSize() diff --git a/angrmanagement/ui/main_window.py b/angrmanagement/ui/main_window.py index 2a74044ef..13e31157a 100644 --- a/angrmanagement/ui/main_window.py +++ b/angrmanagement/ui/main_window.py @@ -82,7 +82,9 @@ def __init__(self, main_window: MainWindow) -> None: self._main_window: MainWindow = main_window def eventFilter(self, qobject, event) -> bool: - if event.type() == QEvent.KeyPress and QKeySequence(event.keyCombination()) == QKeySequence("Ctrl+Shift+P"): + if event.type() == QEvent.Type.KeyPress and QKeySequence(event.keyCombination()) == QKeySequence( + "Ctrl+Shift+P" + ): self._main_window.show_command_palette(qobject) return True return False @@ -108,7 +110,7 @@ def eventFilter(self, qobject, event) -> bool: # Key Event propagation will begin at QWindow and continue down the widget tree. Use KeyEvent on QWindow to # distinguish unique key presses, then intercept KeyEvent at first QWidget the event is propagated to. - if event.type() == QEvent.KeyPress: + if event.type() == QEvent.Type.KeyPress: if isinstance(qobject, QWindow) and qobject.modality() == Qt.WindowModality.NonModal: self._did_process_qwindow_event = True return False @@ -263,7 +265,7 @@ def open_newstate_dialog(self) -> None: new_state_dialog.exec_() def open_doc_link(self) -> None: - QDesktopServices.openUrl(QUrl("https://docs.angr.io/", QUrl.TolerantMode)) + QDesktopServices.openUrl(QUrl("https://docs.angr.io/", QUrl.ParsingMode.TolerantMode)) def open_about_dialog(self) -> None: dlg = LoadAboutDialog() @@ -309,7 +311,9 @@ def _init_statusbar(self) -> None: self._progress_dialog = QProgressDialog("Waiting...", "Cancel", 0, 100, self) self._progress_dialog.setAutoClose(False) - self._progress_dialog.setWindowFlags(self._progress_dialog.windowFlags() & ~Qt.WindowContextHelpButtonHint) + self._progress_dialog.setWindowFlags( + self._progress_dialog.windowFlags() & ~Qt.WindowType.WindowContextHelpButtonHint + ) self._progress_dialog.setModal(True) self._progress_dialog.setMinimumDuration(2**31 - 1) @@ -405,13 +409,13 @@ def _init_shortcuts(self) -> None: self._raise_view(0) # Toggle exec breakpoint - QShortcut(QKeySequence(Qt.Key_F2), self, self.workspace.toggle_exec_breakpoint) + QShortcut(QKeySequence(Qt.Key.Key_F2), self, self.workspace.toggle_exec_breakpoint) # Single step - QShortcut(QKeySequence(Qt.Key_F7), self, self.workspace.step_forward) + QShortcut(QKeySequence(Qt.Key.Key_F7), self, self.workspace.step_forward) # Run - QShortcut(QKeySequence(Qt.Key_F9), self, self.workspace.continue_forward) + QShortcut(QKeySequence(Qt.Key.Key_F9), self, self.workspace.continue_forward) def init_shortcuts_on_dock(self, dock_widget) -> None: """ @@ -512,9 +516,9 @@ def _init_url_scheme_handler(self) -> None: "by registering the angr:// protocol to the current user. Do you want to " "register it? You may unregister at any " "time in Preferences.", - defaultButton=QMessageBox.Yes, + defaultButton=QMessageBox.StandardButton.Yes, ) - if btn == QMessageBox.Yes: + if btn == QMessageBox.StandardButton.Yes: try: AngrUrlScheme().register_url_scheme() except (ValueError, FileNotFoundError) as ex: @@ -595,16 +599,18 @@ def closeEvent(self, event) -> None: msgbox = QMessageBox() msgbox.setWindowTitle("Save database") msgbox.setText("angr management is about to exit. Do you want to save the database?") - msgbox.setIcon(QMessageBox.Question) + msgbox.setIcon(QMessageBox.Icon.Question) msgbox.setWindowIcon(self.windowIcon()) - msgbox.setStandardButtons(QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel) - msgbox.setDefaultButton(QMessageBox.Yes) + msgbox.setStandardButtons( + QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No | QMessageBox.StandardButton.Cancel + ) + msgbox.setDefaultButton(QMessageBox.StandardButton.Yes) r = msgbox.exec_() - if r == QMessageBox.Cancel: + if r == QMessageBox.StandardButton.Cancel: event.ignore() return - elif r == QMessageBox.Yes: + elif r == QMessageBox.StandardButton.Yes: save_r = self.save_database() if not save_r: # failed to save the database @@ -740,9 +746,9 @@ def load_file(self, file_path) -> None: self, "Downloading a file", f"Do you want to download a file from {file_path} and open it in angr management?", - defaultButton=QMessageBox.Yes, + defaultButton=QMessageBox.StandardButton.Yes, ) - if r == QMessageBox.Yes: + if r == QMessageBox.StandardButton.Yes: try: target_path = download_url(file_path, parent=self, to_file=True, file_path=None) except InvalidURLError: @@ -929,7 +935,7 @@ def progress_done(self) -> None: self._progress_dialog.hide() def bring_to_front(self) -> None: - self.setWindowState((self.windowState() & ~Qt.WindowMinimized) | Qt.WindowActive) + self.setWindowState((self.windowState() & ~Qt.WindowState.WindowMinimized) | Qt.WindowState.WindowActive) self.activateWindow() self.raise_() diff --git a/angrmanagement/ui/menus/analyze_menu.py b/angrmanagement/ui/menus/analyze_menu.py index 76120016d..dd8d67de2 100644 --- a/angrmanagement/ui/menus/analyze_menu.py +++ b/angrmanagement/ui/menus/analyze_menu.py @@ -21,14 +21,14 @@ def __init__(self, main_window: MainWindow) -> None: MenuEntry( "&Run Analysis...", main_window.run_analysis, - shortcut=QKeySequence(Qt.Key_F4), + shortcut=QKeySequence(Qt.Key.Key_F4), icon=icon("run-analysis"), ), MenuSeparator(), MenuEntry( "&Decompile", main_window.decompile_current_function, - shortcut=QKeySequence(Qt.Key_F5), + shortcut=QKeySequence(Qt.Key.Key_F5), icon=icon("pseudocode-view"), ), MenuEntry( @@ -36,6 +36,6 @@ def __init__(self, main_window: MainWindow) -> None: main_window.view_proximity_for_current_function, shortcut=QKeySequence("Ctrl+B"), ), - MenuEntry("&Interact", main_window.interact, shortcut=QKeySequence(Qt.Key_F6)), + MenuEntry("&Interact", main_window.interact, shortcut=QKeySequence(Qt.Key.Key_F6)), ], ) diff --git a/angrmanagement/ui/menus/file_menu.py b/angrmanagement/ui/menus/file_menu.py index bd6f8db9d..ada4b8cc1 100644 --- a/angrmanagement/ui/menus/file_menu.py +++ b/angrmanagement/ui/menus/file_menu.py @@ -80,7 +80,7 @@ def __init__(self, main_window: MainWindow) -> None: "&Preferences...", main_window.preferences, shortcut=QKeySequence("Ctrl+Comma"), - role=QAction.PreferencesRole, + role=QAction.MenuRole.PreferencesRole, icon=icon("preferences") if platform.system() != "Darwin" else None, ), MenuSeparator(), diff --git a/angrmanagement/ui/menus/help_menu.py b/angrmanagement/ui/menus/help_menu.py index cb0224f26..48134cd17 100644 --- a/angrmanagement/ui/menus/help_menu.py +++ b/angrmanagement/ui/menus/help_menu.py @@ -26,6 +26,6 @@ def __init__(self, main_window: MainWindow) -> None: "&Documentation", main_window.open_doc_link, shortcut=QKeySequence("Alt+H"), icon=icon("docs") ), MenuSeparator(), - MenuEntry("About angr...", main_window.open_about_dialog, role=QAction.AboutRole), + MenuEntry("About angr...", main_window.open_about_dialog, role=QAction.MenuRole.AboutRole), ] ) diff --git a/angrmanagement/ui/toolbar_manager.py b/angrmanagement/ui/toolbar_manager.py index c09158550..88bc9a93e 100644 --- a/angrmanagement/ui/toolbar_manager.py +++ b/angrmanagement/ui/toolbar_manager.py @@ -34,9 +34,9 @@ def show_toolbar_by_class(self, cls: type[Toolbar]) -> None: self.active[cls] = tb qtb = tb.qtoolbar() if isinstance(qtb, QDockWidget): - self._main_window.addDockWidget(Qt.TopDockWidgetArea, qtb) + self._main_window.addDockWidget(Qt.DockWidgetArea.TopDockWidgetArea, qtb) else: - self._main_window.addToolBar(Qt.TopToolBarArea, qtb) + self._main_window.addToolBar(Qt.ToolBarArea.TopToolBarArea, qtb) else: self.active[cls].qtoolbar().show() diff --git a/angrmanagement/ui/toolbars/nav_toolbar.py b/angrmanagement/ui/toolbars/nav_toolbar.py index 21085225c..569f5c9b5 100644 --- a/angrmanagement/ui/toolbars/nav_toolbar.py +++ b/angrmanagement/ui/toolbars/nav_toolbar.py @@ -29,7 +29,7 @@ def __init__(self, jump_history: JumpHistory, direction_forward: bool = False, p super().__init__(parent) self._dir_fwd = direction_forward self._jump_history = jump_history - self.setPopupMode(QToolButton.MenuButtonPopup) + self.setPopupMode(QToolButton.ToolButtonPopupMode.MenuButtonPopup) self._init_menu() if direction_forward: @@ -98,7 +98,7 @@ def __init__( def qtoolbar(self) -> QToolBar: tb = QToolBar(self.window) if self._small_icon: - sm_ico_pm = tb.style().pixelMetric(QStyle.PM_SmallIconSize, None, tb) + sm_ico_pm = tb.style().pixelMetric(QStyle.PixelMetric.PM_SmallIconSize, None, tb) tb.setIconSize(QSize(sm_ico_pm, sm_ico_pm)) back_btn = NavToolButton(self._jump_history, False, tb) diff --git a/angrmanagement/ui/toolbars/toolbar_dock.py b/angrmanagement/ui/toolbars/toolbar_dock.py index dd80a44bd..395132732 100644 --- a/angrmanagement/ui/toolbars/toolbar_dock.py +++ b/angrmanagement/ui/toolbars/toolbar_dock.py @@ -23,11 +23,11 @@ def paintEvent(self, _) -> None: opt = QStyleOptionToolBar() style = self.style() if self.orientation: - opt.state = QStyle.State_Horizontal - opt.features = QStyleOptionToolBar.Movable - opt.toolBarArea = Qt.NoToolBarArea + opt.state = QStyle.StateFlag.State_Horizontal + opt.features = QStyleOptionToolBar.ToolBarFeature.Movable + opt.toolBarArea = Qt.ToolBarArea.NoToolBarArea opt.rect = r - style.drawPrimitive(QStyle.PE_IndicatorToolBarHandle, opt, painter, self) + style.drawPrimitive(QStyle.PrimitiveElement.PE_IndicatorToolBarHandle, opt, painter, self) painter.end() def sizeHint(self): diff --git a/angrmanagement/ui/view_manager.py b/angrmanagement/ui/view_manager.py index 41d87b07b..2e5d0e803 100644 --- a/angrmanagement/ui/view_manager.py +++ b/angrmanagement/ui/view_manager.py @@ -98,7 +98,7 @@ def add_view(self, view: BaseView) -> None: self.view_to_dock[view] = dw if view.default_docking_position == "center": - policy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + policy = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) policy.setHorizontalStretch(1) policy.setVerticalStretch(1) area_widget.setSizePolicy(policy) diff --git a/angrmanagement/ui/views/breakpoints_view.py b/angrmanagement/ui/views/breakpoints_view.py index 33dfa68b0..350548814 100644 --- a/angrmanagement/ui/views/breakpoints_view.py +++ b/angrmanagement/ui/views/breakpoints_view.py @@ -48,7 +48,7 @@ def columnCount(self, parent: PySide6.QtCore.QModelIndex = ...) -> int: # pylin def headerData( self, section: int, orientation: PySide6.QtCore.Qt.Orientation, role: int = ... ) -> Any: # pylint:disable=unused-argument - if role != Qt.DisplayRole: + if role != Qt.ItemDataRole.DisplayRole: return None if section < len(self.Headers): return self.Headers[section] @@ -61,7 +61,7 @@ def data(self, index: PySide6.QtCore.QModelIndex, role: int = ...) -> Any: if row >= len(self.breakpoint_mgr.breakpoints): return None col = index.column() - if role == Qt.DisplayRole: + if role == Qt.ItemDataRole.DisplayRole: return self._get_column_text(self.breakpoint_mgr.breakpoints[row], col) else: return None @@ -98,14 +98,14 @@ def __init__(self, breakpoint_mgr: BreakpointManager, workspace: Workspace) -> N vheader.setVisible(False) vheader.setDefaultSectionSize(20) - self.setSelectionBehavior(QAbstractItemView.SelectRows) - self.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel) + self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) + self.setHorizontalScrollMode(QAbstractItemView.ScrollMode.ScrollPerPixel) self.model: QBreakpointTableModel = QBreakpointTableModel(self.breakpoint_mgr) self.setModel(self.model) for col in range(len(QBreakpointTableModel.Headers)): - hheader.setSectionResizeMode(col, QHeaderView.ResizeToContents) + hheader.setSectionResizeMode(col, QHeaderView.ResizeMode.ResizeToContents) hheader.setStretchLastSection(True) self.doubleClicked.connect(self._on_cell_double_click) diff --git a/angrmanagement/ui/views/call_explorer_view.py b/angrmanagement/ui/views/call_explorer_view.py index 18d1c01a4..22a9cb7a1 100644 --- a/angrmanagement/ui/views/call_explorer_view.py +++ b/angrmanagement/ui/views/call_explorer_view.py @@ -102,7 +102,7 @@ def _init_widgets(self) -> None: self._tree.setModel(self._model) self._tree.setFont(QFont(Conf.disasm_font)) header = self._tree.header() - header.setSectionResizeMode(QHeaderView.ResizeToContents) + header.setSectionResizeMode(QHeaderView.ResizeMode.ResizeToContents) self._tree.expanded.connect(self._on_item_expanded) self._tree.clicked.connect(self._on_item_clicked) self._tree.doubleClicked.connect(self._on_item_double_clicked) diff --git a/angrmanagement/ui/views/code_view.py b/angrmanagement/ui/views/code_view.py index 212d562d3..4a3c73a95 100644 --- a/angrmanagement/ui/views/code_view.py +++ b/angrmanagement/ui/views/code_view.py @@ -178,7 +178,7 @@ def highlight_chunks(self, chunks) -> None: sel = QTextEdit.ExtraSelection() sel.cursor = self._textedit.textCursor() sel.cursor.setPosition(start) - sel.cursor.setPosition(end, QTextCursor.KeepAnchor) + sel.cursor.setPosition(end, QTextCursor.MoveMode.KeepAnchor) sel.format.setBackground(Conf.pseudocode_highlight_color) extra_selections.append(sel) self._textedit.setExtraSelections(extra_selections) @@ -464,11 +464,13 @@ def _on_view_selector_changed(self, index) -> None: def _init_widgets(self) -> None: window = QMainWindow() - window.setWindowFlags(Qt.Widget) + window.setWindowFlags(Qt.WindowType.Widget) # pseudo code text box self._textedit = QCCodeEdit(self) - self._textedit.setTextInteractionFlags(Qt.TextSelectableByKeyboard | Qt.TextSelectableByMouse) + self._textedit.setTextInteractionFlags( + Qt.TextInteractionFlag.TextSelectableByKeyboard | Qt.TextInteractionFlag.TextSelectableByMouse + ) self._textedit.setLineWrapMode(QCCodeEdit.NoWrap) self._textedit.background = Conf.palette_base window.setCentralWidget(self._textedit) @@ -476,7 +478,7 @@ def _init_widgets(self) -> None: # decompilation options self._options = QDecompilationOptions(self, self.instance) options_dock = QDockWidget("Decompilation Options", self._options) - window.addDockWidget(Qt.RightDockWidgetArea, options_dock) + window.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, options_dock) options_dock.setWidget(self._options) options_dock.setVisible(False) diff --git a/angrmanagement/ui/views/data_dep_view.py b/angrmanagement/ui/views/data_dep_view.py index 246eeb694..9366065c7 100644 --- a/angrmanagement/ui/views/data_dep_view.py +++ b/angrmanagement/ui/views/data_dep_view.py @@ -129,9 +129,9 @@ def run_analysis(self) -> None: self._data_dep_graph = data_dep.graph self.reload() - def hover_enter_block(self, block: QDataDepGraphBlock, modifiers: QtCore.Qt.KeyboardModifierMask) -> None: + def hover_enter_block(self, block: QDataDepGraphBlock, modifiers: QtCore.Qt.KeyboardModifier) -> None: # If the user is holding down 'Control' while hovering, should show descendants instead - if modifiers & QtCore.Qt.ControlModifier: + if modifiers & QtCore.Qt.KeyboardModifier.ControlModifier: self._traced_descendants = self._graph_widget.get_descendants(block) else: self._traced_ancestors = self._graph_widget.get_ancestors(block) @@ -250,7 +250,7 @@ def keyPressEvent(self, event: QtGui.QKeyEvent) -> None: key = event.key() modifiers = event.modifiers() - if key == QtCore.Qt.Key_F and modifiers & QtCore.Qt.ControlModifier: + if key == QtCore.Qt.Key.Key_F and modifiers & QtCore.Qt.KeyboardModifier.ControlModifier: # User would like to search search_dialog = QDataDepGraphSearch(self, self.graph_widget) search_dialog.setModal(False) @@ -261,7 +261,7 @@ def keyPressEvent(self, event: QtGui.QKeyEvent) -> None: def mousePressEvent(self, event: QtGui.QMouseEvent) -> None: button = event.button() - if button == QtCore.Qt.RightButton and event: + if button == QtCore.Qt.MouseButton.RightButton and event: options_menu = QtWidgets.QMenu("Options", self) if self._data_dep_graph is self._data_dep.graph: toggle_text = "Hide temp nodes" diff --git a/angrmanagement/ui/views/disassembly_view.py b/angrmanagement/ui/views/disassembly_view.py index c8f1bc758..3949c032d 100644 --- a/angrmanagement/ui/views/disassembly_view.py +++ b/angrmanagement/ui/views/disassembly_view.py @@ -272,43 +272,43 @@ def on_variable_recovered(self, func_addr: int) -> None: def keyPressEvent(self, event) -> None: key = event.key() - if key == Qt.Key_G: + if key == Qt.Key.Key_G: # jump to window self.popup_jumpto_dialog() return - elif key == Qt.Key_Left and QApplication.keyboardModifiers() & Qt.ALT != 0: + elif key == Qt.Key.Key_Left and QApplication.keyboardModifiers() & Qt.Modifier.ALT != 0: # jump back self.jump_back() return - elif key == Qt.Key_Right and QApplication.keyboardModifiers() & Qt.ALT != 0: + elif key == Qt.Key.Key_Right and QApplication.keyboardModifiers() & Qt.Modifier.ALT != 0: # jump forward self.jump_forward() return - elif key == Qt.Key_A: + elif key == Qt.Key.Key_A: # switch between highlight mode self.toggle_smart_highlighting(not self.infodock.smart_highlighting) return - elif key == Qt.Key_Tab: + elif key == Qt.Key.Key_Tab: # decompile self.decompile_current_function() return - elif key == Qt.Key_Semicolon: + elif key == Qt.Key.Key_Semicolon: # add comment self.popup_comment_dialog() return - elif key == Qt.Key_Space: + elif key == Qt.Key.Key_Space: # switch to linear view self.toggle_disasm_view() event.accept() return - elif key == Qt.Key_Escape: + elif key == Qt.Key.Key_Escape: # jump back self.jump_back() return - elif key == Qt.Key_C: + elif key == Qt.Key.Key_C: self.define_code() return - elif key == Qt.Key_U: + elif key == Qt.Key.Key_U: self.undefine_code() return @@ -515,7 +515,7 @@ def popup_dependson_dialog(self, addr: int | None = None, use_operand: bool = Fa self, "No operand", "Please select an operand first.", - buttons=QMessageBox.Ok, + buttons=QMessageBox.StandardButton.Ok, ) return else: diff --git a/angrmanagement/ui/views/hex_view.py b/angrmanagement/ui/views/hex_view.py index cc35c848e..50f3542d5 100644 --- a/angrmanagement/ui/views/hex_view.py +++ b/angrmanagement/ui/views/hex_view.py @@ -44,6 +44,9 @@ from .view import SynchronizedInstanceView if TYPE_CHECKING: + from PySide6.QtGui import QPainter + from PySide6.QtWidgets import QStyleOptionGraphicsItem, QWidget + from angrmanagement.data.instance import Instance from angrmanagement.ui.workspace import Workspace @@ -96,7 +99,7 @@ class BreakpointHighlightRegion(HexHighlightRegion): """ def __init__(self, bp: Breakpoint, view: HexView) -> None: - super().__init__(Qt.cyan, bp.addr, bp.size) + super().__init__(Qt.GlobalColor.cyan, bp.addr, bp.size) self.bp: Breakpoint = bp self.view: HexView = view @@ -139,7 +142,7 @@ class PatchHighlightRegion(HexHighlightRegion): """ def __init__(self, patch: Patch, view: HexView) -> None: - super().__init__(Qt.yellow, patch.addr, len(patch)) + super().__init__(Qt.GlobalColor.yellow, patch.addr, len(patch)) self.patch: Patch = patch self.view: HexView = view @@ -174,10 +177,10 @@ def revert_with_prompt(self) -> None: dlg = QMessageBox() dlg.setWindowTitle("Revert patch") dlg.setText("Are you sure you want to revert this patch?") - dlg.setIcon(QMessageBox.Question) - dlg.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel) - dlg.setDefaultButton(QMessageBox.Cancel) - if dlg.exec_() != QMessageBox.Yes: + dlg.setIcon(QMessageBox.Icon.Question) + dlg.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.Cancel) + dlg.setDefaultButton(QMessageBox.StandardButton.Cancel) + if dlg.exec_() != QMessageBox.StandardButton.Yes: return self.revert() @@ -247,9 +250,11 @@ class HexGraphicsObject(QGraphicsObject): def __init__(self) -> None: super().__init__() - self.setFlag(QGraphicsItem.ItemUsesExtendedStyleOption, True) # Give me more specific paint update rect info - self.setFlag(QGraphicsItem.ItemIsFocusable, True) # Give me focus/key events - self.setFlag(QGraphicsItem.ItemClipsToShape, True) + self.setFlag( + QGraphicsItem.GraphicsItemFlag.ItemUsesExtendedStyleOption, True + ) # Give me more specific paint update rect info + self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsFocusable, True) # Give me focus/key events + self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemClipsToShape, True) self.display_offset_addr: HexAddress = 0 self.display_num_rows: int = 1 self.display_start_addr: HexAddress = 0 @@ -604,13 +609,13 @@ def mousePressEvent(self, event: QGraphicsSceneMouseEvent) -> None: """ Handle mouse press events (e.g. updating selection). """ - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: addr = self.point_to_addr(event.pos()) if addr is None: return addr, ascii_column = addr self.mouse_pressed = True - if QApplication.keyboardModifiers() in (Qt.ShiftModifier,): + if QApplication.keyboardModifiers() in (Qt.KeyboardModifier.ShiftModifier,): if self.selection_start is None: self.begin_selection() else: @@ -622,7 +627,7 @@ def mouseDoubleClickEvent(self, event: QGraphicsSceneMouseEvent) -> None: """ Handle mouse double-click events (e.g. update selection) """ - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: regions = sorted(self.get_highlight_regions_under_cursor(), key=lambda r: self.cursor - r.addr) if len(regions) > 0: region = regions[0] @@ -647,7 +652,7 @@ def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent) -> None: """ Handle mouse release events. """ - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self.mouse_pressed = False def _set_byte_value(self, value: int) -> None: @@ -676,17 +681,17 @@ def keyPressEvent(self, event: PySide6.QtGui.QKeyEvent) -> None: Handle key press events (e.g. moving cursor around). """ movement_keys = { - Qt.Key_Up: -16, - Qt.Key_Down: 16, - Qt.Key_Right: 1, - Qt.Key_Left: -1, - Qt.Key_PageUp: 0, - Qt.Key_PageDown: 0, - Qt.Key_Home: 0, - Qt.Key_End: 0, + Qt.Key.Key_Up: -16, + Qt.Key.Key_Down: 16, + Qt.Key.Key_Right: 1, + Qt.Key.Key_Left: -1, + Qt.Key.Key_PageUp: 0, + Qt.Key.Key_PageDown: 0, + Qt.Key.Key_Home: 0, + Qt.Key.Key_End: 0, } if event.key() in movement_keys: - if QApplication.keyboardModifiers() & Qt.ShiftModifier: + if QApplication.keyboardModifiers() & Qt.KeyboardModifier.ShiftModifier: if self.selection_start is None: self.begin_selection() else: @@ -694,15 +699,15 @@ def keyPressEvent(self, event: PySide6.QtGui.QKeyEvent) -> None: # FIXME: When holding Ctrl, only scroll the viewport preserve_relative_offset = False - if event.key() == Qt.Key_PageUp: + if event.key() == Qt.Key.Key_PageUp: new_cursor = max(self.start_addr, self.cursor - (self.display_num_rows - 1) * 16) preserve_relative_offset = True - elif event.key() == Qt.Key_PageDown: + elif event.key() == Qt.Key.Key_PageDown: new_cursor = min(self.end_addr - 1, self.cursor + (self.display_num_rows - 1) * 16) preserve_relative_offset = True - elif event.key() == Qt.Key_Home: + elif event.key() == Qt.Key.Key_Home: new_cursor = max(self.start_addr, self.cursor & ~0xF) - elif event.key() == Qt.Key_End: + elif event.key() == Qt.Key.Key_End: new_cursor = min(self.end_addr - 1, (self.cursor & ~0xF) + 0xF) else: new_cursor = self.cursor + movement_keys[event.key()] @@ -711,8 +716,8 @@ def keyPressEvent(self, event: PySide6.QtGui.QKeyEvent) -> None: self.set_cursor(new_cursor, update_viewport=False) event.accept() return - elif QApplication.keyboardModifiers() & Qt.ControlModifier: - if event.key() == Qt.Key_Space: + elif QApplication.keyboardModifiers() & Qt.KeyboardModifier.ControlModifier: + if event.key() == Qt.Key.Key_Space: self.set_cursor(self.cursor, ascii_column=not self.ascii_column_active) event.accept() return @@ -911,7 +916,9 @@ def paint_highlighted_region(self, painter, region: HexHighlightRegion) -> None: painter.drawPath(path) painter.drawPath(self.build_selection_path(region.addr, end_addr, True, half_pen_width)) - def paint(self, painter, option, widget) -> None: # pylint: disable=unused-argument + def paint( + self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: QWidget | None = None + ) -> None: # pylint: disable=unused-argument """ Repaint the item. """ @@ -923,7 +930,7 @@ def paint(self, painter, option, widget) -> None: # pylint: disable=unused-argu max_row = self.display_num_rows - 1 # Paint background - painter.setPen(Qt.NoPen) + painter.setPen(Qt.PenStyle.NoPen) for row in range(min_row, max_row + 1): row_addr = self.row_to_addr(row) if row_addr >= self.display_end_addr: @@ -1024,9 +1031,9 @@ def set_pen_brush_for_active_selection(active: bool) -> None: cursor_height = self.row_padding / 2 def set_pen_brush_for_active_cursor(active: bool) -> None: - painter.setPen(Qt.NoPen) + painter.setPen(Qt.PenStyle.NoPen) if active: - col = Conf.palette_text if self.cursor_blink_state else Qt.NoBrush + col = Conf.palette_text if self.cursor_blink_state else Qt.BrushStyle.NoBrush else: col = Conf.palette_disabled_text painter.setBrush(col) @@ -1074,11 +1081,11 @@ def __init__(self, **kwargs) -> None: super().__init__(**kwargs) self.setMouseTracking(True) self.setBackgroundBrush(Conf.palette_base) - self.setResizeAnchor(QGraphicsView.NoAnchor) - self.setTransformationAnchor(QGraphicsView.NoAnchor) - self.setAlignment(Qt.AlignTop | Qt.AlignLeft) - self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) - self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) + self.setResizeAnchor(QGraphicsView.ViewportAnchor.NoAnchor) + self.setTransformationAnchor(QGraphicsView.ViewportAnchor.NoAnchor) + self.setAlignment(Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignLeft) + self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) + self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) def wheelEvent(self, event) -> None: self.parent().wheelEvent(event) @@ -1115,12 +1122,12 @@ def __init__(self, parent=None) -> None: self._scene.addItem(self.hex) self._view.setScene(self._scene) - self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) - self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) + self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOn) + self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOn) self.verticalScrollBar().actionTriggered.connect(self._on_vertical_scroll_bar_triggered) self.horizontalScrollBar().actionTriggered.connect(self._on_horizontal_scroll_bar_triggered) - self._view.setFrameStyle(QFrame.NoFrame) - self.setFrameStyle(QFrame.NoFrame) + self._view.setFrameStyle(QFrame.Shape.NoFrame) + self.setFrameStyle(QFrame.Shape.NoFrame) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) @@ -1138,10 +1145,10 @@ def _update_vertical_scrollbar(self) -> None: if addr_range > 0: offset = (self.hex.display_start_addr - self.hex.start_addr) >> 4 scrollbar_value = (offset + 1) / addr_range - self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) + self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOn) else: scrollbar_value = 0 - self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) + self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.verticalScrollBar().setValue(int(scrollbar_value * self.scrollbar_range)) @@ -1153,9 +1160,9 @@ def _update_horizontal_scrollbar(self) -> None: vp_rect = self._view.sceneRect() scroll_range = max(0, int(hex_rect.width()) - int(vp_rect.width())) if scroll_range == 0: - self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) + self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) else: - self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) + self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOn) self.horizontalScrollBar().setRange(0, scroll_range) self.horizontalScrollBar().setPageStep(hex_rect.width() / 10) self.horizontalScrollBar().setValue(vp_rect.left()) @@ -1184,15 +1191,15 @@ def _on_vertical_scroll_bar_triggered(self, action: int) -> None: return self._processing_scroll_event = True action = QAbstractSlider.SliderAction(action) - if action == QAbstractSlider.SliderSingleStepAdd: + if action == QAbstractSlider.SliderAction.SliderSingleStepAdd: self.set_display_offset(self.hex.display_offset_addr + 0x10) - elif action == QAbstractSlider.SliderSingleStepSub: + elif action == QAbstractSlider.SliderAction.SliderSingleStepSub: self.set_display_offset(self.hex.display_offset_addr - 0x10) - elif action == QAbstractSlider.SliderPageStepAdd: + elif action == QAbstractSlider.SliderAction.SliderPageStepAdd: self.set_display_offset(self.hex.display_offset_addr + 0x10) - elif action == QAbstractSlider.SliderPageStepSub: + elif action == QAbstractSlider.SliderAction.SliderPageStepSub: self.set_display_offset(self.hex.display_offset_addr - 0x10) - elif action == QAbstractSlider.SliderMove: + elif action == QAbstractSlider.SliderAction.SliderMove: addr_range = self.hex.end_addr - self.hex.start_addr if addr_range <= 0: return @@ -1211,7 +1218,7 @@ def _on_vertical_scroll_bar_triggered(self, action: int) -> None: def _on_horizontal_scroll_bar_triggered(self, action: int) -> None: self._processing_scroll_event = True action = QAbstractSlider.SliderAction(action) - if action == QAbstractSlider.SliderMove: + if action == QAbstractSlider.SliderAction.SliderMove: vp = self.viewport().geometry() vp.moveTo(0, 0) vp = self._view.mapToScene(vp).boundingRect() @@ -1220,7 +1227,7 @@ def _on_horizontal_scroll_bar_triggered(self, action: int) -> None: self._processing_scroll_event = False def wheelEvent(self, event: QWheelEvent) -> None: - if event.modifiers() & Qt.ControlModifier == Qt.ControlModifier: + if event.modifiers() & Qt.KeyboardModifier.ControlModifier == Qt.KeyboardModifier.ControlModifier: self.adjust_viewport_scale(1.25 if event.angleDelta().y() > 0 else 1 / 1.25) else: d = event.angleDelta().y() @@ -1295,7 +1302,7 @@ def changeEvent(self, event: QEvent) -> None: """ Redraw on color scheme update. """ - if event.type() == QEvent.PaletteChange: + if event.type() == QEvent.Type.PaletteChange: self._view.setBackgroundBrush(Conf.palette_base) self.update() @@ -1303,16 +1310,16 @@ def keyPressEvent(self, event: PySide6.QtGui.QKeyEvent) -> None: """ Handle key events. """ - if event.modifiers() & Qt.ControlModifier == Qt.ControlModifier: - if event.key() == Qt.Key_0: + if event.modifiers() & Qt.KeyboardModifier.ControlModifier == Qt.KeyboardModifier.ControlModifier: + if event.key() == Qt.Key.Key_0: self.adjust_viewport_scale() event.accept() return - elif event.key() == Qt.Key_Equal: + elif event.key() == Qt.Key.Key_Equal: self.adjust_viewport_scale(1.25) event.accept() return - elif event.key() == Qt.Key_Minus: + elif event.key() == Qt.Key.Key_Minus: self.adjust_viewport_scale(1 / 1.25) event.accept() return @@ -1425,7 +1432,7 @@ def _on_debugger_state_updated(self) -> None: differs = False if differs: if r is None: - r = HexHighlightRegion(Qt.red, addr, 0) + r = HexHighlightRegion(Qt.GlobalColor.red, addr, 0) regions.append(r) r.size += 1 else: @@ -1551,7 +1558,7 @@ def _init_widgets(self) -> None: Initialize widgets for this view. """ window = QMainWindow() - window.setWindowFlags(Qt.Widget) + window.setWindowFlags(Qt.WindowType.Widget) status_bar = QFrame() status_lyt = QHBoxLayout() @@ -1602,10 +1609,10 @@ def revert_selected_patches(self) -> None: dlg = QMessageBox() dlg.setWindowTitle("Revert patches") dlg.setText("Are you sure you want to revert selected patches?") - dlg.setIcon(QMessageBox.Question) - dlg.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel) - dlg.setDefaultButton(QMessageBox.Cancel) - if dlg.exec_() != QMessageBox.Yes: + dlg.setIcon(QMessageBox.Icon.Question) + dlg.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.Cancel) + dlg.setDefaultButton(QMessageBox.StandardButton.Cancel) + if dlg.exec_() != QMessageBox.StandardButton.Yes: return selected_regions = self.inner_widget.hex.get_active_highlight_regions() @@ -1803,7 +1810,7 @@ def keyPressEvent(self, event: PySide6.QtGui.QKeyEvent) -> None: """ Handle key events. """ - if event.key() == Qt.Key_G: + if event.key() == Qt.Key.Key_G: self.popup_jumpto_dialog() return @@ -1874,7 +1881,7 @@ def _update_highlight_regions_from_synchronized_views(self) -> None: for v in self.sync_state.highlight_regions: if v is not self: for r in self.sync_state.highlight_regions[v]: - regions.append(HexHighlightRegion(Qt.green, r.addr, r.size)) + regions.append(HexHighlightRegion(Qt.GlobalColor.green, r.addr, r.size)) self._sync_view_highlights = regions self._set_highlighted_regions() diff --git a/angrmanagement/ui/views/interaction_view.py b/angrmanagement/ui/views/interaction_view.py index d4debe5bf..23d21bd0d 100644 --- a/angrmanagement/ui/views/interaction_view.py +++ b/angrmanagement/ui/views/interaction_view.py @@ -272,7 +272,7 @@ def _start_interaction(self) -> None: "Please specify the name of a local Docker image that you will interact with. " 'You can run "docker images" in a terminal to see all available Docker ' "images on your local machine.", - QLineEdit.Normal, + QLineEdit.EchoMode.Normal, text="" if not self._last_img_name else self._last_img_name, ) if not ok or not img_name: @@ -368,7 +368,9 @@ def _init_widgets(self) -> None: save_text = QtWidgets.QLineEdit(box_save) save_text.setText("my_interaction") save_text.setPlaceholderText("Interaction Name") - save_text.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Fixed)) + save_text.setSizePolicy( + QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Ignored, QtWidgets.QSizePolicy.Policy.Fixed) + ) box_save.layout().addWidget(save_text) self.widget_text_savename = save_text @@ -407,7 +409,7 @@ def __init__(self, parent, callback) -> None: self._callback = callback def keyPressEvent(self, event) -> None: - if event.key() == QtCore.Qt.Key_Return and event.modifiers() != QtCore.Qt.ShiftModifier: + if event.key() == QtCore.Qt.Key.Key_Return and event.modifiers() != QtCore.Qt.KeyboardModifier.ShiftModifier: self._callback() return super().keyPressEvent(event) diff --git a/angrmanagement/ui/views/registers_view.py b/angrmanagement/ui/views/registers_view.py index 3a7d7ad2f..31cf92ddb 100644 --- a/angrmanagement/ui/views/registers_view.py +++ b/angrmanagement/ui/views/registers_view.py @@ -47,7 +47,7 @@ def columnCount(self, parent: PySide6.QtCore.QModelIndex = ...) -> int: # pylin def headerData( self, section: int, orientation: PySide6.QtCore.Qt.Orientation, role: int = ... ) -> Any: # pylint:disable=unused-argument - if role != Qt.DisplayRole: + if role != Qt.ItemDataRole.DisplayRole: return None if section < len(self.Headers): return self.Headers[section] @@ -59,10 +59,10 @@ def data(self, index: PySide6.QtCore.QModelIndex, role: int = ...) -> Any: row = index.row() reg = self._filtered_register_list()[row] col = index.column() - if role == Qt.DisplayRole: + if role == Qt.ItemDataRole.DisplayRole: return self._get_column_text(reg, col) - elif role == Qt.ForegroundRole: - return QBrush(Qt.red) if self._did_data_change(reg) else None + elif role == Qt.ItemDataRole.ForegroundRole: + return QBrush(Qt.GlobalColor.red) if self._did_data_change(reg) else None else: return None @@ -104,8 +104,8 @@ def __init__(self, register_view) -> None: vheader.setVisible(False) vheader.setDefaultSectionSize(20) - self.setSelectionBehavior(QAbstractItemView.SelectRows) - self.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel) + self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) + self.setHorizontalScrollMode(QAbstractItemView.ScrollMode.ScrollPerPixel) self.model: QRegisterTableModel = QRegisterTableModel(self) self.setModel(self.model) @@ -113,7 +113,7 @@ def __init__(self, register_view) -> None: font = QFont(Conf.disasm_font) self.setFont(font) - hheader.setSectionResizeMode(0, QHeaderView.ResizeToContents) + hheader.setSectionResizeMode(0, QHeaderView.ResizeMode.ResizeToContents) self._dbg_manager = register_view.instance.debugger_mgr self._dbg_watcher = DebuggerWatcher(self._on_debugger_state_updated, self._dbg_manager.debugger) diff --git a/angrmanagement/ui/views/stack_view.py b/angrmanagement/ui/views/stack_view.py index d041ee90b..2689888f9 100644 --- a/angrmanagement/ui/views/stack_view.py +++ b/angrmanagement/ui/views/stack_view.py @@ -44,7 +44,7 @@ def columnCount(self, parent: PySide6.QtCore.QModelIndex = ...) -> int: # pylin def headerData( self, section: int, orientation: PySide6.QtCore.Qt.Orientation, role: int = ... ) -> Any: # pylint:disable=unused-argument - if role != Qt.DisplayRole: + if role != Qt.ItemDataRole.DisplayRole: return None if section < len(self.Headers): return self.Headers[section] @@ -55,7 +55,7 @@ def data(self, index: PySide6.QtCore.QModelIndex, role: int = ...) -> Any: return None row = index.row() col = index.column() - if role == Qt.DisplayRole: + if role == Qt.ItemDataRole.DisplayRole: return self._get_column_text(row, col) else: return None @@ -90,8 +90,8 @@ def __init__(self, stack_view) -> None: vheader.setVisible(False) vheader.setDefaultSectionSize(20) - self.setSelectionBehavior(QAbstractItemView.SelectRows) - self.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel) + self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) + self.setHorizontalScrollMode(QAbstractItemView.ScrollMode.ScrollPerPixel) self.model: QStackTableModel = QStackTableModel(self) self.setModel(self.model) @@ -99,7 +99,7 @@ def __init__(self, stack_view) -> None: font = QFont(Conf.disasm_font) self.setFont(font) - hheader.setSectionResizeMode(0, QHeaderView.ResizeToContents) + hheader.setSectionResizeMode(0, QHeaderView.ResizeMode.ResizeToContents) self._dbg_manager = stack_view.instance.debugger_mgr self._dbg_watcher = DebuggerWatcher(self._on_debugger_state_updated, self._dbg_manager.debugger) diff --git a/angrmanagement/ui/views/symexec_view.py b/angrmanagement/ui/views/symexec_view.py index e6b23a366..781ecfff6 100644 --- a/angrmanagement/ui/views/symexec_view.py +++ b/angrmanagement/ui/views/symexec_view.py @@ -108,7 +108,7 @@ def closeEvent(self, _) -> None: def _init_widgets(self) -> None: main = QMainWindow() - main.setWindowFlags(Qt.Widget) + main.setWindowFlags(Qt.WindowType.Widget) # main.setCorner(Qt.TopLeftCorner, Qt.TopDockWidgetArea) # main.setCorner(Qt.TopRightCorner, Qt.RightDockWidgetArea) @@ -121,12 +121,12 @@ def _init_widgets(self) -> None: simgrs = QSimulationManagers(self.workspace, self.instance, self.current_simgr, self.current_state, parent=main) simgrs_dock = QDockWidget("SimulationManagers", simgrs) - main.addDockWidget(Qt.RightDockWidgetArea, simgrs_dock) + main.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, simgrs_dock) simgrs_dock.setWidget(simgrs) state_viewer = StateInspector(self.workspace, self.current_state, parent=self) state_viewer_dock = QDockWidget("Selected State", state_viewer) - main.addDockWidget(Qt.RightDockWidgetArea, state_viewer_dock) + main.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, state_viewer_dock) state_viewer_dock.setWidget(state_viewer) self._pathtree = pathtree diff --git a/angrmanagement/ui/views/traces_view.py b/angrmanagement/ui/views/traces_view.py index 103b63828..5c78fa954 100644 --- a/angrmanagement/ui/views/traces_view.py +++ b/angrmanagement/ui/views/traces_view.py @@ -46,7 +46,7 @@ def columnCount(self, parent: PySide6.QtCore.QModelIndex = ...) -> int: # pylin def headerData( self, section: int, orientation: PySide6.QtCore.Qt.Orientation, role: int = ... ) -> Any: # pylint:disable=unused-argument - if role != Qt.DisplayRole: + if role != Qt.ItemDataRole.DisplayRole: return None if section < len(self.Headers): return self.Headers[section] @@ -59,7 +59,7 @@ def data(self, index: PySide6.QtCore.QModelIndex, role: int = ...) -> Any: if row >= len(self.instance.traces): return None col = index.column() - if role == Qt.DisplayRole: + if role == Qt.ItemDataRole.DisplayRole: return self._get_column_text(self.instance.traces[row], col) else: return None @@ -88,13 +88,13 @@ def __init__(self, instance: Instance, parent=None) -> None: vheader.setVisible(False) vheader.setDefaultSectionSize(20) - self.setSelectionBehavior(QAbstractItemView.SelectRows) - self.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel) + self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) + self.setHorizontalScrollMode(QAbstractItemView.ScrollMode.ScrollPerPixel) self.model: QTraceTableModel = QTraceTableModel(instance) self.setModel(self.model) - hheader.setSectionResizeMode(0, QHeaderView.ResizeToContents) + hheader.setSectionResizeMode(0, QHeaderView.ResizeMode.ResizeToContents) # # Events diff --git a/angrmanagement/ui/widgets/filesystem_table.py b/angrmanagement/ui/widgets/filesystem_table.py index bae4349d6..b00fd675b 100644 --- a/angrmanagement/ui/widgets/filesystem_table.py +++ b/angrmanagement/ui/widgets/filesystem_table.py @@ -11,10 +11,10 @@ def __init__(self, items, parent) -> None: self.setColumnCount(len(header_labels)) self.setHorizontalHeaderLabels(header_labels) - self.setSelectionBehavior(QAbstractItemView.SelectItems) + self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectItems) header = self.horizontalHeader() - header.setSectionResizeMode(0, QHeaderView.Stretch) - header.setSectionResizeMode(1, QHeaderView.Stretch) + header.setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch) + header.setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch) self.setRowCount(len(items)) for idx, item in enumerate(items): diff --git a/angrmanagement/ui/widgets/qast_viewer.py b/angrmanagement/ui/widgets/qast_viewer.py index c90aa772f..7745e21c2 100644 --- a/angrmanagement/ui/widgets/qast_viewer.py +++ b/angrmanagement/ui/widgets/qast_viewer.py @@ -44,7 +44,7 @@ def __init__( self._size_label = None self._ast_label = None - self.setFrameShape(QFrame.NoFrame) + self.setFrameShape(QFrame.Shape.NoFrame) self.setLineWidth(0) # workspace backref @@ -149,7 +149,7 @@ def _init_widgets(self) -> None: if self._display_size: size_label = QLabel(self) size_label.setProperty("class", "ast_viewer_size") - size_label.setAlignment(Qt.AlignRight) + size_label.setAlignment(Qt.AlignmentFlag.AlignRight) size_label.setMaximumSize(QSize(24, 65536)) self._size_label = size_label layout.addWidget(self._size_label) diff --git a/angrmanagement/ui/widgets/qblock_code.py b/angrmanagement/ui/widgets/qblock_code.py index c0b0560ef..ec677495e 100644 --- a/angrmanagement/ui/widgets/qblock_code.py +++ b/angrmanagement/ui/widgets/qblock_code.py @@ -84,7 +84,7 @@ def update_style(self) -> None: self._fmt_current = self.fmt() if self.should_highlight(): self._fmt_current.setBackground(Conf.disasm_view_operand_highlight_color) - self._fmt_current.setFontWeight(QFont.Bold) + self._fmt_current.setFontWeight(QFont.Weight.Bold) def should_highlight(self) -> bool: """ @@ -159,7 +159,7 @@ def add_variable(self, var) -> None: def mousePressEvent(self, event: QMouseEvent) -> None: # pylint: disable=unused-argument self.infodock.select_qblock_code_obj(self) - if event.button() == Qt.RightButton: + if event.button() == Qt.MouseButton.RightButton: self.infodock.disasm_view.show_context_menu_for_selected_object() def mouseDoubleClickEvent(self, event: QMouseEvent) -> None: @@ -231,7 +231,7 @@ def should_highlight_line(self): def mousePressEvent(self, event: QMouseEvent) -> None: # pylint: disable=unused-argument super().mousePressEvent(event) button = event.button() - if button == Qt.LeftButton: + if button == Qt.MouseButton.LeftButton: ail_obj_ins_addr = getattr(self.obj, "ins_addr", None) if ail_obj_ins_addr is not None: self.infodock.select_instruction(ail_obj_ins_addr) @@ -367,7 +367,7 @@ def should_highlight(self) -> bool: def mouseDoubleClickEvent(self, event: QMouseEvent) -> None: super().mouseDoubleClickEvent(event) button = event.button() - if button == Qt.LeftButton: + if button == Qt.MouseButton.LeftButton: src_ins_addr = getattr(self.stmt, "ins_addr", None) self.infodock.disasm_view.jump_to(self.obj.value, src_ins_addr=src_ins_addr, use_animation=True) @@ -800,7 +800,7 @@ def update_document(self) -> None: def paint(self, painter, option, widget) -> None: # pylint: disable=unused-argument self.update_document() - painter.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) + painter.setRenderHints(QPainter.RenderHint.Antialiasing | QPainter.RenderHint.SmoothPixmapTransform) painter.setFont(self._config.disasm_font) if self.infodock.is_instruction_selected(self.addr) or self.obj.should_highlight_line: @@ -836,7 +836,7 @@ def get_obj_for_mouse_event(self, event: QMouseEvent) -> QBlockCodeObj: return None def mousePressEvent(self, event) -> None: - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self.infodock.select_instruction(self.addr) obj = self.get_obj_for_mouse_event(event) diff --git a/angrmanagement/ui/widgets/qblock_label.py b/angrmanagement/ui/widgets/qblock_label.py index c8ef19d9f..eadc34996 100644 --- a/angrmanagement/ui/widgets/qblock_label.py +++ b/angrmanagement/ui/widgets/qblock_label.py @@ -33,7 +33,7 @@ def __init__(self, addr: int, text: str, config, disasm_view, instance: Instance self._init_widgets() def paint(self, painter, option, widget) -> None: # pylint: disable=unused-argument - painter.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) + painter.setRenderHints(QPainter.RenderHint.Antialiasing | QPainter.RenderHint.SmoothPixmapTransform) painter.setFont(self._config.code_font) # background @@ -48,7 +48,7 @@ def paint(self, painter, option, widget) -> None: # pylint: disable=unused-argu # def mousePressEvent(self, event) -> None: - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self.infodock.select_label(self.addr) # diff --git a/angrmanagement/ui/widgets/qccode_edit.py b/angrmanagement/ui/widgets/qccode_edit.py index bd3490e10..caf1e152e 100644 --- a/angrmanagement/ui/widgets/qccode_edit.py +++ b/angrmanagement/ui/widgets/qccode_edit.py @@ -264,23 +264,23 @@ def keyPressEvent(self, event): saved_mode = self.textInteractionFlags() if key in ( - Qt.Key_Left, - Qt.Key_Right, - Qt.Key_Up, - Qt.Key_Down, - Qt.Key_PageDown, - Qt.Key_PageUp, - Qt.Key_Home, - Qt.Key_End, + Qt.Key.Key_Left, + Qt.Key.Key_Right, + Qt.Key.Key_Up, + Qt.Key.Key_Down, + Qt.Key.Key_PageDown, + Qt.Key.Key_PageUp, + Qt.Key.Key_Home, + Qt.Key.Key_End, ): - self.setTextInteractionFlags(saved_mode | Qt.TextEditable) + self.setTextInteractionFlags(saved_mode | Qt.TextInteractionFlag.TextEditable) result = super().keyPressEvent(event) self.setTextInteractionFlags(saved_mode) return result def paintEvent(self, e) -> None: saved_mode = self.textInteractionFlags() - self.setTextInteractionFlags(saved_mode | Qt.TextEditable) + self.setTextInteractionFlags(saved_mode | Qt.TextInteractionFlag.TextEditable) super().paintEvent(e) self.setTextInteractionFlags(saved_mode) @@ -375,7 +375,7 @@ def comment(self, expr: bool = False, node=None) -> None: text = cdict.get(addr, "") text, ok = QInputDialog.getText( - self._code_view, "Expression Comment" if expr else "Statement Comment", "", QLineEdit.Normal, text + self._code_view, "Expression Comment" if expr else "Statement Comment", "", QLineEdit.EchoMode.Normal, text ) if ok: diff --git a/angrmanagement/ui/widgets/qcolor_option.py b/angrmanagement/ui/widgets/qcolor_option.py index 2a680c9d3..acb25335a 100644 --- a/angrmanagement/ui/widgets/qcolor_option.py +++ b/angrmanagement/ui/widgets/qcolor_option.py @@ -27,7 +27,7 @@ def mouseReleaseEvent(self, event) -> None: # pylint:disable=unused-argument dialog = QColorDialog() dialog.setCurrentColor(self.color.am_obj) dialog.exec() - if dialog.result() == QColorDialog.Accepted: + if dialog.result() == QColorDialog.DialogCode.Accepted: self.set_color(dialog.currentColor()) def _init_widgets(self) -> None: diff --git a/angrmanagement/ui/widgets/qconstraint_viewer.py b/angrmanagement/ui/widgets/qconstraint_viewer.py index b89643e4f..81b6c7ba4 100644 --- a/angrmanagement/ui/widgets/qconstraint_viewer.py +++ b/angrmanagement/ui/widgets/qconstraint_viewer.py @@ -55,9 +55,9 @@ def _init_widgets(self) -> None: table = QTableWidget(self) table.setColumnCount(len(self.COLUMNS)) table.setHorizontalHeaderLabels(self.COLUMNS) - table.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) - table.horizontalHeader().setSectionResizeMode(QHeaderView.Fixed) - table.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch) + table.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) + table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Fixed) + table.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch) self.table = table layout.addWidget(table) diff --git a/angrmanagement/ui/widgets/qdatadep_graph.py b/angrmanagement/ui/widgets/qdatadep_graph.py index ed81f9fca..de4e36b7b 100644 --- a/angrmanagement/ui/widgets/qdatadep_graph.py +++ b/angrmanagement/ui/widgets/qdatadep_graph.py @@ -86,11 +86,11 @@ def set_caption(self, show_src_caption: bool) -> None: self._caption.setText(self._DST_JUMP_TEXT) def _init_widgets(self) -> None: - parent_background_color = self.parent().palette().color(QtGui.QPalette.Window) + parent_background_color = self.parent().palette().color(QtGui.QPalette.ColorRole.Window) self.setStyleSheet(f"background-color: {parent_background_color.name()};") - self.setFrameStyle(QtWidgets.QFrame.Raised | QtWidgets.QFrame.Panel) - self._layout_manager.addWidget(self.preview_graph, 0, QtCore.Qt.AlignCenter) - self._layout_manager.addWidget(self._caption, 1, QtCore.Qt.AlignCenter) + self.setFrameStyle(QtWidgets.QFrame.Shadow.Raised | QtWidgets.QFrame.Shape.Panel) + self._layout_manager.addWidget(self.preview_graph, 0, QtCore.Qt.AlignmentFlag.AlignCenter) + self._layout_manager.addWidget(self._caption, 1, QtCore.Qt.AlignmentFlag.AlignCenter) class QDataDepGraph(QZoomableDraggableGraphicsView): diff --git a/angrmanagement/ui/widgets/qdatadepgraph_block.py b/angrmanagement/ui/widgets/qdatadepgraph_block.py index 58140a94f..a4093e9d1 100644 --- a/angrmanagement/ui/widgets/qdatadepgraph_block.py +++ b/angrmanagement/ui/widgets/qdatadepgraph_block.py @@ -32,7 +32,7 @@ class QDataDepGraphBlock(QCachedGraphicsItem): def __init__(self, is_selected: bool, data_dep_view: DataDepView, node: BaseDepNode, instr: CsInsn | None) -> None: super().__init__() - self.setFlags(QtWidgets.QGraphicsItem.ItemIsFocusable) + self.setFlags(QtWidgets.QGraphicsItem.GraphicsItemFlag.ItemIsFocusable) self._selected = is_selected self._data_dep_view = data_dep_view @@ -67,7 +67,7 @@ def node(self) -> BaseDepNode: def _build_simple_text_item(self, text: str) -> QtWidgets.QGraphicsSimpleTextItem: text_item = QtWidgets.QGraphicsSimpleTextItem(text, self) text_item.setFont(Conf.symexec_font) - text_item.setBrush(QtCore.Qt.black) + text_item.setBrush(QtCore.Qt.GlobalColor.black) text_item.setPos(self.HORIZONTAL_PADDING, self.VERTICAL_PADDING + self._y_off) return text_item @@ -149,13 +149,13 @@ def _update_size(self) -> None: # def mouseDoubleClickEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent) -> None: - if event.button() == QtCore.Qt.LeftButton and self._node.ins_addr: + if event.button() == QtCore.Qt.MouseButton.LeftButton and self._node.ins_addr: self._workspace.viz(self._node.ins_addr) def hoverEnterEvent(self, event: QtWidgets.QGraphicsSceneHoverEvent) -> None: self._selected = True self.refresh() - self.setFocus(QtCore.Qt.MouseFocusReason) + self.setFocus(QtCore.Qt.FocusReason.MouseFocusReason) self.grabKeyboard() self._data_dep_view.hover_enter_block(self, event.modifiers()) @@ -174,14 +174,14 @@ def contextMenuEvent(self, event: QtWidgets.QGraphicsSceneContextMenuEvent) -> N def keyPressEvent(self, event: QtGui.QKeyEvent) -> None: """Handle change from ancestor to descendant tracing""" - if self._selected and event.key() == QtCore.Qt.Key_Control: + if self._selected and event.key() == QtCore.Qt.Key.Key_Control: self._data_dep_view.update_descendants(self) else: super().keyPressEvent(event) def keyReleaseEvent(self, event: QtGui.QKeyEvent) -> None: """Handle change form descendant to ancestor tracing""" - if self._selected and event.key() == QtCore.Qt.Key_Control: + if self._selected and event.key() == QtCore.Qt.Key.Key_Control: self._data_dep_view.update_ancestors(self) else: super().keyReleaseEvent(event) diff --git a/angrmanagement/ui/widgets/qdecomp_options.py b/angrmanagement/ui/widgets/qdecomp_options.py index c12faa9be..471d4c9f2 100644 --- a/angrmanagement/ui/widgets/qdecomp_options.py +++ b/angrmanagement/ui/widgets/qdecomp_options.py @@ -60,11 +60,11 @@ def __init__(self, parent, option, type_: int, enabled: bool = True) -> None: # should make a boolean click option else: - self.setFlags(self.flags() | Qt.ItemIsUserCheckable) + self.setFlags(self.flags() | Qt.ItemFlag.ItemIsUserCheckable) if enabled: - self.setCheckState(0, Qt.Checked) + self.setCheckState(0, Qt.CheckState.Checked) else: - self.setCheckState(0, Qt.Unchecked) + self.setCheckState(0, Qt.CheckState.Unchecked) @property def state(self): diff --git a/angrmanagement/ui/widgets/qdep_graph.py b/angrmanagement/ui/widgets/qdep_graph.py index 156fe81b5..2e616bee4 100644 --- a/angrmanagement/ui/widgets/qdep_graph.py +++ b/angrmanagement/ui/widgets/qdep_graph.py @@ -123,7 +123,7 @@ def keyPressEvent(self, event) -> None: key = event.key() - if key == Qt.Key_Tab: + if key == Qt.Key.Key_Tab: self._symexec_view.switch_to_disassembly_view() event.accept() diff --git a/angrmanagement/ui/widgets/qdepgraph_block.py b/angrmanagement/ui/widgets/qdepgraph_block.py index f4844ff94..7787ae99b 100644 --- a/angrmanagement/ui/widgets/qdepgraph_block.py +++ b/angrmanagement/ui/widgets/qdepgraph_block.py @@ -115,7 +115,7 @@ def _init_widgets(self) -> None: # definition self._definition_item = QGraphicsSimpleTextItem(self._definition_str, self) - self._definition_item.setBrush(Qt.darkBlue) + self._definition_item.setBrush(Qt.GlobalColor.darkBlue) self._definition_item.setFont(Conf.symexec_font) self._definition_item.setPos(x, y) @@ -123,7 +123,7 @@ def _init_widgets(self) -> None: # instruction self._instruction_item = QGraphicsSimpleTextItem(self._instruction_str, self) - self._instruction_item.setBrush(Qt.black) + self._instruction_item.setBrush(Qt.GlobalColor.black) self._instruction_item.setFont(Conf.symexec_font) self._instruction_item.setPos(x, y) @@ -134,7 +134,7 @@ def _init_widgets(self) -> None: x += 10 self._text_item = QGraphicsSimpleTextItem(self._text, self) self._text_item.setFont(Conf.symexec_font) - self._text_item.setBrush(Qt.gray) + self._text_item.setBrush(Qt.GlobalColor.gray) self._text_item.setPos(x, y) # y += self._instruction_item.boundingRect().height() @@ -152,7 +152,7 @@ def mousePressEvent(self, event) -> None: # pylint: disable=no-self-use def mouseReleaseEvent(self, event) -> None: # _l.debug('QStateBlock received mouse release event') - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self.selected = not self.selected self._dep_view.redraw_graph() event.accept() @@ -161,7 +161,7 @@ def mouseReleaseEvent(self, event) -> None: def mouseDoubleClickEvent(self, event) -> None: # _l.debug('QStateBlock received mouse double click event') - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self._workspace.viz(self.addr) event.accept() diff --git a/angrmanagement/ui/widgets/qdisasm_base_control.py b/angrmanagement/ui/widgets/qdisasm_base_control.py index 8b5a46db6..9d7440cf9 100644 --- a/angrmanagement/ui/widgets/qdisasm_base_control.py +++ b/angrmanagement/ui/widgets/qdisasm_base_control.py @@ -85,11 +85,11 @@ def set_disassembly_level(self, level: DisassemblyLevel) -> None: def keyPressEvent(self, event) -> None: key = event.key() - if key == Qt.Key_N: + if key == Qt.Key.Key_N: # rename a label self.disasm_view.popup_rename_label_dialog() return - elif key == Qt.Key_X: + elif key == Qt.Key.Key_X: # XRef # try to get a selected operand r = self.get_selected_operand_info() diff --git a/angrmanagement/ui/widgets/qdisasm_graph.py b/angrmanagement/ui/widgets/qdisasm_graph.py index 7d7574679..6e425e918 100644 --- a/angrmanagement/ui/widgets/qdisasm_graph.py +++ b/angrmanagement/ui/widgets/qdisasm_graph.py @@ -77,9 +77,9 @@ def __init__(self, instance: Instance, disasm_view, parent=None) -> None: self.blocks = [] - self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) - self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) - self.setFrameStyle(QFrame.NoFrame) + self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOn) + self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOn) + self.setFrameStyle(QFrame.Shape.NoFrame) self.setBackgroundBrush(Conf.disasm_view_background_color) self._minimap = QMiniMapView(self, parent=self) @@ -239,9 +239,9 @@ def event(self, event): def mousePressEvent(self, event) -> None: btn = event.button() - if btn == Qt.ForwardButton: + if btn == Qt.MouseButton.ForwardButton: self.disasm_view.jump_forward() - elif btn == Qt.BackButton: + elif btn == Qt.MouseButton.BackButton: self.disasm_view.jump_back() else: super().mousePressEvent(event) @@ -250,13 +250,10 @@ def changeEvent(self, event: QEvent) -> None: """ Redraw on color scheme update. """ - if event.type() == QEvent.PaletteChange: + if event.type() == QEvent.Type.PaletteChange: self.setBackgroundBrush(Conf.disasm_view_background_color) self.reload() - def on_background_click(self) -> None: - pass - # # Layout # diff --git a/angrmanagement/ui/widgets/qfeature_map.py b/angrmanagement/ui/widgets/qfeature_map.py index e20f03dfe..2ff1e8a5e 100644 --- a/angrmanagement/ui/widgets/qfeature_map.py +++ b/angrmanagement/ui/widgets/qfeature_map.py @@ -113,8 +113,10 @@ def __init__(self, instance: Instance, *args, **kwargs) -> None: super().__init__(*args, **kwargs) self.instance = instance - self.setFlag(QGraphicsItem.ItemUsesExtendedStyleOption, True) # Give me more specific paint update rect info - self.setFlag(QGraphicsItem.ItemClipsToShape, True) + self.setFlag( + QGraphicsItem.GraphicsItemFlag.ItemUsesExtendedStyleOption, True + ) # Give me more specific paint update rect info + self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemClipsToShape, True) self.setAcceptHoverEvents(True) self.addr = ObjectContainer(None, name="The current address of the Feature Map.") @@ -362,7 +364,7 @@ def _get_region_display_rect(self, mr: MemoryRegion) -> QRectF: def paint(self, painter, option, _) -> None: painter.setPen(Qt.PenStyle.NoPen) - painter.setBrush(Qt.green if log.level == logging.DEBUG else Conf.feature_map_unknown_color) + painter.setBrush(Qt.GlobalColor.green if log.level == logging.DEBUG else Conf.feature_map_unknown_color) painter.drawRect(option.exposedRect) if not len(self._position_to_region): @@ -499,7 +501,7 @@ def _create_cursor_items(self, **_) -> None: arrow.append(QPointF(0 - half_line_width, 0)) arrow.translate(half_width, 0) - pen = Qt.NoPen + pen = Qt.PenStyle.NoPen brush = QBrush(Qt.GlobalColor.yellow) for addr in self._cursor_addrs: @@ -508,7 +510,7 @@ def _create_cursor_items(self, **_) -> None: continue item = QGraphicsPolygonItem(arrow, parent=self) - item.setCacheMode(QGraphicsItem.ItemCoordinateCache) + item.setCacheMode(QGraphicsItem.CacheMode.ItemCoordinateCache) item.setPen(pen) item.setBrush(brush) item.setZValue(self.ZVALUE_CURSOR) diff --git a/angrmanagement/ui/widgets/qfunction_header.py b/angrmanagement/ui/widgets/qfunction_header.py index 9305d9248..5e311f3a4 100644 --- a/angrmanagement/ui/widgets/qfunction_header.py +++ b/angrmanagement/ui/widgets/qfunction_header.py @@ -51,7 +51,7 @@ def refresh(self) -> None: pass def paint(self, painter, option, widget) -> None: - painter.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) + painter.setRenderHints(QPainter.RenderHint.Antialiasing | QPainter.RenderHint.SmoothPixmapTransform) if self.infodock.is_label_selected(self.addr): highlight_color = Conf.disasm_view_label_highlight_color @@ -64,9 +64,12 @@ def paint(self, painter, option, widget) -> None: # def mousePressEvent(self, event) -> None: - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self.infodock.select_label(self.addr) - elif event.button() == Qt.RightButton and QApplication.keyboardModifiers() == Qt.NoModifier: + elif ( + event.button() == Qt.MouseButton.RightButton + and QApplication.keyboardModifiers() == Qt.KeyboardModifier.NoModifier + ): if self.addr not in self.infodock.selected_labels: self.infodock.select_label(self.addr) self._disasm_view.label_context_menu(self.addr, QCursor.pos()) diff --git a/angrmanagement/ui/widgets/qfunction_table.py b/angrmanagement/ui/widgets/qfunction_table.py index 5d58b09b3..dee91666b 100644 --- a/angrmanagement/ui/widgets/qfunction_table.py +++ b/angrmanagement/ui/widgets/qfunction_table.py @@ -172,7 +172,9 @@ def _data_uncached(self, row, col, role): def sort(self, column, order) -> None: self.layoutAboutToBeChanged.emit() self.func_list = sorted( - self.func_list, key=lambda f: self._get_column_data(f, column), reverse=order == Qt.DescendingOrder + self.func_list, + key=lambda f: self._get_column_data(f, column), + reverse=order == Qt.SortOrder.DescendingOrder, ) self.layoutChanged.emit() @@ -275,7 +277,7 @@ class QFunctionTableHeaderView(QHeaderView): def contextMenuEvent(self, event: PySide6.QtGui.QContextMenuEvent) -> None: # pylint:disable=unused-argument menu = QMenu("Column Menu", self) for idx in range(self.model().columnCount()): - column_text = self.model().headerData(idx, Qt.Orientation.Horizontal, Qt.DisplayRole) + column_text = self.model().headerData(idx, Qt.Orientation.Horizontal, Qt.ItemDataRole.DisplayRole) action = QAction(column_text, self) action.setCheckable(True) hidden = self.isSectionHidden(idx) @@ -313,7 +315,7 @@ def __init__(self, parent, workspace: Workspace, instance: Instance, selection_c self.setHorizontalHeader(header) self.horizontalHeader().setVisible(True) self.verticalHeader().setVisible(False) - self.setSelectionBehavior(QAbstractItemView.SelectRows) + self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) self.setHorizontalScrollMode(QAbstractItemView.ScrollMode.ScrollPerPixel) self.show_alignment_functions = False @@ -323,9 +325,9 @@ def __init__(self, parent, workspace: Workspace, instance: Instance, selection_c self.setModel(self._model) - self.horizontalHeader().setDefaultAlignment(Qt.AlignLeft) + self.horizontalHeader().setDefaultAlignment(Qt.AlignmentFlag.AlignLeft) self.horizontalHeader().setSortIndicatorShown(True) - self.horizontalHeader().setSectionResizeMode(QHeaderView.Interactive) + self.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Interactive) self.horizontalHeader().setStretchLastSection(True) self.verticalHeader().setDefaultSectionSize(24) @@ -414,7 +416,7 @@ def __init__(self, parent) -> None: self.installEventFilter(self) def eventFilter(self, obj, event) -> bool: # pylint:disable=unused-argument - if event.type() == QEvent.KeyPress and event.key() == Qt.Key_Escape: + if event.type() == QEvent.Type.KeyPress and event.key() == Qt.Key.Key_Escape: if self.text(): self.setText("") else: @@ -528,7 +530,7 @@ def _init_widgets(self, selection_callback=None) -> None: self._filter_box = QFunctionTableFilterBox(self) self._filter_box.setClearButtonEnabled(True) self._filter_box.addAction( - qta.icon("fa5s.search", color=Conf.palette_placeholdertext), QLineEdit.LeadingPosition + qta.icon("fa5s.search", color=Conf.palette_placeholdertext), QLineEdit.ActionPosition.LeadingPosition ) self._filter_box.setPlaceholderText("Filter by name...") self._filter_box.textChanged.connect(self._on_filter_box_text_changed) diff --git a/angrmanagement/ui/widgets/qgraph.py b/angrmanagement/ui/widgets/qgraph.py index c8f05a5c5..5f6c1b8ce 100644 --- a/angrmanagement/ui/widgets/qgraph.py +++ b/angrmanagement/ui/widgets/qgraph.py @@ -18,6 +18,8 @@ class QBaseGraphicsView(QGraphicsView): + """QBaseGraphicsView is a QGraphicsView that emits a signal when the visible scene rect changes.""" + visible_scene_rect_changed = Signal(QRectF) # @@ -52,6 +54,8 @@ def viewportEvent(self, event: QEvent) -> bool: class QSaveableGraphicsView(QBaseGraphicsView): + """QSaveableGraphicsView is a QGraphicsView that can save the visible scene to an image file.""" + def __init__(self, parent=None) -> None: super().__init__(parent=parent) self._is_extra_render_pass: bool = False @@ -75,11 +79,11 @@ def save_image_to( minRect = self.scene().itemsBoundingRect() imgRect = minRect.marginsAdded(margins) - image = QImage(imgRect.size().toSize(), QImage.Format_ARGB32) - image.fill(Qt.white) + image = QImage(imgRect.size().toSize(), QImage.Format.Format_ARGB32) + image.fill(Qt.GlobalColor.white) painter = QPainter(image) - painter.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) + painter.setRenderHints(QPainter.RenderHint.Antialiasing | QPainter.RenderHint.SmoothPixmapTransform) # draw the image self.scene().setSceneRect(imgRect) @@ -94,6 +98,8 @@ def save_image_to( class QZoomableDraggableGraphicsView(QSaveableGraphicsView): + """QZoomableDraggableGraphicsView is a QGraphicsView that allows zooming and dragging.""" + ZOOM_X = True ZOOM_Y = True @@ -106,20 +112,17 @@ def __init__(self, parent=None) -> None: self._last_coords = None self._last_screen_pos = None - self.setTransformationAnchor(QGraphicsView.NoAnchor) - self.setResizeAnchor(QGraphicsView.AnchorViewCenter) + self.setTransformationAnchor(QGraphicsView.ViewportAnchor.NoAnchor) + self.setResizeAnchor(QGraphicsView.ViewportAnchor.AnchorViewCenter) # scroll bars are useless when the scene is near-infinite - self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) - self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) + self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) + self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) # the zoom factor, for preserving the zoom self.zoom_factor = None - # self.setRenderHints( - # QPainter.Antialiasing | QPainter.SmoothPixmapTransform) - - self.grabGesture(Qt.PinchGesture) + self.grabGesture(Qt.GestureType.PinchGesture) self._gesture_last_scale = 1.0 def _initial_position(self): @@ -176,7 +179,7 @@ def zoom( self.translate(delta.x(), delta.y()) def wheelEvent(self, event) -> None: - if event.modifiers() & Qt.ControlModifier == Qt.ControlModifier: + if event.modifiers() & Qt.KeyboardModifier.ControlModifier == Qt.KeyboardModifier.ControlModifier: self.zoom( event.angleDelta().y() < 0, QPoint(event.position().x(), event.position().y()), @@ -187,8 +190,8 @@ def wheelEvent(self, event) -> None: super().wheelEvent(event) else: # if it is not an angled zoom (e.g. mouse wheel) parse the shift key specially to mean horizontal movement - if event.modifiers() & Qt.ShiftModifier == Qt.ShiftModifier: - event.setModifiers(event.modifiers() & ~Qt.ShiftModifier) + if event.modifiers() & Qt.KeyboardModifier.ShiftModifier == Qt.KeyboardModifier.ShiftModifier: + event.setModifiers(event.modifiers() & ~Qt.KeyboardModifier.ShiftModifier) self.horizontalScrollBar().wheelEvent(event) else: self.verticalScrollBar().wheelEvent(event) @@ -199,18 +202,24 @@ def _save_last_coords(self, event) -> None: self._last_screen_pos = event.pos() def keyPressEvent(self, event) -> None: - if event.key() == Qt.Key_Equal and (event.modifiers() & Qt.ControlModifier == Qt.ControlModifier): + if event.key() == Qt.Key.Key_Equal and ( + event.modifiers() & Qt.KeyboardModifier.ControlModifier == Qt.KeyboardModifier.ControlModifier + ): self.zoom(out=False) - elif event.key() == Qt.Key_Minus and (event.modifiers() & Qt.ControlModifier == Qt.ControlModifier): + elif event.key() == Qt.Key.Key_Minus and ( + event.modifiers() & Qt.KeyboardModifier.ControlModifier == Qt.KeyboardModifier.ControlModifier + ): self.zoom(out=True) - elif event.key() == Qt.Key_0 and (event.modifiers() & Qt.ControlModifier == Qt.ControlModifier): + elif event.key() == Qt.Key.Key_0 and ( + event.modifiers() & Qt.KeyboardModifier.ControlModifier == Qt.KeyboardModifier.ControlModifier + ): self.zoom(reset=True) else: super().keyPressEvent(event) def mousePressEvent(self, event) -> None: # _l.debug('Received press') - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self._is_mouse_pressed = True self._is_dragging = False @@ -233,7 +242,7 @@ def mouseMoveEvent(self, event) -> None: self._is_dragging = True pos = self.mapToScene(event.pos()) - self.viewport().setCursor(Qt.ClosedHandCursor) + self.viewport().setCursor(Qt.CursorShape.ClosedHandCursor) delta = (pos.x() - self._last_coords[0], pos.y() - self._last_coords[1]) self.translate(*delta) @@ -243,11 +252,11 @@ def mouseMoveEvent(self, event) -> None: super().mouseMoveEvent(event) - def dispatchMouseEventToScene(self, event): - if event.type() == QEvent.MouseButtonPress: - newtype = QEvent.GraphicsSceneMousePress - elif event.type() == QEvent.MouseButtonRelease: - newtype = QEvent.GraphicsSceneMouseRelease + def dispatchMouseEventToScene(self, event: QMouseEvent): + if event.type() == QEvent.Type.MouseButtonPress: + newtype = QEvent.Type.GraphicsSceneMousePress + elif event.type() == QEvent.Type.MouseButtonRelease: + newtype = QEvent.Type.GraphicsSceneMouseRelease else: raise ValueError(f"Unknown event type {event.type()}") @@ -283,14 +292,14 @@ def mouseReleaseEvent(self, event) -> None: :return: """ - if event.button() == Qt.LeftButton and self._is_dragging: - self.viewport().setCursor(Qt.ArrowCursor) + if event.button() == Qt.MouseButton.LeftButton and self._is_dragging: + self.viewport().setCursor(Qt.CursorShape.ArrowCursor) event.accept() if not event.isAccepted(): # create a new event and dispatch it to the scene pressy = QMouseEvent( - QEvent.MouseButtonPress, + QEvent.Type.MouseButtonPress, event.pos(), event.globalPos(), event.button(), @@ -301,7 +310,7 @@ def mouseReleaseEvent(self, event) -> None: _ = self.dispatchMouseEventToScene(pressy) releasy = QMouseEvent( - QEvent.MouseButtonRelease, + QEvent.Type.MouseButtonRelease, event.pos(), event.globalPos(), event.buton(), @@ -311,7 +320,6 @@ def mouseReleaseEvent(self, event) -> None: release_event = self.dispatchMouseEventToScene(releasy) if not release_event.isAccepted(): - self.on_background_click() release_event.accept() self._is_mouse_pressed = False @@ -320,7 +328,7 @@ def mouseReleaseEvent(self, event) -> None: super().mouseReleaseEvent(event) def event(self, event): - if event.type() == QEvent.Gesture and isinstance(event, QGestureEvent): + if event.type() == QEvent.Type.Gesture and isinstance(event, QGestureEvent): return self._handle_pinch_gesture(event) return super().event(event) diff --git a/angrmanagement/ui/widgets/qgraph_arrow.py b/angrmanagement/ui/widgets/qgraph_arrow.py index de06333bf..6923acaa7 100644 --- a/angrmanagement/ui/widgets/qgraph_arrow.py +++ b/angrmanagement/ui/widgets/qgraph_arrow.py @@ -23,7 +23,7 @@ EdgeSort.EXCEPTION_EDGE: "disasm_view_exception_edge_color", } -EDGE_STYLES = {EdgeSort.DIRECT_JUMP: Qt.SolidLine, EdgeSort.EXCEPTION_EDGE: Qt.DashLine} +EDGE_STYLES = {EdgeSort.DIRECT_JUMP: Qt.PenStyle.SolidLine, EdgeSort.EXCEPTION_EDGE: Qt.PenStyle.DashLine} class QGraphArrow(QGraphicsItem): @@ -155,7 +155,7 @@ def hoverLeaveEvent(self, event) -> None: self.infodock.unhover_edge(self.edge.src.addr, self.edge.dst.addr) def mouseDoubleClickEvent(self, event) -> None: - if QApplication.keyboardModifiers() == Qt.ShiftModifier: + if QApplication.keyboardModifiers() == Qt.KeyboardModifier.ShiftModifier: # go to the source self.disasm_view.jump_to(self.edge.src.addr, src_ins_addr=self.edge.dst.addr, use_animation=True) event.accept() @@ -240,7 +240,7 @@ class QDataDepGraphArrow(QGraphArrow): def __init__(self, data_dep_view: DataDepView, *args, **kwargs) -> None: super().__init__(*args, **kwargs) - self.setFlags(QGraphicsItem.ItemIsFocusable) + self.setFlags(QGraphicsItem.GraphicsItemFlag.ItemIsFocusable) self._data_dep_view = data_dep_view self.is_hovered = False @@ -255,9 +255,11 @@ def _should_highlight(self) -> bool: def hoverEnterEvent(self, event) -> None: self.is_hovered = True self.update() # Must trigger repaint to highlight - self.setFocus(Qt.MouseFocusReason) + self.setFocus(Qt.FocusReason.MouseFocusReason) self.grabKeyboard() - self._data_dep_view.graph_widget.handle_preview_request(self, event.modifiers() & Qt.ControlModifier) + self._data_dep_view.graph_widget.handle_preview_request( + self, event.modifiers() & Qt.KeyboardModifier.ControlModifier + ) def hoverLeaveEvent(self, event) -> None: self.is_hovered = False @@ -267,13 +269,13 @@ def hoverLeaveEvent(self, event) -> None: self._data_dep_view.graph_widget.hide_preview() def keyPressEvent(self, event: QKeyEvent) -> None: - if self.is_hovered and event.key() == Qt.Key_Control: + if self.is_hovered and event.key() == Qt.Key.Key_Control: self._data_dep_view.graph_widget.handle_preview_request(self, True) else: super().keyPressEvent(event) def keyReleaseEvent(self, event: QKeyEvent) -> None: - if self.is_hovered and event.key() == Qt.Key_Control: + if self.is_hovered and event.key() == Qt.Key.Key_Control: self._data_dep_view.graph_widget.handle_preview_request(self, False) else: super().keyPressEvent(event) @@ -283,7 +285,7 @@ def mouseDoubleClickEvent(self, event) -> None: A double click on an arrow should center the data-dep view on the arrow's destination or source node If the control modifier is held, then the jump will be made to the destination. Otherwise, the source. """ - jump_to_dst = event.modifiers() & Qt.ControlModifier + jump_to_dst = event.modifiers() & Qt.KeyboardModifier.ControlModifier self._data_dep_view.graph_widget.jump_to_neighbor(self, jump_to_dst, self.mapToParent(event.pos().toPoint())) diff --git a/angrmanagement/ui/widgets/qinst_annotation.py b/angrmanagement/ui/widgets/qinst_annotation.py index b6eb10842..16d402403 100644 --- a/angrmanagement/ui/widgets/qinst_annotation.py +++ b/angrmanagement/ui/widgets/qinst_annotation.py @@ -117,7 +117,9 @@ def _move_states() -> None: symexec_view = self.symexec_view if disasm_view is None or symexec_view is None: return - to_stash, ok = QInputDialog.getText(disasm_view, "Move to?", "Target Stash Name:", QLineEdit.Normal) + to_stash, ok = QInputDialog.getText( + disasm_view, "Move to?", "Target Stash Name:", QLineEdit.EchoMode.Normal + ) if ok: symexec_view.current_simgr.move("active", to_stash, lambda s: s in self.states) symexec_view._simgrs._simgr_viewer.refresh() diff --git a/angrmanagement/ui/widgets/qinstruction.py b/angrmanagement/ui/widgets/qinstruction.py index 189de2720..9f1929228 100644 --- a/angrmanagement/ui/widgets/qinstruction.py +++ b/angrmanagement/ui/widgets/qinstruction.py @@ -77,16 +77,21 @@ def mousePressEvent(self, event: QGraphicsSceneMouseEvent) -> None: if self.disasm_view.workspace.plugins.handle_click_insn(self, event): # stop handling this event if the event has been handled by a plugin event.accept() - elif event.button() == Qt.LeftButton and QApplication.keyboardModifiers() in ( - Qt.NoModifier, - Qt.ControlModifier, + elif event.button() == Qt.MouseButton.LeftButton and QApplication.keyboardModifiers() in ( + Qt.KeyboardModifier.NoModifier, + Qt.KeyboardModifier.ControlModifier, ): # toggle selection self.infodock.toggle_instruction_selection( - self.addr, insn_pos=self.scenePos(), unique=QApplication.keyboardModifiers() != Qt.ControlModifier + self.addr, + insn_pos=self.scenePos(), + unique=QApplication.keyboardModifiers() != Qt.KeyboardModifier.ControlModifier, ) event.accept() - elif event.button() == Qt.RightButton and QApplication.keyboardModifiers() == Qt.NoModifier: + elif ( + event.button() == Qt.MouseButton.RightButton + and QApplication.keyboardModifiers() == Qt.KeyboardModifier.NoModifier + ): if self.addr not in self.infodock.selected_insns: self.infodock.toggle_instruction_selection(self.addr, insn_pos=self.scenePos(), unique=True) self.disasm_view.instruction_context_menu(self.insn, QCursor.pos()) @@ -152,7 +157,7 @@ def load_comment(self) -> None: self._comment = get_comment_for_display(self.instance.kb, self.insn.addr) def paint(self, painter, option, widget) -> None: # pylint: disable=unused-argument - painter.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) + painter.setRenderHints(QPainter.RenderHint.Antialiasing | QPainter.RenderHint.SmoothPixmapTransform) # background color backcolor = self._calc_backcolor() diff --git a/angrmanagement/ui/widgets/qlinear_viewer.py b/angrmanagement/ui/widgets/qlinear_viewer.py index 5a583c21a..7d67d09ff 100644 --- a/angrmanagement/ui/widgets/qlinear_viewer.py +++ b/angrmanagement/ui/widgets/qlinear_viewer.py @@ -37,13 +37,13 @@ def __init__(self, area, parent=None) -> None: self.area: QLinearDisassembly = area self._scene = QGraphicsScene(0, 0, self.width(), self.height()) - self.setAlignment(Qt.AlignTop | Qt.AlignLeft) + self.setAlignment(Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignLeft) self.setScene(self._scene) - self.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) + self.setRenderHints(QPainter.RenderHint.Antialiasing | QPainter.RenderHint.SmoothPixmapTransform) # Do not use the scrollbars since they are hard-linked to the size of the scene, which is bad for us - self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) - self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) + self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) + self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) def wheelEvent(self, event) -> None: self.area.wheelEvent(event) @@ -68,8 +68,8 @@ def __init__(self, instance: Instance, disasm_view, parent=None) -> None: QDisassemblyBaseControl.__init__(self, instance, disasm_view, QAbstractScrollArea) QAbstractScrollArea.__init__(self, parent=parent) - self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) - self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) + self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOn) + self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOn) self.horizontalScrollBar().setSingleStep(Conf.disasm_font_width) self.verticalScrollBar().setSingleStep(16) @@ -177,31 +177,31 @@ def changeEvent(self, event: QEvent) -> None: """ Redraw on color scheme update. """ - if event.type() == QEvent.PaletteChange: + if event.type() == QEvent.Type.PaletteChange: self.reload() def _on_vertical_scroll_bar_triggered(self, action) -> None: action = QAbstractSlider.SliderAction(action) # XXX: `action` is passed as an int - if action == QAbstractSlider.SliderSingleStepAdd: + if action == QAbstractSlider.SliderAction.SliderSingleStepAdd: # scroll down by one line self.prepare_objects(self.offset, start_line=self._start_line_in_object + 1) self.viewport().update() - elif action == QAbstractSlider.SliderSingleStepSub: + elif action == QAbstractSlider.SliderAction.SliderSingleStepSub: # Scroll up by one line self.prepare_objects(self.offset, start_line=self._start_line_in_object - 1) self.viewport().update() - elif action == QAbstractSlider.SliderPageStepAdd: + elif action == QAbstractSlider.SliderAction.SliderPageStepAdd: # Scroll down by one page lines_per_page = int(self.height() // self._line_height) self.prepare_objects(self.offset, start_line=self._start_line_in_object + lines_per_page) self.viewport().update() - elif action == QAbstractSlider.SliderPageStepSub: + elif action == QAbstractSlider.SliderAction.SliderPageStepSub: # Scroll up by one page lines_per_page = int(self.height() // self._line_height) self.prepare_objects(self.offset, start_line=self._start_line_in_object - lines_per_page) self.viewport().update() - elif action == QAbstractSlider.SliderMove: + elif action == QAbstractSlider.SliderAction.SliderMove: # Setting a new offset new_offset = int(self.verticalScrollBar().value() // self._line_height) self.prepare_objects(new_offset) diff --git a/angrmanagement/ui/widgets/qlog_widget.py b/angrmanagement/ui/widgets/qlog_widget.py index 6f74ae808..7b7cf7c7d 100644 --- a/angrmanagement/ui/widgets/qlog_widget.py +++ b/angrmanagement/ui/widgets/qlog_widget.py @@ -74,7 +74,7 @@ def columnCount(self, parent: PySide6.QtCore.QModelIndex = ...) -> int: return len(self.Headers) def headerData(self, section: int, orientation: PySide6.QtCore.Qt.Orientation, role: int = ...) -> Any: - if role != Qt.DisplayRole: + if role != Qt.ItemDataRole.DisplayRole: return None if section < len(self.Headers): return self.Headers[section] @@ -89,12 +89,12 @@ def data(self, index: PySide6.QtCore.QModelIndex, role: int = ...) -> Any: log = self.log[row] col = index.column() - if role == Qt.DisplayRole: + if role == Qt.ItemDataRole.DisplayRole: return self._get_column_text(log, col) - elif role == Qt.DecorationRole and col == QLogTableModel.COL_ICON: + elif role == Qt.ItemDataRole.DecorationRole and col == QLogTableModel.COL_ICON: return self._get_column_icon(log) - elif role == Qt.TextAlignmentRole: - return Qt.AlignTop | Qt.AlignLeft + elif role == Qt.ItemDataRole.TextAlignmentRole: + return Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignLeft return None @@ -151,8 +151,8 @@ def __init__(self, log_view) -> None: hheader.setVisible(True) hheader.setStretchLastSection(True) vheader.setVisible(False) - self.setSelectionBehavior(QAbstractItemView.SelectRows) - self.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel) + self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) + self.setHorizontalScrollMode(QAbstractItemView.ScrollMode.ScrollPerPixel) vheader.setDefaultSectionSize(20) self.setShowGrid(False) @@ -249,7 +249,7 @@ def _after_row_insert(self) -> None: self.scrollToBottom() def keyPressEvent(self, event: PySide6.QtGui.QKeyEvent) -> None: - if event.matches(QKeySequence.Copy): + if event.matches(QKeySequence.StandardKey.Copy): self.copy_selected_messages() else: super().keyPressEvent(event) @@ -268,6 +268,6 @@ def _on_double_clicked(self, item) -> None: @staticmethod def _copy_to_clipboard(content: str) -> None: clipboard = QGuiApplication.clipboard() - clipboard.setText(content, QClipboard.Clipboard) + clipboard.setText(content, QClipboard.Mode.Clipboard) if clipboard.supportsSelection(): - clipboard.setText(content, QClipboard.Selection) + clipboard.setText(content, QClipboard.Mode.Selection) diff --git a/angrmanagement/ui/widgets/qmemory_data_block.py b/angrmanagement/ui/widgets/qmemory_data_block.py index 25df02dab..fe7764955 100644 --- a/angrmanagement/ui/widgets/qmemory_data_block.py +++ b/angrmanagement/ui/widgets/qmemory_data_block.py @@ -72,7 +72,7 @@ def paint(self, painter, option, widget) -> None: # def mousePressEvent(self, event) -> None: - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: # unselect all other labels self.infodock.unselect_all_labels() # select this label @@ -182,7 +182,7 @@ def _init_line(self, addr: int, byte_offset, all_bytes): if line_chars % 8 == 0 and line_chars != self.bytes_per_line: # print a deliminator o = QGraphicsSimpleTextItem("-", self) - o.setBrush(Qt.black) + o.setBrush(Qt.GlobalColor.black) o.setFont(Conf.disasm_font) bytes_list.append(o) diff --git a/angrmanagement/ui/widgets/qmemory_viewer.py b/angrmanagement/ui/widgets/qmemory_viewer.py index 28a6d9213..7fd469441 100644 --- a/angrmanagement/ui/widgets/qmemory_viewer.py +++ b/angrmanagement/ui/widgets/qmemory_viewer.py @@ -203,8 +203,8 @@ def _init_widgets(self) -> None: area = QScrollArea() self._scrollarea = area - area.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) - area.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) + area.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) + area.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) area.setWidgetResizable(True) area.setWidget(self._view) diff --git a/angrmanagement/ui/widgets/qminimap.py b/angrmanagement/ui/widgets/qminimap.py index 55f5d48e7..04b39d802 100644 --- a/angrmanagement/ui/widgets/qminimap.py +++ b/angrmanagement/ui/widgets/qminimap.py @@ -97,13 +97,13 @@ def update_scene_drawing(self) -> None: dpr = self._view.devicePixelRatioF() self._scene_img = QImage( - dpr * self._minimap_scene_rect.width(), dpr * self._minimap_scene_rect.height(), QImage.Format_ARGB32 + dpr * self._minimap_scene_rect.width(), dpr * self._minimap_scene_rect.height(), QImage.Format.Format_ARGB32 ) self._scene_img.setDevicePixelRatio(dpr) self._scene_img.fill(Conf.disasm_view_minimap_background_color) self._view.set_extra_render_pass(True) painter = QPainter(self._scene_img) - painter.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) + painter.setRenderHints(QPainter.RenderHint.Antialiasing | QPainter.RenderHint.SmoothPixmapTransform) scene.render(painter, target=self._minimap_scene_rect) self._view.set_extra_render_pass(False) self.update() @@ -137,7 +137,7 @@ def __init__(self, target_view: QBaseGraphicsView, parent=None) -> None: self._minimap_target_scene_viewer: QMiniMapTargetSceneViewer = QMiniMapTargetSceneViewer(self._target_view) self._minimap_scene.addItem(self._minimap_target_scene_viewer) self._target_view.visible_scene_rect_changed.connect(self.on_target_viewport_visible_scene_rect_changed) - self.setFrameStyle(QFrame.NoFrame) + self.setFrameStyle(QFrame.Shape.NoFrame) def on_target_viewport_visible_scene_rect_changed(self, visible: QRectF) -> None: scene = self._target_view.scene() @@ -212,9 +212,9 @@ def mousePressEvent(self, event: QMouseEvent) -> None: """ Handle mouse press, moving the target view port to cursor position in target scene. """ - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self._is_mouse_pressed = True - self.setCursor(Qt.ClosedHandCursor) + self.setCursor(Qt.CursorShape.ClosedHandCursor) self._target_view.centerOn(self.map_event_pos_to_target_scene_pos(event.pos())) event.accept() @@ -230,8 +230,8 @@ def mouseReleaseEvent(self, event: QMouseEvent) -> None: """ Handle mouse release, ending viewport drag. """ - if event.button() == Qt.LeftButton: - self.setCursor(Qt.ArrowCursor) + if event.button() == Qt.MouseButton.LeftButton: + self.setCursor(Qt.CursorShape.ArrowCursor) event.accept() self._is_mouse_pressed = False @@ -239,7 +239,7 @@ def wheelEvent(self, event: QWheelEvent) -> None: """ Forward the wheel event to target view to handle zoom events. """ - if event.modifiers() & Qt.ControlModifier == Qt.ControlModifier: + if event.modifiers() & Qt.KeyboardModifier.ControlModifier == Qt.KeyboardModifier.ControlModifier: pos = event.position() self._target_view.centerOn(self.map_event_pos_to_target_scene_pos(QPoint(pos.x(), pos.y()))) @@ -249,5 +249,5 @@ def changeEvent(self, event: QEvent) -> None: """ Redraw on color scheme update. """ - if event.type() == QEvent.PaletteChange: + if event.type() == QEvent.Type.PaletteChange: self.reload_target_scene() diff --git a/angrmanagement/ui/widgets/qoperand.py b/angrmanagement/ui/widgets/qoperand.py index 4dd6ae920..4b793801f 100644 --- a/angrmanagement/ui/widgets/qoperand.py +++ b/angrmanagement/ui/widgets/qoperand.py @@ -130,13 +130,13 @@ def operand_descriptor(self): # def mousePressEvent(self, event) -> None: - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: selected = self.infodock.toggle_operand_selection( self.insn.addr, self.operand_index, self.operand_descriptor, insn_pos=self.parentItem().scenePos(), - unique=QApplication.keyboardModifiers() != Qt.ControlModifier, + unique=QApplication.keyboardModifiers() != Qt.KeyboardModifier.ControlModifier, ) if selected: # select the current instruction, too @@ -146,7 +146,7 @@ def mousePressEvent(self, event) -> None: def mouseDoubleClickEvent(self, event) -> None: button = event.button() - if button == Qt.LeftButton: + if button == Qt.MouseButton.LeftButton: if self._branch_target is not None: self.disasm_view.jump_to(self._branch_target, src_ins_addr=self.insn.addr, use_animation=True) return diff --git a/angrmanagement/ui/widgets/qpatch_table.py b/angrmanagement/ui/widgets/qpatch_table.py index c195ba9f3..87c513bbb 100644 --- a/angrmanagement/ui/widgets/qpatch_table.py +++ b/angrmanagement/ui/widgets/qpatch_table.py @@ -52,8 +52,8 @@ def __init__(self, instance: Instance, parent) -> None: self.setColumnCount(len(self.HEADER)) self.setHorizontalHeaderLabels(self.HEADER) - self.setSelectionBehavior(QAbstractItemView.SelectRows) - self.horizontalHeader().setSectionResizeMode(4, QHeaderView.Stretch) + self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) + self.horizontalHeader().setSectionResizeMode(4, QHeaderView.ResizeMode.Stretch) self.verticalHeader().setVisible(False) self.items = [] @@ -124,10 +124,10 @@ def revert_selected_patches(self) -> None: dlg = QMessageBox() dlg.setWindowTitle("Revert patches") dlg.setText("Are you sure you want to revert selected patches?") - dlg.setIcon(QMessageBox.Question) - dlg.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel) - dlg.setDefaultButton(QMessageBox.Cancel) - if dlg.exec_() != QMessageBox.Yes: + dlg.setIcon(QMessageBox.Icon.Question) + dlg.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.Cancel) + dlg.setDefaultButton(QMessageBox.StandardButton.Cancel) + if dlg.exec_() != QMessageBox.StandardButton.Yes: return selected_patches = self.get_selected_patches() diff --git a/angrmanagement/ui/widgets/qphivariable.py b/angrmanagement/ui/widgets/qphivariable.py index ac8f6552c..d1444ce78 100644 --- a/angrmanagement/ui/widgets/qphivariable.py +++ b/angrmanagement/ui/widgets/qphivariable.py @@ -7,10 +7,15 @@ from .qgraph_object import QCachedGraphicsItem if TYPE_CHECKING: + from PySide6.QtGui import QPainter + from PySide6.QtWidgets import QStyleOptionGraphicsItem, QWidget + from angrmanagement.data.instance import Instance class QPhiVariable(QCachedGraphicsItem): + """QPhiVariable is a graphical representation of a phi variable in the disassembly view.""" + IDENT_LEFT_PADDING = 5 def __init__(self, instance: Instance, disasm_view, phi_variable, config, parent=None) -> None: @@ -50,7 +55,12 @@ def __init__(self, instance: Instance, disasm_view, phi_variable, config, parent # Public methods # - def paint(self, painter, option, widget) -> None: # pylint: disable=unused-argument + def paint( # pylint: disable=unused-argument + self, + painter: QPainter, + option: QStyleOptionGraphicsItem, + widget: QWidget | None = None, + ) -> None: if self.disasm_view.show_variable_identifier is False: # Phi variables are not displayed if variable identifies are hidden return @@ -60,37 +70,37 @@ def paint(self, painter, option, widget) -> None: # pylint: disable=unused-argu painter.setFont(self._config.disasm_font) # variable name - painter.setPen(Qt.darkGreen) + painter.setPen(Qt.GlobalColor.darkGreen) painter.drawText(x, self._config.disasm_font_ascent, self._variable_name) x += self._variable_name_width # variable ident if self.disasm_view.show_variable_identifier: x += self.IDENT_LEFT_PADDING - painter.setPen(Qt.blue) + painter.setPen(Qt.GlobalColor.blue) painter.drawText(x, self._config.disasm_font_ascent, self._variable_ident) x += self._variable_ident_width # The equal sign - painter.setPen(Qt.black) + painter.setPen(Qt.GlobalColor.black) painter.drawText(x, self._config.disasm_font_ascent, " = ") x += self._config.disasm_font_width * 3 - painter.setPen(Qt.darkGreen) + painter.setPen(Qt.GlobalColor.darkGreen) painter.drawText(x, self._config.disasm_font_ascent, "\u0278(") x += self._config.disasm_font_width * 2 for i, (subvar_ident, ident_width) in enumerate( zip(self._subvar_idents, self._subvar_ident_widths, strict=False) ): - painter.setPen(Qt.darkGreen) + painter.setPen(Qt.GlobalColor.darkGreen) painter.drawText(x, self._config.disasm_font_ascent, subvar_ident) x += ident_width if i != len(self._subvar_idents) - 1: - painter.setPen(Qt.black) + painter.setPen(Qt.GlobalColor.black) painter.drawText(x, self._config.disasm_font_ascent, ", ") x += 2 + self._config.disasm_font_width - painter.setPen(Qt.darkGreen) + painter.setPen(Qt.GlobalColor.darkGreen) painter.drawText(x, self._config.disasm_font_ascent, ")") def refresh(self) -> None: diff --git a/angrmanagement/ui/widgets/qproximity_graph.py b/angrmanagement/ui/widgets/qproximity_graph.py index ff65cc901..bece5c8ec 100644 --- a/angrmanagement/ui/widgets/qproximity_graph.py +++ b/angrmanagement/ui/widgets/qproximity_graph.py @@ -133,7 +133,7 @@ def keyPressEvent(self, event) -> None: key = event.key() - if key == Qt.Key_Tab: + if key == Qt.Key.Key_Tab: self._symexec_view.switch_to_disassembly_view() event.accept() diff --git a/angrmanagement/ui/widgets/qproximitygraph_block.py b/angrmanagement/ui/widgets/qproximitygraph_block.py index 44358d44d..ca51e1103 100644 --- a/angrmanagement/ui/widgets/qproximitygraph_block.py +++ b/angrmanagement/ui/widgets/qproximitygraph_block.py @@ -76,7 +76,7 @@ def mousePressEvent(self, event) -> None: # pylint: disable=useless-super-deleg super().mousePressEvent(event) def mouseReleaseEvent(self, event) -> None: - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self.selected = not self.selected self._proximity_view.redraw_graph() event.accept() @@ -85,7 +85,7 @@ def mouseReleaseEvent(self, event) -> None: def mouseDoubleClickEvent(self, event) -> None: # Jump to the reference address of the node - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: if self._node.ref_at: self._workspace.viz(next(iter(self._node.ref_at))) event.accept() @@ -169,7 +169,10 @@ def _init_widgets(self) -> None: self._text_item.setPos(self.HORIZONTAL_PADDING, self.VERTICAL_PADDING) def mouseDoubleClickEvent(self, event) -> None: - if event.button() == Qt.LeftButton and (event.modifiers() & Qt.ControlModifier) == Qt.ControlModifier: + if ( + event.button() == Qt.MouseButton.LeftButton + and (event.modifiers() & Qt.KeyboardModifier.ControlModifier) == Qt.KeyboardModifier.ControlModifier + ): # ctrl + double click to collapse a function call event.accept() self._proximity_view.collapse_function(self._node.func) @@ -284,7 +287,10 @@ def _argument_text(self, arg) -> tuple[type, str]: # pylint: disable=no-self-us return object, "Unknown" def mouseDoubleClickEvent(self, event) -> None: - if event.button() == Qt.LeftButton and (event.modifiers() & Qt.ControlModifier) == Qt.ControlModifier: + if ( + event.button() == Qt.MouseButton.LeftButton + and (event.modifiers() & Qt.KeyboardModifier.ControlModifier) == Qt.KeyboardModifier.ControlModifier + ): # ctrl + double click to expand a function call event.accept() self._proximity_view.expand_function(self._node.callee) diff --git a/angrmanagement/ui/widgets/qregister_viewer.py b/angrmanagement/ui/widgets/qregister_viewer.py index 4c49c892d..2065443b9 100644 --- a/angrmanagement/ui/widgets/qregister_viewer.py +++ b/angrmanagement/ui/widgets/qregister_viewer.py @@ -175,8 +175,8 @@ def _init_widgets(self) -> None: layout = QVBoxLayout() area = QScrollArea() - area.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) - area.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) + area.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) + area.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) area.setWidgetResizable(True) regs = self.ARCH_REGISTERS[self._state.arch.name] @@ -190,7 +190,7 @@ def _init_widgets(self) -> None: lbl_reg_name = QLabel(self) lbl_reg_name.setProperty("class", "reg_viewer_label") lbl_reg_name.setText(reg_name) - lbl_reg_name.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) + lbl_reg_name.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) sublayout.addWidget(lbl_reg_name) sublayout.addSpacing(10) @@ -208,7 +208,7 @@ def _init_widgets(self) -> None: container = QFrame() container.setAutoFillBackground(True) palette = container.palette() - palette.setColor(container.backgroundRole(), Qt.white) + palette.setColor(container.backgroundRole(), Qt.GlobalColor.white) container.setPalette(palette) container.setLayout(layout) diff --git a/angrmanagement/ui/widgets/qsimulation_manager_viewer.py b/angrmanagement/ui/widgets/qsimulation_manager_viewer.py index b81c45576..66d845aff 100644 --- a/angrmanagement/ui/widgets/qsimulation_manager_viewer.py +++ b/angrmanagement/ui/widgets/qsimulation_manager_viewer.py @@ -23,7 +23,7 @@ def __init__(self, stash_name: str, simgr_viewer) -> None: self.simgr_viewer = simgr_viewer self.stash_name = stash_name super().__init__(simgr_viewer) - self.setFlags(self.flags() & ~Qt.ItemIsSelectable) + self.setFlags(self.flags() & ~Qt.ItemFlag.ItemIsSelectable) self.refresh() def __iter__(self): @@ -132,7 +132,7 @@ def __init__(self, simgr, parent=None) -> None: self._init_widgets() self.simgr.am_subscribe(self.refresh) - self.setSelectionMode(QAbstractItemView.ExtendedSelection) + self.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection) def _stash_to_selected_states(self): stash_to_states = defaultdict(list) diff --git a/angrmanagement/ui/widgets/qsimulation_managers.py b/angrmanagement/ui/widgets/qsimulation_managers.py index 1ed8c091c..5d90f291f 100644 --- a/angrmanagement/ui/widgets/qsimulation_managers.py +++ b/angrmanagement/ui/widgets/qsimulation_managers.py @@ -100,8 +100,8 @@ def add_address_to_list(qtreelist: QTreeWidget, addr: int): item = QTreeWidgetItem(qtreelist) item.setText(0, f"{addr:#x}") - item.setFlags(item.flags() | Qt.ItemIsUserCheckable) - item.setData(0, Qt.CheckStateRole, Qt.Checked) + item.setFlags(item.flags() | Qt.ItemFlag.ItemIsUserCheckable) + item.setData(0, Qt.ItemDataRole.CheckStateRole, Qt.CheckState.Checked) return item # @@ -350,11 +350,11 @@ def _get_checked_items(qlist: QTreeWidget): items = [] for i in range(qlist.topLevelItemCount()): item = qlist.topLevelItem(i) - if item.checkState(0) == Qt.Checked: + if item.checkState(0) == Qt.CheckState.Checked: items.append(item) for j in range(item.childCount()): sub_item = item.child(j) - if sub_item.checkState(0) == Qt.Checked: + if sub_item.checkState(0) == Qt.CheckState.Checked: items.append(sub_item) return items diff --git a/angrmanagement/ui/widgets/qstate_block.py b/angrmanagement/ui/widgets/qstate_block.py index 17acb1ccf..7ea74b4b9 100644 --- a/angrmanagement/ui/widgets/qstate_block.py +++ b/angrmanagement/ui/widgets/qstate_block.py @@ -84,7 +84,7 @@ def mousePressEvent(self, event) -> None: # pylint: disable=no-self-use def mouseReleaseEvent(self, event) -> None: # _l.debug('QStateBlock received mouse release event') - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self.selected = not self.selected self.symexec_view.redraw_graph() event.accept() @@ -93,7 +93,7 @@ def mouseReleaseEvent(self, event) -> None: def mouseDoubleClickEvent(self, event) -> None: # _l.debug('QStateBlock received mouse double click event') - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: if self.state is not None: self.symexec_view.workspace.viz(self.state.addr) event.accept() @@ -129,7 +129,7 @@ def paint(self, painter, option, widget) -> None: # pylint: disable=unused-argu # The addr label addr_label_x = x + self.HORIZONTAL_PADDING addr_label_y = y + self.VERTICAL_PADDING - painter.setPen(Qt.black) + painter.setPen(Qt.GlobalColor.black) painter.drawText(addr_label_x, addr_label_y + self._config.symexec_font_ascent, self._label_str) y += self._config.symexec_font_height + self.LINE_MARGIN diff --git a/angrmanagement/ui/widgets/qstate_table.py b/angrmanagement/ui/widgets/qstate_table.py index f5fdfebb4..79f2d05c1 100644 --- a/angrmanagement/ui/widgets/qstate_table.py +++ b/angrmanagement/ui/widgets/qstate_table.py @@ -76,7 +76,7 @@ def __init__(self, workspace: Workspace, instance: Instance, parent, selection_c self.setColumnCount(len(header_labels)) self.setHorizontalHeaderLabels(header_labels) - self.setSelectionBehavior(QAbstractItemView.SelectRows) + self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) self.items = [] self.workspace = workspace diff --git a/angrmanagement/ui/widgets/qstring_table.py b/angrmanagement/ui/widgets/qstring_table.py index 5d1fbae64..3f165e15a 100644 --- a/angrmanagement/ui/widgets/qstring_table.py +++ b/angrmanagement/ui/widgets/qstring_table.py @@ -101,11 +101,11 @@ def columnCount(self, parent=None) -> int: # pylint: disable=unused-argument return len(self.HEADER) def headerData(self, section, orientation, role=None) -> Any: # pylint: disable=unused-argument - if role == Qt.DisplayRole: + if role == Qt.ItemDataRole.DisplayRole: if section < len(self.HEADER): return self.HEADER[section] - elif role == Qt.InitialSortOrderRole: - return Qt.AscendingOrder + elif role == Qt.ItemDataRole.InitialSortOrderRole: + return Qt.SortOrder.AscendingOrder return None @@ -120,9 +120,9 @@ def data(self, index, role=None) -> Any: col = index.column() v = self.values[row] - if role == Qt.DisplayRole: + if role == Qt.ItemDataRole.DisplayRole: return self._get_column_text(v, col) - elif role == Qt.FontRole: + elif role == Qt.ItemDataRole.FontRole: return Conf.tabular_view_font return None @@ -132,7 +132,7 @@ def sort(self, column, order=None) -> Any: self._values = sorted( self.values, key=lambda x: self._get_column_data(x, column), - reverse=order == Qt.DescendingOrder, + reverse=order == Qt.SortOrder.DescendingOrder, ) self.layoutChanged.emit() @@ -171,24 +171,24 @@ def __init__(self, instance: Instance, parent, selection_callback=None) -> None: self._selected = selection_callback self._filter = None - self.setSelectionBehavior(QAbstractItemView.SelectRows) + self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) self.setShowGrid(False) self.verticalHeader().setVisible(False) self.verticalHeader().setDefaultSectionSize(24) - self.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel) + self.setHorizontalScrollMode(QAbstractItemView.ScrollMode.ScrollPerPixel) self._model = QStringModel(None) self._proxy = QSortFilterProxyModel(self) self._proxy.setSourceModel(self._model) - self._proxy.setFilterCaseSensitivity(Qt.CaseInsensitive) + self._proxy.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive) self.setModel(self._proxy) self.setSortingEnabled(True) - self.setSelectionMode(QAbstractItemView.SingleSelection) + self.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection) # let the last column (string) fill table width - self.horizontalHeader().setSectionResizeMode(QHeaderView.Fixed) - self.horizontalHeader().setSectionResizeMode(QStringModel.STRING_COL, QHeaderView.Stretch) + self.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Fixed) + self.horizontalHeader().setSectionResizeMode(QStringModel.STRING_COL, QHeaderView.ResizeMode.Stretch) self.doubleClicked.connect(self._on_string_selected) @@ -259,7 +259,7 @@ def _on_string_selected(self, model_index) -> None: self._selected(selected_item) def keyPressEvent(self, event: QKeyEvent) -> None: - if event.key() == Qt.Key_X: + if event.key() == Qt.Key.Key_X: # xrefs if self._model is None: return diff --git a/angrmanagement/ui/widgets/qsymexec_graph.py b/angrmanagement/ui/widgets/qsymexec_graph.py index cf37a57a3..bcf26faa7 100644 --- a/angrmanagement/ui/widgets/qsymexec_graph.py +++ b/angrmanagement/ui/widgets/qsymexec_graph.py @@ -100,7 +100,7 @@ def keyPressEvent(self, event) -> None: key = event.key() - if key == Qt.Key_Tab: + if key == Qt.Key.Key_Tab: self._symexec_view.switch_to_disassembly_view() event.accept() diff --git a/angrmanagement/ui/widgets/qtrace_map.py b/angrmanagement/ui/widgets/qtrace_map.py index ecdef1e1b..a41b63ea4 100644 --- a/angrmanagement/ui/widgets/qtrace_map.py +++ b/angrmanagement/ui/widgets/qtrace_map.py @@ -142,7 +142,7 @@ def _get_offset_size_rect(self, offset: int, size: int) -> QRectF: return QRectF(x, 0, width, self._height) def _create_line_indicator( - self, addr: int, item_map, color=Qt.yellow, show_frontier: bool = False, z=None, z_frontier=None + self, addr: int, item_map, color=Qt.GlobalColor.yellow, show_frontier: bool = False, z=None, z_frontier=None ) -> None: """ Generate a cursor at a given address. @@ -167,7 +167,7 @@ def _create_line_indicator( # Draw frontier gradients r = QRectF(center - frontier_width, pos_y, frontier_width, height) bg = QLinearGradient(r.topLeft(), r.topRight()) - color = Qt.red + color = Qt.GlobalColor.red top_color = QColor(color) top_color.setAlpha(0) bg.setColorAt(0, top_color) @@ -176,7 +176,7 @@ def _create_line_indicator( bg.setColorAt(1, bottom_color) i = QGraphicsRectItem(r, parent=self) - i.setPen(Qt.NoPen) + i.setPen(Qt.PenStyle.NoPen) i.setBrush(bg) if z_frontier is not None: i.setZValue(z_frontier) @@ -184,7 +184,7 @@ def _create_line_indicator( r = QRectF(center, pos_y, frontier_width, height) bg = QLinearGradient(r.topLeft(), r.topRight()) - color = Qt.blue + color = Qt.GlobalColor.blue top_color = QColor(color) bg.setColorAt(0, top_color) bottom_color = QColor(color) @@ -192,7 +192,7 @@ def _create_line_indicator( bg.setColorAt(1, bottom_color) i = QGraphicsRectItem(r, parent=self) - i.setPen(Qt.NoPen) + i.setPen(Qt.PenStyle.NoPen) i.setBrush(bg) if z_frontier is not None: i.setZValue(z_frontier) @@ -235,7 +235,7 @@ def _gen_checkpoint_indicators(self) -> None: scene.removeItem(item) self._checkpoint_items.clear() - color = QColor(Qt.green) + color = QColor(Qt.GlobalColor.green) for checkpoint_addr in self._checkpoints: self._create_line_indicator(checkpoint_addr, self._checkpoint_items, color=color, z=self.ZVALUE_CHECKPOINT) @@ -261,7 +261,9 @@ def _gen_hover_indicator(self) -> None: self._hover_items.clear() if self._hover_addr is not None: - self._create_line_indicator(self._hover_addr, self._hover_items, color=Qt.gray, z=self.ZVALUE_HOVER) + self._create_line_indicator( + self._hover_addr, self._hover_items, color=Qt.GlobalColor.gray, z=self.ZVALUE_HOVER + ) def _remove_hover_indicators(self) -> None: """ @@ -272,14 +274,14 @@ def _remove_hover_indicators(self) -> None: self._gen_hover_indicator() def mousePressEvent(self, event) -> None: - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: pos = event.pos() offset = pos.x() self.select_offset(offset) self._pressed = True def mouseReleaseEvent(self, event) -> None: - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self._pressed = False def mouseMoveEvent(self, event) -> None: @@ -325,8 +327,8 @@ class QTraceMapView(QGraphicsView): def __init__(self, instance: Instance, parent=None) -> None: super().__init__(parent) self.instance = instance - self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) - self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) + self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) + self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.setMouseTracking(True) self._scene = QGraphicsScene(parent=self) self.setScene(self._scene) @@ -337,9 +339,9 @@ def __init__(self, instance: Instance, parent=None) -> None: self._base_width: int = 0 self.setBackgroundBrush(Conf.palette_base) - self.setResizeAnchor(QGraphicsView.NoAnchor) - self.setTransformationAnchor(QGraphicsView.NoAnchor) - self.setAlignment(Qt.AlignTop | Qt.AlignLeft) + self.setResizeAnchor(QGraphicsView.ViewportAnchor.NoAnchor) + self.setTransformationAnchor(QGraphicsView.ViewportAnchor.NoAnchor) + self.setAlignment(Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignLeft) self.update_size() def mouseMoveEvent(self, event) -> None: @@ -358,7 +360,7 @@ def wheelEvent(self, event) -> None: """ Handle wheel events to scale and translate the trace map. """ - if event.modifiers() & Qt.ControlModifier == Qt.ControlModifier: + if event.modifiers() & Qt.KeyboardModifier.ControlModifier == Qt.KeyboardModifier.ControlModifier: self.adjust_viewport_scale( 1.25 if event.angleDelta().y() > 0 else 1 / 1.25, QPoint(event.position().x(), event.position().y()) ) @@ -392,16 +394,16 @@ def keyPressEvent(self, event) -> None: """ Handle key events. """ - if event.modifiers() & Qt.ControlModifier == Qt.ControlModifier: - if event.key() == Qt.Key_0: + if event.modifiers() & Qt.KeyboardModifier.ControlModifier == Qt.KeyboardModifier.ControlModifier: + if event.key() == Qt.Key.Key_0: self.adjust_viewport_scale() event.accept() return - elif event.key() == Qt.Key_Equal: + elif event.key() == Qt.Key.Key_Equal: self.adjust_viewport_scale(1.25) event.accept() return - elif event.key() == Qt.Key_Minus: + elif event.key() == Qt.Key.Key_Minus: self.adjust_viewport_scale(1 / 1.25) event.accept() return @@ -411,7 +413,7 @@ def changeEvent(self, event: QEvent) -> None: """ Redraw on color scheme update. """ - if event.type() == QEvent.StyleChange: + if event.type() == QEvent.Type.StyleChange: self.setBackgroundBrush(Conf.palette_base) self.fm.refresh() diff --git a/angrmanagement/ui/widgets/qtypedef.py b/angrmanagement/ui/widgets/qtypedef.py index a7da106cf..a0129c306 100644 --- a/angrmanagement/ui/widgets/qtypedef.py +++ b/angrmanagement/ui/widgets/qtypedef.py @@ -31,7 +31,7 @@ def __init__(self, parent, ty: TypeRef, all_types: TypesStore) -> None: self.highlight = None # which line should be highlighted self.all_types = all_types - self.setAttribute(Qt.WA_Hover) + self.setAttribute(Qt.WidgetAttribute.WA_Hover) self.setMouseTracking(True) self.refresh() diff --git a/angrmanagement/ui/widgets/qvariable.py b/angrmanagement/ui/widgets/qvariable.py index cdc099de9..8f6a35fb3 100644 --- a/angrmanagement/ui/widgets/qvariable.py +++ b/angrmanagement/ui/widgets/qvariable.py @@ -62,10 +62,10 @@ def refresh(self) -> None: # def mousePressEvent(self, event) -> None: - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self.infodock.toggle_variable_selection( self.variable, - unique=QApplication.keyboardModifiers() != Qt.ControlModifier, + unique=QApplication.keyboardModifiers() != Qt.KeyboardModifier.ControlModifier, ) else: super().mousePressEvent(event) diff --git a/angrmanagement/ui/widgets/qvextemps_viewer.py b/angrmanagement/ui/widgets/qvextemps_viewer.py index 38a2eff4c..16f5c1bad 100644 --- a/angrmanagement/ui/widgets/qvextemps_viewer.py +++ b/angrmanagement/ui/widgets/qvextemps_viewer.py @@ -37,8 +37,8 @@ def sizeHint(self): def _init_widgets(self) -> None: area = QScrollArea() - area.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) - area.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) + area.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) + area.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) area.setWidgetResizable(True) self._area = area @@ -62,7 +62,7 @@ def _load_tmps(self) -> None: lbl_tmp_name = QLabel(self) lbl_tmp_name.setProperty("class", "reg_viewer_label") lbl_tmp_name.setText("tmp_%d" % tmp_id) - lbl_tmp_name.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) + lbl_tmp_name.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) sublayout.addWidget(lbl_tmp_name) sublayout.addSpacing(10) @@ -81,7 +81,7 @@ def _load_tmps(self) -> None: container = QFrame() container.setAutoFillBackground(True) palette = container.palette() - palette.setColor(container.backgroundRole(), Qt.white) + palette.setColor(container.backgroundRole(), Qt.GlobalColor.white) container.setPalette(palette) container.setLayout(layout) diff --git a/angrmanagement/ui/widgets/qxref_viewer.py b/angrmanagement/ui/widgets/qxref_viewer.py index 45be7a426..5a4c7d8d2 100644 --- a/angrmanagement/ui/widgets/qxref_viewer.py +++ b/angrmanagement/ui/widgets/qxref_viewer.py @@ -79,7 +79,7 @@ def sort(self, column, order) -> None: self.xrefs = sorted( self.xrefs, key=lambda x: self._get_column_data(x, column), - reverse=order == Qt.DescendingOrder, + reverse=order == Qt.SortOrder.DescendingOrder, ) self.layoutChanged.emit() @@ -269,11 +269,11 @@ def __init__( super().__init__(parent) self.verticalHeader().setVisible(False) - self.setSelectionBehavior(QAbstractItemView.SelectRows) - self.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel) + self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) + self.setHorizontalScrollMode(QAbstractItemView.ScrollMode.ScrollPerPixel) self.setShowGrid(False) - self.verticalHeader().setSectionResizeMode(QHeaderView.Fixed) + self.verticalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Fixed) self.verticalHeader().setDefaultSectionSize(24) self._instance = instance @@ -312,11 +312,11 @@ def __init__( self.setColumnWidth(idx, width) self.setSortingEnabled(True) - self.setSelectionMode(QAbstractItemView.SingleSelection) + self.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection) hheader = self.horizontalHeader() hheader.setStretchLastSection(True) - hheader.setSectionResizeMode(0, QHeaderView.ResizeToContents) + hheader.setSectionResizeMode(0, QHeaderView.ResizeMode.ResizeToContents) self.doubleClicked.connect(self._on_item_doubleclicked) diff --git a/angrmanagement/utils/graph_layouter.py b/angrmanagement/utils/graph_layouter.py index cf1366dea..5bf163f68 100644 --- a/angrmanagement/utils/graph_layouter.py +++ b/angrmanagement/utils/graph_layouter.py @@ -26,11 +26,11 @@ def __init__(self, graph, col_map, row_map, node_locs, max_col, max_row) -> None self._max_col = max_col # Mark whether a spot (col, row) is valid or not for putting edges. - self._edge_valid = None + self._edge_valid = [] # A map between spots (col, row) and all vertical edges at that spot. - self.vertical_edges = None + self.vertical_edges = [] # A map between spots (col, row) and all horizontal edges at that spot. - self.horizontal_edges = None + self.horizontal_edges = [] self._in_edges = defaultdict(list) self._out_edges = defaultdict(list) diff --git a/pyproject.toml b/pyproject.toml index ccafe7162..5909dade0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,3 +40,13 @@ ignore = [ [tool.ruff.lint.isort] required-imports = ["from __future__ import annotations"] + + +[tool.mypy] +packages = ["angrmanagement", "tests"] +exclude = [ + "angrmanagement/vendor/", + "/build", + "/dist", +] +follow_imports = "silent"