Example #1
0
    def remoteInstall(self, forcedUpdate=False, showMessages=False):
        """
        Install the extension from the remote. This will call `extensionNeedsUpdate()`

        Optional set `forcedUpdate` to `True` if its needed to install the extension anyhow
        """
        if self.isExtensionInstalled(
        ) and not self.extensionNeedsUpdate() and not forcedUpdate:
            # dont download and install if the current intall is newer (only when it forced)
            return
        # get the zip path
        zipPath = self.remoteZipPath()

        try:
            # try to download the zip file
            # and fail silently with a custom error message
            contents = getDataFromURL(zipPath)
        except Exception as e:
            message = "Could not download the extension zip file for: '%s'" % self.extensionName(
            )
            logger.error(message)
            logger.error(e)
            raise ExtensionRepoError(message)
        # create a temp folder
        tempFolder = tempfile.mkdtemp()
        try:
            # try to extract the zip
            # and fail silently with a custom message
            with zipfile.ZipFile(BytesIO(contents)) as z:
                z.extractall(tempFolder)
        except Exception as e:
            message = "Could not extract the extension zip file for: '%s'" % self.extensionName(
            )
            logger.error(message)
            logger.error(e)
            raise ExtensionRepoError(message)
        # find the extension path
        extensionPath = findExtensionInRoot(
            os.path.basename(self.extensionPath), tempFolder)
        if extensionPath:
            # if found get the bundle and install it
            bundle = ExtensionBundle(path=extensionPath)
            bundle.install(showMessages=showMessages)
            self.resetRemembered()
        else:
            # raise an custom error when the extension is not found in the zip
            message = "Could not find the extension: '%s'" % self.extensionPath
            logger.error(message)
            raise ExtensionRepoError(message)
        # remove the temp folder with the extracted zip
        shutil.rmtree(tempFolder)
Example #2
0
    def _remoteInstallCallback(self, url, data, error):
        if error:
            message = "Could not download the extension zip file for: '%s' at url: '%s'" % (
                self.extensionName(), url)
            logger.error(message)
            logger.error(error)
            raise ExtensionRepoError(message)

        # create a temp folder
        tempFolder = tempfile.mkdtemp()
        try:
            # try to extract the zip
            # and fail silently with a custom message
            with zipfile.ZipFile(io.BytesIO(data.bytes())) as z:
                z.extractall(tempFolder)
        except Exception as e:
            message = "Could not extract the extension zip file for: '%s' at url: '%s'" % (
                self.extensionName(), url)
            logger.error(message)
            logger.error(e)
            raise ExtensionRepoError(message)

        # find the extension path
        extensionPath = findExtensionInRoot(
            os.path.basename(self.extensionPath), tempFolder)
        if extensionPath:
            # if found get the bundle and install it
            bundle = ExtensionBundle(path=extensionPath)
            bundle.install(showMessages=self._showMessages)
            self.resetRemembered()
        else:
            # raise an custom error when the extension is not found in the zip
            message = "Could not find the extension: '%s'" % self.extensionPath
            logger.error(message)
            raise ExtensionRepoError(message)

        # remove the temp folder with the extracted zip
        shutil.rmtree(tempFolder)

        # clear the cache for this extension icon so it may be reloaded
        if self.extensionIconURL():
            CachingURLReader.invalidate_cache_for_url(self.extensionIconURL())
            self._extensionIcon = None

        self._needsUpdate = False
        postEvent(EXTENSION_DID_REMOTE_INSTALL_EVENT_KEY, item=self)
Example #3
0
    def glyphEditorWantsToolbarItems(self, info):

        toolbarItems = info['itemDescriptions']

        label = 'Add Overlap'
        identifier = 'addOverlap'
        callback = self.addOverlap
        index = -2

        bundle = ExtensionBundle("AddOverlap")
        icon = bundle.getResourceImage("AddOverlapButton")

        view = ToolbarGlyphTools((30, 25), [dict(image=icon, toolTip=label)],
                                 trackingMode="one")

        newItem = dict(itemIdentifier=identifier,
                       label=label,
                       callback=callback,
                       view=view)

        toolbarItems.insert(index, newItem)
Example #4
0
 def getToolbarIcon(self):
     extBundle = ExtensionBundle("SlightlyBetterTransform")
     toolbarIcon = extBundle.get("SlightlyBetterTransform_ToolbarIcon-2x")
     return toolbarIcon
Example #5
0
# -*- coding: utf-8 -*-

from AppKit import NSColor, NSFont, NSFontAttributeName, NSForegroundColorAttributeName, NSCursor
from mojo.events import installTool, EditingTool, BaseEventTool, setActiveEventTool
from mojo.drawingTools import *
from mojo.UI import UpdateCurrentGlyphView
from defconAppKit.windows.baseWindow import BaseWindowController

import vanilla

from mojo.extensions import ExtensionBundle

shapeBundle = ExtensionBundle("ZoneChecker")
toolbarIcon = shapeBundle.get("ZoneCheckerButton")
"""


    Zonechecker
    
    Check for points near the alignment zones.


"""


class ZoneCheckerTool(EditingTool):

    zoneCheckerToolPrefsLibKey = "com.letterror.zoneChecker.prefs"
    textAttributes = {
        NSFontAttributeName: NSFont.systemFontOfSize_(10),
        NSForegroundColorAttributeName: NSColor.whiteColor(),
Example #6
0
 def extensionBundle(self):
     # get the bundleName
     bundleName = self.extensionPath.split("/")[-1]
     # get the bundle
     return ExtensionBundle(bundleName)
Example #7
0
 def __init__(self):
     addObserver(self, "spaceCenterDidOpen", "spaceCenterDidOpen")
     self.bundle = ExtensionBundle("SpaceFlip")
     self.path1 = self.bundle.resourcesPath() + '/flipButton.pdf'
     self.path2 = self.bundle.resourcesPath() + '/flipButton2.pdf'
     self.flipped = False
Example #8
0
from mojo.events import BaseEventTool, installTool
from AppKit import *

from lib.tools.drawing import strokePixelPath

from dialogKit import ModalDialog, TextBox, EditText
from vanilla import RadioGroup

from robofab.pens.reverseContourPointPen import ReverseContourPointPen

from mojo.extensions import ExtensionBundle

# collecting the image data for building cursors and toolbar icons

shapeBundle = ExtensionBundle("ShapeTool")
_cursorOval = CreateCursor(shapeBundle.get("cursorOval"), hotSpot=(6, 6))

_cursorRect = CreateCursor(shapeBundle.get("cursorRect"), hotSpot=(6, 6))

toolbarIcon = shapeBundle.get("toolbarIcon")


class GeometricShapesWindow(object):
    """
    The Modal window that allows numbers input to draw basic geometric shapes.
    """
    def __init__(self, glyph, callback, x, y):
        self.glyph = glyph
        self.callback = callback
        # create the modal dialog (from dialogKit)
        self.w = ModalDialog((200, 150),
Example #9
0
# BY DJR, with help from Nina Stössinger. Thanks Nina!

# I should probably redo this at some point using angled point instead of doing the math myself. Next time...

from mojo.UI import CurrentGlyphWindow, UpdateCurrentGlyphView
from mojo.events import BaseEventTool, installTool, EditingTool
from AppKit import *
from defconAppKit.windows.baseWindow import BaseWindowController
from mojo.drawingTools import *
from mojo.extensions import ExtensionBundle
from vanilla import *
from mojo.extensions import getExtensionDefault, setExtensionDefault, getExtensionDefaultColor, setExtensionDefaultColor
from lib.tools.defaults import getDefault
from lib.tools import bezierTools

bundle = ExtensionBundle("BoundingTool")
toolbarIcon = bundle.getResourceImage("boundingTool")
try:
    toolbarIcon.setSize_((16, 16))
except:
    pass


class TX:
    @classmethod
    def formatStringValue(cls, f):
        return format(f, '.1f').rstrip('0').rstrip('.')

    @classmethod
    def getItalicOffset(cls, yoffset, italicAngle):
        '''
Example #10
0
# -*- coding: utf-8 -*-

from AppKit import NSColor, NSFont, NSFontAttributeName, NSForegroundColorAttributeName, NSCursor
from mojo.events import installTool, EditingTool, BaseEventTool, setActiveEventTool
from mojo.drawingTools import *
from mojo.UI import UpdateCurrentGlyphView
from defconAppKit.windows.baseWindow import BaseWindowController

from gaussTools import *
import vanilla

from mojo.extensions import ExtensionBundle
shapeBundle = ExtensionBundle("LightMeter")
toolbarIcon = shapeBundle.get("LightMeterButton")

"""


    LightMeterTool 02
    
    This is a sort of a light meter for the glyph window. 
    Running this script will install a tool in the toolbar. 
        
    When selected, the tool draws trails of gray rectangles.
    The gray level of a pixel corresponds to the light 
    contributed by the white and black areas around the cursor.
    The blue number indicates the percentage. 

        100    = white + dot
        n      = some level of gray
        0      = black + dot
Example #11
0
 def inject_version_data(self, headers):
     extension = ExtensionBundle("Ghostlines").version or "Beta"
     version = "RF{};{}".format(RF.version, extension)
     headers["X-Ghostlines-Version"] = version
Example #12
0
 def __init__(self, name=None, path=None):
     self.name = name
     self.bundle = ExtensionBundle(name=self.name, path=path)
Example #13
0
Robo-CJK is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Robo-CJK.  If not, see <https://www.gnu.org/licenses/>.
"""

from mojo.extensions import ExtensionBundle
from mojo.events import EditingTool
from vanilla import *
import os

toolbarIcon = ExtensionBundle("sources/resources").get("SmartSelectorIcon")


class SmartSelector(EditingTool):
    def __init__(self, interface):
        super(SmartSelector, self).__init__()
        self.ui = interface

    def mouseUp(self, point):
        g = self.getGlyph()
        anythingSelected = False
        contours = []
        for p in g.selection:
            c = p.getParent()
            if c not in contours:
                contours.append(c)
Example #14
0
from AppKit import NSImage
from mojo.roboFont import CreateCursor
from mojo.extensions import ExtensionBundle

eraserBundle = ExtensionBundle("EraserTool")
eraserCursor = CreateCursor(eraserBundle.get("eraserCursor"), hotSpot=(4, 14))
toolbarIcon = eraserBundle.get("toolbarToolsEraser")

from mojo.events import EditingTool, installTool
from mojo.UI import UpdateCurrentGlyphView


class EraserTool(EditingTool):
    def mouseDown(self, point, clickCount):
        g = CurrentGlyph()
        self.convertToLine(g)

    def convertToLine(self, glyph):
        if glyph and glyph.selection != []:
            glyph.prepareUndo()
            for c_index in range(len(glyph.contours)):
                c = glyph.contours[c_index]
                for s_index in range(len(c.segments)):
                    s = c.segments[s_index]
                    if s.selected and s.type == "curve":
                        s.type = "line"
                        s.points[0].smooth = False
                        s.smooth = False
                        c.segments[s_index - 1].points[-1].smooth = False

            glyph.deselect()
Example #15
0
#	Speed Punk
#	Visualisation tool of outline curvature for font editors.
#
#	Distributed under Apache 2.0 license
#
##########################################################################################

import traceback
from AppKit import NSLog

try:

    from mojo.events import installTool, EditingTool
    from deYanoneRoboFontSpeedpunk import speedpunklib
    from mojo.extensions import ExtensionBundle
    bundle = ExtensionBundle("SpeedPunk")

    ################################################################################################################


    class SpeedPunkTool(EditingTool):
        def becomeActive(self):
            self.speedpunklib = speedpunklib.SpeedPunkLib()
            self.speedpunklib.tool = self
            self.speedpunklib.Open()

        def becomeInactive(self):
            self.speedpunklib.Close()

        def drawBackground(self, scale):
            try:
import os
from AppKit import NSApp, NSMenuItem, NSAlternateKeyMask, NSCommandKeyMask
import math
from vanilla import ImageButton
from mojo.tools import CallbackWrapper
from mojo.UI import CurrentFontWindow, getDefault, setDefault
from mojo.extensions import ExtensionBundle, getExtensionDefault, setExtensionDefault
from mojo.subscriber import Subscriber, registerFontOverviewSubscriber

bundle = ExtensionBundle(path="../../fitGlyphCells.roboFontExt")
icon = bundle.getResourceImage("_icon_Fit")


class fitGlyphCells(Subscriber):
    '''
	Scale the glyph cells in Font Overview as large as 
	they can be while justified to the width of the frame.
	
	Ryan Bugden
	'''
    def build(self):

        self.key = 'com.ryanbugden.FitGlyphCells.FitOnStartup'
        self.startupSetting = getExtensionDefault(self.key, fallback=1)

        # put in the menu item
        title = "Fit Glyph Cells on Open"
        font_menu = NSApp().mainMenu().itemWithTitle_("Font")
        if not font_menu:
            print("Fit Glyph Cells - Error")
            return
Example #17
0
 def toolbarHelp(self, sender):
     ExtensionBundle("Batch").openHelp()
Example #18
0
from mojo.roboFont import OpenWindow

from lib.tools.notifications import PostNotification
from lib.cells.colorCell import RFPopupColorPanel, RFColorCell
from lib.tools.misc import NSColorToRgba

from plistlib import readPlist, writePlist

# Our own branch of the defconAppKit GlyphView
from defconAppKitBranch.glyphView import GlyphView
from defconAppKit.windows.baseWindow import BaseWindowController

# Temp name for a key to save the extension's preferences
DEFAULTSKEY = "com.andyclymer.themeManager"

EXTENSIONBUNDLE = ExtensionBundle("ThemeManager")

# Preference keys and names for the theme settings
THEMEKEYS = [
    ("glyphViewOncurvePointsSize", "Oncurve Size", float),
    ("glyphViewOffCurvePointsSize", "Offcurve Size", float),
    ("glyphViewStrokeWidth", "Glyph Stroke Width", int),
    ("glyphViewSelectionStrokeWidth", "Selection Stroke Width", int),
    ("glyphViewHandlesStrokeWidth", "Handle stroke width", int),
    ("glyphViewBackgroundColor", "Background Color", tuple),
    ("glyphViewFillColor", "Fill Color", tuple),
    ("glyphViewPreviewFillColor", "Preview Fill Color", tuple),
    ("glyphViewPreviewBackgroundColor", "Preview Background Color", tuple),
    ("glyphViewAlternateFillColor", "Alternate Fill Color", tuple),
    ("glyphViewStrokeColor", "Stroke Color", tuple),
    ("glyphViewCornerPointsFill", "Corner Point Fill Color", tuple),
import math
import AppKit
from mojo.extensions import ExtensionBundle
from mojo.events import installTool, EditingTool
from mojo.drawingTools import *
from mojo.UI import UpdateCurrentGlyphView, getDefault
import merz
from merz.tools.drawingTools import NSImageDrawingTools

#     A visualisation for RoboFont 4 XX
#     Show the ratio between the length of outgoing and incoming sections of bcps and tangents.
#     Show the angle
#     Draw in active and inactive views so we can compare different glyphs
#     [email protected]

angleRatioToolBundle = ExtensionBundle("AngleRatioTool")
toolbarIconPath = os.path.join(angleRatioToolBundle.resourcesPath(), "icon.pdf")
toolbarIcon = AppKit.NSImage.alloc().initWithContentsOfFile_(toolbarIconPath)





def dotSymbolFactory(
        size,
        color,
        strokeColor,
        strokeWidth=0,
        ):
    # create a image draw bot 
    bot = NSImageDrawingTools((size, size))
Example #20
0
import os
import sys
import importlib
from mojo.extensions import getExtensionDefault, setExtensionDefault
from mojo.extensions import ExtensionBundle

KEYPREFIX = "com.andyclymer.andysHacks"

extBundle = ExtensionBundle("AndysRFHacks")
# Clear out any script metadata if it's a new version of the extension
if not extBundle.version == getExtensionDefault("%s.version" % KEYPREFIX,
                                                fallback="0.0"):
    setExtensionDefault("%s.version" % KEYPREFIX, extBundle.version)
    setExtensionDefault("%s.scriptMetadata" % KEYPREFIX, {})

from Scripts import *
# load license text from file
# see choosealicense.com for more open-source licenses
licensePath = os.path.join(basePath, 'license.txt')

# required extensions
requirementsPath = os.path.join(basePath, 'requirements.txt')

# name of the compiled extension file
extensionFile = 'myExtension.roboFontExt'

# path of the compiled extension
buildPath = os.path.join(basePath, 'build')
extensionPath = os.path.join(buildPath, extensionFile)

# initiate the extension builder
B = ExtensionBundle()

# name of the extension
B.name = "myExtension"

# name of the developer
B.developer = 'RoboDocs'

# URL of the developer
B.developerURL = 'http://github.com/roboDocs'

# extension icon (file path or NSImage)
imagePath = os.path.join(resourcesPath, 'icon.png')
B.icon = imagePath

# version of the extension
from mojo.events import BaseEventTool, installTool
from mojo.roboFont import CreateCursor

from mojo.extensions import getExtensionDefault, setExtensionDefault, ExtensionBundle

from lib.tools.notifications import PostNotification
from lib.tools import bezierTools
from lib.tools.defaults import getDefault, setDefault

from settings import *

from generateImages import AddPixelToolRepresentationFactory

AddPixelToolRepresentationFactory()

pixelBundle = ExtensionBundle("PixelTool")
pixelCursor = CreateCursor(pixelBundle.get("pixelCursor"), hotSpot=(1, 19))
pixelToolbarIcon = pixelBundle.get("pixelToolbarIcon")


def _roundPoint(x, y):
    return int(round(x)), int(round(y))

class GridSettingsMenu(object):
    
    def __init__(self, tool, event, view):
        self.tool = tool
        
        self.drawingChoices = [RECT_MODE, OVAL_MODE, COMPONENT_MODE]
                
        self.view = vanilla.Group((0, 0, 0, 0))