def __init__(self): '''Initialize the dialog.''' x = y = padding = 10 buttonHeight = 20 windowWidth = 400 rows = 4.5 self.w = FloatingWindow( (windowWidth, buttonHeight * rows + padding * (rows)), "Glyph Fax Machine") self.fonts = {} # self.w.textBox = TextBox((x, y, -padding, buttonHeight), "Glyphs to Copy") # y += buttonHeight self.w.editText = EditText( (x, y, -padding, buttonHeight * 2 + padding), placeholder="Space-separated list of glyphs to copy") y += buttonHeight * 2 + padding * 2 # self.w.overwriteGlyphsCheckBox = CheckBox((x, y, -padding, buttonHeight), "Overwrite Glyphs", value=False, callback=self.overwriteGlyphsOptions) # y += buttonHeight + padding self.w.overwriteNormalWidthGlyphsCheckBox = CheckBox( (x, y, -padding, buttonHeight), "Overwrite 600w Glyphs", value=False, sizeStyle="small") # self.w.overwriteNormalWidthGlyphsCheckBox.show(False) self.w.overwriteAdjustedWidthGlyphsCheckBox = CheckBox( (windowWidth * 0.4, y, -padding, buttonHeight), "Overwrite non-600w Glyphs", value=False, sizeStyle="small") # self.w.overwriteAdjustedWidthGlyphsCheckBox.show(False) self.w.colorWell = ColorWell( (windowWidth * 0.85, y, -padding, buttonHeight), color=NSColor.orangeColor()) y += buttonHeight + padding self.w.sans2mono = Button( (x, y, windowWidth / 3 - padding / 2, buttonHeight), "Sans → Mono", callback=self.sans2monoCallback) self.w.mono2sans = Button( (windowWidth / 3 + padding, y, -padding, buttonHeight), "Mono → Sans", callback=self.mono2SansCallback) self.w.open()
def __init__(self, posSize, index, isVertical, isHorizontal, step, gridColor, callback): Group.__init__(self, posSize) # from arguments to attributes self.ctrlX, self.ctrlY, self.ctrlWidth, self.ctrlHeight = posSize self.index = index self.isVertical = isVertical self.isHorizontal = isHorizontal self.step = step self.gridColor = gridColor self.callback = callback # ctrls jumpin_X = 12 self.indexText = TextBox( (jumpin_X, 0, 16, vanillaControlsSize['TextBoxRegularHeight']), '{:d})'.format(index)) jumpin_X += self.indexText.getPosSize()[2] self.stepCtrl = EditText( (jumpin_X, 0, 38, vanillaControlsSize['EditTextRegularHeight']), callback=self.stepCtrlCallback) jumpin_X += self.stepCtrl.getPosSize()[2] + 16 self.isHorizontalCheck = CheckBox( (jumpin_X, 0, 32, vanillaControlsSize['CheckBoxRegularHeight']), "H", value=self.isHorizontal, callback=self.isHorizontalCheckCallback) jumpin_X += self.isHorizontalCheck.getPosSize()[2] + 2 self.isVerticalCheck = CheckBox( (jumpin_X, 0, 32, vanillaControlsSize['CheckBoxRegularHeight']), "V", value=self.isVertical, callback=self.isVerticalCheckCallback) jumpin_X += self.isVerticalCheck.getPosSize()[2] + 10 self.whichColorWell = ColorWell( (jumpin_X, 0, 46, self.ctrlHeight), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*gridColor), callback=self.whichColorWellCallback)
def populateWindow(self): """ The UI """ self.fillColor = getExtensionDefault(DEFAULTKEY_FILLCOLOR, FALLBACK_FILLCOLOR) self.strokeColor = getExtensionDefault(DEFAULTKEY_STROKECOLOR, FALLBACK_STROKECOLOR) self.contextBefore = self.contextAfter = "" # Populating the view can only happen after the view is attached to the window, # or else the relative widths go wrong. self.w.add = Button((-40, 3, 30, 22), "+", callback=self.addCallback) self.w.reset = Button((-40, 30, 30, 22), chr(8634), callback=self.resetCallback) # Flag to see if the selection list click is in progress. We are resetting the selection # ourselves, using the list "buttons", but changing that selection will cause another # list update, that should be ignored. self._selectionChanging = False x = y = 4 self.w.fontList = List( (C2, y, 250, -65), self._getFontItems(), selectionCallback=self.fontListCallback, drawFocusRing=False, enableDelete=False, allowsMultipleSelection=False, allowsEmptySelection=True, drawHorizontalLines=True, showColumnTitles=False, columnDescriptions=self._getPathListDescriptor(), rowHeight=16, ) self.w.fill = CheckBox( (x, y, 60, 22), "Fill", sizeStyle=CONTROLS_SIZE_STYLE, value=True, callback=self.fillCallback, ) y += L - 3 self.w.stroke = CheckBox( (x, y, 60, 22), "Stroke", sizeStyle=CONTROLS_SIZE_STYLE, value=False, callback=self.strokeCallback, ) y += L defaultColor = getExtensionDefault(DEFAULTKEY_FILLCOLOR, FALLBACK_FILLCOLOR) self.w.color = ColorWell( (x, y, 60, 22), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( *defaultColor), callback=self.colorCallback, ) y += LL + 5 self.w.alignText = TextBox((x, y, 90, 50), "Alignment", sizeStyle=CONTROLS_SIZE_STYLE) y += L self.w.align = RadioGroup( (x, y, 90, 50), ["Left", "Center", "Right"], isVertical=True, sizeStyle=CONTROLS_SIZE_STYLE, callback=self.alignCallback, ) self.w.align.set(0) self.w.viewCurrent = CheckBox( (C2, -60, 150, 22), "Always View Current", sizeStyle=CONTROLS_SIZE_STYLE, value=False, callback=self.viewCurrentCallback, ) self.w.contextBefore = GlyphNamesEditText( (C2, -30, 85, 20), callback=self.contextEditCallback, continuous=True, sizeStyle="small", placeholder="Left Context", ) self.w.contextBefore.title = "contextBefore" self.w.contextCurrent = GlyphNamesEditText( (C2 + 95, -30, 60, 20), callback=self.contextEditCallback, continuous=True, sizeStyle="small", ) self.w.contextCurrent.title = "contextCurrent" self.w.contextAfter = GlyphNamesEditText( (C2 + 165, -30, 85, 20), callback=self.contextEditCallback, continuous=True, sizeStyle="small", placeholder="Right Context", ) self.w.contextAfter.title = "contextAfter"
def __init__(self, font): self.w = FloatingWindow((185, 370), "Font Nanny") y = 5 self.w.info = TextBox((10, y, 180, 14), text="Glyph Checks (all Glyphs):", sizeStyle="small") y += 20 self.w.check1 = SquareButton((10, y, 145, 20), "Unicode values", callback=self.perform, sizeStyle="small") self.w.color1 = ColorWell( (155, y, 20, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( 0, 0, 1, 0.3)) self.w.color1.enable(0) y += 20 self.w.check2 = SquareButton((10, y, 145, 20), "Contour Count", callback=self.perform, sizeStyle="small") self.w.color2 = ColorWell( (155, y, 20, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( 5, 0, 0, 0.4)) self.w.color2.enable(0) y += 25 self.w.info2 = TextBox((10, y, 180, 14), text="Outline Checks (all Glyphs):", sizeStyle="small") y += 20 self.w.check3 = SquareButton((10, y, 145, 20), "Stray Points", callback=self.perform, sizeStyle="small") self.w.color3 = ColorWell( (155, y, 20, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( .7, .0, .7, .9)) self.w.color3.enable(0) y += 20 self.w.check4 = SquareButton((10, y, 145, 20), "Small Contours", callback=self.perform, sizeStyle="small") self.w.color4 = ColorWell( (155, y, 20, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( 0, .8, 0, 0.9)) self.w.color4.enable(0) y += 20 self.w.check5 = SquareButton((10, y, 145, 20), "Open Contours", callback=self.perform, sizeStyle="small") self.w.color5 = ColorWell( (155, y, 20, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( .4, .4, .4, 0.8)) self.w.color5.enable(0) y += 20 self.w.check6 = SquareButton((10, y, 145, 20), "Duplicate Contours", callback=self.perform, sizeStyle="small") self.w.color6 = ColorWell( (155, y, 20, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( 1, 0, 0, 0.6)) self.w.color6.enable(0) y += 20 self.w.check7 = SquareButton((10, y, 145, 20), "Extreme points", callback=self.perform, sizeStyle="small") self.w.color7 = ColorWell( (155, y, 20, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( 0, .9, 0, 0.6)) self.w.color7.enable(0) y += 20 self.w.check8 = SquareButton((10, y, 145, 20), "Unnecessary Points", callback=self.perform, sizeStyle="small") self.w.color8 = ColorWell( (155, y, 20, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( 1, .0, 1, 0.8)) self.w.color8.enable(0) y += 20 self.w.check9 = SquareButton((10, y, 145, 20), "Unnecessary Handles", callback=self.perform, sizeStyle="small") self.w.color9 = ColorWell( (155, y, 20, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( .4, .0, .0, .3)) self.w.color9.enable(0) y += 20 self.w.check10 = SquareButton((10, y, 145, 20), "Overlapping Points", callback=self.perform, sizeStyle="small") self.w.color10 = ColorWell( (155, y, 20, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( .0, .0, .6, .3)) self.w.color10.enable(0) y += 20 self.w.check11 = SquareButton((10, y, 145, 20), "Points near vert. Metrics", callback=self.perform, sizeStyle="small") self.w.color11 = ColorWell( (155, y, 20, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( 1, 1, .0, .2)) self.w.color11.enable(0) y += 20 self.w.check12 = SquareButton((10, y, 145, 20), "Complex Curves", callback=self.perform, sizeStyle="small") self.w.color12 = ColorWell( (155, y, 20, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(1, 1, 0, 1)) self.w.color12.enable(0) y += 20 self.w.check13 = SquareButton((10, y, 145, 20), "Crossed handles", callback=self.perform, sizeStyle="small") self.w.color13 = ColorWell( (155, y, 20, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( 1, 0, .4, .2)) self.w.color13.enable(0) y += 20 self.w.check14 = SquareButton((10, y, 145, 20), "Straight Lines", callback=self.perform, sizeStyle="small") self.w.color14 = ColorWell( (155, y, 20, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( .0, .6, .0, .3)) self.w.color14.enable(0) y += 30 self.w.horizontalLine = HorizontalLine((10, y - 5, 165, 1)) self.w.clearGlyphMarksButton = SquareButton( (10, y, 90, 20), "Clear all marks", callback=self.clearGlyphMarks, sizeStyle="small") self.w.colorClearGlyphMarks = ColorWell( (100, y, 20, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(1, 1, 1, 1)) self.w.colorClearGlyphMarks.enable(0) self.w.closeWin = SquareButton((120, y, -10, 20), "x) close", callback=self.CloseWindow, sizeStyle="small") self.w.open()
class SingleGridController(Group): """this controller takes care of canvas grid drawing""" def __init__(self, posSize, index, isVertical, isHorizontal, step, gridColor, callback): Group.__init__(self, posSize) # from arguments to attributes self.ctrlX, self.ctrlY, self.ctrlWidth, self.ctrlHeight = posSize self.index = index self.isVertical = isVertical self.isHorizontal = isHorizontal self.step = step self.gridColor = gridColor self.callback = callback # ctrls jumpin_X = 12 self.indexText = TextBox( (jumpin_X, 0, 16, vanillaControlsSize['TextBoxRegularHeight']), '{:d})'.format(index)) jumpin_X += self.indexText.getPosSize()[2] self.stepCtrl = EditText( (jumpin_X, 0, 38, vanillaControlsSize['EditTextRegularHeight']), callback=self.stepCtrlCallback) jumpin_X += self.stepCtrl.getPosSize()[2] + 16 self.isHorizontalCheck = CheckBox( (jumpin_X, 0, 32, vanillaControlsSize['CheckBoxRegularHeight']), "H", value=self.isHorizontal, callback=self.isHorizontalCheckCallback) jumpin_X += self.isHorizontalCheck.getPosSize()[2] + 2 self.isVerticalCheck = CheckBox( (jumpin_X, 0, 32, vanillaControlsSize['CheckBoxRegularHeight']), "V", value=self.isVertical, callback=self.isVerticalCheckCallback) jumpin_X += self.isVerticalCheck.getPosSize()[2] + 10 self.whichColorWell = ColorWell( (jumpin_X, 0, 46, self.ctrlHeight), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*gridColor), callback=self.whichColorWellCallback) def enable(self, onOff): self.indexText.enable(onOff) self.stepCtrl.enable(onOff) self.isHorizontalCheck.enable(onOff) self.isVerticalCheck.enable(onOff) self.whichColorWell.enable(onOff) def get(self): return self.index - 1, { 'horizontal': self.isHorizontal, 'vertical': self.isVertical, 'step': self.step, 'color': self.gridColor } def stepCtrlCallback(self, sender): try: self.step = int(sender.get()) self.callback(self) except ValueError as error: self.step = None self.stepCtrl.set('') def isHorizontalCheckCallback(self, sender): self.isHorizontal = bool(sender.get()) self.callback(self) def isVerticalCheckCallback(self, sender): self.isVertical = bool(sender.get()) self.callback(self) def whichColorWellCallback(self, sender): calibratedColor = sender.get() self.gridColor = (calibratedColor.redComponent(), calibratedColor.greenComponent(), calibratedColor.blueComponent(), calibratedColor.alphaComponent()) self.callback(self)
def __init__(self): # Preferences self._drawing = getExtensionDefault(self.DEFAULTKEY_DRAW, True) self._fill = getExtensionDefault(self.DEFAULTKEY_FILL, True) self._stroke = getExtensionDefault(self.DEFAULTKEY_STROKE, True) self._points = getExtensionDefault(self.DEFAULTKEY_POINTS, True) self._fillColor = getExtensionDefaultColor(self.DEFAULTKEY_FILLCOLOR, self.FALLBACK_FILLCOLOR) self._strokeColor = getExtensionDefaultColor(self.DEFAULTKEY_STROKECOLOR, self.FALLBACK_STROKECOLOR) self._pointsColor = getExtensionDefaultColor(self.DEFAULTKEY_POINTSCOLOR, self.FALLBACK_POINTSCOLOR) self._alignment = getExtensionDefault(self.DEFAULTKEY_ALIGNMENT, 0) self._kerning = getExtensionDefault(self.DEFAULTKEY_KERNING, 1) self._floating = getExtensionDefault(self.DEFAULTKEY_FLOATING, 1) # User preferences self._onCurvePointsSize = getDefault("glyphViewOncurvePointsSize") # typo, should be: OnCurve self._offCurvePointsSize = getDefault("glyphViewOffCurvePointsSize") self._strokeWidth = getDefault("glyphViewStrokeWidth") w, h = 400, 195 x = y = 10 self.initAllFonts() self.w = FloatingWindow((w, h), "Overlay UFOs") self.w.draw = CheckBox((x, y, 95, 18), "Draw", callback=self.drawCallback, value=self._drawing, sizeStyle="small") x += 60 self.w.fill = CheckBox((x, y, 95, 18), "Fill", callback=self.fillCallback, value=self._fill, sizeStyle="small") x += 40 self.w.fillColor = ColorWell((x, y, 45, 20), callback=self.fillColorCallback, color=self._fillColor) x += 60 self.w.stroke = CheckBox((x, y, 95, 18), "Stroke", callback=self.strokeCallback, value=self._stroke, sizeStyle="small") x += 60 self.w.strokeColor = ColorWell((x, y, 45, 20), callback=self.strokeColorCallback, color=self._strokeColor) x += 60 self.w.points = CheckBox((x, y, 95, 18), "Points", callback=self.pointsCallback, value=self._points, sizeStyle="small") x += 60 self.w.pointsColor = ColorWell((x, y, 45, 20), callback=self.pointsColorCallback, color=self._pointsColor) x, y = 10, 40 self.w.alignText = TextBox((x, y, 250, 15), "Alignment:", sizeStyle="small") y += 18 self.w.alignment = RadioGroup((x, y, 80, 55), ['Left', 'Center', 'Right'], isVertical=True, callback=self.alignmentCallback, sizeStyle="small") self.w.alignment.set(self._alignment) y += 62 self.w.kerning = CheckBox((x, y, 100, 10), "Show kerning", callback=self.kerningCallback, value=self._kerning, sizeStyle="mini") y += 18 self.w.floating = CheckBox((x, y, 100, 10), "Floating Window", callback=self.floatingCallback, value=self._floating, sizeStyle="mini") y += 25 self.w.resetDefaults = Button((x, y, 85, 14), "Reset settings", callback=self.resetSettingsCallback, sizeStyle="mini") x, y = 110, 40 self.w.fontList = List((x, y, 240, 55), self.getFontItems(), columnDescriptions=self.getListDescriptor(), showColumnTitles=False, selectionCallback=None, doubleClickCallback=self.fontListCallback, allowsMultipleSelection=True, allowsEmptySelection=True, drawVerticalLines=False, drawHorizontalLines=True, drawFocusRing=False, rowHeight=16 ) y += 55 self.w.hiddenFontList = List((x, y, 240, 55), self.getHiddenFontItems(), columnDescriptions=self.getListDescriptor(), showColumnTitles=False, selectionCallback=None, doubleClickCallback=self.hiddenFontListCallback, allowsMultipleSelection=True, allowsEmptySelection=True, drawVerticalLines=False, drawHorizontalLines=True, drawFocusRing=False, rowHeight=16 ) self._selectionChanging = False self.w.fontList.setSelection([]) # unselect y += 65 self.w.contextLeft = EditText((x, y, 90, 20), callback=self.contextCallback, continuous=True, placeholder="Left", sizeStyle="small") self.w.contextCurrent = EditText((x+95, y, 50, 20), callback=self.contextCallback, continuous=True, placeholder="?", sizeStyle="small") self.w.contextRight = EditText((x+150, y, 90, 20), callback=self.contextCallback, continuous=True, placeholder="Right", sizeStyle="small") x, y = 360, 100 self.w.addFonts = Button((x, y, 30, 20), "+", callback=self.addHiddenFontsCallback, sizeStyle="regular") y += 25 self.w.removeFonts = Button((x, y, 30, 20), unichr(8722), callback=self.removeHiddenFontsCallback, sizeStyle="regular") # Observers addObserver(self, "fontDidOpen", "fontDidOpen") addObserver(self, "fontWillClose", "fontWillClose") # fontDidClose? addObserver(self, "draw", "drawInactive") addObserver(self, "draw", "draw") # Prepare and open window self.setWindowLevel() self.setUpBaseWindowBehavior() self.w.open()
def __init__(self): self.w = FloatingWindow((self._width + 2 * self._frame, self._height), self._title) # ---------- # text boxes # ---------- textBoxY = self._padding self.w.steps_label = TextBox( (self._col_0, textBoxY, self._col_width, self._lineHeight), 'Steps', alignment='right') if rfVersion >= 3.4: self.w.steps_text = NumberEditText( (self._col_1, textBoxY - 2, self._col_width, self._lineHeight), self.steps, callback=self.angleCallback, allowFloat=False, allowNegative=False, allowEmpty=False, minimum=1, decimals=0, continuous=True) else: self.w.steps_text = EditText( (self._col_1, textBoxY - 2, self._col_width, self._lineHeight), self.steps, callback=self.angleCallback, continuous=True) textBoxY += (self._row) self.w.xValue_label = TextBox( (self._col_0, textBoxY, self._col_width, self._lineHeight), 'x', alignment='right') if rfVersion >= 3.4: self.w.xValue_text = NumberEditText( (self._col_1, textBoxY - 2, self._col_width, self._lineHeight), self.xValue, callback=self.xCallback, allowFloat=True, decimals=0) else: self.w.xValue_text = EditText( (self._col_1, textBoxY - 2, self._col_width, self._lineHeight), self.xValue, callback=self.xCallback) textBoxY += (self._row) self.w.yValue_label = TextBox( (self._col_0, textBoxY, self._col_width, self._lineHeight), 'y', alignment='right') if rfVersion >= 3.4: self.w.yValue_text = NumberEditText( (self._col_1, textBoxY - 2, self._col_width, self._lineHeight), self.yValue, callback=self.yCallback, allowFloat=True, decimals=0) else: self.w.yValue_text = EditText( (self._col_1, textBoxY - 2, self._col_width, self._lineHeight), self.yValue, callback=self.yCallback) textBoxY += (self._row) self.w.angle_label = TextBox( (self._col_0, textBoxY, self._col_width, self._lineHeight), 'Angle', alignment='right') self.w.angleResult = TextBox( (self._col_1, textBoxY, self._col_width, self._lineHeight), u'%s°' % self.niceAngleString(self.angle)) textBoxY += (self._row) textBoxY += (self._row * .25) self.w.line = HorizontalLine( (self._gutter, textBoxY, -self._gutter, 0.5)) textBoxY += (self._row * .25) self.w.lock_checkbox = CheckBox( (self._col_1 - 25, textBoxY, -self._gutter, self._lineHeight), 'Lock Center', value=self.lock, callback=self.lockCallback) textBoxY += (self._row) self.w.rounding_checkbox = CheckBox( (self._col_1 - 25, textBoxY, -self._gutter, self._lineHeight), 'Round Result', value=self.rounding, callback=self.roundingCallback) textBoxY += (self._row) # ------- # buttons # ------- self.w.color = ColorWell( (self._col_0, textBoxY, -self._gutter, 2 * self._lineHeight), color=getExtensionDefaultColor( '%s.%s' % (rotatorDefaults, 'color'), self._color), callback=self.colorCallback) textBoxY += (self._row) self.w.buttonRotate = Button( (self._col_0, -30, -self._gutter, self._lineHeight), 'Rotate', callback=self.rotateCallback) self.setUpBaseWindowBehavior() addObserver(self, 'updateOrigin', 'mouseDragged') addObserver(self, 'drawRotationPreview', 'drawBackground') addObserver(self, 'drawSolidPreview', 'drawPreview') self.w.setDefaultButton(self.w.buttonRotate) self.w.open()
def markCallback(self, sender): self.doMarkGlyphs = sender.get() if self.doMarkGlyphs == 1: self.w.colorWell = ColorWell((-265, -85, 100, 23), callback=self.colorCallback, color=self.mark) else: del self.w.colorWell