# Simple PySide UI elements/testing # import binaryninjaui from PySide6 import QtWidgets, QtGui, QtWidgets, QtCore def basic(): popout = QtWidgets.QDialog() popout.setWindowTitle("test popout1") popout.exec_() def qpixmap(): pixmap = QtGui.QPixmap("play-and-pause-button.png") mask = pixmap.createMaskFromColor(QtGui.QColor('black'), QtGui.Qt.MaskOutColor) pixmap.fill((QtGui.QColor('red'))) pixmap.setMask(mask) window = QtWidgets.QDialog() window.setWindowTitle("View Image") label = QtWidgets.QLabel(window) label.setPixmap(pixmap) label.setGeometry(QtCore.QRect(10, 40, pixmap.width(), pixmap.height())) window.resize(pixmap.width()+20, pixmap.height()+100) window.exec_() def qpixmap2(): icon = QtGui.QIcon("play-and-pause-button.svg") button = QtWidgets.QPushButton(icon) msg_box = QtWidgets.QMessageBox() msg_box.setWindowTitle("Testing Icons") msg_box.exec_() def colorize(img, color): pixmap = QtGui.QPixmap(img) mask = pixmap.createMaskFromColor(QtGui.QColor('black'), QtGui.Qt.MaskOutColor) pixmap.fill(color) pixmap.setMask(mask) return pixmap def qicon(): ico = QtGui.QIcon("play-and-pause-button.svg") ico2 = QtGui.QIcon(colorize(ico.pixmap(ico.actualSize(QtCore.QSize(1024, 1024))), QtGui.QColor('red'))) msg_box = QtWidgets.QMessageBox() msg_box.setWindowTitle("Show Icon") button = QtWidgets.QPushButton(msg_box) button.setIcon(ico2) button.setText("PlayPause") msg_box.exec_() # Since Snippets now run on background threads, UI code needs to explicitly ensure that it is run on the main thread. #execute_on_main_thread(qpixmap2) #execute_on_main_thread(qpixmap) #execute_on_main_thread(basic) #execute_on_main_thread(qicon) from binaryninjaui import (UIAction, UIActionHandler) from binaryninja import log_info from PySide6.QtWidgets import QDialog, QLabel, QVBoxLayout def qd(context): dialog = QDialog(parent=context.widget) dialog.setWindowTitle("Hello Dialog") label = QLabel("Hello text") layout = QVBoxLayout() layout.addWidget(label) dialog.setLayout(layout) dialog.show() execute_on_main_thread_and_wait(lambda: qd(uicontext)) # Note: outside of snippets you would use: # UIAction.registerAction("Simple") # UIActionHandler.globalActions().bindAction("Simple", UIAction(qd)) # but snippets can provide the same UI context necessary to parent a QDialog