Skip to content

Commit

Permalink
Add Welcome dialog with some quick actions (angr#1204)
Browse files Browse the repository at this point in the history
  • Loading branch information
mborgerson authored Mar 13, 2024
1 parent b99556f commit 3ebf53b
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
3 changes: 3 additions & 0 deletions angrmanagement/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ def drawContents(self, painter):
main_window.initialized = True
main_window.workspace.view_manager.main_window_initialized()

if file_to_open is None:
main_window.show_welcome_dialog()

app.exec_()


Expand Down
104 changes: 104 additions & 0 deletions angrmanagement/ui/dialogs/welcome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import functools
import os.path

from PySide6.QtGui import QPixmap, Qt
from PySide6.QtWidgets import (
QApplication,
QDialog,
QFrame,
QGraphicsScene,
QGraphicsView,
QGroupBox,
QHBoxLayout,
QPushButton,
QVBoxLayout,
)

from angrmanagement import __version__
from angrmanagement.config import IMG_LOCATION, Conf
from angrmanagement.logic import GlobalInfo
from angrmanagement.ui.icons import icon


class WelcomeDialog(QDialog):
"""
Welcome dialog.
"""

def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Welcome")
self._init_widgets()

def _init_widgets(self):
self.setStyleSheet("QPushButton { text-align:left; }")

# Banner with angr-management version string
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.resize(banner_pixmap.size())
banner_scene = QGraphicsScene()
banner_view.setScene(banner_scene)
pi = banner_scene.addPixmap(banner_pixmap)
font = QApplication.font()
font.setPointSizeF(9.0)
ti = banner_scene.addSimpleText(__version__, font)
ti.setBrush(Qt.white)
ti.moveBy(pi.boundingRect().width() - ti.boundingRect().width() - 6, 6)

# Recent files
recent_files_group = QGroupBox("Recent Projects")
recent_files_layout = QVBoxLayout()
recent_files_group.setLayout(recent_files_layout)

for path in reversed(Conf.recent_files):
pb = QPushButton(icon("file"), os.path.basename(path))
pb.setFlat(True)
pb.clicked.connect(functools.partial(self._load_recent_file, path))
recent_files_layout.addWidget(pb)

recent_files_layout.addStretch()

# Getting Started actions
actions_group = QGroupBox("Getting Started")
actions_layout = QVBoxLayout()

pb = QPushButton(icon("file-open"), "Open file...")
pb.setFlat(True)
pb.clicked.connect(self._open_file)
actions_layout.addWidget(pb)

pb = QPushButton(icon("docs"), "Documentation")
pb.setFlat(True)
pb.clicked.connect(GlobalInfo.main_window.open_doc_link)
actions_layout.addWidget(pb)

pb = QPushButton(icon("about"), "About...")
pb.setFlat(True)
pb.clicked.connect(GlobalInfo.main_window.open_about_dialog)
actions_layout.addWidget(pb)
actions_layout.addStretch()
actions_group.setLayout(actions_layout)

main_layout = QHBoxLayout()
main_layout.addWidget(recent_files_group)
main_layout.addWidget(actions_group)
main_layout.setSpacing(15)
main_layout.setContentsMargins(15, 15, 15, 15)

outer_layout = QVBoxLayout()
outer_layout.setSpacing(0)
outer_layout.setContentsMargins(0, 0, 0, 0)
outer_layout.addWidget(banner_view)
outer_layout.addLayout(main_layout)
self.setLayout(outer_layout)

def _load_recent_file(self, path):
GlobalInfo.main_window.load_file(path)
self.close()

def _open_file(self):
GlobalInfo.main_window.open_file_button()
self.close()
3 changes: 3 additions & 0 deletions angrmanagement/ui/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
from PySide6.QtGui import QIcon

NAME_TO_QTAWESOME_NAME = {
"about": "fa5s.info-circle",
"command-palette": "ph.squares-four-light",
"console-view": "mdi.console-line",
"disassembly-graph": "fa5s.sitemap",
"disassembly-linear": "msc.list-selection",
"disassembly-view": "msc.symbol-constant",
"docs": "mdi6.book-open-page-variant",
"file": "mdi.file",
"file-open": "mdi.folder-open",
"functions-view": "mdi.function",
"hex-view": "mdi.hexadecimal",
"log-view": "mdi.message-bulleted",
Expand Down
6 changes: 6 additions & 0 deletions angrmanagement/ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from .dialogs.load_plugins import LoadPlugins
from .dialogs.new_state import NewState
from .dialogs.preferences import Preferences
from .dialogs.welcome import WelcomeDialog
from .menus.analyze_menu import AnalyzeMenu
from .menus.file_menu import FileMenu
from .menus.help_menu import HelpMenu
Expand Down Expand Up @@ -201,6 +202,11 @@ def __init__(self, app: Optional["QApplication"] = None, parent=None, show=True,
self.windowHandle().screenChanged.connect(self.on_screen_changed)
self.show()

def show_welcome_dialog(self):
dlg = WelcomeDialog(self)
dlg.setModal(True)
dlg.show()

def sizeHint(self, *args, **kwargs): # pylint: disable=unused-argument,no-self-use
return QSize(1200, 800)

Expand Down

0 comments on commit 3ebf53b

Please sign in to comment.