'''Created on May 18, 2020 @author: deeejas'''

import platform
import time
from time import sleep

if platform.system() == 'Windows':
    import pywinctl as gw
elif platform.system() == 'Linux':
    import gi
    gi.require_version('Wnck', '3.0')
    gi.require_version('Gtk', '3.0')
    from gi.repository import Wnck

def parse_and_close(title):
    if platform.system() == 'Windows':
        close_title = gw.getWindowsWithTitle(title)[0]
        # gw.Win32Window.close()
        close_title.activate()
        sleep(2)
        close_title.close()
    elif platform.system() == 'Linux':
        window_list = []
        screen = Wnck.Screen.get_default()
        screen.force_update()
        all_windows = screen.get_windows()
        for name in all_windows:
            if title in name.get_name():
                window_list.append(name)
        rvs_xlsx = window_list[0]
        rvs_xlsx.activate(time.time())
        sleep(2)
        rvs_xlsx.close(time.time())

if __name__ == '__main__':
    parse_and_close('rvs')
