<s> import os <EOL> import sys <EOL> from cute import QtCore , QtWidgets , QtGui , use_qt5 , connect , disconnect , form_to_widget <EOL> import idaapi <EOL> from . import exceptions <EOL> connect_method_to_signal = connect <EOL> def capture_widget ( widget , path = None ) : <EOL> """<STR_LIT>""" <EOL> if use_qt5 : <EOL> pixmap = widget . grab ( ) <EOL> else : <EOL> pixmap = QtGui . QPixmap . grabWidget ( widget ) <EOL> if path : <EOL> pixmap . save ( path ) <EOL> else : <EOL> image_buffer = QtCore . QBuffer ( ) <EOL> image_buffer . open ( QtCore . QIODevice . ReadWrite ) <EOL> pixmap . save ( image_buffer , "<STR_LIT>" ) <EOL> return image_buffer . data ( ) . data ( ) <EOL> def get_widget ( title ) : <EOL> """<STR_LIT>""" <EOL> tform = idaapi . find_tform ( title ) <EOL> if not tform : <EOL> raise exceptions . FormNotFound ( "<STR_LIT>" . format ( title ) ) <EOL> return form_to_widget ( tform ) <EOL> def resize_widget ( widget , width , height ) : <EOL> """<STR_LIT>""" <EOL> widget . setGeometry ( <NUM_LIT:0> , <NUM_LIT:0> , width , height ) <EOL> def get_window ( ) : <EOL> """<STR_LIT>""" <EOL> tform = idaapi . get_current_tform ( ) <EOL> if not tform : <EOL> tform = idaapi . find_tform ( "<STR_LIT>" ) <EOL> widget = form_to_widget ( tform ) <EOL> window = widget . window ( ) <EOL> return window <EOL> class MenuManager ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( MenuManager , self ) . __init__ ( ) <EOL> self . _window = get_window ( ) <EOL> if use_qt5 : <EOL> self . _menu = self . _window . findChild ( QtWidgets . QMenuBar ) <EOL> else : <EOL> self . _menu = self . _window . findChild ( QtGui . QMenuBar ) <EOL> self . _menus = { } <EOL> def add_menu ( self , name ) : <EOL> """<STR_LIT>""" <EOL> if name in self . _menus : <EOL> raise exceptions . MenuAlreadyExists ( "<STR_LIT>" . format ( name ) ) <EOL> menu = self . _menu . addMenu ( name ) <EOL> self . _menus [ name ] = menu <EOL> def remove_menu ( self , name ) : <EOL> """<STR_LIT>""" <EOL> if name not in self . _menus : <EOL> raise exceptions . MenuNotFound ( <EOL> "<STR_LIT>" . format ( name ) ) <EOL> self . _menu . removeAction ( self . _menus [ name ] . menuAction ( ) ) <EOL> del self . _menus [ name ] <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> for menu in self . _menus . itervalues ( ) : <EOL> self . _menu . removeAction ( menu . menuAction ( ) ) <EOL> self . _menus = { } </s>
