#!/usr/bin/python3
# -*- coding: utf-8 -*-
import gi

gi.require_version("Gtk", "3.0")
gi.require_version("Vte", "2.91")
from gi.repository import Gtk, Vte, GLib


def start_vte_command():
    terminal.spawn_async(Vte.PtyFlags.DEFAULT,
                         "/", ["/bin/sh", "-c", "pkexec /lib/installer"], None,
                         GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None,
                         -1, None, None)


terminal = Vte.Terminal()
terminal.connect("child_exited", Gtk.main_quit)
terminal.set_font_scale(2.0)

window = Gtk.Window()
window.add(terminal)
window.connect("destroy", Gtk.main_quit)

dialog = Gtk.MessageDialog(
    transient_for=window,
    flags=0,
    message_type=Gtk.MessageType.QUESTION,
    buttons=Gtk.ButtonsType.YES_NO,
    text="Pardus ETAP 23 Kurulum Onayı",
    secondary_text="<span color='red'><b>Diskinizdeki tüm veriler silinecektir. "
                   "Devam etmek istediğinize emin misiniz?</b></span>",
    secondary_use_markup=True
)
response = dialog.run()
dialog.destroy()

if response == Gtk.ResponseType.YES:
    start_vte_command()
    window.show_all()
    window.fullscreen()
else:
    GLib.idle_add(Gtk.main_quit)

Gtk.main()
