#!/usr/bin/env python # SPDX-FileCopyrightText: Copyright (c) 2021-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: MIT # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. import os import subprocess from subprocess import Popen, PIPE from gi.repository.GObject import GObject from ubiquity import plugin # Plugin settings NAME = 'nv-chromium' BEFORE = None WEIGHT = 30 class PageGtk(plugin.PluginUI): plugin_title = 'ubiquity/text/nv_chromium_label' def __init__(self, controller, *args, **kwargs): super(PageGtk, self).__init__(self, *args, **kwargs) self.script = '/usr/lib/nvidia/utils/nvsnap-install.sh' if not self.check_pre_req(): return from gi.repository import Gtk container = Gtk.VBox(spacing=20) container.set_border_width(20) container.set_homogeneous(False) label_description = Gtk.Label( 'Do you want to install Chromium Browser now?') label_description.set_alignment(0, 0.5) label_description.show() container.pack_start(label_description, False, False, 0) self.button1 = Gtk.RadioButton(label="Install Chromium Browser") self.button1.show() container.pack_start(self.button1, False, False, 0) self.button2 = Gtk.RadioButton.new_from_widget(self.button1) self.button2.set_label("Do not install Chromium Browser") self.button2.set_active(False) self.button2.show() container.pack_start(self.button2, False, False, 0) label2 = Gtk.Label( 'NOTE: Internet connection is required for Chromium Browser installation, and it will take several minutes.\n' + 'You can also install it via snap store after system configuration is finished.\n') label2.set_justify(Gtk.Justification.LEFT) label2.show() container.pack_start(label2, False, False, 0) self.page = container self.controller = controller self.plugin_widgets = self.page def plugin_on_next_clicked(self): if self.button1.get_active(): from gi.repository import Gtk, Vte, Pango dialog = Gtk.Dialog('Installing Chromium Browser, please wait...', self.page.get_toplevel(), Gtk.DialogFlags.MODAL) self.close_button = dialog.add_button(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE) self.close_button.set_sensitive(False) dialog.set_size_request(700 , 150) scroll = Gtk.ScrolledWindow() scroll.set_border_width(10) vte = Vte.Terminal() vte.set_input_enabled(False) scroll.add(vte) run_cmd = [self.script, '-i', 'chromium'] vte.spawn_sync(0, None, run_cmd, None, 0, None, None, None) fontdesc = Pango.font_description_from_string("Ubuntu Mono 12") vte.set_font(fontdesc) vte.connect('child-exited', self.on_child_precess_exit) vte.show() dialog.vbox.pack_start(scroll, True, True, 0) scroll.show_all() dialog.run() dialog.destroy() def on_child_precess_exit(self, term, donnees=None): self.close_button.set_sensitive(True) def check_pre_req(self): if not os.path.exists(self.script): return False return True class PageDebconf(plugin.Plugin): plugin_title = 'ubiquity/text/nv_chromium_label' def __init__(self, controller, *args, **kwargs): super(PageDebconf, self).__init__(self, *args, **kwargs) self.controller = controller class Page(plugin.Plugin): def prepare(self, unfiltered=False): if os.environ.get('UBIQUITY_FRONTEND', None) == 'debconf_ui': nv_chromium_script = '/usr/lib/nvidia/chromium/nvchromium-query' return [nv_chromium_script] return