def update_status(status): """ A callback function supplied by the client in order to be notified whenever the virtual environment starts or exits. This function must take a boolean status as the only argument. The function terminal.watch_child(process_id) is not used because it only sends a child-exited signal when the pseudo terminal exits, but it does not notify when the virtual environment has started successfully. """ # Save the status so it can be used by the navigation actions. global is_running is_running = status # Reset buttons based on status. displayer.reset_buttons(is_back_sensitive=True, is_next_sensitive=status) displayer.set_sensitive('terminal_page__copy_header_bar_button', status) # Display the status. if status: message = 'You are in the virtual environment.' displayer.update_status_image('terminal_page__status', displayer.OK) displayer.update_label('terminal_page__status_label', message) displayer.update_label('terminal_page__kernel_version_label', 'kernel ' + model.application.kernel_version) else: message = 'You are not in the virtual environment.' displayer.update_status_image('terminal_page__status', displayer.ERROR) displayer.update_label('terminal_page__status_label', message) displayer.update_label('terminal_page__kernel_version_label', '') logger.log_value('Virtual environment status message', message)
def on_terminal_page__terminal_child_exited(*args): """ This function is not used. """ logger.log_title('On terminal page terminal child exited') logger.log_value('The arcuments are', args) for arg in args: logger.log_value('The argument is', arg)
def on_button_press_event__terminal_page(widget, event): if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 3: logger.log_value('Mouse button 3 pressed for', 'terminal_page') terminal = model.builder.get_object('terminal_page__terminal') terminal_has_selection = terminal.get_has_selection() clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) # Menu Item 1: Select Text displayer.set_sensitive('terminal_page__select_all_menu_item', True) # Menu Item 2: Copy Test if (terminal_has_selection): displayer.set_sensitive('terminal_page__copy_text_menu_item', True) else: displayer.set_sensitive('terminal_page__copy_text_menu_item', False) # Menu Item 3: Paste Text clipboard_has_text = clipboard.wait_is_text_available() if (is_running and clipboard_has_text and not terminal_has_selection): displayer.set_sensitive('terminal_page__paste_text_menu_item', True) else: displayer.set_sensitive('terminal_page__paste_text_menu_item', False) # Menu Item 4: Paste Files clipboard_has_uris = clipboard.wait_is_uris_available() if (is_running and clipboard_has_uris and not terminal_has_selection): count = len(clipboard.wait_for_uris()) label = 'Paste File' if count == 1 else 'Paste %s Files' % count displayer.update_menu_item('terminal_page__paste_file_menu_item', label) displayer.set_sensitive('terminal_page__paste_file_menu_item', True) else: label = 'Paste File(s)' displayer.update_menu_item('terminal_page__paste_file_menu_item', label) displayer.set_sensitive('terminal_page__paste_file_menu_item', False) menu = model.builder.get_object('terminal_page__menu') menu.popup(None, None, None, None, event.button, event.time)
def on_button_release_event__terminal_page__paste_file_menu_item(*args): clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) model.selected_uris = clipboard.wait_for_uris() model.current_directory = console.get_current_directory() logger.log_value('The current directory is', model.current_directory) # Go to the copy page. # The pseudo terminal process is not registered with the # processor module. As a result, the terminal's process # is not terminated by the interrupt_navigation_thread() function # of the navigator module. This allows the terminal to continue # running while the application navigates away from the terminal # page. The pseudo terminal process must be explicitly killed by # executing the exit_virtual_environment() function of the # console module. handle_navigation('copy-into-terminal')
def selected_uris(uris): model.selected_uris = uris logger.log_value('The selected uris are', model.selected_uris) model.current_directory = console.get_current_directory() logger.log_value('The current directory is', model.current_directory) # Go to the copy page. # The pseudo terminal process is not registered with the # processor module. As a result, the terminal's process # is not terminated by the interrupt_navigation_thread() function # of the navigator module. This allows the terminal to continue # running while the application navigates away from the terminal # page. The pseudo terminal process must be explicitly killed by # executing the exit_virtual_environment() function of the # console module. handle_navigation('copy-into-terminal')
def on_drag_data_received__terminal_page(widget, drag_context, x, y, data, info, drag_time): # Skip if terminal is not running. if not is_running: return logger.log_value('Drag data received for', 'terminal_page') # Gtk.SelectionData # https://lazka.github.io/pgi-docs/#Gtk-3.0/classes/SelectionData.html # The data type is....................... text/uri-list # The data type is....................... text/plain atom = data.get_data_type() data_type = str(atom) logger.log_value('The data type is', data_type) text = data.get_text() if text is not None: console.send_text_to_terminal(text) else: model.selected_uris = data.get_uris() logger.log_value('The selected uris are', model.selected_uris) model.current_directory = console.get_current_directory() logger.log_value('The current directory is', model.current_directory) # Go to the copy page. # The pseudo terminal process is not registered with the # processor module. As a result, the terminal's process # is not terminated by the interrupt_navigation_thread() function # of the navigator module. This allows the terminal to continue # running while the application navigates away from the terminal # page. The pseudo terminal process must be explicitly killed by # executing the exit_virtual_environment() function of the # console module. handle_navigation('copy-into-terminal')
def update_release_description(target_file_path, key, value): # logger.log_label('Update the release description') value = value.replace('"', '') logger.log_value('Update release description in', target_file_path) logger.log_value('▹ Key', key) logger.log_value('▹ Value', value) lines = [] with open(target_file_path, 'r') as file: lines = file.readlines() new_lines = [] for line in lines: if line.startswith(key): line = '%s="%s"' % (key, value) new_lines.append(line.strip()) target_file_name = os.path.basename(target_file_path) temp_file_path = os.path.join(os.path.sep, 'tmp', target_file_name) with open(temp_file_path, 'w') as file: for line in new_lines: file.write(line + os.linesep) program = os.path.join(model.application.directory, 'commands', 'move-path') command = 'pkexec "%s" "%s" "%s" "%s"' % (program, temp_file_path, target_file_path, 'root') result, exit_status, signal_status = execute_synchronous(command) if not exit_status: logger.log_value('Updated', target_file_path) else: logger.log_value('Error. Unable to update', target_file_path) logger.log_value('The result is', result)
######################################################################## # Initialize ######################################################################## terminal = model.builder.get_object('terminal_page__terminal') # Set Terminal Font terminal.set_font(MONOSPACE_FONT) # Set Terminal Colors # TODO: Create and use displayer.get_terminal_colors() function. schema_source = Gio.SettingsSchemaSource.get_default() _, schemas = schema_source.list_schemas(True) schemas = Gio.Settings.list_relocatable_schemas() if 'org.gnome.Terminal.Legacy.Profile' in schemas: logger.log_value('Set terminal colors?', 'Yes') settings = Gio.Settings.new_with_path('org.gnome.Terminal.Legacy.Profile', '/org/gnome/terminal/legacy/') fg_rgb_color = None bg_rgb_color = None hex_palette = settings.get_value('palette') if not hex_palette: # Use custom foreground and background colors. fg_rgb_color = Gdk.RGBA() fg_rgb_color.parse('#e5e5e5') bg_rgb_color = Gdk.RGBA() bg_rgb_color.parse('#191919') hex_palette = [ '#073642', '#DC322F', '#859900', '#B58900', '#268BD2', '#D33682', '#2AA198', '#EEE8D5', '#002B36', '#CB4B16', '#586E75', '#657B83', '#839496', '#6C71C4', '#93A1A1', '#FDF6E3'