How to use groupsR method in pyatom

Best Python code snippet using pyatom_python

Rename Kerning Groups.py

Source:Rename Kerning Groups.py Github

copy

Full Screen

1#MenuTitle: Rename Kerning Groups...2# -*- coding: utf-8 -*-3from __future__ import print_function, division, unicode_literals4__doc__="""5(GUI) Lets you rename kerning names and pairs associated with them. 6"""7import vanilla8import GlyphsApp9thisFont = Glyphs.font10# builing a more accessible kerning dictionary11# it's a dictionary of lists. newKernDic[master.id][left, right, value]12kernDic = thisFont.kerningDict() 13newKernDic = {}14for thisMaster in thisFont.masters:15 kernList = []16 for key1 in kernDic[thisMaster.id]:17 for key2 in kernDic[thisMaster.id][key1]:18 pairInList = [key1, key2, kernDic[thisMaster.id][key1][key2]]19 kernList.append(pairInList)20 newKernDic[thisMaster.id] = kernList21# building popup list22# each value contains a list of glyphs involved. groupsL/R[groupName][glyph, glyph, glyph...]23groupsL = {}24groupsR = {}25for thisGlyph in thisFont.glyphs:26 if thisGlyph.leftKerningGroup != None:27 if not thisGlyph.leftKerningGroup in groupsL:28 groupsL[thisGlyph.leftKerningGroup] = []29 groupsL[thisGlyph.leftKerningGroup].append(thisGlyph.name)30 if thisGlyph.rightKerningGroup != None:31 if not thisGlyph.rightKerningGroup in groupsR:32 groupsR[thisGlyph.rightKerningGroup] = []33 groupsR[thisGlyph.rightKerningGroup].append(thisGlyph.name)34class RenameKerningGroups( object ):35 def __init__( self ):36 # Window 'self.w':37 editX = 18038 editY = 2239 textY = 1740 spaceX = 1041 spaceY = 1042 windowWidth = spaceX*3+editX*2+8543 windowHeight = 15044 self.w = vanilla.FloatingWindow(45 ( windowWidth, windowHeight ), # default window size46 "Rename Kerning Groups", # window title47 minSize = ( windowWidth, windowHeight ), # minimum size (for resizing)48 maxSize = ( windowWidth + 100, windowHeight ), # maximum size (for resizing)49 autosaveName = "com.Tosche.RenameKerningGroups.mainwindow" # stores last window position and size50 )51 52 # UI elements:53 self.w.radio = vanilla.RadioGroup( (spaceX+130, spaceY, 120, textY), ["Left", "Right"], isVertical = False, sizeStyle='regular', callback=self.switchList)54 self.w.radio.set(0)55 self.w.text1 = vanilla.TextBox( (spaceX, spaceY*2+textY, 120, textY), "Rename this Group", sizeStyle='regular' )56 self.w.text2 = vanilla.TextBox( (spaceX, spaceY*3+editY+textY, 120, textY), "to this", sizeStyle='regular' )57 self.w.popup = vanilla.PopUpButton( (spaceX+130, spaceY*2+textY, -15, editY), [str(x) for x in sorted(groupsL)], sizeStyle='regular' )58 self.w.newName = vanilla.EditText( (spaceX+130, spaceY*3+editY+textY, -15, editY), "", sizeStyle = 'regular' )59 # Run Button:60 self.w.runButton = vanilla.Button((-80-15, spaceY*4+editY*3, -15, -15), "Run", sizeStyle='regular', callback=self.RenameKerningGroupsMain )61 self.w.setDefaultButton( self.w.runButton )62 # Open window and focus on it:63 self.w.open()64 self.w.makeKey()65 def switchList(self, sender):66 try:67 if self.w.radio.get() == 0:68 self.w.popup.setItems(sorted(groupsL))69 elif self.w.radio.get() == 1:70 self.w.popup.setItems(sorted(groupsR))71 except Exception as e:72 print("Rename Kerning Group Error (switchList): %s" % e)73 def RenameKerningGroupsMain( self, sender ):74 try:75 newName = self.w.newName.get()76 popupNum = self.w.popup.get()77 if self.w.radio.get() == 0: # it it's a left group78 popup = sorted(groupsL)[popupNum]79 for thisGlyphName in groupsL[popup]:80 thisFont.glyphs[thisGlyphName].leftKerningGroup = newName81 for thisMaster in thisFont.masters:82 for thisPair in newKernDic[thisMaster.id]:83 if "@MMK_R_"+popup in thisPair[1]:84 thisFont.setKerningForPair(thisMaster.id, thisPair[0], "@MMK_R_"+newName, thisPair[2])85 thisFont.removeKerningForPair( thisMaster.id, thisPair[0], "@MMK_R_"+popup)86 # updating groupsL popup87 groupsL[newName] = groupsL.pop(popup)88 self.w.popup.setItems(sorted(groupsL))89 self.w.popup.set(sorted(groupsL).index(newName))90 # updating newKernDic91 for thisMaster in thisFont.masters:92 for thisPair in newKernDic[thisMaster.id]:93 if thisPair[1] == "@MMK_R_"+popup:94 thisPair[1] = "@MMK_R_"+newName95 if self.w.radio.get() == 1: # it it's a right group96 popup = sorted(groupsR)[popupNum]97 for thisGlyphName in groupsR[popup]:98 thisFont.glyphs[thisGlyphName].rightKerningGroup = newName99 for thisMaster in thisFont.masters:100 for thisPair in newKernDic[thisMaster.id]:101 if "@MMK_L_"+popup in thisPair[0]:102 thisFont.setKerningForPair(thisMaster.id, "@MMK_L_"+newName, thisPair[1], thisPair[2])103 thisFont.removeKerningForPair(thisMaster.id, "@MMK_L_"+popup, thisPair[1])104 # updating groupsR popup105 groupsR[newName] = groupsR.pop(popup)106 self.w.popup.setItems(sorted(groupsR))107 self.w.popup.set(sorted(groupsR).index(newName))108 # updating newKernDic109 for thisMaster in thisFont.masters:110 for thisPair in newKernDic[thisMaster.id]:111 if thisPair[0] == "@MMK_L_"+popup:112 thisPair[0] = "@MMK_L_"+newName113 114 except Exception as e:115 # brings macro window to front and reports error:116 Glyphs.showMacroWindow()117 print("Rename Kerning Group Error (RenameKerningGroupsMain): %s" % e)...

Full Screen

Full Screen

Split Lat-Grk-Cyr Kerning.py

Source:Split Lat-Grk-Cyr Kerning.py Github

copy

Full Screen

1#MenuTitle: Split Lat-Grk-Cyr Kerning2# -*- coding: utf-8 -*-3from __future__ import print_function, division, unicode_literals4__doc__="""5Splits kerning groups of LGC (Latin, Greek, Cyrillic) and reconstructs kerning accordingly.6Kern once, split later.7"""8import GlyphsApp9f = Glyphs.font # frontmost f10f.disableUpdateInterface() # suppresses UI updates in f View11Glyphs.clearLog()12kernDic = f.kerningDictForDirection_(0)13newKernDic = {}14for m in f.masters:15 kernList = []16 for l, rs in kernDic[m.id].items():17 for r, v in rs.items():18 pairInList = [l, r, v]19 kernList.append(pairInList)20 newKernDic[m.id] = kernList21# dictionary of groups, each value containg a list of glyphs involved.22# groupsL/R[groupName][glyph, glyph, glyph...]23groupsL = {}24groupsR = {}25for g in f.glyphs:26 if g.category == "Letter":27 if g.leftKerningGroupId() != None:28 if not g.leftKerningGroupId() in groupsR:29 groupsR[g.leftKerningGroupId()] = []30 groupsR[g.leftKerningGroupId()].append(g.name)31 32 if g.rightKerningGroupId() != None:33 if not g.rightKerningGroupId() in groupsL:34 groupsL[g.rightKerningGroupId()] = []35 groupsL[g.rightKerningGroupId()].append(g.name)36groupsL_GCref = groupsL.copy()37groupsR_GCref = groupsR.copy()38def duplicateGroup(group, left):39 for groupName, glyphNames in group.items():40 groupCy = False41 groupCyName = ""42 groupGr = False43 groupGrName = ""44 for gn in glyphNames:45 if f.glyphs[gn].script == "greek":46 if groupGr == False:47 groupGrName = gn48 groupGr = True49 if left:50 f.glyphs[gn].setLeftKerningGroup_(groupGrName)51 else:52 f.glyphs[gn].setRightKerningGroup_(groupGrName)53 elif f.glyphs[gn].script == "cyrillic":54 if groupCy == False:55 groupCyName = gn56 groupCy = True57 if left:58 f.glyphs[gn].setLeftKerningGroup_(groupCyName)59 else:60 f.glyphs[gn].setRightKerningGroup_(groupCyName)61 if left:62 groupsR_GCref[groupName] = ["@MMK_R_"+groupGrName, "@MMK_R_"+groupCyName]63 else:64 groupsL_GCref[groupName] = ["@MMK_L_"+groupGrName, "@MMK_L_"+groupCyName]65duplicateGroup(groupsL, False)66duplicateGroup(groupsR, True)67def splitToGC(thePair, greek):68 if greek == True: # if Greek69 script = "greek"70 bin = 071 else:72 script = "cyrillic"73 bin = 174 try:75 if thePair[0] in groupsL_GCref or thePair[1] in groupsR_GCref: # if either one of the pair uses group76 pairL = ""77 pairR = ""78 if thePair[0] in groupsL_GCref:79 if groupsL_GCref[thePair[0]][bin] != "@MMK_L_":80 pairL = groupsL_GCref[thePair[0]][bin]81 else:82 if f.glyphs[groupsL[thePair[0]][0]].category != "Letter":83 pairL = thePair[0]84 elif f.glyphs[thePair[0]]:85 if f.glyphs[thePair[0]].script == script or f.glyphs[thePair[0]].category != "Letter":86 pairL = thePair[0]87 else:88 pairL = thePair[0]89 if thePair[1] in groupsR_GCref:90 if groupsR_GCref[thePair[1]][bin] != "@MMK_R_":91 pairR = groupsR_GCref[thePair[1]][bin]92 else:93 if f.glyphs[groupsR[thePair[1]][0]].category != "Letter":94 pairR = thePair[1]95 elif f.glyphs[thePair[1]]:96 if f.glyphs[thePair[1]].script == script or f.glyphs[thePair[1]].category != "Letter":97 pairR = thePair[1]98 else:99 pairR = thePair[1]100 if pairL != "" and pairR != "":101 return pairL, pairR102 else:103 return None, None104 else:105 return None, None106 except:107 return None, None108for mID, pairs in newKernDic.items():109 for thisPair in pairs:110 newPairGL, newPairGR = splitToGC(thisPair, True) #Greek111 newPairCL, newPairCR = splitToGC(thisPair, False) #Cyrillic112 if newPairGL != None:113 f.setKerningForPair(mID, newPairGL, newPairGR, thisPair[2])114 if newPairCR != None:115 f.setKerningForPair(mID, newPairCL, newPairCR, thisPair[2])116 # will remove unncessary pairs, like Latin-Greek117 necessityL = 0 # 0=Greek or Cyrillic, 1=non-letter, 2=Latin118 necessityR = 0119 if thisPair[0] in groupsL: # if left is some kind of letter group120 if f.glyphs[groupsL[thisPair[0]][0]].script == "latin":121 necessityL = 2 # definitely Lain122 elif f.glyphs[thisPair[0]]:123 if f.glyphs[thisPair[0]].category == "Letter":124 if f.glyphs[thisPair[0]].script == "latin":125 necessityL = 2 # definitely Latin here!126 elif f.glyphs[thisPair[0]].category != "Letter":127 necessityL = 1128 else: # non-letter kerning group129 necessityL = 1130 if thisPair[1] in groupsR: # if right is some kind of letter group131 if f.glyphs[groupsR[thisPair[1]][0]].script == "latin":132 necessityR = 2 133 elif f.glyphs[thisPair[1]]:134 if f.glyphs[thisPair[1]].category == "Letter":135 if f.glyphs[thisPair[1]].script == "latin":136 necessityR = 2137 elif f.glyphs[thisPair[1]].category != "Letter":138 necessityR = 1139 else:140 necessityR = 1141 if (necessityL == 0 or necessityR == 0) and (necessityL == 2 or necessityR == 2 ):142 f.removeKerningForPair(mID, thisPair[0], thisPair[1])...

Full Screen

Full Screen

experiment.py

Source:experiment.py Github

copy

Full Screen

1import sys, os2sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__),'../')))3import time4import numpy as np5import matplotlib.pyplot as plt6from dynamixel_sdk import *7import data8DEG_2_RAD = np.pi/1809PORT_NAME = 'COM3'10PROTOCOL_VERSION = 2.011BAUDRATE = 100000012SERVO_ID = 113portH = PortHandler(PORT_NAME)14portH.setBaudRate(BAUDRATE)15packetH = PacketHandler(PROTOCOL_VERSION)16# Sweeep to start position17groupSW = GroupSyncWrite(portH, packetH, 30, 2)18goal_pos = int(20/300*1023)19groupSW.addParam(SERVO_ID,goal_pos.to_bytes(2, 'little'))20groupSW.txPacket()21time.sleep(5.0)22# Disable torque23groupSW = GroupSyncWrite(portH, packetH, 24, 1)24groupSW.addParam(SERVO_ID,[0])25groupSW.txPacket()26# Collect data27groupSR = GroupSyncRead(portH, packetH, 37, 2)28groupSR.addParam(SERVO_ID)29init_t = time.time()30exp_data = {31 't': [],32 'pos': []33}34while len(exp_data['t']) == 0 or exp_data['t'][-1] < 1:35 groupSR.txRxPacket()36 current_t = time.time()-init_t37 current_pos = groupSR.getData(SERVO_ID,37,2)/1023*300/180*np.pi38 if current_pos == 0: continue # data loss39 exp_data['t'].append(current_t)40 exp_data['pos'].append(current_pos)41 print(exp_data['t'][-1],exp_data['pos'][-1])42portH.closePort()43# Save data44file_name = 'data/freefall_715.csv'45data.write(46 file_name,47 list(exp_data.keys()),48 list(exp_data.values())49)50plt.figure()51plt.plot(exp_data['t'],exp_data['pos'])...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful