def main(): global application try: options = process_args(sys.argv[1:]) except getopt.error: sys.stderr.write(Sketch._(usage)) sys.exit(1) if options.args: filename = options.args[0] else: filename = '' Sketch.init_ui() from Sketch.UI.skapp import SketchApplication application = SketchApplication(filename, options.display, options.geometry, run_script=options.run_script) setattr(Sketch.main, 'application', application) Sketch.Issue(None, Sketch.const.APP_INITIALIZED, application) application.Run() application.SavePreferences()
def main(): import Sketch, Sketch.config Sketch.Issue(None, Sketch.const.INITIALIZE) #plugins.load_plugin_configuration(config.plugin_path) use_bbox = 0 resolution = 72.0 steps = alpha = None import getopt opts, args = getopt.getopt( sys.argv[1:], 'bhr:s:A:', ['help', 'bbox', 'resolution=', 'gradient-steps=', 'alpha-bits=']) for optchar, value in opts: if optchar == '-h' or optchar == '--help': print_usage() return -1 elif optchar == '-b' or optchar == '--bbox': use_bbox = 1 elif optchar == '-r' or optchar == '--resolution': resolution = float(value) elif optchar == '-s' or optchar == '--gradient-steps': steps = float(value) elif optchar == '-A' or optchar == '--alpha-bits': alpha = int(value) if alpha not in (1, 2, 4): sys.stderr.write("sk2ppm: alpha-bits value must be one of" " 1, 2 or 4\n") return -1 if len(args) not in (1, 2): print_usage() return -1 if steps is not None: Sketch.config.preferences.gradient_steps_print = steps filename = args[0] if len(args) > 1: ppmfile = args[1] else: ppmfile = sys.stdout doc = load.load_drawing(filename) context = Context() context.document = doc export_raster(context, ppmfile, resolution, use_bbox, format="ppm", antialias=alpha)
def PythonPrompt(prompt='>>>', prompt2='...'): # try to import readline in Python 1.5 have_readline = 0 try: import readline have_readline = 1 Sketch.Issue(None, Sketch.const.INIT_READLINE) except ImportError: pass globals = {} # put all of Sketch.main and Sketch into the globals exec 'from Sketch.main import *' in globals exec 'from Sketch import *' in globals # put all sketch specific modules into the globals for module in get_sketch_modules(): globals[module.__name__] = module add_sketch_objects(globals) if have_readline: from Sketch.Lib import skcompleter skcompleter.install(globals, locals) while 1: try: cmd = raw_input(prompt) #cmd = string.strip(cmd) if cmd: if cmd[-1] == ':': # a compound statement lines = [] while string.strip(cmd): lines.append(cmd) cmd = raw_input(prompt2) cmd = string.join(lines + [''], '\n') kind = 'exec' else: kind = 'single' c = compile(cmd, '<string>', kind) exec c in globals, locals except EOFError: print '----- returning to Sketch' return except: import traceback traceback.print_tb(sys.exc_traceback) print 'Exception %s: %s' % (sys.exc_type, sys.exc_value)