[Skencil-commits] r726 - skencil/branches/skencil-0.6/src/Sketch/Base
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Sep 22 21:14:01 CEST 2010
Author: igor_n
Date: 2010-09-22 21:13:59 +0200 (Wed, 22 Sep 2010)
New Revision: 726
Modified:
skencil/branches/skencil-0.6/src/Sketch/Base/load.py
skencil/branches/skencil-0.6/src/Sketch/Base/main.py
skencil/branches/skencil-0.6/src/Sketch/Base/plugins.py
skencil/branches/skencil-0.6/src/Sketch/Base/skexceptions.py
skencil/branches/skencil-0.6/src/Sketch/Base/undo.py
skencil/branches/skencil-0.6/src/Sketch/Base/undodict.py
skencil/branches/skencil-0.6/src/Sketch/Base/warn.py
Log:
mixed indents are removed
Modified: skencil/branches/skencil-0.6/src/Sketch/Base/load.py
===================================================================
--- skencil/branches/skencil-0.6/src/Sketch/Base/load.py 2010-09-22 19:04:20 UTC (rev 725)
+++ skencil/branches/skencil-0.6/src/Sketch/Base/load.py 2010-09-22 19:13:59 UTC (rev 726)
@@ -70,28 +70,28 @@
guess_continuity = 0
def __init__(self):
- self.composite_stack = None
- self.composite_items = []
- self.composite_class = None
- self.composite_args = None
- self.object = None
+ self.composite_stack = None
+ self.composite_items = []
+ self.composite_class = None
+ self.composite_args = None
+ self.object = None
def __push(self):
- self.composite_stack = (self.composite_class,
- self.composite_args,
- self.composite_items,
- self.composite_stack)
+ self.composite_stack = (self.composite_class,
+ self.composite_args,
+ self.composite_items,
+ self.composite_stack)
def __pop(self):
- (self.composite_class, self.composite_args,
- self.composite_items, self.composite_stack) = self.composite_stack
+ (self.composite_class, self.composite_args,
+ self.composite_items, self.composite_stack) = self.composite_stack
def begin_composite(self, composite_class, args = (), kw = None):
- self.__push()
- self.composite_class = composite_class
- self.composite_args = (args, kw)
- self.composite_items = []
- self.object = None
+ self.__push()
+ self.composite_class = composite_class
+ self.composite_args = (args, kw)
+ self.composite_items = []
+ self.object = None
def end_composite(self):
if self.composite_class:
@@ -105,7 +105,7 @@
# then) but they might. If they're empty they're simply
# ignored
if self.composite_items or composite.can_be_empty \
- or composite.is_Plugin:
+ or composite.is_Plugin:
append = composite.load_AppendObject
for item in self.composite_items:
if self.check_object(item):
@@ -120,8 +120,8 @@
raise SketchLoadError('no composite to end')
def end_all(self):
- while self.composite_stack:
- self.end_composite()
+ while self.composite_stack:
+ self.end_composite()
def check_object(self, object):
# Return true if object is OK. Currently this just checks the
@@ -149,8 +149,8 @@
return result
def append_object(self, object):
- self.composite_items.append(object)
- self.object = object
+ self.composite_items.append(object)
+ self.object = object
def pop_last(self):
# remove the last object in self.composite_items and return it
@@ -172,145 +172,145 @@
base_style = None
def __init__(self, file, filename, match):
- LoaderWithComposites.__init__(self)
- self.file = file
- self.filename = filename
- self.match = match
- self.style = Style()
- if self.base_style is not None:
- self.prop_stack = PropertyStack(base=self.base_style.Duplicate())
- else:
- self.prop_stack = PropertyStack()
- self.messages = {}
+ LoaderWithComposites.__init__(self)
+ self.file = file
+ self.filename = filename
+ self.match = match
+ self.style = Style()
+ if self.base_style is not None:
+ self.prop_stack = PropertyStack(base=self.base_style.Duplicate())
+ else:
+ self.prop_stack = PropertyStack()
+ self.messages = {}
def get_prop_stack(self):
- stack = self.prop_stack
- if not self.style.IsEmpty():
- stack.load_AddStyle(self.style)
- stack.condense()
- if self.base_style is not None:
- self.prop_stack = PropertyStack(base =self.base_style.Duplicate())
- else:
- self.prop_stack = PropertyStack()
- self.style = Style()
- return stack
+ stack = self.prop_stack
+ if not self.style.IsEmpty():
+ stack.load_AddStyle(self.style)
+ stack.condense()
+ if self.base_style is not None:
+ self.prop_stack = PropertyStack(base =self.base_style.Duplicate())
+ else:
+ self.prop_stack = PropertyStack()
+ self.style = Style()
+ return stack
def set_prop_stack(self, stack):
self.prop_stack = stack
def document(self, *args, **kw):
- self.begin_composite(doc_class, args, kw)
+ self.begin_composite(doc_class, args, kw)
def layer(self, *args, **kw):
- self.begin_layer_class(layer.Layer, args, kw)
+ self.begin_layer_class(layer.Layer, args, kw)
def end_layer(self):
- self.end_composite()
+ self.end_composite()
def begin_layer_class(self, layer_class, args, kw = None):
- if issubclass(self.composite_class, layer.Layer):
- self.end_composite()
- if issubclass(self.composite_class, doc_class):
- self.begin_composite(layer_class, args, kw)
- else:
- raise SketchLoadError('self.composite_class is %s, not a document',
- self.composite_class)
+ if issubclass(self.composite_class, layer.Layer):
+ self.end_composite()
+ if issubclass(self.composite_class, doc_class):
+ self.begin_composite(layer_class, args, kw)
+ else:
+ raise SketchLoadError('self.composite_class is %s, not a document',
+ self.composite_class)
def bezier(self, paths = None):
- self.append_object(PolyBezier(paths = paths,
- properties = self.get_prop_stack()))
+ self.append_object(PolyBezier(paths = paths,
+ properties = self.get_prop_stack()))
def rectangle(self, m11, m21, m12, m22, v1, v2, radius1 = 0, radius2 = 0):
- trafo = Trafo(m11, m21, m12, m22, v1, v2)
- self.append_object(Rectangle(trafo, radius1 = radius1,
- radius2 = radius2,
- properties = self.get_prop_stack()))
+ trafo = Trafo(m11, m21, m12, m22, v1, v2)
+ self.append_object(Rectangle(trafo, radius1 = radius1,
+ radius2 = radius2,
+ properties = self.get_prop_stack()))
def ellipse(self, m11, m21, m12, m22, v1, v2, start_angle = 0.0,
- end_angle = 0.0, arc_type = ArcPieSlice):
- self.append_object(Ellipse(Trafo(m11, m21, m12, m22, v1, v2),
- start_angle, end_angle, arc_type,
- properties = self.get_prop_stack()))
+ end_angle = 0.0, arc_type = ArcPieSlice):
+ self.append_object(Ellipse(Trafo(m11, m21, m12, m22, v1, v2),
+ start_angle, end_angle, arc_type,
+ properties = self.get_prop_stack()))
def simple_text(self, str, trafo = None, valign = text.ALIGN_BASE,
- halign = text.ALIGN_LEFT):
- if type(trafo) == TupleType:
- if len(trafo) == 2:
- trafo = apply(Translation, trafo)
- else:
- raise TypeError, "trafo must be a Trafo-object or a 2-tuple"
- self.append_object(text.SimpleText(text = str, trafo = trafo,
- valign = valign, halign = halign,
- properties = self.get_prop_stack()))
+ halign = text.ALIGN_LEFT):
+ if type(trafo) == TupleType:
+ if len(trafo) == 2:
+ trafo = apply(Translation, trafo)
+ else:
+ raise TypeError, "trafo must be a Trafo-object or a 2-tuple"
+ self.append_object(text.SimpleText(text = str, trafo = trafo,
+ valign = valign, halign = halign,
+ properties = self.get_prop_stack()))
def image(self, image, trafo):
- if type(trafo) == TupleType:
- if len(trafo) == 2:
- trafo = apply(Translation, trafo)
- else:
- raise TypeError, "trafo must be a Trafo-object or a 2-tuple"
+ if type(trafo) == TupleType:
+ if len(trafo) == 2:
+ trafo = apply(Translation, trafo)
+ else:
+ raise TypeError, "trafo must be a Trafo-object or a 2-tuple"
image = ImageData(image)
self.append_object(Image(image, trafo = trafo))
def begin_group(self, *args, **kw):
- self.begin_composite(group.Group, args, kw)
+ self.begin_composite(group.Group, args, kw)
def end_group(self):
- self.end_composite()
+ self.end_composite()
def guess_cont(self):
- self.guess_continuity = 1
+ self.guess_continuity = 1
def end_composite(self):
- isdoc = self.composite_class is doc_class
- LoaderWithComposites.end_composite(self)
- if isdoc:
- self.add_meta(self.object)
+ isdoc = self.composite_class is doc_class
+ LoaderWithComposites.end_composite(self)
+ if isdoc:
+ self.add_meta(self.object)
def add_meta(self, doc):
- doc.meta.fullpathname = self.filename
- dir, name = os.path.split(self.filename)
- doc.meta.directory = dir
- doc.meta.filename = name
- doc.meta.native_format = 0
- doc.meta.format_name = self.format_name
+ doc.meta.fullpathname = self.filename
+ dir, name = os.path.split(self.filename)
+ doc.meta.directory = dir
+ doc.meta.filename = name
+ doc.meta.native_format = 0
+ doc.meta.format_name = self.format_name
def add_message(self, message):
- pdebug(('load', 'echo_messages'), message)
- self.messages[message] = self.messages.get(message, 0) + 1
+ pdebug(('load', 'echo_messages'), message)
+ self.messages[message] = self.messages.get(message, 0) + 1
def Messages(self):
- messages = self.messages.items()
- list = []
- for message, count in messages:
- if count > 1:
- list.append(_("%(message)s (%(count)d times)") % locals())
- else:
- list.append(message)
- list.sort()
- return string.join(list, '\n')
+ messages = self.messages.items()
+ list = []
+ for message, count in messages:
+ if count > 1:
+ list.append(_("%(message)s (%(count)d times)") % locals())
+ else:
+ list.append(message)
+ list.sort()
+ return string.join(list, '\n')
class SimplifiedLoader(GenericLoader):
def __init__(self, file, filename, match):
- GenericLoader.__init__(self, file, filename, match)
- self.lineno = 1 # first line has been read
+ GenericLoader.__init__(self, file, filename, match)
+ self.lineno = 1 # first line has been read
def readline(self):
- line = self.file.readline()
- self.lineno = self.lineno + 1
- return line
+ line = self.file.readline()
+ self.lineno = self.lineno + 1
+ return line
def set_properties(self, **kw):
- style = self.style
- for key, value in kw.items():
- setattr(style, key, value)
+ style = self.style
+ for key, value in kw.items():
+ setattr(style, key, value)
def empty_line(self):
- self.style.line_pattern = EmptyPattern
+ self.style.line_pattern = EmptyPattern
def empty_fill(self):
- self.style.fill_pattern = EmptyPattern
+ self.style.fill_pattern = EmptyPattern
@@ -325,44 +325,44 @@
line = line + file.read(12 - len(line))
#print line
for info in plugins.import_plugins:
- match = info.rx_magic.match(line)
- if match:
- loader = info(file, filename, match)
- try:
- if do_profile:
- import profile
- warn(INTERNAL, 'profiling...')
- prof = profile.Profile()
- prof.runctx('loader.Load()', globals(), locals())
- prof.dump_stats(os.path.join(info.dir,
- info.module_name + '.prof'))
- warn(INTERNAL, 'profiling... (done)')
- doc = loader.object
- else:
+ match = info.rx_magic.match(line)
+ if match:
+ loader = info(file, filename, match)
+ try:
+ if do_profile:
+ import profile
+ warn(INTERNAL, 'profiling...')
+ prof = profile.Profile()
+ prof.runctx('loader.Load()', globals(), locals())
+ prof.dump_stats(os.path.join(info.dir,
+ info.module_name + '.prof'))
+ warn(INTERNAL, 'profiling... (done)')
+ doc = loader.object
+ else:
#t = time.clock()
- doc = loader.Load()
+ doc = loader.Load()
#print 'load in', time.clock() - t, 'sec.'
- messages = loader.Messages()
- if messages:
- doc.meta.load_messages = messages
- return doc
- finally:
- info.UnloadPlugin()
+ messages = loader.Messages()
+ if messages:
+ doc.meta.load_messages = messages
+ return doc
+ finally:
+ info.UnloadPlugin()
else:
- raise SketchLoadError(_("unrecognised file type"))
+ raise SketchLoadError(_("unrecognised file type"))
def load_drawing(filename):
if type(filename) == StringType:
- try:
- file = open(filename, 'r')
- except IOError, value:
- message = value.strerror
- raise SketchLoadError(_("Cannot open %(filename)s:\n%(message)s")
- % locals())
+ try:
+ file = open(filename, 'r')
+ except IOError, value:
+ message = value.strerror
+ raise SketchLoadError(_("Cannot open %(filename)s:\n%(message)s")
+ % locals())
else:
- # assume a file object. This does not happen at the moment and
- # SKLoder requires the filename for external objects.
- file = filename
- filename = ''
+ # assume a file object. This does not happen at the moment and
+ # SKLoder requires the filename for external objects.
+ file = filename
+ filename = ''
return load_drawing_from_file(file, filename)
Modified: skencil/branches/skencil-0.6/src/Sketch/Base/main.py
===================================================================
--- skencil/branches/skencil-0.6/src/Sketch/Base/main.py 2010-09-22 19:04:20 UTC (rev 725)
+++ skencil/branches/skencil-0.6/src/Sketch/Base/main.py 2010-09-22 19:13:59 UTC (rev 726)
@@ -77,40 +77,40 @@
# recognize a standard X geometry specification... (hack)
if '-geometry' in args:
- try:
- idx = args.index('-geometry')
- geo = args[idx:idx + 2]
- if len(geo) == 2:
- del args[idx:idx + 2]
- geo[0] = '-g'
- args[0:0] = geo
- except:
- pass
+ try:
+ idx = args.index('-geometry')
+ geo = args[idx:idx + 2]
+ if len(geo) == 2:
+ del args[idx:idx + 2]
+ geo[0] = '-g'
+ args[0:0] = geo
+ except:
+ pass
opts, args = getopt.getopt(args, 'd:g:hi',
- ['display=', 'geometry=', 'help', 'run-script=',
+ ['display=', 'geometry=', 'help', 'run-script=',
'version'])
# the option -i is a hack to allow sketch to be used as a `python
# interpreter' in the python shell in python-mode.el
options = util.Empty(args = args,
- display = None,
- geometry = None,
+ display = None,
+ geometry = None,
run_script = None)
for optchar, value in opts:
- if optchar == '-d' or optchar == '--display':
- options.display = value
- elif optchar == '-g' or optchar == '--geometry':
- options.geometry = value
+ if optchar == '-d' or optchar == '--display':
+ options.display = value
+ elif optchar == '-g' or optchar == '--geometry':
+ options.geometry = value
elif optchar == '--run-script':
options.run_script = value
- elif optchar == '-h' or optchar == '--help':
- print Sketch._(usage)
- sys.exit(0)
- elif optchar == '--version':
- print Sketch._(version) % Sketch.SketchVersion
- sys.exit(0)
+ elif optchar == '-h' or optchar == '--help':
+ print Sketch._(usage)
+ sys.exit(0)
+ elif optchar == '--version':
+ print Sketch._(version) % Sketch.SketchVersion
+ sys.exit(0)
return options
@@ -129,22 +129,22 @@
global application
try:
- options = process_args(sys.argv[1:])
+ options = process_args(sys.argv[1:])
except getopt.error:
- sys.stderr.write(Sketch._(usage))
- sys.exit(1)
+ sys.stderr.write(Sketch._(usage))
+ sys.exit(1)
if options.args:
- filename = options.args[0]
+ filename = options.args[0]
else:
- filename = ''
+ filename = ''
Sketch.init_ui()
from Sketch.UI.skapp import SketchApplication
application = SketchApplication(filename, options.display,
- options.geometry,
+ options.geometry,
run_script = options.run_script)
Sketch.Issue(None, Sketch.const.APP_INITIALIZED, application)
application.Run()
Modified: skencil/branches/skencil-0.6/src/Sketch/Base/plugins.py
===================================================================
--- skencil/branches/skencil-0.6/src/Sketch/Base/plugins.py 2010-09-22 19:04:20 UTC (rev 725)
+++ skencil/branches/skencil-0.6/src/Sketch/Base/plugins.py 2010-09-22 19:13:59 UTC (rev 726)
@@ -39,11 +39,11 @@
"""
names = split(package, '.')
for i in range(1, len(names) + 1):
- name = join(names[:i], '.')
- if not sys.modules.has_key(name):
- module = imp.new_module(name)
- module.__path__ = []
- sys.modules[name] = module
+ name = join(names[:i], '.')
+ if not sys.modules.has_key(name):
+ module = imp.new_module(name)
+ module.__path__ = []
+ sys.modules[name] = module
return sys.modules[name]
class ConfigInfo:
@@ -53,12 +53,12 @@
def __init__(self, module_name, dir, version = '1.0.0', unload = None,
load_immediately = 0, standard_messages = 0):
- self.module_name = module_name
- self.dir = dir
- self.unload = unload
+ self.module_name = module_name
+ self.dir = dir
+ self.unload = unload
self.load_immediately = load_immediately
- self.version = version
- self.plugin_list.append(self)
+ self.version = version
+ self.plugin_list.append(self)
self.standard_messages = standard_messages
if not self.standard_messages:
bindtextdomain(self.module_name, message_dir)
@@ -67,45 +67,45 @@
self.load_module()
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
+ 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
def UnloadPlugin(self):
- if self.unload:
- module_name = self.package + '.' + self.module_name
- try:
- module = sys.modules[module_name]
- except KeyError:
- # might happen if the module wasn't even loaded
- return
- self.module = None
- if type(self.unload) == type(""):
- getattr(module, self.unload)(module)
- else:
- name = module.__name__
- module.__dict__.clear()
- del sys.modules[name]
+ if self.unload:
+ module_name = self.package + '.' + self.module_name
+ try:
+ module = sys.modules[module_name]
+ except KeyError:
+ # might happen if the module wasn't even loaded
+ return
+ self.module = None
+ if type(self.unload) == type(""):
+ getattr(module, self.unload)(module)
+ else:
+ name = module.__name__
+ module.__dict__.clear()
+ del sys.modules[name]
def nls_function(self):
if self.standard_messages:
@@ -113,9 +113,9 @@
else:
domain = self.module_name
def _(text, domain = domain):
- #print domain, text
+ #print domain, text
result = dgettext(domain, text)
- #print '->', result
+ #print '->', result
return result
return _
@@ -135,37 +135,37 @@
plugin_list = import_plugins
def __init__(self, module_name, dir, rx_magic, class_name, format_name,
- tk_file_type = (), version = '1.0.0', unload = None,
+ tk_file_type = (), version = '1.0.0', unload = None,
load_immediately = 0, standard_messages = 0):
- ConfigInfo.__init__(self, module_name, dir, version = version,
- unload = unload,
+ ConfigInfo.__init__(self, module_name, dir, version = version,
+ unload = unload,
load_immediately = load_immediately,
standard_messages = standard_messages)
- self.rx_magic = re.compile(rx_magic)
- self.class_name = class_name
- self.format_name = format_name
- self.tk_file_type = tk_file_type
- self.translate()
+ self.rx_magic = re.compile(rx_magic)
+ self.class_name = class_name
+ self.format_name = format_name
+ self.tk_file_type = tk_file_type
+ self.translate()
def translate(self):
- name, ext = self.tk_file_type
- name = self.gettext(name)
- self.tk_file_type = name, ext
+ name, ext = self.tk_file_type
+ name = self.gettext(name)
+ self.tk_file_type = name, ext
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})
+ 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})
def UnloadPlugin(self):
- if config.preferences.unload_import_filters:
- ConfigInfo.UnloadPlugin(self)
+ if config.preferences.unload_import_filters:
+ ConfigInfo.UnloadPlugin(self)
export_plugins = []
export_formats = {}
@@ -175,57 +175,57 @@
plugin_list = export_plugins
def __init__(self, module_name, dir, format_name, tk_file_type = (),
- extensions = (), version = '1.0.0', unload = None,
+ extensions = (), version = '1.0.0', unload = None,
load_immediately = 0, standard_messages = 0):
- ConfigInfo.__init__(self, module_name, dir, version = version,
- unload = unload,
+ ConfigInfo.__init__(self, module_name, dir, version = version,
+ unload = unload,
load_immediately = load_immediately,
standard_messages = standard_messages)
- self.format_name = format_name
- self.tk_file_type = tk_file_type
- if type(extensions) != type(()):
- extensions = (extensions,)
- self.extensions = extensions
- export_formats[format_name] = self
+ self.format_name = format_name
+ self.tk_file_type = tk_file_type
+ if type(extensions) != type(()):
+ extensions = (extensions,)
+ self.extensions = extensions
+ export_formats[format_name] = self
def translate(self):
- name, ext = self.tk_file_type
- name = self.gettext(name)
- self.tk_file_type = name, ext
+ name, ext = self.tk_file_type
+ name = self.gettext(name)
+ self.tk_file_type = name, ext
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()
+ 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()
def UnloadPlugin(self):
- if config.preferences.unload_import_filters:
- ConfigInfo.UnloadPlugin(self)
+ if config.preferences.unload_import_filters:
+ ConfigInfo.UnloadPlugin(self)
def find_export_plugin(name):
return export_formats.get(name)
def guess_export_plugin(extension):
for plugin in export_plugins:
- if extension in plugin.extensions:
- return plugin.format_name
+ if extension in plugin.extensions:
+ return plugin.format_name
return ''
object_plugins = {}
@@ -238,35 +238,35 @@
version = '1.0.0', parameters = (), uses_selection = 0,
custom_dialog = '', load_immediately = 0,
standard_messages = 0):
- ConfigInfo.__init__(self, module_name, dir, version = version,
+ ConfigInfo.__init__(self, module_name, dir, version = version,
load_immediately = load_immediately,
standard_messages = standard_messages)
- self.class_name = class_name
+ self.class_name = class_name
self.factory = factory
- self.menu_text = menu_text
- self.parameters = parameters
+ self.menu_text = menu_text
+ self.parameters = parameters
self.uses_selection = uses_selection
self.custom_dialog = custom_dialog
- object_plugins[class_name] = self
- self.translate()
+ object_plugins[class_name] = self
+ self.translate()
def translate(self):
- gettext = self.gettext
- self.menu_text = gettext(self.menu_text)
- parameters = []
- for parameter in self.parameters:
- parameters.append(parameter[:-1] + (gettext(parameter[-1]),))
- self.parameters = parameters
+ gettext = self.gettext
+ self.menu_text = gettext(self.menu_text)
+ parameters = []
+ for parameter in self.parameters:
+ parameters.append(parameter[:-1] + (gettext(parameter[-1]),))
+ self.parameters = parameters
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})
+ 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})
def Constructor(self):
return self.load_module_attr(self.class_name)
@@ -281,7 +281,7 @@
__call__ = CallFactory
def HasParameters(self):
- return len(self.parameters)
+ return len(self.parameters)
def UsesSelection(self):
return self.uses_selection
@@ -300,7 +300,7 @@
config_types = {'Import': ImportInfo,
'Export': ExportInfo,
- 'PluginCompound': PluginCompoundInfo
+ 'PluginCompound': PluginCompoundInfo
}
@@ -310,27 +310,27 @@
file = open(file, 'r')
cfg = []
for line in file.readlines():
- if rx_end.match(line):
- break
- elif cfg or rx_start.match(line):
- if line[0] == '#':
- line = line[1:]
- if line[-2] == '\\':
- line = line[:-2]
- cfg.append(line)
+ if rx_end.match(line):
+ break
+ elif cfg or rx_start.match(line):
+ if line[0] == '#':
+ line = line[1:]
+ if line[-2] == '\\':
+ line = line[:-2]
+ cfg.append(line)
return join(cfg, '')
def _search_dir(dir, recurse, package = 'Sketch.Plugins'):
try:
- files = os.listdir(dir)
+ files = os.listdir(dir)
except os.error, value:
- warn(USER, _("Cannot list directory %(filename)s\n%(message)s"),
- filename = dir, message = value[1])
- return
+ warn(USER, _("Cannot list directory %(filename)s\n%(message)s"),
+ filename = dir, message = value[1])
+ return
for file in files:
- filename = os.path.join(dir, file)
+ filename = os.path.join(dir, file)
if os.path.isdir(filename):
if file == "Lib":
# A Lib directory on the plugin path. It's assumed to
@@ -344,49 +344,49 @@
# an ordinary directory and we should recurse into it to
# find more modules, so do that.
_search_dir(filename, recurse - 1, package + '.' + file)
- elif filename[-3:] == '.py':
- 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)
+ elif filename[-3:] == '.py':
+ 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()
+ 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:
- recurse = 1
- else:
- recurse = 0
- _search_dir(dir, recurse)
+ # XXX unix specific
+ if len(dir) >= 2 and dir[-1] == '/':
+ if dir[-2] == '/':
+ recurse = -1
+ else:
+ recurse = 1
+ else:
+ recurse = 0
+ _search_dir(dir, recurse)
if __debug__:
- pdebug('timing', 'time to scan cfg files: %g', time.clock()-start)
+ pdebug('timing', 'time to scan cfg files: %g', time.clock()-start)
# rearrange import plugins to ensure that native format is first
for loader in import_plugins:
- if loader.format_name == NativeFormat:
- import_plugins.remove(loader)
- import_plugins.insert(0, loader)
+ if loader.format_name == NativeFormat:
+ import_plugins.remove(loader)
+ import_plugins.insert(0, loader)
Subscribe(const.INITIALIZE, load_plugin_configuration)
Modified: skencil/branches/skencil-0.6/src/Sketch/Base/skexceptions.py
===================================================================
--- skencil/branches/skencil-0.6/src/Sketch/Base/skexceptions.py 2010-09-22 19:04:20 UTC (rev 725)
+++ skencil/branches/skencil-0.6/src/Sketch/Base/skexceptions.py 2010-09-22 19:13:59 UTC (rev 726)
@@ -30,6 +30,6 @@
class SketchIOError(SketchError):
def __init__(self, errno, strerror, filename = ''):
- self.errno = errno
- self.strerror = strerror
- self.filename = filename
+ self.errno = errno
+ self.strerror = strerror
+ self.filename = filename
Modified: skencil/branches/skencil-0.6/src/Sketch/Base/undo.py
===================================================================
--- skencil/branches/skencil-0.6/src/Sketch/Base/undo.py 2010-09-22 19:04:20 UTC (rev 725)
+++ skencil/branches/skencil-0.6/src/Sketch/Base/undo.py 2010-09-22 19:13:59 UTC (rev 726)
@@ -36,24 +36,24 @@
# execute a single undoinfo
func = info[0]
if type(func) == StringType:
- text = func
- func = info[1]
- args = info[2:]
+ text = func
+ func = info[1]
+ args = info[2:]
else:
- args = info[1:]
- text = None
+ 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
+ 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)
-
+ warn(INTERNAL, 'Exception in undo:\ninfo: %s\nfunc: %s\nargs: %s',
+ info, func, args)
+ warn_tb(INTERNAL)
+
def UndoList(infos):
undoinfo = map(Undo, infos)
undoinfo.reverse()
@@ -61,28 +61,28 @@
def _get_callable(info):
if type(info[0]) == StringType:
- return info[1]
+ return info[1]
return info[0]
def CreateListUndo(infos):
infos.reverse()
undolist = []
for info in infos:
- if info is NullUndo:
- continue
- if info[0] is UndoList:
+ if info is NullUndo:
+ continue
+ if info[0] is UndoList:
undolist[len(undolist):] = list(info[-1])
- else:
- undolist.append(info)
+ else:
+ undolist.append(info)
if undolist:
- if len(undolist) == 1:
- return undolist[0]
- return (UndoList, undolist)
+ if len(undolist) == 1:
+ return undolist[0]
+ return (UndoList, undolist)
return NullUndo
def CreateMultiUndo(*infos):
if len(infos) > 1:
- return CreateListUndo(list(infos))
+ return CreateListUndo(list(infos))
return infos[0]
@@ -103,24 +103,24 @@
# Check whether INFO has the correct format for undoinfo. Raise
# UndoTypeError if the format is invalid.
if type(info) != TupleType:
- raise UndoTypeError("undo info is not a tuple (%s, type %s)"
- % (info, type(info)))
+ raise UndoTypeError("undo info is not a tuple (%s, type %s)"
+ % (info, type(info)))
if len(info) < 1:
- raise UndoTypeError("undo info is empty tuple")
+ raise UndoTypeError("undo info is empty tuple")
f = info[0]
if type(f) == StringType:
- if len(info) > 1:
- f = info[1]
+ if len(info) > 1:
+ f = info[1]
if not callable(f):
- raise UndoTypeError("undo info has no callable item")
+ raise UndoTypeError("undo info has no callable item")
def check_info_silently(info):
# Return true if INFO is valid undo information, false otherwise.
try:
- check_info(info)
- return 1
+ check_info(info)
+ return 1
except UndoTypeError:
- return 0
+ return 0
class UndoRedo:
@@ -134,94 +134,94 @@
# last save or not.
undo_count = 0
-
+
def __init__(self):
- self.undoinfo = []
- self.redoinfo = []
- self.SetUndoLimit(preferences.undo_limit)
- if not self.undo_count:
- self.undo_count = 0
+ self.undoinfo = []
+ self.redoinfo = []
+ self.SetUndoLimit(preferences.undo_limit)
+ if not self.undo_count:
+ self.undo_count = 0
def SetUndoLimit(self, undo_limit):
- if undo_limit is None:
- # unlimited undo. approximate by choosing a very large number
- undo_limit = maxint
- if undo_limit >= 1:
- self.max_undo = undo_limit
- else:
- self.max_undo = 1
+ if undo_limit is None:
+ # unlimited undo. approximate by choosing a very large number
+ undo_limit = maxint
+ if undo_limit >= 1:
+ self.max_undo = undo_limit
+ else:
+ self.max_undo = 1
def CanUndo(self):
- # Return true, iff an undo operation can be performed.
- return len(self.undoinfo) > 0
+ # Return true, iff an undo operation can be performed.
+ return len(self.undoinfo) > 0
def CanRedo(self):
- # Return true, iff a redo operation can be performed.
- return len(self.redoinfo) > 0
+ # Return true, iff a redo operation can be performed.
+ return len(self.redoinfo) > 0
def Undo(self):
- # If undo info is available, perform a single undo and add the
- # redo info to the redo list. Also, decrement the undo count.
- if len(self.undoinfo) > 0:
- self.add_redo(Undo(self.undoinfo[0]))
- del self.undoinfo[0]
- self.undo_count = self.undo_count - 1
+ # If undo info is available, perform a single undo and add the
+ # redo info to the redo list. Also, decrement the undo count.
+ if len(self.undoinfo) > 0:
+ self.add_redo(Undo(self.undoinfo[0]))
+ del self.undoinfo[0]
+ self.undo_count = self.undo_count - 1
def AddUndo(self, info, clear_redo = 1):
- # Add the undo info INFO to the undo list. If the undo list is
- # longer than self.max_undo, discard the excessive undo info.
- # Also increment the undo count and discard all redo info.
- #
- # The flag CLEAR_REDO is used for internal purposes and inhibits
- # clearing the redo info if it is false. This flag is only used
- # by the Redo method. Code outside of this class should not use
- # this parameter.
- check_info(info)
- if info:
- self.undoinfo.insert(0, info)
- self.undo_count = self.undo_count + 1
- if len(self.undoinfo) > self.max_undo:
- del self.undoinfo[self.max_undo:]
- if clear_redo:
- self.redoinfo = []
+ # Add the undo info INFO to the undo list. If the undo list is
+ # longer than self.max_undo, discard the excessive undo info.
+ # Also increment the undo count and discard all redo info.
+ #
+ # The flag CLEAR_REDO is used for internal purposes and inhibits
+ # clearing the redo info if it is false. This flag is only used
+ # by the Redo method. Code outside of this class should not use
+ # this parameter.
+ check_info(info)
+ if info:
+ self.undoinfo.insert(0, info)
+ self.undo_count = self.undo_count + 1
+ if len(self.undoinfo) > self.max_undo:
+ del self.undoinfo[self.max_undo:]
+ if clear_redo:
+ self.redoinfo = []
def Redo(self):
- # If redo info is available, perform a single redo and add the
- # undo info to the undo list. The undo count is taken care of by
- # the AddUndo method.
- if len(self.redoinfo) > 0:
- self.AddUndo(Undo(self.redoinfo[0]), 0)
- del self.redoinfo[0]
+ # If redo info is available, perform a single redo and add the
+ # undo info to the undo list. The undo count is taken care of by
+ # the AddUndo method.
+ if len(self.redoinfo) > 0:
+ self.AddUndo(Undo(self.redoinfo[0]), 0)
+ del self.redoinfo[0]
def add_redo(self, info):
- # Internal method: add a single redo info
- check_info(info)
- self.redoinfo.insert(0, info)
+ # Internal method: add a single redo info
+ check_info(info)
+ self.redoinfo.insert(0, info)
def UndoText(self):
- # Return a string to describe the operation that would be undone
- # next, in a format suitable for a menu entry.
- if self.undoinfo:
- undolabel = self.undoinfo[0][0]
- if type(undolabel) == StringType:
- return _("Undo %s") % undolabel
- return _("Undo")
+ # Return a string to describe the operation that would be undone
+ # next, in a format suitable for a menu entry.
+ if self.undoinfo:
+ undolabel = self.undoinfo[0][0]
+ if type(undolabel) == StringType:
+ return _("Undo %s") % undolabel
+ return _("Undo")
def RedoText(self):
- # Return a string to describe the operation that would be redone
- # next, in a format suitable for a menu entry.
- if self.redoinfo:
- redolabel = self.redoinfo[0][0]
- if type(redolabel) == StringType:
- return _("Redo %s") % redolabel
- return _("Redo")
+ # Return a string to describe the operation that would be redone
+ # next, in a format suitable for a menu entry.
+ if self.redoinfo:
+ redolabel = self.redoinfo[0][0]
+ if type(redolabel) == StringType:
+ return _("Redo %s") % redolabel
+ return _("Redo")
def Reset(self):
- # Forget all undo/redo information
- self.__init__()
+ # Forget all undo/redo information
+ self.__init__()
def ResetUndoCount(self):
- self.undo_count = 0
+ self.undo_count = 0
def UndoCount(self):
- return self.undo_count
+ return self.undo_count
Modified: skencil/branches/skencil-0.6/src/Sketch/Base/undodict.py
===================================================================
--- skencil/branches/skencil-0.6/src/Sketch/Base/undodict.py 2010-09-22 19:04:20 UTC (rev 725)
+++ skencil/branches/skencil-0.6/src/Sketch/Base/undodict.py 2010-09-22 19:13:59 UTC (rev 726)
@@ -26,55 +26,55 @@
class UndoDict:
def __init__(self):
- self.dict = {}
+ self.dict = {}
def __getitem__(self, key):
- return self.dict[key]
+ return self.dict[key]
def __len__(self):
- return len(self.dict)
-
+ return len(self.dict)
+
def keys(self):
- return self.dict.keys()
+ return self.dict.keys()
def items(self):
- return self.dict.items()
+ return self.dict.items()
def values(self):
- return self.dict.values()
-
+ return self.dict.values()
+
def has_key(self, key):
- return self.dict.has_key(key)
+ return self.dict.has_key(key)
def SetItem(self, key, item):
- # Add ITEM to self using KEY.
- #
- # Two cases:
- #
- # 1. ITEM is stored in self under item.Name(): Store it under
- # KEY, rename ITEM and remove the old entry.
- #
- # 2. ITEM is not stored in self: Store it under KEY and rename
- # ITEM.
- if self.dict.has_key(key):
- if self.dict[key] is item:
- return NullUndo
- # name conflict
- raise ValueError, '%s already used' % key
- oldname = item.Name()
- if self.dict.has_key(oldname):
- del self.dict[oldname]
- undo = (self.SetItem, oldname, item)
- else:
- undo = (self.DelItem, key)
- item.SetName(key)
- self.dict[key] = item
- return undo
+ # Add ITEM to self using KEY.
+ #
+ # Two cases:
+ #
+ # 1. ITEM is stored in self under item.Name(): Store it under
+ # KEY, rename ITEM and remove the old entry.
+ #
+ # 2. ITEM is not stored in self: Store it under KEY and rename
+ # ITEM.
+ if self.dict.has_key(key):
+ if self.dict[key] is item:
+ return NullUndo
+ # name conflict
+ raise ValueError, '%s already used' % key
+ oldname = item.Name()
+ if self.dict.has_key(oldname):
+ del self.dict[oldname]
+ undo = (self.SetItem, oldname, item)
+ else:
+ undo = (self.DelItem, key)
+ item.SetName(key)
+ self.dict[key] = item
+ return undo
def DelItem(self, key):
- item = self.dict[key]
- del self.dict[key]
- return (self.SetItem, key, item)
+ item = self.dict[key]
+ del self.dict[key]
+ return (self.SetItem, key, item)
-
-
+
+
Modified: skencil/branches/skencil-0.6/src/Sketch/Base/warn.py
===================================================================
--- skencil/branches/skencil-0.6/src/Sketch/Base/warn.py 2010-09-22 19:04:20 UTC (rev 725)
+++ skencil/branches/skencil-0.6/src/Sketch/Base/warn.py 2010-09-22 19:13:59 UTC (rev 726)
@@ -30,106 +30,106 @@
def write_error(message):
sys.stderr.write(message)
if message and message[-1] != '\n':
- sys.stderr.write('\n')
+ sys.stderr.write('\n')
def flexible_format(format, args, kw):
try:
- if args:
- text = format % args
- elif kw:
- text = format % kw
- else:
- text = format
+ if args:
+ text = format % args
+ elif kw:
+ text = format % kw
+ else:
+ text = format
except TypeError:
- if args:
- text = string.join([format] + map(str, args))
- elif kw:
- text = string.join([format] + map(str, kw.items()))
- else:
- text = format
-
+ if args:
+ text = string.join([format] + map(str, args))
+ elif kw:
+ text = string.join([format] + map(str, kw.items()))
+ else:
+ text = format
+
return text
-
+
def warn(_level, _message, *args, **kw):
_message = flexible_format(_message, args, kw)
if _level == INTERNAL:
- if config.preferences.print_internal_warnings:
- write_error(_message)
+ if config.preferences.print_internal_warnings:
+ write_error(_message)
else:
- app = main.application
+ app = main.application
if app and config.preferences.warn_method == 'dialog':
- app.MessageBox(title = _("Warning"), message = _message,
- icon = 'warning')
- else:
- write_error(_message)
+ app.MessageBox(title = _("Warning"), message = _message,
+ icon = 'warning')
+ else:
+ write_error(_message)
return _message
def warn_tb(_level, _message = '', *args, **kw):
_message = flexible_format(_message, args, kw)
if _level == INTERNAL:
- if config.preferences.print_internal_warnings:
- write_error(_message)
- traceback.print_exc()
+ if config.preferences.print_internal_warnings:
+ write_error(_message)
+ traceback.print_exc()
else:
- app = main.application
- if app:
- tb = _("Print Traceback")
- result = app.MessageBox(title = _("Warning"), message = _message,
- icon = 'warning', buttons = (_("OK"), tb))
- if result == tb:
- from cStringIO import StringIO
- file = StringIO()
- traceback.print_exc(file = file)
- _message = file.getvalue()
- app.MessageBox(title = _("Traceback"), message = _message,
- icon = 'warning')
- else:
- write_error(_message)
- traceback.print_exc()
+ app = main.application
+ if app:
+ tb = _("Print Traceback")
+ result = app.MessageBox(title = _("Warning"), message = _message,
+ icon = 'warning', buttons = (_("OK"), tb))
+ if result == tb:
+ from cStringIO import StringIO
+ file = StringIO()
+ traceback.print_exc(file = file)
+ _message = file.getvalue()
+ app.MessageBox(title = _("Traceback"), message = _message,
+ icon = 'warning')
+ else:
+ write_error(_message)
+ traceback.print_exc()
return _message
-
+
def Dict(**kw):
return kw
_levels = Dict(default = 1,
- __del__ = 0,
- Graphics = 1,
+ __del__ = 0,
+ Graphics = 1,
properties = 0,
- DND = 1,
+ DND = 1,
context_menu = 0,
- Load = Dict(default = 1,
- PSK = 1,
- AI = 1,
+ Load = Dict(default = 1,
+ PSK = 1,
+ AI = 1,
echo_messages = 1),
- PS = 1,
- bezier = 1,
- styles = 1,
- tkext = 0,
- handles = 0,
- timing = 0)
+ PS = 1,
+ bezier = 1,
+ styles = 1,
+ tkext = 0,
+ handles = 0,
+ timing = 0)
def pdebug(level, message, *args, **kw):
if not config.preferences.print_debug_messages:
return
if level:
- if type(level) == StringType:
- level = (level,)
- enabled = _levels
- for item in level:
- try:
- enabled = enabled[item]
- except:
- break
- if type(enabled) == DictionaryType:
- enabled = enabled['default']
- if not enabled:
- return
+ if type(level) == StringType:
+ level = (level,)
+ enabled = _levels
+ for item in level:
+ try:
+ enabled = enabled[item]
+ except:
+ break
+ if type(enabled) == DictionaryType:
+ enabled = enabled['default']
+ if not enabled:
+ return
message = flexible_format(message, args, kw)
write_error(message)
More information about the Skencil-commits
mailing list