|
1 | | -from binaryninja import log_error |
| 1 | +from binaryninja import log_error, log_info |
2 | 2 | from PySide6.QtWidgets import (QDockWidget, QVBoxLayout, QHBoxLayout, |
3 | | - QPushButton, QLabel, QCheckBox, QWidget) |
| 3 | + QPushButton, QLabel, QCheckBox, QWidget, QTabWidget) |
4 | 4 | from PySide6.QtCore import Qt |
5 | 5 | from PySide6.QtGui import QPixmap |
| 6 | +from PySide6.QtWidgets import QWidget |
6 | 7 | from PySide6.QtCore import QCoreApplication |
7 | 8 | from PySide6.QtWidgets import QMessageBox |
8 | 9 | from PySide6.QtWidgets import QProgressBar |
9 | 10 | from revengai.utils import create_progress_dialog |
10 | 11 | from revengai.utils.data_thread import DataThread |
11 | 12 | import os |
12 | 13 |
|
13 | | -class AIDecompilerDialog(QDockWidget): |
| 14 | +class AIDecompilerDialog(QWidget): |
14 | 15 | def __init__(self, config, ai_decompiler, bv, func): |
15 | 16 | super().__init__() |
16 | 17 | self.config = config |
17 | 18 | self.ai_decompiler = ai_decompiler |
18 | 19 | self.bv = bv |
19 | 20 | self.func = func |
20 | | - self.init_ui() |
| 21 | + self.tabs = QTabWidget() |
| 22 | + self.init_ui(func) |
21 | 23 |
|
22 | | - def init_ui(self): |
| 24 | + def init_ui(self, func): |
23 | 25 | self.setWindowTitle("RevEng.AI: AI Decompiler") |
24 | | - |
25 | | - # Create a widget to hold the layout |
26 | | - content_widget = QWidget() |
27 | | - layout = QVBoxLayout(content_widget) |
28 | | - |
29 | | - title_label = QLabel("Getting AI decompiler...") |
30 | | - title_label.setStyleSheet("font-size: 18px;") |
31 | | - layout.addWidget(title_label) |
| 26 | + layout = QVBoxLayout() |
| 27 | + self.setLayout(layout) |
| 28 | + layout.addWidget(self.tabs) |
| 29 | + self.add_tab(func) |
| 30 | + self.tabs.tabCloseRequested.connect(self.close_tab) |
| 31 | + |
| 32 | + def add_tab(self, tab_name): |
| 33 | + tab_name = str(f"0x{tab_name:x}") |
| 34 | + for i in range(self.tabs.count()): |
| 35 | + log_info(f"RevEng.AI | Tab {self.tabs.tabText(i)} == {tab_name}") |
| 36 | + if self.tabs.tabText(i) == tab_name: |
| 37 | + self.tabs.setCurrentIndex(i) |
| 38 | + return |
| 39 | + |
| 40 | + log_info(f"RevEng.AI | Adding tab {tab_name}") |
| 41 | + tab = QWidget() |
| 42 | + layout = QVBoxLayout() |
| 43 | + layout.addWidget(QLabel(f"{tab_name} UI goes here")) |
| 44 | + tab.setLayout(layout) |
| 45 | + index = self.tabs.addTab(tab, tab_name) |
| 46 | + self.tabs.setCurrentIndex(index) |
| 47 | + |
| 48 | + if self.tabs.count() > 1: |
| 49 | + self.tabs.setTabsClosable(True) |
| 50 | + |
| 51 | + def close_tab(self, index): |
| 52 | + log_info(f"RevEng.AI | Closing tab {index} of {self.tabs.count()} tabs") |
| 53 | + self.tabs.removeTab(index) |
| 54 | + if self.tabs.count() == 1: |
| 55 | + self.tabs.setTabsClosable(False) |
32 | 56 |
|
33 | | - progress_bar = QProgressBar() |
34 | | - progress_bar.setMinimumWidth(250) |
35 | | - progress_bar.setMinimumHeight(20) |
36 | | - layout.addWidget(progress_bar) |
37 | 57 |
|
38 | | - # Set the content widget |
39 | | - self.setWidget(content_widget) |
40 | 58 |
|
41 | | - self.setStyleSheet(""" |
42 | | - QProgressBar { |
43 | | - border: 1px solid #cccccc; |
44 | | - border-radius: 4px; |
45 | | - text-align: center; |
46 | | - background-color: #f0f0f0; |
47 | | - min-width: 250px; |
48 | | - min-height: 20px; |
49 | | - } |
50 | | - QProgressBar::chunk { |
51 | | - background-color: #007bff; |
52 | | - border-radius: 3px; |
53 | | - } |
54 | | - """) |
| 59 | + |
0 commit comments