コード例 #1
0
ファイル: plugins.py プロジェクト: veltsov/skencil-tk
 def __call__(self, document, filename, file=None, options=None):
     poptkey = 'Export.' + self.format_name
     if poptkey not in document.options:
         document.options[poptkey] = self.get_default_options()
     myoptions = document.options[poptkey]
     if options is None:
         if len(self.parameters):
             self.ask_options(myoptions)
     elif len(options):
         myoptions.update(options)
     try:
         module = self.load_module()
     except:
         warn_tb(INTERNAL, 'When importing plugin %s', self.module_name)
         raise SketchError(
             _("Cannot load filter %(name)s") % {'name': self.module_name})
     if file is None and self.preopen_output:
         file = open(filename, 'w')
         close = 1
     else:
         close = 0
     if module is not None:
         module.save(document, file, filename, myoptions)
     if close:
         file.close()
     if self.format_name == NativeFormat:
         document.ClearEdited()
     self.UnloadPlugin()
コード例 #2
0
ファイル: plugins.py プロジェクト: shumik/skencil-c
    def load_module_attr(self, attr):
	try:
	    module = self.load_module()
	    if module is not None:
		return getattr(module, attr)
	except:
	    warn_tb(INTERNAL, 'When importing plugin %s', self.module_name)
	    raise SketchError(_("Cannot load plugin %(name)s.%(attr)s")
			      % {'name':self.module_name, 'attr':attr})
コード例 #3
0
ファイル: plugins.py プロジェクト: shumik/skencil-c
    def __call__(self, *args, **kw):
	try:
	    module = self.load_module()
	    if module is not None:
		return apply(getattr(module, self.class_name), args, kw)
	except:
	    warn_tb(INTERNAL, 'When importing plugin %s', self.module_name)
	    raise SketchError('Cannot load filter %(name)s.%(message)s'
			      % {'name':self.module_name,
				 'message':self.class_name})
コード例 #4
0
ファイル: connector.py プロジェクト: veltsov/skencil-tk
 def Issue(self, object, channel, *args):
     #print object, channel, args
     try:
         receivers = self.connections[id(object)][channel]
     except KeyError:
         return
     for func, fargs in receivers:
         try:
             apply(func, args + fargs)
         except:
             warn_tb(INTERNAL, "%s.%s: %s%s", object, channel, func, fargs)
コード例 #5
0
ファイル: connector.py プロジェクト: shumik/skencil-c
    def Issue(self, object, channel, *args):
	#print object, channel, args
	try:
	    receivers = self.connections[id(object)][channel]
	except KeyError:
	    return
	for func, fargs in receivers:
	    try:
		apply(func, args + fargs)
	    except:
		warn_tb(INTERNAL, "%s.%s: %s%s", object, channel, func, fargs)
コード例 #6
0
ファイル: plugins.py プロジェクト: veltsov/skencil-tk
 def __call__(self, *args, **kw):
     try:
         module = self.load_module()
         if module is not None:
             return apply(getattr(module, self.class_name), args, kw)
     except:
         warn_tb(INTERNAL, 'When importing plugin %s', self.module_name)
         raise SketchError('Cannot load filter %(name)s.%(message)s' % {
             'name': self.module_name,
             'message': self.class_name
         })
コード例 #7
0
ファイル: plugins.py プロジェクト: veltsov/skencil-tk
 def load_module_attr(self, attr):
     try:
         module = self.load_module()
         if module is not None:
             return getattr(module, attr)
     except:
         warn_tb(INTERNAL, 'When importing plugin %s', self.module_name)
         raise SketchError(
             _("Cannot load plugin %(name)s.%(attr)s") % {
                 'name': self.module_name,
                 'attr': attr
             })
コード例 #8
0
ファイル: undo.py プロジェクト: shumik/skencil-c
def Undo(info):
    # execute a single undoinfo
    func = info[0]
    if type(func) == StringType:
        text = func
        func = info[1]
        args = info[2:]
    else:
        args = info[1:]
        text = None
    try:
        redo = apply(func, args)
        if text is not None and callable(redo[0]):
            return (text,) + redo
        else:
            return redo
    except:
        warn(INTERNAL, "Exception in undo:\ninfo: %s\nfunc: %s\nargs: %s", info, func, args)
        warn_tb(INTERNAL)
コード例 #9
0
ファイル: undo.py プロジェクト: veltsov/skencil-tk
def Undo(info):
    # execute a single undoinfo
    func = info[0]
    if type(func) == StringType:
        text = func
        func = info[1]
        args = info[2:]
    else:
        args = info[1:]
        text = None
    try:
        redo = apply(func, args)
        if text is not None and callable(redo[0]):
            return (text, ) + redo
        else:
            return redo
    except:
        warn(INTERNAL, 'Exception in undo:\ninfo: %s\nfunc: %s\nargs: %s',
             info, func, args)
        warn_tb(INTERNAL)
コード例 #10
0
def read_resource_file(filename, magic, errmsg, functions):
    file = open(filename, 'r')
    try:
        line = file.readline()
        if line[:len(magic)] != magic:
            raise SketchError(errmsg % filename)

        from skread import parse_sk_line

        linenr = 1
        while 1:
            line = file.readline()
            if not line:
                break
            linenr = linenr + 1
            try:
                parse_sk_line(line, functions)
            except:
                warn_tb(USER, '%s:%d', filename, linenr)
    finally:
        file.close()
コード例 #11
0
ファイル: plugins.py プロジェクト: shumik/skencil-c
    def __call__(self, document, filename, file = None, options = None):
	if options is None:
	    options = {}
	try:
	    module = self.load_module()
	except:
	    warn_tb(INTERNAL, 'When importing plugin %s', self.module_name)
	    raise SketchError(_("Cannot load filter %(name)s")
			      % {'name':self.module_name})
	if file is None:
	    file = open(filename, 'w')
	    close = 1
	else:
	    close = 0
	if module is not None:
	    module.save(document, file, filename, options)
	if close:
	    file.close()
	if self.format_name == NativeFormat:
	    document.ClearEdited()
	self.UnloadPlugin()
コード例 #12
0
ファイル: loadres.py プロジェクト: shumik/skencil-c
def read_resource_file(filename, magic, errmsg, functions):
    file = open(filename, 'r')
    try:
        line = file.readline()
        if line[:len(magic)] != magic:
            raise SketchError(errmsg % filename)

        from skread import parse_sk_line

        linenr = 1
        while 1:
            line = file.readline()
            if not line:
                break
            linenr = linenr + 1
            try:
                parse_sk_line(line, functions)
            except:
                warn_tb(USER, '%s:%d', filename, linenr)
    finally:
        file.close()
コード例 #13
0
def load_user_preferences():
    # Load the user specific configuration.
    if os.path.isdir(config.user_config_dir):
        sys.path.insert(0, config.user_config_dir)

    filename = os.path.join(config.user_config_dir, config.user_settings_file)
    if os.path.isfile(filename):
        try:
            execfile(filename, {'preferences':config.preferences})
        except:
            warn_tb(USER, "Cannot read the preferences file")
    try:
        import userhooks
    except ImportError:
        tb = sys.exc_info()[2]
        try:
            if tb.tb_next is not None:
                # The ImportError exception was raised from inside the
                # userhooks module.
                warn_tb(USER, "Cannot import the userhooks file")
            else:
                # There's no userhooks module.
                pass
        finally:
            del tb
    except:
        warn_tb(USER, "Cannot import the userhooks file")
コード例 #14
0
ファイル: configutil.py プロジェクト: shumik/skencil-c
def load_user_preferences():
    # Load the user specific configuration.
    if os.path.isdir(config.user_config_dir):
	sys.path.insert(0, config.user_config_dir)

    filename = os.path.join(config.user_config_dir, config.user_settings_file)
    if os.path.isfile(filename):
	try:
	    execfile(filename, {'preferences':config.preferences})
	except:
	    warn_tb(USER, "Cannot read the preferences file")
    try:
	import userhooks
    except ImportError:
        tb = sys.exc_info()[2]
        try:
            if tb.tb_next is not None:
                # The ImportError exception was raised from inside the
                # userhooks module.
                warn_tb(USER, "Cannot import the userhooks file")
            else:
                # There's no userhooks module.
                pass
        finally:
            del tb
    except:
	warn_tb(USER, "Cannot import the userhooks file")
コード例 #15
0
ファイル: plugins.py プロジェクト: veltsov/skencil-tk
 def load_module(self):
     if self.module is not None:
         return self.module
     try:
         file, filename, desc = imp.find_module(self.module_name,
                                                [self.dir])
     except:
         warn_tb(INTERNAL, 'Cannot find plugin module %s', self.module_name)
         return None
     try:
         try:
             create_packages(self.package)
             module_name = self.package + '.' + self.module_name
             self.module = imp.load_module(module_name, file, filename,
                                           desc)
         except:
             warn_tb(USER, _("Cannot load plugin module %s"),
                     self.module_name)
             raise
     finally:
         if file is not None:
             file.close()
     self.module._ = self.nls_function()
     return self.module
コード例 #16
0
ファイル: plugins.py プロジェクト: shumik/skencil-c
    def load_module(self):
	if self.module is not None:
	    return self.module
	try:
	    file, filename, desc = imp.find_module(self.module_name,
						   [self.dir])
	except:
	    warn_tb(INTERNAL, 'Cannot find plugin module %s', self.module_name)
	    return None
	try:
	    try:
		create_packages(self.package)
		module_name = self.package + '.' + self.module_name
		self.module = imp.load_module(module_name, file, filename,
					      desc)
	    except:
		warn_tb(USER, _("Cannot load plugin module %s"),
			self.module_name)
		raise
	finally:
	    if file is not None:
		file.close()
	self.module._ = self.nls_function()
	return self.module
コード例 #17
0
ファイル: plugins.py プロジェクト: shumik/skencil-c
	    try:
		module_name = os.path.splitext(os.path.basename(filename))[0]
		vars = {'_':_}	# hack
		cfg = extract_cfg(filename)
		exec cfg in config_types, vars
		infoclass = vars.get('type')
		if infoclass is None:
		    warn(USER, _("No plugin-type information in %(filename)s"),
			 filename = filename)
		else:
		    del vars['type']
		    del vars['_']
		    info = apply(infoclass, (module_name, dir), vars)
		    info.package = package
	    except:
		warn_tb(INTERNAL, 'In config file %s', filename)
		warn(USER, _("can't read configuration information from "
			     "%(filename)s"),
		     filename =	 filename)

def load_plugin_configuration(): #path):
    if __debug__:
	import time
	start = time.clock()
    path = config.plugin_path
    for dir in path:
	# XXX unix specific
	if len(dir) >= 2 and dir[-1] == '/':
	    if dir[-2] == '/':
		recurse = -1
	    else:
コード例 #18
0
ファイル: plugins.py プロジェクト: veltsov/skencil-tk
                module_name = os.path.splitext(os.path.basename(filename))[0]
                vars = {'_': _}  # hack
                cfg = extract_cfg(filename)
                exec cfg in config_types, vars
                infoclass = vars.get('type')
                if infoclass is None:
                    warn(USER,
                         _("No plugin-type information in %(filename)s"),
                         filename=filename)
                else:
                    del vars['type']
                    del vars['_']
                    info = apply(infoclass, (module_name, dir), vars)
                    info.package = package
            except:
                warn_tb(INTERNAL, 'In config file %s', filename)
                warn(USER,
                     _("can't read configuration information from "
                       "%(filename)s"),
                     filename=filename)


def load_plugin_configuration():  #path):
    if __debug__:
        import time
        start = time.clock()
    path = config.plugin_path
    for dir in path:
        # XXX unix specific
        if len(dir) >= 2 and dir[-1] == '/':
            if dir[-2] == '/':