Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup keyboard code #352

Merged
merged 3 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix a bug with Text action default pause values
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
commit 4ebd1045332098b62fbe1639a0a0259b26ad56aa
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