<s> """<STR_LIT>""" <EOL> import logging <EOL> from webview import OPEN_DIALOG , FOLDER_DIALOG , SAVE_DIALOG <EOL> logger = logging . getLogger ( __name__ ) <EOL> try : <EOL> from gi . repository import Gtk as gtk <EOL> from gi . repository import Gdk <EOL> from gi . repository import WebKit as webkit <EOL> except ImportError as e : <EOL> import_error = True <EOL> logger . warn ( "<STR_LIT>" , exc_info = True ) <EOL> else : <EOL> import_error = False <EOL> class BrowserView : <EOL> instance = None <EOL> def __init__ ( self , title , url , width , height , resizable , fullscreen , min_size ) : <EOL> BrowserView . instance = self <EOL> Gdk . threads_init ( ) <EOL> window = gtk . Window ( title = title ) <EOL> if resizable : <EOL> window . set_size_request ( min_size [ <NUM_LIT:0> ] , min_size [ <NUM_LIT:1> ] ) <EOL> window . resize ( width , height ) <EOL> else : <EOL> window . set_size_request ( width , height ) <EOL> window . set_resizable ( resizable ) <EOL> window . set_position ( gtk . WindowPosition . CENTER ) <EOL> if fullscreen : <EOL> window . fullscreen ( ) <EOL> window . connect ( "<STR_LIT>" , gtk . main_quit ) <EOL> scrolled_window = gtk . ScrolledWindow ( ) <EOL> window . add ( scrolled_window ) <EOL> webview = webkit . WebView ( ) <EOL> webview . props . settings . props . enable_default_context_menu = False <EOL> scrolled_window . add_with_viewport ( webview ) <EOL> window . show_all ( ) <EOL> webview . load_uri ( url ) <EOL> self . window = window <EOL> self . webview = webview <EOL> def show ( self ) : <EOL> Gdk . threads_enter ( ) <EOL> gtk . main ( ) <EOL> Gdk . threads_leave ( ) <EOL> def destroy ( self ) : <EOL> Gdk . threads_enter ( ) <EOL> self . window . destroy ( ) <EOL> Gdk . threads_leave ( ) <EOL> def create_file_dialog ( self , dialog_type , directory , allow_multiple , save_filename ) : <EOL> Gdk . threads_enter ( ) <EOL> if dialog_type == FOLDER_DIALOG : <EOL> gtk_dialog_type = gtk . FileChooserAction . SELECT_FOLDER <EOL> title = "<STR_LIT>" <EOL> button = gtk . STOCK_OPEN <EOL> elif dialog_type == OPEN_DIALOG : <EOL> gtk_dialog_type = gtk . FileChooserAction . OPEN <EOL> title = "<STR_LIT>" <EOL> button = gtk . STOCK_OPEN <EOL> elif dialog_type == SAVE_DIALOG : <EOL> gtk_dialog_type = gtk . FileChooserAction . SAVE <EOL> title = "<STR_LIT>" <EOL> button = gtk . STOCK_SAVE <EOL> dialog = gtk . FileChooserDialog ( title , self . window , gtk_dialog_type , <EOL> ( gtk . STOCK_CANCEL , gtk . ResponseType . CANCEL , button , gtk . ResponseType . OK ) ) <EOL> dialog . set_select_multiple ( allow_multiple ) <EOL> dialog . set_current_folder ( directory ) <EOL> if dialog_type == SAVE_DIALOG : <EOL> dialog . set_current_name ( save_filename ) <EOL> response = dialog . run ( ) <EOL> if response == gtk . ResponseType . OK : <EOL> if not allow_multiple or len ( dialog . get_filenames ( ) ) == <NUM_LIT:1> : <EOL> file_name = dialog . get_filename ( ) <EOL> else : <EOL> file_name = dialog . get_filenames ( ) <EOL> else : <EOL> file_name = None <EOL> dialog . destroy ( ) <EOL> Gdk . threads_leave ( ) <EOL> return file_name <EOL> def load_url ( self , url ) : <EOL> self . webview . load_uri ( url ) <EOL> def create_window ( title , url , width , height , resizable , fullscreen , min_size ) : <EOL> browser = BrowserView ( title , url , width , height , resizable , fullscreen , min_size ) <EOL> browser . show ( ) <EOL> def destroy_window ( ) : <EOL> if BrowserView . instance is not None : <EOL> BrowserView . instance . destroy ( ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def load_url ( url ) : <EOL> if BrowserView . instance is not None : <EOL> BrowserView . instance . load_url ( url ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def create_file_dialog ( dialog_type , directory , allow_multiple , save_filename ) : <EOL> if BrowserView . instance is not None : <EOL> return BrowserView . instance . create_file_dialog ( dialog_type , directory , allow_multiple , save_filename ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) </s>
