Skip to content

Commit

Permalink
Merge pull request #6 from dictation-toolbox/master
Browse files Browse the repository at this point in the history
remove the old unimacro website (#55) try 2
  • Loading branch information
quintijn authored Aug 15, 2024
2 parents b46490e + 13ffe0d commit f61d63e
Show file tree
Hide file tree
Showing 522 changed files with 771 additions and 31,678 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ More about [Unimacro Grammars](https://qh.antenna.nl/unimacro/grammars/globalgra
# Developer instructions.

If you want to install your local unimacro development environment as the working unimacro:
`pip install -e . `.
`pip install -e .[dev,test] `.

`py -m build` to build the Python package locally.

Publishing to PyPi is done through the [trusted publisher mechanism](https://docs.pypi.org/trusted-publishers/using-a-publisher/) when a release is created on github using github actions.

BEFORE YOU PUBLISH review the version number of dependencies in pyproject.toml, see if you require newer ones.
To publish a release to [Python Packaging Index](https://pypi.org/), [draft a new release](https://github.com/dictation-toolbox/unimacro/releases).



Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ requires-python = ">=3.10"
readme = "README.md"


dependencies = ["dtactions >= 1.5.7",
dependencies = ["dtactions >= 1.6.1",
"debugpy >= 1.2.0",
"pywin32 >= 304",
"natlinkcore >= 5.3.7",
"pysimplegui"]
"natlinkcore >= 5.4.0",
"FreeSimpleGUI>=5.1.0"]

classifiers=[ "Development Status :: 4 - Beta",
"Topic :: Multimedia :: Sound/Audio :: Speech",
Expand Down Expand Up @@ -56,7 +56,6 @@ pythonpath = [
]
testpaths= [
"tests",
"src/unimacro/unimacro_test"
]
python_files = [
"unittest*.py",
Expand Down
128 changes: 56 additions & 72 deletions src/unimacro/UnimacroGrammars/_brackets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
Basically two ways are implemented:
1. Say: "between brackets hello comma this is a test"
2. select text, and say "between brackets"/
2. select text, and say "between brackets"
3. say "empty braces"
4. say "here parens"
Notes:
======
Expand All @@ -21,16 +23,19 @@
2. No capitalisation is done unless you call as directive.
3. Dictation errors cannot be corrected with the spell window. Select,
dictate again and
correct then if needed.
dictate again and then correct then if needed.
Note: the natlinkclipboard module from dtactions is not ready for use. Use
the unimacroutils module of unimacro.
"""
#pylint:disable=C0115, C0116, W0201, W0613
from natlinkcore import nsformat
from dtactions.unimacro import unimacroutils
from dtactions.unimacro.unimacroactions import doAction as action
from dtactions.unimacro.unimacroactions import doKeystroke as keystroke
from dtactions.natlinkclipboard import Clipboard
# from dtactions.natlinkclipboard import Clipboard
import unimacro.natlinkutilsbj as natbj
import natlink

Expand All @@ -57,7 +62,7 @@ def gotBegin(self,moduleInfo):
def gotResultsInit(self, words, fullResults):
self.dictated = '' # analysis of dgndictation or dgnletters
self.pleft = self.pright = '' # the left and right parts of the brackets

self.here, self.between, self.empty = False, False, False
if self.mayBeSwitchedOn == 'exclusive':
print(f'recog brackets, switch off mic: {words}')
natbj.SetMic('off')
Expand Down Expand Up @@ -90,98 +95,75 @@ def rule_brackets(self, words):

def subrule_before(self, words):
"(here|between|empty)+"
self.here, self.between = False, False

for w in words:
if self.hasCommon(w, 'between'): # this is the trigger word, ignore
self.between = True
if self.hasCommon(w, 'here'): # this is the trigger word, ignore
self.here = True
if self.hasCommon(w, 'empty'): # this is the trigger word, ignore
self.between = False

self.empty = True

def gotResults(self, words, fullResults):

# see if something selected, leaving the clipboard intact
# keystroke('{ctrl+x}') # try to cut the selection
if self.between:
cb = Clipboard(save_clear=True)
action('<<cut>>')
cb.wait_for_clipboard_change()
text = cb.get_text()
else:
text = ""
# if no text is dictated, self.dictated = ""
text, leftTextDict, rightTextDict = stripFromBothSides(self.dictated)

if self.here:
print('do a left buttonClick')
unimacroutils.buttonClick('left', 1)
print('do a "visibleWait')
unimacroutils.visibleWait()
print('after a visibleWait')

leftText = rightText = leftTextDict = rightTextDict = ""
if text:
# strip from clipboard text:
text, leftText, rightText = stripFromBothSides((text))

if self.dictated.strip():
text, leftTextDict, rightTextDict = stripFromBothSides(self.dictated)
elif self.dictated:
# the case of only a space-bar:
leftTextDict = self.dictated

if self.empty:
if self.dictated:
print(f'_brackets, warning, dictated text "{self.dictated}" is ignored, because of keyword "empty"')
self.do_keystrokes_brackets()
return

# only if no dictated text, try to cut the selection (if there, add one char for safety with
# the clipboard actions, only fails when at end of file)
if not self.dictated:
unimacroutils.saveClipboard()
keystroke('{shift+right}') # take one extra char for the clipboard to hit
action('<<cut>>')
action('W')
cb_text = unimacroutils.getClipboard()
unimacroutils.restoreClipboard()
if cb_text:
text, lastchar = cb_text[:-1], cb_text[-1]
else:
action('<<undo>>')
raise OSError('no value in clipboard, restore cut text')
print(f'_brackets, got from clipboard: "{text}" + extra char: "{lastchar}"')
self.do_keystrokes_brackets(text=text, lastchar=lastchar)
return

lSpacing = leftText + leftTextDict
rSpacing = rightTextDict + rightText

if lSpacing:
keystroke(lSpacing)
self.do_keystrokes_brackets(text=text, l_spacing=leftTextDict, r_spacing=rightTextDict)

#
def do_keystrokes_brackets(self, text='', lastchar='', l_spacing='', r_spacing=''):
"""do the pleft text pright keystrokes with spacing issues
handle the "between" keyword here!
"""
keystroke(l_spacing)
keystroke(self.pleft)
unimacroutils.visibleWait()
if text:
#print 'text: |%s|'% repr(text)
keystroke(text)
unimacroutils.visibleWait()
unimacroutils.visibleWait()
keystroke(self.pright)
unimacroutils.visibleWait()

if rSpacing:
keystroke(rSpacing)

if not text:
# go back so you stand inside the (brackets):
nLeft = len(self.pright) + len(rSpacing)
keystroke(f'{{left {nLeft}}}')
#
def fillDefaultInifile(self, ini):
"""filling entries for default ini file
"""
if self.language == 'nld':
ini.set('brackets', 'aanhalingstekens', '""')
ini.set('brackets', 'kwoots', "''")
ini.set('brackets', 'brekkits', '[]')
ini.set('brackets', 'haakjes', '()')
ini.set('brackets', 'punt haakjes', '<>')
ini.set('brackets', 'driedubbele aanhalingstekens', '""""""')
ini.set('brackets', 'accolades', '{}')
ini.set('brackets', 'html punt haakjes', "&lt;|>")
ini.set('brackets', 'html brekkits', "&#091;|]")
else:
ini.set('brackets', 'double quotes', '""')
ini.set('brackets', 'quotes', "''")
ini.set('brackets', 'single quotes', "''")
ini.set('brackets', 'square brackets', '[]')
ini.set('brackets', 'brackets', '()')
ini.set('brackets', 'parenthesis', '()')
ini.set('brackets', 'backticks', '``')
ini.set('brackets', 'parens', '()')
ini.set('brackets', 'angle brackets', '<>')
ini.set('brackets', 'triple quotes', '""""""')
ini.set('brackets', 'html angle brackets', "&lt;|>")
ini.set('brackets', 'html square brackets', "&#091;|]")
ini.set('brackets', 'braces', '{}')
keystroke(r_spacing)
if lastchar:
keystroke(lastchar)
keystroke("{left %s}"% len(lastchar))
if self.between:
keystroke("{left %s}"% len(self.pright))


def stripFromBothSides(text):
"""strip whitespace from left side and from right side and return
Expand All @@ -190,6 +172,8 @@ def stripFromBothSides(text):
input: text
output: stripped, leftSpacing, rightSpacing
"""
if not text:
return "", "", ""
leftText = rightText = ""
lSpaces = len(text) - len(text.lstrip())
leftText = rightText = ""
Expand Down
23 changes: 18 additions & 5 deletions src/unimacro/UnimacroGrammars/_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@
import win32gui
from win32com.client import Dispatch
import win32clipboard
from logging import Logger,getLogger
from io import StringIO

import natlink
from natlinkcore import readwritefile
Expand Down Expand Up @@ -616,7 +614,6 @@ def getActiveFolder(self, hndle=None, className=None):
if not className:
return None
f = None

if className == "CabinetWClass":
f = mess.getFolderFromCabinetWClass(hndle)
elif className == '#32770':
Expand Down Expand Up @@ -1185,6 +1182,7 @@ def gotResults_namepathcopy(self, words, fullResults):
else:
self.info("_folders, namepathcopy, choose copy name or path, not: %s", repr(words))
return

if self.catchRemember == "folder":
if not self.wantedFolder:
self.info("_folders, namepathcopy, no valid folder")
Expand All @@ -1211,6 +1209,8 @@ def gotResults_namepathcopy(self, words, fullResults):
result = self.wantedWebsite.split("/")[-1]
else:
result = self.wantedWebsite.split()[-1]
else:
result = ''
self.info('namepathcopy, result: %s (type: %s)', result, type(result))
unimacroutils.setClipboard(result, 13) # 13 unicode!!

Expand Down Expand Up @@ -1931,6 +1931,15 @@ def gotoFolder(self, f):
## print 'xx: %s, Iam2x: %s, IamExplorer: %s'% (xx, Iam2x, IamExplorer)
##
IamExplorer = prog == 'explorer'
try:
classname = win32gui.GetClassName(hndle)
except:
logger.debug('Invalid hndle for GetClassName: {hndle}')
classname = ''
IamChild32770 = (not istop) and classname == '#32770'



IamChild32770 = (not istop) and win32gui.GetClassName(hndle) == '#32770'
if IamChild32770:
self.className = '#32770'
Expand Down Expand Up @@ -2018,7 +2027,9 @@ def gotoFolder(self, f):
if len(t) < lenMin:
take = h
lenMin = len(t)

break
else: ## TODO QH simplify this!
take = 0
## print 'i: %s, take: %s'% (i, nearList[i])
toHandle = take
thisHandle = hndle ## ?? TODO
Expand Down Expand Up @@ -2338,6 +2349,8 @@ def get_clipboard_files(folders=False):
files = [win32clipboard.GetClipboardData(win32clipboard.CF_TEXT)]
elif win32clipboard.CF_OEMTEXT in f:
files = [win32clipboard.GetClipboardData(win32clipboard.CF_OEMTEXT)]
else:
files = [] ## OK? Quintijn
if not files:
# self.info "get_clipboard_files, no files found from clipboard"
return None
Expand Down Expand Up @@ -2453,7 +2466,7 @@ def unload():
# thisGrammar.catchTimerRecentFolders(132524, "CabinetWClass")
active_folder = thisGrammar.getActiveFolder(198434)
print(f'active_folder: {active_folder}')

thisGrammar.displayRecentFolders()
# get hndle of a explore window (via _general "give window info") and try interactive
# thisGrammar.catchTimerRecentFolders(132524, "CabinetWClass")

Expand Down
11 changes: 10 additions & 1 deletion src/unimacro/UnimacroGrammars/_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from natlinkcore import natlinkstatus
from natlinkcore import nsformat
from natlinkcore import natlinkutils as natut
from natlinkcore import natlinktimer
from unimacro import natlinkutilsbj as natbj
from unimacro import namelist # for name phrases

Expand Down Expand Up @@ -126,7 +127,7 @@ class ThisGrammar(ancestor):
<test> exported = test micstate;
<choose> exported = choose {n1-10};
<reload> exported = reload Natlink;
<info> exported = give (user | prog |window |unimacro| path) (info|information) ;
<info> exported = give (user|prog|window|unimacro|path|timer) (info|information) ;
<undo> exported = Undo [That] [{count} [times]];
<redo> exported = Redo [That] [{count} [times]];
<namephrase> exported = Make That [Name] phrase;
Expand Down Expand Up @@ -699,6 +700,14 @@ def gotResults_info(self,words,fullResults):
elif self.hasCommon(words,'path'):
T.append('the python path:')
T.append(pprint.pformat(sys.path))
elif self.hasCommon(words, "timer"):
timer_info = natlinktimer.getNatlinktimerStatus()
if timer_info is None:
T.append('natlinktimer is not active')
elif timer_info == 1:
T.append('there is 1 timer active')
else:
T.append(f'there are {timer_info} timers active')
elif self.hasCommon(words, "class"):
T.append()
else:
Expand Down
Loading

0 comments on commit f61d63e

Please sign in to comment.