def handle(self, text_window: PaneControl, text_pos: TextPosition) -> TextPosition: if text_pos[0:2] in (' "', '("', '>"'): text_window.SendKeys('{Right}{Shift}({Right})„', waitTime=0) text_pos.text = text_pos.text.replace(text_pos[1], '„', 1) text_pos += 2 elif text_pos[-2:0] in (' "', '("', '>"'): text_window.SendKeys('{Shift}({Left})„', waitTime=0) text_pos.text = text_pos.text.replace(text_pos[-2], '„', 1) return text_pos
def handle(self, text_window: PaneControl, text_pos: TextPosition) -> TextPosition: if text_pos[-1] == '\n': if text_pos[0] not in ('$', '|'): text_window.SendKeys('$>', waitTime=0) text_pos.insert('$>') text_pos += 2 if text_pos[0] in ('-', '—'): text_window.SendKeys('{Shift}({Right 2})— {Left 2}', waitTime=0) return text_pos
def handle(self, text_window: PaneControl, text_pos: TextPosition) -> TextPosition: stop_chars = (' ', '(', '=', '>', '\t', '\n', '_', '[') while all( (text_pos[-1] not in stop_chars, self.it_access.State != 0, text_pos.pos != 0)): if text_pos[-2:0] == '$>': text_window.SendKeys('{Shift}({Left 2})', waitTime=0) self.it_invoke.Invoke(waitTime=0) text_window.SendKeys('{Right}', waitTime=0) continue text_window.SendKeys('{Left}', waitTime=0) text_pos -= 1 return text_pos
def handle(self, text_window: PaneControl, text_pos: TextPosition) -> TextPosition: keys = [self.precode + key for key in self.dict.keys()] if text_pos[0:2] in keys: n = self.__count_chars(text_pos) text_window.SendKeys('{Shift}({Right ' + str(1 + n) + '})', waitTime=0) chars_new = '' for char in text_pos[1:1 + n]: chars_new += self.dict[char] text_window.SendKeys(chars_new + '{Left}', waitTime=0) text_pos.text = text_pos.text.replace(text_pos[0:1 + n], chars_new, 1) text_pos += n - 1 return text_pos
def handle(self, text_window: PaneControl, text_pos: TextPosition) -> TextPosition: if text_pos[0:2] in ('" ', '".', '",'): text_window.SendKeys('{Shift}({Right})”', waitTime=0) text_pos.text = text_pos.text.replace(text_pos[0], '”', 1) text_pos += 1 return text_pos
def handle(self, text_window: PaneControl, text_pos: TextPosition) -> TextPosition: if text_pos[0] != '\n': text_window.SendKeys('{Left}', waitTime=0) else: text_window.SendKeys('€', waitTime=0) return text_pos offset = self.__set_offset(text_pos) text_window.SendKeys(f'{{Shift}}({{Left {offset}}})', waitTime=0) self.it_invoke.Invoke(waitTime=0) if offset > 0: text_window.SendKeys('{Left}', waitTime=0) text_window.SendKeys(f'€{{Right {offset}}}', waitTime=0) while self.it_access.State == 16: time.sleep(0.001) return text_pos - 1
def handle(self, text_window: PaneControl, text_pos: TextPosition) -> TextPosition: if text_pos[0:3] in (' - ', '>- ', '>-\t'): new_dash = text_pos[0] + '— ' text_window.SendKeys('{Shift}({Right 3})' + new_dash, waitTime=0) text_pos.text = text_pos.text.replace(text_pos[0:3], new_dash, 1) text_pos += 3 return text_pos
def text_position_initialise( text_window: PaneControl, copy_button_control: ButtonControl) -> TextPosition: text_window.SetFocus() sleep(0.5) text_window.SendKeys('{Ctrl}{Home}') sleep(0.5) text_window.SendKeys('{Shift}{Ctrl}{End}') copy_button_control.Click(simulateMove=False, waitTime=1) sleep(0.5) text_window.SendKeys('{Left}', waitTime=0) text = pyperclip.paste() text = re.sub('\r\n', '\n', text) text = re.sub('\n+', '\n', text) text = re.sub('— ', '— ', text) return TextPosition(text, 0, text_window=text_window)
def handle(self, text_window: PaneControl, text_pos: TextPosition) -> TextPosition: if text_pos[0:3] in SKR.keys(): text_window.SendKeys('{Shift}({Right 3})', waitTime=0) char_abb = text_pos[0:3] is_italic = self.it_access.State == 16 text_window.SendKeys(SKR[char_abb], waitTime=0) while self.it_access.State == 16: time.sleep(0.001) if is_italic: text_window.SendKeys('{Shift}({Left})', waitTime=0) self.it_invoke.Invoke() text_window.SendKeys('{Right}', waitTime=0) while self.it_access.State == 0: time.sleep(0.001) text_pos.text = text_pos.text.replace(char_abb, SKR[char_abb], 1) text_pos += 1 return text_pos
def handle(self, text_window: PaneControl, text_pos: TextPosition) -> TextPosition: while self.it_access.State == 16: text_pos = self.abb_hdl.handle(text_window, text_pos) text_window.SendKeys('{Right}', waitTime=0) text_pos += 1 if text_pos.pos >= len(text_pos.text) or text_pos[0] == '\n': self.it_invoke.Invoke() break return text_pos
def handle(self, text_window: PaneControl, text_pos: TextPosition) -> TextPosition: if text_pos[-4:-1] in [' w ', ' — ']: text_window.SendKeys('{Left}', waitTime=0.07) text_window.SendKeys('{Shift}({Left 4})', waitTime=0.07) self.copy_button_control.Click(simulateMove=False) text_window.SendKeys('{Right}') test = pyperclip.paste() if test[0] == '€': text_window.SendKeys('{Left 3}{Back}{Right 4}') else: text_window.SendKeys('{Right}') if text_pos[-1] in (' ', '>', '(') or text_pos.pos == 0: text_window.SendKeys('€', waitTime=0) text_pos = self.abb_hdl.handle(text_window, text_pos) text_window.SendKeys('{Right}', waitTime=0) text_pos += 1 while self.it_access.State == 0: time.sleep(0.001) return text_pos
def corrector(italic: uiautomation.ButtonControl, text_window: uiautomation.PaneControl, copy_button_control: uiautomation.ButtonControl) -> str: normal_handlers, italic_handlers = handlers_initialize( italic, copy_button_control) text_pos = text_position_initialise(text_window, copy_button_control) while text_pos.pos < len(text_pos.text): for mapping in KeyboardMappings.get_all(): mapping() for hdl in normal_handlers: text_pos = hdl.handle(text_window, text_pos) text_pos = cursor.forward(text_pos, 1) italic_pattern = italic.GetLegacyIAccessiblePattern() if italic_pattern.State == 0: continue elif italic_pattern.State == 16: print('Pierwsze znaki italicu: ' + text_pos[-1:1]) if text_pos[-4:-1] in [' w ', ' — ']: text_window.SendKeys('{Left}', waitTime=0.07) text_window.SendKeys('{Shift}({Left 4})', waitTime=0.07) copy_button_control.Click(simulateMove=False) text_window.SendKeys('{Right}') test = pyperclip.paste() print(test) if test[0] == '€': text_window.SendKeys('{Left 3}{Back}{Right 4}') else: text_window.SendKeys('{Right}') elif text_pos[-1:1] == ', ': text_window.SendKeys('{Right}') text_pos += 1 if italic_pattern.State == 16: text_window.SendKeys('€') for hdl in italic_handlers: text_pos = hdl.handle(text_window, text_pos) # if italic_pattern.State == 0: # n = old_pass - pass_count # TextWindow.SendKeys('{Shift}({Right ' + str(n) + '})') # Italic.GetInvokePattern().Invoke() # TextWindow.SendKeys('{Right}') # pass_count += n # else: # TextWindow.SendKeys('{Right}') # pass_count += 1 # else: # TextWindow.SendKeys('{Left}€{Right}') # it_str = text[pass_count - 1:pass_count + 1] # # if it_str: # it_str = it_str[:-2] # else: # continue # print(it_str) # if it_str[-1] in [',', '.', ' ', ';']: # if it_str[-3:] in [' r.', ' w.', '...'] or it_str[-4:] == ' al.' or it_str[-5:] == ' cit.': # TextWindow.SendKeys('{Left}€{Right}', waitTime=0.01) # else: # TextWindow.SendKeys('{Left 2}') # Italic.GetInvokePattern().Invoke() # TextWindow.SendKeys('€{Right 2}') # elif it_str[-2:] == ', ': # print(it_str) # TextWindow.SendKeys('{Left 3}€{Right 3}', waitTime=0.01) # else: return text_pos.text