Ejemplo n.º 1
0
def start():
    """This is the main function that is called unconditionally.
    Unconditionally means, regardless of whether __name__ == '__main__' or not.

    It is all a mess but with historical reasons where imports had to be in the
    right order :).

    It would be nice to refactor it one day.
    """

    # Enforce all requirements so that the program doesn't crash in the middle of execution.
    if __name__ == '__main__':
        from utils.requirements import check_libraries_requirements
        check_libraries_requirements()

    # Import multiprocessing and enable freeze_support which is needed on windows
    import multiprocessing
    multiprocessing.freeze_support()

    # Import kivy as soon as possible to let it eat all the kivy args from sys.argv
    import kivy

    #
    # we have to protect the instantiation of the kivy app, cause
    # of the use of multiprocessing. If you spawn a new thread or process
    # it loads this file again. So there is the need of the __main__ guard.
    #
    if __name__ == "__main__":
        import sys

        # initialize settings class
        from utils.settings import Settings
        settings = Settings(sys.argv[1:])

        import launcher_config

        # HACK: clear sys.argv for kivy. Keep only the first element
        # sys.argv = sys.argv[0:1]

        # configure kivy
        from kivy import resources
        from kivy.config import Config
        from utils.paths import (
            get_common_resources_path,
            get_resources_path,
            get_source_path,
        )
        from utils.devmode import devmode

        default_log_level = devmode.get_log_level('info')

        resources.resource_add_path(get_common_resources_path())
        resources.resource_add_path(get_source_path())
        resources.resource_add_path(get_resources_path())

        Config.set('kivy', 'window_icon', get_resources_path(launcher_config.icon))
        Config.set('kivy', 'log_level', default_log_level)
        Config.set('input', 'mouse', 'mouse,disable_multitouch')

        if not settings.get('update'):
            Config.set('graphics', 'resizable', 0)
            Config.set('graphics', 'width', 1000)
            Config.set('graphics', 'height', 666)
            Config.set('graphics', 'borderless', 0)
        else:
            Config.set('graphics', 'resizable', 0)
            Config.set('graphics', 'width', 400)
            Config.set('graphics', 'height', 150)
            Config.set('graphics', 'borderless', 1)

        #
        # other imports
        #
        from kivy.app import App
        from kivy.uix.label import Label
        from kivy.uix.widget import Widget
        from kivy.uix.boxlayout import BoxLayout
        from kivy.uix.button import Button
        from kivy.uix.rst import RstDocument
        from kivy.uix.stacklayout import StackLayout
        from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelItem, TabbedPanelStrip, TabbedPanelHeader
        from kivy.graphics import Line, Color
        from kivy.properties import NumericProperty, ObjectProperty, BooleanProperty, StringProperty
        from kivy.core.window import Window
        from kivy.clock import Clock
        from kivy.logger import Logger
        from kivy.uix.screenmanager import ScreenManager, Screen
        from kivy.core.text import LabelBase
        from kivy.base import ExceptionManager

        from utils.app import BaseApp
        from view.numberinput import NumberInput
        from view.dynamicbutton import DynamicButton
        from view.hoverbutton import HoverButton
        from view.statusimage import StatusImage
        from view.errorpopup import error_popup_decorator
        from view.errorpopup import PopupHandler
        from view.modlist import ModList
        from view.serverlist import ServerListScrolled
        from view.simplewidgets import CheckLabel

        from gui.mainwidget import MainWidget
        from gui.updatermainwidget import UpdaterMainWidget
        from gui.installscreen import InstallScreen
        from gui.prefscreen import PrefScreen

        import logging

        Logger.info('Para: Starting MAIN PROCESS')

        if settings.get('use_exception_popup') == True:
            ExceptionManager.add_handler(PopupHandler())

        class MainScreenManager(ScreenManager):
            pass

        class LauncherApp(BaseApp):
            """Main class for the normal app"""

            title = launcher_config.launcher_name.encode('utf-8')

            def __init__(self, settings):
                super(LauncherApp, self).__init__()
                self.settings = settings

            def build(self):
                logger = logging.getLogger('concurrent.futures')
                logger.addHandler(logging.StreamHandler())
                return MainWidget()

        class SelfUpdaterApp(BaseApp):
            """app which starts the self updater"""

            title = '{} updater'.format(launcher_config.launcher_name).encode('utf-8')

            def __init__(self, settings):
                super(SelfUpdaterApp, self).__init__()
                self.settings = settings

            def build(self):
                logger = logging.getLogger('concurrent.futures')
                logger.addHandler(logging.StreamHandler())
                return UpdaterMainWidget()

        if __name__ == '__main__':
            launcher_app = None

            if settings.get('update'):
                print 'launching self updater'
                launcher_app = SelfUpdaterApp(settings).run()

            else:
                launcher_app = LauncherApp(settings)
                launcher_app.run = error_popup_decorator(launcher_app.run)
                launcher_app.run()
Ejemplo n.º 2
0
import textwrap
import time

from datetime import datetime
from distutils.version import LooseVersion
from kivy.logger import Logger
from kivy.config import Config
from sync import integrity, torrent_utils
from sync.mod import Mod
from sync.server import Server
from sync.torrentsyncer import TorrentSyncer
from third_party import teamspeak
from utils.devmode import devmode
from utils.requests_wrapper import download_url, DownloadException

default_log_level = devmode.get_log_level('info')
Config.set('kivy', 'log_level', default_log_level)

################################################################################
################################## ATTENTION!!! ################################
################################################################################
#
#
# Everything below this comment is run IN A DIFFERENT PROCESS!
# To communicate with the main program, you have to use the resolve(), reject()
# and progress() calls of the message queue!
#
#
################################################################################
################################## ATTENTION!!! ################################
################################################################################