def __init__(self, parameter, posSize, title=None, callback=None): super(ParameterSliderTextInput, self).__init__(posSize) self.parameter = parameter self.callback = callback editTextPosSize = (-65, 0, 40, 22) if title is None: sliderPosSize = (5, 3, -80, 15) elif title is not None: title = title.capitalize() sliderPosSize = (70, 3, -80, 15) self.title = TextBox((0, 3, 65, 30), title, sizeStyle='small') if parameter.dissociable: editTextPosSize = (-65, 0, 40, 22) self.checkBox = CheckBox((-22, 5, 22, 25), u'∞', callback=self.setFree, value=True, sizeStyle='mini') self.slider = Slider(sliderPosSize, minValue=parameter.limits[0], maxValue=parameter.limits[1], value=parameter.value, callback=self.valueInput, sizeStyle='small') self.textInput = EditText(editTextPosSize, str(parameter.value), callback=self.valueInput, continuous=False, sizeStyle='small') self.parameter.bind(self)
class SliderGroup(Group): def __init__(self, posSize, minValue, maxValue, value, callback): Group.__init__(self, posSize) self.slider = Slider( (2, 3, -55, 17), minValue=minValue, maxValue=maxValue, value=value, sizeStyle="regular", callback=self.sliderChanged) self.edit = EditText( (-40, 0, -0, 22), text=str(value), placeholder=str(value), callback=self.editChanged) self.callback = callback def sliderChanged(self, sender): self.edit.set(str(int(self.slider.get()))) self.callback(sender) def editChanged(self, sender): try: value = int(float(self.edit.get())) except ValueError: value = int(self.edit.getPlaceholder()) self.edit.set(value) self.slider.set(value) self.callback(sender)
def __init__(self): self.font = Glyphs.font # Returns the current that is open in GlyphsApp self.currentGlyphName = 'H' self.glyph = self.font[self.currentGlyphName].layers[0] lsb = int(round(self.glyph.LSB)) rsb = int(round(self.glyph.RSB)) pad = 10 leading = 32 y = pad w = 300 h = 400 buttonWidth = 100 buttonHeight = 48 self.w = Window((100, 100, w, h), 'DemoWindowTool') self.w.doDraw = CheckBox((pad, y, 100, 24), 'Draw', callback=self.doDrawCallback) y += leading self.w.leftMarginLabel = TextBox((pad, y, -pad, 24), 'Left margin') y += leading / 2 self.w.leftMarginSlider = Slider( (pad, y, -pad - 60, 24), minValue=MIN_LSB, maxValue=MAX_LSB, value=lsb, tickMarkCount=10, callback=self.leftMarginSliderCallback) self.w.leftMarginBox = EditText((-pad - 60 + pad, y, -pad, 24), callback=self.leftMarginBoxCallback) self.w.leftMarginBox.set(str(lsb)) y += leading self.w.rightMarginLabel = TextBox((pad, y, -pad, 24), 'Right margin') y += leading / 2 self.w.rightMarginSlider = Slider( (pad, y, -pad - 60, 24), minValue=MIN_RSB, maxValue=MAX_RSB, value=rsb, tickMarkCount=10, callback=self.rightMarginSliderCallback) self.w.rightMarginBox = EditText((-pad - 60 + pad, y, -pad, 24), callback=self.rightMarginBoxCallback) self.w.rightMarginBox.set(str(rsb)) y = self.w.saveFont = Button((-buttonWidth - pad, -buttonHeight - pad, buttonWidth, buttonHeight), 'Save', callback=self.saveFontCallback) self.w.open()
def __init__(self, posSize, text, minValue, maxValue, value, callback): Group.__init__(self, posSize) self.text = TextBox((0, 0, -0, 20), text) self.slider = Slider((2, 20, -60, 17), minValue=minValue, maxValue=maxValue, value=value, sizeStyle="small", callback=self.sliderChanged) self.edit = EditText((-40, 15, -0, 22), text=str(value), placeholder=str(value), callback=self.editChanged) self.callback = callback
def __init__(self, glyph): # if glyph is None, show a message if glyph is None: Message('no glyph selected', title='moveTool', informativeText='Please select one glyph first!') return # store the glyph and initial move values as object attributes self.glyph = glyph self.moveXTRA = 0 # create a floating window self.w = FloatingWindow((200, 74), "move %s" % self.glyph.name) # add a slider for moving in the x axis self.w.sliderXTRA = Slider((10, 10, -10, 22), value=0, maxValue=200, minValue=0, callback=self.adjustXTRA) # self.w.sliderXOPQ = Slider( # (10, 10, -10, 22), # value=0, maxValue=200, minValue=-200, # callback=self.adjust) # open the window self.w.open()
def showWindow_(self, sender): try: from vanilla import Group, Slider, TextBox, Window self.windowWidth = 300 self.windowHeight = 240 self.w = Window((self.windowWidth, self.windowWidth), "Rotate View", minSize=(self.windowWidth, self.windowWidth + 20)) self.w.Preview = RoatatePreview((0, 0, -0, -60)) self.w.controlBox = Group((0, -60, -0, -0)) self.w.controlBox.slider = Slider((10, 6, -10, 23), tickMarkCount=17, callback=self.sliderCallback, value=0, minValue=-360, maxValue=360) self.w.controlBox.textBox = TextBox((10, -25, -10, 22), text="0.00°", alignment="center") self.w.controlBox.slider.getNSSlider().setEnabled_(False) self.w.open() self.changeGlyph_(None) Glyphs.addCallback( self.changeGlyph_, UPDATEINTERFACE ) #will be called on ever change to the interface except: print(traceback.format_exc())
def __init__(self): self.glyph = None # Typical RoboFont function self.updating = False pad = 10 leading = 32 y = pad w = 300 h = 400 buttonWidth = 100 buttonHeight = 48 self.w = FloatingWindow((100, 100, w, h), 'DemoWindowTool') self.w.doDraw = CheckBox((pad, y, 100, 24), 'Draw', callback=self.doDrawCallback) y += leading self.w.mySlider = Slider((pad, y, -pad, 24), minValue=0, maxValue=2000, value=0, tickMarkCount=10, callback=self.mySliderCallback) y = self.w.saveFont = Button((-buttonWidth - pad, -buttonHeight - pad, buttonWidth, buttonHeight), 'Save', callback=self.saveFontCallback) addObserver(self, "currentGlyphChanged", "currentGlyphChanged") # Subscribe to application event addObserver(self, 'draw', 'draw') addObserver(self, 'drawBackground', 'drawBackground') self.w.bind('close', self.windowCloseCallback) self.w.open()
def __init__(self, parameter, posSize, title=None, callback=None): super(ParameterSliderTextInput, self).__init__(posSize) self.parameter = parameter self.callback = callback editTextPosSize = (-65, 0, 40, 22) if title is None: sliderPosSize = (5, 3, -80, 15) elif title is not None: if "point" in title: title = title.lstrip("point") title = "p. " + title title = title.capitalize() sliderPosSize = (70, 3, -80, 15) self.title = TextBox((0, 3, 65, 30), title, sizeStyle="small") if parameter.dissociable: editTextPosSize = (-65, 0, 40, 22) self.checkBox = CheckBox((-22, 5, 22, 25), u"∞", callback=self.setFree, value=True, sizeStyle="mini") self.parameter.bind(self.checkBox) self.slider = Slider( sliderPosSize, minValue=parameter.limits[0], maxValue=parameter.limits[1], value=parameter.value, callback=self.valueInput, sizeStyle="small", ) self.textInput = EditText( editTextPosSize, str(parameter.value), callback=self.valueInput, continuous=False, sizeStyle="small" ) self.parameter.bind(self) self.parameter.bind(self.slider) self.parameter.bind(self.textInput)
def showWindow_(self, sender): if Glyphs.font is None: self.helperWindow(self.warningNoFontOpen) elif len(Glyphs.font.masters) < 2: self.helperWindow(self.warningOnlyOneMaster) else: mastersList = [] for m in Glyphs.font.masters: mastersList.append(m.name) currentMasterIndex = Glyphs.font.masterIndex self.windowWidth = 250 self.windowHeight = 25 * len(mastersList) + 23 + 30 self.w = FloatingWindow((self.windowWidth, self.windowHeight), self.name) self.w.radiomasters = RadioGroup( (10, 10, -10, 25 * len(mastersList)), mastersList, callback=self.changeMaster) self.w.slider = Slider((10, -35, -10, 23), tickMarkCount=len(mastersList), stopOnTickMarks=True, value=currentMasterIndex, minValue=0, maxValue=len(mastersList) - 1, sizeStyle="small", continuous=False, callback=self.changeMasterSlider) self.w.open()
def __init__(self): """ Use "accuracy" in UI because it's easier to understand, but convert to "tolerance" because it's easier to use in parallel slope math later. """ self.maxValue = 5 self.w = ShowHideWindow((150, 60), "Set Accuracy") self.w.accuracySlider = Slider( (10, 9, -10, 23), minValue=0, maxValue=self.maxValue, value=self.maxValue - hf.readSetting(settingDir), sizeStyle="small", callback=self.accuracySliderCB) self.w.lessText = TextBox((10, 30, -10, 12), text="Less", sizeStyle="small") self.w.moreText = TextBox((10, 30, -10, 12), text="More", alignment="right", sizeStyle="small") self.w.center() self.w.makeKey()
def __init__(self): # create a window self.w = Window((400, 400), minSize=(200, 200)) # add a slider self.w.slider = Slider((10, 10, -10, 22), callback=self.sliderCallback) # add a drawBox view self.w.drawBotCanvas = DrawView((0, 40, -0, -0)) # draw something self.drawIt() # open the window self.w.open()
def __init__(self, parent): self.parent = parent self.w = FloatingWindow((150, 130), "Speed Punk %s" % VERSION, closable = False, autosaveName = 'de_yanone_speedPunk_%s.prefWindow' % (environment), ) self.w.illustrationPositionRadioGroup = RadioGroup((10, 10, -10, 40), ["Outside of glyph", "Outer side of curve"], callback=self.radioGroupCallback, sizeStyle = "small") self.w.curveGainTextBox = TextBox((10, 60, -10, 17), "Gain", sizeStyle = "mini") self.w.curveGainSlider = Slider((10, 70, -10, 25), tickMarkCount=5, callback=self.curveGainSliderCallback, sizeStyle = "small", minValue = curveGain[0], maxValue = curveGain[1], value = self.parent.getPreference('curveGain')) self.w.illustrationPositionRadioGroup.set(self.parent.getPreference('illustrationPositionIndex')) self.w.faderCheckBox = CheckBox((10, 100, -10, 17), "Fader", sizeStyle = "small", callback = self.faderCheckBoxCallback) self.w.faderSlider = Slider((10, 125, -10, 25), sizeStyle = "small", minValue = 0, maxValue = 1.0, value = 1.0, callback = self.faderSliderCallback) self.w.gradientImage = ImageView((10, 150, -10, 15)) self.w.histogramImage = ImageView((10, 150, -10, 15))
def __init__(self): self.w = HUDFloatingWindow((self.getWindowPostition()[0], self.getWindowPostition()[1], 200, 60), "BezierSurgeon", closable=False) self.w.getNSWindow().setTitleVisibility_(True) self.w.getNSWindow().setTitlebarAppearsTransparent_(True) self.w.sliderVal = Slider( (10, 0, -10, 22), value=0.500, maxValue=1, minValue=0, callback=self.getValues) self.w.sliderVal.enable(False) self.w.button = SquareButton((85, 25, 30, 25), "✁", callback=self.insertPoint) self.w.button.enable(False) self.setUpBaseWindowBehavior() self.addObservers() self.w.open()
def __init__(self, posSize, minValue, maxValue, value, callback): Group.__init__(self, posSize) self.slider = Slider( (2, 3, -55, 17), minValue=minValue, maxValue=maxValue, value=value, sizeStyle="regular", callback=self.sliderChanged) self.edit = EditText( (-40, 0, -0, 22), text=str(value), placeholder=str(value), callback=self.editChanged) self.callback = callback
def __init__(self, posSize, label, minValue, value, maxValue, continuous=True, callback=None): super().__init__(posSize) self._callback = callback self.label = TextBox((0, 0, 0, 20), label) self.slider = Slider((0, 18, -60, 20), value=minValue, minValue=minValue, maxValue=maxValue, continuous=continuous, callback=self._sliderCallback) self.editField = EditText((-50, 16, 0, 24), "", continuous=False, callback=self._editFieldCallback) self.editField._nsObject.setAlignment_(AppKit.NSRightTextAlignment) self._setSliderFromValue(value) self._setEditFieldFromValue(value)
def __init__(self): self.f = CurrentFont() self.u = getKerningPairsFromUFO.UFOkernReader(self.f) self.absKerning = int(self.u.absoluteKerning) self.amountOfPairs = len(self.u.allKerningPairs) self.textString = ('The font has %s flat kerning pairs.\n' 'Set at %s points, the absolute amount\n' 'of kerning would cover the distance of\n%s.') wWidth = 300 wHeight = 250 if self.amountOfPairs: message = u'CONGRATULATIONS! \U0001F600' else: message = u'Bummer. \U0001F622' self.w = Window((wWidth, wHeight), message) self.w.measurementSystem = RadioGroup((20, 15, -10, 20), ["Metric", "Imperial"], callback=self.parametersChanged, isVertical=False) self.w._pointSize = TextBox((20, 145, -30, 17), 'Point size:') self.w.pointSize = Slider((100, 145, -30, 17), minValue=0, maxValue=1000, callback=self.parametersChanged, value=12) pointSize = int(self.w.pointSize.get()) absKerning = int(self.absKerning * (pointSize / self.f.info.unitsPerEm)) self.w.text = TextBox( (20, 45, -20, 85), self.textString % (self.amountOfPairs, int( self.w.pointSize.get()), self.convertToMetric(absKerning))) self.w.button = Button((20, -40, -30, 20), "Copy kerning pairs to clipboard", callback=self.button) self.w.open()
def _buildUI(self): w = FloatingWindow((300, 340), "Rotated Glyph Preview", (300, 340), (2560, 1440)) w.preview = GlyphPreview((2, 2, -2, -40)) w.rotationSlider = Slider( (10, -30, -10, 20), minValue=-180, maxValue=180, value=self.settings["rotation"], tickMarkCount=5, stopOnTickMarks=False, continuous=True, callback=self._setRotation, sizeStyle="small", ) return w
def __init__(self, parameter, posSize, title=None, callback=None): super(ParameterSliderTextInput, self).__init__(posSize) self.parameter = parameter self.callback = callback editTextPosSize = (-45, 0, 45, 22) if title is None: sliderPosSize = (5, 3, -80, 15) elif title is not None: if len(title) > 15: title = '{0}.'.format(title[:16]) title = title.capitalize() sliderPosSize = (120, 3, -55, 15) self.title = TextBox((0, 3, 115, 30), title, sizeStyle='small') if parameter.dissociable: editTextPosSize = (-65, 0, 40, 22) self.checkBox = CheckBox((-22, 5, 22, 25), u'∞', callback=self.setFree, value=True, sizeStyle='mini') self.slider = Slider(sliderPosSize, minValue=parameter.limits[0], maxValue=parameter.limits[1], value=parameter.value, callback=self.valueInput, sizeStyle='small') self.textInput = EditText(editTextPosSize, str(parameter.value), callback=self.valueInput, continuous=False, sizeStyle='small') self.parameter.bind(self)
def __init__(self, glyph): # if glyph is None, show a message # store the glyph and initial move values as object attributes self.w = FloatingWindow((200, 64), "move "+str(labelslider)) for labelslider in BuildLabelsList(f): # create a floating window # add a slider for moving in the x axis self.g = glyph self.moveX = 0 self.label= labelslider self.w.labelslider = Slider( (10, 10, -10, 22), value=0, maxValue=100, minValue=-100, callback=self.adjust) # open the window self.w.button = Button((15, -35, -15, 20), "Done") self.w.open()
def showWindow_(self, sender): try: from vanilla import Group, Slider, TextBox, Window self.windowWidth = 300 self.windowHeight = 240 self.w = Window((self.windowWidth, self.windowWidth), "Rotate View", minSize=(self.windowWidth, self.windowWidth)) window = self.w.getNSWindow() window.setStyleMask_(window.styleMask() | NSFullSizeContentViewWindowMask) try: # only available in 10.10 window.setTitlebarAppearsTransparent_(True) except: pass #window.toolbar = nil; window.setMovableByWindowBackground_(True) self.w.Preview = RoatatePreview((0, 0, -0, -28)) self.w.controlBox = Group((0, -28, -0, -0)) self.w.controlBox.slider = Slider((10, 2, -55, 28), tickMarkCount=17, callback=self.sliderCallback, value=0, minValue=-360, maxValue=360) self.w.controlBox.textBox = TextBox((-55, -23, -5, -3), text="0°", alignment="center") self.w.controlBox.slider.getNSSlider().setEnabled_(False) self.w.open() self.changeGlyph_(None) Glyphs.addCallback( self.changeGlyph_, UPDATEINTERFACE ) #will be called on ever change to the interface except: print(traceback.format_exc())
def __init__(self): self.fontName = "Bitcount Grid Single" fnt = getFont(self.fontName) axesInfo = getAxisInfo(fnt) self.w = Window((500, 400), "Test", minSize=(300, 200)) # self.w.button = Button((10, 10, 120, 24), "Click", callback=self.myCallback) y = 10 self.sliderMapping = {} for index, axisInfo in enumerate(axesInfo): slider = Slider((10, y, 130, 24), value=axisInfo['default'], minValue=axisInfo['minValue'], maxValue=axisInfo['maxValue'], callback=self.sliderChanged) self.sliderMapping[slider] = axisInfo['tag'] setattr(self.w, "slider_%s" % index, slider) y += 34 self.w.textEditor = TextEditor((150, 0, 0, 0)) attrs = {AppKit.NSFontAttributeName: fnt} self.w.textEditor._textView.setTypingAttributes_(attrs) self.w.open()
class SliderGroup(Group): def __init__(self, posSize, text, minValue, maxValue, value, callback): Group.__init__(self, posSize) self.text = TextBox((0, 0, -0, 20), text) self.slider = Slider((2, 20, -60, 17), minValue=minValue, maxValue=maxValue, value=value, sizeStyle="small", callback=self.sliderChanged) self.edit = EditText((-40, 15, -0, 22), text=str(value), placeholder=str(value), callback=self.editChanged) self.callback = callback def sliderChanged(self, sender): self.edit.set(str(int(self.slider.get()))) self.callback(sender) def editChanged(self, sender): try: value = int(float(self.edit.get())) except ValueError: value = int(self.edit.getPlaceholder()) self.edit.set(value) self.slider.set(value) def enable(self): self.text.enable(True) self.slider.enable(True) self.edit.enable(True) def disable(self): self.text.enable(False) self.slider.enable(False) self.edit.enable(False)
class ParameterSliderTextInput(Group): """ Custom Vanilla object consisting mainly of a Slider & and text input linked together (through a parameter object) """ def __init__(self, parameter, posSize, title=None, callback=None): super(ParameterSliderTextInput, self).__init__(posSize) self.parameter = parameter self.callback = callback editTextPosSize = (-65, 0, 40, 22) if title is None: sliderPosSize = (5, 3, -80, 15) elif title is not None: if "point" in title: title = title.lstrip("point") title = "p. " + title title = title.capitalize() sliderPosSize = (70, 3, -80, 15) self.title = TextBox((0, 3, 65, 30), title, sizeStyle="small") if parameter.dissociable: editTextPosSize = (-65, 0, 40, 22) self.checkBox = CheckBox((-22, 5, 22, 25), u"∞", callback=self.setFree, value=True, sizeStyle="mini") self.parameter.bind(self.checkBox) self.slider = Slider( sliderPosSize, minValue=parameter.limits[0], maxValue=parameter.limits[1], value=parameter.value, callback=self.valueInput, sizeStyle="small", ) self.textInput = EditText( editTextPosSize, str(parameter.value), callback=self.valueInput, continuous=False, sizeStyle="small" ) self.parameter.bind(self) self.parameter.bind(self.slider) self.parameter.bind(self.textInput) def enable(self, b): self.slider.enable(b) self.textInput.enable(b) if hasattr(self, checkBox): self.checkBox.enable(b) def valueInput(self, sender): value = sender.get() parameter = self.parameter if value == "R": parameter.reset() parameter.update() if self.callback is not None: self.callback(self) return elif value != "*": parameter.setInput(value, sender=sender) parameter.update() if self.callback is not None: self.callback(self) def setFree(self, sender): value = bool(sender.get()) self.parameter.setFree(value)
def __init__(self): flushAlign = 76 firstRowY = 12 rowOffsetY = 30 firstCheckY = 135 checkOffsetY = 27 rightMarginX = -12 self.windowWidth = 410 self.windowHeightWithoutOptions = 45 self.windowHeightWithOptions = 280 self.scriptIsRTL = False windowPos = getExtensionDefault("%s.%s" % (extensionKey, "windowPos")) if not windowPos: windowPos = (100, 100) self.optionsVisible = getExtensionDefault( "%s.%s" % (extensionKey, "optionsVisible")) if self.optionsVisible: optionsButtonSign = '-' windowHeight = self.windowHeightWithOptions else: self.optionsVisible = False # needs to be set because the first time the extension runs self.optionsVisible will be None optionsButtonSign = '+' windowHeight = self.windowHeightWithoutOptions self.chars = getExtensionDefault("%s.%s" % (extensionKey, "chars")) if not self.chars: self.chars = '' self.sliderValue = getExtensionDefault("%s.%s" % (extensionKey, "sliderValue")) if not self.sliderValue: self.sliderValue = 25 self.scriptsIndex = getExtensionDefault("%s.%s" % (extensionKey, "scriptsIndex")) if not self.scriptsIndex: self.scriptsIndex = 0 self.langsIndex = getExtensionDefault("%s.%s" % (extensionKey, "langsIndex")) if not self.langsIndex: self.langsIndex = 0 self.w = FloatingWindow( (windowPos[0], windowPos[1], self.windowWidth, windowHeight), "adhesiontext") # 1st row self.w.labelChars = TextBox((10, firstRowY, flushAlign, 20), "Characters:", alignment="right") self.w.chars = EditText((flushAlign + 15, firstRowY - 1, 199, 22), self.chars, callback=self.charsCallback) self.w.button = Button((300, firstRowY, 68, 20), "Get text", callback=self.buttonCallback) self.w.spinner = FixedSpinner((325, firstRowY, 20, 20), displayWhenStopped=False) self.w.optionsButton = SquareButton((378, firstRowY + 1, 18, 18), optionsButtonSign, sizeStyle="small", callback=self.optionsCallback) # set the initial state of the button according to the content of the chars EditText if len(self.w.chars.get()): self.w.button.enable(True) else: self.w.button.enable(False) # keep track of the content of chars EditText self.previousChars = self.w.chars.get() # 2nd row self.w.labelWords = TextBox( (10, firstRowY + rowOffsetY, flushAlign, 20), "Words:", alignment="right") self.w.wordCount = TextBox( (flushAlign + 12, firstRowY + rowOffsetY, 40, 20), alignment="left") self.w.slider = Slider( (flushAlign + 47, firstRowY + rowOffsetY + 1, 165, 20), value=self.sliderValue, minValue=5, maxValue=200, callback=self.sliderCallback) # set the initial wordCount value according to the position of the slider self.w.wordCount.set(int(self.w.slider.get())) # 3rd row self.w.labelScripts = TextBox( (10, firstRowY + rowOffsetY * 2, flushAlign, 20), "Script:", alignment="right") self.w.scriptsPopup = PopUpButton( (flushAlign + 15, firstRowY + rowOffsetY * 2, 150, 20), scriptsNameList, callback=self.scriptsCallback) self.w.scriptsPopup.set(self.scriptsIndex) # 4th row self.w.labelLangs = TextBox( (10, firstRowY + rowOffsetY * 3, flushAlign, 20), "Language:", alignment="right") self.w.langsPopup = PopUpButton( (flushAlign + 15, firstRowY + rowOffsetY * 3, 150, 20), []) # set the initial list of languages according to the script value self.w.langsPopup.setItems( langsNameDict[scriptsNameList[self.w.scriptsPopup.get()]]) self.w.langsPopup.set(self.langsIndex) self.punctCheck = getExtensionDefault("%s.%s" % (extensionKey, "punctCheck")) if not self.punctCheck: self.punctCheck = 0 self.figsCheck = getExtensionDefault("%s.%s" % (extensionKey, "figsCheck")) if not self.figsCheck: self.figsCheck = 0 self.figsPopup = getExtensionDefault("%s.%s" % (extensionKey, "figsPopup")) if not self.figsPopup: self.figsPopup = 0 self.trimCheck = getExtensionDefault("%s.%s" % (extensionKey, "trimCheck")) if not self.trimCheck: self.trimCheck = 0 self.caseCheck = getExtensionDefault("%s.%s" % (extensionKey, "caseCheck")) if not self.caseCheck: self.caseCheck = 0 self.casingCheck = getExtensionDefault("%s.%s" % (extensionKey, "casingCheck")) if not self.casingCheck: self.casingCheck = 0 self.casingPopup = getExtensionDefault("%s.%s" % (extensionKey, "casingPopup")) if not self.casingPopup: self.casingPopup = 0 # 1st checkbox self.w.punctCheck = CheckBox((flushAlign + 15, firstCheckY, 130, 20), "Add punctuation") self.w.punctCheck.set(self.punctCheck) # 2nd checkbox self.w.figsCheck = CheckBox( (flushAlign + 15, firstCheckY + checkOffsetY, 120, 20), "Insert numbers", callback=self.figsCallback) self.w.figsCheck.set(self.figsCheck) self.w.figsPopup = PopUpButton( (210, firstCheckY + checkOffsetY, 90, 20), figOptionsList) self.w.figsPopup.set(self.figsPopup) # enable or disable the figure options PopUp depending on the figures CheckBox if scriptsNameList[self.w.scriptsPopup.get()] in enableFigOptionList: self.w.figsPopup.show(True) if self.w.figsCheck.get(): self.w.figsPopup.enable(True) else: self.w.figsPopup.enable(False) else: self.w.figsPopup.show(False) # 3rd checkbox self.w.trimCheck = CheckBoxPlus( (flushAlign + 15, firstCheckY + checkOffsetY * 2, 120, 20), "Trim accents") self.w.trimCheck.set(self.trimCheck) if scriptsNameList[self.w.scriptsPopup.get()] in enableTrimCheckList: self.w.trimCheck.enable(True) else: self.w.trimCheck.enable(False) # 4th checkbox self.w.caseCheck = CheckBoxPlus( (flushAlign + 15, firstCheckY + checkOffsetY * 3, 120, 20), "Ignore casing") self.w.caseCheck.set(self.caseCheck) if scriptsNameList[self.w.scriptsPopup.get()] in enableCaseCheckList: self.w.caseCheck.enable(True) else: self.w.caseCheck.enable(False) # 5th checkbox self.w.casingCheck = CheckBoxPlus( (flushAlign + 15, firstCheckY + checkOffsetY * 4, 115, 20), "Change casing", callback=self.casingCallback) self.w.casingCheck.set(self.casingCheck) if scriptsNameList[self.w.scriptsPopup.get()] in enableCaseCheckList: self.w.casingCheck.enable(True) else: self.w.casingCheck.enable(False) self.w.casingPopup = PopUpButton( (210, firstCheckY + checkOffsetY * 4, 90, 20), casingNameList) self.w.casingPopup.set(self.casingPopup) # enable or disable the casing PopUp depending on the casing CheckBox if self.w.casingCheck.get() and self.w.casingCheck.isEnable(): self.w.casingPopup.enable(True) else: self.w.casingPopup.enable(False) self.nsTextField = self.w.chars.getNSTextField() self.w.setDefaultButton(self.w.button) self.w.bind("close", self.windowClose) self.w.open() self.w.makeKey()
def build_ui(self, useFloatingWindow=True): self.methods = { 0: "balance", 1: "free", 2: "hobby", } self.methodNames = [ "Balance", "Adjust:", "Hobby:", ] height = 108 width = 200 sliderX = 76 if useFloatingWindow: self.paletteView = FloatingWindow( posSize=(width, height), title="Curve EQ", minSize=(width, height + 16), maxSize=(1000, height + 16), ) else: self.paletteView = Window((width, height)) self.paletteView.group = Group((0, 0, width, height)) y = 8 self.paletteView.group.eqMethodSelector = RadioGroup( (8, y, -8, -36), titles=self.methodNames, callback=self._changeMethod, sizeStyle="small", ) y += 22 self.paletteView.group.eqCurvatureSlider = Slider( (sliderX, y, -8, 17), callback=self._changeCurvatureFree, minValue=0.5, maxValue=1.0, value=0.75, # Will be replaced by saved value sizeStyle="small", ) y += 25 self.paletteView.group.eqHobbyTensionSlider = Slider( (sliderX, y, -8, 17), tickMarkCount=5, callback=self._changeTension, minValue=0.5, maxValue=1.0, sizeStyle="small", ) if useFloatingWindow: y = height - 32 self.paletteView.group.eqSelectedButton = Button( (8, y, -8, 25), "Equalize Selected", callback=self._eqSelected, sizeStyle="small", )
def __init__(self, parent): self.parent = parent self.w = FloatingWindow((150, 130), "Speed Punk %s" % VERSION, closable = False, autosaveName = 'de_yanone_speedPunk_%s.prefWindow' % (environment), ) self.w.illustrationPositionRadioGroup = RadioGroup((10, 10, -10, 40), ( Glyphs.localize({ 'en': 'Outside of glyph', 'de': 'Außen an Form', 'fr': 'Éxterieur de la forme', 'es': 'Exterior del glifo', 'pt': 'Fora do glifo', }), Glyphs.localize({ 'en': 'Outer side of curve', 'de': 'Außen am Pfad', 'fr': 'Éxterieur de la courbe', 'es': 'Exterior del trazo', 'pt': 'Fora da curva', }), ), callback=self.radioGroupCallback, sizeStyle = "small") self.w.curveGainTextBox = TextBox((10, 60, -10, 17), Glyphs.localize({ 'en': 'Gain', 'de': 'Stärke', 'fr': 'Volume', 'es': 'Volumen', 'pt': 'Volume', }), sizeStyle = "mini") self.w.curveGainSlider = Slider((10, 70, -10, 25), tickMarkCount=5, callback=self.curveGainSliderCallback, sizeStyle = "small", minValue = curveGain[0], maxValue = curveGain[1], value = self.parent.getPreference('curveGain')) self.w.illustrationPositionRadioGroup.set(self.parent.getPreference('illustrationPositionIndex')) self.w.faderCheckBox = CheckBox((10, 100, -10, 17), Glyphs.localize({ 'en': 'Fade', 'de': 'Ausblenden', 'fr': 'Opacité', 'es': 'Opacidad', 'pt': 'Opacidade', }), sizeStyle = "small", callback = self.faderCheckBoxCallback) self.w.faderSlider = Slider((10, 125, -10, 25), sizeStyle = "small", minValue = 0, maxValue = 1.0, value = 1.0, callback = self.faderSliderCallback) self.w.gradientImage = ImageView((10, 150, -10, 15)) self.w.histogramImage = ImageView((10, 150, -10, 15))
def settings(self): from vanilla import Group, Slider, TextBox, Window self.name = 'Scrawl' self.slider_value = 1 # current slider value # Create Vanilla window and group with controls viewWidth = 266 viewHeight = 42 self.sliderMenuView = Window((viewWidth, viewHeight)) self.sliderMenuView.group = Group((0, 0, viewWidth, viewHeight)) self.w = self.sliderMenuView.group y = 0 self.w.text = TextBox((20, y, -20, 17), "%s Pen Size" % self.name) y += 18 self.w.pen_size = Slider( (20, y, -60, 24), minValue=1, maxValue=256, value=float(self.slider_value), tickMarkCount=0, # stopOnTickMarks = False, # continuuous = True, callback=self.slider_callback, sizeStyle="small", ) self.w.pen_size_text = TextBox((-50, y + 3, -20, 17), "%s" % default_pen_size) self.generalContextMenus = [ { "view": self.sliderMenuView.group.getNSView() }, { "name": Glyphs.localize({ 'en': u'Delete Scrawl', 'de': u'Gekritzel löschen' }), "action": self.delete_data }, { "name": Glyphs.localize({ 'en': u'Save Scrawl To Background Image', 'de': u'Gekritzel als Hintergrundbild speichern' }), "action": self.save_background }, # { # "name": Glyphs.localize({ # 'en': u'Save current size as master default', # 'de': u'Aktuelle Größe als Master-Standard speichern' # }), # "action": self.save_background # }, ] self.keyboardShortcut = 'c' self.pen_size = default_pen_size self.pixel_size = default_pixel_size self.pixel_ratio = default_pixel_ratio self.rect = NSMakeRect(0, 0, 1000, 1000) self.data = None self.prev_location = None self.erase = False self.mouse_position = None self.layer = None self.needs_save = False self.current_layer = self.get_current_layer()
def __init__(self): padding = 10 lineHeight = 20 buttonHeight = 20 width = 123 height = lineHeight * 6 + buttonHeight * 4 + padding * 9 self.w = FloatingWindow((width, height), title='spacing') x = y = padding self.w.makeGroupButton = Button((x, y, -padding, buttonHeight), 'make group', callback=self.makeGroupCallback, sizeStyle='small') y += buttonHeight + padding self.w.side = RadioGroup((x, y, -padding, lineHeight), ['left', 'right'], isVertical=False, callback=self.updateViewsCallback, sizeStyle='small') self.w.side.set(0) y += lineHeight + padding self.w.copySpacingButton = Button((x, y, -padding, buttonHeight), 'copy margin', callback=self.copySpacingCallback, sizeStyle='small') y += buttonHeight + padding self.w.useBeam = CheckBox((x, y, -padding, lineHeight), 'use beam', callback=self.useBeamCallback, sizeStyle='small') y += lineHeight self.w.allLayers = CheckBox((x, y, -padding, lineHeight), 'all layers', callback=self.updateViewsCallback, sizeStyle='small') y += lineHeight + padding self.w.opacityLabel = TextBox((x, y, -padding, lineHeight), 'opacity:', sizeStyle='small') y += lineHeight self.w.opacity = Slider((x, y, -padding, lineHeight), value=0.4, minValue=0.0, maxValue=0.9, callback=self.updateViewsCallback, sizeStyle='small') y += lineHeight + padding self.w.exportButton = Button((x, y, -padding, buttonHeight), 'export…', callback=self.exportCallback, sizeStyle='small') y += buttonHeight + padding self.w.importButton = Button((x, y, -padding, buttonHeight), 'import…', callback=self.importCallback, sizeStyle='small') y += buttonHeight + padding self.w.verbose = CheckBox((x, y, -padding, lineHeight), 'verbose', value=True, sizeStyle='small') self.setUpBaseWindowBehavior() addObserver(self, "drawGlyphsInGroup", "spaceCenterDraw") self.w.getNSWindow().setTitlebarAppearsTransparent_(True) self.w.open()
class SliderPlus(Group): _callback = weakrefCallbackProperty() def __init__(self, posSize, label, minValue, value, maxValue, continuous=True, callback=None): super().__init__(posSize) self._callback = callback self.label = TextBox((0, 0, 0, 20), label) self.slider = Slider((0, 18, -60, 20), value=minValue, minValue=minValue, maxValue=maxValue, continuous=continuous, callback=self._sliderCallback) self.editField = EditText((-50, 16, 0, 24), "", continuous=False, callback=self._editFieldCallback) self.editField._nsObject.setAlignment_(AppKit.NSRightTextAlignment) self._setSliderFromValue(value) self._setEditFieldFromValue(value) def _breakCycles(self): self._callback = None super()._breakCycles() def _sliderCallback(self, sender): value = sender.get() self._setEditFieldFromValue(value) callCallback(self._callback, self) def _editFieldCallback(self, sender): value = sender.get() if not value: # self._setSliderFromValue(None) callCallback(self._callback, self) return value = value.replace(",", ".") try: f = float(value) except ValueError: pass else: self.slider.set(f) sliderValue = self.slider.get() if sliderValue != f: self._setEditFieldFromValue(sliderValue) callCallback(self._callback, self) def _setSliderFromValue(self, value): if isinstance(value, set): value = sum(value) / len(value) elif value is None: minValue = self.slider._nsObject.minValue() maxValue = self.slider._nsObject.maxValue() value = (minValue + maxValue) / 2 self.slider.set(value) def _setEditFieldFromValue(self, value): if isinstance(value, set): if len(value) == 1: value = next(iter(value)) else: value = None if value is None: s = "" else: if int(value) == value: s = str(int(value)) else: s = f"{value:.1f}" self.editField.set(s) def get(self): if not self.editField.get(): return None else: return self.slider.get() def set(self, value): self._setSliderFromValue(value) self._setEditFieldFromValue(value)
class ParameterSliderTextInput(Group): ''' Custom Vanilla object consisting mainly of a Slider & and text input linked together (through a parameter object) ''' def __init__(self, parameter, posSize, title=None, callback=None): super(ParameterSliderTextInput, self).__init__(posSize) self.parameter = parameter self.callback = callback editTextPosSize = (-45, 0, 45, 22) if title is None: sliderPosSize = (5, 3, -80, 15) elif title is not None: if len(title) > 15: title = '{0}.'.format(title[:16]) title = title.capitalize() sliderPosSize = (120, 3, -55, 15) self.title = TextBox((0, 3, 115, 30), title, sizeStyle='small') if parameter.dissociable: editTextPosSize = (-65, 0, 40, 22) self.checkBox = CheckBox((-22, 5, 22, 25), u'∞', callback=self.setFree, value=True, sizeStyle='mini') self.slider = Slider(sliderPosSize, minValue=parameter.limits[0], maxValue=parameter.limits[1], value=parameter.value, callback=self.valueInput, sizeStyle='small') self.textInput = EditText(editTextPosSize, str(parameter.value), callback=self.valueInput, continuous=False, sizeStyle='small') self.parameter.bind(self) def get(self): return self.parameter.get() def enable(self, b): self.slider.enable(b) self.textInput.enable(b) if hasattr(self, checkBox): self.checkBox.enable(b) def valueInput(self, sender): value = sender.get() parameter = self.parameter if value == 'R': parameter.reset() parameter.update() if self.callback is not None: self.callback(self) return elif value != '*': parameter.setInput(value, sender=sender) parameter.update() if self.callback is not None: self.callback(self) def update(self, sender): value = self.parameter.get() self.textInput.set(str(value)) if (value != '*'): self.slider.set(value) if hasattr(self, 'checkBox'): free = self.parameter.hasMaster self.checkBox.set(free) def setFree(self, sender): value = not bool(sender.get()) self.parameter.setFree(value)
from vanilla import Window, Slider, Button # or from vanilla import * w = Window((400, 300), "My new window") w.mySlider = Slider((10, 10, 200, 20)) w.myButton = Button((10, 40, 100, 20), "Click me!") w.open()
class ParameterSliderTextInput(Group): ''' Custom Vanilla object consisting mainly of a Slider & and text input linked together (through a parameter object) ''' def __init__(self, parameter, posSize, title=None, callback=None): super(ParameterSliderTextInput, self).__init__(posSize) self.parameter = parameter self.callback = callback editTextPosSize = (-65, 0, 40, 22) if title is None: sliderPosSize = (5, 3, -80, 15) elif title is not None: title = title.capitalize() sliderPosSize = (70, 3, -80, 15) self.title = TextBox((0, 3, 65, 30), title, sizeStyle='small') if parameter.dissociable: editTextPosSize = (-65, 0, 40, 22) self.checkBox = CheckBox((-22, 5, 22, 25), u'∞', callback=self.setFree, value=True, sizeStyle='mini') self.slider = Slider(sliderPosSize, minValue=parameter.limits[0], maxValue=parameter.limits[1], value=parameter.value, callback=self.valueInput, sizeStyle='small') self.textInput = EditText(editTextPosSize, str(parameter.value), callback=self.valueInput, continuous=False, sizeStyle='small') self.parameter.bind(self) def get(self): return self.parameter.get() def enable(self, b): self.slider.enable(b) self.textInput.enable(b) if hasattr(self, checkBox): self.checkBox.enable(b) def valueInput(self, sender): value = sender.get() parameter = self.parameter if value == 'R': parameter.reset() parameter.update() if self.callback is not None: self.callback(self) return elif value != '*': parameter.setInput(value, sender=sender) parameter.update() if self.callback is not None: self.callback(self) def update(self, sender): value = self.parameter.get() self.textInput.set(str(value)) if (value != '*'): self.slider.set(value) if hasattr(self, 'checkBox'): free = self.parameter.hasMaster self.checkBox.set(free) def setFree(self, sender): value = not bool(sender.get()) self.parameter.setFree(value)