示例#1
0
 def __init__(self):
     """
     Connects main window and output window for errors.
     """
     self.outputWindow = Window((400, 300), minSize=(1, 1), closable=True)
     self.outputWindow.outputView = OutPutEditor((0, 0, -0, -0),
                                                 readOnly=True)
     self.window = Window((800, 600), minSize=(1, 1), closable=True)
     self.window.drawView = DrawView((0, 32, -0, -0))
     self.scriptPath = None
     self.scriptFileName = None
     self.scriptName = None
     self.initialize()
     self.window.open()
     self.outputWindow.open()
示例#2
0
    def __init__(self):
        """Connects main window and output window for errors."""

        for path in getFontPaths():
            name = path.split('/')[-1]
            self.FONTS.append(name)

        self.font = findFont(self.FONTS[0])
        self.context = getContext()
        self.window = Window((800, 600), minSize=(1, 1), closable=True)
        self.window.drawView = DrawView((0, 32, -0, -0))
        self.outputWindow = Window((400, 300), minSize=(1, 1), closable=True)
        self.outputWindow.outputView = OutPutEditor((0, 0, -0, -0), readOnly=True)
        self.initialize()
        self.window.open()
        self.outputWindow.open()
	def init(self):
		self = super(GlyphsDrawBotController, self).init()
		document = None
		# make a window
		self.w = Window((400, 400), "DrawBot", minSize=(200, 200), textured=False)
		# setting previously stored frames, if any
		self.w.getNSWindow().setFrameUsingName_(self.windowAutoSaveName)
		_NSWindow = self.w.getNSWindow()
		self.setWindow_(_NSWindow)
		_NSWindow.setDelegate_(self)
		_NSWindow.setContentBorderThickness_forEdge_(27, 1)
		try:
			# on 10.7+ full screen support
			self.w.getNSWindow().setCollectionBehavior_(128)  # NSWindowCollectionBehaviorFullScreenPrimary
		except:
			pass

		# the code editor
		self.codeView = CodeEditor((0, 0, -0, -0))
		self.codeView.getNSTextView().bind_toObject_withKeyPath_options_("value", self, "document.text", {NSContinuouslyUpdatesValueBindingOption:True})
		scrollview = self.codeView.getNSTextView().enclosingScrollView()
		scrollview.setBorderType_(0)
		
		# the output view (will catch all stdout and stderr)
		self.outPutView = OutPutEditor((0, 0, -0, -0), readOnly=True)
		scrollview = self.outPutView.getNSTextView().enclosingScrollView()
		scrollview.setBorderType_(0)
		
		# the view to draw in
		self.drawView = DrawView((0, 0, -0, -0))
		pdfView = self.drawView.getNSView()
		view = pdfView.documentView()
		# the view with all thumbnails
		self.thumbnails = ThumbnailView((0, 0, -0, -0))
		# connect the thumbnail view with the draw view
		self.thumbnails.setDrawView(self.drawView)

		# collect all code text view in a splitview
		paneDescriptors = [
			dict(view=self.codeView, identifier="codeView", minSize=50, canCollapse=False),
			dict(view=self.outPutView, identifier="outPutView", size=100, minSize=50, canCollapse=False),
		]
		self.codeSplit = SplitView((0, 0, -0, -0), paneDescriptors, isVertical=False)

		# collect the draw scroll view and the code split view in a splitview
		paneDescriptors = [
			dict(view=self.thumbnails, identifier="thumbnails", minSize=100, size=100, maxSize=100),
			dict(view=self.drawView, identifier="drawView", minSize=50),
			dict(view=self.codeSplit, identifier="codeSplit", minSize=50, canCollapse=False),
		]
		self.w.split = SplitView((0, 0, -0, -27), paneDescriptors)
		
		self.w.runButton = Button((-67, -24, 50, 20), "Run", callback=self.runButtonAction_)
		self.w.runButton.bind("\r", ["command"])
		self.w.runButton._nsObject.setToolTip_(u"Run the script (cmd+\u23CE)")
		
		self.w.clearButton = Button((-135, -24, 58, 20), "Clear", callback=self.clearButtonAction_)
		self.w.clearButton.bind("k", ["command"])
		self.w.clearButton._nsObject.setToolTip_(u"Clear Log (cmd+K)")
		
		# get the real size of the window
		windowX, windowY, windowWidth, windowHeight = self.w.getPosSize()
		# set the split view dividers at a specific position based on the window size
		self.w.split.setDividerPosition(0, 0)
		self.w.split.setDividerPosition(1, windowWidth * .6)
		self.w.split.setDividerPosition(1, windowWidth * .6)
		self.codeSplit.setDividerPosition(0, windowHeight * .7)
		
		return self
示例#4
0
    script = 'fill(random(), random(), random())\nrect(10+random()*100, 10+random()*100, 200, 300)'
    newDrawing()
    namespace = DrawBotNamespace(_drawBotDrawingTool,
                                 _drawBotDrawingTool._magicVariables)
    _drawBotDrawingTool._addToNamespace(namespace)

    # Creates a new standard output, catching all print statements and tracebacks.
    stdout = StdOutput(output, outputView=outputWindow.outputView)
    stderr = StdOutput(output,
                       isError=True,
                       outputView=outputWindow.outputView)

    # Calls DrawBot's ScriptRunner with above parameters.
    ScriptRunner(script,
                 None,
                 namespace=namespace,
                 stdout=stdout,
                 stderr=stderr)
    _drawBotDrawingTool._drawInContext(context)
    pdfDocument = _drawBotDrawingTool.pdfImage()


if __name__ == '__main__':

    w = Window((10, 10, 400, 200), 'Window')
    w.button = Button((20, 20, 100, 30), 'Hit', callback=hitCallback)
    w.open()

    outputWindow = Window((500, 10, 400, 300), minSize=(1, 1), closable=True)
    outputWindow.outputView = OutPutEditor((0, 0, -0, -0), readOnly=True)
    outputWindow.open()