Ejemplo n.º 1
0
    def __init__(self, posSize, index, aFont, isTop, isBottom,
                 directionCallback, displayedCallback):
        super(FontRow, self).__init__(posSize)
        self.directionCallback = directionCallback
        self.displayedCallback = displayedCallback
        self.index = index
        self.ctrlFont = aFont

        squareButtonSide = FONT_ROW_HEIGHT - 6

        self.check = CheckBox(
            (0, 0, 16, vanillaControlsSize['CheckBoxRegularHeight']),
            '',
            value=self.isDisplayed,
            callback=self.checkCallback)

        self.caption = TextBox(
            (18, 2, 120, vanillaControlsSize['TextBoxRegularHeight']),
            '{}'.format(self.ctrlFont.info.styleName))

        self.buttonUp = SquareButton((-(squareButtonSide * 2 + MARGIN_COL), 0,
                                      squareButtonSide, squareButtonSide),
                                     u'↑',
                                     callback=self.buttonUpCallback)
        if isTop is True:
            self.buttonUp.show(False)

        self.buttonDw = SquareButton(
            (-squareButtonSide, 0, squareButtonSide, squareButtonSide),
            u'↓',
            callback=self.buttonDwCallback)
        if isBottom is True:
            self.buttonDw.show(False)
Ejemplo n.º 2
0
    def __init__(self, posSize, index, callback):
        super(LabelCtrl, self).__init__(posSize)
        self.callback = callback
        self.index = index

        self.jumpingX = 0
        self.attachButton = SquareButton((self.jumpingX, 0, self.attachButtonWidth, vanillaControlsSize['EditTextRegularHeight']),
                                         'Attach',
                                         sizeStyle='small',
                                         callback=self.attachButtonCallback)

        self.jumpingX += MARGIN_COL + self.attachButtonWidth
        self.labelNameEdit = EditText((self.jumpingX, 0, self.labelNameEditWidth, vanillaControlsSize['EditTextRegularHeight']),
                                      callback=self.labelNameEditCallback)

        self.jumpingX += MARGIN_COL + self.labelNameEditWidth
        self.plusButton = SquareButton((self.jumpingX, 0, self.plusButtonWidth, vanillaControlsSize['EditTextRegularHeight']),
                                       '+',
                                       sizeStyle='small',
                                       callback=self.plusButtonCallback)

        self.jumpingX += MARGIN_COL + self.lessButtonWidth
        self.lessButton = SquareButton((self.jumpingX, 0, self.lessButtonWidth, vanillaControlsSize['EditTextRegularHeight']),
                                       '-',
                                       sizeStyle='small',
                                       callback=self.lessButtonCallback)
Ejemplo n.º 3
0
    def __init__(self):

        # base window
        self.w = FloatingWindow((0, 0, PLUGIN_WIDTH, PLUGIN_HEIGHT))

        jumpingY = MARGIN_VER
        self.w.libChoice = PopUpButton(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['PopUpButtonRegularHeight']), ['A', 'B', 'C'],
            callback=self.libChoiceCallback)

        jumpingY += vanillaControlsSize['PopUpButtonRegularHeight'] + MARGIN_VER
        self.w.addButton = SquareButton(
            (MARGIN_HOR, jumpingY, NET_WIDTH * .6, SQUARE_BUTTON_HEIGHT),
            'add stem',
            callback=self.addButtonCallback)

        self.w.checkBoxStar = CheckBoxStar(
            (MARGIN_HOR + MARGIN_VER + NET_WIDTH * .6, jumpingY,
             NET_WIDTH * .35, NET_WIDTH * .35),
            callback=self.checkBoxStarCallback)

        jumpingY += SQUARE_BUTTON_HEIGHT + MARGIN_VER
        self.w.removeButton = SquareButton(
            (MARGIN_HOR, jumpingY, NET_WIDTH * .6, SQUARE_BUTTON_HEIGHT),
            'remove stem',
            callback=self.removeButtonCallback)

        # lit up!
        self.w.open()
Ejemplo n.º 4
0
    def __init__(self, posSize, callback):
        super(WordListController, self).__init__(posSize)
        x, y, self.ctrlWidth, self.ctrlHeight = posSize
        self.callback = callback

        # handling kerning words
        self.kerningWordsDB = loadKerningTexts(STANDARD_KERNING_TEXT_FOLDER)
        self.kerningTextBaseNames = self.kerningWordsDB.keys()
        self.activeKerningTextBaseName = self.kerningTextBaseNames[0]
        # this is the list used for data manipulation
        self.wordsWorkingList = self.kerningWordsDB[self.activeKerningTextBaseName]
        # this list instead is used for data visualization in the ctrl
        self._makeWordsDisplayList(self.activeKerningTextBaseName)
        self.activeWord = self.wordsWorkingList[0]['word']
        self.wordFilter = ''

        jumping_Y = 0
        self.kerningVocabularyPopUp = PopUpButton((0, jumping_Y, self.ctrlWidth*.6, vanillaControlsSize['PopUpButtonRegularHeight']),
                                                  self.kerningTextBaseNames,
                                                  callback=self.kerningVocabularyPopUpCallback)

        self.openTextsFolderButton = SquareButton((self.ctrlWidth*.62, jumping_Y, self.ctrlWidth*.38, vanillaControlsSize['PopUpButtonRegularHeight']+1),
                                                  'Load texts...',
                                                  sizeStyle='small',
                                                  callback=self.openTextsFolderButtonCallback)

        wordsColumnDescriptors = [
            {'title': '#', 'width': 30, 'editable': False},
            {'title': 'word', 'width': self.ctrlWidth-80, 'editable': False},
            {'title': 'done?', 'width': 35, 'cell': CheckBoxListCell(), 'editable': False}]

        jumping_Y += self.openTextsFolderButton.getPosSize()[3] + MARGIN_VER
        self.wordsListCtrl = List((0, jumping_Y, self.ctrlWidth, 170),
                                  self.wordsDisplayList,
                                  enableDelete=False,
                                  allowsMultipleSelection=False,
                                  columnDescriptions=wordsColumnDescriptors,
                                  selectionCallback=self.wordsListCtrlSelectionCallback,
                                  doubleClickCallback=self.wordsListCtrlDoubleClickCallback)

        jumping_Y += self.wordsListCtrl.getPosSize()[3] + MARGIN_VER
        self.wordsFilterCtrl = EditText((-70, jumping_Y-1, 70, vanillaControlsSize['EditTextRegularHeight']),
                                        placeholder='filter...',
                                        callback=self.wordsFilterCtrlCallback)

        self.wordsDone = len([row['done?'] for row in self.wordsWorkingList if row['done?'] != 0])
        self.infoCaption = TextBox((0, jumping_Y+2, self.ctrlWidth-self.wordsFilterCtrl.getPosSize()[2], vanillaControlsSize['TextBoxRegularHeight']),
                                   'done: {:d}/{:d}'.format(self.wordsDone, len(self.wordsWorkingList)))

        jumping_Y += self.wordsFilterCtrl.getPosSize()[3] + MARGIN_VER
        self.loadStatus = SquareButton((0, jumping_Y, 90, vanillaControlsSize['ButtonRegularHeight']+2),
                                       'Load status',
                                       callback=self.loadStatusCallback)

        self.saveButton = SquareButton((-90, jumping_Y, 90, vanillaControlsSize['ButtonRegularHeight']+2),
                                       'Save status',
                                       callback=self.saveButtonCallback)
Ejemplo n.º 5
0
    def __init__(self):
        self.font_order = []
        self.position = "left"
        
        L = 0  # left
        T = 0  # top
        W = 200 # width
        H = 300  # height
        p = 10 # padding
        buttonHeight = 20

        title = "☎️ Hotline Glyph"
        self.w = Window((W, H), title, minSize=(W/3, H/3))

        self.w.fileList = List(
            (L, T, -0, -(p * 3 + buttonHeight * 2)),
            self.font_order,
            columnDescriptions=[
                {"title": "✓", "width":20},
                {"title": "File name"},
                ], # files
            showColumnTitles=False,
            allowsMultipleSelection=True,
            enableDelete=True,
            otherApplicationDropSettings = dict(
                type=NSFilenamesPboardType,
                operation=NSDragOperationCopy,
                callback=self.dropCallback),
            dragSettings=dict(type="RangeType", 
                                callback=self.font_list_drag_callback),
            selfDropSettings=dict(type="RangeType", 
                                operation=NSDragOperationMove, 
                                callback=self.font_list_drop_callback)
            )

        self.w.editText = EditText((p, -(p * 2 + buttonHeight * 2), -p, buttonHeight))

        self.w.draw = CheckBox((p, -(p + buttonHeight), -p, buttonHeight), 'show', value=True, callback=self.updateViewCallback)

        self.w.toLeftbutton = SquareButton((-p*6, -(p + buttonHeight), p*2, buttonHeight), "←", sizeStyle='small', callback=self.toLeft)
        self.w.toRightbutton = SquareButton((-p*3, -(p + buttonHeight), p*2, buttonHeight), "➝", sizeStyle='small', callback=self.toRight)

        addObserver(self, "drawPreviewRef", "drawBackground")
        addObserver(self, "drawRef", "drawPreview")

        self.setUpBaseWindowBehavior() # Needed for the windowCloseCallback

        self.w.open()
Ejemplo n.º 6
0
    def __init__(self):
        super(VisualReporter, self).__init__()

        self.allFonts = AllFonts()
        self.sortAllFonts()
        self.collectFontNames()

        self.w = Window((0, 0, PLUGIN_WIDTH, 1), PLUGIN_TITLE)

        jumpingY = UI_MARGIN
        self.w.fontsPopUp = PopUpButton(
            (UI_MARGIN, jumpingY, NET_WIDTH,
             vanillaControlsSize['PopUpButtonRegularHeight']),
            self.fontNames,
            callback=None)

        jumpingY += vanillaControlsSize['PopUpButtonRegularHeight'] + UI_MARGIN
        self.w.reportButton = SquareButton(
            (UI_MARGIN, jumpingY, NET_WIDTH,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Generate PDF Report',
            callback=self.reportButtonCallback)
        jumpingY += vanillaControlsSize['ButtonRegularHeight'] * 1.5 + UI_MARGIN

        self.setUpBaseWindowBehavior()
        addObserver(self, 'updateFontOptions', "newFontDidOpen")
        addObserver(self, 'updateFontOptions', "fontDidOpen")
        addObserver(self, 'updateFontOptions', "fontWillClose")
        self.w.bind("close", self.windowCloseCallback)
        self.w.resize(PLUGIN_WIDTH, jumpingY)
        self.w.open()
    def __init__(self):
        self.filters = PenBallFiltersManager()
        self.filters.loadFiltersFromJSON('/'.join([LOCALPATH, JSONFILE]))
        self.glyphNames = []
        self.observedGlyphs = []
        self.cachedFont = RFont(showUI=False)
        self.currentFont = CurrentFont()
        filtersList = self.filters.keys()
        if len(filtersList) > 0:
            self.currentFilterName = filtersList[0]
        else:
            self.currentFilterName = None
        self.fill = True

        self.observers = [
            ('fontChanged', 'fontBecameCurrent'),
            ('fontChanged', 'fontDidOpen'),
            ('fontChanged', 'fontDidClose'),
        ]

        self.w = Window((100, 100, 800, 500), 'PenBall Wizard v{0}'.format(__version__), minSize=(500, 400))
        self.w.filtersPanel = Group((0, 0, 300, -0))
        self.w.filtersPanel.filtersList = List((0, 0, -0, -40), filtersList, selectionCallback=self.filterSelectionChanged, doubleClickCallback=self.filterEdit, allowsMultipleSelection=False, allowsEmptySelection=False, rowHeight=22)
        self.w.filtersPanel.controls = Group((0, -40, -0, 0))
        self.w.filtersPanel.addFilter = SquareButton((0, -40, 100, 40), 'Add filter', sizeStyle='small', callback=self.addFilter)
        self.w.filtersPanel.addFilterChain = SquareButton((100, -40, 100, 40), 'Add operations', sizeStyle='small', callback=self.addFilterChain)
        self.w.filtersPanel.removeFilter = SquareButton((-100, -40, 100, 40), 'Remove filter', sizeStyle='small', callback=self.removeFilter)
        self.w.textInput = EditText((300, 0, -90, 22), '', callback=self.stringInput)
        self.w.generate = SquareButton((-90, 0, 90, 22), 'Generate', callback=self.generateGlyphsToFont, sizeStyle='small')
        self.w.preview = MultiLineView((300, 22, -0, -0))
        self.w.switchFillStroke = SquareButton((-75, -40, 60, 25), 'Stroke', callback=self.switchFillStroke, sizeStyle='small')
        displayStates = self.w.preview.getDisplayStates()
        for key in ['Show Metrics','Upside Down','Stroke','Beam','Inverse','Water Fall','Multi Line']:
            displayStates[key] = False
        for key in ['Fill','Single Line']:
            displayStates[key] = True
        self.w.preview.setDisplayStates(displayStates)

        for callback, event in self.observers:
            addObserver(self, callback, event)

        self.updateControls()

        self.w.bind('close', self.end)
        self.launchWindow()
        self.w.open()
Ejemplo n.º 8
0
	def __init__( self, titles ):
		self.button = ''
		margin = 10
		size = 40
		self.w = Window( ( len( titles ) * ( margin + size ) + margin, 2 * margin + size ), "Symmetrify" )
		top = margin
		left = margin

		for title in titles:
			button = SquareButton( ( left, top, size, size ), title, callback = self.buttonCallback )
			setattr( self.w, title, button )
			left += size + margin
Ejemplo n.º 9
0
    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()
Ejemplo n.º 10
0
    def initUI(self):
        self.prevSelection = [0]
        w, h = self.minSize
        self.w = HUDFloatingWindow((0, 0, w, h),self.windowTitle,minSize=self.minSize,autosaveName=key)
        self.w.getNSWindow().setHasShadow_(False)

        columnInfo = [
                dict(title='icon', cell=ImageListCell(), width=self.rowHeight+self.rowHeight/8),
                dict(title='tool', cell=VerticallyCenteredTextFieldCell('mini'), editable=False),
                dict(title='active', cell=CheckBoxListCell(), editable=True, width=17),
            ]

        self.w.palette = Group((0,0,-0,-0))
        self.w.palette.list = List((0,0,-0,-66),[], columnDescriptions=columnInfo, rowHeight=self.rowHeight, selectionCallback=self.selectionCallback,showColumnTitles=False, allowsEmptySelection=True, allowsMultipleSelection=False, drawHorizontalLines=True,drawFocusRing=True,editCallback=self.listChangedCallback)#,dragSettings=dict(type=toolOrderDragType, callback=self.dragCallback), selfDropSettings=dict(type=toolOrderDragType, operation=NSDragOperationMove, callback=self.dropListSelfCallback))
        self.selectionCallback(self.w.palette.list)
        self.w.palette.openSettings = GradientButton((5,-66+5,-5,-5),imageNamed=NSImageNameActionTemplate,sizeStyle='mini',callback=self.openSettingsCallback)
        self.w.settings = Group((-self.settingsWidth,0,self.settingsWidth,-0))
        columnInfo = [

                dict(title='hotkey', editable=True),
                dict(title='modifier',cell=PopUpButtonListCell(self.modifiers), binding="selectedValue")
            ]
        self.w.settings.list = List((5,0,-0,-66),[], columnDescriptions=columnInfo, rowHeight=self.rowHeight, showColumnTitles=False, allowsEmptySelection=True, allowsMultipleSelection=False, drawVerticalLines=True, drawFocusRing=True,editCallback=self.hotkeyEditCallback)
        self.w.settings.hideToolbar = CheckBox((5,-66+5,-5,15),'hide toolbar',sizeStyle='mini', callback=self.hideToolbarCallback,value=self.hideToolbar)
        # self.w.settings.sortDefaulr = SquareButton((self.settingsWidth/2+2.5,-66+5,-5,15),'sort default bar',sizeStyle='mini',callback=self.sortDefaultToolsCallback)
        self.w.settings.showOnLaunchChB = CheckBox((5,-44+5,-5,15),'show on launch',sizeStyle='mini', callback=self.showOnLaunchCallback,value=self.showOnLaunch)
        self.w.settings.exportBtn = SquareButton((5,-22+2,self.settingsWidth/2-5-2.5,15),'export prefs',sizeStyle='mini',callback=self.exportImportCallback)
        self.w.settings.importBtn = SquareButton((self.settingsWidth/2+2.5,-22+2,-5,15),'import prefs',sizeStyle='mini',callback=self.exportImportCallback)
        self.w.settings.show(False)
        self.hideToolbarCallback(self.w.settings.hideToolbar)
        self._rebuildToolPalette()
        self.w.palette.list.setSelection(self.prevSelection)
        self.w.bind('close', self.windowClose)
        self.w.bind('resize', self.windowResize)
        self.windowResize(self.w)
        self.w.open()
Ejemplo n.º 11
0
    def __init__(self, posSize, attachCallback, labelName=None):
        super(Label, self).__init__(posSize)
        self.labelName = labelName
        self.attachCallback = attachCallback

        self.edit = EditText((0, 0, NET_WIDTH * .7,
                              vanillaControlsSize['EditTextRegularHeight']),
                             text=self.labelName,
                             continuous=True,
                             callback=self.editCallback)

        self.button = SquareButton(
            (NET_WIDTH * .72, 0, NET_WIDTH * .28,
             vanillaControlsSize['EditTextRegularHeight']),
            'attach!',
            callback=self.buttonCallback)
Ejemplo n.º 12
0
    def __init__(self, posSize, whichMargin, callback):
        super(SingleMargin, self).__init__(posSize)
        self.callback = callback
        x, y, width, height = posSize

        if whichMargin == 'LEFT':
            whichArrow = 'leftarrow'
        else:
            whichArrow = 'rightarrow'

        jumpingY = 0
        self.caption = TextBox(
            (0, jumpingY, width, vanillaControlsSize['TextBoxRegularHeight']),
            whichMargin)

        jumpingY += vanillaControlsSize['TextBoxRegularHeight'] + MARGIN_ROW
        self.plusFourButton = SquareButton(
            (0, jumpingY, SQUARE_SIDE, SQUARE_SIDE),
            '+4',
            sizeStyle='small',
            callback=self.plusFourButtonCallback)
        self.plusFourButton.bind(whichArrow, [])

        self.minusFourButton = SquareButton(
            (SQUARE_SIDE, jumpingY, SQUARE_SIDE, SQUARE_SIDE),
            '-4',
            sizeStyle='small',
            callback=self.minusFourButtonCallback)
        self.minusFourButton.bind(whichArrow, ['option'])

        jumpingY += SQUARE_SIDE
        self.plusTwentyButton = SquareButton(
            (0, jumpingY, SQUARE_SIDE, SQUARE_SIDE),
            '+20',
            sizeStyle='small',
            callback=self.plusTwentyButtonCallback)
        self.plusTwentyButton.bind(whichArrow, ['command'])

        self.minusTwentyButton = SquareButton(
            (SQUARE_SIDE, jumpingY, SQUARE_SIDE, SQUARE_SIDE),
            '-20',
            sizeStyle='small',
            callback=self.minusTwentyButtonCallback)
        self.minusTwentyButton.bind(whichArrow, ['option', 'command'])
    def __init__(self):
        self.w = FloatingWindow(
            (120, 140),
            minSize=(100, 40),
            textured=True,
        )
        self.w.ti_checkbox = CheckBox((10, 10, -10, 20),
                                      'Test Install',
                                      value=True)
        self.w.otf_checkbox = CheckBox((10, 30, -10, 20),
                                       'OTF Backup',
                                       value=True)
        self.w.button = SquareButton((10, 60, -10, -10),
                                     'GO',
                                     callback=self.button_callback)

        self.w.open()
Ejemplo n.º 14
0
    def __init__(self):

        # init window
        self.w = FloatingWindow((PLUGIN_WIDTH, 300), 'labeler.py')

        self.jumpingY = MARGIN_VER
        self.w.labelCtrl_0 = LabelCtrl((MARGIN_HOR, self.jumpingY, NET_WIDTH, vanillaControlsSize['EditTextRegularHeight']),
                                       index=self.labelCltrIndex,
                                       callback=self.labelCtrlsCallback)
        self.jumpingY += vanillaControlsSize['EditTextRegularHeight'] + MARGIN_VER

        self.w.separation = HorizontalLine((MARGIN_HOR, self.jumpingY, NET_WIDTH, vanillaControlsSize['HorizontalLineThickness']))
        self.w.clearButton = SquareButton((MARGIN_HOR, self.jumpingY+vanillaControlsSize['HorizontalLineThickness'] + MARGIN_VER, NET_WIDTH, vanillaControlsSize['ButtonRegularHeight']),
                                          'Clear Glyph Labels',
                                          sizeStyle='small',
                                          callback=self.clearButtonCallback)

        # resize window
        self._computeWindowHeight()
        self.w.resize(PLUGIN_WIDTH, self.windowHeight)

        # open window
        self.w.open()
    def buildFilterGroupSheet(self, filterName='', makeNew=False):

        subfilters = self.filters[filterName].subfilters if filterName in self.filters else []
        subfilterItems = [{'filterName': subfilterName, 'mode': subfilterMode if subfilterMode is not None else '', 'source': source if source is not None else ''} for subfilterName, subfilterMode, source in subfilters]

        self.filterSheet = Sheet((0, 0, 400, 350), self.w)
        self.filterSheet.new = makeNew
        self.filterSheet.index = self.filters[filterName].index if not makeNew else -1
        applyTitle = 'Add Operation' if filterName == '' else 'Update Operation'
        self.filterSheet.apply = SquareButton((-145, -37, 130, 22), applyTitle, callback=self.processFilterGroup, sizeStyle='small')
        self.filterSheet.cancel = SquareButton((-210, -37, 60, 22), 'Cancel', callback=self.closeFilterSheet, sizeStyle='small')

        y = 20
        self.filterSheet.nameTitle = TextBox((15, y, 100, 22), 'Filter Name')
        self.filterSheet.name = EditText((125, y, -15, 22), filterName)
        y += 22

        columns = [
            {'title': 'filterName', 'editable': True, 'width': 140},
            {'title': 'mode', 'editable': True, 'width': 89},
            {'title': 'source', 'editable': True, 'width': 100}
        ]

        buttonSize = 20
        gutter = 7

        y += 20
        self.filterSheet.subfilters = List((15 + buttonSize + gutter, y, -15, -52), subfilterItems, columnDescriptions=columns, allowsMultipleSelection=False, allowsEmptySelection=False)
        self.filterSheet.addSubfilter = SquareButton((15, -52-(buttonSize*2)-gutter, buttonSize, buttonSize), '+', sizeStyle='small', callback=self.addSubfilter)
        self.filterSheet.removeSubfilter = SquareButton((15, -52-buttonSize, buttonSize, buttonSize), '-', sizeStyle='small', callback=self.removeSubfilter)
        if len(subfilters) == 0:
            self.filterSheet.removeSubfilter.enable(False)
        y += 75
        self.filterSheet.moveSubfilterUp = SquareButton((15, y, buttonSize, buttonSize), u'⇡', sizeStyle='small', callback=self.moveSubfilterUp)
        self.filterSheet.moveSubfilterDown = SquareButton((15, y + buttonSize + gutter, buttonSize, buttonSize), u'⇣', sizeStyle='small', callback=self.moveSubfilterDown)

        if filterName == '':
            self.currentFilterName = ''
Ejemplo n.º 16
0
    def __init__(self):
        super(AscenderDescenderCalculator, self).__init__()
        self.w = FloatingWindow((0, 0, PLUGIN_WIDTH, PLUGIN_HEIGHT),
                                PLUGIN_TITLE)

        jumpingY = MARGIN_VER
        self.w.calcButton = SquareButton(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Measure Extremes',
            callback=self.calcButtonCallback)

        jumpingY += vanillaControlsSize[
            'ButtonRegularHeight'] * 1.5 + MARGIN_ROW
        self.w.topCaption = TextBox(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['TextBoxRegularHeight']), 'Top: None')

        jumpingY += vanillaControlsSize['TextBoxRegularHeight'] + MARGIN_ROW
        self.w.btmCaption = TextBox(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['TextBoxRegularHeight']), 'Bottom: None')

        jumpingY += vanillaControlsSize['TextBoxRegularHeight']
        self.w.separationLine = HorizontalLine(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['TextBoxRegularHeight']))

        jumpingY += vanillaControlsSize['TextBoxRegularHeight'] + MARGIN_ROW
        self.w.check_hhea = CheckBox(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['CheckBoxRegularHeight']),
            'hhea table',
            value=self.is_hhea,
            callback=self.check_hheaCallback)

        jumpingY += vanillaControlsSize['CheckBoxRegularHeight'] + MARGIN_ROW
        self.w.check_vhea = CheckBox(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['CheckBoxRegularHeight']),
            'vhea table',
            value=self.is_vhea,
            callback=self.check_vheaCallback)

        jumpingY += vanillaControlsSize['CheckBoxRegularHeight'] + MARGIN_ROW
        self.w.check_osTwo = CheckBox(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['CheckBoxRegularHeight']),
            'OS/2 table',
            value=self.is_osTwo,
            callback=self.check_osTwoCallback)

        jumpingY += vanillaControlsSize['CheckBoxRegularHeight'] + MARGIN_ROW
        self.w.check_usWin = CheckBox(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['CheckBoxRegularHeight']),
            'usWin table',
            value=self.is_usWin,
            callback=self.check_usWinCallback)

        jumpingY += vanillaControlsSize['CheckBoxRegularHeight'] + MARGIN_ROW
        self.w.writeButton = SquareButton(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Write values into fonts',
            callback=self.writeButtonCallback)

        jumpingY += vanillaControlsSize[
            'ButtonRegularHeight'] * 1.5 + MARGIN_VER * 1.5
        self.w.resize(PLUGIN_WIDTH, jumpingY)
        self.setUpBaseWindowBehavior()
        self.w.open()
Ejemplo n.º 17
0
    def __init__(self):

        # init window
        self.win = FloatingWindow((self.pluginWidth, self.pluginHeight),
                                  "Broad Nib")

        # checkBox preview
        jumpingY = self.marginTop
        self.win.preview = CheckBox(
            (self.marginLft, jumpingY, self.netWidth, CheckBoxHeight),
            "Preview",
            value=self.preview,
            sizeStyle='small',
            callback=self.previewCallback)

        jumpingY += CheckBoxHeight
        self.win.shapeRadio = RadioGroup(
            (self.marginLft + 10, jumpingY, self.netWidth, 32),
            SHAPE_OPTIONS,
            sizeStyle='small',
            callback=self.shapeRadioCallback)
        self.win.shapeRadio.enable(False)
        self.win.shapeRadio.set(0)

        # checkBox draw values
        jumpingY += self.marginRow + self.win.shapeRadio.getPosSize()[3] - 3
        self.win.drawValues = CheckBox(
            (self.marginLft, jumpingY, self.netWidth, CheckBoxHeight),
            "Draw Values",
            value=self.drawValues,
            sizeStyle='small',
            callback=self.drawValuesCallback)

        # oval width
        jumpingY += self.marginRow + CheckBoxHeight
        self.win.widthCaption = TextBox(
            (self.marginLft, jumpingY + 3, self.netWidth * .5, TextBoxHeight),
            "Width:",
            sizeStyle='small')

        self.win.widthEdit = EditText(
            (self.marginLft + self.netWidth * .5, jumpingY, self.netWidth * .4,
             EditTextHeight),
            sizeStyle='small',
            callback=self.widthEditCallback)

        # oval height
        jumpingY += self.marginRow + EditTextHeight
        self.win.heightCaption = TextBox(
            (self.marginLft, jumpingY + 3, self.netWidth * .5, TextBoxHeight),
            "Height:",
            sizeStyle='small')

        self.win.heightEdit = EditText(
            (self.marginLft + self.netWidth * .5, jumpingY, self.netWidth * .4,
             EditTextHeight),
            sizeStyle='small',
            callback=self.heightEditCallback)

        # oval angle
        jumpingY += self.marginRow + EditTextHeight
        self.win.angleCaption = TextBox(
            (self.marginLft, jumpingY + 3, self.netWidth * .5, TextBoxHeight),
            "Angle:",
            sizeStyle='small')

        self.win.angleEdit = EditText(
            (self.marginLft + self.netWidth * .5, jumpingY, self.netWidth * .4,
             EditTextHeight),
            sizeStyle='small',
            callback=self.angleEditCallback)

        # add
        jumpingY += self.marginRow + EditTextHeight
        self.win.addToLib = SquareButton(
            (self.marginLft, jumpingY, self.netWidth, SquareButtonHeight),
            "Add to lib",
            sizeStyle='small',
            callback=self.addToLibCallback)

        # clear
        jumpingY += self.marginRow + EditTextHeight
        self.win.clearLib = SquareButton(
            (self.marginLft, jumpingY, self.netWidth, SquareButtonHeight),
            "Clear lib",
            sizeStyle='small',
            callback=self.clearLibCallback)

        jumpingY += self.marginRow + EditTextHeight
        self.win.expandToForeground = SquareButton(
            (self.marginLft, jumpingY, self.netWidth, SquareButtonHeight),
            "Expand",
            sizeStyle='small',
            callback=self.expandToForegroundCallback)

        # managing observers
        addObserver(self, "_drawBackground", "drawBackground")
        addObserver(self, "_drawBackground", "drawInactive")
        addObserver(self, "_drawBlack", "drawPreview")
        self.win.bind("close", self.closing)

        # adjust window
        jumpingY += self.marginRow + EditTextHeight
        self.win.setPosSize((200, 200, self.pluginWidth, jumpingY))

        # opening window
        self.win.open()
Ejemplo n.º 18
0
    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()
Ejemplo n.º 19
0
    def __init__(self):
        super(CornersRounder, self).__init__()

        self._initLogger()
        self.rounderLogger.info('we are on air! start: __init__()')

        self._updateFontsAttributes()
        if self.allFonts != []:
            self.selectedFont = self.allFonts[0]

        self._initRoundingsData()
        if self.selectedFont is not None:
            self.layerNames = ['foreground'] + self.selectedFont.layerOrder
            self.sourceLayerName = self.layerNames[0]
            self.targetLayerName = self.layerNames[0]

            if PLUGIN_LIB_NAME in self.selectedFont.lib:
                self.roundingsData = pullRoundingsDataFromFont(
                    self.selectedFont)

        self.w = Window((0, 0, PLUGIN_WIDTH, PLUGIN_HEIGHT), PLUGIN_TITLE)

        jumpingY = MARGIN_VER
        self.w.fontPopUp = PopUpButton(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['PopUpButtonRegularHeight']),
            [os.path.basename(item.path) for item in self.allFonts],
            callback=self.fontPopUpCallback)

        jumpingY += vanillaControlsSize['PopUpButtonRegularHeight'] + MARGIN_VER
        self.w.sepLineOne = HorizontalLine(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['HorizontalLineThickness']))

        jumpingY += MARGIN_VER
        for eachI in range(LABELS_AMOUNT):
            singleLabel = Label((MARGIN_HOR, jumpingY, NET_WIDTH,
                                 vanillaControlsSize['EditTextRegularHeight']),
                                attachCallback=self.attachCallback,
                                labelName='')

            setattr(self.w, 'label{:d}'.format(eachI), singleLabel)
            jumpingY += MARGIN_ROW + vanillaControlsSize[
                'EditTextRegularHeight']
        self._fromRoundingsData2LabelCtrls()

        jumpingY += MARGIN_ROW
        self.w.sepLineTwo = HorizontalLine(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['HorizontalLineThickness']))
        jumpingY += MARGIN_ROW * 2

        # tables
        labelListWdt = 78
        marginTable = 1
        angleListWdt = (NET_WIDTH - labelListWdt - marginTable * 3) // 3
        tableLineHeight = 16
        tableHgt = LABELS_AMOUNT * tableLineHeight + 33

        captionY = jumpingY
        captionOffset = 12
        jumpingY += vanillaControlsSize['TextBoxSmallHeight'] + MARGIN_ROW

        labelColumnDesc = [{"title": "labelName", 'editable': True}]
        jumpingX = MARGIN_HOR

        self.w.labelNameList = List(
            (jumpingX, jumpingY, labelListWdt, tableHgt), [],
            columnDescriptions=labelColumnDesc,
            showColumnTitles=True,
            editCallback=self.labelNameListCallback,
            rowHeight=tableLineHeight,
            drawHorizontalLines=True,
            drawVerticalLines=True,
            autohidesScrollers=True,
            allowsMultipleSelection=False)

        anglesColumnDesc = [{
            "title": "rad",
            'editable': True
        }, {
            "title": "bcp",
            'editable': True
        }]

        jumpingX += labelListWdt + marginTable
        self.w.fortyFiveCaption = TextBox(
            (jumpingX + captionOffset, captionY, angleListWdt,
             vanillaControlsSize['TextBoxSmallHeight']),
            u'45°',
            sizeStyle='small')

        self.w.fortyFiveList = List(
            (jumpingX, jumpingY, angleListWdt, tableHgt), [],
            columnDescriptions=anglesColumnDesc,
            showColumnTitles=True,
            rowHeight=tableLineHeight,
            editCallback=self.fortyFiveListCallback,
            drawHorizontalLines=True,
            drawVerticalLines=True,
            autohidesScrollers=True,
            allowsMultipleSelection=False)

        jumpingX += angleListWdt + marginTable
        self.w.ninetyCaption = TextBox(
            (jumpingX + captionOffset, captionY, angleListWdt,
             vanillaControlsSize['TextBoxSmallHeight']),
            u'90°',
            sizeStyle='small')

        self.w.ninetyList = List((jumpingX, jumpingY, angleListWdt, tableHgt),
                                 [],
                                 columnDescriptions=anglesColumnDesc,
                                 showColumnTitles=True,
                                 rowHeight=tableLineHeight,
                                 editCallback=self.ninetyListCallback,
                                 drawHorizontalLines=True,
                                 drawVerticalLines=True,
                                 autohidesScrollers=True,
                                 allowsMultipleSelection=False)

        jumpingX += angleListWdt + marginTable
        self.w.hundredThirtyFiveCaption = TextBox(
            (jumpingX + captionOffset, captionY, angleListWdt,
             vanillaControlsSize['TextBoxSmallHeight']),
            u'135°',
            sizeStyle='small')

        self.w.hundredThirtyFiveList = List(
            (jumpingX, jumpingY, angleListWdt, tableHgt), [],
            columnDescriptions=anglesColumnDesc,
            showColumnTitles=True,
            rowHeight=tableLineHeight,
            editCallback=self.hundredThirtyFiveListCallback,
            drawHorizontalLines=True,
            drawVerticalLines=True,
            autohidesScrollers=True,
            allowsMultipleSelection=False)
        self._fromRoundingsData2Lists()
        jumpingY += tableHgt + MARGIN_ROW * 2

        rgtX = MARGIN_HOR + NET_WIDTH * .52
        midWdt = NET_WIDTH * .48
        self.w.pushButton = SquareButton(
            (MARGIN_HOR, jumpingY, midWdt,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Push Data',
            callback=self.pushButtonCallback)
        self.w.clearLibButton = SquareButton(
            (rgtX, jumpingY, midWdt,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Clear Lib',
            callback=self.clearLibButtonCallback)

        jumpingY += vanillaControlsSize[
            'ButtonRegularHeight'] * 1.5 + MARGIN_ROW * 2
        self.w.sepLineThree = HorizontalLine(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['HorizontalLineThickness']))
        jumpingY += MARGIN_ROW * 2

        self.w.sourceLayerCaption = TextBox(
            (MARGIN_HOR, jumpingY, midWdt,
             vanillaControlsSize['TextBoxRegularHeight']), 'source layer')
        self.w.targetLayerCaption = TextBox(
            (rgtX, jumpingY, midWdt,
             vanillaControlsSize['TextBoxRegularHeight']), 'target layer')

        jumpingY += vanillaControlsSize['TextBoxRegularHeight'] + MARGIN_ROW
        self.w.sourceLayerPopUp = PopUpButton(
            (MARGIN_HOR, jumpingY, midWdt,
             vanillaControlsSize['PopUpButtonRegularHeight']),
            self.layerNames,
            callback=self.sourceLayerPopUpCallback)
        if self.layerNames and self.sourceLayerName:
            self.w.sourceLayerPopUp.set(
                self.layerNames.index(self.sourceLayerName))

        self.w.targetLayerCombo = ComboBox(
            (rgtX, jumpingY, midWdt,
             vanillaControlsSize['PopUpButtonRegularHeight']),
            self.layerNames,
            callback=self.targetLayerComboCallback)
        if self.layerNames and self.targetLayerName:
            self.w.targetLayerCombo.set(self.targetLayerName)

        jumpingY += vanillaControlsSize[
            'PopUpButtonRegularHeight'] + MARGIN_ROW * 4
        self.w.roundGlyphButton = SquareButton(
            (MARGIN_HOR, jumpingY, midWdt,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            u'Round Glyph (⌘+R)',
            callback=self.roundGlyphButtonCallback)
        self.w.roundGlyphButton.bind('r', ['command'])

        self.w.roundFontButton = SquareButton(
            (rgtX, jumpingY, midWdt,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Round Font',
            callback=self.roundFontButtonCallback)
        jumpingY += vanillaControlsSize[
            'ButtonRegularHeight'] * 1.5 + MARGIN_VER * 2

        self.w.resize(PLUGIN_WIDTH, jumpingY)

        self._checkPushButton()
        self._checkRoundButtons()
        self.setUpBaseWindowBehavior()
        addObserver(self, 'fontDidOpenCallback', 'fontDidOpen')
        addObserver(self, 'fontDidCloseCallback', 'fontDidClose')
        addObserver(self, '_keyDown', 'keyDown')
        self.w.open()
Ejemplo n.º 20
0
class WordListController(Group):
    """this controller takes good care of word list flow"""

    def __init__(self, posSize, callback):
        super(WordListController, self).__init__(posSize)
        x, y, self.ctrlWidth, self.ctrlHeight = posSize
        self.callback = callback

        # handling kerning words
        self.kerningWordsDB = loadKerningTexts(STANDARD_KERNING_TEXT_FOLDER)
        self.kerningTextBaseNames = self.kerningWordsDB.keys()
        self.activeKerningTextBaseName = self.kerningTextBaseNames[0]
        # this is the list used for data manipulation
        self.wordsWorkingList = self.kerningWordsDB[self.activeKerningTextBaseName]
        # this list instead is used for data visualization in the ctrl
        self._makeWordsDisplayList(self.activeKerningTextBaseName)
        self.activeWord = self.wordsWorkingList[0]['word']
        self.wordFilter = ''

        jumping_Y = 0
        self.kerningVocabularyPopUp = PopUpButton((0, jumping_Y, self.ctrlWidth*.6, vanillaControlsSize['PopUpButtonRegularHeight']),
                                                  self.kerningTextBaseNames,
                                                  callback=self.kerningVocabularyPopUpCallback)

        self.openTextsFolderButton = SquareButton((self.ctrlWidth*.62, jumping_Y, self.ctrlWidth*.38, vanillaControlsSize['PopUpButtonRegularHeight']+1),
                                                  'Load texts...',
                                                  sizeStyle='small',
                                                  callback=self.openTextsFolderButtonCallback)

        wordsColumnDescriptors = [
            {'title': '#', 'width': 30, 'editable': False},
            {'title': 'word', 'width': self.ctrlWidth-80, 'editable': False},
            {'title': 'done?', 'width': 35, 'cell': CheckBoxListCell(), 'editable': False}]

        jumping_Y += self.openTextsFolderButton.getPosSize()[3] + MARGIN_VER
        self.wordsListCtrl = List((0, jumping_Y, self.ctrlWidth, 170),
                                  self.wordsDisplayList,
                                  enableDelete=False,
                                  allowsMultipleSelection=False,
                                  columnDescriptions=wordsColumnDescriptors,
                                  selectionCallback=self.wordsListCtrlSelectionCallback,
                                  doubleClickCallback=self.wordsListCtrlDoubleClickCallback)

        jumping_Y += self.wordsListCtrl.getPosSize()[3] + MARGIN_VER
        self.wordsFilterCtrl = EditText((-70, jumping_Y-1, 70, vanillaControlsSize['EditTextRegularHeight']),
                                        placeholder='filter...',
                                        callback=self.wordsFilterCtrlCallback)

        self.wordsDone = len([row['done?'] for row in self.wordsWorkingList if row['done?'] != 0])
        self.infoCaption = TextBox((0, jumping_Y+2, self.ctrlWidth-self.wordsFilterCtrl.getPosSize()[2], vanillaControlsSize['TextBoxRegularHeight']),
                                   'done: {:d}/{:d}'.format(self.wordsDone, len(self.wordsWorkingList)))

        jumping_Y += self.wordsFilterCtrl.getPosSize()[3] + MARGIN_VER
        self.loadStatus = SquareButton((0, jumping_Y, 90, vanillaControlsSize['ButtonRegularHeight']+2),
                                       'Load status',
                                       callback=self.loadStatusCallback)

        self.saveButton = SquareButton((-90, jumping_Y, 90, vanillaControlsSize['ButtonRegularHeight']+2),
                                       'Save status',
                                       callback=self.saveButtonCallback)

    def _filterDisplayList(self):
        self.wordsDisplayList = [row for row in self.wordsWorkingList if self.wordFilter in row['word']]

    def _makeWordsDisplayList(self, textBaseName):
        self.wordsDisplayList = []
        for eachRow in self.kerningWordsDB[self.activeKerningTextBaseName]:
            fixedWord = eachRow['word'].replace('//', '/')
            self.wordsDisplayList.append({'#': eachRow['#'], 'word': fixedWord, 'done?': eachRow['done?']})

    def _updateInfoCaption(self):
        self.infoCaption.set('done: {:d}/{:d}'.format(self.wordsDone, len(self.wordsWorkingList)))

    def get(self):
        return self.activeWord

    def getActiveIndex(self):
        activeWordData = [wordData for wordData in self.wordsDisplayList if wordData['word'] == self.activeWord][0]
        activeWordIndex = self.wordsDisplayList.index(activeWordData)
        return activeWordIndex

    def nextWord(self):
        activeWordData = [wordData for wordData in self.wordsDisplayList if wordData['word'] == self.activeWord][0]
        activeWordIndex = self.wordsDisplayList.index(activeWordData)
        nextWordIndex = (activeWordIndex+1)%len(self.wordsDisplayList)
        self.activeWord = self.wordsDisplayList[nextWordIndex]['word']
        self.wordsListCtrl.setSelection([nextWordIndex])

    def previousWord(self):
        activeWordData = [wordData for wordData in self.wordsDisplayList if wordData['word'] == self.activeWord][0]
        activeWordIndex = self.wordsDisplayList.index(activeWordData)
        previousWordIndex = (activeWordIndex-1)%len(self.wordsDisplayList)
        self.activeWord = self.wordsDisplayList[previousWordIndex]['word']
        self.wordsListCtrl.setSelection([previousWordIndex])

    def jumpToLine(self, lineIndex):
        try:
            self.activeWord = self.wordsDisplayList[lineIndex]['word']
            self.wordsListCtrl.setSelection([lineIndex])
        except IndexError:
            pass

    def switchActiveWordSolvedAttribute(self):
        activeWordData = [wordData for wordData in self.wordsDisplayList if wordData['word'] == self.activeWord][0]
        activeWordIndex = self.wordsDisplayList.index(activeWordData)
        if activeWordData['done?'] == 0:
            self.wordsDisplayList[activeWordIndex]['done?'] = 1
        else:
            self.wordsDisplayList[activeWordIndex]['done?'] = 0
        self.wordsListCtrl.set(self.wordsDisplayList)
        self.wordsListCtrl.setSelection([activeWordIndex])

    # ctrls callbacks
    def kerningVocabularyPopUpCallback(self, sender):
        self.activeKerningTextBaseName = self.kerningTextBaseNames[sender.get()]
        self.wordsWorkingList = self.kerningWordsDB[self.activeKerningTextBaseName]
        self.activeWord = self.wordsWorkingList[0]['word']
        self._makeWordsDisplayList(self.activeKerningTextBaseName)
        self._filterDisplayList()
        self.wordsListCtrl.set(self.wordsDisplayList)
        self.callback(self)

    def openTextsFolderButtonCallback(self, sender):
        textFolder = u'{}'.format(getFolder('Choose a folder for texts files')[0])
        # handling kerning words
        self.kerningWordsDB = loadKerningTexts(textFolder)
        self.kerningTextBaseNames = self.kerningWordsDB.keys()
        self.activeKerningTextBaseName = self.kerningTextBaseNames[0]
        # this is the list used for data manipulation
        self.wordsWorkingList = self.kerningWordsDB[self.activeKerningTextBaseName]
        # this list instead is used for data visualization in the ctrl
        self._makeWordsDisplayList(self.activeKerningTextBaseName)
        self.activeWord = self.wordsWorkingList[0]['word']
        self.wordFilter = ''
        self._filterDisplayList()
        self._updateInfoCaption()
        # ctrls to be updated
        self.kerningVocabularyPopUp.setItems(self.kerningTextBaseNames)
        self.wordsListCtrl.set(self.wordsDisplayList)
        self.wordsFilterCtrl.set(self.wordFilter)
        self.callback(self)

    def wordsListCtrlSelectionCallback(self, sender):
        """this takes care of word count"""
        self.wordsDisplayList = [{'#': row['#'], 'word': row['word'], 'done?': row['done?']} for row in sender.get()]
        for eachDisplayedRow in self.wordsDisplayList:
            for indexWorkingRow, eachWorkingRow in enumerate(self.wordsWorkingList):
                if eachWorkingRow['word'] == eachDisplayedRow['word']:
                    self.wordsWorkingList[indexWorkingRow] = eachDisplayedRow
        self.wordsDone = len([row['done?'] for row in self.wordsWorkingList if row['done?'] != 0])
        self._updateInfoCaption()

    def wordsListCtrlDoubleClickCallback(self, sender):
        self.activeWord = self.wordsDisplayList[sender.getSelection()[0]]['word']
        self.callback(self)


    def wordsFilterCtrlCallback(self, sender):
        self.wordFilter = sender.get()
        self._filterDisplayList()
        self.wordsListCtrl.set(self.wordsDisplayList)
        if len(self.wordsDisplayList) == 0:
            self.activeWord = None
        else:
            if self.activeWord not in [row['word'] for row in self.wordsDisplayList]:
                self.activeWord = self.wordsDisplayList[0]['word']
        self.callback(self)

    def loadStatusCallback(self, sender):
        kerningStatusPath = getFile(title='Load Kerning Status JSON file',
                                    allowsMultipleSelection=False)[0]

        if os.path.splitext(os.path.basename(kerningStatusPath))[1] == '.json':
            jsonFile = open(kerningStatusPath, 'r')
            statusDictionary = json.load(jsonFile)
            jsonFile.close()

            # unwrap dictionaries
            self.kerningWordsDB = statusDictionary['kerningWordsDB']
            self.kerningTextBaseNames = statusDictionary['kerningTextBaseNames']
            self.activeKerningTextBaseName = statusDictionary['activeKerningTextBaseName']
            self.wordsWorkingList = statusDictionary['wordsWorkingList']
            self.wordsDisplayList = statusDictionary['wordsDisplayList']
            self.activeWord = statusDictionary['activeWord']
            self.wordFilter = statusDictionary['wordFilter']

            # adjust controllers
            self.kerningVocabularyPopUp.setItems(self.kerningTextBaseNames)
            self.kerningVocabularyPopUp.set(self.kerningTextBaseNames.index(self.activeKerningTextBaseName))
            self.wordsListCtrl.set(self.wordsDisplayList)

            for indexRow, eachRow in enumerate(self.wordsDisplayList):
                if eachRow['word'] == self.activeWord:
                    self.wordsListCtrl.setSelection([indexRow])
                    break

            self._updateInfoCaption()
            self.callback(self)

        else:
            message('No JSON, no party!', 'Chosen file is not in the right format')

    def saveButtonCallback(self, sender):
        statusDict = {
            'kerningWordsDB': self.kerningWordsDB,
            'kerningTextBaseNames': self.kerningTextBaseNames,
            'activeKerningTextBaseName': self.activeKerningTextBaseName,
            'wordsWorkingList': self.wordsWorkingList,
            'wordsDisplayList': self.wordsDisplayList,
            'activeWord': self.activeWord,
            'wordFilter': self.wordFilter}

        kerningStatusPath = putFile(title='Save Kerning Status JSON file',
                                    fileName='kerningStatus.json',
                                    canCreateDirectories=True)

        jsonFile = open(kerningStatusPath, 'w')
        json.dump(statusDict, jsonFile, indent=4)
        jsonFile.write('\n')
        jsonFile.close()
Ejemplo n.º 21
0
    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()
Ejemplo n.º 22
0
class JoystickController(Group):

    lastEvent = None
    keyboardCorrection = 0

    def __init__(self, posSize,
                       fontObj,
                       isSymmetricalEditingOn,
                       isSwappedEditingOn,
                       isVerticalAlignedEditingOn,
                       autoSave,
                       autoSaveSpan,
                       activePair,
                       callback):

        super(JoystickController, self).__init__(posSize)
        self.fontObj = fontObj
        self.activePair = activePair

        self.isSymmetricalEditingOn = isSymmetricalEditingOn
        self.isSwappedEditingOn = isSwappedEditingOn
        self.isVerticalAlignedEditingOn = isVerticalAlignedEditingOn
        self.autoSave = autoSave
        self.autoSaveSpan = autoSaveSpan
        self.callback = callback

        buttonSide = 36
        self.ctrlWidth, self.ctrlHeight = posSize[2], posSize[3]
        self.jumping_X = buttonSide/2.
        self.jumping_Y = 0

        self.minusMajorCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                           "{:+d}".format(MAJOR_STEP),
                                           sizeStyle='small',
                                           callback=self.minusMajorCtrlCallback)
        self.minusMajorCtrl.bind(*MINUS_MAJOR_SHORTCUT)

        self.jumping_X += buttonSide
        self.minusMinorCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                           "{:+d}".format(MINOR_STEP),
                                           sizeStyle='small',
                                           callback=self.minusMinorCtrlCallback)
        self.minusMinorCtrl.bind(*MINUS_MINOR_SHORTCUT)

        self.jumping_X += buttonSide
        self.plusMinorCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                          "{:+d}".format(MINOR_STEP),
                                          sizeStyle='small',
                                          callback=self.plusMinorCtrlCallback)
        self.plusMinorCtrl.bind(*PLUS_MINOR_SHORTCUT)

        self.jumping_X += buttonSide
        self.plusMajorCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                          "{:+d}".format(MAJOR_STEP),
                                          sizeStyle='small',
                                          callback=self.plusMajorCtrlCallback)
        self.plusMajorCtrl.bind(*PLUS_MAJOR_SHORTCUT)

        self.jumping_X = buttonSide/2.
        self.jumping_Y += buttonSide
        self.lftSwitchCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide*2, buttonSide*.75),
                                        "lft switch",
                                        sizeStyle='small',
                                        callback=self.lftSwitchCtrlCallback)
        self.lftSwitchCtrl.bind(*LEFT_BROWSING_SHORTCUT)

        self.jumping_X += buttonSide*2
        self.rgtSwitchCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide*2, buttonSide*.75),
                                       "rgt switch",
                                       sizeStyle='small',
                                       callback=self.rgtSwitchCtrlCallback)
        self.rgtSwitchCtrl.bind(*RIGHT_BROWSING_SHORTCUT)

        self.jumping_X = buttonSide/2.
        self.jumping_Y += buttonSide
        self.exceptionTrigger = SquareButton((self.jumping_X, self.jumping_Y, buttonSide*2, buttonSide*.75),
                                                'exception',
                                                sizeStyle='small',
                                                callback=self.exceptionTriggerCallback)
        self.exceptionTrigger.bind(*EXCEPTION_SHORTCUT)

        self.jumping_X += buttonSide*2
        self.undoButton = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide*.75),
                                       'undo',
                                       sizeStyle='small',
                                       callback=self.undoButtonCallback)
        self.undoButton.bind(*UNDO_SHORTCUT)

        self.jumping_X += buttonSide
        self.redoButton = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide*.75),
                                       'redo',
                                       sizeStyle='small',
                                       callback=self.redoButtonCallback)
        self.redoButton.bind(*REDO_SHORTCUT)

        self.jumping_X = buttonSide/2.
        self.jumping_Y += buttonSide*.75
        self.previewCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide*2, buttonSide*.75),
                                        "preview",
                                        sizeStyle='small',
                                        callback=self.previewCtrlCallback)
        self.previewCtrl.bind(*PREVIEW_SHORTCUT)

        self.jumping_X += buttonSide*2
        self.solvedCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide*2, buttonSide*.75),
                                       "solved",
                                       sizeStyle='small',
                                       callback=self.solvedCtrlCallback)
        self.solvedCtrl.bind(*SOLVED_SHORTCUT)

        self.jumping_X = buttonSide/2.
        self.jumping_Y += buttonSide*.75+2
        self.symmetricalModeCheck = CheckBox((self.jumping_X, self.jumping_Y, self.ctrlWidth, vanillaControlsSize['CheckBoxRegularHeight']),
                                          'symmetrical editing',
                                          value=self.isSwappedEditingOn,
                                          callback=self.symmetricalModeCallback)

        self.jumping_Y += buttonSide*.6
        self.swappedModeCheck = CheckBox((self.jumping_X, self.jumping_Y, self.ctrlWidth, vanillaControlsSize['CheckBoxRegularHeight']),
                                          'swapped editing',
                                          value=self.isSwappedEditingOn,
                                          callback=self.swappedModeCallback)

        self.jumping_Y += buttonSide*.6
        self.verticalAlignedModeCheck = CheckBox((self.jumping_X, self.jumping_Y, self.ctrlWidth, vanillaControlsSize['CheckBoxRegularHeight']),
                                                 'vertically aligned editing',
                                                 value=self.isVerticalAlignedEditingOn,
                                                 callback=self.verticalAlignedModeCheckCallback)
        self.verticalAlignedModeCheck.bind(*VERTICAL_MODE_SHORTCUT)

        self.hiddenSwappedEditingButton = Button((self.jumping_X, self.ctrlHeight+40, self.ctrlWidth, vanillaControlsSize['ButtonRegularHeight']),
                                                   'hiddenSymmetriyEditingButton',
                                                   callback=self.hiddenSwappedEditingButtonCallback)
        self.hiddenSwappedEditingButton.bind(*FLIPPED_EDITING_SHORTCUT)

        self.hiddenJumpToLineButton = Button((self.jumping_X, self.ctrlHeight+40, self.ctrlWidth, vanillaControlsSize['ButtonRegularHeight']),
                                                   'hiddenJumpToLineButton',
                                                   callback=self.hiddenJumpToLineButtonCallback)
        self.hiddenJumpToLineButton.bind(*JUMP_TO_LINE_SHORTCUT)

        self.jumping_X = buttonSide
        self.jumping_Y += buttonSide
        self.previousWordCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                             u'↖',
                                             callback=self.previousWordCtrlCallback)
        self.previousWordCtrl.bind(*PREVIOUS_WORD_SHORTCUT)

        self.jumping_X += buttonSide
        self.cursorUpCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                         u'↑',
                                         callback=self.cursorUpCtrlCallback)
        self.cursorUpCtrl.bind(*CURSOR_UP_SHORTCUT)

        self.jumping_X += buttonSide*1.5
        self.activePairEditCorrection = EditText((self.jumping_X, self.jumping_Y, 50, vanillaControlsSize['EditTextRegularHeight']),
                                                 text='{:d}'.format(0),   # init value
                                                 continuous=False,
                                                 callback=self.activePairEditCorrectionCallback)

        self.jumping_X = buttonSide
        self.jumping_Y += buttonSide
        self.cursorLeftCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                           u"←",
                                           callback=self.cursorLeftCtrlCallback)
        self.cursorLeftCtrl.bind(*CURSOR_LEFT_SHORTCUT)

        self.jumping_X += buttonSide*2
        self.cursorRightCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                            u'→',
                                            callback=self.cursorRightCtrlCallback)
        self.cursorRightCtrl.bind(*CURSOR_RIGHT_SHORTCUT)

        self.jumping_X = buttonSide
        self.jumping_Y += buttonSide

        self.delPairCtrl = SquareButton((self.jumping_X-6, self.jumping_Y+6, buttonSide, buttonSide),
                                        u'Del',
                                        callback=self.delPairCtrlCallback)
        self.delPairCtrl.bind(*DEL_PAIR_SHORTCUT)

        self.jumping_X += buttonSide
        self.cursorDownCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                           u'↓',
                                           callback=self.cursorDownCtrlCallback)
        self.cursorDownCtrl.bind(*CURSOR_DOWN_SHORTCUT)

        self.jumping_X += buttonSide
        self.nextWordCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                         u'↘',
                                         callback=self.nextWordCtrlCallback)
        self.nextWordCtrl.bind(*NEXT_WORD_SHORTCUT)

        self.jumping_Y += buttonSide*1.3
        self.jumping_X = buttonSide*.5
        self.autoSaveCheck = CheckBox((self.jumping_X, self.jumping_Y, buttonSide*2.5, vanillaControlsSize['CheckBoxRegularHeight']),
                                      'auto save',
                                      callback=self.autoSaveCheckCallback)

        self.jumping_X += buttonSide*2.5
        self.autoSaveSpanPopUp = PopUpButton((self.jumping_X, self.jumping_Y, buttonSide*1.5, vanillaControlsSize['PopUpButtonRegularHeight']),
                                             AUTO_SAVE_SPAN_OPTIONS,
                                             callback=self.autoSaveSpanPopUpCallback)
        self.autoSaveSpanPopUp.set(AUTO_SAVE_SPAN_OPTIONS.index("{:d}'".format(self.autoSaveSpan)))

    # goes out
    def getLastEvent(self):
        return self.lastEvent

    def getKeyboardCorrection(self):
        return self.keyboardCorrection

    def getAutoSaveState(self):
        return self.autoSave, self.autoSaveSpan

    # comes in
    def setActivePair(self, activePair):
        self.activePair = activePair
        self.updateCorrectionValue()

    def setSwappedEditing(self, value):
        self.isSwappedEditingOn = value
        self.swappedModeCheck.set(self.isSwappedEditingOn)

    def setSymmetricalEditing(self, value):
        self.isSymmetricalEditingOn = value
        self.symmetricalModeCheck.set(self.isSymmetricalEditingOn)

    def setFontObj(self, value):
        self.fontObj = value
        self.updateCorrectionValue()

    def updateCorrectionValue(self):
        correction, kerningReference, pairKind = getCorrection(self.activePair, self.fontObj)
        try:
            self.activePairEditCorrection.set('{:d}'.format(correction))
        except ValueError:
            self.activePairEditCorrection.set('')

    # callbacks
    def minusMajorCtrlCallback(self, sender):
        self.lastEvent = 'minusMajor'
        self.callback(self)

    def minusMinorCtrlCallback(self, sender):
        self.lastEvent = 'minusMinor'
        self.callback(self)

    def plusMinorCtrlCallback(self, sender):
        self.lastEvent = 'plusMinor'
        self.callback(self)

    def plusMajorCtrlCallback(self, sender):
        self.lastEvent = 'plusMajor'
        self.callback(self)

    def delPairCtrlCallback(self, sender):
        self.lastEvent = 'deletePair'
        self.callback(self)

    def exceptionTriggerCallback(self, sender):
        self.lastEvent = 'exceptionTrigger'
        self.callback(self)

    def undoButtonCallback(self, sender):
        self.lastEvent = 'undo'
        self.callback(self)

    def redoButtonCallback(self, sender):
        self.lastEvent = 'redo'
        self.callback(self)

    def previewCtrlCallback(self, sender):
        self.lastEvent = 'preview'
        self.callback(self)

    def solvedCtrlCallback(self, sender):
        self.lastEvent = 'solved'
        self.callback(self)

    def swappedModeCallback(self, sender):
        self.lastEvent = 'swappedEditing'
        self.isSwappedEditingOn = bool(sender.get())
        self.callback(self)

    def symmetricalModeCallback(self, sender):
        self.lastEvent = 'symmetricalEditing'
        self.isSymmetricalEditingOn = bool(sender.get())
        self.callback(self)

    def verticalAlignedModeCheckCallback(self, sender):
        self.lastEvent = 'verticalAlignedEditing'
        self.isVerticalAlignedEditingOn = bool(sender.get())
        self.callback(self)

    def hiddenSwappedEditingButtonCallback(self, sender):
        self.lastEvent = 'swappedEditing'
        self.isSwappedEditingOn = not self.isSwappedEditingOn
        self.swappedModeCheck.set(self.isSwappedEditingOn)
        self.callback(self)

    def hiddenJumpToLineButtonCallback(self, sender):
        self.lastEvent = 'jumpToLineTrigger'
        self.callback(self)

    def previousWordCtrlCallback(self, sender):
        self.lastEvent = 'previousWord'
        self.callback(self)

    def cursorUpCtrlCallback(self, sender):
        self.lastEvent = 'cursorUp'
        self.callback(self)

    def cursorLeftCtrlCallback(self, sender):
        self.lastEvent = 'cursorLeft'
        self.callback(self)

    def cursorRightCtrlCallback(self, sender):
        self.lastEvent = 'cursorRight'
        self.callback(self)

    def cursorDownCtrlCallback(self, sender):
        self.lastEvent = 'cursorDown'
        self.callback(self)

    def nextWordCtrlCallback(self, sender):
        self.lastEvent = 'nextWord'
        self.callback(self)

    def lftSwitchCtrlCallback(self, sender):
        self.lastEvent = 'switchLftGlyph'
        self.callback(self)

    def rgtSwitchCtrlCallback(self, sender):
        self.lastEvent = 'switchRgtGlyph'
        self.callback(self)

    def activePairEditCorrectionCallback(self, sender):
        # removing the pair, if nothing is written
        if sender.get() == '':
            self.keyboardCorrection = None
            self.callback(self)
            return

        # if numbers are there...
        try:
            self.lastEvent = 'keyboardEdit'
            self.keyboardCorrection = int(sender.get())
            self.callback(self)
        except ValueError:
            if sender.get() != '-':
                self.activePairEditCorrection.set('{}'.format(self.keyboardCorrection))
                print traceback.format_exc()

    def autoSaveCheckCallback(self, sender):
        self.lastEvent = 'autoSave'
        self.autoSave = bool(sender.get())
        self.callback(self)

    def autoSaveSpanPopUpCallback(self, sender):
        self.lastEvent = 'autoSave'
        self.autoSaveSpan = INT_2_SPAN[AUTO_SAVE_SPAN_OPTIONS[sender.get()]]
        self.callback(self)
Ejemplo n.º 23
0
    def __init__(self):
        self.w = Window((180, 340),
                        u'Touché!',
                        minSize=(180, 340),
                        maxSize=(1000, 898))
        p = 10
        w = 160

        # options
        self.w.options = Group((0, 0, 180, 220))

        buttons = {
            "checkSelBtn": {
                "text": "Check selected glyphs\nfor touching pairs",
                "callback": self.checkSel,
                "y": p
            },
            "checkAllBtn": {
                "text": "Check entire font\n(can take several minutes!)",
                "callback": self.checkAll,
                "y": 60
            }
        }
        for button, data in buttons.items():
            setattr(
                self.w.options, button,
                SquareButton((p, data["y"], w, 40),
                             data["text"],
                             callback=data["callback"],
                             sizeStyle="small"))

        self.w.options.zeroCheck = CheckBox((p, 108, w, 20),
                                            "Ignore zero-width glyphs",
                                            value=True,
                                            sizeStyle="small")
        self.w.options.progress = ProgressSpinner((82, 174, 16, 16),
                                                  sizeStyle="small")

        # results
        self.w.results = Group((0, 220, 180, -0))
        self.w.results.show(False)

        textBoxes = {"stats": 24, "result": 42}
        for box, y in textBoxes.items():
            setattr(self.w.results, box,
                    TextBox((p, y, w, 14), "", sizeStyle="small"))

        moreButtons = {
            "spaceView": {
                "text": "View all in Space Center",
                "callback": self.showAllPairs,
                "y": 65
            },
            "exportTxt": {
                "text": "Export as MM pair list",
                "callback": self.exportPairList,
                "y": 90
            }
        }
        for button, data in moreButtons.items():
            setattr(
                self.w.results, button,
                SquareButton((p, data["y"], w, 20),
                             data["text"],
                             callback=data["callback"],
                             sizeStyle="small"))

        # list and preview
        self.w.outputList = List((180, 0, 188, -0), [{
            "left glyph": "",
            "right glyph": ""
        }],
                                 columnDescriptions=[{
                                     "title": "left glyph"
                                 }, {
                                     "title": "right glyph"
                                 }],
                                 showColumnTitles=False,
                                 allowsMultipleSelection=False,
                                 enableDelete=False,
                                 selectionCallback=self.showPair)
        self.w.preview = MultiLineView((368, 0, -0, -0), pointSize=256)

        self.w.open()
Ejemplo n.º 24
0
    def __init__(self, posSize,
                       fontObj,
                       isSymmetricalEditingOn,
                       isSwappedEditingOn,
                       isVerticalAlignedEditingOn,
                       autoSave,
                       autoSaveSpan,
                       activePair,
                       callback):

        super(JoystickController, self).__init__(posSize)
        self.fontObj = fontObj
        self.activePair = activePair

        self.isSymmetricalEditingOn = isSymmetricalEditingOn
        self.isSwappedEditingOn = isSwappedEditingOn
        self.isVerticalAlignedEditingOn = isVerticalAlignedEditingOn
        self.autoSave = autoSave
        self.autoSaveSpan = autoSaveSpan
        self.callback = callback

        buttonSide = 36
        self.ctrlWidth, self.ctrlHeight = posSize[2], posSize[3]
        self.jumping_X = buttonSide/2.
        self.jumping_Y = 0

        self.minusMajorCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                           "{:+d}".format(MAJOR_STEP),
                                           sizeStyle='small',
                                           callback=self.minusMajorCtrlCallback)
        self.minusMajorCtrl.bind(*MINUS_MAJOR_SHORTCUT)

        self.jumping_X += buttonSide
        self.minusMinorCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                           "{:+d}".format(MINOR_STEP),
                                           sizeStyle='small',
                                           callback=self.minusMinorCtrlCallback)
        self.minusMinorCtrl.bind(*MINUS_MINOR_SHORTCUT)

        self.jumping_X += buttonSide
        self.plusMinorCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                          "{:+d}".format(MINOR_STEP),
                                          sizeStyle='small',
                                          callback=self.plusMinorCtrlCallback)
        self.plusMinorCtrl.bind(*PLUS_MINOR_SHORTCUT)

        self.jumping_X += buttonSide
        self.plusMajorCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                          "{:+d}".format(MAJOR_STEP),
                                          sizeStyle='small',
                                          callback=self.plusMajorCtrlCallback)
        self.plusMajorCtrl.bind(*PLUS_MAJOR_SHORTCUT)

        self.jumping_X = buttonSide/2.
        self.jumping_Y += buttonSide
        self.lftSwitchCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide*2, buttonSide*.75),
                                        "lft switch",
                                        sizeStyle='small',
                                        callback=self.lftSwitchCtrlCallback)
        self.lftSwitchCtrl.bind(*LEFT_BROWSING_SHORTCUT)

        self.jumping_X += buttonSide*2
        self.rgtSwitchCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide*2, buttonSide*.75),
                                       "rgt switch",
                                       sizeStyle='small',
                                       callback=self.rgtSwitchCtrlCallback)
        self.rgtSwitchCtrl.bind(*RIGHT_BROWSING_SHORTCUT)

        self.jumping_X = buttonSide/2.
        self.jumping_Y += buttonSide
        self.exceptionTrigger = SquareButton((self.jumping_X, self.jumping_Y, buttonSide*2, buttonSide*.75),
                                                'exception',
                                                sizeStyle='small',
                                                callback=self.exceptionTriggerCallback)
        self.exceptionTrigger.bind(*EXCEPTION_SHORTCUT)

        self.jumping_X += buttonSide*2
        self.undoButton = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide*.75),
                                       'undo',
                                       sizeStyle='small',
                                       callback=self.undoButtonCallback)
        self.undoButton.bind(*UNDO_SHORTCUT)

        self.jumping_X += buttonSide
        self.redoButton = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide*.75),
                                       'redo',
                                       sizeStyle='small',
                                       callback=self.redoButtonCallback)
        self.redoButton.bind(*REDO_SHORTCUT)

        self.jumping_X = buttonSide/2.
        self.jumping_Y += buttonSide*.75
        self.previewCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide*2, buttonSide*.75),
                                        "preview",
                                        sizeStyle='small',
                                        callback=self.previewCtrlCallback)
        self.previewCtrl.bind(*PREVIEW_SHORTCUT)

        self.jumping_X += buttonSide*2
        self.solvedCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide*2, buttonSide*.75),
                                       "solved",
                                       sizeStyle='small',
                                       callback=self.solvedCtrlCallback)
        self.solvedCtrl.bind(*SOLVED_SHORTCUT)

        self.jumping_X = buttonSide/2.
        self.jumping_Y += buttonSide*.75+2
        self.symmetricalModeCheck = CheckBox((self.jumping_X, self.jumping_Y, self.ctrlWidth, vanillaControlsSize['CheckBoxRegularHeight']),
                                          'symmetrical editing',
                                          value=self.isSwappedEditingOn,
                                          callback=self.symmetricalModeCallback)

        self.jumping_Y += buttonSide*.6
        self.swappedModeCheck = CheckBox((self.jumping_X, self.jumping_Y, self.ctrlWidth, vanillaControlsSize['CheckBoxRegularHeight']),
                                          'swapped editing',
                                          value=self.isSwappedEditingOn,
                                          callback=self.swappedModeCallback)

        self.jumping_Y += buttonSide*.6
        self.verticalAlignedModeCheck = CheckBox((self.jumping_X, self.jumping_Y, self.ctrlWidth, vanillaControlsSize['CheckBoxRegularHeight']),
                                                 'vertically aligned editing',
                                                 value=self.isVerticalAlignedEditingOn,
                                                 callback=self.verticalAlignedModeCheckCallback)
        self.verticalAlignedModeCheck.bind(*VERTICAL_MODE_SHORTCUT)

        self.hiddenSwappedEditingButton = Button((self.jumping_X, self.ctrlHeight+40, self.ctrlWidth, vanillaControlsSize['ButtonRegularHeight']),
                                                   'hiddenSymmetriyEditingButton',
                                                   callback=self.hiddenSwappedEditingButtonCallback)
        self.hiddenSwappedEditingButton.bind(*FLIPPED_EDITING_SHORTCUT)

        self.hiddenJumpToLineButton = Button((self.jumping_X, self.ctrlHeight+40, self.ctrlWidth, vanillaControlsSize['ButtonRegularHeight']),
                                                   'hiddenJumpToLineButton',
                                                   callback=self.hiddenJumpToLineButtonCallback)
        self.hiddenJumpToLineButton.bind(*JUMP_TO_LINE_SHORTCUT)

        self.jumping_X = buttonSide
        self.jumping_Y += buttonSide
        self.previousWordCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                             u'↖',
                                             callback=self.previousWordCtrlCallback)
        self.previousWordCtrl.bind(*PREVIOUS_WORD_SHORTCUT)

        self.jumping_X += buttonSide
        self.cursorUpCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                         u'↑',
                                         callback=self.cursorUpCtrlCallback)
        self.cursorUpCtrl.bind(*CURSOR_UP_SHORTCUT)

        self.jumping_X += buttonSide*1.5
        self.activePairEditCorrection = EditText((self.jumping_X, self.jumping_Y, 50, vanillaControlsSize['EditTextRegularHeight']),
                                                 text='{:d}'.format(0),   # init value
                                                 continuous=False,
                                                 callback=self.activePairEditCorrectionCallback)

        self.jumping_X = buttonSide
        self.jumping_Y += buttonSide
        self.cursorLeftCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                           u"←",
                                           callback=self.cursorLeftCtrlCallback)
        self.cursorLeftCtrl.bind(*CURSOR_LEFT_SHORTCUT)

        self.jumping_X += buttonSide*2
        self.cursorRightCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                            u'→',
                                            callback=self.cursorRightCtrlCallback)
        self.cursorRightCtrl.bind(*CURSOR_RIGHT_SHORTCUT)

        self.jumping_X = buttonSide
        self.jumping_Y += buttonSide

        self.delPairCtrl = SquareButton((self.jumping_X-6, self.jumping_Y+6, buttonSide, buttonSide),
                                        u'Del',
                                        callback=self.delPairCtrlCallback)
        self.delPairCtrl.bind(*DEL_PAIR_SHORTCUT)

        self.jumping_X += buttonSide
        self.cursorDownCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                           u'↓',
                                           callback=self.cursorDownCtrlCallback)
        self.cursorDownCtrl.bind(*CURSOR_DOWN_SHORTCUT)

        self.jumping_X += buttonSide
        self.nextWordCtrl = SquareButton((self.jumping_X, self.jumping_Y, buttonSide, buttonSide),
                                         u'↘',
                                         callback=self.nextWordCtrlCallback)
        self.nextWordCtrl.bind(*NEXT_WORD_SHORTCUT)

        self.jumping_Y += buttonSide*1.3
        self.jumping_X = buttonSide*.5
        self.autoSaveCheck = CheckBox((self.jumping_X, self.jumping_Y, buttonSide*2.5, vanillaControlsSize['CheckBoxRegularHeight']),
                                      'auto save',
                                      callback=self.autoSaveCheckCallback)

        self.jumping_X += buttonSide*2.5
        self.autoSaveSpanPopUp = PopUpButton((self.jumping_X, self.jumping_Y, buttonSide*1.5, vanillaControlsSize['PopUpButtonRegularHeight']),
                                             AUTO_SAVE_SPAN_OPTIONS,
                                             callback=self.autoSaveSpanPopUpCallback)
        self.autoSaveSpanPopUp.set(AUTO_SAVE_SPAN_OPTIONS.index("{:d}'".format(self.autoSaveSpan)))
    def buildFilterSheet(self, filterName='', makeNew=False):
        sheetFields = {
            'file': '',
            'module': '',
            'filterObjectName': '',
            'limits': {},
            'arguments': {},
        }
        if filterName != '':
            filterDict = self.filters[filterName].getFilterDict()
            for key in filterDict:
                if key == "arguments":
                    entry = OrderedDict(filterDict[key])
                else:
                    entry = filterDict[key]
                sheetFields[key] = entry

        self.filterSheet = Sheet((0, 0, 400, 350), self.w)
        self.filterSheet.new = makeNew
        self.filterSheet.index = self.filters[filterName].index if not makeNew else -1
        applyTitle = 'Add Filter' if filterName == '' else 'Update Filter'
        self.filterSheet.apply = SquareButton((-115, -37, 100, 22), applyTitle, callback=self.processFilter, sizeStyle='small')
        self.filterSheet.cancel = SquareButton((-205, -37, 80, 22), 'Cancel', callback=self.closeFilterSheet, sizeStyle='small')

        y = 20
        self.filterSheet.nameTitle = TextBox((15, y, 100, 22), 'Filter Name')
        self.filterSheet.name = EditText((125, y, -15, 22), filterName)
        y += 22

        tabs = ['module','file']
        selectedTab = 0 if len(sheetFields['module']) >= len(sheetFields['file']) else 1
        filterObjectName = sheetFields['filterObjectName']

        y += 20
        self.filterSheet.importPath = Tabs((15, y, -15, 75), tabs)
        self.filterSheet.importPath.set(selectedTab)
        modulePathTab = self.filterSheet.importPath[0]
        filePathTab = self.filterSheet.importPath[1]

        modulePathTab.pathInput = EditText((10, 10, -10, -10), sheetFields['module'])
        filePathTab.pathInput = EditText((10, 10, -110, -10), sheetFields['file'])
        filePathTab.fileInput = SquareButton((-100, 10, 90, -10), u'Add File…', sizeStyle='small', callback=self.getFile)
        y += 75

        y += 10
        self.filterSheet.filterObjectTitle = TextBox((15, y, 100, 22), 'Filter Object (pen, function)')
        self.filterSheet.filterObject = EditText((125, y, -15, 22), filterObjectName)
        y += 22

        y += 20
        columns = [
            {'title': 'argument', 'width': 160, 'editable':True},
            {'title': 'value', 'width': 71, 'editable':True},
            {'title': 'min', 'width': 49, 'editable':True},
            {'title': 'max', 'width': 49, 'editable':True}
        ]

        arguments = sheetFields['arguments']
        limits = sheetFields['limits']

        argumentItems = []

        for key, value in arguments.items():
            if isinstance(value, bool):
                value = str(value)
            elif isinstance(value, float):
                value = round(value, 2)
            argItem = {
                'argument': key,
                'value': value
                }
            if key in limits:
                minimum, maximum = sheetFields['limits'][key]
                argItem['min'] = minimum
                argItem['max'] = maximum

            argumentItems.append(argItem)

        buttonSize = 20
        gutter = 7
        self.filterSheet.arguments = List((15 + buttonSize + gutter, y, -15, -52), argumentItems, columnDescriptions=columns, allowsMultipleSelection=False, allowsEmptySelection=False)
        self.filterSheet.addArgument = SquareButton((15, -52-(buttonSize*2)-gutter, buttonSize, buttonSize), '+', sizeStyle='small', callback=self.addArgument)
        self.filterSheet.removeArgument = SquareButton((15, -52-buttonSize, buttonSize, buttonSize), '-', sizeStyle='small', callback=self.removeArgument)
        if len(argumentItems) == 0:
            self.filterSheet.removeArgument.enable(False)

        if filterName == '':
            self.currentFilterName = ''
Ejemplo n.º 26
0
    def __init__(self, willOpen=True):
        super(SidebearingsLinker, self).__init__()

        # collecting fonts
        self.allFonts = AllFonts()
        if self.allFonts != []:
            self.selectedFont = self.allFonts[0]

        # interface
        self.w = FloatingWindow((PLUGIN_WIDTH, PLUGIN_HEIGHT), PLUGIN_TITLE)

        jumpingY = MARGIN_VER
        self.w.fontPopUp = PopUpButton(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['PopUpButtonRegularHeight']),
            getNamesFrom(self.allFonts),
            callback=self.fontPopUpCallback)

        jumpingY += vanillaControlsSize['PopUpButtonRegularHeight'] + MARGIN_ROW
        self.w.canvas = CanvasGroup(
            (MARGIN_HOR, jumpingY, NET_WIDTH, CANVAS_HEIGHT), delegate=self)

        jumpingY += CANVAS_HEIGHT + MARGIN_ROW
        linksColumnDescriptions = [{
            "title": "left",
            'key': 'lft',
            'width': LIST_WIDE_COL
        }, {
            "title": "active",
            "cell": CheckBoxListCell(),
            'key': 'lftActive',
            'width': LIST_NARROW_COL
        }, {
            "title": "glyph",
            'key': 'servant',
            'width': LIST_WIDE_COL,
            "editable": False
        }, {
            "title": "active",
            "cell": CheckBoxListCell(),
            'key': 'rgtActive',
            'width': LIST_NARROW_COL
        }, {
            "title": "right",
            'key': 'rgt',
            'width': LIST_WIDE_COL
        }]

        if self.selectedFont is not None:
            links = loadLinksFromFont(self.selectedFont)
        else:
            links = []

        self.w.linksList = List(
            (MARGIN_HOR, jumpingY, NET_WIDTH, 200),
            links,
            showColumnTitles=False,
            allowsMultipleSelection=False,
            drawVerticalLines=True,
            columnDescriptions=linksColumnDescriptions,
            selectionCallback=self.selectionLinksListCallback,
            editCallback=self.editLinksListCallback)

        if self.selectedFont is not None:
            self.w.linksList.setSelection([0])
            self.currentRow = self.w.linksList[0]
            self.matchDisplayedSubscriptions()

        jumpingY += self.w.linksList.getPosSize()[3] + MARGIN_ROW
        buttonWidth = (NET_WIDTH - MARGIN_HOR) / 2
        self.w.linkAllButton = SquareButton(
            (MARGIN_HOR, jumpingY, buttonWidth,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Link All',
            callback=self.linkAllButtonCallback)

        self.w.unlockAllButton = SquareButton(
            (MARGIN_HOR * 2 + buttonWidth, jumpingY, buttonWidth,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Unlink All',
            callback=self.unlockAllButtonCallback)

        jumpingY += vanillaControlsSize[
            'ButtonRegularHeight'] * 1.5 + MARGIN_ROW
        self.w.separationLineOne = HorizontalLine(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['HorizontalLineThickness']))

        jumpingY += MARGIN_ROW
        self.w.pushIntoFontButton = SquareButton(
            (MARGIN_HOR, jumpingY, buttonWidth,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Push into font',
            callback=self.pushIntoFontButtonCallback)
        self.w.pushIntoFontButton.enable(False)

        self.w.clearLibsButton = SquareButton(
            (MARGIN_HOR * 2 + buttonWidth, jumpingY, buttonWidth,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Clear Libs',
            callback=self.clearLibsButtonCallback)

        jumpingY += vanillaControlsSize[
            'ButtonRegularHeight'] * 1.5 + MARGIN_ROW
        self.w.loadFromTable = SquareButton(
            (MARGIN_HOR, jumpingY, buttonWidth,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Load from table',
            callback=self.loadFromTableCallback)
        self.w.loadFromTable.enable(True)

        self.w.exportTable = SquareButton(
            (MARGIN_HOR * 2 + buttonWidth, jumpingY, buttonWidth,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Export table',
            callback=self.exportTableCallback)
        self.w.exportTable.enable(True)

        jumpingY += vanillaControlsSize[
            'ButtonRegularHeight'] * 1.5 + MARGIN_VER * 2
        self.w.resize(PLUGIN_WIDTH, jumpingY)

        self.setUpBaseWindowBehavior()

        if self.selectedFont is not None:
            self.matchSubscriptions()
            result = askYesNo('Warning',
                              'Do you want to align servants to masters?')
            if bool(result) is True:
                self._alignServantsToMasters()

        addObserver(self, "drawOnGlyphCanvas", "draw")
        addObserver(self, "drawOnGlyphCanvas", "drawInactive")
        addObserver(self, 'fontDidOpenCallback', 'fontDidOpen')
        addObserver(self, 'fontDidCloseCallback', 'fontDidClose')
        if willOpen is True:
            self.w.open()
Ejemplo n.º 27
0
class FontRow(Group):

    lastDirection = None
    isDisplayed = True

    def __init__(self, posSize, index, aFont, isTop, isBottom,
                 directionCallback, displayedCallback):
        super(FontRow, self).__init__(posSize)
        self.directionCallback = directionCallback
        self.displayedCallback = displayedCallback
        self.index = index
        self.ctrlFont = aFont

        squareButtonSide = FONT_ROW_HEIGHT - 6

        self.check = CheckBox(
            (0, 0, 16, vanillaControlsSize['CheckBoxRegularHeight']),
            '',
            value=self.isDisplayed,
            callback=self.checkCallback)

        self.caption = TextBox(
            (18, 2, 120, vanillaControlsSize['TextBoxRegularHeight']),
            '{}'.format(self.ctrlFont.info.styleName))

        self.buttonUp = SquareButton((-(squareButtonSide * 2 + MARGIN_COL), 0,
                                      squareButtonSide, squareButtonSide),
                                     u'↑',
                                     callback=self.buttonUpCallback)
        if isTop is True:
            self.buttonUp.show(False)

        self.buttonDw = SquareButton(
            (-squareButtonSide, 0, squareButtonSide, squareButtonSide),
            u'↓',
            callback=self.buttonDwCallback)
        if isBottom is True:
            self.buttonDw.show(False)

    def setFont(self, aFont):
        self.ctrlFont = aFont
        self.caption.set('{}'.format(self.ctrlFont.info.styleName))

    def getDirection(self):
        return self.lastDirection

    def setIsDisplayed(self, isDisplayed):
        self.isDisplayed = isDisplayed
        self.check.set(self.isDisplayed)

    def getIsDisplayed(self):
        return self.isDisplayed

    def getFont(self):
        return self.ctrlFont

    def checkCallback(self, sender):
        self.isDisplayed = bool(sender.get())
        self.displayedCallback(self)

    def buttonUpCallback(self, sender):
        self.lastDirection = 'up'
        self.directionCallback(self)

    def buttonDwCallback(self, sender):
        self.lastDirection = 'down'
        self.directionCallback(self)