def create_btn(sender, data): core.set_value("company_id", "Creating {} Model ...".format(model_company.split('_')[0])) dict = { "filename": model_company, "input_dim": g_input_dim, "hidden_dim": g_hidden_dim, "num_layers": g_num_layers, "output_dim": g_output_dim, "num_epochs": g_num_epochs } if not g_fast_mode: core.run_async_function(create_model, dict, return_handler=create) else: create(None, create_model(None, dict))
def convert_file(self, sender, data: Payload): """ Callback function, will convert the currently selected image. It works asynchronously by calling _convert_file using run_async_function. And once completed, calls _convert_file_return_callback to create the text window containing the OCR text gathered from the image. :param sender: The sender object (see dearpygui documentation) :param data: Payload object :return: None """ # if the data has a delete element, delete it self._delete_widgets(data.delete) self._disable_widgets(data.disable) core.run_async_function( self._convert_file, data, return_handler=self._convert_file_return_callback)
def translate_text(self, sender, data: Payload): """ Will use data.value_name (as a key) to get text in the value storage. It will then asynchronously translate the text. The source language is defined in the data.source_language attribute The destination language is defined in the data.destination_language The translated text is stored back into a value storage using data.destination_value_name as a key :param sender: :param data: Payload object containing the text and source+destination languages :return: """ self._disable_widgets(data.disable) text = core.get_value(data.value_name) data.text = text core.run_async_function(self._translate_text, data, return_handler=self._translate_text_callback) return data
def backupcallback(sender, data): backupinfo = (get_value("World Name"), get_value("Wait Time"), get_value("Fail Wait Time")) worldinfo = findworld(backupinfo[0]) if (worldinfo != 0): if (dobackup(worldinfo[0], worldinfo[1], backupinfo[0]) == 1): add_text( f"Backup created at {datetime.now().strftime('[%Y_%m_%d]_[%H_%M]')}", parent="main") run_async_function(async_sleep, backupinfo[1], return_handler=backupcallback) else: add_text(f'Backup failed. Is the world being accessed?', parent="main") run_async_function(async_sleep, backupinfo[2], return_handler=backupcallback) else: add_text(f'World ({backupinfo[0]}) not found', parent="main")
def show_status(self, text): """Show the status of load and save Parameters ---------- text : str The status to show """ dpg_core.set_value(self._status_id, text) dpg_simple.show_item(self._status_id) dpg_simple.show_item(self._status_id_same_line) def cb(*args): dpg_simple.hide_item(self._status_id) dpg_simple.hide_item(self._status_id_same_line) dpg_core.run_async_function( name=lambda *args: sleep(3), data=None, return_handler=cb, )
def start(): """ Renders main window elements. """ with open('token.txt', 'r') as token_file: token = token_file.readline() try: # Connect to IBM core.run_async_function(get_backends_async, data=token) core.set_render_callback(show_button) # Progress bar with simple.window('Please wait', no_scrollbar=True, height=70, width=400, x_pos=500, y_pos=200): core.add_progress_bar('progress', value=0.0, overlay='Connecting to IBM...', width=400) core.run_async_function(progress_async, 0) # Menu bar with simple.menu_bar("Main Menu Bar"): with simple.menu("File"): core.add_menu_item("Save", callback=print_me) core.add_menu_item("Save As", callback=print_me) core.add_menu_item("Help", callback=open_help_window) core.add_menu_item("About", callback=open_about_window) # Parameters group with simple.group('left group', width=350): # Select file button core.add_child('##file_block', width=350, height=180, show=False) core.add_button('File Selector', callback=file_picker) core.add_spacing(name='##space2', count=3) core.add_text('File location:') core.add_label_text('##filedir', value='None Selected', source='directory') core.add_spacing(name='##space3', count=3) core.add_text('File name:') core.add_label_text('##file', value='None Selected', source='file_directory') core.end() core.add_spacing(name='##space4', count=3) # Architecture type radio button core.add_child('##settings_block', width=350, height=450, show=False) core.add_text('Architecture type:') core.add_radio_button('radio##1', items=[ 'IBM simulator', 'IBM quantum computer', 'Arbitrary computer coupling' ], callback=show_architecture_list, source='device_type') core.add_spacing(name='##space5', count=3) # "Create arbitrary coupling" button core.add_button('Create custom architecture', callback=create_architecture, show=False) core.add_spacing(name='##space11', count=3) # Layout radio button core.add_text('Quantum circuit layout method:') core.add_radio_button( 'radio##2', items=['Original IBM layout', 'Advanced SWAP placement'], source='layout_type') core.add_spacing(name='##space6', count=3) # Optimization level slider core.add_text('Optimization level:') core.add_slider_int( '##optimization_lvl', default_value=1, min_value=0, max_value=3, tip='drag the slider to select an optimization level', width=300, source='opt_level') core.add_spacing(name='##space7', count=3) # Number of iterations slider core.add_text('Number of iterations:') core.add_input_int('##num_of_iter', width=300, callback=check_iteration_num, default_value=100) core.add_spacing(name='##space8', count=3) # Default settings button core.add_button('Set Default', callback=set_default) core.end() core.add_spacing(name='##space9', count=3) # Process button core.add_button('Process', callback=process, show=False) # graph images core.add_same_line(name='line##3', xoffset=370) with simple.group('center group'): core.add_child('##images_block', width=640, show=False) # Input circuit preview core.add_text('Input circuit:') core.add_drawing('input_circuit', width=600, height=500) core.draw_rectangle('input_circuit', [0, 150], [600, 500], [255, 255, 255, 0], [255, 255, 255, 50]) # Output circuit view core.add_text('Output circuit:') core.add_drawing('output_circuit', width=600, height=500) core.draw_rectangle('output_circuit', [0, 150], [600, 500], [255, 255, 255, 0], [255, 255, 255, 50]) core.end() # program output core.add_same_line(name='line##3', xoffset=1020) with simple.group('right group'): core.add_child('##output_block1', width=460, height=300, show=False) core.add_button('Open qasm file', callback=open_qasm) core.add_text('Path to IBM circuit representation') core.add_label_text('##circuitImage') core.add_button('Mapping', callback=show_mapping) core.end() core.add_text('Program output:', show=False) core.add_child('##output_block2', width=460, height=180, show=False) core.add_text('Program output will be displayed here', wrap=440) core.end() except Exception as exc: print("[ERROR]: {}".format(exc))