2014-10-27 16:29:04 -06:00
# -*- coding: utf-8 -*-
2015-04-03 16:57:08 -06:00
import platform
""" there are lots of things not implemented for Gtk+ yet.
We ' ve started this effort 1 Apr 2015 so it isn ' t fully functional . We will remove the ifs statements when are no needed """
system = platform . system ( )
if system == " Windows " :
import sys
import os
#redirect the original stdout and stderr
stdout = sys . stdout
stderr = sys . stderr
sys . stdout = open ( os . path . join ( os . getenv ( " temp " ) , " stdout.log " ) , " w " )
sys . stderr = open ( os . path . join ( os . getenv ( " temp " ) , " stderr.log " ) , " w " )
2014-11-12 20:41:29 -06:00
import languageHandler
2014-10-27 16:29:04 -06:00
import paths
import commandline
2014-11-12 20:41:29 -06:00
import config
import sound
import output
2015-01-19 12:15:57 -06:00
import logging
import application
2015-02-04 17:00:03 -06:00
import keys
2015-01-27 17:09:28 -06:00
from mysc . thread_utils import call_threaded
2015-02-22 18:45:26 -06:00
import fixes
2015-02-28 08:31:19 -06:00
#extra variables to control the temporal stdout and stderr, while the final files are opened. We understand that some errors could happen while all outputs are closed, so let's try to avoid it.
2015-04-03 16:57:08 -06:00
import widgetUtils
if system == " Windows " :
from logger import logger
from update import updater
stdout_temp = sys . stdout
stderr_temp = sys . stderr
2015-02-28 08:31:19 -06:00
#if it's a binary version
2015-04-03 16:57:08 -06:00
if hasattr ( sys , ' frozen ' ) :
sys . stderr = open ( paths . logs_path ( " stderr.log " ) , ' w ' )
sys . stdout = open ( paths . logs_path ( " stdout.log " ) , ' w ' )
else :
sys . stdout = stdout
sys . stderr = stderr
#the final log files have been opened succesfully, let's close the temporal files
stdout_temp . close ( )
stderr_temp . close ( )
#finally, remove the temporal files. TW Blue doesn't need them anymore, and we will get more free space on the harddrive
os . remove ( stdout_temp . name )
os . remove ( stderr_temp . name )
if system == " Linux " :
from gi . repository import Gdk , GObject , GLib
2015-01-19 12:15:57 -06:00
log = logging . getLogger ( " main " )
2014-11-12 20:41:29 -06:00
def setup ( ) :
2015-04-19 18:10:34 -05:00
log . debug ( " Starting " + application . name + " %s " % ( application . version , ) )
2014-11-12 20:41:29 -06:00
config . setup ( )
2015-01-19 12:15:57 -06:00
log . debug ( " Using %s %s " % ( platform . system ( ) , platform . architecture ( ) [ 0 ] ) )
log . debug ( " Application path is %s " % ( paths . app_path ( ) , ) )
2015-02-22 11:38:22 -06:00
log . debug ( " config path is %s " % ( paths . config_path ( ) , ) )
2014-11-12 20:41:29 -06:00
sound . setup ( )
output . setup ( )
languageHandler . setLanguage ( config . app [ " app-settings " ] [ " language " ] )
2015-02-04 17:00:03 -06:00
keys . setup ( )
2014-11-12 20:41:29 -06:00
from controller import mainController
from sessionmanager import sessionManager
2015-04-03 16:57:08 -06:00
app = widgetUtils . mainLoopObject ( )
if system == " Windows " :
updater . do_update ( )
2014-11-12 20:41:29 -06:00
sm = sessionManager . sessionManagerController ( )
sm . fill_list ( )
if len ( sm . sessions ) == 0 : sm . show ( )
else :
sm . do_ok ( )
2015-04-03 16:57:08 -06:00
if hasattr ( sm . view , " destroy " ) :
sm . view . destroy ( )
2014-11-12 20:41:29 -06:00
del sm
2015-02-22 18:45:26 -06:00
fixes . setup ( )
2014-11-12 20:41:29 -06:00
r = mainController . Controller ( )
2015-04-03 16:57:08 -06:00
r . view . show ( )
2015-01-27 17:09:28 -06:00
r . do_work ( )
2015-03-09 15:55:34 -06:00
r . check_invisible_at_startup ( )
2015-04-03 16:57:08 -06:00
if system == " Windows " :
call_threaded ( r . start )
elif system == " Linux " :
GLib . idle_add ( r . start )
app . run ( )
2014-11-12 20:41:29 -06:00
2015-04-03 16:57:08 -06:00
setup ( )