Skip to content

Commit

Permalink
Merge pull request #334 from dictation-toolbox/fix/keyboard-side-effects
Browse files Browse the repository at this point in the history
Change keyboard-related import-time side-effects
  • Loading branch information
drmfinlay committed Apr 26, 2021
2 parents 4b47603 + 3176e78 commit 2cdeff9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
11 changes: 8 additions & 3 deletions dragonfly/actions/action_base_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .action_base import DynStrActionBase
from .keyboard import Keyboard


_CONFIG_LOADED = False
UNICODE_KEYBOARD = False
HARDWARE_APPS = [
"tvnviewer.exe", "vncviewer.exe", "mstsc.exe", "virtualbox.exe"
Expand All @@ -50,6 +50,7 @@ def load_configuration():
global UNICODE_KEYBOARD
global HARDWARE_APPS
global PAUSE_DEFAULT
global _CONFIG_LOADED

home = os.path.expanduser("~")
config_folder = os.path.join(home, ".dragonfly2-speech")
Expand All @@ -75,8 +76,7 @@ def load_configuration():
if parser.has_option("Text", "pause_default"):
PAUSE_DEFAULT = parser.getfloat("Text", "pause_default")


load_configuration()
_CONFIG_LOADED = True


class BaseKeyboardAction(DynStrActionBase):
Expand Down Expand Up @@ -110,6 +110,11 @@ def require_hardware_events(self):
if not sys.platform.startswith("win") or self._use_hardware:
return True

# Load the keyboard configuration, if necessary.
global _CONFIG_LOADED
if not _CONFIG_LOADED:
load_configuration()

# Otherwise check if hardware events should be used with the current
# foreground window.
from dragonfly.windows import Window
Expand Down
15 changes: 7 additions & 8 deletions dragonfly/actions/action_paste.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,19 @@ class Paste(DynStrActionBase):

_default_format = Clipboard.format_unicode

# Default paste action.
# Fallback on Shift-insert if 'v' isn't available. Use Super-v on macs.
try:
_default_paste = (Key("w-v/20") if sys.platform == "darwin"
else Key("c-v/20"))
except ActionError:
_default_paste = Key("s-insert/20")
# Default paste action spec.
_default_paste_spec = "w-v/20" if sys.platform == "darwin" else "c-v/20"

# pylint: disable=redefined-builtin
def __init__(self, contents, format=None, paste=None, static=False):
if not format:
format = self._default_format
if paste is None:
paste = self._default_paste
try:
paste = Key(self._default_paste_spec)
except ActionError:
# Fallback on Shift-insert if 'v' isn't available.
paste = Key("s-insert/20")
if isinstance(contents, string_types):
spec = contents
self.contents = None
Expand Down

0 comments on commit 2cdeff9

Please sign in to comment.