Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add adjustable font size for HiDPI monitors for IDA plugin #2570 #2583

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions capa/ida/plugin/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,12 @@ def get_values(self):
)


class CapaExplorerForm(idaapi.PluginForm):
"""form element for plugin interface"""
# Add this import at the top of the file
from PyQt5.QtGui import QFont


# Modify the __init__ method of the CapaExplorerForm class
class CapaExplorerForm(idaapi.PluginForm):
def __init__(self, name: str, option=Options.NO_ANALYSIS):
"""initialize form elements"""
super().__init__()
Expand Down Expand Up @@ -233,6 +236,10 @@ def __init__(self, name: str, option=Options.NO_ANALYSIS):
self.view_rulegen_limit_features_by_ea: QtWidgets.QCheckBox
self.view_rulegen_status_label: QtWidgets.QLabel

# Font settings
self.font_size = 10 # Default font size
self.font_family = "Courier" # Default font family

self.Show()

analyze = settings.user.get(CAPA_SETTINGS_ANALYZE)
Expand All @@ -254,6 +261,34 @@ def OnCreate(self, form):
self.load_interface()
self.load_ida_hooks()

# Add font menu
self.add_font_menu()

def add_font_menu(self):
"""Add a menu option to adjust font size."""
menu = idaapi.create_menu("Options")
idaapi.add_menu_item(menu, "Increase Font Size", "", 0, self.increase_font_size, ())
idaapi.add_menu_item(menu, "Decrease Font Size", "", 0, self.decrease_font_size, ())
Comment on lines +267 to +271
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add this to the plugin's existing Settings option.


def increase_font_size(self):
"""Increase the font size."""
self.font_size += 1
self.apply_font()

def decrease_font_size(self):
"""Decrease the font size."""
self.font_size -= 1
self.apply_font()

def apply_font(self):
"""Apply the font to all widgets."""
font = QFont(self.font_family, self.font_size)
self.parent.setFont(font)
self.view_tree.setFont(font)
self.view_rulegen_preview.setFont(font)
self.view_rulegen_editor.setFont(font)
self.view_rulegen_features.setFont(font)

def Show(self):
"""creates form if not already create, else brings plugin to front"""
return super().Show(
Expand Down
7 changes: 3 additions & 4 deletions capa/ida/plugin/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ class CapaExplorerRulegenPreview(QtWidgets.QTextEdit):
def __init__(self, parent=None):
""" """
super().__init__(parent)

self.setFont(QtGui.QFont("Courier", weight=QtGui.QFont.Bold))
self.setFont(QtGui.QFont("Courier", 10, weight=QtGui.QFont.Bold)) # Set default font size
self.setLineWrapMode(QtWidgets.QTextEdit.NoWrap)
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
self.setAcceptRichText(False)
Expand Down Expand Up @@ -327,7 +326,7 @@ def __init__(self, preview, parent=None):
self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
self.setStyleSheet("QTreeView::item {padding-right: 15 px;padding-bottom: 2 px;}")

self.setFont(QtGui.QFont("Courier", 10))
# configure view columns to auto-resize
for idx in range(3):
self.header().setSectionResizeMode(idx, QtWidgets.QHeaderView.Interactive)
Expand Down Expand Up @@ -817,7 +816,7 @@ def __init__(self, editor, parent=None):

self.setHeaderLabels(["Feature", "Address"])
self.setStyleSheet("QTreeView::item {padding-right: 15 px;padding-bottom: 2 px;}")

self.setFont(QtGui.QFont("Courier", 10))
# configure view columns to auto-resize
for idx in range(2):
self.header().setSectionResizeMode(idx, QtWidgets.QHeaderView.Interactive)
Expand Down
Loading