Exemple #1
0
def main(argv=list(sys.argv)):
    try:
        if "--test" in argv or "--pdb" in argv:
            DEFAULT_LOGGING_CONFIG['handlers']['console']['level'] = 'DEBUG'

        use_pdb = "--pdb" in argv
        if use_pdb:
            argv.remove("--pdb")
            objc.setVerbose(1)

            # make PyObjC use our exception handler
            Debugging.installExceptionHandler = install_exception_handler

        if "--test" in argv:
            from editxt.test.runner import TestApplication
            app = TestApplication(argv)
        else:
            logging.config.dictConfig(DEFAULT_LOGGING_CONFIG)
            from editxt.application import Application
            argv = argv[1:] # drop program name
            doc = __doc__.replace('Profile directory.',
                'Profile directory [default: {}].'
                .format(Application.default_profile()))
            opts = docopt.docopt(doc, argv, version=editxt.__version__)
            app = Application(opts.get('--profile'))

        editxt.app = app
        run(app, argv, use_pdb)
    except Exception as err:
        if len(logging.root.handlers) == 0:
            logging.config.dictConfig(DEFAULT_LOGGING_CONFIG)
        log.error('unhandled error', exc_info=True)
        sys.exit(1)
Exemple #2
0
    def testSortInvalid(self):
        # Invalid calls to sortUsingFunction:context:

        a = NSMutableArray.arrayWithArray_(range(4))
        self.assertEquals(a, (0, 1, 2, 3))

        t = objc.getVerbose()
        objc.setVerbose(0)
        try:
            self.assertRaises(TypeError, a.sortUsingFunction_context_, dir)
            self.assertRaises(TypeError, a.sortUsingFunction_context_, dir, 1, 2)
            self.assertRaises(TypeError, a.sortUsingFunction_context_, cmp, u'a')
        finally:
            objc.setVerbose(t)
Exemple #3
0
    def testSortInvalid(self):
        # Invalid calls to sortUsingFunction:context:
        def cmp(a, b):
            return -1

        a = NSMutableArray.arrayWithArray_(range(4))
        self.assertEqual(a, (0, 1, 2, 3))

        t = objc.getVerbose()
        objc.setVerbose(0)
        try:
            self.assertRaises(TypeError, a.sortUsingFunction_context_, dir)
            self.assertRaises(TypeError, a.sortUsingFunction_context_, dir, 1, 2)
            self.assertRaises(TypeError, a.sortUsingFunction_context_, lambda *args: cmp(*args), b'a'.decode('ascii'))
        finally:
            objc.setVerbose(t)
Exemple #4
0
    def testSortInvalid(self):
        """
        Invalid calls to sortUsingFunction:context:
        """

        a = NSMutableArray.arrayWithArray_(range(4))
        self.assertEquals(a, (0, 1, 2, 3))

        t = objc.getVerbose()
        objc.setVerbose(0)
        try:
            self.assertRaises(TypeError, a.sortUsingFunction_context_, dir)
            self.assertRaises(TypeError, a.sortUsingFunction_context_, dir, 1,
                              2)
            self.assertRaises(TypeError, a.sortUsingFunction_context_, cmp,
                              u'a')
        finally:
            objc.setVerbose(t)
Exemple #5
0
    def testSortInvalid(self):
        # Invalid calls to sortUsingFunction:context:
        def cmp(a, b):
            return -1

        a = NSMutableArray.arrayWithArray_(range(4))
        self.assertEqual(a, (0, 1, 2, 3))

        t = objc.getVerbose()
        objc.setVerbose(0)
        try:
            self.assertRaises(TypeError, a.sortUsingFunction_context_, dir)
            self.assertRaises(TypeError, a.sortUsingFunction_context_, dir, 1,
                              2)
            self.assertRaises(TypeError, a.sortUsingFunction_context_,
                              lambda *args: cmp(*args), u'a')
        finally:
            objc.setVerbose(t)
Exemple #6
0
    def test_verbose(self):
        orig = objc.options.verbose
        try:
            with filterWarnings("error", DeprecationWarning):
                self.assertRaises(DeprecationWarning, objc.setVerbose, False)
                self.assertRaises(DeprecationWarning, objc.getVerbose)

            with filterWarnings("ignore", DeprecationWarning):
                self.assertEqual(objc.getVerbose(), orig)

                objc.setVerbose(False)
                self.assertEqual(objc.options.verbose, False)
                self.assertEqual(objc.getVerbose(), False)

                objc.setVerbose(True)
                self.assertEqual(objc.options.verbose, True)
                self.assertEqual(objc.getVerbose(), True)

        finally:
            objc.options.verbose = orig
Exemple #7
0
def init(use_pdb):

    # prevent NSLog("PyObjC: Converting exception to Objective-C")
    # See pyobjc-core/Modules/objc/objc_util.m
    objc.setVerbose(0)

    errors.is_debugging = use_pdb
    if use_pdb:
        # make PyObjC use our exception handler
        Debugging.installExceptionHandler = errors.install_exception_handler
    else:
        errors.install_exception_handler()

    fix_PyObjCTools_path()

    # HACK monkey-patch pyobc exception handler to use our logger
    def log_error(template, message=None):
        log.error(template if message is None else message)
    #AppHelper.NSLog = log_error
    Debugging.NSLog = log_error
Exemple #8
0
def main():
    argv = list(sys.argv)

    if "--test" in argv or "--pdb" in argv:
        DEFAULT_LOGGING_CONFIG['handlers']['console']['level'] = 'DEBUG'
    logging.config.dictConfig(DEFAULT_LOGGING_CONFIG)

    use_pdb = "--pdb" in argv
    if use_pdb:
        argv.remove("--pdb")
        objc.setVerbose(1)

    if "--test" in argv:
        from editxt.test.runner import TestApplication
        app = TestApplication(argv)
    else:
        from editxt.application import Application
        app = Application()
    init(app)

    AppHelper.runEventLoop(argv, errlog.unexpected_error, pdb=use_pdb)
Exemple #9
0
    def test_verbose(self):
        orig = objc.options.verbose
        try:
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter("always")
                objc.setVerbose(False)
                objc.getVerbose()

            self.assertEqual(len(w), 2)
            self.assertEqual(w[0].category, DeprecationWarning)
            self.assertEqual(w[1].category, DeprecationWarning)

            with warnings.catch_warnings(record=True):
                warnings.simplefilter("ignore")
                self.assertEqual(objc.getVerbose(), orig)

                objc.setVerbose(False)
                self.assertEqual(objc.options.verbose, False)
                self.assertEqual(objc.getVerbose(), False)

                objc.setVerbose(True)
                self.assertEqual(objc.options.verbose, True)
                self.assertEqual(objc.getVerbose(), True)

        finally:
            objc.options.verbose = orig
Exemple #10
0
# -*- coding: UTF-8 -*- # -----------------------------------------------------------------------------
#     BuroFont Editor
#     (c) 2014+  Font Bureau
#
#     No distribution without permission.
#
# -----------------------------------------------------------------------------
#
#   run.py
#
import os
from PyObjCTools import AppHelper
from AppKit import NSApplication, NSApp, NSBundle, NSLog # @UnresolvedImport
import objc
objc.setVerbose(True) # @UndefinedVariable

import AppDelegate
import MyWindowController

app = NSApplication.sharedApplication()
nibPath = os.path.join(os.path.dirname(__file__), "dist", "Skeleton.app", "Contents", "Resources", "English.lproj", "MainMenu.nib")
NSBundle.loadNibFile_externalNameTable_withZone_(nibPath, {}, None) # @UndefinedVariable
nibPath = os.path.join(os.path.dirname(__file__), "dist", "Skeleton.app", "Contents", "Resources", "English.lproj", "TestWindow.nib")
NSBundle.loadNibFile_externalNameTable_withZone_(nibPath, {}, None) # @UndefinedVariable
delegate = AppDelegate.AppDelegate.alloc().init() # @UndefinedVariable
app.setDelegate_(delegate)

# Bring app to top
NSApp.activateIgnoringOtherApps_(True)

AppHelper.runEventLoop()
Exemple #11
0
#-*- coding: utf-8 -*-

import objc
objc.setVerbose(1)

from AppKit import NSApplication

from build.worker import Worker
from remote.connection import DeviceConnectionFactory

app_delegate = NSApplication.sharedApplication().delegate()

worker = Worker.alloc().init()
connection_factory = DeviceConnectionFactory.alloc().init()

app_delegate.setWorker_(worker)
app_delegate.setConnectionFactory_(connection_factory);
Exemple #12
0
from PyObjCTools import NibClassBuilder, AppHelper

import Foundation, AppKit, WebKit
from Foundation import *
from AppKit import *
import objc
objc.setVerbose(1)

import PyDocURLProtocol
import PyDocEvents

PyDocURLProtocol.setup()

NibClassBuilder.extractClasses('PyDocBrowser')

# the web browser doesn't have or need any code really

if __name__ == '__main__':
    AppHelper.runEventLoop()
Exemple #13
0
    def loadModuleAtPath_className_functionName_arguments_(
            self, path, klass, func, args):
        f = open(path)
        try:

            # verbose logging of exceptions
            objc.setVerbose(1)

            theResult = "no result available"
            realfunc = None
            taskObject = None

            # load code at path as a module
            modKosmic = imp.load_module('modKosmic', f, path,
                                        (".py", "r", imp.PY_SOURCE))

            # without the mod reference this fails.
            # also getattr(modKosmic, klass, None) has issues.
            if klass is not None and len(klass) > 0:
                try:
                    taskObject = eval('modKosmic.' + klass + '.alloc().init()')

                # attribute error thrown if cannot instantiate
                except AttributeError as x:
                    taskObject = None
                except:
                    # raise again and let the outer block handle it
                    raise

            # get function from object
            if taskObject is not None:

                # get function
                realfunc = getattr(taskObject, func, None)

            # get function from module
            if realfunc is None:
                # get function
                realfunc = getattr(modKosmic, func, None)

            # if we have a function then call it
            if realfunc is not None:

                # call the function with our arguments
                # we make a tuple from our list and then unpack it
                theResult = realfunc(*tuple(args))

            # cannot find function
            else:
                theResult = 'cannot find function: ' + func
                self.error = theResult

        except Exception as e:

            # exception args are a tuple
            args = e.args
            if len(args) > 0:
                theResult = self.__class__.__name__ + ' error loading script:' + e.args[
                    0]
            else:
                theResult = 'unknown error'

            self.error = theResult

        except:
            theResult = 'an error has occurred in the script executor'
            self.error = theResult
        finally:
            f.close()

        return theResult
Exemple #14
0
from PyObjCTools import AppHelper
import objc;objc.setVerbose(1)

# Import all submodules,  to make sure all
# classes are known to the runtime
import CalendarMatrix
import InfoWindowController
import SelectionNotifyMatrix
import ToDoCell
import ToDoDocument
import ToDoItem
import TodoAppDelegate

AppHelper.runEventLoop()
Exemple #15
0
from PyObjCTools import NibClassBuilder, AppHelper

import ImageBrowserController

import objc; objc.setVerbose(True)

AppHelper.runEventLoop()
Exemple #16
0
import logging
import os
import os.path

from Foundation import NSLog
from objc import setVerbose
from PyObjCTools import AppHelper

from earthreader.mac.log import NSLogHandler
from earthreader.mac.main import main


if __name__ == '__main__':
    formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')
    debug_handler = NSLogHandler()
    debug_handler.setLevel(logging.DEBUG)  # FIXME
    logfile_path = os.path.join(os.environ['HOME'], 'Library', 'Logs',
                                'EarthReader.log')
    file_handler = logging.FileHandler(logfile_path)
    file_handler.setLevel(logging.DEBUG)  # FIXME
    file_handler.setFormatter(formatter)
    for logger_name in 'earthreader', 'libearth':
        logger = logging.getLogger(logger_name)
        logger.addHandler(debug_handler)
        logger.addHandler(file_handler)
        logger.setLevel(logging.DEBUG)  # FIXME
    NSLog('Logs will go to ' + logfile_path)
    main()
    setVerbose(1)
    AppHelper.runEventLoop()
Exemple #17
0
#  main.py
#  AutoDMG
#
#  Created by Per Olofsson on 2013-09-19.
#  Copyright 2013-2014 Per Olofsson, University of Gothenburg. All rights reserved.
#

import os
import sys
import argparse
import traceback

import objc
import Foundation

objc.setVerbose(True)

from IEDLog import LogDebug, LogInfo, LogNotice, LogWarning, LogError, LogMessage
import IEDLog
from IEDUtil import *
import platform


def get_date_string():
    formatter = NSDateFormatter.alloc().init()
    formatter.setDateFormat_(u"yyyy-MM-dd")
    return formatter.stringFromDate_(NSDate.date())


def get_log_dir():
    logDir = os.path.expanduser(u"~/Library/Logs/AutoDMG")
Exemple #18
0
from PyObjCTools import AppHelper

import Foundation, AppKit, WebKit
from Foundation import *
from AppKit import *
import objc; objc.setVerbose(1)

import PyDocURLProtocol
import PyDocEvents

PyDocURLProtocol.setup()

# the web browser doesn't have or need any code really

if __name__ == '__main__':
    AppHelper.runEventLoop()
Exemple #19
0
#    X I E R P A  3  A P P
#    Distribution by the MIT License.
#
# -----------------------------------------------------------------------------
#
#   run.py
#
#   http://twistedmatrix.com/documents/13.0.0/api/twisted.internet._threadedselect.html
#
#
import os
from PyObjCTools import AppHelper
from AppKit import NSApplication, NSApp, NSBundle, NSLog  # @UnresolvedImport
import objc

objc.setVerbose(True)  # @UndefinedVariable

# Specialized reactor for integrating with arbitrary foreign event loop, such as those you find in GUI toolkits.
from twisted.internet._threadedselect import install

reactor = install()

# import modules containing classes required to start application and load MainMenu.nib
import XierpaAppDelegate

app = NSApplication.sharedApplication()
nibPath = os.path.join(
    os.path.dirname(__file__), "dist", "Xierpa3.app", "Contents", "Resources", "en.lproj", "MainMenu.nib"
)
NSBundle.loadNibFile_externalNameTable_withZone_(nibPath, {}, None)  # @UndefinedVariable
delegate = XierpaAppDelegate.XierpaAppDelegate.alloc().init()  # @UndefinedVariable
Exemple #20
0
import PyObjCTools.AppHelper

import os
from random import randint

import drawBot
from drawBot.ui.drawBotController import DrawBotController
from drawBot.ui.preferencesController import PreferencesController
from drawBot.ui.debug import DebugWindowController

from drawBot.misc import getDefault, stringToInt
from drawBot.updater import Updater

import objc

objc.setVerbose(0)

class DrawBotDocument(AppKit.NSDocument):

    def readFromFile_ofType_(self, path, tp):
        return True, None

    def writeSafelyToURL_ofType_forSaveOperation_error_(self, url, fileType, saveOperation, error):
        path = url.path()
        code = self.vanillaWindowController.code()
        f = file(path, "w")
        f.write(code.encode("utf8"))
        f.close()
        return True, None

    def makeWindowControllers(self):
Exemple #21
0
from PyObjCTools import AppHelper

import AppController

# Uncomment the next two lines to make
# PyObjC more verbose, which helps during
# debugging.
import objc
objc.setVerbose(True)


AppHelper.runEventLoop()
Exemple #22
0
from PyObjCTools import NibClassBuilder, AppHelper
import objc; objc.setVerbose(True)

import AppController
import CalController

AppHelper.runEventLoop()