How to use deletetext method in pyatom

Best Python code snippet using pyatom_python

Autoquote.py

Source:Autoquote.py Github

copy

Full Screen

1#!/usr/bin/env python2# -*- coding: utf-8 -*-3# File: quotes.py - changes typewriter quotes to typographic quotes4# © 2010.08.28 Gregory Pittman5# This program is free software; you can redistribute it and/or modify6# it under the terms of the GNU General Public License as published by7# the Free Software Foundation; either version 2 of the License, or8# (at your option) any later version.9"""10USAGE11You must have a document open, and a text frame selected.12There will be a valueDialog asking for your language for the quotes, 13the default is 'en', but change the default to suit your needs.14Detected errors shut down the script with an appropriate message.15"""16import scribus17if scribus.haveDoc() > 0:18 c = 019 lang = scribus.valueDialog("Choose by language or country", 'Language: af, be, ch, cs, de, de-g, en, es, et, fi, fr,\n hu, is, lt, mk, nl, pl, ru, se, sk, sl, sq and uk\n are current choices','en')20 if (lang == 'en'):21 lead_double = u"\u201c"22 follow_double = u"\u201d"23 lead_single = u"\u2018"24 follow_single = u"\u2019"25 elif (lang == 'de'):26 lead_double = u"\u201e"27 follow_double = u"\u201c"28 lead_single = u"\u2019"29 follow_single = u"\u201a"30 elif (lang == 'de-g'): # German with inverted guillemets for double quotes31 lead_double = u"\u00bb"32 follow_double = u"\u00ab"33 lead_single = u"\u2019"34 follow_single = u"\u201a"35 elif (lang == 'fr'): 36 lead_double = u"\u00ab"37 follow_double = u"\u00bb"38 lead_single = u"\u2018"39 follow_single = u"\u2019" # am hoping this will cover contractions like je t'aime40 elif (lang == 'pl'):41 lead_double = u"\u201e"42 follow_double = u"\u201d"43 lead_single = u"\u201a"44 follow_single = u"\u2019"45 elif ((lang == 'se') or (lang == 'fi')):46 lead_double = u"\u201d"47 follow_double = u"\u201d"48 lead_single = u"\u2019"49 follow_single = u"\u2019"50 elif (lang == 'af'):51 lead_double = u"\u201c"52 follow_double = u"\u201d"53 lead_single = u"\u2018"54 follow_single = u"\u2019"55 elif (lang == 'sq'):56 lead_double = u"\u201e"57 follow_double = u"\u201c"58 lead_single = u"\u2018"59 follow_single = u"\u2019"60 elif ((lang == 'be') or (lang == 'ch') or (lang == 'uk') or (lang == 'ru')):61 lead_double = u"\u00ab"62 follow_double = u"\u00bb"63 lead_single = u"\u2039"64 follow_single = u"\u203a"65 elif (lang == 'uk'):66 lead_double = u"\u00ab"67 follow_double = u"\u00bb"68 lead_single = u"\u2039"69 follow_single = u"\u203a"70 elif (lang == 'es'):71 lead_double = u"\u00ab"72 follow_double = u"\u00bb"73 lead_single = u"\u2018"74 follow_single = u"\u2019"75 elif ((lang == 'lt') or (lang == 'is') or (lang == 'sk') or (lang == 'sl') or (lang == 'cs') or (lang == 'et')):76 lead_double = u"\u201e"77 follow_double = u"\u201c"78 lead_single = u"\u201a"79 follow_single = u"\u2018"80 elif (lang == 'mk'):81 lead_double = u"\u201e"82 follow_double = u"\u201c"83 lead_single = u"\u2019"84 follow_single = u"\u2018"85 elif ((lang == 'hu') or (lang == 'nl')):86 lead_double = u"\u201e"87 follow_double = u"\u201d"88 lead_single = u"\u00bb"89 follow_single = u"\u00ab"90 else:91 scribus.messageBox('Language Error', 'You need to choose an available language', scribus.ICON_WARNING, scribus.BUTTON_OK)92 sys.exit(2)93 94else:95 scribus.messageBox('Usage Error', 'You need a Document open', scribus.ICON_WARNING, scribus.BUTTON_OK)96 sys.exit(2)97if scribus.selectionCount() == 0:98 scribus.messageBox('Scribus - Usage Error',99 "There is no object selected.\nPlease select a text frame and try again.",100 scribus.ICON_WARNING, scribus.BUTTON_OK)101 sys.exit(2)102if scribus.selectionCount() > 1:103 scribus.messageBox('Scribus - Usage Error',104 "You have more than one object selected.\nPlease select one text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)105 sys.exit(2)106textbox = scribus.getSelectedObject()107pageitems = scribus.getPageItems()108boxcount = 1109for item in pageitems:110 if (item[0] == textbox):111 if (item[1] != 4):112 scribus.messageBox('Scribus - Usage Error', "This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)113 sys.exit(2)114contents = scribus.getTextLength(textbox)115while c <= (contents -1):116 if ((c + 1) > contents - 1):117 nextchar = ' '118 else:119 scribus.selectText(c+1, 1, textbox)120 nextchar = scribus.getAllText(textbox)121 scribus.selectText(c, 1, textbox)122 char = scribus.getAllText(textbox)123 if (len(char) != 1):124 c += 1125 continue126 if ((ord(char) == 34) and (c == 0)):127 scribus.deleteText(textbox)128 scribus.insertText(lead_double, c, textbox)129 elif (ord(char) == 34):130 if ((prevchar == '.') or (prevchar == ',') or (prevchar == '?') or (prevchar == '!')):131 scribus.deleteText(textbox)132 scribus.insertText(follow_double, c, textbox)133 elif ((ord(prevchar) == 39) and ((nextchar != ' ') and (nextchar != ',') and (nextchar != '.'))):134 scribus.deleteText(textbox)135 scribus.insertText(lead_double, c, textbox)136 elif ((nextchar == '.') or (nextchar == ',')):137 scribus.deleteText(textbox)138 scribus.insertText(follow_double, c, textbox)139 elif ((prevchar == ' ') or ((nextchar != ' ') and (ord(nextchar) != 39))):140 scribus.deleteText(textbox)141 scribus.insertText(lead_double, c, textbox)142 else:143 scribus.deleteText(textbox)144 scribus.insertText(follow_double, c, textbox)145 146 if ((ord(char) == 39) and (c == 0)):147 scribus.deleteText(textbox)148 scribus.insertText(lead_single, c, textbox)149 elif (ord(char) == 39):150 if ((prevchar == '.') or (prevchar == ',') or (prevchar == '?') or (prevchar == '!')):151 scribus.deleteText(textbox)152 scribus.insertText(follow_single, c, textbox)153 elif ((ord(prevchar) == 34) and ((nextchar != ' ') and (nextchar != ',') and (nextchar != '.'))):154 scribus.deleteText(textbox)155 scribus.insertText(lead_single, c, textbox)156 elif ((prevchar != ' ') and (ord(prevchar) != 34) and (nextchar != ' ')):157 scribus.deleteText(textbox)158 scribus.insertText(follow_single, c, textbox)159 elif ((prevchar == ' ') or ((nextchar != ' ') and (ord(nextchar) != 34))):160 scribus.deleteText(textbox)161 scribus.insertText(lead_single, c, textbox)162 else:163 scribus.deleteText(textbox)164 scribus.insertText(follow_single, c, textbox)165 166 c += 1167 prevchar = char168scribus.setRedraw(1)169scribus.docChanged(1)170endmessage = 'Successfully ran script\n Last character read was '+str(char) # Change this message to your liking...

Full Screen

Full Screen

6093.设计一个文本编辑器.py

Source:6093.设计一个文本编辑器.py Github

copy

Full Screen

1#!/usr/bin/env python2# -*- coding: utf-8 -*-3"""4@File : 6093.设计一个文本编辑器.py5@Time : 2022/06/05 11:01:256@Author : wylu7@Version : 1.08@Contact : 15wylu@gmail.com9@License : Copyright © 2020, wylu-CHINA-SHENZHEN. All rights reserved.10@Desc :11"""12class Node:13 def __init__(self, val='#', prev=None, next=None):14 self.val = val15 self.prev = prev16 self.next = next17class TextEditor:18 def __init__(self):19 self.head = Node()20 self.tail = Node()21 self.head.next = self.tail22 self.tail.prev = self.head23 self.cursor = self.head24 self.indice = 025 self.total = 026 def addText(self, text: str) -> None:27 tmp = self.cursor.next28 for ch in text:29 self.cursor.next = Node(ch, prev=self.cursor)30 self.cursor = self.cursor.next31 self.cursor.next = tmp32 tmp.prev = self.cursor33 self.indice += len(text)34 self.total += len(text)35 def deleteText(self, k: int) -> int:36 k = min(k, self.indice)37 self.indice -= k38 self.total -= k39 tmp = self.cursor.next40 for _ in range(k):41 self.cursor = self.cursor.prev42 self.cursor.next = tmp43 tmp.prev = self.cursor44 return k45 def cursorLeft(self, k: int) -> str:46 k = min(k, self.indice)47 self.indice -= k48 for _ in range(k):49 self.cursor = self.cursor.prev50 res = []51 cur = self.cursor52 for _ in range(min(self.indice, 10)):53 res.append(cur.val)54 cur = cur.prev55 res.reverse()56 return ''.join(res)57 def cursorRight(self, k: int) -> str:58 k = min(k, self.total - self.indice)59 self.indice += k60 for _ in range(k):61 self.cursor = self.cursor.next62 res = []63 cur = self.cursor64 for _ in range(min(self.indice, 10)):65 res.append(cur.val)66 cur = cur.prev67 res.reverse()68 return ''.join(res)69 def __str__(self) -> str:70 res = []71 cur = self.head.next72 while cur != self.tail:73 res.append(cur.val)74 cur = cur.next75 return ''.join(res)76# Your TextEditor object will be instantiated and called as such:77# obj = TextEditor()78# obj.addText(text)79# param_2 = obj.deleteText(k)80# param_3 = obj.cursorLeft(k)81# param_4 = obj.cursorRight(k)82if __name__ == '__main__':83 obj = TextEditor()84 # ["TextEditor","addText","deleteText","addText","cursorLeft","addText","deleteText","addText","cursorLeft","deleteText"]85 # [[],["arnvmumatgmyw"],[5],["zrlufuifuy"],[2],["unh"],[20],["kwwp"],[6],[9]]86 obj.addText('arnvmumatgmyw')87 print(obj)88 print("==================================")89 print(obj.deleteText(5))90 print(obj)91 print("==================================")92 obj.addText('zrlufuifuy')93 print(obj)94 print("==================================")95 print(obj.cursorLeft(2))96 print(obj)97 print("==================================")98 # ==============================================================99 # ["TextEditor","addText","cursorLeft","deleteText","cursorLeft","addText","cursorRight"]100 # [[],["bxyackuncqzcqo"],[12],[3],[5],["osdhyvqxf"],[10]]101 # obj.addText('bxyackuncqzcqo')102 # print(obj)103 # print("==================================")104 # print(obj.cursorLeft(12))105 # print(obj)106 # print("==================================")107 # print(obj.deleteText(3))108 # print(obj)109 # print("==================================")110 # print(obj.cursorLeft(5))111 # print(obj)112 # print("==================================")113 # obj.addText('osdhyvqxf')114 # print(obj)115 # print("==================================")116 # print(obj.cursorRight(10))117 # print(obj)118 # print("==================================")119 # ==============================================================120 # obj.addText('leetcode')121 # print(obj)122 # print(obj.deleteText(4))123 # print(obj)124 # obj.addText('practice')125 # print(obj)126 # print(obj.cursorRight(3))127 # print(obj)128 # print(obj.cursorLeft(8))129 # print(obj)130 # print(obj.deleteText(10))131 # print(obj)132 # print(obj.cursorLeft(2))133 # print(obj)134 # print(obj.cursorRight(6))...

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