コード例 #1
0
    def drawHashMarksAndLabelsInRect_(self, rect):
        bounds = self.bounds()
        view = self.clientView()

        rulerBackgroundColor = self.rulerBackgroundColor()
        if rulerBackgroundColor is not None:
            rulerBackgroundColor.set()
            NSRectFill(bounds)

        if not isinstance(view, NSTextView):
            return

        layoutManager = view.layoutManager()
        container = view.textContainer()
        text = view.string()
        nullRange = NSMakeRange(NSNotFound, 0)
        yinset = view.textContainerInset().height
        visibleRect = self.scrollView().contentView().bounds()
        textAttributes = self.textAttributes()

        lines = self.lineIndices()

        glyphRange = layoutManager.glyphRangeForBoundingRect_inTextContainer_(visibleRect, container)
        _range = layoutManager.characterRangeForGlyphRange_actualGlyphRange_(glyphRange, None)[0]
        _range.length += 1

        count = len(lines)
        index = 0

        lineNumber = self.lineNumberForCharacterIndex_inText_(_range.location, text)

        for line in range(lineNumber, count):
            index = lines[line]
            if NSLocationInRange(index, _range):
                rects, rectCount = layoutManager.rectArrayForCharacterRange_withinSelectedCharacterRange_inTextContainer_rectCount_(
                    NSMakeRange(index, 0),
                    nullRange,
                    container,
                    None
                )
                if rectCount > 0:
                    ypos = yinset + NSMinY(rects[0]) - NSMinY(visibleRect)
                    labelText = NSString.stringWithString_("%s" % (line + 1))
                    stringSize = labelText.sizeWithAttributes_(textAttributes)

                    x = NSWidth(bounds) - stringSize.width - self.RULER_MARGIN
                    y = ypos + (NSHeight(rects[0]) - stringSize.height) / 2.0
                    w = NSWidth(bounds) - self.RULER_MARGIN * 2.0
                    h = NSHeight(rects[0])

                    labelText.drawInRect_withAttributes_(NSMakeRect(x, y, w, h), textAttributes)

            if index > NSMaxRange(_range):
                break

        path = NSBezierPath.bezierPath()
        path.moveToPoint_((bounds.origin.x + bounds.size.width, bounds.origin.y))
        path.lineToPoint_((bounds.origin.x + bounds.size.width, bounds.origin.y + bounds.size.height))
        NSColor.grayColor().set()
        path.stroke()
コード例 #2
0
    def drawDiameter(self, x, y, scale=1, showSize=False):

        # draw points contributing to the level.
        s = self.prefs["chunkSize"]
        stroke(None)
        for (px, py), v in self._hits.items():
            fill(self._outsideColor[0], self._outsideColor[1], self._outsideColor[2], v * 80)
            oval(px - 0.5 * s, py - 0.5 * s, s, s)
        for (px, py), v in self._misses.items():
            fill(self._insideColor[0], self._insideColor[1], self._insideColor[2], v * 80)
            oval(px - 0.5 * s, py - 0.5 * s, s, s)

        stroke(0.5)
        strokeWidth(self.diameterMarkerWidth * scale)
        fill(None)
        oval(
            x - 0.5 * self.prefs["diameter"],
            y - 0.5 * self.prefs["diameter"],
            self.prefs["diameter"],
            self.prefs["diameter"],
        )

        if showSize:
            tp = x, y + 20 * scale
            self.getNSView()._drawTextAtPoint(
                u"⌀ %3.2f" % (self.prefs["diameter"]),
                self.textAttributes,
                tp,
                yOffset=(0.5 * self.prefs["diameter"]) / scale,
                drawBackground=True,
                backgroundColor=NSColor.grayColor(),
            )
コード例 #3
0
    def drawDiameter(self, x, y, scale=1, showSize=False):
        
        # draw points contributing to the level.
        s = self.prefs['chunkSize']
        stroke(None)
        for (px,py), v in self._hits.items():
            fill(self._outsideColor[0],self._outsideColor[1],self._outsideColor[2], v*80)
            oval(px-0.5*s, py-0.5*s, s, s)
        for (px,py), v in self._misses.items():
            fill(self._insideColor[0],self._insideColor[1],self._insideColor[2], v*80)
            oval(px-0.5*s, py-0.5*s, s, s)

        stroke(0.5)
        strokeWidth(self.diameterMarkerWidth*scale)
        fill(None)
        oval(x-0.5*self.prefs['diameter'], y-0.5*self.prefs['diameter'], self.prefs['diameter'], self.prefs['diameter'])

        if showSize:
            tp = x, y + 20*scale
            self.getNSView()._drawTextAtPoint(
                u"⌀ %3.2f"%(self.prefs['diameter']),
                self.textAttributes,
                tp,
                yOffset=(.5*self.prefs['diameter'])/scale,
                drawBackground=True,
                backgroundColor=NSColor.grayColor())
コード例 #4
0
def text_Gray(text):
    size = NSRegularControlSize
    attrs = {}
    attrs[NSForegroundColorAttributeName] = NSColor.grayColor()
    string = NSMutableAttributedString.alloc().initWithString_attributes_(
        text, attrs)
    #attrs[NSFontAttributeName] = NSFont.boldSystemFontOfSize_(NSFont.systemFontSizeForControlSize_(size))
    attrs[NSFontAttributeName] = NSFont.systemFontOfSize_(
        NSFont.systemFontSizeForControlSize_(size))
    attributedString = NSMutableAttributedString.alloc(
    ).initWithString_attributes_(text, attrs)
    return attributedString
コード例 #5
0
#
#		Python GUI - DrawableContainers - PyObjC
#

from Foundation import NSMakeRect
from AppKit import NSView, NSScrollView, NSColor
from GUI import export
from GUI.Utils import PyGUI_Flipped_NSView
from GUI import Canvas
from GUI.Geometry import rect_to_ns_rect
from GUI.Utils import NSMultiClass, PyGUI_NS_ViewBase
from GUI.GDrawableContainers import default_size, \
    DrawableContainer as GDrawableContainer

ns_gray = NSColor.grayColor()

class DrawableContainer(GDrawableContainer):

    def __init__(self, **kwds):
        width, height = default_size
        ns_frame = NSMakeRect(0, 0, width, height)
        ns_inner_view = PyGUI_User_NSView.alloc().initWithFrame_(ns_frame)
        if self._ns_scrollable:
            ns_view = NSScrollView.alloc().initWithFrame_(ns_frame)
            ns_view.setDocumentView_(ns_inner_view)
            ns_view.setBackgroundColor_(ns_gray)
        else:
            ns_view = ns_inner_view
        ns_inner_view.pygui_component = self
        GDrawableContainer.__init__(self, _ns_view = ns_view, _ns_inner_view = ns_inner_view)
        self.set(**kwds)
コード例 #6
0
#
#		Python GUI - DrawableContainers - PyObjC
#

from Foundation import NSMakeRect
from AppKit import NSView, NSScrollView, NSColor
from GUI import export
from GUI.Utils import PyGUI_Flipped_NSView
from GUI import Canvas
from GUI.Geometry import rect_to_ns_rect
from GUI.Utils import NSMultiClass, PyGUI_NS_ViewBase
from GUI.GDrawableContainers import default_size, \
 DrawableContainer as GDrawableContainer

ns_gray = NSColor.grayColor()


class DrawableContainer(GDrawableContainer):
    def __init__(self, **kwds):
        width, height = default_size
        ns_frame = NSMakeRect(0, 0, width, height)
        ns_inner_view = PyGUI_User_NSView.alloc().initWithFrame_(ns_frame)
        if self._ns_scrollable:
            ns_view = NSScrollView.alloc().initWithFrame_(ns_frame)
            ns_view.setDocumentView_(ns_inner_view)
            ns_view.setBackgroundColor_(ns_gray)
        else:
            ns_view = ns_inner_view
        ns_inner_view.pygui_component = self
        GDrawableContainer.__init__(self,
                                    _ns_view=ns_view,
コード例 #7
0
ファイル: colors.py プロジェクト: PageBot/PageBotNano
    return getRGBA(r * 255, b * 255, g * 255, a)


rgb = rgba

# Preset colors.

blackColor = NSColor.blackColor()
opaqueBlackColor = getRGBA(0, 0, 0, 0.5)
blueColor = NSColor.blueColor()
brownColor = NSColor.brownColor()
clearColor = NSColor.clearColor()
cyanColor = NSColor.cyanColor()
darkGrayColor = getRGBA(80, 80, 80)
darkGreyColor = darkGrayColor
grayColor = NSColor.grayColor()
greyColor = grayColor
grayColor = NSColor.grayColor()
greenColor = NSColor.greenColor()
lightGreenColor = getRGBA(75, 211, 154)
darkGreenColor = getRGBA(41, 120, 37)
lightestGrayColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(
    0.98, 0.98, 0.98, 1)
lightestGreyColor = lightestGrayColor
lightGrayColor = NSColor.lightGrayColor()
lightGreyColor = lightGrayColor
magentaColor = NSColor.magentaColor()
orangeColor = NSColor.orangeColor()
lightOrangeColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(
    0.98, 0.81, 0.32, 1)
purpleColor = NSColor.purpleColor()
コード例 #8
0
ファイル: osx_panel.py プロジェクト: xoconusco/verano16
        self.height = height


class Color:
    """ A class representing a color """

    def __init__(self, ns_color):
        self.ns_color = ns_color


Color.BLACK = Color(NSColor.blackColor())
Color.BLUE = Color(NSColor.blueColor())
Color.BROWN = Color(NSColor.brownColor())
Color.CYAN = Color(NSColor.cyanColor())
Color.DARK_GRAY = Color(NSColor.darkGrayColor())
Color.GRAY = Color(NSColor.grayColor())
Color.GREEN = Color(NSColor.greenColor())
Color.MAGENTA = Color(NSColor.magentaColor())
Color.ORANGE = Color(NSColor.orangeColor())
Color.PURPLE = Color(NSColor.purpleColor())
Color.RED = Color(NSColor.redColor())
Color.WHITE = Color(NSColor.whiteColor())
Color.YELLOW = Color(NSColor.yellowColor())


class Font:
    """ Text font """

    def __init__(self, name, size):
        self.ns_font = NSFont.fontWithName_size_(name, size)
コード例 #9
0

# Kinda hack, storing in empty module, to prevent globals to re-initialized, if variables are changed.
scriptGlobals = pagebot.getGlobals(path2ScriptId(__file__))

if not hasattr(scriptGlobals, 'initializedLayerEditor'):
    scriptGlobals.initializedLayerEditor = True
    # Store Italics flag, so we can test if it changed.
    scriptGlobals.italics = Italics
    # Store Use_BitPath flag, so we can test if it changed.
    scriptGlobals.use_BitPath = Use_BitPath
    # Currently (random) selected fonts per layer
    clearFonts(
    )  # Initialize font choice, so new random fonts will be selected.
    scriptGlobals.layerColors = {
        0: NSColor.grayColor(),
        1: NSColor.grayColor(),
        2: NSColor.grayColor(),
        3: NSColor.grayColor(),
        4: NSColor.grayColor(),
        5: NSColor.grayColor()
    }  #
    # Collections of avaiable fonts, filtered by weight and stem-pixel
    scriptGlobals.fontNamePaths = {}
    scriptGlobals.lightPaths = {}  # Not Bold or Black
    scriptGlobals.boldPaths = {}
    scriptGlobals.singleLightPaths = {}  # Not Bold or Black
    scriptGlobals.singleBoldPaths = {}
    scriptGlobals.doubleLightPaths = {}  # Not Bold or Black
    scriptGlobals.doubleBoldPaths = {}
コード例 #10
0
    def drawHashMarksAndLabelsInRect_(self, rect):
        bounds = self.bounds()
        view = self.clientView()

        rulerBackgroundColor = self.rulerBackgroundColor()
        if rulerBackgroundColor is not None:
            rulerBackgroundColor.set()
            NSRectFill(bounds)

        if not isinstance(view, NSTextView):
            return

        layoutManager = view.layoutManager()
        container = view.textContainer()
        text = view.string()
        nullRange = NSMakeRange(NSNotFound, 0)
        yinset = view.textContainerInset().height
        visibleRect = self.scrollView().contentView().bounds()
        textAttributes = self.textAttributes()

        lines = self.lineIndices()

        glyphRange = layoutManager.glyphRangeForBoundingRect_inTextContainer_(
            visibleRect, container)
        _range = layoutManager.characterRangeForGlyphRange_actualGlyphRange_(
            glyphRange, None)[0]
        _range.length += 1

        count = len(lines)
        index = 0

        lineNumber = self.lineNumberForCharacterIndex_inText_(
            _range.location, text)

        for line in range(lineNumber, count):
            index = lines[line]
            if NSLocationInRange(index, _range):
                rects, rectCount = layoutManager.rectArrayForCharacterRange_withinSelectedCharacterRange_inTextContainer_rectCount_(
                    NSMakeRange(index, 0), nullRange, container, None)
                if rectCount > 0:
                    ypos = yinset + NSMinY(rects[0]) - NSMinY(visibleRect)
                    labelText = NSString.stringWithString_("%s" % (line + 1))
                    stringSize = labelText.sizeWithAttributes_(textAttributes)

                    x = NSWidth(bounds) - stringSize.width - self.RULER_MARGIN
                    y = ypos + (NSHeight(rects[0]) - stringSize.height) / 2.0
                    w = NSWidth(bounds) - self.RULER_MARGIN * 2.0
                    h = NSHeight(rects[0])

                    labelText.drawInRect_withAttributes_(
                        NSMakeRect(x, y, w, h), textAttributes)

            if index > NSMaxRange(_range):
                break

        path = NSBezierPath.bezierPath()
        path.moveToPoint_(
            (bounds.origin.x + bounds.size.width, bounds.origin.y))
        path.lineToPoint_((bounds.origin.x + bounds.size.width,
                           bounds.origin.y + bounds.size.height))
        NSColor.grayColor().set()
        path.stroke()
コード例 #11
0
    def __init__(self, posSize, interface, sheet):
        super(ReferenceViewer, self).__init__(posSize)
        self.ui = interface
        self.s = sheet

        self.FontList_comboBox = ComboBox((10, 10, 130, 18),
                                          Global.fontsList.get(),
                                          sizeStyle='small')
        self.FontList_comboBox.set(Global.fontsList.get()[0])

        self.addReferenceFont_button = Button(
            (150, 9, 70, 20),
            "Add",
            sizeStyle="small",
            callback=self._addReferenceFont_button_callback)

        self.removeReference_button = Button(
            (225, 9, 70, 20),
            "Remove",
            sizeStyle="small",
            callback=self._removeReference_button_callback)

        self.s.reference_list_selection = []
        self.reference_list = List(
            (10, 35, 285, 125),
            self.s.referenceViewerList,
            columnDescriptions=[{
                "title": "Font"
            }],
            selectionCallback=self._reference_list_selectionCallback,
            drawFocusRing=False)

        self.settings = Group((10, 170, 295, -0))
        self.settings.show(0)

        y = 3

        self.settings.size_title = TextBox((0, y, 100, 20),
                                           "Size (FU)",
                                           sizeStyle="small")
        self.settings.size_editText = EditText(
            (-60, y - 3, -10, 20),
            "",
            sizeStyle="small",
            callback=self._size_editText_callback)

        self.settings.size_slider = Slider((90, y - 3, -65, 20),
                                           minValue=0,
                                           maxValue=1000,
                                           value=250,
                                           sizeStyle="small",
                                           callback=self._size_slider_callback)

        y += 30
        self.settings.color_title = TextBox((0, y, 100, 20),
                                            "Color (FU)",
                                            sizeStyle="small")
        self.settings.color_colorWell = ColorWell(
            (90, y - 3, -10, 20),
            callback=self._color_editText_callback,
            color=NSColor.grayColor())

        self.canvas = CanvasGroup(
            (-295, 10, -10, -10),
            delegate=ProjectCanvas(self.s, "ReferenceViewer", self))

        self.s.w.bind('close', self.windowWillClose)
        self.observer()