コード例 #1
0
ファイル: dictionaries.py プロジェクト: tallforasmurf/PPQT2
def get_tag_list(path = ''):
    tag_dict = {}
    if path : # don't bother searching a nullstring path
        _find_tags(path, tag_dict)
    _find_tags(paths.get_dicts_path(), tag_dict)
    _find_tags(paths.get_extras_path(), tag_dict)
    return tag_dict
コード例 #2
0
ファイル: helpview.py プロジェクト: tallforasmurf/PPQT2
 def path_change( self, code='extras' ) :
     if code == 'extras' :
         extras_path = paths.get_extras_path()
         help_path = os.path.join( extras_path , 'ppqt2help.html' )
         sphinx_path = os.path.join( extras_path, 'sphinx', 'index.html' )
         if os.access( help_path, os.R_OK ) and os.access( sphinx_path, os.R_OK ) :
             # the help file exists. Save a QUrl describing it, and load it.
             self.help_url = QUrl.fromLocalFile( sphinx_path )
             self.view.load( self.help_url )
         else :
             self.help_url = None
             self.view.setHtml( DEFAULT_HTML )
コード例 #3
0
ファイル: helpview.py プロジェクト: tallforasmurf/PPQT2
 def path_change(self, code='extras'):
     if code == 'extras':
         extras_path = paths.get_extras_path()
         help_path = os.path.join(extras_path, 'ppqt2help.html')
         sphinx_path = os.path.join(extras_path, 'sphinx', 'index.html')
         if os.access(help_path, os.R_OK) and os.access(
                 sphinx_path, os.R_OK):
             # the help file exists. Save a QUrl describing it, and load it.
             self.help_url = QUrl.fromLocalFile(sphinx_path)
             self.view.load(self.help_url)
         else:
             self.help_url = None
             self.view.setHtml(DEFAULT_HTML)
コード例 #4
0
ファイル: dictionaries.py プロジェクト: B-Rich/PPQT2
def get_tag_list(path = ''):
    tag_dict = {}
    _find_tags(path, tag_dict)
    _find_tags(paths.get_dicts_path(), tag_dict)
    _find_tags(paths.get_extras_path(), tag_dict)
    return tag_dict
コード例 #5
0
 def reset( self ) :
     p = paths.get_extras_path()
     self.path_edit.setText( p )
コード例 #6
0
import logging
import sys
import os
import test_boilerplate as T

T.set_up_paths()
T.make_app()

# Initialize paths to Tests/Files/extras/dicts (from paths_test)
import paths

test_extras = os.path.join(T.path_to_Files, 'extras')
T.settings.clear()
T.settings.setValue("paths/extras_path", test_extras)
paths.initialize(T.settings)
assert paths.get_extras_path() == test_extras
test_dicts = paths.get_dicts_path()

import dictionaries

T.settings.setValue("dictionaries/default_tag", 'en_GB')
dictionaries.initialize(T.settings)
assert 'en_GB' == dictionaries.get_default_tag()

# There are 3 dicts in Tests/Files/extras/dicts: en_US, en_GB, fr_FR
# There are 4 in Tests/Files/extras, those 3 plus de_DE

expect_tag_list = {
    'en_US': test_dicts,
    'en_GB': test_dicts,
    'fr_FR': test_dicts,
コード例 #7
0
#
# set up logging to a stream
import logging
import sys
import os
import test_boilerplate as T
T.set_up_paths()
T.make_app()

# Initialize paths to Tests/Files/extras/dicts (from paths_test)
import paths
test_extras = os.path.join(T.path_to_Files,'extras')
T.settings.clear()
T.settings.setValue("paths/extras_path", test_extras)
paths.initialize(T.settings)
assert paths.get_extras_path() == test_extras
test_dicts = paths.get_dicts_path()

import dictionaries
T.settings.setValue("dictionaries/default_tag",'en_GB')
dictionaries.initialize(T.settings)
assert 'en_GB' == dictionaries.get_default_tag()

# There are 3 dicts in Tests/Files/extras/dicts: en_US, en_GB, fr_FR
# There are 4 in Tests/Files/extras, those 3 plus de_DE

expect_tag_list = {'en_US':test_dicts,'en_GB':test_dicts,'fr_FR':test_dicts,'de_DE':test_extras}
tag_list = dictionaries.get_tag_list()
for (tag,path) in expect_tag_list.items():
    assert tag in tag_list
    assert tag_list[tag] == expect_tag_list[tag]
コード例 #8
0
ファイル: paths_test.py プロジェクト: B-Rich/PPQT2
app.setOrganizationDomain("pgdp.net")
app.setApplicationName("PPQT2")
from PyQt5.QtCore import QSettings
settings = QSettings()
import constants as C
import paths

assert paths.check_path(test_path)
assert not paths.check_path(os.path.join(test_path,'arglebargle'))
assert not paths.check_path(os.path.join(files_path,'unreadable.aff'))

settings.clear()
paths.initialize(settings)
# with null settings, extras defaults to cwd = test_path
check_log('initial extras path is '+test_path ,logging.DEBUG)
assert paths.get_extras_path() == test_path
assert paths.get_dicts_path() == ''
# point settings to an extras, expect dicts to follow
test_extras = os.path.join(files_path,'extras')
settings.setValue("paths/extras_path", test_extras)
paths.initialize(settings)
check_log('initial extras path is '+test_extras ,logging.DEBUG)
assert paths.get_extras_path() == test_extras
test_dicts = os.path.join(test_extras,'dicts')
assert paths.get_dicts_path() == test_dicts
# test shutdown
settings.clear()
paths.shutdown(settings)
assert settings.value("paths/extras_path",'wrong') == test_extras
assert settings.value("paths/dicts_path",'wrong') == test_dicts
# operate the pref sets
コード例 #9
0
ファイル: paths_test.py プロジェクト: tallforasmurf/PPQT2
import constants as C
import paths
T.settings.clear()
# test readable folder
test_path = T.path_to_Files
assert paths.check_path(test_path)
# nonexistent file
assert not paths.check_path(os.path.join(test_path, 'arglebargle'))
# file that has the read perms turned off
assert not paths.check_path(os.path.join(test_path, 'unreadable.aff'))

paths.initialize(T.settings)

# with null settings, extras defaults to cwd = test_path
assert T.check_log('initial extras path is ' + test_path, logging.INFO)
assert paths.get_extras_path() == test_path
assert paths.get_dicts_path() == ''
# check assuming bookloupe is installed
if C.PLATFORM_IS_WIN:
    assert paths.get_loupe_path() == ''  # TODO FIX WHEN KNOWN
else:
    assert paths.get_loupe_path() == '/usr/local/bin/bookloupe'
# point settings to an extras, expect dicts to follow
test_extras = os.path.join(T.path_to_Files, 'extras')
T.settings.setValue("paths/extras_path", test_extras)
paths.initialize(T.settings)
assert T.check_log('initial extras path is ' + test_extras, logging.INFO)
assert paths.get_extras_path() == test_extras
test_dicts = os.path.join(test_extras, 'dicts')
assert paths.get_dicts_path() == test_dicts
# Make sure that what we put into loupe, we get back
コード例 #10
0
ファイル: translators.py プロジェクト: tallforasmurf/PPQT2
def build_xlt_menu( mainwindow, slot ):

    # Create the submenu but assume it will be empty.
    submenu = QMenu(
        _TR( 'Name of Translators submenu', 'Translators...' ) )
    submenu.setToolTip(
        _TR( 'Translators submenu tooltip',
             'Available Translators in extras/Translators folder' ) )
    submenu.setEnabled( False )

    # Form the path to extras/Translators and try to get a list
    # of all files in it. If it doesn't exist or isn't a dir,
    # we get an error.
    xlt_dir = os.path.join( paths.get_extras_path(), 'Translators' )
    try :
        xlt_files = os.listdir( xlt_dir )
    except Exception as E:
        # this error is logged but not displayed to the user as its
        # only effect is an empty, disabled submenu.
        xlt_logger.error( 'Unable to load any Translator modules')
        xlt_logger.error( str(E) )
        xlt_files = []

    # Check every file in extras/Translators as a possible Translator
    for candidate in xlt_files :

        # Form the full path
        candidate_path = os.path.join( xlt_dir, candidate )

        # Is it readable?
        if not os.access( candidate_path, os.R_OK ) : continue

        # Is it a python source? (Not supporting .pyc just now)
        if not candidate.endswith('.py') : continue

        # Create a loader object - this throws no exceptions
        xlt_logger.info( 'Loading translator module '+candidate )
        xlt_loader = importlib.machinery.SourceFileLoader(
            os.path.splitext( candidate )[0], candidate_path )

        # Try the actual load, which executes the code and can throw
        # exceptions either directly from the loader, or uncaught exceptions
        # thrown by the loaded code. If any exceptions, skip it.
        xlt_logger.info( 'Executing translator into namespace '+candidate )
        try:
            xlt_namespace = xlt_loader.load_module()
        except Exception as E :
            # This error is only logged. It is of interest only to the
            # coder of a Translator wondering why it doesn't appear.
            xlt_logger.error( 'Error loading or executing Translator {}:'.format(candidate) )
            xlt_logger.error( str(E) )
            continue

        # The loaded module should have a MENU_NAME which is a string
        xlt_name = getattr( xlt_namespace, 'MENU_NAME', False )
        if not isinstance(xlt_name, str) :
            xlt_logger.error('Translator {} has no MENU_NAME string'.format(candidate) )
            continue

        # The MENU_NAME should be of reasonable length for a menu item
        if ( len( xlt_name ) > 16 ) or ( len( xlt_name ) < 3 ) :
            xlt_logger.error('Translator {} MENU_NAME too long or too short'.format(candidate) )
            continue

        # The loaded module should offer global functions initialize() and
        # translate(). If not, log an error.

        xlt_fun = getattr( xlt_namespace, 'initialize', False )
        if not isinstance( xlt_fun, types.FunctionType ):
            xlt_logger.error('Translator {} lacks initialize() member'.format(candidate) )
            continue
        xlt_fun = getattr( xlt_namespace, 'translate', False )
        if not isinstance( xlt_fun, types.FunctionType ) :
            xlt_logger.error('Translator {} lacks translate() member'.format(candidate) )
            continue
        xlt_fun = getattr( xlt_namespace, 'finalize', False )
        if not isinstance( xlt_fun, types.FunctionType ) :
            xlt_logger.error('Translator {} lacks finalize() member'.format(candidate) )
            continue
        # OK, we are going to trust it. Save the namespace for use later.
        xlt_index = len( _XLT_NAMESPACES )
        _XLT_NAMESPACES.append( xlt_namespace )

        # Build the menu action with the given name and an optional tooltip.
        action = submenu.addAction( xlt_namespace.MENU_NAME )
        action.setToolTip( getattr( xlt_namespace, 'TOOLTIP', '' ) )

        # Save the index to the namespace as the menu action's data()
        action.setData( xlt_index )

        # Connect the action to the slot provided
        action.triggered.connect( slot )

        # The menu is not going to be empty, so make it enabled
        submenu.setEnabled( True )

    # end for candidate in xlt_files
    return submenu