From cdf38fb4d512298c651b57055aaa57fa95a92063 Mon Sep 17 00:00:00 2001 From: justvanrossum Date: Wed, 8 Nov 2017 18:05:12 +0100 Subject: [PATCH] various py3 changes; should all still work on py2.7, too --- DrawBot.py | 4 +-- drawBot/__init__.py | 4 ++- drawBot/context/__init__.py | 14 ++++---- drawBot/context/baseContext.py | 26 +++++++++------ drawBot/context/drawBotContext.py | 4 ++- drawBot/context/dummyContext.py | 4 ++- drawBot/context/gifContext.py | 6 ++-- drawBot/context/imageContext.py | 4 ++- drawBot/context/movContext.py | 4 ++- drawBot/context/pdfContext.py | 15 ++++++--- drawBot/context/printContext.py | 46 ++++++++++++++------------ drawBot/context/svgContext.py | 9 ++++-- drawBot/drawBotDrawingTools.py | 41 +++++++++++++++-------- drawBot/scriptTools.py | 6 ++-- drawBot/ui/codeEditor.py | 28 +++++++++++++--- drawBot/ui/debug.py | 4 ++- drawBot/ui/drawBotController.py | 8 +++-- drawBot/ui/lineNumberRulerView.py | 2 +- drawBot/ui/preferencesController.py | 4 ++- drawBot/updater.py | 13 +++++--- setup.py | 50 +++++++++++++++-------------- 21 files changed, 188 insertions(+), 108 deletions(-) diff --git a/DrawBot.py b/DrawBot.py index 39b54b37..6d32578d 100644 --- a/DrawBot.py +++ b/DrawBot.py @@ -102,7 +102,7 @@ class DrawBotAppDelegate(AppKit.NSObject): def init(self): self = super(DrawBotAppDelegate, self).init() - code = stringToInt("GURL") + code = stringToInt(b"GURL") AppKit.NSAppleEventManager.sharedAppleEventManager().setEventHandler_andSelector_forEventClass_andEventID_(self, "getUrl:withReplyEvent:", code, code) return self @@ -146,7 +146,7 @@ def showDebug_(self, sender): def getUrl_withReplyEvent_(self, event, reply): import urlparse import urllib2 - code = stringToInt("----") + code = stringToInt(b"----") url = event.paramDescriptorForKeyword_(code) urlString = url.stringValue() documentController = AppKit.NSDocumentController.sharedDocumentController() diff --git a/drawBot/__init__.py b/drawBot/__init__.py index 4c4fa7e4..eb66c887 100644 --- a/drawBot/__init__.py +++ b/drawBot/__init__.py @@ -1,3 +1,5 @@ -from drawBotDrawingTools import _drawBotDrawingTool +from __future__ import absolute_import + +from .drawBotDrawingTools import _drawBotDrawingTool _drawBotDrawingTool._addToNamespace(globals()) diff --git a/drawBot/context/__init__.py b/drawBot/context/__init__.py index 52887f9a..e9f350cc 100644 --- a/drawBot/context/__init__.py +++ b/drawBot/context/__init__.py @@ -1,9 +1,11 @@ -from pdfContext import PDFContext -from imageContext import ImageContext -from gifContext import GifContext -from svgContext import SVGContext -from movContext import MOVContext -from printContext import PrintContext +from __future__ import absolute_import + +from .pdfContext import PDFContext +from .imageContext import ImageContext +from .gifContext import GifContext +from .svgContext import SVGContext +from .movContext import MOVContext +from .printContext import PrintContext allContexts = [PDFContext, ImageContext, SVGContext, MOVContext, PrintContext, GifContext] diff --git a/drawBot/context/baseContext.py b/drawBot/context/baseContext.py index 8a343900..491da9e7 100644 --- a/drawBot/context/baseContext.py +++ b/drawBot/context/baseContext.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import + import AppKit import CoreText import Quartz @@ -8,8 +10,8 @@ from drawBot.misc import DrawBotError, cmyk2rgb, warnings -from tools import openType -from tools import variation +from .tools import openType +from .tools import variation _FALLBACKFONT = "LucidaGrande" @@ -333,10 +335,11 @@ def setNSBezierPath(self, path): """ self._path = path - def pointInside(self, (x, y)): + def pointInside(self, xy): """ Check if a point `x`, `y` is inside a path. """ + x, y = xy return self._path.containsPoint_((x, y)) def bounds(self): @@ -930,7 +933,7 @@ def append(self, txt, **kwargs): existingOpenTypeFeatures = openType.getFeatureTagsForFontName(self._font) # sort features by their on/off state # set all disabled features first - orderedOpenTypeFeatures = sorted(self._openTypeFeatures.items(), key=lambda (k, v): v) + orderedOpenTypeFeatures = sorted(self._openTypeFeatures.items(), key=lambda kv: kv[1]) for featureTag, value in orderedOpenTypeFeatures: coreTextFeatureTag = featureTag if not value: @@ -1755,7 +1758,7 @@ def _transform(self, matrix): def _textBox(self, txt, box, align): pass - def _image(self, path, (x, y), alpha, pageNumber): + def _image(self, path, xy, alpha, pageNumber): pass def _frameDuration(self, seconds): @@ -1770,10 +1773,10 @@ def _saveImage(self, path, multipage): def _printImage(self, pdf=None): pass - def _linkDestination(self, name, (x, y)): + def _linkDestination(self, name, xy): pass - def _linkRect(self, name, (x, y, w, h)): + def _linkRect(self, name, xywh): pass # @@ -2185,7 +2188,8 @@ def textBox(self, txt, box, align="left"): self._state.path = None self._textBox(txt, box, align) - def image(self, path, (x, y), alpha, pageNumber): + def image(self, path, xy, alpha, pageNumber): + x, y = xy self._image(path, (x, y), alpha, pageNumber) def installFont(self, path): @@ -2218,8 +2222,10 @@ def _fontNameForPath(self, path): psName = psName.toUnicode() return psName - def linkDestination(self, name, (x, y)): + def linkDestination(self, name, xy): + x, y = xy self._linkDestination(name, (x, y)) - def linkRect(self, name, (x, y, w, h)): + def linkRect(self, name, xywh): + x, y, w, h = xywh self._linkRect(name, (x, y, w, h)) diff --git a/drawBot/context/drawBotContext.py b/drawBot/context/drawBotContext.py index 9678a7b9..74d205a8 100644 --- a/drawBot/context/drawBotContext.py +++ b/drawBot/context/drawBotContext.py @@ -1,6 +1,8 @@ +from __future__ import absolute_import + import Quartz -from pdfContext import PDFContext +from .pdfContext import PDFContext class DrawBotContext(PDFContext): diff --git a/drawBot/context/dummyContext.py b/drawBot/context/dummyContext.py index c0bb7491..0885a8b5 100644 --- a/drawBot/context/dummyContext.py +++ b/drawBot/context/dummyContext.py @@ -1,4 +1,6 @@ -from baseContext import BaseContext +from __future__ import absolute_import, print_function + +from .baseContext import BaseContext class DummyContext(BaseContext): diff --git a/drawBot/context/gifContext.py b/drawBot/context/gifContext.py index 12f6457b..abe68c37 100644 --- a/drawBot/context/gifContext.py +++ b/drawBot/context/gifContext.py @@ -1,11 +1,13 @@ +from __future__ import absolute_import + import AppKit import Quartz import tempfile -from imageContext import ImageContext +from .imageContext import ImageContext -from tools.gifTools import generateGif +from .tools.gifTools import generateGif class GifContext(ImageContext): diff --git a/drawBot/context/imageContext.py b/drawBot/context/imageContext.py index f1bab755..6728fc5a 100644 --- a/drawBot/context/imageContext.py +++ b/drawBot/context/imageContext.py @@ -1,9 +1,11 @@ +from __future__ import absolute_import + import AppKit import Quartz import os -from pdfContext import PDFContext +from .pdfContext import PDFContext class ImageContext(PDFContext): diff --git a/drawBot/context/movContext.py b/drawBot/context/movContext.py index 426c7e00..05a828fa 100644 --- a/drawBot/context/movContext.py +++ b/drawBot/context/movContext.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import + import AppKit import QTKit import Quartz @@ -5,7 +7,7 @@ import os from drawBot.misc import DrawBotError -from pdfContext import PDFContext +from .pdfContext import PDFContext class MOVContext(PDFContext): diff --git a/drawBot/context/pdfContext.py b/drawBot/context/pdfContext.py index 897dc543..771446d4 100644 --- a/drawBot/context/pdfContext.py +++ b/drawBot/context/pdfContext.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import + import platform from distutils.version import StrictVersion import AppKit @@ -6,9 +8,9 @@ import math -from tools import gifTools +from .tools import gifTools -from baseContext import BaseContext, FormattedString +from .baseContext import BaseContext, FormattedString from drawBot.misc import DrawBotError, isPDF, isGIF @@ -263,7 +265,8 @@ def _getImageSource(self, key, pageNumber): raise DrawBotError("No image found at %s" % key) return self._cachedImages[key] - def _image(self, path, (x, y), alpha, pageNumber): + def _image(self, path, xy, alpha, pageNumber): + x, y = xy self._save() _isPDF, image = self._getImageSource(path, pageNumber) if image is not None: @@ -382,7 +385,8 @@ def _rgbNSColorToCGColor(self, c): return Quartz.CGColorCreateGenericGray(c.whiteComponent(), c.alphaComponent()) return Quartz.CGColorCreateGenericRGB(c.redComponent(), c.greenComponent(), c.blueComponent(), c.alphaComponent()) - def _linkDestination(self, name, (x, y)): + def _linkDestination(self, name, xy): + x, y = xy if (x, y) == (None, None): x, y = self.width * 0.5, self.height * 0.5 x = max(0, min(x, self.width)) @@ -390,6 +394,7 @@ def _linkDestination(self, name, (x, y)): centerPoint = Quartz.CGPoint(x, y) Quartz.CGPDFContextAddDestinationAtPoint(self._pdfContext, name, centerPoint) - def _linkRect(self, name, (x, y, w, h)): + def _linkRect(self, name, xywh): + x, y, w, h = xywh rectBox = Quartz.CGRectMake(x, y, w, h) Quartz.CGPDFContextSetDestinationForRect(self._pdfContext, name, rectBox) diff --git a/drawBot/context/printContext.py b/drawBot/context/printContext.py index ef2030d9..abb4e30e 100644 --- a/drawBot/context/printContext.py +++ b/drawBot/context/printContext.py @@ -1,4 +1,6 @@ -from baseContext import BaseContext +from __future__ import absolute_import, print_function + +from .baseContext import BaseContext class PrintContext(BaseContext): @@ -6,46 +8,50 @@ class PrintContext(BaseContext): fileExtensions = ["*"] def _newPage(self, width, height): - print "newPage", width, height + print("newPage", width, height) def _save(self): - print "save" + print("save") def _restore(self): - print "restore" + print("restore") def _blendMode(self, operation): - print "blend mode", operation + print("blend mode", operation) def _drawPath(self): - print "drawPath", self._state.path + print("drawPath", self._state.path) def _clipPath(self): - print "clipPath", self._state.path + print("clipPath", self._state.path) def _transform(self, matrix): - print "transform", matrix + print("transform", matrix) - def _textBox(self, txt, (x, y, w, h), align): - print "textBox", txt, (x, y, w, h), align + def _textBox(self, txt, xywh, align): + x, y, w, h = xywh + print("textBox", txt, (x, y, w, h), align) - def _image(self, path, (x, y), alpha, pageNumber): - print "image", path, x, y, alpha, pageNumber + def _image(self, path, xy, alpha, pageNumber): + x, y = xy + print("image", path, x, y, alpha, pageNumber) def _frameDuration(self, seconds): - print "frameDuration", seconds + print("frameDuration", seconds) def _reset(self, other=None): - print "reset", other + print("reset", other) def _saveImage(self, path, multipage): - print "saveImage", path, multipage + print("saveImage", path, multipage) def _printImage(self, pdf=None): - print "printImage", pdf + print("printImage", pdf) - def _linkDestination(self, name, (x, y)): - print "linkDestination", name, (x, y) + def _linkDestination(self, name, xy): + x, y = xy + print("linkDestination", name, (x, y)) - def _linkRect(self, name, (x, y, w, h)): - print "linkRect", name, (x, y, w, h) \ No newline at end of file + def _linkRect(self, name, xywh): + x, y, w, h = xywh + print("linkRect", name, (x, y, w, h)) diff --git a/drawBot/context/svgContext.py b/drawBot/context/svgContext.py index 8436a198..93c025c8 100644 --- a/drawBot/context/svgContext.py +++ b/drawBot/context/svgContext.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import + import AppKit import CoreText @@ -10,8 +12,8 @@ from fontTools.misc.transform import Transform -from tools.openType import getFeatureTagsForFontAttributes -from baseContext import BaseContext, GraphicsState, Shadow, Color, FormattedString, Gradient +from .tools.openType import getFeatureTagsForFontAttributes +from .baseContext import BaseContext, GraphicsState, Shadow, Color, FormattedString, Gradient from drawBot.misc import warnings, formatNumber @@ -433,10 +435,11 @@ def _textBox(self, txt, box, align): self._svgContext.newline() self._svgEndClipPath() - def _image(self, path, (x, y), alpha, pageNumber): + def _image(self, path, xy, alpha, pageNumber): # todo: # support embedding of images when the source is not a path but # a nsimage or a pdf / gif with a pageNumber + x, y = xy self._svgBeginClipPath() if path.startswith("http"): url = AppKit.NSURL.URLWithString_(path) diff --git a/drawBot/drawBotDrawingTools.py b/drawBot/drawBotDrawingTools.py index bbfc7be3..a641645e 100644 --- a/drawBot/drawBotDrawingTools.py +++ b/drawBot/drawBotDrawingTools.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import + import AppKit import CoreText import Quartz @@ -6,14 +8,16 @@ import os import random -from context import getContextForFileExt -from context.baseContext import BezierPath, FormattedString -from context.dummyContext import DummyContext +from .context import getContextForFileExt +from .context.baseContext import BezierPath, FormattedString +from .context.dummyContext import DummyContext + +from .context.tools.imageObject import ImageObject +from .context.tools import gifTools -from context.tools.imageObject import ImageObject -from context.tools import gifTools +from .misc import DrawBotError, warnings, VariableController, optimizePath, isPDF, isEPS, isGIF -from misc import DrawBotError, warnings, VariableController, optimizePath, isPDF, isEPS, isGIF +from fontTools.misc.py23 import basestring def _getmodulecontents(module, names=None): @@ -58,7 +62,7 @@ def _deprecatedWarningWrapInTuple(txt): '10x14' : (720, 1008), } -for key, (w, h) in _paperSizes.items(): +for key, (w, h) in list(_paperSizes.items()): _paperSizes["%sLandscape" % key] = (h, w) @@ -388,7 +392,7 @@ def saveImage(self, paths, multipage=None): # save it as a png and pdf on the current users desktop saveImage(["~/Desktop/firstImage.png", "~/Desktop/firstImage.pdf"]) """ - if isinstance(paths, (str, unicode)): + if isinstance(paths, basestring): paths = [paths] for rawPath in paths: path = optimizePath(rawPath) @@ -503,10 +507,11 @@ def newpath(self): _deprecatedWarningLowercase("newPath()") self.newPath() - def moveTo(self, (x, y)): + def moveTo(self, xy): """ Move to a point `x`, `y`. """ + x, y = xy self._requiresNewFirstPage = True self._addInstruction("moveTo", (x, y)) @@ -514,10 +519,11 @@ def moveto(self, x, y): _deprecatedWarningLowercase("moveTo((%s, %s))" % (x, y)) self.moveTo((x, y)) - def lineTo(self, (x, y)): + def lineTo(self, xy): """ Line to a point `x`, `y`. """ + x, y = xy self._requiresNewFirstPage = True self._addInstruction("lineTo", (x, y)) @@ -525,11 +531,14 @@ def lineto(self, x, y): _deprecatedWarningLowercase("lineTo((%s, %s))" % (x, y)) self.lineTo((x, y)) - def curveTo(self, (x1, y1), (x2, y2), (x3, y3)): + def curveTo(self, xy1, xy2, xy3): """ Curve to a point `x3`, `y3`. With given bezier handles `x1`, `y1` and `x2`, `y2`. """ + x1, y1 = xy1 + x2, y2 = xy2 + x3, y3 = xy3 self._requiresNewFirstPage = True self._addInstruction("curveTo", (x1, y1), (x2, y2), (x3, y3)) @@ -544,10 +553,12 @@ def arc(self, center, radius, startAngle, endAngle, clockwise): self._requiresNewFirstPage = True self._addInstruction("arc", center, radius, startAngle, endAngle, clockwise) - def arcTo(self, (x1, y1), (x2, y2), radius): + def arcTo(self, xy1, xy2, radius): """ Arc from one point to an other point with a given `radius`. """ + x1, y1 = xy1 + x2, y2 = xy2 self._requiresNewFirstPage = True self._addInstruction("arcTo", (x1, y1), (x2, y2), radius) @@ -1905,7 +1916,7 @@ def imageSize(self, path, pageNumber=None): w, h = rep.size() return w, h - def imagePixelColor(self, path, (x, y)): + def imagePixelColor(self, path, xy): """ Return the color `r, g, b, a` of an image at a specified `x`, `y` possition. @@ -1940,6 +1951,7 @@ def imagePixelColor(self, path, (x, y)): # draw some text text("W", (x, y)) """ + x, y = xy if isinstance(path, (str, unicode)): path = optimizePath(path) bitmap = _chachedPixelColorBitmaps.get(path) @@ -2050,12 +2062,13 @@ def linkDestination(self, name, x=None, y=None): self._requiresNewFirstPage = True self._addInstruction("linkDestination", name, (x, y)) - def linkRect(self, name, (x, y, w, h)): + def linkRect(self, name, xywh): """ Add a rect for a link within a PDF. The link rectangle will be set independent of the current context transformations. """ + x, y, w, h = (x, y, w, h) self._requiresNewFirstPage = True self._addInstruction("linkRect", name, (x, y, w, h)) diff --git a/drawBot/scriptTools.py b/drawBot/scriptTools.py index 91a54e21..27f35fc1 100644 --- a/drawBot/scriptTools.py +++ b/drawBot/scriptTools.py @@ -13,6 +13,8 @@ from drawBot.misc import getDefault +from fontTools.misc.py23 import PY2 + class StdOutput(object): @@ -23,7 +25,7 @@ def __init__(self, output, isError=False, outputView=None): self._previousFlush = time.time() def write(self, data): - if isinstance(data, str): + if PY2 and isinstance(data, str): try: data = unicode(data, "utf-8", "replace") except UnicodeDecodeError: @@ -219,7 +221,7 @@ def __init__(self, text=None, path=None, stdout=None, stderr=None, namespace=Non if not checkSyntaxOnly: self._scriptDone = False try: - exec code in namespace + exec(code, namespace) except KeyboardInterrupt: pass except: diff --git a/drawBot/ui/codeEditor.py b/drawBot/ui/codeEditor.py index 8bbe2c09..30adba6e 100644 --- a/drawBot/ui/codeEditor.py +++ b/drawBot/ui/codeEditor.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import + import AppKit from keyword import kwlist @@ -16,8 +18,9 @@ hasJedi = False from vanilla import * +from vanilla.py23 import python_method -from lineNumberRulerView import NSLineNumberRuler +from .lineNumberRulerView import NSLineNumberRuler from drawBot.misc import getDefault, getFontDefault, getColorDefault, DrawBotError from drawBot.drawBotDrawingTools import _drawBotDrawingTool @@ -178,9 +181,9 @@ def _hexStringToNSColor(txt, default=AppKit.NSColor.blackColor()): def _NSColorToHexString(color): color = color.colorUsingColorSpaceName_(AppKit.NSCalibratedRGBColorSpace) - r = color.redComponent() * 255 - g = color.greenComponent() * 255 - b = color.blueComponent() * 255 + r = round(color.redComponent() * 255) + g = round(color.greenComponent() * 255) + b = round(color.blueComponent() * 255) return "#%02X%02X%02X" % (r, g, b) @@ -500,6 +503,7 @@ def resetHighLightSyntax(self): self._highlightSyntax(0, self.string()) self._ignoreProcessEditing = False + @python_method def _highlightSyntax(self, location, text): if self.lexer() is None: return @@ -784,6 +788,7 @@ def completionsForPartialWordRange_indexOfSelectedItem_(self, charRange, index): func = languageData.get("wordCompletions", self._genericCompletions) return func(text, charRange) + @python_method def _genericCompletions(self, text, charRange): partialString = text.substringWithRange_(charRange) keyWords = list() @@ -941,6 +946,7 @@ def uncommentFilter(lines): return commentedLines self._filterLines(uncommentFilter) + @python_method def _jumpToLine(self, lineNumber): lines = 1 string = self.string() @@ -1049,6 +1055,7 @@ def _updateRulersColors(self): backgroundColor = _hexStringToNSColor(styles.background_color, self._fallbackBackgroundColor) ruler.setRulerBackgroundColor_(backgroundColor) + @python_method def _deleteIndentation(self, sender, isForward, superFunc): selectedRange = self.selectedRange() if self.usesTabs() or selectedRange.length: @@ -1074,6 +1081,7 @@ def _deleteIndentation(self, sender, isForward, superFunc): else: superFunc(sender) + @python_method def _findMatchingParen(self, location, char, matchChar, end): add = 1 if end: @@ -1095,6 +1103,7 @@ def _findMatchingParen(self, location, char, matchChar, end): location += add return found + @python_method def _balanceParenForChar(self, char, location): if self.lexer() is None: return @@ -1108,6 +1117,7 @@ def _balanceParenForChar(self, char, location): openToCloseMap = _reverseMap(openToCloseMap) self._balanceParens(location=location, char=char, matchChar=openToCloseMap[char], end=True) + @python_method def _balanceParens(self, location, char, matchChar, end): found = self._findMatchingParen(location, char, matchChar, end) if found is not None: @@ -1126,9 +1136,11 @@ def _balanceParens(self, location, char, matchChar, end): self.layoutManager().setTemporaryAttributes_forCharacterRange_(balancingAttrs, (found, 1)) self.performSelector_withObject_afterDelay_("_resetBalanceParens:", (oldAttrs, effRng), 0.2) - def _resetBalanceParens_(self, (attrs, rng)): + def _resetBalanceParens_(self, attrs_rng): + attrs, rng = attrs_rng self.layoutManager().setTemporaryAttributes_forCharacterRange_(attrs, rng) + @python_method def _filterLines(self, filterFunc): selectedRange = self.selectedRange() lines, linesRange = self._getTextForRange(selectedRange) @@ -1143,6 +1155,7 @@ def _filterLines(self, filterFunc): newSelRng = linesRange.location, len(filteredLines) self.setSelectedRange_(newSelRng) + @python_method def _getLeftWordRange(self, newRange): if newRange.location == 0: return 0 @@ -1169,6 +1182,7 @@ def _getLeftWordRange(self, newRange): return location + @python_method def _getRightWordRange(self, newRange): text = self.string() lenText = len(text) @@ -1192,11 +1206,13 @@ def _getRightWordRange(self, newRange): isChar = not isChar return location + @python_method def _getTextForRange(self, lineRange): string = self.string() lineRange = string.lineRangeForRange_(lineRange) return string.substringWithRange_(lineRange), lineRange + @python_method def _getSelectedValueForRange(self, selectedRange): value = None try: @@ -1209,12 +1225,14 @@ def _getSelectedValueForRange(self, selectedRange): pass return value + @python_method def _insertTextAndRun(self, txt, txtRange): self.insertText_(txt) newRange = AppKit.NSMakeRange(txtRange.location, len(txt)) self.setSelectedRange_(newRange) return self._runInternalCode() + @python_method def _runInternalCode(self): pool = AppKit.NSAutoreleasePool.alloc().init() try: diff --git a/drawBot/ui/debug.py b/drawBot/ui/debug.py index 8b6eedbd..7ef87b15 100644 --- a/drawBot/ui/debug.py +++ b/drawBot/ui/debug.py @@ -1,10 +1,12 @@ +from __future__ import absolute_import + from AppKit import * import sys from vanilla import * -from codeEditor import OutPutEditor +from .codeEditor import OutPutEditor class ShowHideNSPanel(NSPanel): diff --git a/drawBot/ui/drawBotController.py b/drawBot/ui/drawBotController.py index b980ea38..3a9c955f 100644 --- a/drawBot/ui/drawBotController.py +++ b/drawBot/ui/drawBotController.py @@ -1,16 +1,18 @@ +from __future__ import absolute_import + import AppKit from vanilla import * from defconAppKit.windows.baseWindow import BaseWindowController -from codeEditor import CodeEditor, OutPutEditor -from drawView import DrawView, ThumbnailView +from .codeEditor import CodeEditor, OutPutEditor +from .drawView import DrawView, ThumbnailView from drawBot.scriptTools import ScriptRunner, CallbackRunner, DrawBotNamespace, StdOutput from drawBot.drawBotDrawingTools import _drawBotDrawingTool from drawBot.context.drawBotContext import DrawBotContext from drawBot.misc import getDefault, setDefault, warnings -from splitView import SplitView +from .splitView import SplitView class DrawBotController(BaseWindowController): diff --git a/drawBot/ui/lineNumberRulerView.py b/drawBot/ui/lineNumberRulerView.py index 6b72ff75..e4e3eb69 100644 --- a/drawBot/ui/lineNumberRulerView.py +++ b/drawBot/ui/lineNumberRulerView.py @@ -134,7 +134,7 @@ def lineNumberForCharacterIndex_inText_(self, index, text): right = len(lines) while (right - left) > 1: - mid = (right + left) / 2 + mid = (right + left) // 2 lineStart = lines[mid] if index < lineStart: diff --git a/drawBot/ui/preferencesController.py b/drawBot/ui/preferencesController.py index 65a5d047..a0a0da0f 100644 --- a/drawBot/ui/preferencesController.py +++ b/drawBot/ui/preferencesController.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import + from AppKit import * from vanilla import * @@ -6,7 +8,7 @@ from drawBot.misc import getDefault, setDefault, getFontDefault, setFontDefault, getColorDefault, setColorDefault -from codeEditor import _textAttributesForStyle, _hexToNSColor, fallbackBackgroundColor, fallbackHightLightColor, fallbackFont, styleFromDefault, fallbackStyles +from .codeEditor import _textAttributesForStyle, _hexToNSColor, fallbackBackgroundColor, fallbackHightLightColor, fallbackFont, styleFromDefault, fallbackStyles class ColorCell(NSActionCell): diff --git a/drawBot/updater.py b/drawBot/updater.py index e737a374..43db94d6 100644 --- a/drawBot/updater.py +++ b/drawBot/updater.py @@ -1,4 +1,9 @@ -import urllib2 +from __future__ import absolute_import, print_function + +try: + from urllib2 import urlopen +except ImportError: + from urllib.request import urlopen import subprocess import plistlib import AppKit @@ -9,7 +14,7 @@ from defconAppKit.windows.progressWindow import ProgressWindow from drawBot import __version__ -from misc import DrawBotError, getDefault +from .misc import DrawBotError, getDefault def getCurrentVersion(): @@ -20,7 +25,7 @@ def getCurrentVersion(): return "" path = "https://raw.github.com/typemytype/drawbot/master/drawBot/drawBotSettings.py" try: - response = urllib2.urlopen(path, timeout=5) + response = urlopen(path, timeout=5) code = response.read() response.close() exec(code) @@ -49,7 +54,7 @@ def downloadCurrentVersion(): break AppKit.NSWorkspace.sharedWorkspace().openFile_(dmgPath) except: - print "Something went wrong while downloading %s" % path + print("Something went wrong while downloading %s" % path) class Updater(object): diff --git a/setup.py b/setup.py index 326a776b..f801b125 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,5 @@ +from __future__ import print_function + from distutils.core import setup from distutils import sysconfig import py2app @@ -139,53 +141,53 @@ def getValueFromSysArgv(key, default=None): # copy external tools into the resources folder (gifsicle) gifsiclePathSource = os.path.join(os.getcwd(), "drawBot", "context", "tools", "gifsicle") gifsiclePathDest = os.path.join(appLocation, "contents", "Resources", "gifsicle") - print "copy", gifsiclePathSource, gifsiclePathDest + print("copy", gifsiclePathSource, gifsiclePathDest) shutil.copyfile(gifsiclePathSource, gifsiclePathDest) - os.chmod(gifsiclePathDest, 0775) + os.chmod(gifsiclePathDest, 0o775) mkbitmapPathSource = os.path.join(os.getcwd(), "drawBot", "context", "tools", "mkbitmap") mkbitmapPathDest = os.path.join(appLocation, "contents", "Resources", "mkbitmap") - print "copy", mkbitmapPathSource, mkbitmapPathDest + print("copy", mkbitmapPathSource, mkbitmapPathDest) shutil.copyfile(mkbitmapPathSource, mkbitmapPathDest) - os.chmod(mkbitmapPathDest, 0775) + os.chmod(mkbitmapPathDest, 0o775) potracePathSource = os.path.join(os.getcwd(), "drawBot", "context", "tools", "potrace") potracePathDest = os.path.join(appLocation, "contents", "Resources", "potrace") - print "copy", potracePathSource, potracePathDest + print("copy", potracePathSource, potracePathDest) shutil.copyfile(potracePathSource, potracePathDest) - os.chmod(potracePathDest, 0775) + os.chmod(potracePathDest, 0o775) if codeSignDeveloperName: # ================ # = code singing = # ================ - print "---------------------" - print "- code signing -" + print("---------------------") + print("- code signing -") cmds = ["codesign", "--force", "--deep", "--sign", "Developer ID Application: %s" % codeSignDeveloperName, appLocation] popen = subprocess.Popen(cmds) popen.wait() - print "- done code singing -" - print "---------------------" + print("- done code singing -") + print("---------------------") - print "------------------------------" - print "- verifying with codesign... -" + print("------------------------------") + print("- verifying with codesign... -") cmds = ["codesign", "--verify", "--verbose=4", appLocation] popen = subprocess.Popen(cmds) popen.wait() - print "------------------------------" + print("------------------------------") - print "---------------------------" - print "- verifying with spctl... -" + print("---------------------------") + print("- verifying with spctl... -") cmds = ["spctl", "--verbose=4", "--raw", "--assess", "--type", "execute", appLocation] popen = subprocess.Popen(cmds) popen.wait() - print "---------------------------" + print("---------------------------") # ================ # = creating dmg = # ================ - print "------------------------" - print "- building dmg... -" + print("------------------------") + print("- building dmg... -") if os.path.exists(existingDmgLocation): os.remove(existingDmgLocation) @@ -203,13 +205,13 @@ def getValueFromSysArgv(key, default=None): shutil.rmtree(imgLocation) - print "- done building dmg... -" - print "------------------------" + print("- done building dmg... -") + print("------------------------") if ftpHost and ftpPath and ftpLogin and ftpPassword: import ftplib - print "-------------------------" - print "- uploading to ftp -" + print("-------------------------") + print("- uploading to ftp -") session = ftplib.FTP(ftpHost, ftpLogin, ftpPassword) session.cwd(ftpPath) @@ -226,6 +228,6 @@ def getValueFromSysArgv(key, default=None): session.storbinary('STOR %s' % fileName, dmgFile) dmgFile.close() - print "- done uploading to ftp -" - print "-------------------------" + print("- done uploading to ftp -") + print("-------------------------") session.quit()