Ejemplo n.º 1
0
def main( app_cls, argv ):
    #
    #   set a working STDOUT before loading most modules
    #
    # help debug when stdout goes nowhere useful
    # Mac OS X and Windows are the main problems
    if wb_platform_specific.isMacOs() or wb_platform_specific.isWindows():
        if '--noredirect' not in argv:
            sys.stdout = open( os.environ.get( 'WB_STDOUT_LOG', str(wb_platform_specific.getNullDevice()) ), 'w', 1 )
            sys.stderr = sys.stdout

    # don't pollute any subprocesses with env vars
    # from packaging processing
    for envvar in ['PYTHONPATH', 'PYTHONHOME', 'PYTHONEXECUTABLE']:
        if envvar in os.environ:
            del os.environ[ envvar ]

    # Create the win application and start its message loop
    app = app_cls( argv )

    app.main_window.show()

    rc = app.exec_()

    # force clean up of objects to avoid segv on exit
    del app

    # prevent exit handlers from running as this allows for a segv
    # My guess is that there are some Qt objects that are not owned
    # but I have no way to take them down
    #os._exit( rc )
    return rc
Ejemplo n.º 2
0
    def __init__(self, app_name_parts, args, debug_class, extra_loggers=None):
        self.top_window = None
        self.main_window = None
        # used to set the names of files and windows for this app
        self.app_name_parts = app_name_parts

        # setup the platform specific support
        wb_platform_specific.setupPlatform(self.app_name_parts, sys.argv[0])

        if extra_loggers is None:
            extra_loggers = []

        wb_logging.AppLoggingMixin.__init__(self, extra_loggers)
        wb_background_thread.BackgroundWorkMixin.__init__(self)

        self.may_quit = False

        self.args = args

        self.startup_dir = os.getcwd()

        self.all_temp_files = []
        self.all_processes = []

        # on the Mac the app's cwd is the resource folder
        if wb_platform_specific.isMacOs():
            if 'PWD' in os.environ:
                os.chdir(os.environ['PWD'])
            else:
                os.chdir(os.environ['HOME'])

        self.__debug_noredirect = False
        self.__debug = False
        self.__trace = False
        self.__git_debug = False
        self.__log_stdout = False

        self.all_positional_args = []

        debug_config_string = None

        while len(args) > 1:
            arg = args[1]

            if arg.startswith('-psn_'):
                del args[1]

            elif arg.startswith('--name='):
                self.opt_name = arg[len('--name='):]
                del args[1]

            elif arg == '--noredirect':
                self.__debug_noredirect = True
                del args[1]

            elif arg == '--log-stdout':
                self.__log_stdout = True
                del args[1]

            elif arg == '--debug' and len(args) > 2:
                self.__debug = True
                debug_config_string = args[2]
                del args[1]
                del args[1]

            elif arg == '--start-dir' and len(args) > 2:
                os.chdir(args[2])
                del args[1]
                del args[1]

            elif arg == '--':
                break

            elif self.optionParse(args):
                pass

            elif arg.startswith('--'):
                print('Error: unknown option %s' % (arg, ))
                break

            else:
                self.all_positional_args.append(arg)
                del args[1]

        self.args = args
        self.app_name = os.path.basename(args[0])
        self.app_dir = os.path.dirname(args[0])
        if self.app_dir == '':
            self.app_dir = self.startup_dir

        locale_path = wb_platform_specific.getLocalePath()
        self.translation = gettext.translation(
            '-'.join([part.lower() for part in self.app_name_parts]),
            str(locale_path),
            # language defaults
            fallback=True)

        import builtins
        # T_( 'non plural' )
        builtins.__dict__['T_'] = self.translation.gettext
        # S_( 'singular', 'plural', n )
        builtins.__dict__['S_'] = self.translation.ngettext
        # U_( 'static string' )
        # define here to keep mypy happy - humm  does not work...
        builtins.__dict__['U_'] = U_

        # Debug settings
        self.__last_client_error = []

        # part 1 of settings up logging
        self.setupLogging()

        # and debug trace
        self.debug_options = debug_class(self.log)
        if debug_config_string is not None:
            self.debug_options.setDebug(debug_config_string)

        self.debugLogApp = self.debug_options.debugLogApp

        self.setupAppDebug()

        # these messages just go into the log file not the log widget
        self.log.info('startup_dir %s' % (self.startup_dir, ))
        self.log.info('locale_path %s' % (locale_path, ))
        self.log.info('find %r' %
                      (gettext.find('scm-workbench', str(locale_path)), ))
        self.log.info('info %r' % (self.translation.info(), ))

        for path in sys.path:
            self.log.info('sys.path: %r' % (path, ))

        for var in sorted(os.environ):
            self.log.info('Environment %s=%s' % (var, os.environ[var]))

        self.log.info('app_dir %s' % (wb_platform_specific.getAppDir(), ))
        self.log.info('preferences_dir %s' %
                      (wb_platform_specific.getPreferencesDir(), ))
        self.log.info('Qt libraryPaths %r' %
                      (QtWidgets.QApplication.libraryPaths(), ))

        QtWidgets.QApplication.__init__(self, [sys.argv[0]])

        self.__is_dark_mode = self.palette().text().color().lightnessF(
        ) > self.palette().window().color().lightnessF()
        self.prefs = None

        # capture logs into the log widget
        self.__wb_log = wb_logging.WbLog(self)

        # background threads depend on Qt
        self.startBackgroundThread()
        self.log.infoheader(
            T_('Starting %s') % (' '.join(self.app_name_parts), ))

        self.prefs_manager = self.createPreferencesManager()
        try:
            self.log.info('Reading preferences')
            self.prefs_manager.readPreferences()

        except xml_preferences.ParseError as e:
            # the preferences are defaulted on a failure to load
            self.log.error(str(e))

        self.prefs = self.prefs_manager.getPreferences()

        if self.isDarkMode():
            self.setDarkPalette()
            self.__wb_log.initStyles()

        self.code_font = None

        # part 2 of settings up logging is done in main window code
        self.main_window = self.createMainWindow()

        self.applicationStateChanged.connect(
            self.applicationStateChangedHandler)
Ejemplo n.º 3
0
 ====================================================================

    be_config.py

    Based on code from git WorkBench

'''
import wb_platform_specific

# point size and face need to chosen for platform
if wb_platform_specific.isWindows():
    face = 'Courier New'
    point_size = 8

elif wb_platform_specific.isMacOs():
    face = 'Monaco'
    point_size = 12

else:
    # for unix systems
    face = 'Courier'
    point_size = 12

diff_colour_normal = '#000000'
diff_colour_header = '#1919c0'

diff_colour_insert_line = '#008200'
diff_colour_delete_line = '#dc143c'
diff_colour_change_line = '#0000ff'
Ejemplo n.º 4
0
 ====================================================================

    be_config.py

    Based on code from git WorkBench

'''
import wb_platform_specific

# point size and face need to chosen for platform
if wb_platform_specific.isWindows():
    face = 'Courier New'
    point_size = 8

elif wb_platform_specific.isMacOs():
    face = 'Monaco'
    point_size = 12

else:
    # for unix systems
    face = 'Courier'
    point_size = 12

diff_light_colour_normal = '#000000'
diff_light_colour_header = '#1919c0'

diff_light_colour_insert_line = '#008200'
diff_light_colour_delete_line = '#dc143c'
diff_light_colour_change_line = '#0000ff'
Ejemplo n.º 5
0
    def __init__( self, app_name_parts, args, debug_class, extra_loggers=None ):
        self.top_window = None
        self.main_window = None
        # used to set the names of files and windows for this app
        self.app_name_parts = app_name_parts

        # setup the platform specific support
        wb_platform_specific.setupPlatform( self.app_name_parts, sys.argv[0] )

        QtWidgets.QApplication.__init__( self, [sys.argv[0]] )

        if extra_loggers is None:
            extra_loggers = []

        wb_logging.AppLoggingMixin.__init__( self, extra_loggers )
        wb_background_thread.BackgroundWorkMixin.__init__( self )

        self.may_quit = False

        self.args = args

        self.startup_dir = os.getcwd()

        self.all_temp_files = []
        self.all_processes = []

        # on the Mac the app's cwd is the resource folder
        if wb_platform_specific.isMacOs():
            if 'PWD' in os.environ:
                os.chdir( os.environ['PWD'] )
            else:
                os.chdir( os.environ['HOME'] )

        self.__debug_noredirect = False
        self.__debug = False
        self.__trace = False
        self.__git_debug = False
        self.__log_stdout = False

        self.all_positional_args = []

        debug_config_string = None

        while len(args) > 1:
            arg = args[ 1 ]

            if arg.startswith( '-psn_' ):
                del args[ 1 ]

            elif arg.startswith( '--name=' ):
                self.opt_name = arg[len('--name='):]
                del args[ 1 ]

            elif arg == '--noredirect':
                self.__debug_noredirect = True
                del args[ 1 ]

            elif arg == '--log-stdout':
                self.__log_stdout = True
                del args[ 1 ]

            elif arg == '--debug' and len(args) > 2:
                self.__debug = True
                debug_config_string = args[2]
                del args[ 1 ]
                del args[ 1 ]

            elif arg == '--start-dir' and len(args) > 2:
                os.chdir( args[2]  )
                del args[1]
                del args[1]

            elif arg == '--':
                break

            elif self.optionParse( args ):
                pass

            elif arg.startswith( '--' ):
                print( 'Error: unknown option %s' % (arg,) )
                break

            else:
                self.all_positional_args.append( arg )
                del args[1]

        self.args = args
        self.app_name = os.path.basename( args[0] )
        self.app_dir = os.path.dirname( args[0] )
        if self.app_dir == '':
            self.app_dir = self.startup_dir

        self.background_thread.start()

        locale_path = wb_platform_specific.getLocalePath()
        self.translation = gettext.translation(
                '-'.join( [part.lower() for part in self.app_name_parts] ),
                str(locale_path),
                # language defaults
                fallback=True )

        import builtins
        # T_( 'non plural' )
        builtins.__dict__['T_'] = self.translation.gettext
        # S_( 'singular', 'plural', n )
        builtins.__dict__['S_'] = self.translation.ngettext
        # U_( 'static string' )
        # define here to keep mypy happy - humm  does not work...
        builtins.__dict__['U_'] = U_

        # Debug settings
        self.__last_client_error = []

        # part 1 of settings up logging

        self.setupLogging()

        # and debug trace
        self._debug_options = debug_class( self.log )
        if debug_config_string is not None:
            self._debug_options.setDebug( debug_config_string )

        self._debugApp = self._debug_options._debugApp

        self.setupScmDebug()

        # these messages just go into the log file not the log widget
        self.log.info( 'startup_dir %s' % (self.startup_dir,) )
        self.log.info( 'locale_path %s' % (locale_path,) )
        self.log.info( 'find %r' % (gettext.find( 'scm-workbench', str(locale_path) ),) )
        self.log.info( 'info %r' % (self.translation.info(),) )

        for path in sys.path:
            self.log.info( 'sys.path: %r' % (path,) )

        for var in sorted( os.environ.keys() ):
            self.log.info( 'Environment %s=%s' % (var, os.environ[ var ]) )

        self.log.info( 'app_dir %s' % (wb_platform_specific.getAppDir(),) )
        self.log.info( 'preferences_dir %s' % (wb_platform_specific.getPreferencesDir(),) )

        # and capture logs into the log widget
        self.__wb_log = wb_logging.WbLog( self )

        self.prefs_manager = self.createPreferencesManager()
        try:
            self.log.info( 'Reading preferences' )
            self.prefs_manager.readPreferences()

        except xml_preferences.ParseError as e:
            # the preferences are defaulted on a failure to load
            self.log.error( str(e) )

        self.prefs = self.prefs_manager.getPreferences()

        # part 2 of settings up logging is done in main window code
        self.main_window = self.createMainWindow()

        self.applicationStateChanged.connect( self.applicationStateChangedHandler )