Skip to content

Commit

Permalink
Fix a bug with Text action default pause values
Browse files Browse the repository at this point in the history
This change fixes a bug where the PAUSE_DEFAULT setting in the
Windows-only settings.cfg file is not used properly by Text actions.
  • Loading branch information
drmfinlay committed Aug 23, 2021
1 parent 72d5154 commit 4ebd104
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
16 changes: 14 additions & 2 deletions dragonfly/actions/action_base_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
HARDWARE_APPS = [
"tvnviewer.exe", "vncviewer.exe", "mstsc.exe", "virtualbox.exe"
]
PAUSE_DEFAULT = 0.005


def load_configuration():
Expand All @@ -48,6 +49,7 @@ def load_configuration():

global UNICODE_KEYBOARD
global HARDWARE_APPS
global PAUSE_DEFAULT
global _CONFIG_LOADED

home = os.path.expanduser("~")
Expand All @@ -63,13 +65,18 @@ def load_configuration():
f.write(u'[Text]\n')
f.write(u'hardware_apps = %s\n' % "|".join(HARDWARE_APPS))
f.write(u'unicode_keyboard = %s\n' % UNICODE_KEYBOARD)
f.write(u'pause_default = %f\n' % PAUSE_DEFAULT)

parser = configparser.ConfigParser()
parser.read(config_path)
if parser.has_option("Text", "hardware_apps"):
HARDWARE_APPS = parser.get("Text", "hardware_apps").lower().split("|")
HARDWARE_APPS = (parser.get("Text", "hardware_apps")
.lower().split("|"))
if parser.has_option("Text", "unicode_keyboard"):
UNICODE_KEYBOARD = parser.getboolean("Text", "unicode_keyboard")
if parser.has_option("Text", "pause_default"):
PAUSE_DEFAULT = parser.getfloat("Text", "pause_default")
BaseKeyboardAction._pause_default = PAUSE_DEFAULT

_CONFIG_LOADED = True

Expand All @@ -81,10 +88,15 @@ class BaseKeyboardAction(DynStrActionBase):
"""

_keyboard = Keyboard()
_pause_default = 0.005
_pause_default = PAUSE_DEFAULT

def __init__(self, spec=None, static=False, use_hardware=False):
self._use_hardware = use_hardware

# Load the Windows-only config file if necessary.
if not _CONFIG_LOADED and os.name == "nt":
load_configuration()

super(BaseKeyboardAction, self).__init__(spec, static)

def require_hardware_events(self):
Expand Down
10 changes: 3 additions & 7 deletions dragonfly/actions/action_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,13 @@ class Text(BaseKeyboardAction):

def __init__(self, spec=None, static=False, pause=None,
autofmt=False, use_hardware=False):
# Use the default pause time if pause is None.
self._pause = self._pause_default if pause is None else pause

# Set other members and call the super constructor.
self._autofmt = autofmt

if isinstance(spec, binary_type):
spec = spec.decode(getpreferredencoding())

BaseKeyboardAction.__init__(self, spec=spec, static=static,
use_hardware=use_hardware)
# Set other members.
self._autofmt = autofmt
self._pause = self._pause_default if pause is None else pause

def _parse_spec(self, spec):
"""Convert the given *spec* to keyboard events."""
Expand Down

0 comments on commit 4ebd104

Please sign in to comment.