Ejemplo n.º 1
0
 def __init__(self, parent, app):
     super().__init__(parent)
     if DlgPreferences.color_highlight_background is None:
         DlgPreferences.color_highlight_background = \
             self.palette().color(QtGui.QPalette.Highlight).name()
     if DlgPreferences.color_highlight_text is None:
         DlgPreferences.color_highlight_text = self.palette().color(
             QtGui.QPalette.HighlightedText).name()
     self.app = app
     self._ui = dlg_preferences_ui.Ui_Dialog()
     self._ui.setupUi(self)
     self._connect_slots()
     # force reload of settings
     settings.load()
     self._setup_builtin_pages()
     self._setup_editor_pages()
     self._setup_plugin_pages()
     self._ui.categories.sortByColumn(0, QtCore.Qt.AscendingOrder)
     self._ui.categories.expandAll()
     self.restore_state()
     btns = self._ui.buttons
     btns.button(btns.Reset).setToolTip(
         _('Reset changes made to the current page.'))
     btns.button(btns.RestoreDefaults).setToolTip(
         _('Restore factory defaults for the current page.'))
     btns.button(btns.Apply).setToolTip(
         _('Apply changes but keep dialog open.'))
     btns.button(btns.Ok).setToolTip(
         _('Apply changes and close dialog.'))
     btns.button(btns.Cancel).setToolTip(
         _('Close dialog and cancel any changes.'))
     self._ui.pages.setContentsMargins(0, 0, 0, 0)
Ejemplo n.º 2
0
 def __init__(self, parent, app):
     super().__init__(parent)
     _logger().info('opening preferences dialog')
     if DlgPreferences.color_highlight_background is None:
         DlgPreferences.color_highlight_background = \
             self.palette().color(QtGui.QPalette.Highlight).name()
     if DlgPreferences.color_highlight_text is None:
         DlgPreferences.color_highlight_text = self.palette().color(
             QtGui.QPalette.HighlightedText).name()
     self.app = app
     self._ui = dlg_preferences_ui.Ui_Dialog()
     self._ui.setupUi(self)
     self._connect_slots()
     # force reload of settings
     settings.load()
     self._setup_pages()
     self._ui.categories.sortByColumn(0, QtCore.Qt.AscendingOrder)
     self._ui.categories.expandAll()
     self.restore_state()
     btns = self._ui.buttons
     btns.button(btns.Reset).setToolTip(
         _('Reset changes made to the current page.'))
     btns.button(btns.RestoreDefaults).setToolTip(
         _('Restore factory defaults for the current page.'))
     btns.button(btns.Apply).setToolTip(
         _('Apply changes but keep dialog open.'))
     btns.button(btns.Ok).setToolTip(_('Apply changes and close dialog.'))
     btns.button(btns.Cancel).setToolTip(
         _('Close dialog and cancel any changes.'))
     self._ui.pages.setContentsMargins(0, 0, 0, 0)
Ejemplo n.º 3
0
def test_add_mimetype_extension():
    settings.load()
    settings._SETTINGS.clear()
    mtype = 'text/x-own'
    ext = '.own'
    assert ext not in mime_types.get_extensions(mtype)
    utils.add_mimetype_extension(mtype, ext)
    assert ext in mime_types.get_extensions(mtype)
Ejemplo n.º 4
0
def test_add_mimetype_extension():
    settings.load()
    settings._SETTINGS.clear()
    mtype = 'text/x-own'
    ext = '.own'
    assert ext not in mime_types.get_extensions(mtype)
    utils.add_mimetype_extension(mtype, ext)
    assert ext in mime_types.get_extensions(mtype)
Ejemplo n.º 5
0
def test_user_config():
    settings.load()
    data = project.load_user_config(PATH1)
    assert data == {}
    data = {'Foo': 'bar', 'Spam': 4, 'Eggs': [1, 2, 3]}
    project.save_user_config(PATH1, data)
    usd = project.load_user_config(PATH1)
    assert data == usd
    usd['Foo'] = 'BAR'
    project.save_user_config(PATH1, usd)
Ejemplo n.º 6
0
 def __enter__(self):
     if self._remove_project_folder:
         try:
             shutil.rmtree(os.path.join(self._path, project.FOLDER))
         except OSError:
             pass
     a = app()
     a.show_windows = False
     settings.load()
     QtCore.QSettings().clear()
     settings.set_confirm_app_exit(False)
     a.open_path(self._path)
     self.instance = a.editor_windows[-1]
     return self
Ejemplo n.º 7
0
def get_sources():
    """
    Returns the template sources (directory associated with a label).
    """
    s = settings.load()
    tmpl_sources = s.value('_templates/sources', '[]')
    tmpl_sources = json.loads(tmpl_sources)
    return sorted(tmpl_sources, key=lambda x: x['label'])
Ejemplo n.º 8
0
def get_sources():
    """
    Returns the template sources (directory associated with a label).
    """
    s = settings.load()
    tmpl_sources = s.value('_templates/sources', '[]')
    tmpl_sources = json.loads(tmpl_sources)
    return sorted(tmpl_sources, key=lambda x: x['label'])
Ejemplo n.º 9
0
def add_source(label, path):
    """
    Adds a template source

    :param label: Name of the template source.
    :param path: Path of the template source.
    """
    tmpl_sources = get_sources()
    tmpl_sources.append({'label': label, 'path': path})
    s = settings.load()
    s.setValue('_templates/sources', json.dumps(tmpl_sources))
Ejemplo n.º 10
0
def add_source(label, path):
    """
    Adds a template source

    :param label: Name of the template source.
    :param path: Path of the template source.
    """
    tmpl_sources = get_sources()
    tmpl_sources.append({'label': label, 'path': path})
    s = settings.load()
    s.setValue('_templates/sources', json.dumps(tmpl_sources))
Ejemplo n.º 11
0
def rm_source(label):
    """
    Removes the specified template source.

    :param label: Name of the template source to remove.
    """
    tmpl_sources = get_sources()
    for src in tmpl_sources:
        if src['label'] == label:
            tmpl_sources.remove(src)
    s = settings.load()
    s.setValue('_templates/sources', json.dumps(tmpl_sources))
Ejemplo n.º 12
0
def rm_source(label):
    """
    Removes the specified template source.

    :param label: Name of the template source to remove.
    """
    tmpl_sources = get_sources()
    for src in tmpl_sources:
        if src['label'] == label:
            tmpl_sources.remove(src)
    s = settings.load()
    s.setValue('_templates/sources', json.dumps(tmpl_sources))
Ejemplo n.º 13
0
def clear_sources():
    """
    Clear template sources.
    """
    s = settings.load()
    s.setValue('_templates/sources', json.dumps([]))
Ejemplo n.º 14
0
def main():
    """
    Application entry point, runs the application
    """
    # parse command line args
    args = argparser.parse_args()
    if args.log:
        # print the last application log
        try:
            with open(logger.get_path(), 'r') as f:
                print(f.read())
        finally:
            sys.exit(0)
    if args.version:
        # print versions
        from hackedit.api.versions import versions_str
        print(versions_str())
        sys.exit(0)

    # tell pyqode that we use the PyQt5 API.
    os.environ['QT_API'] = 'pyqt5'

    # Setup Qt Application
    qapp = QtWidgets.QApplication(sys.argv)
    qapp.setOrganizationName('HackEdit')
    qapp.setOrganizationDomain('hackedit.com')
    qapp.setApplicationDisplayName('HackEdit')
    qapp.setApplicationName('HackEdit')
    qapp.setApplicationVersion(__version__)

    get_translation()

    # setup logger
    from hackedit.app import settings
    settings.load()

    log_level = settings.log_level()
    # override log level
    if args.log_level:
        log_level = args.log_level
    elif args.verbose:
        log_level = logging.DEBUG
    logger.setup(log_level)

    _logger().info('starting up...')

    # Setup splash screen
    if settings.show_splashscreen():
        from hackedit.app.forms import hackedit_rc
        assert hackedit_rc

        pixmap = QtGui.QPixmap(':/splashscreen.png')
        splash = QtWidgets.QSplashScreen(pixmap)
        splash.show()
        splash.raise_()
        qapp.processEvents()

        splash.showMessage(_('Loading application module'),
                           QtCore.Qt.AlignBottom | QtCore.Qt.AlignHCenter,
                           QtCore.Qt.white)
        qapp.processEvents()

    else:
        splash = None

    # Setup hackedit application, this may take a while as we have
    # to load all plugin entry points, load the icon theme,...
    from hackedit.app.application import Application
    app = Application(qapp, splash, args)

    # Run the application!
    _logger().info('running...')
    app.run()

    # remove temporary stdout/stderr
    try:
        sys.stdout.close()
        os.remove(stdout_path)
    except OSError:
        pass
    try:
        sys.stderr.close()
        os.remove(stderr_path)
    except OSError:
        pass
Ejemplo n.º 15
0
def main():
    """
    Application entry point, runs the application
    """
    # parse command line args
    args = argparser.parse_args()
    if args.log:
        # print the last application log
        try:
            with open(logger.get_path(), 'r') as f:
                print(f.read())
        finally:
            sys.exit(0)
    if args.version:
        # print versions
        from hackedit.api.versions import versions_str
        print(versions_str())
        sys.exit(0)

    # tell pyqode that we use the PyQt5 API.
    os.environ['QT_API'] = 'pyqt5'

    # Setup Qt Application
    qapp = QtWidgets.QApplication(sys.argv)
    qapp.setOrganizationName('HackEdit')
    qapp.setOrganizationDomain('hackedit.com')
    qapp.setApplicationDisplayName('HackEdit')
    qapp.setApplicationName('HackEdit')
    qapp.setApplicationVersion(__version__)

    get_translation()

    # setup logger
    from hackedit.app import settings
    settings.load()

    log_level = settings.log_level()
    # override log level
    if args.log_level:
        log_level = args.log_level
    elif args.verbose:
        log_level = logging.DEBUG
    logger.setup(log_level)

    _logger().info('hackedit vendor path: %s',
                   os.environ.get('HACKEDIT_VENDOR_PATH'))

    # Setup splash screen
    if settings.show_splashscreen():
        from hackedit.app.forms import hackedit_rc
        assert hackedit_rc

        pixmap = QtGui.QPixmap(':/splashscreen.png')
        splash = QtWidgets.QSplashScreen(pixmap)
        splash.show()
        splash.raise_()
        qapp.processEvents()

        splash.showMessage(_('Loading application module'),
                           QtCore.Qt.AlignBottom | QtCore.Qt.AlignHCenter,
                           QtCore.Qt.white)
        qapp.processEvents()

    else:
        splash = None

    # Setup hackedit application, this may take a while as we have
    # to load all plugin entry points, load the icon theme,...
    from hackedit.app.application import Application
    app = Application(qapp, splash, args)

    # Run the application!
    _logger().info('running...')
    app.run()

    # remove temporary stdout/stderr
    try:
        sys.stdout.close()
        os.remove(stdout_path)
    except OSError:
        pass
    try:
        sys.stderr.close()
        os.remove(stderr_path)
    except OSError:
        pass
Ejemplo n.º 16
0
def clear_sources():
    """
    Clear template sources.
    """
    s = settings.load()
    s.setValue('_templates/sources', json.dumps([]))