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

import os
import sys
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import subprocess

class DialogWindow(Gtk.Dialog):
    def __init__(self, parent, width, height):
        Gtk.Dialog.__init__(self, "ddCopy 0.3.3", parent, 0,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_OK, Gtk.ResponseType.OK))

        self.set_default_size(375, 100)
        self.set_icon_from_file('/usr/share/icons/hicolor/48x48/apps/ddcopy.svg')
        self.set_position(Gtk.WindowPosition.CENTER)        
        # create tabs
        notebook = Gtk.Notebook()
        self.vbox.pack_start(notebook, True, True, 0)

        # create tab 1
        page1 = Gtk.Box()
        page1.set_border_width(10)
        notebook.append_page(page1, Gtk.Label("Create Live USB"))
        image1 = Gtk.Image.new_from_file("/usr/share/icons/hicolor/48x48/apps/ddcopy.svg")
        page1.pack_start(image1, False, False, 0)
        page1.pack_start(Gtk.Label("Create a Bootable Live USB from a iso Image"), False, False, 0)

        # create tab 2
        page2 = Gtk.Box()
        page2.set_border_width(10)
        notebook.append_page(page2, Gtk.Label("Create Live DVD"))
        image2 = Gtk.Image.new_from_file("/usr/share/icons/hicolor/48x48/apps/ddcopy-dvd.svg")
        page2.pack_start(image2, False, False, 0)
        page2.pack_start(Gtk.Label("Create a Bootable Live DVD from a iso Image"), False, False, 0)

        # create tab 3
        page3 = Gtk.Box()
        page3.set_border_width(10)
        notebook.append_page(page3, Gtk.Label("Format USB Device"))
        image3 = Gtk.Image.new_from_file("/usr/share/icons/hicolor/48x48/apps/ddcopy-format.svg")
        page3.pack_start(image3, False, False, 0)
        page3.pack_start(Gtk.Label("Format a USB Key or Removable Device"), False, False, 0)

        # create tab 4
        page4 = Gtk.Box()
        page4.set_border_width(10)
        notebook.append_page(page4, Gtk.Label("About"))
        image4 = Gtk.Image.new_from_file("/usr/share/ddcopy/data/icons/about.png")
        page4.pack_start(image4, False, False, 0)
        page4.pack_start(Gtk.Label("About ddCopy"), False, False, 0)

        self.show_all()

    def run(self):
        response = super().run()
        if response == Gtk.ResponseType.OK:
            notebook = self.get_children()[0].get_children()[0]
            if notebook.get_current_page() == 0:
                subprocess.Popen(['/usr/share/ddcopy/data/ddcopy_usb'])
            elif notebook.get_current_page() == 1:
                subprocess.Popen(['/usr/share/ddcopy/data/ddcopy_dvd'])
            elif notebook.get_current_page() == 2:
                subprocess.Popen(['/usr/share/ddcopy/data/ddcopy_format'])
            elif notebook.get_current_page() == 3:
                subprocess.Popen(['/usr/lib64/ddcopy/ddCopy'])
        return response

dialog = DialogWindow(None, 400, 300)
response = dialog.run()

if response == Gtk.ResponseType.OK:
    print("OK clicked")
elif response == Gtk.ResponseType.CANCEL:
    print("Cancel clicked")

dialog.destroy()
