Skip to content

Commit

Permalink
Use enum names for mypy (#1304)
Browse files Browse the repository at this point in the history
* Use enum names for mypy

* Improve lint
  • Loading branch information
twizmwazin authored Aug 1, 2024
1 parent 271fa18 commit c42ae67
Show file tree
Hide file tree
Showing 101 changed files with 621 additions and 542 deletions.
14 changes: 7 additions & 7 deletions angrmanagement/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions angrmanagement/logic/url_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions angrmanagement/plugins/ail2asm/asm_output.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion angrmanagement/plugins/dep_viewer/dep_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion angrmanagement/plugins/source_importer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
23 changes: 12 additions & 11 deletions angrmanagement/plugins/source_viewer/source_viewer_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
28 changes: 16 additions & 12 deletions angrmanagement/plugins/trace_viewer/qtrace_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions angrmanagement/plugins/trace_viewer/trace_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down
30 changes: 16 additions & 14 deletions angrmanagement/plugins/value_search/qsearch_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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()

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit c42ae67

Please sign in to comment.