Beispiel #1
0
def main():
    cmdLine = _parseCommandLine()

    profiler = _StartProfiler(cmdLine["profiling"])

    try:
        _checkDependencies(profiler)
    except ImportError:
        sys.exit(-1)

    # Imports only here. Hack for ability to get help and version info even on system without PyQt.
    import PyQt5.QtGui
    import qutepart

    logging.basicConfig(level=logging.ERROR)
    logging.getLogger('qutepart').removeHandler(qutepart.consoleHandler)

    sys.excepthook = excepthook

    app = PyQt5.QtWidgets.QApplication(sys.argv)
    app.setApplicationName(enki.core.defines.PACKAGE_NAME)
    app.setOrganizationName(enki.core.defines.PACKAGE_ORGANISATION)
    app.setOrganizationDomain(enki.core.defines.PACKAGE_URL)
    app.lastWindowClosed.connect(app.quit)

    profiler.stepDone('Construct application')

    # init the core
    from enki.core.core import core
    core.init(profiler, cmdLine)

    _openFiles(core, cmdLine, profiler)

    profiler.stepDone('Open files')

    if core.workspace().currentDocument():
        core.workspace().currentDocument().setFocus()

    core.mainWindow().loadState()
    profiler.stepDone('Load state')

    core.mainWindow().show()

    profiler.stepDone('Show main window')

    # execute application
    if profiler.enabled:
        core.workspace().forceCloseAllDocuments()
        result = 0
    else:
        result = app.exec_()

    core.term()

    profiler.printInfo()

    profiler.stepDone('Terminate core')

    return result
Beispiel #2
0
def main():
    cmdLine = _parseCommandLine()

    profiler = _StartProfiler(cmdLine["profiling"])

    try:
        _checkDependencies(profiler)
    except ImportError:
        sys.exit(-1)

    # Imports only here. Hack for ability to get help and version info even on system without PyQt.
    import PyQt5.QtGui
    import qutepart

    logging.basicConfig(level=logging.ERROR)
    logging.getLogger('qutepart').removeHandler(qutepart.consoleHandler)

    sys.excepthook = excepthook

    app = PyQt5.QtWidgets.QApplication(sys.argv)
    app.setApplicationName(enki.core.defines.PACKAGE_NAME)
    app.setOrganizationName(enki.core.defines.PACKAGE_ORGANISATION)
    app.setOrganizationDomain(enki.core.defines.PACKAGE_URL)
    app.lastWindowClosed.connect(app.quit)

    profiler.stepDone('Construct application')

    # init the core
    from enki.core.core import core
    core.init(profiler, cmdLine)

    _openFiles(core, cmdLine, profiler)

    profiler.stepDone('Open files')

    if core.workspace().currentDocument():
        core.workspace().currentDocument().setFocus()

    core.mainWindow().loadState()
    profiler.stepDone('Load state')

    core.mainWindow().show()

    profiler.stepDone('Show main window')

    # execute application
    if profiler.enabled:
        core.workspace().forceCloseAllDocuments()
        result = 0
    else:
        result = app.exec_()

    core.term()

    profiler.printInfo()

    profiler.stepDone('Terminate core')

    return result
Beispiel #3
0
    def setUp(self):
        self._finished = False
        self._cleanUpFs()
        try:
            os.mkdir(self.TEST_FILE_DIR)
        except OSError as e:
            pass

        with open(self.EXISTING_FILE, 'w') as f:
            f.write(self.EXISTING_FILE_TEXT)

        os.chdir(self.TEST_FILE_DIR)

        core.init(DummyProfiler())
Beispiel #4
0
    def setUp(self):
        self._finished = False
        self._cleanUpFs()
        try:
            os.mkdir(self.TEST_FILE_DIR)
        except OSError as e:
            pass

        with open(self.EXISTING_FILE, 'w') as f:
            f.write(self.EXISTING_FILE_TEXT)

        os.chdir(self.TEST_FILE_DIR)

        core.init(DummyProfiler(), {'session_name': ''})
Beispiel #5
0
    def test_1(self):
        # Enki restores configs from old directory ~/.enki to new ~/.config/enki
        oldCfg = enki.core.core._OLD_CONFIG_DIR
        currCfg = enki.core.defines.CONFIG_DIR

        enki.core.core._OLD_CONFIG_DIR = self.TEST_FILE_DIR + '/old'
        enki.core.defines.CONFIG_DIR = self.TEST_FILE_DIR + '/new'

        try:
            os.mkdir(enki.core.core._OLD_CONFIG_DIR)
            core.init(base.DummyProfiler(), {'session_name': '', 'auto-session-name': ''})
            self.assertTrue(os.path.isdir(enki.core.defines.CONFIG_DIR))
            self.assertFalse(os.path.isdir(enki.core.core._OLD_CONFIG_DIR))
        finally:
            enki.core.core._OLD_CONFIG_DIR = oldCfg
            enki.core.defines.CONFIG_DIR = currCfg
Beispiel #6
0
    def test_1(self):
        # Enki restores configs from old directory ~/.enki to new ~/.config/enki
        oldCfg = enki.core.core._OLD_CONFIG_DIR
        currCfg = enki.core.defines.CONFIG_DIR

        enki.core.core._OLD_CONFIG_DIR = self.TEST_FILE_DIR + '/old'
        enki.core.defines.CONFIG_DIR = self.TEST_FILE_DIR + '/new'

        try:
            os.mkdir(enki.core.core._OLD_CONFIG_DIR)
            core.init(base.DummyProfiler(), {'session_name': ''})
            self.assertTrue(os.path.isdir(enki.core.defines.CONFIG_DIR))
            self.assertFalse(os.path.isdir(enki.core.core._OLD_CONFIG_DIR))
        finally:
            enki.core.core._OLD_CONFIG_DIR = oldCfg
            enki.core.defines.CONFIG_DIR = currCfg
Beispiel #7
0
    def setUp(self):
        self._finished = False
        self._cleanUpFs()

        # Ignore warnings from PyQt5 ui loader
        warnings.simplefilter("ignore", ResourceWarning)
        warnings.simplefilter("ignore", DeprecationWarning)

        try:
            os.mkdir(self.TEST_FILE_DIR)
        except OSError as e:
            pass

        with open(self.EXISTING_FILE, 'w') as f:
            f.write(self.EXISTING_FILE_TEXT)

        os.chdir(self.TEST_FILE_DIR)

        core.init(DummyProfiler(), {'session_name': ''})
Beispiel #8
0
    def setUp(self):
        self._finished = False
        self._cleanUpFs()

        # Ignore warnings from PyQt5 ui loader
        warnings.simplefilter("ignore", ResourceWarning)
        warnings.simplefilter("ignore", DeprecationWarning)

        try:
            os.mkdir(self.TEST_FILE_DIR)
        except OSError as e:
            pass

        with open(self.EXISTING_FILE, 'w') as f:
            f.write(self.EXISTING_FILE_TEXT)

        os.chdir(self.TEST_FILE_DIR)

        core.init(DummyProfiler(), {'session_name': ''})
Beispiel #9
0
    def test_1(self):
        """ Init with current document path
        """
        path = os.path.abspath("../..")

        dock = self.findDock("&File Browser")
        dock._onVisibilityChanged(True)
        dock.setCurrentPath(path)

        core.term()
        core.init(base.DummyProfiler(), {"session_name": ""})
        dock = self.findDock("&File Browser")
        dock._onVisibilityChanged(True)

        # We can't simply do ``dock.currentPath() == path`` because of
        # Windows fun: ``u'C:/Users/bjones/AppData/Local' != 'c:\\users\\bjones\\appdata\\local'``.
        # We can't use ``os.path.samefile()`` because that's available only on
        # Unix for Python 2.7. So, use normpath and normcase per
        # http://stackoverflow.com/questions/21158667/comparing-two-paths-in-python.
        self.assertEqual(normpathcase(dock.currentPath()), normpathcase(self.TEST_FILE_DIR))
Beispiel #10
0
    def test_1(self):
        """ Init with current document path
        """
        path = os.path.abspath('../..')

        dock = self.findDock('&File Browser')
        dock._onVisibilityChanged(True)
        dock.setCurrentPath(path)

        core.term()
        core.init(base.DummyProfiler(), {'session_name': '',
                                         'auto-session-name': ''})
        dock = self.findDock('&File Browser')
        dock._onVisibilityChanged(True)

        # We can't simply do ``dock.currentPath() == path`` because of
        # Windows fun: ``u'C:/Users/bjones/AppData/Local' != 'c:\\users\\bjones\\appdata\\local'``.
        # We can't use ``os.path.samefile()`` because that's available only on
        # Unix for Python 2.7. So, use normpath and normcase per
        # http://stackoverflow.com/questions/21158667/comparing-two-paths-in-python.
        self.assertEqual(normpathcase(dock.currentPath()), normpathcase(self.TEST_FILE_DIR))
Beispiel #11
0
    def test_2(self):
        # Enki shows QMessageBox if failed to move config dir
        oldCfg = enki.core.core._OLD_CONFIG_DIR
        currCfg = enki.core.defines.CONFIG_DIR

        enki.core.core._OLD_CONFIG_DIR = self.TEST_FILE_DIR + '/old'
        enki.core.defines.CONFIG_DIR = '/new'
        try:
            os.mkdir(enki.core.core._OLD_CONFIG_DIR)

            def inDialog(dialog):
                self.assertTrue(dialog.windowTitle().startswith('Failed to move configs'))
                dialog.accept()

            self.openDialog(lambda: core.init(base.DummyProfiler(), {'session_name': ''}), inDialog)
        finally:
            enki.core.core._OLD_CONFIG_DIR = oldCfg
            enki.core.defines.CONFIG_DIR = currCfg
Beispiel #12
0
class TestCase(unittest.TestCase):
    CREATE_NOT_SAVED_DOCUMENT = True
    NOT_SAVED_DOCUMENT_TEXT = None

    def setUp(self):
        try:
            os.unlink('/tmp/enki.json')
        except OSError, IOError:
            pass

        self.app = QApplication(sys.argv)
        core.init(None)

        if self.CREATE_NOT_SAVED_DOCUMENT:
            core.workspace().createEmptyNotSavedDocument()
            if self.NOT_SAVED_DOCUMENT_TEXT is not None:
                core.workspace().currentDocument(
                ).qutepart.text = self.NOT_SAVED_DOCUMENT_TEXT
Beispiel #13
0
    def test_2(self):
        # Enki shows QMessageBox if failed to move config dir
        oldCfg = enki.core.core._OLD_CONFIG_DIR
        currCfg = enki.core.defines.CONFIG_DIR

        enki.core.core._OLD_CONFIG_DIR = self.TEST_FILE_DIR + '/old'
        enki.core.defines.CONFIG_DIR = '/new'
        try:
            os.mkdir(enki.core.core._OLD_CONFIG_DIR)

            def inDialog(dialog):
                self.assertTrue(
                    dialog.windowTitle().startswith('Failed to move configs'))
                dialog.accept()

            self.openDialog(
                lambda: core.init(base.DummyProfiler(), {'session_name': ''}),
                inDialog)
        finally:
            enki.core.core._OLD_CONFIG_DIR = oldCfg
            enki.core.defines.CONFIG_DIR = currCfg