Source

fsgamer / fsgamer / main.py

Full commit
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-

import sys
import os

from gi.repository import Gtk # pylint: disable=E0611

from fsgamer import FsgamerWindow
from fsgamer import FsgrunDialog

from fsgamer_lib import set_up_logging, get_version

from fsgamer_app import Application
import utils
import fsgamer_wm
import openbox
import atexit
import xorgutils
#from chvt import main


skip_atexit = False
exe = ""

def skip_killing(func):
    def inner(*a, **k):
        global skip_atexit
        skip_atexit = True
        func(*a, **k)
    return inner

def main():
    """constructor for your class instances"""
    options, args = utils.parse_options()
    set_up_logging(options)

    if options.verbose:
        utils.set_verbose(options.verbose)


    # This basically routes shit, yo
    #
    # 1. Running actual windows manager (fsgwm or openbox)
    # 2. Running game (split with xinit and game)
    # 3. Executing config GUI
    # 4. Run TTS daemon
    # 5....... others!

    global exe
    exe = options.exe

    if options.killall:
        # Just let cleanup operation kill 
        return


    if options.killpact:
        # Just let cleanup operation kill 
        killpact(options.exe)
        return

    if options.wm:
        sys.exit(fsgamer_wm.main(options.exe, options.opts))
        return

    if options.tts:
        tts_server()
        return

    if options.openbox:
        start_openbox(options)
        return

    ##############################################################################
    # Okay, we're running the game or config GUI. It's important we have total
    # control over child processes now since we'll be spawning lots of them
    os.setpgrp()
    if options.exe:
        #if utils.shell_run.is_running("openbox"):
        #    print "Sorry, FSGamer currently cannot be run under openbox."
        #    sys.exit(1)


        # Check deps first
        #fsgamer_wm.check_dependencies()

        # Execing a function
        a = Application.from_cli(options, args)

        if options.desktop:
            fsgrun_gui(a)
        else:
            a.run()
    else:
        configuration_management_gui()


@skip_killing
def start_openbox(options):
    if not openbox.ENABLED:
        utils.error("dependency", "openbox")
    openbox.main(options.exe, options.opts)

@skip_killing
def tts_server():
    import notifications_listener
    notifications_listener.main()

def configuration_management_gui():
    # Run the application.
    window = FsgamerWindow.FsgamerWindow()
    window.show()
    Gtk.main()


def killpact(exe):
    utils.shell_run.return_when_stopped_running(exe)

def fsgrun_gui(a):
    window = FsgrunDialog.FsgrunDialog()
    window.show()
    window.set_run_application(a)
    Gtk.main()

@atexit.register
def cleanup():
    if not skip_atexit:
        xorgutils.XorgProcess.killall_userstarted()
        # And totally kill everything
        utils.shell_run.killall_fsgamer()