Skip to content

Commit

Permalink
_latex.py works for most things, I believe.
Browse files Browse the repository at this point in the history
small things in _lines.py
  • Loading branch information
quintijn committed Oct 21, 2022
1 parent cfc632d commit b29b8dc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
37 changes: 21 additions & 16 deletions src/unimacro/UnimacroGrammars/_latex.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Unimacro grammar to Dictate latex markup, as defined in an inifile
"""
# This file is part of a SourceForge project called "unimacro" see
# This file is/was part of a SourceForge project called "unimacro" see
# http://unimacro.SourceForge.net and http://qh.antenna.nl/unimacro
# (c) copyright 2003 see http://qh.antenna.nl/unimacro/aboutunimacro.html
# or the file COPYRIGHT.txt in the natlink\natlink directory
Expand All @@ -12,14 +12,12 @@
# March 2011
#
#pylint:disable = R0912, C0209, E1101
import time
import natlink
from natlinkcore import nsformat
from natlinkcore import natlinkstatus
from dtactions.unimacro import unimacroutils
from dtactions.unimacro.unimacroactions import doAction as action
from dtactions.sendkeys import sendkeys as keystroke
from dtactions.natlinkclipboard import Clipboard
import unimacro.natlinkutilsbj as natbj

status = natlinkstatus.NatlinkStatus()
Expand Down Expand Up @@ -94,7 +92,7 @@ def gotResults_command(self, words, fullResults):
contents = self.get_selection_that(line = 0)
if self.hasCommon(words, ['line']):
contents = self.get_selection_that(line = 1)

contents = contents.strip()

stringpaste(Cmd)
if pos > 0 or self.hasCommon(words, ['arguments']):
Expand All @@ -112,13 +110,14 @@ def gotResults_command(self, words, fullResults):
if label:
## workaround for keystrokes: {{}
keystroke('{enter}')
stringpaste(r'\label{}%s}'% (self.makes_label(label, contents)))
stringpaste(r'\label{%s}'% (self.makes_label(label, contents)))
keystroke('{enter}')

def gotResults_options(self, words, fullResults):
selection = self.view_selection_current_line()
if selection:
print(f'select_current_line: {selection}')
pass
# print(f'select_current_line: {selection}')
else:
print('no selection found')
options = self.getFromInifile(words, 'options', noWarning=1)
Expand Down Expand Up @@ -195,9 +194,9 @@ def gotResults(self, words, fullResults):

def gotResults_dgndictation(self, words, fullResults):
"""do with nsformat functions"""
print('got dgndictation: %s'% words)
# print('got dgndictation: %s'% words)
self.dictation, dummy = nsformat.formatWords(words) # state not needed in call
print(' result of nsformat: %s'% repr(self.dictation))
# print(' result of nsformat: %s'% repr(self.dictation))


def get_selection_that(self, line = 0):
Expand All @@ -207,39 +206,45 @@ def get_selection_that(self, line = 0):
action('<<selectline>><<cut>>')
else:
action('<<cut>>')
action('W')
contents = natlink.getClipboard().strip().replace('\r', '')
if len(contents) == 0:
if line:
print('_latex, empty line')
return ""
action('HW select that')
action('<<cut>>')
action('W')
contents = natlink.getClipboard().strip().replace('\r', '')
if len(contents) == 0:
print('_latex, empty contents, no last dicatate utterance available')
print('_latex, empty contents, no last dictate utterance available')

unimacroutils.restoreClipboard()
return contents

def view_selection_current_line(self):
cb = Clipboard()
contents = cb.copy_and_get_clipboard()
unimacroutils.saveClipboard()
keystroke('{ctrl+c}')
action('W')
contents = natlink.getClipboard()
if len(contents) == 0:
print('no_space_by_existing selection')
# print('no_space_by_existing selection')
keystroke('{end}{shift+home}')
time.sleep(0.3)
contents = cb.copy_and_get_clipboard()
keystroke('{ctrl+c}')
action('W')
contents = natlink.getClipboard()
unimacroutils.restoreClipboard()
return contents



def makes_label(self, Type, Text):
return Type + ':' + ''.join(Text.split()).lower()

def stringpaste(t):
"""paste via clipboard, to circumvent German keyboard issues
"""
action('SCLIP "%s"'%t)
print(f'stringpaste: |{t}|')
action(f'SCLIP "{t}"')

# standard stuff Joel (QH, Unimacro, python3):
try:
Expand Down
2 changes: 1 addition & 1 deletion src/unimacro/UnimacroGrammars/_lines.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file was part of a SourceForge project called "unimacro" see
# http://unimacro.SourceForge.net and http://qh.antenna.nl/unimacro
# (c) copyright 2003 see http://qh.antenna.nl/unimacro/aboutunimacro.html
# (c) copyright 2003 see https://qh.antenna.nl/unimacro/aboutunimacro/index.html
# or the file COPYRIGHT.txt in the natlink\natlink directory
# Now in the dictation-toolbox: https://github.com/dictation-toolbox/unimacro

Expand Down

0 comments on commit b29b8dc

Please sign in to comment.